Esempio n. 1
0
    Color defaultGUI = Color.white; // set to white to avoid errors (Color is non-nullable)

    #endregion Fields

    #region Methods

    // add an item to the inventory
    public void AddItem(GroundItem i)
    {
        // only add items if there's room in the inventory
        if (!IsFull())
        {
            // create a new game object and give it a held item script
            GameObject toAdd = new GameObject(i.name);
            toAdd.AddComponent<HeldItem>();
            toAdd.GetComponent<HeldItem>().Initialize(i.GetComponent<SpriteRenderer>().sprite, i.cooldown);
            toAdd.GetComponent<HeldItem>().projectile = i.projectile;

            // add the new item to the inventory
            inv[currentItems] = toAdd;
            currentItems++;
            Destroy(i.gameObject);
            Debug.Log("Item \"" + toAdd.ToString() + "\" added to inventory");
        }
    }
Esempio n. 2
0
	void TempItemp_OnDisable(GroundItem obj)
	{
		if(obj == null) return;

        float left = Vector2.Distance(new Vector2(obj.gameObject.transform.position.x, obj.gameObject.transform.position.y), _leftPoint);
        float right = Vector2.Distance(new Vector2(obj.gameObject.transform.position.x, obj.gameObject.transform.position.y), _rightPoint);

        if(left < right)
		{
			obj.OnDisable -= TempItemp_OnDisable;
            _leftPoint = new Vector2(obj.gameObject.transform.position.x + _itemHalfWidth, _leftPoint.y);
		}
        else
		{
			obj.OnDisable -= TempItemp_OnDisable;
            _rightPoint = new Vector2(obj.gameObject.transform.position.x - _itemHalfWidth, _rightPoint.y);
		}
	}
Esempio n. 3
0
        public override void dropLoot()
        {
            Entity  killer = this.getKiller();
            Player  p      = killer is Player ? (Player)killer : null;
            NpcDrop drop   = this.npcDef.getDrop();

            if (killer == null || p == null)
            {
                return;
            }
            if (drop != null)
            {
                try {
                    List <Item> drops   = new List <Item>();
                    int         random  = misc.random(100);
                    int         random2 = 100 - random;
                    if (random2 == 0)
                    {
                        random2++;
                    }
                    if (random2 < 25)                   // 25% - semi rare
                    {
                        if (drop.getUncommonDrops() != null && drop.getUncommonDrops().Count > 0)
                        {
                            drops.Add(drop.getUncommonDrops()[misc.random(drop.getUncommonDrops().Count - 1)]);
                        }
                    }
                    else if (random2 >= 25 && random2 < 95)                     // 65%  common
                    {
                        if (drop.getCommonDrops() != null && drop.getCommonDrops().Count > 0)
                        {
                            drops.Add(drop.getCommonDrops()[misc.random(drop.getCommonDrops().Count - 1)]);
                        }
                    }
                    else if (random2 >= 95)                     // 5% - rare
                    {
                        if (drop.getRareDrops() != null && drop.getRareDrops().Count > 0)
                        {
                            drops.Add(drop.getRareDrops()[misc.random(drop.getRareDrops().Count - 1)]);
                        }
                    }
                    random = random2;
                    if (drop.getAlwaysDrops().Count != 0)
                    {
                        foreach (Item d in drop.getAlwaysDrops())
                        {
                            drops.Add(d);
                        }
                    }
                    foreach (Item each_drop in drops)
                    {
                        int amount = each_drop.getItemAmount();
                        int itemId = each_drop.getItemId();
                        if (amount < 0)
                        {
                            amount = misc.random((amount - (amount * 2)));
                            if (amount == 0)
                            {
                                amount = 1;
                            }
                        }
                        if (itemId == 8844)                       // defender
                        {
                            itemId = WarriorGuildData.DEFENDERS[((Player)killer).getDefenderWave()];
                        }
                        bool stackable = ItemData.forId(itemId).isNoted() || ItemData.forId(itemId).isStackable();
                        if (stackable || (!stackable && amount == 1))
                        {
                            if (Server.getGroundItems().addToStack(itemId, amount, this.getLocation(), p))
                            {
                            }
                            else
                            {
                                GroundItem item = new GroundItem(itemId, amount, this.getLocation(), p);
                                Server.getGroundItems().newEntityDrop(item);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < amount; i++)
                            {
                                GroundItem item = new GroundItem(itemId, 1, this.getLocation(), p);
                                Server.getGroundItems().newEntityDrop(item);
                            }
                        }
                    }
                } catch (Exception e) {
                    misc.WriteError("Error at npc dropLoot, msg=" + e.Message);
                }
            }
        }
 private static bool CannotBePickedUp(this GroundItem groundItem) => groundItem.Item.BagType == BagType.MAIN && groundItem.Item.Type == 3 && groundItem.Item.SubType == 0;
