public AttackEnemy(State previousState, AggressivePlayer player) : base(CutterTimeout, DefenseTimeout, player) { previousState?.Dispose(); var targetPlayer = player.Player .GetEnemyPlayers() .MinBy(enemy => { var keep = (enemy.Plugin as PlayerWithKeep)?.Keep; return(keep == null ? double.MaxValue : Vector3.Distance(player.Keep.Building.Center, keep.Building.Center)); }).FirstOrDefault(); target = targetPlayer?.Plugin as PlayerWithKeep; if (target != null) { target.Player.OnRemoval += TargetDied; } }
void TargetDied(IPlayer player) { target = null; }