public void ProcessPushDestination(int selectedNodeId) { bool guestPush = (ActionNumber == 3 || ActionNumber == 4) && SubActionNumber == 6; bool guestCounterPush = (ActionNumber == 1 || ActionNumber == 2) && SubActionNumber == 7; bool hostPush = (ActionNumber == 1 || ActionNumber == 2) && SubActionNumber == 6; bool hostCounterPush = (ActionNumber == 3 || ActionNumber == 4) && SubActionNumber == 7; Monster pushedMonster; if (hostPush) { pushedMonster = GuestMonsters.Single(m => m.CurrentNode.Id == SelectedAttackNode.Id); } else if (hostCounterPush) { pushedMonster = GuestMonsters.Single(m => m.CurrentNode.Id == SelectedMonster.CurrentNode.Id); } else if (guestPush) { pushedMonster = HostMonsters.Single(m => m.CurrentNode.Id == SelectedAttackNode.Id); } else if (guestCounterPush) { pushedMonster = HostMonsters.Single(m => m.CurrentNode.Id == SelectedMonster.CurrentNode.Id); } else { SubActionNumber = 0; return; } Node selectedNode = GameGraph.Nodes[selectedNodeId]; pushedMonster.CurrentNode = selectedNode; int[] pathToDestination = { selectedNode.Id }; SubActionNumber = 0; _hostServer.SendToAll(CustomMessageTypes.PushDestinationResponse, new PushDestinationResponseMessage { ActionNumber = ActionNumber, SubActionNumber = SubActionNumber, DestinationNodeId = selectedNodeId, PushedMonsterTypeId = pushedMonster.MonsterTypeId, PathToDestinationNodeIds = pathToDestination }); }
public void ProcessAttackAction(int attackingMonsterTypeId, int defendingMonsterTypeId) { Monster attacker; Monster defender; bool isHostAttacker = ActionNumber == 1 || ActionNumber == 2; if (isHostAttacker) { attacker = HostMonsters.Single(m => m.MonsterTypeId == attackingMonsterTypeId); defender = GuestMonsters.Single(m => m.MonsterTypeId == defendingMonsterTypeId); } else { attacker = GuestMonsters.Single(m => m.MonsterTypeId == attackingMonsterTypeId); defender = HostMonsters.Single(m => m.MonsterTypeId == defendingMonsterTypeId); } AttackResult attackResult = AttackCalculator.Calculate(attacker.AttackRating, defender.DefenseRating); IEnumerable <Node> friendlyOccupiedNodes = HostMonsters.Select(monster => monster.CurrentNode).ToList(); IEnumerable <Node> enemyOccupiedNodes = GuestMonsters.Select(monster => monster.CurrentNode).ToList(); switch (attackResult) { case AttackResult.Kill: if (isHostAttacker) { GuestMonsters.Remove(defender); } else { HostMonsters.Remove(defender); } SubActionNumber = 0; _hostServer.SendToAll(CustomMessageTypes.AttackKillResponse, new AttackKillResponseMessage { ActionNumber = ActionNumber, SubActionNumber = SubActionNumber, AttackingMonsterTypeId = attackingMonsterTypeId, DefendingMonsterTypeId = defendingMonsterTypeId, AttackResultId = (int)AttackResult.Kill, Message = "Kill" }); break; case AttackResult.CounterKill: if (isHostAttacker) { HostMonsters.Remove(attacker); } else { GuestMonsters.Remove(attacker); } SelectedMonster = null; SubActionNumber = 0; _hostServer.SendToAll(CustomMessageTypes.AttackKillResponse, new AttackKillResponseMessage { ActionNumber = ActionNumber, SubActionNumber = SubActionNumber, AttackingMonsterTypeId = attackingMonsterTypeId, DefendingMonsterTypeId = defendingMonsterTypeId, AttackResultId = (int)AttackResult.CounterKill, Message = "Counter Kill" }); break; case AttackResult.Push: AvailablePushDestinations = MoveCalculator.FindMoves(defender.CurrentNode, 1, friendlyOccupiedNodes.Union(enemyOccupiedNodes)).Select(m => m.DestinationNode); if (!AvailablePushDestinations.Any()) { SubActionNumber = 0; _hostServer.SendToAll(CustomMessageTypes.GameState, new GameStateMessage { ActionNumber = ActionNumber, SubActionNumber = SubActionNumber, Message = "No available push destinations.", HostMonsterState = JsonConvert.SerializeObject(HostMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)), GuestMonsterState = JsonConvert.SerializeObject(GuestMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)) }); } else { SubActionNumber = 6; _hostServer.SendToAll(CustomMessageTypes.AttackPushResponse, new AttackPushResponseMessage { ActionNumber = ActionNumber, SubActionNumber = SubActionNumber, AttackingMonsterTypeId = attackingMonsterTypeId, DefendingMonsterTypeId = defendingMonsterTypeId, AvailablePushDestinationIds = AvailablePushDestinations.Select(d => d.Id).ToArray(), AttackResultId = (int)AttackResult.Push, Message = "Push" }); } break; case AttackResult.CounterPush: AvailablePushDestinations = MoveCalculator.FindMoves(attacker.CurrentNode, 1, friendlyOccupiedNodes.Union(enemyOccupiedNodes)).Select(m => m.DestinationNode); if (!AvailablePushDestinations.Any()) { SubActionNumber = 0; _hostServer.SendToAll(CustomMessageTypes.GameState, new GameStateMessage { ActionNumber = ActionNumber, SubActionNumber = SubActionNumber, Message = "No available push destinations.", HostMonsterState = JsonConvert.SerializeObject(HostMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)), GuestMonsterState = JsonConvert.SerializeObject(GuestMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)) }); } else { SubActionNumber = 7; _hostServer.SendToAll(CustomMessageTypes.AttackPushResponse, new AttackPushResponseMessage { ActionNumber = ActionNumber, SubActionNumber = SubActionNumber, AttackingMonsterTypeId = attackingMonsterTypeId, DefendingMonsterTypeId = defendingMonsterTypeId, AvailablePushDestinationIds = AvailablePushDestinations.Select(d => d.Id).ToArray(), AttackResultId = (int)AttackResult.CounterPush, Message = "Counter Push" }); } break; default: throw new ArgumentOutOfRangeException(); } }