public void UpdateThink() { if (HasPlayer()) { return; } if (_unit != null) { if (_unit is KeepNpcCreature.KeepCreature) { KeepNpcCreature.KeepCreature npc = _unit as KeepNpcCreature.KeepCreature; if (((npc.Z - npc.SpawnPoint.Z > 120 || npc.SpawnPoint.Z - npc.Z > 30)) || !npc.PointWithinRadiusFeet(npc.WorldSpawnPoint, 200)) { ProcessCombatEnd(); return; } } } if (CurrentBrain != null && CurrentBrain.IsStart && !CurrentBrain.IsStop) { CurrentBrain.Think(); if (State == AiState.FIGHTING) { CurrentBrain.Fight(); } } Creature creature = _unit as Creature; if (creature == null || creature is Pet) { return; } if (!creature.PointWithinRadiusFeet(creature.WorldSpawnPoint, 200)) { ProcessCombatEnd(); } }
/*private bool IsNeutralFaction(Creature c) * { * if (c.Spawn.Faction == 0 || (((c.Spawn.Faction >> 8 & 0x1))) == 0) return true; * else return false; * }*/ public Unit GetAttackableUnit() { Unit unitOwner = GetUnit(); float maxRange = MaxAggroRange + unitOwner.Level / 1.5f; Unit target = null; lock (RangedEnemies) foreach (Unit enemy in RangedEnemies) { Player player = enemy as Player; if (player != null && player.StealthLevel > 0 && unitOwner.Level <= player.EffectiveLevel + 2) { continue; } if (!CombatInterface.CanAttack(unitOwner, enemy)) { continue; } float dist = _Owner.GetDistanceToObject(enemy, true); if (dist > maxRange) { continue; } if (unitOwner != null) { if (unitOwner is KeepNpcCreature.KeepCreature) { KeepNpcCreature.KeepCreature npc = unitOwner as KeepNpcCreature.KeepCreature; //Keep NPCs have additional hardening. If their target goes outside the keep, instantly reset. if (enemy.Z - npc.SpawnPoint.Z > 120 || npc.SpawnPoint.Z - enemy.Z > 30 || !enemy.PointWithinRadiusFeet(npc.WorldSpawnPoint, 200) || !npc.PointWithinRadiusFeet(npc.WorldSpawnPoint, 200)) { continue; } if (!enemy.LOSHit(npc)) { continue; } } else if (unitOwner is Creature) { Creature creature = unitOwner as Creature; if (creature is Pet) { Pet pet = creature as Pet; if (pet == null || pet.Owner == null) { continue; } //Only aggro if we have LOS to the owner. if (!enemy.LOSHit(pet.Owner)) { continue; } } else { //Standard NPC checks. if (!creature.PointWithinRadiusFeet(creature.WorldSpawnPoint, 200)) { continue; } if (!enemy.LOSHit(creature)) { continue; } } } else { } } maxRange = dist; target = enemy; } return(target); }