A card game engine for TCGs, primarily Magic: The Gathering but with support for others
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Filling out the rest of the managrove-core crate from older code

+108 -5
+35 -3
managrove-core/src/game/card.rs
··· 1 1 use uuid::Uuid; 2 2 3 + use crate::game::{player::PlayerId, state::GameState}; 4 + 3 5 pub struct CardDefId(Uuid); 4 6 pub struct CardId(Uuid); 5 7 6 8 pub struct Card { 7 - // TODO 9 + id: CardDefId, 10 + name: String, 11 + cost: Cost, 12 + attack: Option<i32>, 13 + defense: Option<i32>, 14 + text: String 8 15 } 9 16 10 17 pub struct CardInstance { 11 - // TODO 12 - } 18 + id: CardId, 19 + source: CardDefId, 20 + current_attack: Option<i32>, 21 + current_defense: Option<i32> 22 + } 23 + 24 + pub enum Mana { 25 + Black(i32), 26 + Blue(i32), 27 + Green(i32), 28 + Red(i32), 29 + White(i32), 30 + Colorless(i32) 31 + } 32 + 33 + pub struct Cost(Vec<Mana>); 34 + pub type ManaPool = Vec<Mana>; 35 + 36 + impl Cost { 37 + fn can_pay(&self, _state: &GameState, _player: PlayerId, _source: CardId) -> bool { 38 + false 39 + } 40 + 41 + fn pay(&self, _state: &mut GameState, _player: PlayerId, _source: CardId) { 42 + 43 + } 44 + }
+41 -1
managrove-core/src/game/player.rs
··· 1 1 use uuid::Uuid; 2 + use crate::game::{card::ManaPool, zone::{Zone, ZoneId, ZoneVisibility}}; 3 + use std::collections::HashMap; 2 4 5 + #[derive(Clone)] 3 6 pub struct PlayerId(Uuid); 4 7 5 8 pub struct Player { 6 - // TODO 9 + id: PlayerId, 10 + name: String, 11 + life: i32, 12 + hand: ZoneId, 13 + library: ZoneId, 14 + graveyard: ZoneId, 15 + battlefield: ZoneId, 16 + exile: ZoneId, 17 + status_counters: HashMap<String, i32>, 18 + mana: ManaPool 19 + } 20 + 21 + impl Player { 22 + pub fn new(id: PlayerId, name: String, zones: &mut HashMap<ZoneId, Zone>, namespace_uuid: &Uuid) -> Self { 23 + let hand_zone_id = ZoneId::new(format!("{}-{}", name, "hand"), namespace_uuid); 24 + zones.insert(hand_zone_id.clone(), Zone::new(String::from("Hand"), id.clone(), hand_zone_id.clone(), ZoneVisibility::Player)); 25 + let library_zone_id = ZoneId::new(format!("{}-{}", name, "library"), namespace_uuid); 26 + zones.insert(library_zone_id.clone(), Zone::new(String::from("Library"), id.clone(), library_zone_id.clone(), ZoneVisibility::Hidden)); 27 + let graveyard_zone_id = ZoneId::new(format!("{}-{}", name, "graveyard"), namespace_uuid); 28 + zones.insert(graveyard_zone_id.clone(), Zone::new(String::from("Graveyard"), id.clone(), graveyard_zone_id.clone(), ZoneVisibility::All)); 29 + let battlefield_zone_id = ZoneId::new(format!("{}-{}", name, "battlefield"), namespace_uuid); 30 + zones.insert(battlefield_zone_id.clone(), Zone::new(String::from("Battlefield"), id.clone(), battlefield_zone_id.clone(), ZoneVisibility::All)); 31 + let exile_zone_id = ZoneId::new(format!("{}-{}", name, "exile"), namespace_uuid); 32 + zones.insert(exile_zone_id.clone(), Zone::new(String::from("Exile"), id.clone(), exile_zone_id.clone(), ZoneVisibility::All)); 33 + 34 + Self { 35 + id, 36 + name, 37 + life: 0, 38 + hand: hand_zone_id, 39 + library: library_zone_id, 40 + graveyard: graveyard_zone_id, 41 + battlefield: battlefield_zone_id, 42 + exile: exile_zone_id, 43 + status_counters: HashMap::new(), 44 + mana: Vec::new() 45 + } 46 + } 7 47 }
+32 -1
managrove-core/src/game/zone.rs
··· 1 1 use uuid::Uuid; 2 2 3 + use crate::game::{player::PlayerId, card::CardId}; 4 + 5 + #[derive(Clone, Hash, Eq, PartialEq)] 3 6 pub struct ZoneId(Uuid); 7 + 8 + impl ZoneId { 9 + pub fn new(name: String, namespace_uuid: &Uuid) -> Self { 10 + Self(Uuid::new_v5(namespace_uuid, name.as_bytes())) 11 + } 12 + } 4 13 5 14 pub struct Zone { 6 - // TODO 15 + id: ZoneId, 16 + owner: PlayerId, 17 + cards: Vec<CardId>, 18 + name: String, 19 + visibility: ZoneVisibility 20 + } 21 + 22 + impl Zone { 23 + pub fn new(name: String, owner: PlayerId, id: ZoneId, visibility: ZoneVisibility) -> Self { 24 + Self { 25 + id, 26 + owner, 27 + name, 28 + visibility, 29 + cards: Vec::new() 30 + } 31 + } 32 + } 33 + 34 + pub enum ZoneVisibility { 35 + Player, 36 + Hidden, 37 + All 7 38 }