Esempio n. 5
0
        public CustomItem(LabelOnGround item, FilesContainer fs, float distance, Dictionary <string, int> weightsRules, bool isMetamorphItem = false)
        {
            if (isMetamorphItem)
            {
                IsMetaItem    = true;
                LabelOnGround = item;
                Distance      = distance;
                var itemItemOnGround = item.ItemOnGround;
                var worldIcon        = itemItemOnGround?.GetComponent <MinimapIcon>();
                if (worldIcon == null)
                {
                    return;
                }
                //var groundItem = worldItem.ItemEntity;
                WorldIcon  = worldIcon;
                GroundItem = itemItemOnGround;
                Path       = GroundItem?.Path;

                if (Path != null && Path.Length < 1)
                {
                    DebugWindow.LogMsg($"World2: {worldIcon.Address:X} P: {Path}", 2);
                    DebugWindow.LogMsg($"Ground2: {GroundItem.Address:X} P {Path}", 2);
                    return;
                }

                IsTargeted = () =>
                {
                    var isTargeted = itemItemOnGround.GetComponent <Targetable>()?.isTargeted;
                    return(isTargeted != null && (bool)isTargeted);
                };

                var baseItemType = fs.BaseItemTypes.Translate(Path);

                if (baseItemType != null)
                {
                    ClassName = baseItemType.ClassName;
                    BaseName  = baseItemType.BaseName;
                    Width     = baseItemType.Width;
                    Height    = baseItemType.Height;
                    if (weightsRules.TryGetValue(BaseName, out var w))
                    {
                        Weight = w;
                    }
                    if (ClassName.StartsWith("Heist"))
                    {
                        IsHeist = true;
                    }
                }

                IsValid = true;
            }
            else
            {
                isMetamorphItem = false;
                LabelOnGround   = item;
                Distance        = distance;
                var itemItemOnGround = item.ItemOnGround;
                var worldItem        = itemItemOnGround?.GetComponent <WorldItem>();
                if (worldItem == null)
                {
                    return;
                }
                var groundItem = worldItem.ItemEntity;
                GroundItem = groundItem;
                Path       = groundItem?.Path;
                if (GroundItem == null)
                {
                    return;
                }

                if (Path != null && Path.Length < 1)
                {
                    DebugWindow.LogMsg($"World: {worldItem.Address:X} P: {Path}", 2);
                    DebugWindow.LogMsg($"Ground: {GroundItem.Address:X} P {Path}", 2);
                    return;
                }

                IsTargeted = () =>
                {
                    var isTargeted = itemItemOnGround.GetComponent <Targetable>()?.isTargeted;
                    return(isTargeted != null && (bool)isTargeted);
                };

                var baseItemType = fs.BaseItemTypes.Translate(Path);

                if (baseItemType != null)
                {
                    ClassName = baseItemType.ClassName;
                    BaseName  = baseItemType.BaseName;
                    Width     = baseItemType.Width;
                    Height    = baseItemType.Height;
                    if (weightsRules.TryGetValue(BaseName, out var w))
                    {
                        Weight = w;
                    }
                    if (ClassName.StartsWith("Heist"))
                    {
                        IsHeist = true;
                    }
                }

                var WeaponClass = new List <string>
                {
                    "One Hand Mace",
                    "Two Hand Mace",
                    "One Hand Axe",
                    "Two Hand Axe",
                    "One Hand Sword",
                    "Two Hand Sword",
                    "Thrusting One Hand Sword",
                    "Bow",
                    "Claw",
                    "Dagger",
                    "Rune Dagger",
                    "Sceptre",
                    "Staff",
                    "Wand"
                };

                if (GroundItem.HasComponent <Quality>())
                {
                    var quality = GroundItem.GetComponent <Quality>();
                    Quality = quality.ItemQuality;
                }

                if (GroundItem.HasComponent <Base>())
                {
                    var @base = GroundItem.GetComponent <Base>();
                    IsElder    = @base.isElder;
                    IsShaper   = @base.isShaper;
                    IsHunter   = @base.isHunter;
                    IsRedeemer = @base.isRedeemer;
                    IsCrusader = @base.isCrusader;
                    IsWarlord  = @base.isWarlord;
                }

                if (GroundItem.HasComponent <Mods>())
                {
                    var mods = GroundItem.GetComponent <Mods>();
                    Rarity       = mods.ItemRarity;
                    IsIdentified = mods.Identified;
                    ItemLevel    = mods.ItemLevel;
                    IsFractured  = mods.HaveFractured;
                    IsVeiled     = mods.ItemMods.Any(m => m.DisplayName.Contains("Veil"));
                }

                if (GroundItem.HasComponent <Sockets>())
                {
                    var sockets = GroundItem.GetComponent <Sockets>();
                    IsRGB       = sockets.IsRGB;
                    Sockets     = sockets.NumberOfSockets;
                    LargestLink = sockets.LargestLinkSize;
                }

                if (GroundItem.HasComponent <Weapon>())
                {
                    IsWeapon = true;
                }

                MapTier = GroundItem.HasComponent <Map>() ? GroundItem.GetComponent <Map>().Tier : 0;
                IsValid = true;
            }
        }
 public static bool IsLever(this GroundItem groundItem) => groundItem.CannotBePickedUp() && groundItem.Item.Data[0] == 1000 || groundItem.Item.Data[0] == 1001;
 public static bool IsGold(this GroundItem groundItem) => groundItem.CannotBePickedUp() && groundItem.Item.Data[0] == 70;
