Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
starknetdev committed Oct 11, 2023
2 parents bfd8055 + 727490b commit e7b4a29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion contracts/game/src/game/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ trait IGame<TContractState> {
fn get_stat_upgrades_available(self: @TContractState, adventurer_id: felt252) -> u8;
fn get_last_action_block(self: @TContractState, adventurer_id: felt252) -> u16;
fn get_actions_per_block(self: @TContractState, adventurer_id: felt252) -> u8;
fn get_reveal_block(self: @TContractState, adventurer_id: felt252) -> u64;

// adventurer stats (includes boost)
fn get_stats(self: @TContractState, adventurer_id: felt252) -> Stats;
Expand Down Expand Up @@ -118,7 +119,7 @@ trait IGame<TContractState> {

// game settings
fn next_game_entropy_rotation(self: @TContractState) -> felt252;
fn game_rate_limit(self: @TContractState) -> u64;
fn game_rate_limit(self: @TContractState) -> u64;
fn starting_gold(self: @TContractState) -> u16;
fn starting_health(self: @TContractState) -> u16;
fn base_potion_price(self: @TContractState) -> u16;
Expand Down
14 changes: 9 additions & 5 deletions contracts/game/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,9 @@ mod Game {
fn get_actions_per_block(self: @ContractState, adventurer_id: felt252) -> u8 {
_unpack_adventurer(self, adventurer_id).actions_per_block
}
fn get_reveal_block(self: @ContractState, adventurer_id: felt252) -> u64 {
_get_reveal_block(self, adventurer_id)
}
fn get_equipped_items(
self: @ContractState, adventurer_id: felt252
) -> Array<ItemPrimitive> {
Expand Down Expand Up @@ -1327,16 +1330,11 @@ mod Game {
name, start_block: current_block, starting_stats: empty_stats
};

// emit a StartGame event
__event_StartGame(ref self, adventurer, adventurer_id, adventurer_meta);

// adventurer immediately gets ambushed by a starter beast
let beast_battle_details = _starter_beast_ambush(
ref adventurer, adventurer_id, weapon, starter_beast_rnd
);

__event_AmbushedByBeast(ref self, adventurer, adventurer_id, beast_battle_details);

// pack and save new adventurer and metadata
_pack_adventurer(ref self, adventurer_id, adventurer);
_pack_adventurer_meta(ref self, adventurer_id, adventurer_meta);
Expand All @@ -1346,6 +1344,10 @@ mod Game {

// set caller as owner
self._owner.write(adventurer_id, get_caller_address());

// emit events
__event_StartGame(ref self, adventurer, adventurer_id, adventurer_meta);
__event_AmbushedByBeast(ref self, adventurer, adventurer_id, beast_battle_details);
}

fn _starter_beast_ambush(
Expand Down Expand Up @@ -3123,7 +3125,9 @@ mod Game {
let adventurer_state = AdventurerState {
owner: get_caller_address(), adventurer_id, adventurer
};

let reveal_block = _get_reveal_block(@self, adventurer_id);

self.emit(StartGame { adventurer_state, adventurer_meta, reveal_block });
}

Expand Down

1 comment on commit e7b4a29

@vercel
Copy link

@vercel vercel bot commented on e7b4a29 Oct 11, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.