public static Mobile[] ByInflication(this IEnumerable <Mobile> mobiles, TargetInfliction inflictionType) { switch (inflictionType) { case TargetInfliction.Any: return(mobiles.ToArray()); case TargetInfliction.Lowest: return(mobiles.Where(m => m.Hits < m.HitsMax && !m.IsDead).OrderBy(m => m.Hits).ToArray()); case TargetInfliction.Poisoned: return(mobiles.Where(m => m.IsPoisoned).ToArray()); case TargetInfliction.Mortaled: return(mobiles.Where(m => m.IsYellowHits).ToArray()); case TargetInfliction.Paralyzed: return(mobiles.Where(m => m.IsFrozen).ToArray()); case TargetInfliction.Dead: return(mobiles.Where(m => m.IsDead).ToArray()); case TargetInfliction.Unmounted: return(mobiles.Where(m => m.GetLayer(Layer.Mount) == 0).ToArray()); default: throw new ArgumentOutOfRangeException(nameof(inflictionType), inflictionType, null); } }
public Mobile GetMobile(TargetNotoriety notoFlags, TargetBodyType bodyType, TargetDistance targetDistance, TargetFriendType friendType, TargetInfliction inflictionType) { Notoriety[] noto = NotoFlagsToArray(notoFlags); Mobile m; switch (targetDistance) { case TargetDistance.Next: m = GetNextMobile(noto, bodyType, MAX_DISTANCE, friendType, inflictionType); break; case TargetDistance.Nearest: m = GetNextMobile(noto, bodyType, 3, friendType, inflictionType); break; case TargetDistance.Closest: m = GetClosestMobile(noto, bodyType, friendType, inflictionType); break; default: throw new ArgumentOutOfRangeException(nameof(targetDistance), targetDistance, null); } return(m); }
public Mobile GetClosestMobile(IEnumerable <Notoriety> notoriety, TargetBodyType bodyType = TargetBodyType.Any, TargetFriendType friendType = TargetFriendType.Include, TargetInfliction inflictionType = TargetInfliction.Any) { Mobile mobile; Func <int, bool> bodyTypePredicate; switch (bodyType) { case TargetBodyType.Any: bodyTypePredicate = i => true; break; case TargetBodyType.Humanoid: bodyTypePredicate = i => _bodyData.Where(bd => bd.BodyType == TargetBodyType.Humanoid).Select(bd => bd.Graphic) .Contains(i); break; case TargetBodyType.Transformation: bodyTypePredicate = i => _bodyData.Where(bd => bd.BodyType == TargetBodyType.Transformation).Select(bd => bd.Graphic) .Contains(i); break; case TargetBodyType.Both: bodyTypePredicate = i => _bodyData.Where(bd => bd.BodyType == TargetBodyType.Humanoid || bd.BodyType == TargetBodyType.Transformation) .Select(bd => bd.Graphic).Contains(i); break; default: throw new ArgumentOutOfRangeException(nameof(bodyType), bodyType, null); } if (friendType == TargetFriendType.Only) { mobile = Engine.Mobiles .SelectEntities(m => MobileCommands.InFriendList(m.Serial) && bodyTypePredicate(m.ID) && (!Options.CurrentOptions.GetFriendEnemyUsesIgnoreList || !ObjectCommands.IgnoreList.Contains(m.Serial))) .OrderBy(m => m.Distance).ByInflication(inflictionType).FirstOrDefault(); } else { mobile = Engine.Mobiles.SelectEntities(m => notoriety.Contains(m.Notoriety) && m.Distance < MAX_DISTANCE && bodyTypePredicate(m.ID) && (friendType == TargetFriendType.Include || !MobileCommands.InFriendList(m.Serial)) && (!Options.CurrentOptions.GetFriendEnemyUsesIgnoreList || !ObjectCommands.IgnoreList.Contains(m.Serial))).OrderBy(m => m.Distance) .ByInflication(inflictionType)?.FirstOrDefault(); } return(mobile); }
public bool GetFriend(TargetNotoriety notoFlags, TargetBodyType bodyType, TargetDistance targetDistance, TargetFriendType friendType = TargetFriendType.Include, TargetInfliction inflictionType = TargetInfliction.Any) { Mobile m = GetMobile(notoFlags, bodyType, targetDistance, friendType, inflictionType); if (m == null) { return(false); } SetFriend(m); return(true); }
public Mobile GetMobile(TargetNotoriety notoFlags, TargetBodyType bodyType, TargetDistance targetDistance, TargetFriendType friendType, TargetInfliction inflictionType, int previousSerial = 0) { Notoriety[] noto = NotoFlagsToArray(notoFlags); Mobile m; switch (targetDistance) { case TargetDistance.Next: m = GetNextMobile(noto, bodyType, MAX_DISTANCE, friendType, inflictionType); break; case TargetDistance.Nearest: Mobile previousMobile = Engine.Mobiles.GetMobile(previousSerial); if (previousMobile == null || previousMobile.Distance > MAX_DISTANCE) { m = GetClosestMobile(noto, bodyType, friendType, inflictionType); } else { m = GetNextMobile(noto, bodyType, MAX_DISTANCE, friendType, inflictionType, false, previousMobile); } break; case TargetDistance.Closest: m = GetClosestMobile(noto, bodyType, friendType, inflictionType); break; case TargetDistance.Previous: m = GetNextMobile(noto, bodyType, MAX_DISTANCE, friendType, inflictionType, true); break; default: throw new ArgumentOutOfRangeException(nameof(targetDistance), targetDistance, null); } return(m); }
public bool GetEnemy(TargetNotoriety notoFlags, TargetBodyType bodyType, TargetDistance targetDistance, TargetFriendType friendType = TargetFriendType.None, TargetInfliction inflictionType = TargetInfliction.Any) { Mobile m = GetMobile(notoFlags, bodyType, targetDistance, friendType, inflictionType, targetDistance == TargetDistance.Nearest ? AliasCommands.GetAlias("enemy") : 0); if (m == null) { return(false); } SetEnemy(m); return(true); }
public Mobile GetNextMobile(IEnumerable <Notoriety> notoriety, TargetBodyType bodyType = TargetBodyType.Any, int distance = MAX_DISTANCE, TargetFriendType friendType = TargetFriendType.Include, TargetInfliction inflictionType = TargetInfliction.Any, bool reverse = false) { bool looped = false; while (true) { Mobile[] mobiles; Func <int, bool> bodyTypePredicate; switch (bodyType) { case TargetBodyType.Any: bodyTypePredicate = i => true; break; case TargetBodyType.Humanoid: bodyTypePredicate = i => _bodyData.Where(bd => bd.BodyType == TargetBodyType.Humanoid).Select(bd => bd.Graphic) .Contains(i); break; case TargetBodyType.Transformation: bodyTypePredicate = i => _bodyData.Where(bd => bd.BodyType == TargetBodyType.Transformation) .Select(bd => bd.Graphic).Contains(i); break; case TargetBodyType.Both: bodyTypePredicate = i => _bodyData.Where(bd => bd.BodyType == TargetBodyType.Humanoid || bd.BodyType == TargetBodyType.Transformation) .Select(bd => bd.Graphic).Contains(i); break; default: throw new ArgumentOutOfRangeException(nameof(bodyType), bodyType, null); } if (friendType == TargetFriendType.Only) { //Notoriety, bodyType ignored mobiles = Engine.Mobiles.SelectEntities(m => m.Distance < distance && MobileCommands.InFriendList(m.Serial) && bodyTypePredicate(m.ID) && !_ignoreList.Contains(m) && (!Options.CurrentOptions.GetFriendEnemyUsesIgnoreList || !ObjectCommands.IgnoreList.Contains(m.Serial))); } else { mobiles = Engine.Mobiles.SelectEntities(m => notoriety.Contains(m.Notoriety) && m.Distance < distance && bodyTypePredicate(m.ID) && !_ignoreList.Contains(m) && (friendType == TargetFriendType.Include || !MobileCommands.InFriendList(m.Serial)) && (!Options.CurrentOptions.GetFriendEnemyUsesIgnoreList || !ObjectCommands.IgnoreList.Contains(m.Serial))); } if (reverse) { mobiles = mobiles.Reverse().ToArray(); } mobiles = mobiles.ByInflication(inflictionType); if (mobiles == null || mobiles.Length == 0) { _ignoreList.Clear(); if (looped) { return(null); } looped = true; continue; } Mobile mobile = mobiles.FirstOrDefault(); _ignoreList.Add(mobile); return(mobile); } }