Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #577 number out of bounds during optimistic start #578

Merged
merged 2 commits into from
Apr 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading