Skip to content

Commit

Permalink
more balance
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Sep 18, 2023
1 parent ceab688 commit cc51ff3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 45 deletions.
8 changes: 6 additions & 2 deletions src/components/risks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use traits::{Into, TryInto};
use option::OptionTrait;
use debug::PrintTrait;

use rollyourown::constants::{SCALING_FACTOR, COPS_DRUG_THRESHOLD, ENCOUNTER_BIAS_GANGS};
use rollyourown::constants::{SCALING_FACTOR, COPS_DRUG_THRESHOLD, GANGS_CASH_THRESHOLD, ENCOUNTER_BIAS_GANGS};
use rollyourown::PlayerStatus;

#[derive(Component, Copy, Drop, Serde)]
Expand All @@ -28,12 +28,16 @@ impl RisksImpl of RisksTrait {
return match result <= ENCOUNTER_BIAS_GANGS {
bool::False => {
if drug_count < COPS_DRUG_THRESHOLD {
return PlayerStatus::BeingMugged;
return PlayerStatus::Normal;
}

PlayerStatus::BeingArrested
},
bool::True => {
if cash <= GANGS_CASH_THRESHOLD {
return PlayerStatus::Normal;
}

PlayerStatus::BeingMugged
}
};
Expand Down
8 changes: 5 additions & 3 deletions src/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const SCALING_FACTOR: u128 = 10_000;
const TRAVEL_RISK: u8 = 60; // 60% chance of travel encounter
const CAPTURE_RISK: u8 = 60; // 60% chance of capture

const ENCOUNTER_BIAS_GANGS: u128 = 75; // 75% chance of gangs encounter vs cops
const COPS_DRUG_THRESHOLD: usize = 5; // cops encounter threshold
const ENCOUNTER_BIAS_GANGS: u128 = 50; // 50% chance of gangs encounter vs cops
const COPS_DRUG_THRESHOLD: usize = 2; // cops encounter threshold
const GANGS_CASH_THRESHOLD: u128 = 1000_0000; // gangs encounter threshold

const HEALTH_IMPACT: u8 = 10;
const GANGS_PAYMENT: usize = 20;
const GANGS_PAYMENT: usize = 20; // 20% of cash
const COPS_PAYMENT: usize = 20; // 20% of drugs

// starting stats
const STARTING_CASH: u128 = 2000_0000; // $2000
Expand Down
14 changes: 5 additions & 9 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, HEALTH_IMPACT, COPS_DRUG_THRESHOLD};
use rollyourown::constants::{GANGS_PAYMENT, COPS_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 @@ -64,23 +64,19 @@ mod decide {
let seed = starknet::get_tx_info().unbox().transaction_hash;
match risks.run(seed) {
bool::False => (Outcome::Escaped, 0, 0, 0),
bool::True => (
Outcome::Captured, 0, 0, HEALTH_IMPACT * (1 + player.run_attempts)
)
bool::True => (Outcome::Captured, 0, 0, HEALTH_IMPACT)
}
},
Action::Pay => {
match player.status {
PlayerStatus::Normal => (Outcome::Unsupported, 0, 0, 0),
PlayerStatus::BeingMugged => {
let drug_loss = take_drugs(ctx, game_id, player_id, GANGS_PAYMENT);
let cash_loss = (player.cash * GANGS_PAYMENT.into()) / 100;
(Outcome::Paid, cash_loss, drug_loss, 0)
(Outcome::Paid, cash_loss, 0, 0)
},
PlayerStatus::BeingArrested => {
let cash_loss = cops_payment(player.drug_count);
assert(cash_loss <= player.cash, 'not enough cash to pay cops');
(Outcome::Paid, cash_loss, 0, 0)
let drug_loss = take_drugs(ctx, game_id, player_id, COPS_PAYMENT);
(Outcome::Paid, 0, drug_loss, 0)
}
}
},
Expand Down
36 changes: 5 additions & 31 deletions web/src/pages/[gameId]/event/decision.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { usePlayerStore } from "@/hooks/state";
import { ConsequenceEventData } from "@/dojo/events";
import { Heading, Text, VStack } from "@chakra-ui/react";
import { useRouter } from "next/router";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useCallback, useEffect, useState } from "react";
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";
import { playSound, Sounds } from "@/hooks/sound";
Expand Down Expand Up @@ -46,29 +45,19 @@ export default function Decision() {
case PlayerStatus.BeingMugged:
setPrefixTitle("You encountered a...");
setTitle("Gang!");
setDemand(`They want 20% of your DRUGS and $PAPER!`);
setDemand(`They want 20% of your $PAPER!`);
break;
case PlayerStatus.BeingArrested:
const payment = formatCash(copsPayment(playerEntity.drugCount));
setPrefixTitle("You encountered the...");
setTitle("Cops!");
setDemand(
`You're carrying DRUGS! These dirty cops are demanding ${payment} PAPER!`,
);
setDemand(`The want 20% of your DRUGS!`);
break;
}

setStatus(playerEntity.status);
}
}, [playerEntity, isSubmitting]);

const canPay = useMemo(() => {
if (playerEntity && playerEntity.status == PlayerStatus.BeingArrested) {
return playerEntity.cash >= copsPayment(playerEntity.drugCount);
}
return true;
}, [playerEntity]);

useEffect(() => {
if (status == PlayerStatus.BeingArrested) {
playSound(Sounds.Police);
Expand Down Expand Up @@ -137,7 +126,6 @@ export default function Decision() {
prefixTitle={prefixTitle}
title={title}
demand={demand}
canPay={canPay}
imageSrc={`/images/events/${
status == PlayerStatus.BeingMugged ? "muggers.gif" : "cops.gif"
}`}
Expand All @@ -151,25 +139,12 @@ export default function Decision() {
);
}

const copsPayment = (drugCount: number) => {
if (drugCount < COPS_DRUG_THRESHOLD + 20) {
return 1000;
} else if (drugCount < COPS_DRUG_THRESHOLD + 50) {
return 5000;
} else if (drugCount < COPS_DRUG_THRESHOLD + 80) {
return 10000;
} else {
return 20000;
}
};

const Encounter = ({
prefixTitle,
title,
demand,
imageSrc,
penalty,
canPay,
isSubmitting,
onPay,
onRun,
Expand All @@ -179,7 +154,6 @@ const Encounter = ({
demand?: string;
imageSrc: string;
penalty?: string;
canPay: boolean;
isSubmitting?: boolean;
onPay: () => void;
onRun: () => void;
Expand Down Expand Up @@ -242,14 +216,14 @@ const Encounter = ({
</Button>
<Button
w="full"
isDisabled={isPaying || isRunning || !canPay}
isDisabled={isPaying || isRunning}
isLoading={isPaying}
onClick={() => {
setIsPaying(true);
onPay();
}}
>
{canPay ? "PAY" : "Not enough $PAPER"}
PAY
</Button>
</Footer>
</VStack>
Expand Down

0 comments on commit cc51ff3

Please sign in to comment.