public override void Visit(AttackPlayerAction action) { Player target = GameManager.GetPlayer(action.Target.Character); Player caller = GameManager.GetPlayer(action.Caller); CreatureCard playedCard = (CreatureCard)(caller.GetCardFromId(action.PlayedCardId, Place.INNER) ?? caller.GetCardFromId(action.PlayedCardId, Place.OUTER)); playedCard.Energy -= playedCard.Attack.Cost; AttacksVisitor attackVisitor = new AttacksVisitor(GameManager, caller, action.Target, playedCard); int attackPower = playedCard.Attack.Visit(attackVisitor); target.Health -= attackPower; foreach (CharacterEnum dest in GameManager.UserDict.Keys.ToList()) { GameManager.UserDict[dest].Write(new ResponseMessage(new AttackPlayerResponse(action.Caller, action.Target.Character, playedCard, target.Health))); } foreach (KeyValuePair <CharacterEnum, Response> kvp in attackVisitor.SuccessiveResponse) { GameManager.UserDict[kvp.Key].Write(new ResponseMessage(kvp.Value)); } if (!target.IsAlive) { GameManager.KillPlayer(caller.Character, target.Character); } }
public override void Visit(UseAbilityAction action) { GameManager.PlayersAliveBeforeAction = GameManager.UserDict.Keys.ToList().Where(c => GameManager.GetPlayer(c).IsAlive).ToList(); Player caller = GameManager.GetPlayer(action.Caller); CreatureCard playedCard = (CreatureCard)(caller.GetCardFromId(action.PlayedCardId, Place.INNER) ?? caller.GetCardFromId(action.PlayedCardId, Place.OUTER)); playedCard.Energy -= playedCard.Ability.Cost; AttacksVisitor attackVisitor = new AttacksVisitor(GameManager, caller, null, playedCard); if (action.Targets == null) { playedCard.Visit(attackVisitor, caller.Character, playedCard.Ability); } else { attackVisitor.Targets = action.Targets; playedCard.Visit(attackVisitor, caller.Character, playedCard.Ability); } foreach (KeyValuePair <CharacterEnum, Response> kvp in attackVisitor.SuccessiveResponse) { //Log("Player " + kvp.Key.ToString() + " recieved a successive response"); GameManager.UserDict[kvp.Key].Write(new ResponseMessage(kvp.Value)); } foreach (CharacterEnum c in GameManager.UserDict.Keys) { GameManager.UserDict[c].Write(new ResponseMessage(new CardsModifiedResponse(playedCard))); } // visitor must take care of players which he kills foreach (CharacterEnum ch in GameManager.PlayersAliveBeforeAction) { if (!GameManager.GetPlayer(ch).IsAlive) { GameManager.KillPlayer(caller.Character, ch); } } }