Skip to content

Commit

Permalink
Merge pull request #578 from BibliothecaDAO/577-optimistic-start-bug
Browse files Browse the repository at this point in the history
fixes #577 number out of bounds during optimistic start
  • Loading branch information
ponderingdemocritus authored Apr 27, 2024
2 parents 276730e + 2ac6e1c commit 39d07e7
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions contracts/game/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ mod Game {
// let adventurer = _load_adventurer(self, adventurer_id);
// _assert_upgrades_available(adventurer);

// let adventurer_entropy = _load_adventurer_entropy(self, adventurer_id);
// let adventurer_entropy = _get_adventurer_entropy(self, adventurer_id);

// _get_items_on_market_by_slot(
// self,
Expand Down Expand Up @@ -2457,27 +2457,12 @@ mod Game {
self: @ContractState, adventurer_id: felt252
) -> (Adventurer, felt252, GameEntropy, Bag) {
let adventurer = _load_adventurer(self, adventurer_id);
let adventurer_entropy = _load_adventurer_entropy(self, adventurer_id);
let adventurer_entropy = _get_adventurer_entropy(self, adventurer_id);
let game_entropy = _load_game_entropy(self);
let bag = _load_bag(self, adventurer_id);
(adventurer, adventurer_entropy, game_entropy, bag)
}

fn _load_adventurer_entropy(self: @ContractState, adventurer_id: felt252) -> felt252 {
// get the block the adventurer started the game on
let start_block = _load_adventurer_metadata(self, adventurer_id).start_block;

// use longer block delay on mainnet for stronger entropy
let chain_id = starknet::get_execution_info().unbox().tx_info.unbox().chain_id;
if chain_id == MAINNET_CHAIN_ID {
_get_mainnet_entropy(adventurer_id, start_block)
} else if chain_id == SEPOLIA_CHAIN_ID {
_get_testnet_entropy(adventurer_id, start_block)
} else {
_get_basic_entropy(adventurer_id, start_block)
}
}

fn _load_adventurer(self: @ContractState, adventurer_id: felt252) -> Adventurer {
let mut adventurer = self._adventurer.read(adventurer_id);
_apply_starting_stats(self, ref adventurer, adventurer_id);
Expand Down

0 comments on commit 39d07e7

Please sign in to comment.