/// <summary> /// Adds a retaliate target for a monster that it would not normally attack /// </summary> public void AddRetaliateTarget(PhysicsObj obj) { rwLock.EnterWriteLock(); try { if (RetaliateTargets.ContainsKey(obj.ID)) { //Console.WriteLine($"{PhysicsObj.Name}.AddRetaliateTarget({obj.Name}) - retaliate target already exists"); return; } //Console.WriteLine($"{PhysicsObj.Name}.AddRetaliateTarget({obj.Name})"); RetaliateTargets.Add(obj.ID, obj); // we're going to add retaliate targets to the list of visible targets as well, // so that we don't have to traverse both VisibleTargets and RetaliateTargets // in all of the logic based on VisibleTargets if (VisibleTargets.ContainsKey(obj.ID)) { //Console.WriteLine($"{PhysicsObj.Name}.AddRetaliateTarget({obj.Name}) - visible target already exists"); return; } VisibleTargets.Add(obj.ID, obj); } finally { rwLock.ExitWriteLock(); } }
/// <summary> /// For monster and CombatPet FindNextTarget /// - for monsters, contains players and combat pets /// - for combat pets, contains monsters /// </summary> public bool AddVisibleTarget(PhysicsObj obj, bool clamp = true) { if (PhysicsObj.WeenieObj.IsCombatPet) { // only tracking monsters if (!obj.WeenieObj.IsMonster) { Console.WriteLine($"{PhysicsObj.Name}.ObjectMaint.AddVisibleTarget({obj.Name}): tried to add a non-monster"); return(false); } } else { // only tracking players and combat pets if (!obj.IsPlayer && !obj.WeenieObj.IsCombatPet) { Console.WriteLine($"{PhysicsObj.Name}.ObjectMaint.AddVisibleTarget({obj.Name}): tried to add a non-player / non-combat pet"); return(false); } } if (PhysicsObj.DatObject) { Console.WriteLine($"{PhysicsObj.Name}.ObjectMaint.AddVisibleTarget({obj.Name}): tried to add player for dat object"); return(false); } if (clamp && InitialClamp && obj.IsPlayer && !obj.ObjMaint.KnownObjects.ContainsKey(obj.ID)) { var distSq = PhysicsObj.Position.Distance2DSquared(obj.Position); if (distSq > InitialClamp_DistSq) { return(false); } } // TryAdd for existing keys still modifies collection? if (VisibleTargets.ContainsKey(obj.ID)) { return(false); } //Console.WriteLine($"{PhysicsObj.Name} ({PhysicsObj.ID:X8}).ObjectMaint.AddVisibleTarget({obj.Name})"); VisibleTargets.Add(obj.ID, obj); // maintain inverse for monsters / combat pets if (!obj.IsPlayer) { obj.ObjMaint.AddVisibleTarget(PhysicsObj); } return(true); }
public bool VisibleTargetsContainsKey(uint key) { rwLock.EnterReadLock(); try { return(VisibleTargets.ContainsKey(key)); } finally { rwLock.ExitReadLock(); } }
/// <summary> /// For monster and CombatPet FindNextTarget /// - for monsters, contains players and combat pets /// - for combat pets, contains monsters /// </summary> private bool AddVisibleTarget(PhysicsObj obj, bool clamp = true) { if (PhysicsObj.WeenieObj.IsCombatPet) { // only tracking monsters if (!obj.WeenieObj.IsMonster) { Console.WriteLine($"{PhysicsObj.Name}.ObjectMaint.AddVisibleTarget({obj.Name}): tried to add a non-monster"); return(false); } } else if (PhysicsObj.WeenieObj.IsFactionMob) { // only tracking players, combat pets, and monsters of differing faction if (!obj.IsPlayer && !obj.WeenieObj.IsCombatPet && (!obj.WeenieObj.IsMonster || PhysicsObj.WeenieObj.SameFaction(obj))) { Console.WriteLine($"{PhysicsObj.Name}.ObjectMaint.AddVisibleTarget({obj.Name}): tried to add a non-player / non-combat pet / non-opposing faction mob"); return(false); } } else { // handle special case: // we want to select faction mobs for monsters inverse targets, // but not add to the original monster if (obj.WeenieObj.IsFactionMob) { obj.ObjMaint.AddVisibleTarget(PhysicsObj); return(false); } // only tracking players and combat pets if (!obj.IsPlayer && !obj.WeenieObj.IsCombatPet) { Console.WriteLine($"{PhysicsObj.Name}.ObjectMaint.AddVisibleTarget({obj.Name}): tried to add a non-player / non-combat pet"); return(false); } } if (PhysicsObj.DatObject) { Console.WriteLine($"{PhysicsObj.Name}.ObjectMaint.AddVisibleTarget({obj.Name}): tried to add player for dat object"); return(false); } if (clamp && InitialClamp && obj.IsPlayer && !obj.ObjMaint.KnownObjects.ContainsKey(obj.ID)) { var distSq = PhysicsObj.Position.Distance2DSquared(obj.Position); if (distSq > InitialClamp_DistSq) { return(false); } } // TryAdd for existing keys still modifies collection? if (VisibleTargets.ContainsKey(obj.ID)) { return(false); } //Console.WriteLine($"{PhysicsObj.Name} ({PhysicsObj.ID:X8}).ObjectMaint.AddVisibleTarget({obj.Name})"); VisibleTargets.Add(obj.ID, obj); // maintain inverse for monsters / combat pets if (!obj.IsPlayer) { obj.ObjMaint.AddVisibleTarget(PhysicsObj); } return(true); }