Esempio n. 8
0
        public static void cutTree(Player p, ushort treeId, Location treeLocation, int i, bool newCut, int distance)
        {
            if (!newCut && p.getTemporaryAttribute("cuttingTree") == null)
            {
                return;
            }
            if (newCut)
            {
                if (i == 10 || i == 11)               // Magic or Yew tree.
                {
                    if (!Server.getGlobalObjects().objectExists(treeId, treeLocation))
                    {
                        //	misc.WriteError(p.getUsername() + " tried to cut a non existing Magic or Yew tree!");
                        //	return;
                    }
                }
                Tree newTree = new Tree(i, treeId, treeLocation, LOGS[i], LEVEL[i], TREE_NAME[i], XP[i], distance);
                p.setTemporaryAttribute("cuttingTree", newTree);
            }
            Tree treeToCut = (Tree)p.getTemporaryAttribute("cuttingTree");

            if (!canCut(p, treeToCut, null))
            {
                resetWoodcutting(p);
                return;
            }
            if (newCut)
            {
                p.setLastAnimation(new Animation(getAxeAnimation(p)));
                p.setFaceLocation(treeLocation);
                p.getPackets().sendMessage("You begin to swing your axe at the tree..");
            }
            int   delay        = getCutTime(p, treeToCut.getTreeIndex());
            Event cutTreeEvent = new Event(delay);

            cutTreeEvent.setAction(() => {
                cutTreeEvent.stop();
                if (p.getTemporaryAttribute("cuttingTree") == null)
                {
                    resetWoodcutting(p);
                    return;
                }
                Tree tree = (Tree)p.getTemporaryAttribute("cuttingTree");
                if (!canCut(p, treeToCut, tree))
                {
                    resetWoodcutting(p);
                    return;
                }
                Server.getGlobalObjects().lowerHealth(tree.getTreeId(), tree.getTreeLocation());
                if (!Server.getGlobalObjects().originalObjectExists(tree.getTreeId(), tree.getTreeLocation()))
                {
                    resetWoodcutting(p);
                    p.setLastAnimation(new Animation(65535));
                }
                if (p.getInventory().addItem(tree.getLog()))
                {
                    p.getPackets().closeInterfaces();
                    int index = tree.getTreeIndex();
                    string s  = index == 1 || index == 3 || index == 8 ? "an" : "a";
                    p.getSkills().addXp(Skills.SKILL.WOODCUTTING, tree.getXp());
                    if (index == 6)
                    {
                        p.getPackets().sendMessage("You retrieve some Hollow bark from the tree.");
                    }
                    else
                    {
                        p.getPackets().sendMessage("You cut down " + s + " " + tree.getName() + " log.");
                    }
                    if (misc.random(3) == 0)
                    {
                        int nestId   = misc.random(10) == 0 ? 5073 : 5074;
                        GroundItem g = new GroundItem(nestId, 1, new Location(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ()), p);
                        Server.getGroundItems().newEntityDrop(g);
                        p.getPackets().sendMessage("Something falls out of the tree and lands at your feet.");
                    }
                }
                cutTree(p, tree.getTreeId(), tree.getTreeLocation(), tree.getTreeIndex(), false, tree.getDistance());
            });
            Server.registerEvent(cutTreeEvent);
            if (delay >= 2550)
            {
                Event treeCuttingAnimationEvent = new Event(2550);
                int   time = delay;
                treeCuttingAnimationEvent.setAction(() => {
                    time -= 2550;
                    if (time <= 0)
                    {
                        treeCuttingAnimationEvent.stop();
                    }
                    Tree tree = (Tree)p.getTemporaryAttribute("cuttingTree");
                    if (!canCut(p, treeToCut, tree))
                    {
                        treeCuttingAnimationEvent.stop();
                        return;
                    }
                    p.setFaceLocation(treeLocation);
                    p.setLastAnimation(new Animation(getAxeAnimation(p)));
                });
                Server.registerEvent(treeCuttingAnimationEvent);
            }
        }
