BibliothecaDAO / realms-contracts

Realms Monorepo for Ethereum contracts and Starknet contracts.
https://bibliothecadao.xyz/
MIT License
86 stars 33 forks source link

Bug in Flee Function #305

Closed loothero closed 1 year ago

loothero commented 1 year ago

The current Loot Survivor flee logic has a bug in which increasing the adventurers dexterity decreasing chance of fleeing.

let adventurer_speed = unpacked_adventurer.Dexterity - weight_of_equipment; ... let (flee_rnd) = get_random_number(); let (flee_chance) = BeastLib.get_random_flee(flee_rnd); let can_flee = is_le(adventurer_speed + 1, flee_chance); if (can_flee == TRUE) { IAdventurer.update_status( adventurer_address, Uint256(beast.Adventurer, 0), AdventurerStatus.Idle ); IAdventurer.assign_beast(adventurer_address, Uint256(beast.Adventurer, 0), 0); return (TRUE,); } else { return (FALSE,); }

Where BeastLib.get_random_flee(flee_rnd); returns either 0 or 1.

There are two problems here:

  1. let can_flee = is_le(adventurer_speed + 1, flee_chance); is inverted - it was probably intended to be let can_flee = is_le(flee_chance, adventurer_speed + 1 );
  2. We need BeastLib.get_random_flee(flee_rnd); to be based on the adventurers level, otherwise once an adventurer gets to dexterity 2 they will be able to flee everytime which will be too easy.

For the second issue, I suggest we use the same approach for assigning level to newly discovered beasts which is to make it random but centered around the adventurers level.

        // If the adventurer is less than the beast base level (currently 3)
        let is_less_than_base_level = is_le(adventurer_state.Level, BASE_BEAST_LEVEL);
        // Set the beast level to the adventurer level
        if (is_less_than_base_level == TRUE) {
            tempvar beast_level = adventurer_state.Level;
        } else {
            // once the adventurer exceeds base level, beast level will be random but centered around adventurers level
            tempvar beast_level = rnd_level_boost + (adventurer_state.Level - BASE_BEAST_LEVEL);
        }
        let Level = beast_level;
loothero commented 1 year ago

This is fixed but leaving this issue open until we have test cases to harden