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

JON-475: add event in game #8

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/models/data/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct Beast {
}

#[derive(Copy, Drop, IntrospectPacked, Serde)]
#[dojo::event]
#[dojo::model]
struct PlayerBeast {
#[key]
Expand Down
1 change: 1 addition & 0 deletions src/models/data/challenge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct Challenge {
}

#[derive(Copy, Drop, IntrospectPacked, Serde)]
#[dojo::event]
#[dojo::model]
struct ChallengePlayer {
#[key]
Expand Down
18 changes: 18 additions & 0 deletions src/models/data/events.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,21 @@ struct ChallengeCompleted {
player_name: felt252,
game_id: u32
}

#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct BeastAttack {
#[key]
player: ContractAddress,
attack: u32
}

#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct PlayerAttack {
#[key]
player: ContractAddress,
attack: u32
}
13 changes: 7 additions & 6 deletions src/models/status/round/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use jokers_of_neon::constants::card::INVALID_CARD;
use jokers_of_neon::models::data::beast::{
GameModeBeast, GameModeBeastStore, Beast, BeastStore, PlayerBeast, PlayerBeastStore
};
use jokers_of_neon::models::data::events::{PlayWinGameEvent, PlayGameOverEvent};
use jokers_of_neon::models::data::events::{PlayWinGameEvent, PlayGameOverEvent, BeastAttack, PlayerAttack};
use jokers_of_neon::models::data::game_deck::{GameDeckImpl, GameDeck, GameDeckStore};
use jokers_of_neon::models::status::game::game::{Game, GameStore, GameState, GameSubState};
use jokers_of_neon::models::status::game::rage::{RageRound, RageRoundStore};
Expand Down Expand Up @@ -73,13 +73,13 @@ impl BeastImpl of BeastTrait {

let rage_round = RageRoundStore::get(world, game_id);

let score = play(world, ref game, @cards_index, @modifiers_index);
let attack = play(world, ref game, @cards_index, @modifiers_index);

let player_attack = score; // TODO:
emit!(world, (PlayerAttack { player: get_caller_address(), attack }));

let mut beast = BeastStore::get(world, game.id);
beast.health = if player_attack < beast.health {
beast.health - player_attack
beast.health = if attack < beast.health {
beast.health - attack
} else {
0
};
Expand Down Expand Up @@ -109,7 +109,7 @@ impl BeastImpl of BeastTrait {
_ => Option::None
}.unwrap();
IRageSystemDispatcher { contract_address: rage_system_address.try_into().unwrap() }.calculate(game.id);
// create_level(world, ref store, game); TODO:
// create_level(world, ref store, game); TODO:
} else if player_beast.energy.is_zero() {
_attack_beast(world, ref store, ref game, ref player_beast, ref beast, ref game_mode_beast);
} else {
Expand Down Expand Up @@ -242,6 +242,7 @@ fn _attack_beast(
ref beast: Beast,
ref game_mode_beast: GameModeBeast
) {
emit!(world, (BeastAttack { player: get_caller_address(), attack: beast.attack }));
game.player_hp = if beast.attack > game.player_hp {
0
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/models/status/round/challenge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl ChallengeImpl of ChallengeTrait {
} else {
let mut challenge_player = ChallengePlayerStore::get(world, game_id);
challenge_player.plays -= 1;
emit!(world, (challenge_player));
ChallengePlayerStore::set(@challenge_player, world);
}

Expand Down Expand Up @@ -117,6 +118,7 @@ impl ChallengeImpl of ChallengeTrait {

let mut challenge_player = ChallengePlayerStore::get(world, game_id);
challenge_player.discards -= 1;
emit!(world, (challenge_player));
ChallengePlayerStore::set(@challenge_player, world);

let game_deck = GameDeckStore::get(world, game_id);
Expand Down
20 changes: 10 additions & 10 deletions src/tests/test_game_play.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -649,48 +649,48 @@ mod test_rage_cards {
let round_after = store.get_round(game.id);
assert(round_after.player_score == 40, 'wrong round player_score');
}
// #[test]
// #[test]
// #[available_gas(30000000000000000)]
// fn test_play_rage_card_diminished_hold() {
// let (world, systems) = setup::spawn_game();
// let mut store = StoreTrait::new(world);
// let mut game = mock_game(ref store, PLAYER());
// mock_round(ref store, @game, 300);

// // Mock RageRound
// // Mock RageRound
// let len_hand_before = game.len_hand;
// mock_rage_round(world, game.id, array![RAGE_CARD_DIMINISHED_HOLD]);

// // Set game state in shop
// // Set game state in shop
// game.state = GameState::AT_SHOP;
// store.set_game(game);

// set_contract_address(PLAYER());
// set_contract_address(PLAYER());
// systems.shop_system.skip_shop(game.id);

// let game_after = store.get_game(game.id);
// let game_after = store.get_game(game.id);
// assert(game_after.len_hand == len_hand_before - 2, 'wrong game_after len_hand');
// }

// #[test]
// #[test]
// #[available_gas(30000000000000000)]
// fn test_play_rage_card_zero_waste() {
// let (world, systems) = setup::spawn_game();
// let mut store = StoreTrait::new(world);
// let mut game = mock_game(ref store, PLAYER());
// mock_round(ref store, @game, 300);

// // Mock RageRound
// // Mock RageRound
// mock_rage_round(world, game.id, array![RAGE_CARD_ZERO_WASTE]);

// // Set game state in shop
// // Set game state in shop
// game.state = GameState::AT_SHOP;
// store.set_game(game);

// set_contract_address(PLAYER());
// set_contract_address(PLAYER());
// systems.shop_system.skip_shop(game.id);

// let round = store.get_round(game.id);
// let round = store.get_round(game.id);
// assert(round.discard == 0, 'wrong round discard');
// }
}
Expand Down
18 changes: 6 additions & 12 deletions src/tests/test_game_play_beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ mod test_play_beast_special_cards {

// Mock hand
let hand_cards_ids = array![
SIX_CLUBS_ID,
QUEEN_CLUBS_ID,
FOUR_CLUBS_ID,
JACK_HEARTS_ID,
KING_DIAMONDS_ID,
MULTI_MODIFIER_1_ID
SIX_CLUBS_ID, QUEEN_CLUBS_ID, FOUR_CLUBS_ID, JACK_HEARTS_ID, KING_DIAMONDS_ID, MULTI_MODIFIER_1_ID
];
mock_current_hand_cards_ids(ref store, game.id, hand_cards_ids);

Expand Down Expand Up @@ -285,23 +280,23 @@ mod test_play_beast_special_cards {
player_beast_after.energy == player_beast_before.energy - game_mode_beast.cost_play, 'wrong player energy'
);
}
// #[test]
// #[test]
// #[available_gas(30000000000000000)]
// fn test_play_special_initial_advantage() {
// let (world, systems) = setup::spawn_game();
// let mut store = StoreTrait::new(world);
// let mut game = mock_game(ref store, PLAYER());
// mock_round(ref store, @game, 300);

// // Mock special card
// // Mock special card
// let special_cards_ids = array![SPECIAL_INITIAL_ADVANTAGE_ID];
// mock_special_cards(ref store, ref game, special_cards_ids);

// // Mock hand
// // Mock hand
// let hand_cards_ids = array![ACE_CLUBS_ID, ACE_HEARTS_ID, ACE_DIAMONDS_ID, ACE_SPADES_ID];
// mock_current_hand_cards_ids(ref store, game.id, hand_cards_ids);

// set_contract_address(PLAYER());
// set_contract_address(PLAYER());
// systems.game_system.play(game.id, array![0, 1, 2, 3], array![100, 100, 100, 100]);
// // Four of a Kind - points: 60, multi: 7
// // points: 11 + 11 + 11 + 11 + 100
Expand All @@ -318,8 +313,7 @@ mod test_play_beast_modifier_cards {
KING_SPADES_ID, TWO_SPADES_ID, TWO_DIAMONDS_ID, TWO_CLUBS_ID, FOUR_DIAMONDS_ID, FOUR_HEARTS_ID
};
use jokers_of_neon::constants::modifiers::{
MULTI_MODIFIER_1_ID, POINTS_MODIFIER_4_ID, MULTI_MODIFIER_4_ID, POINTS_MODIFIER_2_ID,
MULTI_MODIFIER_3_ID,
MULTI_MODIFIER_1_ID, POINTS_MODIFIER_4_ID, MULTI_MODIFIER_4_ID, POINTS_MODIFIER_2_ID, MULTI_MODIFIER_3_ID,
};
use jokers_of_neon::models::data::beast::{
GameModeBeast, GameModeBeastStore, Beast, BeastStore, PlayerBeast, PlayerBeastStore
Expand Down
Loading