Esempio n. 9
0
        public CustomItem(LabelOnGround item, FilesContainer fs, float distance)
        {
            LabelOnGround = item;
            Distance      = distance;
            var itemItemOnGround = item.ItemOnGround;
            var worldItem        = itemItemOnGround?.GetComponent <WorldItem>();

            if (worldItem == null)
            {
                return;
            }
            var groundItem = worldItem.ItemEntity;

            GroundItem = groundItem;
            Path       = groundItem?.Path;
            if (GroundItem == null)
            {
                return;
            }

            if (Path != null && Path.Length < 1)
            {
                DebugWindow.LogMsg($"World: {worldItem.Address:X} P: {Path}", 2);
                DebugWindow.LogMsg($"Ground: {GroundItem.Address:X} P {Path}", 2);
                return;
            }

            IsTargeted = () =>
            {
                var isTargeted = itemItemOnGround.GetComponent <Targetable>()?.isTargeted;
                return(isTargeted != null && (bool)isTargeted);
            };

            var baseItemType = fs.BaseItemTypes.Translate(Path);

            if (baseItemType != null)
            {
                ClassName = baseItemType.ClassName;
                BaseName  = baseItemType.BaseName;
                Width     = baseItemType.Width;
                Height    = baseItemType.Height;
            }

            var WeaponClass = new List <string>
            {
                "One Hand Mace",
                "Two Hand Mace",
                "One Hand Axe",
                "Two Hand Axe",
                "One Hand Sword",
                "Two Hand Sword",
                "Thrusting One Hand Sword",
                "Bow",
                "Claw",
                "Dagger",
                "Sceptre",
                "Staff",
                "Wand"
            };

            if (GroundItem.HasComponent <Quality>())
            {
                var quality = GroundItem.GetComponent <Quality>();
                Quality = quality.ItemQuality;
            }

            if (GroundItem.HasComponent <Base>())
            {
                var @base = GroundItem.GetComponent <Base>();
                IsElder  = @base.isElder;
                IsShaper = @base.isShaper;
            }

            if (GroundItem.HasComponent <Mods>())
            {
                var mods = GroundItem.GetComponent <Mods>();
                Rarity       = mods.ItemRarity;
                IsIdentified = mods.Identified;
                ItemLevel    = mods.ItemLevel;
                IsFractured  = mods.HaveFractured;
            }

            if (GroundItem.HasComponent <Sockets>())
            {
                var sockets = GroundItem.GetComponent <Sockets>();
                IsRGB       = sockets.IsRGB;
                Sockets     = sockets.NumberOfSockets;
                LargestLink = sockets.LargestLinkSize;
            }

            if (WeaponClass.Any(ClassName.Equals))
            {
                IsWeapon = true;
            }

            MapTier = GroundItem.HasComponent <Map>() ? GroundItem.GetComponent <Map>().Tier : 0;
            IsValid = true;
        }
