private static void DoUpdateLocation(IHommRobot actor, Location newLocation) { actor.World.Round.Update(actor.Player, newLocation); if (actor.Player.HasNoArmy()) { actor.Die(); } }
private void Resolve(HommWorld world, IHommRobot first, IHommRobot second) { var currentTime = world.Clocks.CurrentTime; var combatDuration = HommRules.Current.CombatDuration; var firstAvailable = combatQueue.ContainsKey(first) ? combatQueue[first] : currentTime; var otherAvailable = combatQueue.ContainsKey(second) ? combatQueue[second] : currentTime; var thisCombatStart = Math.Max(firstAvailable, otherAvailable); var thisCombatEnd = combatQueue[first] = combatQueue[second] = thisCombatStart + combatDuration; world.Clocks.AddTrigger(new OneTimeTrigger(thisCombatStart, () => { if (first.IsDisabled || second.IsDisabled) { return; } // TODO: play combat animation world.Clocks.AddTrigger(new OneTimeTrigger(thisCombatEnd, () => { currentCombats.Remove(Tuple.Create(first, second)); currentCombats.Remove(Tuple.Create(second, first)); if (combatQueue[first] == thisCombatEnd) { combatQueue.Remove(first); } if (combatQueue[second] == thisCombatEnd) { combatQueue.Remove(second); } Combat.ResolveBattle(first.Player, second.Player); if (first.Player.HasNoArmy()) { first.Die(); } if (second.Player.HasNoArmy()) { second.Die(); } })); })); }
public double BeginCombat(ICombatable other, Tile robotTile, Tile otherTile, Action onPlayerWin) { robotTile.BeginCombat(); otherTile.BeginCombat(); hommEngine.Freeze(player.Name); hommEngine.Freeze(other.UnityId); hommEngine.SetRotation(player.Name, robotTile.Location.GetDirectionTo(otherTile.Location).ToUnityAngle()); hommEngine.SetRotation(other.UnityId, otherTile.Location.GetDirectionTo(robotTile.Location).ToUnityAngle()); hommEngine.SetAnimation(player.Name, Animation.Attack); hommEngine.SetAnimation(other.UnityId, Animation.Attack); var combatTriggerTime = world.Clocks.CurrentTime + HommRules.Current.CombatDuration; world.Clocks.AddTrigger(new OneTimeTrigger(combatTriggerTime, () => { var initialOtherArmy = new Dictionary <UnitType, int>(other.Army); Combat.Resolve(player, other); var armies = new ArmiesPair(player.Army, other.Army); armies.Log("after Combat.ResolveBattle"); if (other.HasNoArmy()) { Debugger.Log("other has no army"); if (other is TileObject) { Debugger.Log("other is tile object, delete it"); ((TileObject)other).OnRemove(); } if (other is Player) { var otherPlayer = other as Player; world.Actors .Where(x => x is IHommRobot) .Cast <IHommRobot>() .Single(x => x.Player.Name == otherPlayer.Name) .Die(); } player.OnVictoryAchieved(other, initialOtherArmy); } else { hommEngine.SetAnimation(other.UnityId, Animation.Idle); } if (player.HasNoArmy()) { robot.Die(); } else { onPlayerWin(); } robotTile.EndCombat(); otherTile.EndCombat(); })); return(combatTriggerTime); }