Skip to content

Commit

Permalink
chore: more ui / balance changes (#149)
Browse files Browse the repository at this point in the history
* more balance

* fix map position

* fix trade page on mobile

* use sunset image for all escaped

* update risks

* Inventory text update

* back button on travel mobile page

* mobile fixes

* add bag count in inventory

* fix test
  • Loading branch information
broody authored Sep 19, 2023
1 parent 4a97e1d commit 2d529c9
Show file tree
Hide file tree
Showing 17 changed files with 914 additions and 795 deletions.
10 changes: 8 additions & 2 deletions src/components/risks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ 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 +30,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
10 changes: 6 additions & 4 deletions src/constants.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const SCALING_FACTOR: u128 = 10_000;

const TRAVEL_RISK: u8 = 60; // 60% chance of travel encounter
const TRAVEL_RISK: u8 = 75; // 75% 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
37 changes: 13 additions & 24 deletions src/systems/decide.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
mod decide {
use array::ArrayTrait;
use box::BoxTrait;
use traits::Into;
use traits::{Into, TryInto};
use starknet::ContractAddress;

use dojo::world::Context;

use rollyourown::PlayerStatus;
use rollyourown::constants::{COPS_DRUG_THRESHOLD, HEALTH_IMPACT, GANGS_PAYMENT};
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};
use rollyourown::components::drug::{Drug, DrugTrait};
use rollyourown::utils::random;

#[derive(Copy, Drop, Serde, PartialEq)]
enum Action {
Expand Down Expand Up @@ -64,23 +65,25 @@ 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 => {
let random_loss: u8 = random(seed, 0, HEALTH_IMPACT.into())
.try_into()
.unwrap();
let health_loss: u8 = HEALTH_IMPACT + random_loss;
(Outcome::Captured, 0, 0, health_loss)
}
}
},
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 Expand Up @@ -116,20 +119,6 @@ mod decide {
);
}


fn cops_payment(drug_count: u32) -> u128 {
if drug_count < COPS_DRUG_THRESHOLD + 20 {
1000_0000 // $1000
} else if drug_count < COPS_DRUG_THRESHOLD + 50 {
5000_0000 // $5000
} else if drug_count < COPS_DRUG_THRESHOLD + 80 {
10000_0000 // $10000
} else {
20000_0000 // $20000
}
}