Esempio n. 10
0
        public override void dropLoot()
        {
            Entity killer = this.getKiller();
            Player klr    = killer is Npc ? null : (Player)killer;

            if (klr == null)
            {
                klr = this;
            }
            int amountToKeep = isSkulled() ? 0 : 3;

            if (prayers.isProtectItem())
            {
                amountToKeep = isSkulled() ? 1 : 4;
            }

            /*
             * Meh wanted to make a much more effient system.
             * //price of item, [item, object[]=(inventory/euqipment)]
             * //Inventory Items
             * SortedDictionary<int, object[]> valueSortedItems = new SortedDictionary<int, object[]>();
             * Item item;
             * int price = 0;
             * for(int i = 0; i < Inventory.MAX_INVENTORY_SLOTS; i++) {
             *  item = inventory.getSlot(i);
             *  if(item.getItemId() != -1 && item.getItemAmount() > 0) { //is real item.
             *      //price of item stacked
             *      price = item.getItemAmount() * item.getDefinition().getPrice().getMaximumPrice();
             *      valueSortedItems.Add(price, new object[] {item, 0});
             *  }
             * }
             * //Equipment Items
             * for(int i = 0; i < 14; i++) {
             *  item = equipment.getSlot(i);
             *  if(item.getItemId() != -1 && item.getItemAmount() > 0) { //is real item.
             *      //price of item stacked
             *      price = item.getItemAmount() * item.getDefinition().getPrice().getMaximumPrice();
             *      valueSortedItems.Add(price, new object[] {item, 1});
             *  }
             * }*/

            int[]  protectedItems = new int[amountToKeep];
            bool[] saved          = new bool[amountToKeep];
            if (protectedItems.Length > 0)
            {
                protectedItems[0] = ProtectedItems.getProtectedItem1(this)[0];
            }
            if (protectedItems.Length > 1)
            {
                protectedItems[1] = ProtectedItems.getProtectedItem2(this)[0];
            }
            if (protectedItems.Length > 2)
            {
                protectedItems[2] = ProtectedItems.getProtectedItem3(this)[0];
            }
            if (protectedItems.Length > 3)
            {
                protectedItems[3] = ProtectedItems.getProtectedItem4(this)[0];
            }
            bool save = false;

            for (int i = 0; i < 28; i++)
            {
                save = false;
                Item item = inventory.getSlot(i);
                if (item.getItemId() > 0)
                {
                    for (int j = 0; j < protectedItems.Length; j++)
                    {
                        if (amountToKeep > 0 && protectedItems[j] > 0)
                        {
                            if (!saved[j] && !save)
                            {
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() == 1)
                                {
                                    saved[j] = true;
                                    save     = true;
                                }
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() > 1)
                                {
                                    item.setItemAmount(item.getItemAmount() - 1);
                                    saved[j] = true;
                                    save     = true;
                                }
                            }
                        }
                    }
                    if (!save)
                    {
                        int itemId = item.getItemId();
                        if (itemId >= 4708 && itemId <= 4759)
                        {
                            itemId = BrokenBarrows.getBrokenId(itemId);
                        }
                        GroundItem gi = new GroundItem(itemId, item.getItemAmount(), this.getLocation(), item.getDefinition().isPlayerBound() ? this : klr);
                        Server.getGroundItems().newEntityDrop(gi);
                    }
                }
            }
            inventory.clearAll();
            saved = new bool[amountToKeep];
            foreach (ItemData.EQUIP equip in Enum.GetValues(typeof(ItemData.EQUIP)))
            {
                if (equip == ItemData.EQUIP.NOTHING)
                {
                    continue;
                }
                save = false;
                Item item = this.getEquipment().getSlot(equip);
                if (item.getItemId() > 0)
                {
                    for (int j = 0; j < protectedItems.Length; j++)
                    {
                        if (amountToKeep > 0 && protectedItems[j] > -1)
                        {
                            if (!saved[j] && !save)
                            {
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() == 1)
                                {
                                    saved[j] = true;
                                    save     = true;
                                }
                                if (item.getItemId() == protectedItems[j] && item.getItemAmount() > 1)
                                {
                                    item.setItemAmount(item.getItemAmount() - 1);
                                    saved[j] = true;
                                    save     = true;
                                }
                            }
                        }
                    }
                    if (!save)
                    {
                        int itemId = item.getItemId();
                        if (itemId >= 4708 && itemId <= 4759)
                        {
                            itemId = BrokenBarrows.getBrokenId(itemId);
                        }
                        GroundItem gi = new GroundItem(itemId, item.getItemAmount(), this.getLocation(), item.getDefinition().isPlayerBound() ? this : klr);
                        Server.getGroundItems().newEntityDrop(gi);
                    }
                }
            }
            equipment.clearAll();
            GroundItem bones = new GroundItem(526, 1, this.getLocation(), klr);

            Server.getGroundItems().newEntityDrop(bones);
            inventory.setProtectedItems(protectedItems);
        }