internal bool IsOpponent(Creature creature) { return(IsOpponent(creature, false)); }
internal void RemoveCreature(uint id) { int currentIndex = 0; int lastIndex = m_CreatureCount - 1; int foundIndex = -1; Creature foundCreature = null; while (currentIndex <= lastIndex) { int tmpIndex = currentIndex + lastIndex >> 1; foundCreature = m_Creatures[tmpIndex]; if (foundCreature.ID < id) { currentIndex = tmpIndex + 1; } else if (foundCreature.ID > id) { lastIndex = tmpIndex - 1; } else { foundIndex = tmpIndex; break; } } if (!foundCreature || foundIndex < 0) { throw new System.ArgumentException("CreatureStorage.RemoveCreature: creature " + id + " not found"); } else if (foundCreature == Player) { throw new System.Exception("CreatureStorage.RemoveCreature: cannot remove player."); } if (foundCreature == Aim) { Aim = null; UpdateExtendedMark(foundCreature); } if (foundCreature == AttackTarget) { AttackTarget = null; UpdateExtendedMark(foundCreature); } if (foundCreature == FollowTarget) { FollowTarget = null; UpdateExtendedMark(foundCreature); } if (Trappers != null) { int index = Trappers.FindIndex((x) => x == foundCreature); if (index > 0) { Trappers[index].Trapper = false; Trappers.RemoveAt(index); } } foundCreature.Reset(); m_Creatures.RemoveAt(foundIndex); m_CreatureCount--; m_OpponentState = OpponentStates.Rebuild; }
protected int OpponentComparator(Creature a, Creature b) { if (a == null || b == null) { return(0); } var pos = 0; var sortType = OpenTibiaUnity.OptionStorage.OpponentSort; bool desc = false; if (sortType == OpponentSortTypes.SortDistanceDesc || sortType == OpponentSortTypes.SortHitpointsDesc || sortType == OpponentSortTypes.SortKnownSinceDesc || sortType == OpponentSortTypes.SortNameDesc) { desc = true; } switch (sortType) { case OpponentSortTypes.SortDistanceAsc: case OpponentSortTypes.SortDistanceDesc: var myPosition = Player.Position; var d1 = System.Math.Max(System.Math.Abs(myPosition.x - a.Position.x), System.Math.Abs(myPosition.y - a.Position.y)); var d2 = System.Math.Max(System.Math.Abs(myPosition.x - b.Position.x), System.Math.Abs(myPosition.y - b.Position.y)); if (d1 < d2) { pos = -1; } else if (d1 > d2) { pos = 1; } break; case OpponentSortTypes.SortHitpointsAsc: case OpponentSortTypes.SortHitpointsDesc: if (a.HealthPercent < b.HealthPercent) { pos = -1; } else if (a.HealthPercent > b.HealthPercent) { pos = 1; } break; case OpponentSortTypes.SortNameAsc: case OpponentSortTypes.SortNameDesc: pos = a.Name.CompareTo(b.Name); break; case OpponentSortTypes.SortKnownSinceAsc: case OpponentSortTypes.SortKnownSinceDesc: break; } if (pos == 0) { if (a.KnownSince < b.KnownSince) { pos = -1; } else if (a.KnownSince > b.KnownSince) { pos = 1; } else { return(0); } } return(pos * (desc ? -1 : 1)); }