diff --git a/src/game.rs b/src/game.rs index 35b5e50..adeb5fd 100644 --- a/src/game.rs +++ b/src/game.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; use crate::{ game::{ - hand::Hand, + hand::{Hand, Pond}, player::{CurrentPlayer, MainPlayer}, round::{TurnState, Wind}, wall::Wall, @@ -27,6 +27,17 @@ pub enum GameState { #[derive(Message)] pub enum GameMessage { Discarded(Entity), + CallPending, + Called { player: Entity, calltype: Entity }, +} + +impl GameMessage { + pub(crate) fn is_called(&self) -> bool { + match self { + GameMessage::Called { .. } => true, + _ => false, + } + } } pub struct Riichi; @@ -47,10 +58,9 @@ impl Plugin for Riichi { .add_systems(OnEnter(TurnState::Menzen), round::menzen) .add_systems(Update, round::riichi_kan.run_if(in_state(TurnState::RiichiKan))) .add_systems(Update, round::discard.run_if(in_state(TurnState::Discard))) - .add_systems(Update, round::debug_discard.run_if(in_state(TurnState::Discard))) - .add_systems(Update, round::ron_chi_pon_kan.run_if(in_state(TurnState::RonChiiPonKan))) + .add_systems(OnEnter(TurnState::RonChiiPonKan), round::notify_callable) + .add_systems(Update, round::ron_chi_pon_kan.run_if(in_state(TurnState::RonChiiPonKan)).after(round::notify_callable)) .add_systems(OnEnter(TurnState::End), round::end) - // .add_systems(Update, systems) // semicolon stopper ; } @@ -73,6 +83,7 @@ pub(crate) fn setup( player, points, Hand, + Pond, Wind::from_repr((i - 1) as usize).unwrap(), ); diff --git a/src/game/hand.rs b/src/game/hand.rs index 0870043..9717d79 100644 --- a/src/game/hand.rs +++ b/src/game/hand.rs @@ -10,6 +10,9 @@ use crate::{ #[derive(Component)] pub struct Hand; +#[derive(Component)] +pub struct Pond; + #[derive(Component)] pub struct Drawn; diff --git a/src/game/round.rs b/src/game/round.rs index 698322e..4e35bb4 100644 --- a/src/game/round.rs +++ b/src/game/round.rs @@ -1,11 +1,13 @@ -use bevy::prelude::*; +use std::rc::Weak; + +use bevy::{platform::collections::HashMap, prelude::*}; use strum::{EnumCount, FromRepr}; use crate::{ EnumNextCycle, game::{ GameMessage, GameState, - hand::{Discarded, Drawn, Hand}, + hand::{Discarded, Drawn, Hand, Pond}, player::{CurrentPlayer, Player}, wall::Wall, }, @@ -58,6 +60,15 @@ pub(crate) enum TurnState { End, } +#[derive(Component, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub(crate) enum CallType { + Skip, + Ron, + Chii, + Pon, + Kan, +} + impl Default for MatchSettings { fn default() -> Self { Self { @@ -191,10 +202,45 @@ pub(crate) fn discard( Ok(()) } +#[derive(Resource)] +pub struct PendingCalls { + eligible: Vec, + calls: HashMap, +} + +pub(crate) fn notify_callable() {} + pub(crate) fn ron_chi_pon_kan( + mut commands: Commands, + mut reader: MessageReader, + + discarded: Single>, + mut ponds: Query<(&Children, Entity), (With, Without)>, + calls: Query<&CallType>, + curr_turnstate: Res>, mut next_turnstate: ResMut>, ) { + // check if can call? + // message players? + // collect then prioritize + + // let mut received = vec![]; + let mut received: Vec<_> = reader + .read() + .filter_map(|m| { + if let GameMessage::Called { player, calltype } = m + && let Ok(calltype) = calls.get(*calltype) + { + Some((calltype, player)) + } else { + None + } + }) + .collect(); + received.sort_unstable_by_key(|(c, t)| c); + // received.sort_unstable_by_key(|m| m.); + next_turnstate.set(curr_turnstate.next()); }