Ejemplo n.º 1
0
        private void TakeItem(Item i, KonjoBot.Objects.Bot.LootItem lot)
        {
            if (lot.Cap <= Core.client.Player.Capacity)
            {
                if (lot.Cap * i.Count > Core.client.Player.Capacity)
                {
                    i.Count = 1;
                }

                switch (lot.Destination)
                {
                case Constants.LootDestination.Arrow:
                    i.Move(ItemLocation.FromSlot(Constants.SlotNumber.Ammo));
                    break;

                case Constants.LootDestination.Container:
                    if (lot.ContainerDestionation == 16)   // any
                    {
                        i.Move(LootTo(i));
                    }
                    else
                    {
                        i.Move(LootToIndex(i, lot.ContainerDestionation));
                    }

                    break;

                case Constants.LootDestination.Ground:
                    i.Move(ItemLocation.FromLocation(Core.client.PlayerLocation));
                    break;

                case Constants.LootDestination.LeftHand:
                    i.Move(ItemLocation.FromSlot(Constants.SlotNumber.Left));
                    break;

                case Constants.LootDestination.RightHand:
                    i.Move(ItemLocation.FromSlot(Constants.SlotNumber.Right));
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void Loot(byte number)
        {
            Container container = Core.Client.Inventory.GetContainer(number);

            if (container == null || !IsLootContainer(number))
            {
                return;
            }

            IEnumerable <Item> containterEnumerable = container.GetItems();
            List <Item>        containerItems       = containterEnumerable.ToList();

            while (containerItems.Count > 0)
            {
                Item     item     = containerItems.Last();
                LootItem lootItem = LootItems.Find(delegate(LootItem loot) { return(loot.Id == item.Id); });

                if (lootItem != null)
                {
                    if (lootItem.Container == (byte)LootContainer.Ground)
                    {
                        int startAmmount = container.Amount;

                        for (int i = 0; i < maxTries && container.Amount == startAmmount; i++)
                        {
                            item.Move(ItemLocation.FromLocation(Core.Player.Location));
                            Thread.Sleep(100);
                        }
                    }
                    else
                    {
                        Container lootContainer = null;

                        #region Select container

                        if (lootItem.Container == (byte)LootContainer.Any)
                        {
                            lootContainer = GetLootContainer(item);
                        }
                        else
                        {
                            lootContainer = Core.Client.Inventory.GetContainer(lootItem.Container);
                        }

                        #endregion

                        if (lootContainer == null)
                        {
                            continue;
                        }

                        int startAmmount = container.Amount;

                        for (int i = 0; i < maxTries && container.Amount == startAmmount; i++)
                        {
                            GetItem(item, lootContainer);
                            Thread.Sleep(100);
                        }
                    }
                }

                containerItems.Remove(item);
            }

            #region Eat Foot

            if (EatFromMonsters)
            {
                Item food = containterEnumerable.FirstOrDefault(i => ItemLists.Foods.ContainsKey(i.Id));

                if (food != null)
                {
                    for (int i = 0; i < food.Count; i++)
                    {
                        food.Use();
                        Thread.Sleep(300);
                    }
                }
            }

            #endregion

            #region Open bag / close container

            Item bag = containterEnumerable.LastOrDefault(i => i.GetFlag(Tibia.Addresses.DatItem.Flag.IsContainer));

            if (bag != null)
            {
                OpenNewContainer(bag, container.Number);
            }
            else
            {
                container.Close();
            }

            Thread.Sleep(100);

            #endregion
        }
Ejemplo n.º 3
0
        void HookProxy_TileAddThing(Location location, byte stack, int itemid)
        {
            if (location.Z != Core.client.PlayerLocation.Z)
            {
                return;
            }
            Item Corpse = new Item(Core.client, itemid);

            Corpse.Location = ItemLocation.FromLocation(location, stack);
            if (Corpse.ItemData.IsCorpse != true)
            {
                return;
            }
            if (Core.Global.OpenCorpses && Core.Global.LooterEnabled)
            {
                if (Core.Global.LootFriendly)
                {
                    if (Core.client.Player.RedSquare > 0)
                    {
                        Creature c = Core.client.Battlelist.GetScreenCreatures().FirstOrDefault(t => t.Id == Core.client.Player.RedSquare);
                        if (c != null)
                        {
                            TargetLoc = c.Location;
                        }
                        if (location.Equals(TargetLoc))
                        {
                            if (Core.Global.WalkerEnabled)
                            {
                                CorpseList.Add(new Corpse(location, Corpse, DateTime.Now));
                            }
                            else
                            {
                                byte containerIndex = (byte)Core.client.Inventory.ContainersCount();
                                Core.LastCorpse = containerIndex;
                                LastCorpeses[containerIndex] = 1;
                                Core.SleepRandom();
                                Corpse.Use(containerIndex);
                            }
                        }
                    }
                }
                else
                {
                    if (location.DistanceTo(Core.client.PlayerLocation) <= 8)
                    {
                        if (Core.Global.WalkerEnabled)
                        {
                            CorpseList.Add(new Corpse(location, Corpse, DateTime.Now));
                        }
                        else
                        {
                            byte containerIndex = (byte)Core.client.Inventory.ContainersCount();
                            Core.LastCorpse = containerIndex;
                            LastCorpeses[containerIndex] = 1;
                            Core.SleepRandom();
                            Corpse.Use(containerIndex);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        protected void GetTileDescription(Tile tile, NetworkMessage msg)
        {
            if (tile != null)
            {
                List <TileObject> objects = tile.Objects;
                objects.Insert(0, new TileObject(tile.Ground.Id, tile.Ground.Count, 0));

                foreach (TileObject o in objects)
                {
                    if (o.Id <= 0)
                    {
                        return;
                    }
                    else if (o.Id == 0x0061 || o.Id == 0x0062 || o.Id == 0x0063)
                    {
                        // Add a creature
                        Creature c = Client.BattleList.GetCreatures().FirstOrDefault(cr => cr.Id == o.Data);

                        if (c == null)
                        {
                            throw new Exception("Creature does not exist.");
                        }

                        // Add as unknown
                        msg.AddUInt16((ushort)o.Id);

                        // No need to remove a creature
                        msg.AddUInt32(0);

                        // Add the creature id
                        msg.AddUInt32((uint)c.Id);

                        msg.AddString(c.Name);

                        msg.AddByte((byte)c.HPBar);

                        msg.AddByte((byte)c.Direction);

                        msg.AddOutfit(c.Outfit);

                        msg.AddByte((byte)c.Light);

                        msg.AddByte((byte)c.LightColor);

                        msg.AddUInt16((ushort)c.WalkSpeed);

                        msg.AddByte((byte)c.Skull);

                        msg.AddByte((byte)c.PartyShield);
                    }
                    else if (o.Id <= 9999)
                    {
                        // Add an item
                        Item item = new Item(Client, (uint)o.Id, (byte)o.Data, "",
                                             ItemLocation.FromLocation(tile.Location, (byte)o.StackOrder));

                        msg.AddUInt16((ushort)o.Id);

                        try
                        {
                            if (item.HasExtraByte)
                            {
                                msg.AddByte(item.Count);
                            }
                        }
                        catch { }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        protected bool ParseThing(NetworkMessage msg, Location pos, Tile tile, int n, NetworkMessage outMsg)
        {
            //get thing type
            ushort thingId = msg.GetUInt16();

            outMsg.AddUInt16(thingId);

            PacketCreature c;

            if (thingId == 0x0061 || thingId == 0x0062)
            {
                c          = new PacketCreature(Client);
                c.Location = pos;

                //creatures
                if (thingId == 0x0062) //creature is known
                {
                    c.Type = PacketCreatureType.Known;
                    c.Id   = msg.GetUInt32();
                    outMsg.AddUInt32(c.Id); //creatureid
                }
                else if (thingId == 0x0061)
                { //creature is not known
                    //perhaps we have to remove a known creature
                    c.RemoveId = msg.GetUInt32();
                    outMsg.AddUInt32(c.RemoveId);

                    //add a new creature
                    c.Type = PacketCreatureType.Unknown;
                    c.Id   = msg.GetUInt32();
                    outMsg.AddUInt32(c.Id);

                    c.Name = msg.GetString();
                    outMsg.AddString(c.Name);
                }

                //read creature properties
                c.Health = msg.GetByte();
                outMsg.AddByte(c.Health);

                c.Direction = msg.GetByte();
                outMsg.AddByte(c.Direction);

                c.Outfit = msg.GetOutfit();
                outMsg.AddOutfit(c.Outfit);

                c.LightLevel = msg.GetByte();
                outMsg.AddByte(c.LightLevel);

                c.LightColor = msg.GetByte();
                outMsg.AddByte(c.LightColor);

                c.Speed = msg.GetUInt16();
                outMsg.AddUInt16(c.Speed);

                c.Skull = (Constants.Skull)msg.GetByte();
                outMsg.AddByte((byte)c.Skull);

                c.PartyShield = (Constants.PartyShield)msg.GetByte();
                outMsg.AddByte((byte)c.PartyShield);

                creatures.Add(c);

                return(true);
            }
            else if (thingId == 0x0063)
            {
                //creature turn
                c          = new PacketCreature(Client);
                c.Location = pos;
                c.Type     = PacketCreatureType.Turn;
                c.Id       = msg.GetUInt32();
                outMsg.AddUInt32(c.Id);

                c.Direction = msg.GetByte();
                outMsg.AddByte(c.Direction);

                creatures.Add(c);

                return(true);
            }
            else
            {
                //item
                UInt16 itemId;
                if (thingId == UInt16.MaxValue)
                {
                    itemId = msg.GetUInt16();
                    outMsg.AddUInt16(itemId);
                }
                else
                {
                    itemId = thingId;
                }

                Item item = new Item(Client, itemId, 0, "", ItemLocation.FromLocation(pos, (byte)n));

                if (item.HasExtraByte)
                {
                    item.Count = msg.GetByte();
                    outMsg.AddByte(item.Count);
                }

                if (n == 0)
                {
                    tile.Ground = item;
                }
                else
                {
                    tile.Items.Add(item);
                }

                return(true);
            }
        }