Skip to content

Commit

Permalink
only reset idle counter on beast defeat (#552)
Browse files Browse the repository at this point in the history
* previously this would get reset on every attack
* adventurers can occasionally exploit this is to significantly slow down the game
* this circumvents idle death penalty and global entropy system
  • Loading branch information
loothero committed Feb 24, 2024
1 parent 1f1909d commit e00b35e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions contracts/game/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,6 @@ mod Game {
@self, immutable_adventurer, adventurer_id, game_entropy
);

// update players last action block
adventurer.set_last_action_block(block_number);

// process attack or apply idle penalty
if !idle {
// get weapon specials
Expand Down Expand Up @@ -1099,6 +1096,9 @@ mod Game {
// zero out beast health
adventurer.beast_health = 0;

// update players last action block
adventurer.set_last_action_block(starknet::get_block_info().unbox().block_number);

// get gold reward and increase adventurers gold
let gold_earned = beast.get_gold_reward(beast_seed);
let ring_bonus = adventurer.ring.jewelry_gold_bonus(gold_earned);
Expand Down Expand Up @@ -2699,6 +2699,7 @@ mod Game {
let (is_idle, _) = _is_idle(self, adventurer, adventurer_id, game_entropy);
assert(is_idle, messages::ADVENTURER_NOT_IDLE);
}

fn _is_idle(
self: @ContractState,
adventurer: Adventurer,
Expand Down
2 changes: 1 addition & 1 deletion contracts/game/src/tests/test_game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ mod tests {
let mut game = new_adventurer(STARTING_BLOCK_NUMBER, 1696201757);

// attack starter beast, resulting in adventurer last action block number being 510
game.attack(ADVENTURER_ID, false);
game.attack(ADVENTURER_ID, true);

// get updated adventurer state
let adventurer = game.get_adventurer(ADVENTURER_ID);
Expand Down

0 comments on commit e00b35e

Please sign in to comment.