Exemplo n.º 1
0
        private void OnNewTick(Client client, Packet packet)
        {
            LootState     state   = _states[client];
            NewTickPacket newTick = (NewTickPacket)packet;

            // Updated Objects
            foreach (Status status in newTick.Statuses)
            {
                if (state.LootBagItems.ContainsKey(status.ObjectId))
                {
                    foreach (StatData statData in status.Data)
                    {
                        if (statData.Id >= 8 && statData.Id <= 15)
                        {
                            state.LootBagItems[status.ObjectId][statData.Id - 8] = statData.IntValue;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void OnMove(Client client, Packet packet)
        {
            if (!_states.ContainsKey(client))
            {
                return;
            }
            LootState state = _states[client];

            foreach (int bagId in state.LootBagItems.Keys)
            {
                float distance = state.LootBagLocations[bagId].DistanceTo(client.PlayerData.Pos);
                if (LootHelperConfig.Default.AutoLoot && Environment.TickCount - state.LastLoot > 900 && distance <= 1)
                {
                    for (int bi = 0; bi < state.LootBagItems[bagId].Length; bi++)
                    {
                        if (state.LootBagItems[bagId][bi] == -1)
                        {
                            continue;
                        }

                        if (!LootHelperConfig.Default.AutoLootList.Contains(ReverseLookup(state.LootBagItems[bagId][bi])))
                        {
                            continue;
                        }

                        state.LastLoot = Environment.TickCount;
                        for (int i = 4; i < client.PlayerData.Slot.Length; i++)
                        {
                            if (client.PlayerData.Slot[i] == -1)
                            {
                                InvSwapPacket invSwap = (InvSwapPacket)Packet.Create(PacketType.INVSWAP);
                                invSwap.Time     = client.Time + 10;
                                invSwap.Position = client.PlayerData.Pos;

                                invSwap.SlotObject1            = new SlotObject();
                                invSwap.SlotObject1.ObjectId   = bagId;
                                invSwap.SlotObject1.SlotId     = (byte)bi;
                                invSwap.SlotObject1.ObjectType = state.LootBagItems[bagId][bi];

                                invSwap.SlotObject2            = new SlotObject();
                                invSwap.SlotObject2.ObjectId   = client.ObjectId;
                                invSwap.SlotObject2.SlotId     = (byte)(i);
                                invSwap.SlotObject2.ObjectType = -1;

                                client.SendToServer(invSwap);
                                break;
                            }
                        }
                    }
                }

                if (LootHelperConfig.Default.LootNotifications && Environment.TickCount - state.LastNotif > 2000 && distance < 15)
                {
                    state.LastNotif = Environment.TickCount;
                    string message = "";

                    foreach (int item in state.LootBagItems[bagId])
                    {
                        if (item != -1)
                        {
                            message += ReverseLookup(item) + "\\n";
                        }
                    }

                    if (message.Length > 3)
                    {
                        client.SendToClient(PluginUtils.CreateNotification(
                                                bagId, LootHelperConfig.Default.NotificationColor.ToArgb(), message));
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void OnUpdate(Client client, Packet packet)
        {
            LootState    state  = _states[client];
            UpdatePacket update = (UpdatePacket)packet;

            // New Objects
            foreach (Entity entity in update.NewObjs)
            {
                string type = BagTypeToString(entity.ObjectType);
                if (type == null)
                {
                    continue;
                }
                if (LootHelperConfig.Default.LootBags.Contains(type, StringComparison.OrdinalIgnoreCase) || LootHelperConfig.Default.NotifBags.Contains(type, StringComparison.OrdinalIgnoreCase))
                {
                    if (LootHelperConfig.Default.QuestBags.Contains(type, StringComparison.OrdinalIgnoreCase))
                    {
                        if (LootHelperConfig.Default.LootQuests)
                        {
                            state.CustomQuest = entity.Status.ObjectId;
                            QuestObjIdPacket questObjId = (QuestObjIdPacket)Packet.Create(PacketType.QUESTOBJID);
                            questObjId.ObjectId = entity.Status.ObjectId;
                            client.SendToClient(questObjId);
                        }
                    }

                    int bagId = entity.Status.ObjectId;
                    // Set the bag type
                    if (!state.LootBagTypes.ContainsKey(bagId))
                    {
                        state.LootBagTypes.Add(bagId, type);
                    }
                    else
                    {
                        state.LootBagTypes[bagId] = type;
                    }
                    // Set the bag contents to empty
                    if (!state.LootBagItems.ContainsKey(bagId))
                    {
                        state.LootBagItems.Add(bagId, new int[] { -1, -1, -1, -1, -1, -1, -1, -1 });
                    }
                    else
                    {
                        state.LootBagItems[bagId] = new int[] { -1, -1, -1, -1, -1, -1, -1, -1 }
                    };
                    // Set the bag location
                    if (!state.LootBagLocations.ContainsKey(bagId))
                    {
                        state.LootBagLocations.Add(bagId, entity.Status.Position);
                    }
                    else
                    {
                        state.LootBagLocations[bagId] = entity.Status.Position;
                    }
                    // Fill in the bag contents
                    foreach (StatData statData in entity.Status.Data)
                    {
                        if (statData.Id >= 8 && statData.Id <= 15)
                        {
                            state.LootBagItems[bagId][statData.Id - 8] = statData.IntValue;
                        }
                    }
                }
            }

            // Removed Objects
            foreach (int drop in update.Drops)
            {
                if (drop == state.CustomQuest && state.OriginalQuest != -1)
                {
                    QuestObjIdPacket questObjId = (QuestObjIdPacket)Packet.Create(PacketType.QUESTOBJID);
                    questObjId.ObjectId = state.OriginalQuest;
                    client.SendToClient(questObjId);

                    state.OriginalQuest = -1;
                    state.CustomQuest   = -1;
                }

                if (state.LootBagItems.ContainsKey(drop))
                {
                    state.LootBagItems.Remove(drop);
                    state.LootBagLocations.Remove(drop);
                }
            }
        }
Exemplo n.º 4
0
        private void OnUpdate(Client client, Packet packet)
        {
            LootState    state  = _states[client];
            UpdatePacket update = (UpdatePacket)packet;

            // New Objects
            foreach (Entity entity in update.NewObjs)
            {
                ushort type = entity.ObjectType;
                if (_desiredBags.Contains(type))
                {
                    if (LootHelperConfig.Default.LootQuests)
                    {
                        state.CustomQuest = entity.Status.ObjectId;
                        QuestObjIdPacket questObjId = (QuestObjIdPacket)Packet.Create(PacketType.QUESTOBJID);
                        questObjId.ObjectId = entity.Status.ObjectId;
                        client.SendToClient(questObjId);
                    }

                    int bagId = entity.Status.ObjectId;
                    if (!state.LootBagItems.ContainsKey(bagId))
                    {
                        state.LootBagItems.Add(bagId, new int[] { -1, -1, -1, -1, -1, -1, -1, -1 });
                    }
                    else
                    {
                        state.LootBagItems[bagId] = new int[] { -1, -1, -1, -1, -1, -1, -1, -1 }
                    };

                    if (!state.LootBagLocations.ContainsKey(bagId))
                    {
                        state.LootBagLocations.Add(bagId, entity.Status.Position);
                    }
                    else
                    {
                        state.LootBagLocations[bagId] = entity.Status.Position;
                    }

                    foreach (StatData statData in entity.Status.Data)
                    {
                        if (statData.Id >= 8 && statData.Id <= 15)
                        {
                            state.LootBagItems[bagId][statData.Id - 8] = statData.IntValue;
                        }
                    }
                }
            }

            // Removed Objects
            foreach (int drop in update.Drops)
            {
                if (drop == state.CustomQuest && state.OriginalQuest != -1)
                {
                    QuestObjIdPacket questObjId = (QuestObjIdPacket)Packet.Create(PacketType.QUESTOBJID);
                    questObjId.ObjectId = state.OriginalQuest;
                    client.SendToClient(questObjId);

                    state.OriginalQuest = -1;
                    state.CustomQuest   = -1;
                }

                if (state.LootBagItems.ContainsKey(drop))
                {
                    state.LootBagItems.Remove(drop);
                    state.LootBagLocations.Remove(drop);
                }
            }
        }
Exemplo n.º 5
0
        private void OnMove(Client client, Packet packet)
        {
            if (!_states.ContainsKey(client))
            {
                return;
            }
            LootState state = _states[client];

            foreach (int bagId in state.LootBagItems.Keys)
            {
                if (state.LootBagTypes[bagId] == null)
                {
                    continue;
                }
                float distance = state.LootBagLocations[bagId].DistanceTo(client.PlayerData.Pos);
                if (LootHelperConfig.Default.LootBags.Contains(state.LootBagTypes[bagId], StringComparison.OrdinalIgnoreCase))
                {
                    if (LootHelperConfig.Default.AutoLoot && Environment.TickCount - state.LastLoot > LootHelperConfig.Default.LootSpeed && distance <= 1)
                    {
                        for (int bi = 0; bi < state.LootBagItems[bagId].Length; bi++)
                        {
                            if (state.LootBagItems[bagId][bi] == -1)
                            {
                                continue;
                            }

                            bool next = true;
                            if (LootHelperConfig.Default.AutoLootList.Contains(ReverseLookup(state.LootBagItems[bagId][bi])))
                            {
                                next = false;
                            }
                            else if (CheckLootTier(state.LootBagItems[bagId][bi]))
                            {
                                next = false;
                            }

                            if (next)
                            {
                                continue;
                            }

                            state.LastLoot = Environment.TickCount;

                            if (state.LootBagItems[bagId][bi] == 2594 && client.PlayerData.HealthPotionCount < 6)
                            {
                                InvSwapPacket invSwap = (InvSwapPacket)Packet.Create(PacketType.INVSWAP);
                                invSwap.Time     = client.Time + 10;
                                invSwap.Position = client.PlayerData.Pos;

                                invSwap.SlotObject1            = new SlotObject();
                                invSwap.SlotObject1.ObjectId   = bagId;
                                invSwap.SlotObject1.SlotId     = (byte)bi;
                                invSwap.SlotObject1.ObjectType = (short)state.LootBagItems[bagId][bi];

                                invSwap.SlotObject2            = new SlotObject();
                                invSwap.SlotObject2.ObjectId   = client.ObjectId;
                                invSwap.SlotObject2.SlotId     = (byte)(state.LootBagItems[bagId][bi] - 2340);
                                invSwap.SlotObject2.ObjectType = -1;

                                //state.LastLoot = Environment.TickCount;
                                client.SendToServer(invSwap);
                                continue;
                            }
                            else if (state.LootBagItems[bagId][bi] == 2595 && client.PlayerData.MagicPotionCount < 6)
                            {
                                InvSwapPacket invSwap = (InvSwapPacket)Packet.Create(PacketType.INVSWAP);
                                invSwap.Time     = client.Time + 10;
                                invSwap.Position = client.PlayerData.Pos;

                                invSwap.SlotObject1            = new SlotObject();
                                invSwap.SlotObject1.ObjectId   = bagId;
                                invSwap.SlotObject1.SlotId     = (byte)bi;
                                invSwap.SlotObject1.ObjectType = (short)state.LootBagItems[bagId][bi];

                                invSwap.SlotObject2            = new SlotObject();
                                invSwap.SlotObject2.ObjectId   = client.ObjectId;
                                invSwap.SlotObject2.SlotId     = (byte)(state.LootBagItems[bagId][bi] - 2340);
                                invSwap.SlotObject2.ObjectType = -1;

                                //state.LastLoot = Environment.TickCount;
                                client.SendToServer(invSwap);
                                continue;
                            }
                            else
                            {
                                for (int i = 4; i < 20; i++)
                                {
                                    if (i < 12)
                                    {
                                        if (client.PlayerData.Slot[i] == -1)
                                        {
                                            InvSwapPacket invSwap = (InvSwapPacket)Packet.Create(PacketType.INVSWAP);
                                            invSwap.Time     = client.Time + 10;
                                            invSwap.Position = client.PlayerData.Pos;

                                            invSwap.SlotObject1            = new SlotObject();
                                            invSwap.SlotObject1.ObjectId   = bagId;
                                            invSwap.SlotObject1.SlotId     = (byte)bi;
                                            invSwap.SlotObject1.ObjectType = state.LootBagItems[bagId][bi];

                                            invSwap.SlotObject2            = new SlotObject();
                                            invSwap.SlotObject2.ObjectId   = client.ObjectId;
                                            invSwap.SlotObject2.SlotId     = (byte)(i);
                                            invSwap.SlotObject2.ObjectType = -1;

                                            //state.LastLoot = Environment.TickCount;
                                            client.SendToServer(invSwap);
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        if (client.PlayerData.HasBackpack)
                                        {
                                            if (client.PlayerData.BackPack[i - 12] == -1)
                                            {
                                                InvSwapPacket invSwap = (InvSwapPacket)Packet.Create(PacketType.INVSWAP);
                                                invSwap.Time     = client.Time + 10;
                                                invSwap.Position = client.PlayerData.Pos;

                                                invSwap.SlotObject1            = new SlotObject();
                                                invSwap.SlotObject1.ObjectId   = bagId;
                                                invSwap.SlotObject1.SlotId     = (byte)bi;
                                                invSwap.SlotObject1.ObjectType = state.LootBagItems[bagId][bi];

                                                invSwap.SlotObject2            = new SlotObject();
                                                invSwap.SlotObject2.ObjectId   = client.ObjectId;
                                                invSwap.SlotObject2.SlotId     = (byte)(i);
                                                invSwap.SlotObject2.ObjectType = -1;

                                                //state.LastLoot = Environment.TickCount;
                                                client.SendToServer(invSwap);
                                                continue;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (LootHelperConfig.Default.NotifBags.Contains(state.LootBagTypes[bagId], StringComparison.OrdinalIgnoreCase))
                {
                    if (!state.BagLastNotif.ContainsKey(bagId))
                    {
                        state.BagLastNotif.Add(bagId, 0);
                    }

                    if (LootHelperConfig.Default.LootNotifications && Environment.TickCount - state.BagLastNotif[bagId] > 2000 && distance < 15)
                    {
                        state.BagLastNotif[bagId] = Environment.TickCount;
                        string message = "";

                        foreach (int item in state.LootBagItems[bagId])
                        {
                            if (item != -1)
                            {
                                message += ReverseLookup(item) + "\\n";
                            }
                        }

                        if (message.Length > 3)
                        {
                            client.SendToClient(PluginUtils.CreateNotification(bagId, LootHelperConfig.Default.NotificationColor.ToArgb(), message));
                        }
                    }
                }
            }
        }