Skip to content

Commit

Permalink
shuffle_drug_prices after level up
Browse files Browse the repository at this point in the history
  • Loading branch information
notV4l committed Mar 14, 2024
1 parent f0d8331 commit b59d2ae
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ private_key = "0x1800000000300000180000000000030000000000003006001800006600"

[profile.staging.tool.dojo.env]
rpc_url = "https://api.cartridge.gg/x/ryo420/katana"
account_address = "0x795abc2a2d5866f75c58025741329973db20966d1add5dd2a9fbdf0bb8a0266"
private_key = "0x2e8ac99614186737cefc47effe03134f5a19c6dc2443c16510d3384769f9c78"
account_address = "0x754d8bc62099e306ab40deb98accc3e717eb1a7b8838060c6312c6e8f8ee1d7"
private_key = "0x2f9a2435c3195dfa3c2f8290de5347e0da48193fd6d6d80320f0201a0964b8c"

[profile.prod.tool.dojo.env]
rpc_url = "https://api.cartridge.gg/x/ryo420/katana"
Expand Down
1 change: 1 addition & 0 deletions src/config/locations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl LocationsEnumerableImpl of Enumerable<Locations> {
];
items.span()
}

}

//
Expand Down
33 changes: 29 additions & 4 deletions src/packing/markets_packed.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,15 @@ impl MarketsPackedImpl of MarketsPackedTrait {
loop {
match locations.pop_front() {
Option::Some(location) => {
let mut drugs = DrugsEnumerableImpl::all();
// limit to 4 drugs slots
let _ = drugs.pop_back();
let _ = drugs.pop_back();

// limit to 4 drugs slots == [0,1,2,3]
let mut drugs = array![
Drugs::Ludes,
Drugs::Speed,
Drugs::Weed,
Drugs::Shrooms,
].span();

loop {
match drugs.pop_front() {
Option::Some(drug) => {
Expand Down Expand Up @@ -158,6 +163,26 @@ impl MarketsPackedImpl of MarketsPackedTrait {
};
};
}

//
//
//

fn shuffle_drug_prices(ref self: MarketsPacked, ref randomizer: Random, drug_level: u8) {
let mut locations = LocationsEnumerableImpl::all();

let drug = drug_level.sub_capped(1,0);

loop {
match locations.pop_front() {
Option::Some(location) => {
let rand_tick = randomizer.between::<usize>(0, 63).into();
self.set_tick(*location, drug.into(), rand_tick);
},
Option::None(_) => { break; }
};
};
}
}

//
Expand Down
13 changes: 9 additions & 4 deletions src/packing/player.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use rollyourown::{
player_layout::{PlayerLayout, PlayerLayoutEnumerableImpl, PlayerLayoutPackableImpl},
drugs_packed::{DrugsPacked, DrugsPackedImpl},
encounters_packed::{EncountersPacked, EncountersPackedImpl, Encounters},
markets_packed::{MarketsPacked, MarketsPackedImpl, MarketsPackedTrait}
},
};

Expand Down Expand Up @@ -163,15 +164,16 @@ impl PlayerImpl of PlayerTrait {
}

fn level_up_drug(
ref self: Player, drugs_packed: DrugsPacked, encounters_packed: EncountersPacked
ref self: Player, ref game_store: GameStore, ref randomizer: Random
//drugs_packed: DrugsPacked, encounters_packed: EncountersPacked
) {
// check if already max drug_level
if self.drug_level == 4 {
return;
};

let cops_level = encounters_packed.get_encounter_level(Encounters::Cops);
let gang_level = encounters_packed.get_encounter_level(Encounters::Gang);
let cops_level = game_store.encounters.get_encounter_level(Encounters::Cops);
let gang_level = game_store.encounters.get_encounter_level(Encounters::Gang);
let level = cops_level + gang_level;

// level up each 2 encounters capped to 4
Expand All @@ -183,13 +185,16 @@ impl PlayerImpl of PlayerTrait {
}

// check if not carrying drug to be disabled
let drugs = drugs_packed.get();
let drugs = game_store.drugs.get();
if drugs.quantity > 0 && drugs.drug.into() < drug_level {
return;
}

// update drug level
self.drug_level = drug_level;

// randomize price for new drug
game_store.markets.shuffle_drug_prices(ref randomizer, drug_level.into());
}

fn hustle(self: Player, ref game_store: GameStore, ref randomizer: Random) {
Expand Down
2 changes: 1 addition & 1 deletion src/systems/game_loop.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn on_turn_end(ref game_store: GameStore, ref randomizer: Random) -> bool {
}

// level up drug_level if possible
game_store.player.level_up_drug(game_store.drugs, game_store.encounters);
game_store.player.level_up_drug(ref game_store, ref randomizer);

// markets variations
game_store.markets.market_variations(ref randomizer);
Expand Down
13 changes: 10 additions & 3 deletions web/src/pages/[gameId]/logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ import {
} from "@chakra-ui/react";
import { observer } from "mobx-react-lite";
import { useEffect, useRef, useState } from "react";
import { shortString } from "starknet";
Tooltip,
UnorderedList,
VStack,
} from "@chakra-ui/react";
import { observer } from "mobx-react-lite";
import { useEffect, useRef, useState } from "react";
import { shortString } from "starknet";

type LogByDay = {
Expand Down Expand Up @@ -153,12 +160,12 @@ const Logs = () => {
</TabList>

<TabPanels w="full">
<TabPanel w="full" h="calc(100vh - 360px)">
<TabPanel w="full" maxH="600px" /*h="calc(100vh - 360px)"*/>
<Box display="flex" alignItems="center" justifyContent="center" h="100%">
<Loadout />
</Box>
</TabPanel>
<TabPanel w="full" h="calc(100vh - 360px)" overflowY="scroll">
<TabPanel w="full" maxH="600px" /*h="calc(100vh - 360px)"*/ overflowY="scroll">
<VStack w="full" mt={["-20px", "-30px"]} ref={listRef}>
{logs && logs.map((log) => renderDay(configStore, game, log))}
</VStack>
Expand All @@ -176,7 +183,7 @@ const CustomLeftPanel = () => {
return (
<VStack w="full" h="full" justifyContent="center" alignItems="center" flex="1" marginBottom="50px" gap={0}>
<Text textStyle="subheading" textAlign="center" fontSize={["9px", "11px"]}>
{game ? reputationRanks[game.player.drugLevel as reputationRanksKeys] : ""}
{game ? reputationRanks[game.player.drugLevel as reputationRanksKeys] : ""}
</Text>
<Heading fontSize={["36px", "48px"]} fontWeight="400" mb={["0px", "20px"]}>
{shortString.decodeShortString(gameInfos?.player_name || "")}
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function Home() {
<Tab>HALL OF FAME</Tab>
</TabList>

<TabPanels mt={0} h="calc(100vh - 400px)" overflowY="scroll">
<TabPanels mt={0} maxH="600px" overflowY="scroll">
<TabPanel p={0}>
<Leaderboard />
</TabPanel>
Expand Down

0 comments on commit b59d2ae

Please sign in to comment.