Skip to content

Commit

Permalink
back in business!
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Sep 6, 2023
1 parent 905bc26 commit c8ade60
Show file tree
Hide file tree
Showing 24 changed files with 169 additions and 145 deletions.
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rollyourown"
version = "0.1.0"
cairo-version = "2.0.0-rc4"
cairo-version = "2.2.0"

[cairo]
sierra-replace-ids = true
Expand All @@ -24,4 +24,4 @@ private_key = "0x1800000000300000180000000000030000000000003006001800006600"
#account_address = "0x2"
#private_key = "0xc1cf1490de1352865301bb8705143f3ef938f97fdf892f1090dcb5ac7bcd1d"

#world_address = "0x617a865eaaf42b325cc29f44c08b4fbe5face88aff560ed2743ae510efbf0f7"
#world_address = "0x3c3dfeb374720dfd73554dc2b9e0583cb9668efb3055d07d1533afa5d219fd5"
2 changes: 1 addition & 1 deletion scripts/default_auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euo pipefail
pushd $(dirname "$0")/..

export WORLD_ADDRESS="0x4b603970f151d639330fc35ddd591d7bac3c94505369270a969e54304a7e3f6";
export WORLD_ADDRESS="0x3c3dfeb374720dfd73554dc2b9e0583cb9668efb3055d07d1533afa5d219fd5";

