From 4fe3c56447f696ff85dbc45d334ad027b4b93d6e Mon Sep 17 00:00:00 2001 From: dub_zn Date: Sun, 3 Nov 2024 18:52:25 -0300 Subject: [PATCH] Re-scale beast stats --- src/models/status/round/beast.cairo | 48 +++++++++++++++++-------- src/models/status/round/challenge.cairo | 12 ++++--- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/models/status/round/beast.cairo b/src/models/status/round/beast.cairo index 938b002..346b328 100644 --- a/src/models/status/round/beast.cairo +++ b/src/models/status/round/beast.cairo @@ -251,13 +251,14 @@ fn _attack_beast( ref game_mode_beast: GameModeBeast ) { emit!(world, (BeastAttack { player: get_caller_address(), attack: beast.attack })); - game - .current_player_hp = - if beast.attack > game.current_player_hp { - 0 - } else { - game.current_player_hp - beast.attack - }; + let mut randomizer = RandomImpl::new(world); + let beast_dmg = randomizer.between::(0, 5 * game.level) + beast.attack; + + game.current_player_hp = if beast_dmg > game.current_player_hp { + 0 + } else { + game.current_player_hp - beast_dmg + }; if game.current_player_hp.is_zero() { let play_game_over_event = PlayGameOverEvent { player: get_caller_address(), game_id: game.id }; @@ -286,12 +287,31 @@ fn _create_beast(world: IWorldDispatcher, game_id: u32, level: u8) { } fn _generate_stats(level: u8) -> (u8, u32, u32) { // tier, health, attack - match level { - 0 => (0, 0, 0), - 1 => (1, 300, 15), - 2 => (1, 600, 25), - 3 => (1, 900, 35), - 4 => (1, 1200, 45), - _ => (2, 2000, 50), + if level <= 4 { + (0, _calculate_beast_hp(level), 10) + } else if level <= 8 { + (2, _calculate_beast_hp(level), 20) + } else if level <= 12 { + (3, _calculate_beast_hp(level), 30) + } else if level <= 16 { + (4, _calculate_beast_hp(level), 40) + } else { + (5, _calculate_beast_hp(level), 50) + } +} + +fn _calculate_beast_hp(level: u8) -> u32 { + if level <= 2 { + 300 * level + } else if level <= 10 { + 600 * level - 600 + } else if level <= 20 { + 1200 * level - 6600 + } else if level <= 25 { + 3000 * level - 42600 + } else if level <= 30 { + 7000 * level - 142600 + } else { + 20000 * level - 532600 } } diff --git a/src/models/status/round/challenge.cairo b/src/models/status/round/challenge.cairo index ab5782f..262e0e1 100644 --- a/src/models/status/round/challenge.cairo +++ b/src/models/status/round/challenge.cairo @@ -94,11 +94,13 @@ impl ChallengeImpl of ChallengeTrait { challenge_player.plays -= 1; emit!(world, (challenge_player)); if challenge_player.plays.is_zero() { - game.current_player_hp = if game.current_player_hp <= 5 * game.level { - 0 - } else { - game.current_player_hp - 5 * game.level - }; + game + .current_player_hp = + if game.current_player_hp <= 5 * game.level { + 0 + } else { + game.current_player_hp - 5 * game.level + }; if game.current_player_hp.is_zero() { let play_game_over_event = PlayGameOverEvent { player: get_caller_address(), game_id: game.id };