/// <summary> /// Check completeness of last action on stack. /// </summary> public void CheckLastActionOnStack() { if (this.Count == 0) { return; } MagicAction ma = this.Peek() as MagicAction; if (ma == null) { return; } if (ma.CardSource != null) { if (ma.CardSource.Controler != engine.pp) { return; } } //Magic.CurrentGameWin.CursorVisible = true; if (!ma.IsComplete) { if (ma.remainingCost == CostTypes.Tap) { ma.remainingCost = null; ma.CardSource.Tap(); } else if ((engine.pp.AvailableManaOnTable + engine.pp.ManaPool) < ma.RemainingCost?.ManaCost) { Magic.AddLog("Not enough mana available"); CancelLastActionOnStack(); return; } else if (engine.pp.ManaPool != null && ma.RemainingCost?.ManaCost != null) { string lastRemCost = ma.RemainingCost.ToString(); ma.PayCost(ref engine.pp.ManaPool); bool skipUpdateUI = false; if (ma.RemainingCost != null) { if (string.Equals(ma.RemainingCost.ToString(), lastRemCost, StringComparison.Ordinal)) { skipUpdateUI = true; } } if (!skipUpdateUI) { engine.pp.NotifyValueChange("ManaPoolElements", engine.pp.ManaPoolElements); notifyStackElementChange(); } } // if (ma.IsComplete && ma.GoesOnStack) // GivePriorityToNextPlayer (); } if (ma.IsComplete) { if (ma.GoesOnStack) { //should show spell to player... //UpdateStackLayouting(); engine.GivePriorityToNextPlayer(); } else { PopMSE(); ma.Resolve(); } return; } engine.pp.UpdateUi(); // AbilityActivation aa = ma as AbilityActivation; // //mana doest go on stack // if (aa != null){ // if (aa.Source.AbilityType == AbilityEnum.Mana) { // MagicEvent (new AbilityEventArg (aa.Source, aa.CardSource)); // MagicStack.Pop; // return; // } // } }
public override void Process() { MagicEngine e = MagicEngine.CurrentEngine; switch (CurrentState) { case PlayerStates.Init: return; case PlayerStates.PlayDrawChoice: //chose to play first e.currentPlayerIndex = e.getPlayerIndex(this); CurrentState = PlayerStates.InitialDraw; return; case PlayerStates.InitialDraw: initialDraw(); CurrentState = PlayerStates.KeepMuliganChoice; return; case PlayerStates.KeepMuliganChoice: //choose to keep CurrentState = PlayerStates.Ready; e.RaiseMagicEvent(new MagicEventArg(MagicEventType.PlayerIsReady, this)); return; } if (e.pp != this || e.State < EngineStates.CurrentPlayer) { return; } if (HasActionPending) { ActivateAvailableMana(e); return; } if (e.cp == this) { switch (e.CurrentPhase) { case GamePhases.Untap: PhaseDone = true; break; case GamePhases.Upkeep: PhaseDone = true; break; case GamePhases.Draw: PhaseDone = true; break; case GamePhases.Main1: case GamePhases.Main2: if (AllowedLandsToBePlayed > 0) { if (AITryToPlayLand()) { break; } } if (!CastAvailableAndAllowedCreature()) { PhaseDone = true; } break; case GamePhases.BeforeCombat: PhaseDone = true; break; case GamePhases.DeclareAttacker: AITryToAttack(); PhaseDone = true; break; case GamePhases.DeclareBlocker: PhaseDone = true; break; case GamePhases.FirstStrikeDame: PhaseDone = true; break; case GamePhases.CombatDamage: PhaseDone = true; break; case GamePhases.EndOfCombat: PhaseDone = true; break; case GamePhases.EndOfTurn: PhaseDone = true; break; case GamePhases.CleanUp: PhaseDone = true; break; } } else { if (e.pp == this) { Magic.AddLog("AI just had priority"); e.GivePriorityToNextPlayer(); } // switch (e.CurrentPhase) // { // case GamePhases.Untap: // PhaseDone = true; // break; // case GamePhases.Upkeep: // PhaseDone = true; // break; // case GamePhases.Draw: // PhaseDone = true; // break; // case GamePhases.Main1: // PhaseDone = true; // break; // case GamePhases.BeforeCombat: // PhaseDone = true; // break; // case GamePhases.DeclareAttacker: // PhaseDone = true; // break; // case GamePhases.DeclareBlocker: // PhaseDone = true; // break; // case GamePhases.FirstStrikeDame: // PhaseDone = true; // break; // case GamePhases.CombatDamage: // PhaseDone = true; // break; // case GamePhases.EndOfCombat: // PhaseDone = true; // break; // case GamePhases.Main2: // PhaseDone = true; // break; // case GamePhases.EndOfTurn: // PhaseDone = true; // break; // case GamePhases.CleanUp: // PhaseDone = true; // break; // } } }