Skip to content

Commit

Permalink
toast messages for events
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Sep 18, 2023
1 parent 2fafa69 commit 386e52d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/components/market.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl MarketImpl of MarketTrait {
}
} else {
panic(array!['invalid drug_id']);
PricingInfos { min_price: 0, max_price: 0, min_qty: 0, max_qty: 0, }
PricingInfos { min_price: 0, max_price: 0, min_qty: 0, max_qty: 0, }
}
}
}
Expand All @@ -102,7 +102,7 @@ fn normalize(amount: usize, market: Market) -> (u128, u128, u128) {


#[test]
#[should_panic(expected: ('not enough liquidity',))]
#[should_panic(expected: ('not enough liquidity', ))]
fn test_not_enough_quantity() {
let mut market = Market {
game_id: 0, location_id: 0, drug_id: 0, cash: SCALING_FACTOR * 1, quantity: 1
Expand Down
5 changes: 2 additions & 3 deletions src/constants.cairo
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const SCALING_FACTOR: u128 = 10_000;

const TRAVEL_RISK: u8 = 50; // 50% chance of travel encounter
const TRAVEL_RISK: u8 = 75; // 75% chance of travel encounter
const CAPTURE_RISK: u8 = 50; // 50% chance of capture

const ENCOUNTER_BIAS_GANGS: u128 = 60;
const COPS_DRUG_THRESHOLD: usize = 5; // cops encounter threshold

const HEALTH_IMPACT: u8 = 10;
const COPS_PAYMENT: usize = 20;
const GANGS_PAYMENT: usize = 10;
const GANGS_PAYMENT: usize = 20;

// starting stats
const STARTING_CASH: u128 = 2000_0000; // $2000
Expand Down
5 changes: 3 additions & 2 deletions src/systems/create.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ mod create_game {

// emit game created
emit!(
ctx.world,
GameCreated { game_id, creator: ctx.origin, start_time, max_players, max_turns }
ctx.world, GameCreated {
game_id, creator: ctx.origin, start_time, max_players, max_turns
}
);

(game_id, ctx.origin)
Expand Down
11 changes: 7 additions & 4 deletions src/systems/decide.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod decide {
use dojo::world::Context;

use rollyourown::PlayerStatus;
use rollyourown::constants::{GANGS_PAYMENT, COPS_PAYMENT, HEALTH_IMPACT, COPS_DRUG_THRESHOLD};
use rollyourown::constants::{GANGS_PAYMENT, HEALTH_IMPACT, COPS_DRUG_THRESHOLD};
use rollyourown::components::game::{Game, GameTrait};
use rollyourown::components::risks::{Risks, RisksTrait};
use rollyourown::components::player::{Player, PlayerTrait};
Expand Down Expand Up @@ -63,7 +63,9 @@ mod decide {
let mut risks = get!(ctx.world, (game_id, player.location_id).into(), Risks);
let seed = starknet::get_tx_info().unbox().transaction_hash;
match risks.run(seed) {
bool::False => (Outcome::Captured, 0, 0, HEALTH_IMPACT),
bool::False => (
Outcome::Captured, 0, 0, HEALTH_IMPACT * (1 + player.run_attempts)
),
bool::True => (Outcome::Escaped, 0, 0, 0)
}
},
Expand Down Expand Up @@ -107,8 +109,9 @@ mod decide {

emit!(ctx.world, Decision { game_id, player_id, action });
emit!(
ctx.world,
Consequence { game_id, player_id, outcome, health_loss, drug_loss, cash_loss }
ctx.world, Consequence {
game_id, player_id, outcome, health_loss, drug_loss, cash_loss
}
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/systems/set_name.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ mod set_name {
use rollyourown::components::name::Name;

fn execute(ctx: Context, game_id: u32, player_name: felt252) {
set!(ctx.world, (Name { game_id, player_id: ctx.origin, short_string: player_name, }))
set!(ctx.world, (Name { game_id, player_id: ctx.origin, short_string: player_name, }))
}
}
3 changes: 1 addition & 2 deletions src/systems/travel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ mod travel {
set!(ctx.world, (player));

emit!(
ctx.world,
Traveled {
ctx.world, Traveled {
game_id, player_id, from_location: player.location_id, to_location: next_location_id
}
);
Expand Down
16 changes: 14 additions & 2 deletions web/src/pages/[gameId]/event/decision.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import Layout from "@/components/Layout";
import { Footer } from "@/components/Footer";
import Button from "@/components/Button";
import { formatCash } from "@/utils/ui";
import { useToast } from "@/hooks/toast";
import { Heart } from "@/components/icons";

const BASE_PAYMENT = 500;
const COPS_DRUG_THRESHOLD = 5;

export default function Decision() {
Expand All @@ -28,6 +29,7 @@ export default function Decision() {
const [demand, setDemand] = useState<string>();
const [penalty, setPenalty] = useState<string>();

const { toast } = useToast();
const { account } = useDojo();
const { decide } = useSystems();
const { addEncounter } = usePlayerStore();
Expand All @@ -43,7 +45,7 @@ export default function Decision() {
case PlayerStatus.BeingMugged:
setPrefixTitle("You encountered a...");
setTitle("Gang!");
setDemand(`They want 10% of your DRUGS and $PAPER!`);
setDemand(`They want 20% of your DRUGS and $PAPER!`);
break;
case PlayerStatus.BeingArrested:
const payment = formatCash(copsPayment(playerEntity.drugCount));
Expand Down Expand Up @@ -81,9 +83,19 @@ export default function Decision() {
setPrefixTitle("Your escape...");
setTitle("Failed!");
setPenalty(`You loss ${event.healthLoss}HP!`);
toast(
`You were captured and loss ${event.healthLoss}HP!`,
Heart,
`http://amazing_explorer/${result.hash}`,
);
break;

case Outcome.Died:
toast(
`You too ${event.healthLoss}HP damage and died...`,
Heart,
`http://amazing_explorer/${result.hash}`,
);
return router.push(`/${gameId}/end`);

case Outcome.Escaped:
Expand Down

0 comments on commit 386e52d

Please sign in to comment.