# make sure all components/systems are deployed
COMPONENTS=("Game" "Market" "Name" "Player" "Risks")
Expand Down
10 changes: 5 additions & 5 deletions src/components/risks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl RisksImpl of RisksTrait {
let mut event_occured = false;

if occurs(seed, *self.travel) {
seed = pedersen(seed, seed);
seed = pedersen::pedersen(seed, seed);
event_occured = true;

// TEMP: for testing, mugging is only risk
Expand Down Expand Up @@ -79,7 +79,7 @@ fn occurs(seed: felt252, likelihood: u8) -> bool {
#[test]
#[available_gas(1000000)]
fn test_never_occurs() {
let seed = pedersen(1, 1);
let seed = pedersen::pedersen(1, 1);
let risks = Risks { game_id: 0, location_id: 0, travel: 0, hurt: 0, mugged: 0, arrested: 0, };
let (event_occured, result) = risks.travel(seed);

Expand All @@ -92,7 +92,7 @@ fn test_never_occurs() {
#[test]
#[available_gas(1000000)]
fn test_always_occurs() {
let seed = pedersen(1, 1);
let seed = pedersen::pedersen(1, 1);
let risks = Risks {
game_id: 0, location_id: 0, travel: 100, hurt: 100, mugged: 100, arrested: 100,
};
Expand All @@ -104,15 +104,15 @@ fn test_always_occurs() {
#[test]
#[available_gas(1000000)]
fn test_occurs() {
let seed = pedersen(1, 1);
let seed = pedersen::pedersen(1, 1);
let event = occurs(seed, 10);
assert(!event, 'should not occur');
}

#[test]
#[available_gas(1000000)]
fn test_not_occurs() {
let seed = pedersen(1, 1);
let seed = pedersen::pedersen(1, 1);
let event = occurs(seed, 28);
assert(event, 'should occur');
}
Expand Down
10 changes: 7 additions & 3 deletions src/systems/create.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ mod create_game {
);

let mut seed = starknet::get_tx_info().unbox().transaction_hash;
seed = pedersen(seed, *location_id);
seed = pedersen::pedersen(seed, *location_id);

let mut drugs = DrugTrait::all();
loop {
match drugs.pop_front() {
Option::Some(drug_id) => {
// HACK: temp hack to get some randomness
seed = pedersen(seed, *drug_id);
seed = pedersen::pedersen(seed, *drug_id);
let market_cash = random(seed, MIN_CASH, MAX_CASH);
let rand = random(seed, MIN_QUANITTY.into(), MAX_QUANTITY.into());
let market_quantity: usize = rand.try_into().unwrap();
Expand Down Expand Up @@ -142,7 +142,11 @@ mod create_game {
emit!(ctx.world, PlayerJoined { game_id, player_id: ctx.origin, location_id: location_id });

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

(game_id, ctx.origin)
}
Expand Down
8 changes: 1 addition & 7 deletions src/systems/travel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,14 @@ mod travel {
});
}

// If arrested, player loses a turn and stays at same location
if result.arrested {
player.turns_remaining - 1;
set!(ctx.world, (player));
return (true);
}

// If mugged, player loses half their cash
if result.mugged {
player.cash /= 2;
}

// update player
player.location_id = next_location_id;
player.turns_remaining -= 1;
set!(ctx.world, (player));

emit!(ctx.world, Traveled {
Expand Down
24 changes: 12 additions & 12 deletions web/.env.development
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#NEXT_PUBLIC_DISABLE_MEDIAPLAYER_AUTOPLAY="true"
#NEXT_PUBLIC_RPC_ENDPOINT="http://localhost:5050"
#NEXT_PUBLIC_GRAPHQL_ENDPOINT="http://localhost:8080"
#NEXT_PUBLIC_ADMIN_ADDRESS="0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973"
#NEXT_PUBLIC_ADMIN_PRIVATE_KEY="0x1800000000300000180000000000030000000000003006001800006600"
#NEXT_PUBLIC_ACCOUNT_CLASS_HASH="0x04d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f"


NEXT_PUBLIC_DISABLE_MEDIAPLAYER_AUTOPLAY="true"
NEXT_PUBLIC_RPC_ENDPOINT="https://api.cartridge.gg/x/shinai/madara"
NEXT_PUBLIC_RPC_ENDPOINT="http://localhost:5050"
NEXT_PUBLIC_GRAPHQL_ENDPOINT="http://localhost:8080"
NEXT_PUBLIC_ADMIN_ADDRESS="0x2"
NEXT_PUBLIC_ADMIN_PRIVATE_KEY="0xc1cf1490de1352865301bb8705143f3ef938f97fdf892f1090dcb5ac7bcd1d"
NEXT_PUBLIC_ACCOUNT_CLASS_HASH="0x006280083f8c2a2db9f737320d5e3029b380e0e820fe24b8d312a6a34fdba0cd"
NEXT_PUBLIC_ADMIN_ADDRESS="0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973"
NEXT_PUBLIC_ADMIN_PRIVATE_KEY="0x1800000000300000180000000000030000000000003006001800006600"
NEXT_PUBLIC_ACCOUNT_CLASS_HASH="0x04d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f"


# NEXT_PUBLIC_DISABLE_MEDIAPLAYER_AUTOPLAY="true"
# NEXT_PUBLIC_RPC_ENDPOINT="https://api.cartridge.gg/x/shinai/madara"
# NEXT_PUBLIC_GRAPHQL_ENDPOINT="http://localhost:8080"
# NEXT_PUBLIC_ADMIN_ADDRESS="0x2"
# NEXT_PUBLIC_ADMIN_PRIVATE_KEY="0xc1cf1490de1352865301bb8705143f3ef938f97fdf892f1090dcb5ac7bcd1d"
# NEXT_PUBLIC_ACCOUNT_CLASS_HASH="0x006280083f8c2a2db9f737320d5e3029b380e0e820fe24b8d312a6a34fdba0cd"
2 changes: 2 additions & 0 deletions web/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
4 changes: 2 additions & 2 deletions web/src/components/Inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import React from "react";
import { usePlayerEntity } from "@/hooks/dojo/entities/usePlayerEntity";
import { useRouter } from "next/router";
import { getDrugByName } from "@/hooks/ui";
import { getDrugById } from "@/hooks/ui";
import { useDojo } from "@/hooks/dojo";

export const Inventory = ({ ...props }: StyleProps) => {
Expand Down Expand Up @@ -50,7 +50,7 @@ export const Inventory = ({ ...props }: StyleProps) => {
<>
<HStack key={index} gap="10px">
<HStack color="yellow.400">
{getDrugByName(drug.name).icon({ boxSize: "26" })}
{getDrugById(drug.id).icon({ boxSize: "26" })}
<Text>{drug.quantity}</Text>
</HStack>
{index < playerEntity.drugs.length - 1 && (
Expand Down
2 changes: 1 addition & 1 deletion web/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const RYO_WORLD_ADDRESS =
"0x4b603970f151d639330fc35ddd591d7bac3c94505369270a969e54304a7e3f6";
"0x3c3dfeb374720dfd73554dc2b9e0583cb9668efb3055d07d1533afa5d219fd5";
export const ETH_CONTRACT_ADDRESS =
"0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
12 changes: 7 additions & 5 deletions web/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,16 +774,18 @@ export type PlayerEntityQuery = {
cursor: any;
node?: {
__typename?: "Entity";
keys?: Array<string | null> | null;
components?: Array<
| { __typename: "Drug"; quantity?: any | null }
| { __typename: "Drug"; drug_id?: any | null; quantity?: any | null }
| { __typename: "Game" }
| { __typename: "Market" }
| { __typename: "Name"; short_string?: any | null }
| { __typename: "Name" }
| {
__typename: "Player";
cash?: any | null;
health?: any | null;
turns_remaining?: any | null;
location_id?: any | null;
}
| { __typename: "Risks" }
| null
Expand Down Expand Up @@ -1018,19 +1020,19 @@ export const PlayerEntityDocument = `
totalCount
edges {
node {
keys
components {
__typename
... on Player {
cash
health
turns_remaining
location_id
}
... on Drug {
drug_id
quantity
}
... on Name {
short_string
}
}
}
cursor
Expand Down
49 changes: 46 additions & 3 deletions web/src/graphql/entities.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ query PlayerEntity($gameId: String!, $playerId: String!) {
totalCount
edges {
node {
keys
components {
__typename
... on Player {
cash
health
turns_remaining
location_id
}
... on Drug {
drug_id
quantity
}
... on Name {
short_string
}
}
}
cursor
Expand Down Expand Up @@ -63,3 +63,46 @@ query LocationEntities($gameId: String!, $locationId: String!) {
}
}
}

# TODO: Query entire game state per gameId in one query
# query GameState($gameId: String!) {
# entities (first: 100, keys: [$gameId]]) {
# totalCount
# edges {
# node {
# componentNames
# components {
# __typename
# ... on Game {
# creator
# is_finished
# max_players
# max_turns
# num_players
# start_time
# }
# ... on Player {
# cash
# health
# turns_remaining
# }
# ... on Drug {
# quantity
# }
# ... on Market {
# drug_id
# location_id
# cash
# quantity
# }
# ... on Risks {
# arrested
# hurt
# mugged
# travel
# }
# }
# }
# }
# }
# }
3 changes: 0 additions & 3 deletions web/src/hooks/dojo/entities/useGameEntity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,13 @@ export const useGameEntity = ({
{ id: key },
{
enabled: !!gameId,
refetchInterval: REFETCH_INTERVAL,
},
);

useEffect(() => {
if (gameId) {
console.log(gameId);
const key_ = ec.starkCurve.poseidonHashMany([num.toBigInt(gameId)]);
setKey(num.toHex(key_));
console.log(num.toHex(key_));
}
}, [gameId]);

Expand Down
Loading

0 comments on commit c8ade60

Please sign in to comment.