From 20eaafaeca02100755c826375e9bbdc0096b7237 Mon Sep 17 00:00:00 2001 From: dub_zn Date: Sun, 3 Nov 2024 18:06:48 -0300 Subject: [PATCH 1/3] add replay-logic --- src/models/status/round/challenge.cairo | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/models/status/round/challenge.cairo b/src/models/status/round/challenge.cairo index 938f137..ab5782f 100644 --- a/src/models/status/round/challenge.cairo +++ b/src/models/status/round/challenge.cairo @@ -54,7 +54,7 @@ impl ChallengeImpl of ChallengeTrait { ChallengeStore::set(@challenge, world); emit!(world, (challenge)); - let challenge_player = ChallengePlayer { game_id, discards: 5, plays: 5 }; + let challenge_player = ChallengePlayer { game_id, discards: game.max_discard, plays: game.max_hands }; ChallengePlayerStore::set(@challenge_player, world); emit!(world, (challenge_player)); @@ -93,13 +93,25 @@ impl ChallengeImpl of ChallengeTrait { } else { challenge_player.plays -= 1; emit!(world, (challenge_player)); - ChallengePlayerStore::set(@challenge_player, world); if challenge_player.plays.is_zero() { - let play_game_over_event = PlayGameOverEvent { player: get_caller_address(), game_id: game.id }; - emit!(world, (play_game_over_event)); - game.state = GameState::FINISHED; + 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 }; + emit!(world, (play_game_over_event)); + game.state = GameState::FINISHED; + return; + } + challenge_player.discards = game.max_discard; + challenge_player.plays = game.max_hands; + + ChallengePlayerStore::set(@challenge_player, world); + emit!(world, (challenge_player)); GameStore::set(@game, world); - return; } let mut cards = array![]; From 4fe3c56447f696ff85dbc45d334ad027b4b93d6e Mon Sep 17 00:00:00 2001 From: dub_zn Date: Sun, 3 Nov 2024 18:52:25 -0300 Subject: [PATCH 2/3] 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 }; From 2b087bd482e556fc2844f3a5e842cf0c8f523ccf Mon Sep 17 00:00:00 2001 From: dub_zn Date: Sun, 3 Nov 2024 19:46:40 -0300 Subject: [PATCH 3/3] fix event --- src/models/status/round/beast.cairo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models/status/round/beast.cairo b/src/models/status/round/beast.cairo index 346b328..7f8f00f 100644 --- a/src/models/status/round/beast.cairo +++ b/src/models/status/round/beast.cairo @@ -250,15 +250,15 @@ fn _attack_beast( ref beast: Beast, ref game_mode_beast: GameModeBeast ) { - emit!(world, (BeastAttack { player: get_caller_address(), attack: 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 }; + emit!(world, (BeastAttack { player: get_caller_address(), attack: beast_dmg })); if game.current_player_hp.is_zero() { let play_game_over_event = PlayGameOverEvent { player: get_caller_address(), game_id: game.id };