Skip to content
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
33 changes: 32 additions & 1 deletion src/interfaces/IActions.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dojo_starter::model::game_model::{GameType, Game};
use dojo_starter::model::game_player_model::{PlayerSymbol, GamePlayer};
use dojo_starter::model::player_model::Player;
use dojo_starter::model::property_model::Property;
use dojo_starter::model::property_model::{Property, TradeOffer, TradeOfferDetails};
use dojo_starter::model::utility_model::Utility;
use dojo_starter::model::rail_road_model::RailRoad;
use dojo_starter::model::community_chest_model::CommunityChest;
Expand Down Expand Up @@ -42,10 +42,41 @@ pub trait IActions<T> {
fn get_community_chest(self: @T, id: u8, game_id: u256) -> CommunityChest;
fn get_railroad(self: @T, id: u8, game_id: u256) -> RailRoad;
fn get_tax(self: @T, id: u8, game_id: u256) -> Tax;
fn use_getout_of_jail_chance(ref self: T, game_id: u256) -> bool;
fn use_getout_of_jail_community_chest(ref self: T, game_id: u256) -> bool;

fn offer_trade(
ref self: T,
game_id: u256,
to: ContractAddress,
offered_property_ids: Array<u8>,
requested_property_ids: Array<u8>,
cash_offer: u256,
cash_request: u256,
trade_type: TradeOffer,
) -> u256;

fn accept_trade(ref self: T, trade_id: u256, game_id: u256) -> bool;

fn reject_trade(ref self: T, trade_id: u256, game_id: u256) -> bool;

fn counter_trade(
ref self: T,
game_id: u256,
original_offer_id: u256,
offered_property_ids: Array<u8>,
requested_property_ids: Array<u8>,
cash_offer: u256,
cash_request: u256,
trade_type: TradeOffer,
) -> u256;
fn approve_counter_trade(ref self: T, trade_id: u256) -> bool;
fn get_trade(self: @T, trade_id: u256) -> TradeOfferDetails;

// Dice & player movement
fn roll_dice(ref self: T) -> (u8, u8);
fn move_player(ref self: T, game_id: u256, steps: u8) -> u8;
fn pay_jail_fine(ref self: T, game_id: u256) -> bool;
// fn handle_chance(ref self: T, game_id: u256, random_index: u32) -> @ByteArray;

// Handling landings on board
Expand Down
2 changes: 2 additions & 0 deletions src/model/game_player_model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct GamePlayer {
pub no_section8: u8,
pub is_bankrupt: bool,
pub is_active: bool,
pub jail_turns: u8,
}


Expand Down Expand Up @@ -78,6 +79,7 @@ impl GamePlayerImpl of GamePlayerTrait {
no_section6: 0,
no_section7: 0,
no_section8: 0,
jail_turns: 0,
}
}

Expand Down
75 changes: 75 additions & 0 deletions src/model/property_model.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
use starknet::{ContractAddress, contract_address_const};

#[derive(Serde, Copy, Drop, Introspect, PartialEq)]
#[dojo::model]
pub struct TradeCounter {
#[key]
pub id: felt252,
pub current_val: u256,
}

#[derive(Clone, Drop, Serde)]
#[dojo::model]
pub struct TradeOfferDetails {
#[key]
pub id: u256,
pub from: ContractAddress,
pub to: ContractAddress,
pub game_id: u256,
pub offered_property_ids: Array<u8>,
pub requested_property_ids: Array<u8>,
pub cash_offer: u256,
pub cash_request: u256,
pub trade_type: TradeOffer,
pub status: TradeStatus,
pub is_countered: bool,
pub approve_counter: bool,
}
#[derive(Copy, Drop, Serde)]
#[dojo::model]
pub struct Property {
Expand Down Expand Up @@ -38,6 +63,27 @@ pub enum PropertyType {
VisitingJail,
}

#[derive(Serde, Copy, Drop, Introspect, PartialEq, Debug)]
pub enum TradeOffer {
PropertyForProperty,
PropertyForCash,
CashForProperty,
CashPlusPropertyForProperty,
PropertyForCashPlusProperty,
CashForChanceJailCard,
CashForCommunityJailCard,
CommunityJailCardForCash,
ChanceJailCardForCash,
}

#[derive(Serde, Copy, Drop, Introspect, PartialEq, Debug)]
pub enum TradeStatus {
Accepted,
Rejected,
Pending,
Countered,
}


#[derive(Drop, Copy, Serde)]
#[dojo::model]
Expand Down Expand Up @@ -84,10 +130,39 @@ pub trait PropertyTrait {
fn change_game_property_ownership(
ref self: Property, new_owner: ContractAddress, owner: ContractAddress,
) -> bool;
// fn property_transfer(
// initiator_property: Property, initiator: GamePlayer, receiver: GamePlayer,
// ) -> (GamePlayer, GamePlayer, Property);
}


impl PropertyImpl of PropertyTrait {
// fn property_transfer(
// mut initiator_property: Property, mut initiator: GamePlayer, mut receiver: GamePlayer,
// ) -> (GamePlayer, GamePlayer, Property) {
// assert(initiator_property.game_id == receiver.game_id, 'Not in the same Game');

// // Update the property owner
// initiator_property.owner = receiver.address;

// // Build a new properties array for initiator excluding the transferred property
// let mut new_properties = array![];
// let mut i = 0;
// while (i < initiator.properties_owned.len()) {
// let prop = initiator.properties_owned[i];
// if prop.property_id != initiator_property.property_id {
// new_properties.append(prop);
// }
// i += 1;
// };
// initiator.properties_owned = new_properties;

// // Add the property to receiver's properties
// receiver.properties_owned.append(initiator_property);

// (initiator, receiver, initiator_property)
// }

fn new(
id: u8,
game_id: u256,
Expand Down
Loading
Loading