diff --git a/src/interfaces/IActions.cairo b/src/interfaces/IActions.cairo index b585b80..3101516 100644 --- a/src/interfaces/IActions.cairo +++ b/src/interfaces/IActions.cairo @@ -28,7 +28,7 @@ pub trait IActions { // Board spaces retrieval fn get_property(self: @T, id: u8, game_id: u256) -> Property; - + 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; @@ -103,6 +103,4 @@ pub trait IActions { ref self: T, from: GamePlayer, to: GamePlayer, amount: u256, ) -> Array; fn mint(ref self: T, recepient: ContractAddress, game_id: u256, amount: u256); - - } diff --git a/src/model/property_model.cairo b/src/model/property_model.cairo index d653834..db9c272 100644 --- a/src/model/property_model.cairo +++ b/src/model/property_model.cairo @@ -130,12 +130,10 @@ pub trait PropertyTrait { fn change_game_property_ownership( ref self: Property, new_owner: ContractAddress, owner: ContractAddress, ) -> bool; - } impl PropertyImpl of PropertyTrait { - fn new( id: u8, game_id: u256, diff --git a/src/systems/actions.cairo b/src/systems/actions.cairo index 7b49b5b..6247f22 100644 --- a/src/systems/actions.cairo +++ b/src/systems/actions.cairo @@ -129,7 +129,6 @@ pub mod actions { ); } - fn get_property(self: @ContractState, id: u8, game_id: u256) -> Property { let world = self.world_default(); @@ -137,7 +136,7 @@ pub mod actions { property } - + fn start_game(ref self: ContractState, game_id: u256) -> bool { let mut world = self.world_default(); let mut game: Game = world.read_model(game_id); @@ -2002,61 +2001,56 @@ pub mod actions { ); } - fn vote_to_kick_player(ref self: ContractState, game_id: u256, target_player: ContractAddress) { - let mut world = self.world_default(); - let caller = get_caller_address(); - - // Ensure caller is not voting for himself - assert!(caller != target_player, "You can't vote to kick yourself"); - - // Load target and caller players - let mut target: GamePlayer = world.read_model((target_player, game_id)); - let caller_player: GamePlayer = world.read_model((caller, game_id)); - - // Ensure both are in the same game - assert!(target.game_id == game_id, "Not same game"); - - // Increase strike (can also implement vote tracking to prevent multiple votes) - target.strikes += 1; + fn vote_to_kick_player( + ref self: ContractState, game_id: u256, target_player: ContractAddress, + ) { + let mut world = self.world_default(); + let caller = get_caller_address(); - // Save updated target player - world.write_model(@target); + // Ensure caller is not voting for himself + assert!(caller != target_player, "You can't vote to kick yourself"); - // Count total players - let game: Game = world.read_model(game_id); - let total_players: u8 = game.number_of_players; - let strike_percent = (target.strikes * 100) / total_players; + // Load target and caller players + let mut target: GamePlayer = world.read_model((target_player, game_id)); + let caller_player: GamePlayer = world.read_model((caller, game_id)); - + // Ensure both are in the same game + assert!(target.game_id == game_id, "Not same game"); - // Kick if strikes >= 70% - if strike_percent >= 70 { - + // Increase strike (can also implement vote tracking to prevent multiple votes) + target.strikes += 1; - // Transfer all properties to the bank - let bank = get_contract_address(); - let mut i = 0; - while i < target.properties_owned.len() { - let prop_id = *target.properties_owned.at(i); - let mut property: Property = world.read_model((prop_id, game_id)); - property.owner = bank; - world.write_model(@property); - i += 1; - }; + // Save updated target player + world.write_model(@target); - // Clear player data - target.properties_owned = array![]; - target.balance = 0; - target.strikes = 0; - // target.has_left = true; + // Count total players + let game: Game = world.read_model(game_id); + let total_players: u8 = game.number_of_players; + let strike_percent = (target.strikes * 100) / total_players; - // Save updated player - world.write_model(@target); + // Kick if strikes >= 70% + if strike_percent >= 70 { + // Transfer all properties to the bank + let bank = get_contract_address(); + let mut i = 0; + while i < target.properties_owned.len() { + let prop_id = *target.properties_owned.at(i); + let mut property: Property = world.read_model((prop_id, game_id)); + property.owner = bank; + world.write_model(@property); + i += 1; + }; - - } -} + // Clear player data + target.properties_owned = array![]; + target.balance = 0; + target.strikes = 0; + // target.has_left = true; + // Save updated player + world.write_model(@target); + } + } } #[generate_trait] diff --git a/src/tests/test_world.cairo b/src/tests/test_world.cairo index 54580c2..9a7926c 100644 --- a/src/tests/test_world.cairo +++ b/src/tests/test_world.cairo @@ -28,7 +28,7 @@ mod tests { TradeCounter, m_TradeCounter, TradeOfferDetails, m_TradeOfferDetails, TradeOffer, TradeStatus, }; - + use starknet::{testing, get_caller_address, contract_address_const}; fn namespace_def() -> NamespaceDef {