Skip to content

Commit

Permalink
integrate aventurer
Browse files Browse the repository at this point in the history
  • Loading branch information
dpinones committed Nov 2, 2024
1 parent 8039958 commit 7779915
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/models/status/game/game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ enum GameSubState {
DRAFT_MODIFIERS,
DRAFT_SPECIALS,
DRAFT_DECK,
DRAFT_ADVENTURER
DRAFT_ADVENTURER,
DRAFT_ADVENTURER_CARDS
}

#[derive(Serde, Copy, Drop, IntrospectPacked, PartialEq)]
Expand Down
47 changes: 47 additions & 0 deletions src/systems/game_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ trait IGameSystem {
fn discard_effect_card(ref world: IWorldDispatcher, game_id: u32, card_index: u32);
fn discard_special_card(ref world: IWorldDispatcher, game_id: u32, special_card_index: u32);
fn use_adventurer(ref world: IWorldDispatcher, game_id: u32, adventurer_id: u32);
fn skip_adventurer(ref world: IWorldDispatcher, game_id: u32);
fn select_aventurer_cards(ref world: IWorldDispatcher, game_id: u32, cards_index: Array<u32>);
}

mod errors {
Expand All @@ -40,6 +42,7 @@ mod errors {
const WRONG_SUBSTATE_DRAFT_SPECIALS: felt252 = 'Wrong substate DRAFT_SPECIALS';
const WRONG_SUBSTATE_SELECT_REWARD: felt252 = 'Wrong substate SELECT_REWARD';
const WRONG_SUBSTATE_DRAFT_ADVENTURER: felt252 = 'Wrong substate SELECT_ADVENTURE';
const WRONG_SUBSTATE_ADVENTURER_CARDS: felt252 = 'Wrong substate SELECT_ADV_CARDS';
}

#[dojo::contract]
Expand Down Expand Up @@ -300,6 +303,50 @@ mod game_system {

AdventurerTrait::use_adventurer(world, adventurer_id, ref game);

game.substate = GameSubState::DRAFT_ADVENTURER_CARDS;
store.set_game(game);

let cards = open_blister_pack(world, ref store, game, SPECIAL_CARDS_PACK_ID);
let blister_pack_result = BlisterPackResult { game_id, cards_picked: false, cards };
emit!(world, (blister_pack_result));
store.set_blister_pack_result(blister_pack_result);
}

fn skip_adventurer(ref world: IWorldDispatcher, game_id: u32) {
let mut store: Store = StoreTrait::new(world);

let mut game = store.get_game(game_id);
// Check that the game exists (if the game has no owner means it does not exists)
assert(game.owner.is_non_zero(), errors::GAME_NOT_FOUND);

// Check that the owner of the game is the caller
assert(game.owner == get_caller_address(), errors::CALLER_NOT_OWNER);

// Check that the status of the game
assert(game.substate == GameSubState::DRAFT_ADVENTURER, errors::WRONG_SUBSTATE_DRAFT_ADVENTURER);

game.substate = GameSubState::DRAFT_DECK;
store.set_game(game);
}

fn select_aventurer_cards(ref world: IWorldDispatcher, game_id: u32, cards_index: Array<u32>) {
let mut store: Store = StoreTrait::new(world);

let mut game = store.get_game(game_id);
// Check that the game exists (if the game has no owner means it does not exists)
assert(game.owner.is_non_zero(), errors::GAME_NOT_FOUND);

// Check that the owner of the game is the caller
assert(game.owner == get_caller_address(), errors::CALLER_NOT_OWNER);

// Check that the status of the game
assert(game.substate == GameSubState::DRAFT_ADVENTURER_CARDS, errors::WRONG_SUBSTATE_ADVENTURER_CARDS);

let mut blister_pack_result = store.get_blister_pack_result(game.id);
assert(cards_index.len() <= 2, errors::INVALID_CARD_INDEX_LEN);

select_cards_from_blister(world, ref game, blister_pack_result.cards, cards_index);

game.substate = GameSubState::DRAFT_DECK;
store.set_game(game);
}
Expand Down

0 comments on commit 7779915

Please sign in to comment.