fn take_drugs(
ctx: Context, game_id: u32, player_id: ContractAddress, percentage: usize
) -> usize {
Expand Down
8 changes: 4 additions & 4 deletions src/tests/trade.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rollyourown::components::player::Player;
use rollyourown::tests::create::{spawn_game, spawn_player};
use rollyourown::constants::SCALING_FACTOR;

const DRUG_ID: felt252 = 0x57656564; // weed
const WEED_ID: felt252 = 0x57656564; // weed
const QUANTITY: usize = 3;

#[test]
Expand All @@ -32,20 +32,20 @@ fn test_trade() {
let mut buy_calldata = array::ArrayTrait::<felt252>::new();
buy_calldata.append(game_id.into());
buy_calldata.append(player.location_id);
buy_calldata.append(DRUG_ID);
buy_calldata.append(WEED_ID);
buy_calldata.append(QUANTITY.into());
world.execute('buy'.into(), buy_calldata);

let player = get!(world, (game_id, player_id).into(), (Player));
let player_drug = get!(world, (game_id, player_id, DRUG_ID).into(), (Drug));
let player_drug = get!(world, (game_id, player_id, WEED_ID).into(), (Drug));
assert(player.drug_count == QUANTITY, 'wrong drug count');
assert(player_drug.quantity == QUANTITY, 'wrong purchase amount');

// market sell 1 weed
let mut sell_calldata = array::ArrayTrait::<felt252>::new();
sell_calldata.append(game_id.into());
sell_calldata.append(player.location_id);
sell_calldata.append(DRUG_ID);
sell_calldata.append(WEED_ID);
sell_calldata.append(1);
world.execute('sell'.into(), sell_calldata);

Expand Down
12 changes: 11 additions & 1 deletion src/tests/travel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ use dojo::test_utils::spawn_test_world;
use rollyourown::PlayerStatus;
use rollyourown::components::player::Player;
use rollyourown::tests::create::{spawn_game, spawn_player};
use rollyourown::constants::{TRAVEL_RISK};
use rollyourown::constants::{TRAVEL_RISK, COPS_DRUG_THRESHOLD};

const WEED_ID: felt252 = 0x57656564; // weed

#[test]
#[available_gas(110000000)]
fn test_travel_and_decision() {
let (world_address, game_id, player_id) = spawn_game(); // creator auto joins
let world = IWorldDispatcher { contract_address: world_address };
let player = get!(world, (game_id, player_id).into(), (Player));

let mut buy_calldata = array::ArrayTrait::<felt252>::new();
buy_calldata.append(game_id.into());
buy_calldata.append(player.location_id);
buy_calldata.append(WEED_ID);
buy_calldata.append(COPS_DRUG_THRESHOLD.into());
world.execute('buy'.into(), buy_calldata);

let brooklyn_id = 'Brooklyn';
let mut travel_calldata = array::ArrayTrait::<felt252>::new();
Expand Down
35 changes: 2 additions & 33 deletions web/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,18 @@ const Header = ({ back }: HeaderProps) => {
{playerEntity && gameEntity && (
<HStack flex="1" justify="center">
<HStack
h={["80px", "40px"]}
h="40px"
w="auto"
px="20px"
spacing={["10px", "30px"]}
bg="neon.700"
clipPath={`polygon(${generatePixelBorderPath()})`}
>
<Flex
w="full"
flexDirection={["column-reverse", "row"]}
align="center"
justify="center"
gap="10px"
>
<Flex w="full" align="center" justify="center" gap="10px">
<HStack>
<Gem /> <Text>{formatCash(playerEntity.cash)}</Text>
</HStack>
<HStack>
<Divider
orientation="vertical"
borderColor="neon.600"
h="12px"
visibility={["hidden", "visible"]}
/>
<HStack color={inventory > 0 ? "yellow.400" : "auto"}>
<Bag />
<Text>{inventory === 100 ? "Full" : `${inventory}/100`}</Text>
</HStack>
<Divider
orientation="vertical"
borderColor="neon.600"
Expand All @@ -108,21 +92,6 @@ const Header = ({ back }: HeaderProps) => {
<HStack>
<Heart /> <Text>{playerEntity.health}</Text>
</HStack>
{/* <Divider
orientation="vertical"
borderColor="neon.600"
h="12px"
/>
<HStack>
<Clock />
<Text>
{playerEntity.turnsRemaining === 0
? "Final"
: `${
gameEntity.maxTurns - playerEntity.turnsRemaining + 1
}/${gameEntity.maxTurns + 1}`}
</Text>
</HStack> */}
</HStack>
</Flex>
</HStack>
Expand Down
15 changes: 12 additions & 3 deletions web/src/components/Inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { usePlayerEntity } from "@/dojo/entities/usePlayerEntity";
import { useRouter } from "next/router";
import { useDojo } from "@/dojo";
import { getDrugById } from "@/dojo/helpers";
import { Bag } from "./icons";

export const Inventory = ({ ...props }: StyleProps) => {
const router = useRouter();
Expand All @@ -24,9 +25,17 @@ export const Inventory = ({ ...props }: StyleProps) => {

return (
<VStack {...props} w="full" align="flex-start">
<Text textStyle="subheading" fontSize="10px" color="neon.500">
Inventory
</Text>
<HStack w="full" justify="space-between">
<Text textStyle="subheading" fontSize="10px" color="neon.500">
Your Inventory
</Text>
<HStack color="yellow.400">
<Bag />
<Text>
{playerEntity?.drugCount}/{playerEntity?.bagLimit}
</Text>
</HStack>
</HStack>
<Card
w="full"
h="40px"
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const LeftPanel = ({
...props
}: Partial<LeftPanelProps> & StyleProps) => {
return (
<VStack my="auto" flex={["0", "1"]} {...props}>
<VStack flex={["0", "1"]} my={["none", "auto"]} {...props}>
<VStack
zIndex="1"
position={map ? "absolute" : "unset"}
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/icons/Skull.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Icon, IconProps } from ".";
export const Skull = (props: IconProps) => {
return (
<Icon viewBox="0 0 24 24" {...props}>
<path d="M19.0001 7.99998V6.99987H18.0001V5.99994H17.0002V5H6.99998V5.99994H6.00005V6.99987H5.00011V7.99981L4 7.99998V12.9997H4.99994V14.9995H5.99987V15.9995H6.99981V18.9993H8.99969V16.9994H10.9996V18.9993H12.9994V16.9994H14.9993V18.9993H16.9992V15.9995H17.9991V14.9995H18.9991V12.9997H19.999V9.99985L20 8.99992V7.99998L19.0001 7.99998ZM17.0002 12.9997H15.0003V11.9997H14.0004V9.99986H17.0002V12.9997ZM11.0002 14.9997V12.9998H13.0001V14.9997H11.0002ZM7.00015 11.9997V9.99986H9.99997V11.9997H9.0002V12.9997H7.00015V11.9997Z"/>
<path d="M19.0001 7.99998V6.99987H18.0001V5.99994H17.0002V5H6.99998V5.99994H6.00005V6.99987H5.00011V7.99981L4 7.99998V12.9997H4.99994V14.9995H5.99987V15.9995H6.99981V18.9993H8.99969V16.9994H10.9996V18.9993H12.9994V16.9994H14.9993V18.9993H16.9992V15.9995H17.9991V14.9995H18.9991V12.9997H19.999V9.99985L20 8.99992V7.99998L19.0001 7.99998ZM17.0002 12.9997H15.0003V11.9997H14.0004V9.99986H17.0002V12.9997ZM11.0002 14.9997V12.9998H13.0001V14.9997H11.0002ZM7.00015 11.9997V9.99986H9.99997V11.9997H9.0002V12.9997H7.00015V11.9997Z" />
</Icon>
);
};
};
1 change: 0 additions & 1 deletion web/src/components/map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { motion, useAnimate } from "framer-motion";
import { useEffect } from "react";
import { HitBox } from "./HitBox";
import { Outline } from "./Outline";
import { Markers } from "./Markers";
import { Location } from "@/dojo/types";

type CoordinateType = {
Expand Down
32 changes: 16 additions & 16 deletions web/src/dojo/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const outcomes: OutcomeInfo[] = [
name: "Escaped",
type: Outcome.Escaped,
status: PlayerStatus.BeingArrested,
imageSrc: "/images/events/escaped.png",
imageSrc: "/images/sunset.png",
getResponse: (isInitial: boolean) =>
getCopResponses(Outcome.Escaped, isInitial),
color: "neon.200",
Expand All @@ -152,7 +152,7 @@ export const outcomes: OutcomeInfo[] = [
name: "Escaped",
type: Outcome.Escaped,
status: PlayerStatus.BeingMugged,
imageSrc: "/images/events/escaped.png",
imageSrc: "/images/sunset.png",
getResponse: (isInitial: boolean) =>
getMuggerResponses(Outcome.Escaped, isInitial),
color: "neon.200",
Expand All @@ -167,13 +167,13 @@ export const outcomes: OutcomeInfo[] = [
color: "red",
},
{
name: "Got killed by the Cops",
type: Outcome.Died,
status: PlayerStatus.BeingArrested,
imageSrc: "/images/events/fought.png",
getResponse: (isInitial: boolean) =>
getMuggerResponses(Outcome.Died, isInitial),
color: "red",
name: "Got killed by the Cops",
type: Outcome.Died,
status: PlayerStatus.BeingArrested,
imageSrc: "/images/events/fought.png",
getResponse: (isInitial: boolean) =>
getMuggerResponses(Outcome.Died, isInitial),
color: "red",
},
];

Expand Down Expand Up @@ -209,13 +209,13 @@ export function getOutcomeInfo(
status: PlayerStatus,
type: Outcome,
): OutcomeInfo {
const found = outcomes.find((item) => {
return item.status === status && item.type === type;
});
if(!found) {
console.log(`getOutcomeInfo outcome ${status} ${type} not found !`)
}
return found || outcomes[0]
const found = outcomes.find((item) => {
return item.status === status && item.type === type;
});
if (!found) {
console.log(`getOutcomeInfo outcome ${status} ${type} not found !`);
}
return found || outcomes[0];
}

export function sortDrugMarkets(drugMarkets?: DrugMarket[]): DrugMarket[] {
Expand Down
Loading

1 comment on commit 2d529c9

@vercel
Copy link

@vercel vercel bot commented on 2d529c9 Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

rollyourown – ./

rollyourown.preview.cartridge.gg
rollyourown-git-main.preview.cartridge.gg

Please sign in to comment.