diff --git a/src/systems/create.cairo b/src/systems/create.cairo index f86512509..2f200d1f0 100644 --- a/src/systems/create.cairo +++ b/src/systems/create.cairo @@ -43,21 +43,19 @@ mod create_game { #[derive(Drop, starknet::Event)] struct PlayerJoined { game_id: u32, - player_id: ContractAddress, - location_id: felt252, + player_id: ContractAddress } fn execute( ctx: Context, start_time: u64, max_players: usize, max_turns: usize ) -> (u32, ContractAddress) { let game_id = ctx.world.uuid(); - let location_id = LocationTrait::random(); let player = Player { game_id, player_id: ctx.origin, - status: PlayerStatus::Normal(()), - location_id, + status: PlayerStatus::Normal, + location_id: 0, cash: STARTING_CASH, health: STARTING_HEALTH, run_attempts: 0, @@ -139,7 +137,7 @@ mod create_game { }; // emit player joined - emit!(ctx.world, PlayerJoined { game_id, player_id: ctx.origin, location_id: location_id }); + emit!(ctx.world, PlayerJoined { game_id, player_id: ctx.origin}); // emit game created emit!( diff --git a/src/systems/join.cairo b/src/systems/join.cairo index 8b4dad143..5c6c7e1ab 100644 --- a/src/systems/join.cairo +++ b/src/systems/join.cairo @@ -22,8 +22,7 @@ mod join_game { #[derive(Drop, starknet::Event)] struct PlayerJoined { game_id: u32, - player_id: ContractAddress, - location_id: felt252, + player_id: ContractAddress } fn execute(ctx: Context, game_id: u32) -> ContractAddress { @@ -37,13 +36,11 @@ mod join_game { game.num_players += 1; - let location_id = LocationTrait::random(); - let player = Player { game_id, player_id, - status: PlayerStatus::Normal(()), - location_id, + status: PlayerStatus::Normal, + location_id: 0, cash: STARTING_CASH, health: STARTING_HEALTH, run_attempts: 0, @@ -54,7 +51,7 @@ mod join_game { }; set!(ctx.world, (game, player)); - emit!(ctx.world, PlayerJoined { game_id, player_id, location_id }); + emit!(ctx.world, PlayerJoined { game_id, player_id }); player_id } diff --git a/src/systems/travel.cairo b/src/systems/travel.cairo index 1a39b9aa8..c61388699 100644 --- a/src/systems/travel.cairo +++ b/src/systems/travel.cairo @@ -51,21 +51,25 @@ mod travel { assert(player.can_continue(), 'player cannot travel'); assert(player.location_id != next_location_id, 'already at location'); - let mut risks: Risks = get!(ctx.world, (game_id, next_location_id).into(), Risks); - let seed = starknet::get_tx_info().unbox().transaction_hash; - player.status = risks.travel(seed, player.cash, player.drug_count); - if player.status != PlayerStatus::Normal { - set!(ctx.world, (player)); - emit!(ctx.world, AdverseEvent { game_id, player_id, player_status: player.status }); - - return true; - } + // initial travel when game starts has no risk or events + if player.location_id != 0 { + let mut risks: Risks = get!(ctx.world, (game_id, next_location_id).into(), Risks); + let seed = starknet::get_tx_info().unbox().transaction_hash; + player.status = risks.travel(seed, player.cash, player.drug_count); + if player.status != PlayerStatus::Normal { + set!(ctx.world, (player)); + emit!(ctx.world, AdverseEvent { game_id, player_id, player_status: player.status }); + + return true; + } - //market price fluctuation - market_events(ctx, game_id); + //market price fluctuation + market_events(ctx, game_id); + + player.turns_remaining -= 1; + } player.location_id = next_location_id; - player.turns_remaining -= 1; set!(ctx.world, (player)); emit!( diff --git a/web/src/pages/index.tsx b/web/src/pages/index.tsx index 9f66c1afb..6b6523690 100644 --- a/web/src/pages/index.tsx +++ b/web/src/pages/index.tsx @@ -85,16 +85,14 @@ export default function Home() { NUM_TURNS, ); - const { gameId, locationId } = event as JoinedEventData; + const { gameId } = event as JoinedEventData; toast( "Created Game", Alert, `http://amazing_explorer/${hash}`, ); - router.push( - `/${gameId}/${getLocationById(locationId)?.slug}`, - ); + router.push(`/${gameId}/travel}`); }} > Hustle