Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public Target(TargetType targetType, int senderSerial, TargetFlags flags, int targetSerial, int x, int y,
                      int z, int id, bool cancelClientCursor)
        {
            if (senderSerial == -1)
            {
                senderSerial = Engine.TargetSerial;
            }

            if (targetSerial > 0)
            {
                Engine.Player.LastTargetSerial = targetSerial;
                Engine.Player.LastTargetType   = targetType;
            }

            if (Engine.TargetFlags == TargetFlags.Harmful &&
                Options.CurrentOptions.PreventTargetingFriendsWithHarmful &&
                MobileCommands.InFriendList(targetSerial))
            {
                Commands.SystemMessage(Strings.Target_blocked____try_again___);
                Commands.ResendTargetToClient();

                return;
            }

            _writer = new PacketWriter(19);
            _writer.Write((byte)0x6C);
            _writer.Write((byte)targetType);
            _writer.Write(senderSerial);
            _writer.Write((byte)flags);
            _writer.Write(targetSerial);
            _writer.Write((short)x);
            _writer.Write((short)y);
            _writer.Write((short)z);
            _writer.Write((short)id);

            Engine.TargetExists = false;

            if (cancelClientCursor)
            {
                Engine.SendPacketToClient(new Target(targetType, senderSerial, TargetFlags.Cancel, targetSerial, x, y,
                                                     z, id, false));
                Engine.AddSendPreFilter(new PacketFilterInfo(0x6C,
                                                             new[] { PacketFilterConditions.IntAtPositionCondition(senderSerial, 2) },
                                                             (p, pfi) => { Engine.RemoveSendPreFilter(pfi); }));
            }
        }
        private static void OnTargetSent(PacketReader reader)
        {
            if (Engine.Player == null)
            {
                return;
            }

            TargetType targetType = (TargetType)reader.ReadByte();

            Engine.Player.LastTargetType = targetType;

            int senderSerial = reader.ReadInt32(); // sender serial
            int flags        = reader.ReadByte();
            int serial       = reader.ReadInt32();
            int x            = reader.ReadInt16();
            int y            = reader.ReadInt16();
            int z            = reader.ReadInt16();
            int id           = reader.ReadInt16();

            if (targetType == TargetType.Object && flags != 0x03 && serial != 0)
            {
                Engine.Player.LastTargetSerial = serial;
                Engine.Player.LastTargetType   = targetType;

                switch ((TargetFlags)flags)
                {
                case TargetFlags.Harmful when Engine.Mobiles.GetMobile(serial, out Mobile enemyMobile) &&
                    AliasCommands.GetAlias("enemy") != serial:
                    TargetManager.GetInstance().SetEnemy(enemyMobile);

                    break;

                case TargetFlags.Beneficial when Engine.Mobiles.GetMobile(serial, out Mobile friendMobile) &&
                    MobileCommands.InFriendList(serial) &&
                    AliasCommands.GetAlias("friend") != serial:
                    TargetManager.GetInstance().SetFriend(friendMobile);

                    break;
                }
            }

            Engine.TargetExists = false;

            TargetSentEvent?.Invoke(targetType, senderSerial, flags, serial, x, y, z, id);
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        private static void OnPartyCommand(PacketReader reader)
        {
            int command = reader.ReadByte();

            switch (command)
            {
            case 1:
            {
                int count = reader.ReadByte();

                List <int> partyMembers = new List <int>();

                for (int i = 0; i < count; i++)
                {
                    int serial = reader.ReadInt32();
                    partyMembers.Add(serial);
                }

                if (Engine.Player == null)
                {
                    return;
                }

                Engine.Player.Party = partyMembers.ToArray();

                break;
            }

            case 2:
            {
                int count = reader.ReadByte();

                reader.ReadInt32();     // removed member serial

                List <int> partyMembers = new List <int>();

                for (int i = 0; i < count; i++)
                {
                    int serial = reader.ReadInt32();
                    partyMembers.Add(serial);
                }

                if (Engine.Player == null)
                {
                    return;
                }

                Engine.Player.Party = partyMembers.ToArray();

                break;
            }

            case 7:
            {
                int leaderSerial = reader.ReadInt32();

                if (Options.CurrentOptions.AutoAcceptPartyInvite)
                {
                    if (!Options.CurrentOptions.AutoAcceptPartyOnlyFromFriends ||
                        Options.CurrentOptions.AutoAcceptPartyOnlyFromFriends &&
                        MobileCommands.InFriendList(leaderSerial))
                    {
                        Engine.SendPacketToServer(new AcceptPartyInvitation(leaderSerial));
                    }
                }

                break;
            }
            }
        }