// TODO: optimize this somehow public void AutoAttack() { if (_attackTarget != null) { if (!InRange(_attackTarget, _attackRange) || !_context.MapContext().CheckLOS(CurrentPosition, _attackTarget.GetPosition())) { _attackTarget = null; } else if (_currentAttackCooldown == null) { ByteVector2 attackSpot = _attackTarget.GetPosition(); Entity[] toAttack = _context.MapContext().GetEntities(attackSpot, 0); // Damage nearby foreach (Entity e in toAttack) { if (!e.InFaction(_context.factionID) && e != _attackTarget) { Attack(e); } } if (Attack(_attackTarget)) { _currentAttackCooldown = new AttackCooldownJob(_attackCooldown, _context); } else { _attackTarget = null; } } } else { // Try to find a target Entity[] surroundings = _context.gameManager.MapManager.GetEntities(CurrentPosition, _attackRange); foreach (Entity e in surroundings) { // Only target hostile faction entities if (!e.InFaction(_context.factionID) && !e.InFaction(0) && ((byte)e.Type <= Constants.Entities.UNIT_IDS || e.Type == Constants.Entities.Hub.ID || e.Type == Constants.Entities.SandBags.ID)) { _attackTarget = e; break; } } } }
public void ResetAttack() { _currentAttackCooldown = null; }