Beispiel #1
0
        public static bool IsItemUseable(BaseInventory inventoryContext)
        {
            //Never auto-use from the ground
            if (inventoryContext == null)
            {
                return(false);
            }

            //List of Contexts where it is not okay to auto-use
            List <int> invalidContexts = new List <int>
            {
                BaseInventory.INVENTORY_TYPE_BUYIER,
                BaseInventory.INVENTORY_TYPE_CRAFTING,
                BaseInventory.INVENTORY_TYPE_NONE,
                BaseInventory.INVENTORY_TYPE_NPC,
                BaseInventory.INVENTORY_TYPE_SHOP
            };

            if (invalidContexts.Contains(inventoryContext.inventoryType))
            {
                return(false);
            }

            //Other selection may happen here

            return(true);
        }
Beispiel #2
0
        public FruitTree(BuildingDef def, string layerName, MapSpot anchor, IMapController controller, MapRotation rotation) : base(def, layerName, anchor, controller, rotation)
        {
            _stageLengths = new List <Dictionary <string, int> >();
            _stageLengths.Add(new Dictionary <string, int> {
                { "HOUR", 1 }
            });
            _stageLengths.Add(new Dictionary <string, int> {
                { "HOUR", 1 }
            });
            _stageLengths.Add(new Dictionary <string, int> {
                { "HOUR", 1 }
            });

            var outputConfif = new InventoryConfig()
            {
                CanProvideItems    = true,
                CanReceiveItems    = false,
                HasMassLimit       = false,
                MaxMass            = -1,
                RespectsStackLimit = false
            };

            var timeKeeper = GameMaster.Instance.GetController <ITimeKeeper>();

            _timeKeeper      = timeKeeper;
            _finishDate      = timeKeeper.ProjectTime(_stageLengths[0]);
            _outputInventory = new DefaultInventory(GameMaster.Instance.GetController <IItemController>(), this, outputConfif);
        }
Beispiel #3
0
        public override void Respawn()
        {
            SetModel("models/citizen/citizen.vmdl");

            //
            // Use WalkController for movement (you can make your own PlayerController for 100% control)
            //
            Controller = new RunnerPlayerController();

            //
            // Use StandardPlayerAnimator  (you can make your own PlayerAnimator for 100% control)
            //
            Animator = new StandardPlayerAnimator();

            //
            // Use ThirdPersonCamera (you can make your own Camera for 100% control)
            //
            CameraMode = new FirstPersonCamera();

            Inventory = new BaseInventory(this);

            EnableAllCollisions       = true;
            EnableDrawing             = true;
            EnableHideInFirstPerson   = true;
            EnableShadowInFirstPerson = true;

            base.Respawn();
        }
Beispiel #4
0
		public SearchSlotId(bool inclBank)
		{
			Container = null;
			Slot = 0;
			InclBank = inclBank;
			SearchPos = 0;
		}
Beispiel #5
0
        /// <summary>
        /// Try to loot the item at the given index of the current loot
        /// </summary>
        /// <returns>The looted Item or null if Item could not be taken</returns>
        public void TakeItem(LooterEntry entry, uint index, BaseInventory targetCont, int targetSlot)
        {
            LootItem lootItem = (LootItem)null;

            try
            {
                Character owner = entry.Owner;
                if (owner == null || (long)index >= (long)this.Items.Length)
                {
                    return;
                }
                lootItem = this.Items[index];
                InventoryError itemConditions = this.CheckTakeItemConditions(entry, lootItem);
                if (itemConditions == InventoryError.OK)
                {
                    this.HandoutItem(owner, lootItem, targetCont, targetSlot);
                }
                else
                {
                    ItemHandler.SendInventoryError((IPacketReceiver)owner.Client, (Item)null, (Item)null,
                                                   itemConditions);
                }
            }
            catch (Exception ex)
            {
                LogUtil.ErrorException(ex, "{0} threw an Exception while looting \"{1}\" (index = {2}) from {3}",
                                       (object)entry.Owner, (object)lootItem, (object)index, (object)targetCont);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Try to loot the item at the given index of the current loot
        /// </summary>
        /// <returns>The looted Item or null if Item could not be taken</returns>
        public void TakeItem(LooterEntry entry, uint index, BaseInventory targetCont, int targetSlot)
        {
            LootItem lootItem = null;

            try
            {
                var chr = entry.Owner;
                if (chr != null && index < Items.Length)
                {
                    lootItem = Items[index];
                    var err = CheckTakeItemConditions(entry, lootItem);
                    if (err == InventoryError.OK)
                    {
                        HandoutItem(chr, lootItem, targetCont, targetSlot);
                    }
                    else
                    {
                        ItemHandler.SendInventoryError(chr.Client, null, null, err);
                    }
                }
            }
            catch (Exception e)
            {
                LogUtil.ErrorException(e, "{0} threw an Exception while looting \"{1}\" (index = {2}) from {3}",
                                       entry.Owner, lootItem, index, targetCont);
            }
        }
Beispiel #7
0
    public void SetTrackedInventory(BaseInventory inventory)
    {
        _tracked_inventory = inventory;

        if (tracking)
        {
            placed_pieces = new int[Database.base_pieces.max_id + 1];
            placed_groups = new int[Database.enemy_groups.max_id + 1];
        }
    }
Beispiel #8
0
        /// <summary>
        /// Hands out the given LootItem to the given Character.
        /// </summary>
        /// <remarks>Adds the given container at the given slot or -if not specified- to the next free slot</remarks>
        /// <param name="chr"></param>
        /// <param name="lootItem"></param>
        /// <param name="targetCont"></param>
        /// <param name="targetSlot"></param>
        public void HandoutItem(Character chr, LootItem lootItem, BaseInventory targetCont, int targetSlot)
        {
            InventoryError err;
            var            multiLooters = lootItem.MultiLooters;

            int amount;

            if (targetCont != null)
            {
                // specific slot
                amount = lootItem.Amount;
                if (!targetCont.IsValidSlot(targetSlot) || targetCont.Items[targetSlot] != null)
                {
                    // slot is not valid or occupied
                    err = targetCont.TryAdd(lootItem.Template, ref amount, ItemReceptionType.Loot);
                }
                else
                {
                    err = targetCont.TryAdd(lootItem.Template, ref amount, targetSlot, ItemReceptionType.Loot);
                }
            }
            else
            {
                // auto loot
                amount = lootItem.Amount;
                //err = chr.Inventory.TryAdd(lootItem.Template, ref amount);
                err = chr.Inventory.TryAdd(lootItem.Template, ref amount, ItemReceptionType.Loot);
            }

            if (err == InventoryError.OK)
            {
                if (amount < lootItem.Amount && multiLooters == null)
                {
                    // Only a part of the item stack was added, a part remains
                    // TODO: Amount changed, but amount displayed to looters is still the same (SMSG_LOOT_ITEM_NOTIFY?)
                    lootItem.Amount = amount;
                }

                if (multiLooters != null)
                {
                    multiLooters.Remove(chr.LooterEntry);
                }
                if (multiLooters == null || multiLooters.Count == 0)
                {
                    RemoveItem(lootItem);
                }
                chr.Achievements.CheckPossibleAchievementUpdates(Constants.Achievements.AchievementCriteriaType.LootItem, (uint)lootItem.Template.ItemId, (uint)lootItem.Amount);
            }
            else
            {
                ItemHandler.SendInventoryError(chr.Client, null, null, err);
            }
        }
        private void BinarySerialize(BaseInventory inventory)
        {
            var        serializedFile = Path.GetTempPath() + string.Format("/__InventoryTest__.bin");
            IFormatter formatter      = new BinaryFormatter();
            Stream     stream         = new FileStream(serializedFile,
                                                       FileMode.Create,
                                                       FileAccess.Write,
                                                       FileShare.None);

            formatter.Serialize(stream, inventory);
            stream.Close();
        }
Beispiel #10
0
 public static void ConvertInventory(BaseInventory inventory)
 {
     //Replaces each item in each slot with a useable version
     for (int i = 0; i < inventory.slots.Count; i++)
     {
         for (int itemNo = 0; itemNo < inventory.slots[i].items.Count; itemNo++)
         {
             BaseItem item = inventory.slots[i].items[itemNo];
             inventory.slots[i].items[itemNo] = ConvertToUseable(item);
         }
     }
 }
Beispiel #11
0
    void Start()
    {
        player_rigidbody2D = this.GetComponent<Rigidbody2D>();
        player_animator = this.GetComponent<Animator>();
        //player_collider = this.GetComponent<Collider2D>();
        //interactableList = this.GetComponent<InteractableList>();
        playerInventory = this.GetComponent<BaseInventory>();

        player_rigidbody2D.freezeRotation = true;

        playerInventory.AddItemToInventory("Old Sword");
        playerInventory.AddItemToInventory("Steel Sword");
        playerInventory.AddItemToInventory("Infernal Sword");
    }
        private BaseInventory BinaryDeserialize(BaseInventory stats)
        {
            var        serializedFile = Path.GetTempPath() + string.Format("/__InventoryTest__.bin");
            IFormatter formatter      = new BinaryFormatter();
            Stream     stream         = new FileStream(serializedFile,
                                                       FileMode.Open,
                                                       FileAccess.Read,
                                                       FileShare.Read);
            BaseInventory serializedStats = (BaseInventory)formatter.Deserialize(stream);

            stream.Close();
            File.Delete(serializedFile);
            return(serializedStats);
        }
        private void TestInventory(BaseInventory original, BaseInventory serialized)
        {
            var items                = original.Items.GetEnumerator();
            var quantities           = original.Quantities.GetEnumerator();
            var serializedItems      = serialized.Items.GetEnumerator();
            var serializedQuantities = serialized.Quantities.GetEnumerator();

            while (items.MoveNext() && quantities.MoveNext() &&
                   serializedItems.MoveNext() && serializedQuantities.MoveNext())
            {
                Assert.AreEqual(items.Current, serializedItems.Current);
                Assert.AreEqual(quantities.Current, serializedQuantities.Current);
            }
        }
Beispiel #14
0
        private bool CheckFreeSlots(IList <SimpleSlotId> myFreeSlots, Item[] items)
        {
            bool flag   = true;
            int  index1 = 0;

            for (int index2 = 0; index2 < 6; ++index2)
            {
                if (items[index2] != null)
                {
                    if (myFreeSlots.Count <= index1)
                    {
                        flag = false;
                        break;
                    }

                    int              slot      = myFreeSlots[index1].Slot;
                    BaseInventory    container = myFreeSlots[index1].Container;
                    IItemSlotHandler handler   = container.GetHandler(slot);
                    InventoryError   err       = InventoryError.OK;
                    handler.CheckAdd(slot, items[index2].Amount, items[index2], ref err);
                    if (err != InventoryError.OK)
                    {
                        flag = false;
                        break;
                    }

                    int amount = items[index2].Amount;
                    container.CheckUniqueness(items[index2], ref amount, ref err, true);
                    if (err != InventoryError.OK)
                    {
                        flag = false;
                        break;
                    }

                    ++index1;
                }
            }

            if (!flag)
            {
                m_chr.SendSystemMessage("You don't have enough free slots");
                m_otherWindow.m_chr.SendSystemMessage("Other party doesn't have enough free slots");
                SendStatus(TradeStatus.StateChanged, true);
            }

            return(flag);
        }
Beispiel #15
0
    /// <summary>
    /// Display the Model in the Editor.</summary>
    void DrawInventory(BaseInventory inventory)
    {
        var items      = inventory.Items.GetEnumerator();
        var quantities = inventory.Quantities.GetEnumerator();

        while (items.MoveNext() && quantities.MoveNext())
        {
            EditorGUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField(ItemDatabase.GetItemById(items.Current).Name, GUILayout.Width(133));
            EditorGUILayout.LabelField("x" + quantities.Current.ToString(), GUILayout.Width(30));

            if (GUILayout.Button("+", GUILayout.Width(18)))
            {
                inventory.AddItem(items.Current, 1);
                EditorUtility.SetDirty(target);
                EditorGUILayout.EndHorizontal();
            }
            else if (GUILayout.Button("-", GUILayout.Width(18)))
            {
                inventory.RemoveItem(items.Current, 1);
                EditorUtility.SetDirty(target);
                EditorGUILayout.EndHorizontal();
            }
            else if (GUILayout.Button("X", GUILayout.Width(18)))
            {
                inventory.RemoveItem(items.Current, quantities.Current);
                EditorUtility.SetDirty(target);
                EditorGUILayout.EndHorizontal();
                break;
            }
            else
            {
                EditorGUILayout.EndHorizontal();
            }
        }

        //if (GUILayout.Button("Reset"))
        //{
        //    inventory.Reset();
        //    EditorUtility.SetDirty(inventory);
        //}
    }
Beispiel #16
0
        /// <summary>
        /// Reset and initialize the entire view based on the given Inventory.</summary>
        private void InitFromInventory(BaseInventory inventory)
        {
            // Reset the inventory
            foreach (KeyValuePair <int, SlottableItem> entry in _items)
            {
                Destroy(entry.Value.gameObject);
            }
            _items.Clear();
            NumberOfSlots = inventory.ItemCount;
            ResetSlots();

            // Add the Items from the Inventory
            var items      = inventory.Items.GetEnumerator();
            var quantities = inventory.Quantities.GetEnumerator();

            while (items.MoveNext() && quantities.MoveNext())
            {
                AddItem(items.Current, quantities.Current);
            }
        }
    /// <summary>
    /// Display the Model in the Editor.</summary>
    void DrawInventory(BaseInventory inventory, Loot loot)
    {
        for (int i = 0; i < loot._serializedInventoryItems.Length; i++)
        {
            int item     = loot._serializedInventoryItems[i];
            int quantity = loot._serializedInventoryQuantities[i];

            EditorGUILayout.BeginHorizontal("box");
            EditorGUILayout.LabelField(ItemDatabase.GetItemById(item).Name, GUILayout.Width(133));
            EditorGUILayout.LabelField("x" + quantity.ToString(), GUILayout.Width(30));

            if (GUILayout.Button("+", GUILayout.Width(18)))
            {
                inventory.AddItem(item, 1);
                EditorUtility.SetDirty(target);
                loot.OnBeforeSerialize();
                EditorGUILayout.EndHorizontal();
            }
            else if (GUILayout.Button("-", GUILayout.Width(18)))
            {
                inventory.RemoveItem(item, 1);
                EditorUtility.SetDirty(target);
                loot.OnBeforeSerialize();
                EditorGUILayout.EndHorizontal();
            }
            else if (GUILayout.Button("X", GUILayout.Width(18)))
            {
                inventory.RemoveItem(item, quantity);
                EditorUtility.SetDirty(target);
                loot.OnBeforeSerialize();
                EditorGUILayout.EndHorizontal();
                break;
            }
            else
            {
                EditorGUILayout.EndHorizontal();
            }
        }
    }
Beispiel #18
0
 /// <summary>Hands out the given LootItem to the given Character.</summary>
 /// <remarks>Adds the given container at the given slot or -if not specified- to the next free slot</remarks>
 /// <param name="chr"></param>
 /// <param name="lootItem"></param>
 /// <param name="targetCont"></param>
 /// <param name="targetSlot"></param>
 public void HandoutItem(Character chr, LootItem lootItem, BaseInventory targetCont, int targetSlot)
 {
 }
Beispiel #19
0
        /// <summary>
        /// Hands out the given LootItem to the given Character.
        /// </summary>
        /// <remarks>Adds the given container at the given slot or -if not specified- to the next free slot</remarks>
        /// <param name="chr"></param>
        /// <param name="lootItem"></param>
        /// <param name="targetCont"></param>
        /// <param name="targetSlot"></param>
        public void HandoutItem(Character chr, LootItem lootItem, BaseInventory targetCont, int targetSlot)
        {
            InventoryError err;
            var multiLooters = lootItem.MultiLooters;

            int amount;
            if (targetCont != null)
            {
                // specific slot
                amount = lootItem.Amount;
                if (!targetCont.IsValidSlot(targetSlot) || targetCont.Items[targetSlot] != null)
                {
                    // slot is not valid or occupied
                    err = targetCont.TryAdd(lootItem.Template, ref amount, ItemReceptionType.Loot);
                }
                else
                {
                    err = targetCont.TryAdd(lootItem.Template, ref amount, targetSlot, ItemReceptionType.Loot);
                }
            }
            else
            {
                // auto loot
                amount = lootItem.Amount;
                //err = chr.Inventory.TryAdd(lootItem.Template, ref amount);
                err = chr.Inventory.TryAdd(lootItem.Template, ref amount, ItemReceptionType.Loot);
            }

            if (err == InventoryError.OK)
            {
                if (amount < lootItem.Amount && multiLooters == null)
                {
                    // Only a part of the item stack was added, a part remains
                    // TODO: Amount changed, but amount displayed to looters is still the same (SMSG_LOOT_ITEM_NOTIFY?)
                    lootItem.Amount = amount;
                }

                if (multiLooters != null)
                {
                    multiLooters.Remove(chr.LooterEntry);
                }
                if (multiLooters == null || multiLooters.Count == 0)
                {
                    RemoveItem(lootItem);
                }
                chr.Achievements.CheckPossibleAchievementUpdates(Constants.Achievements.AchievementCriteriaType.LootItem, (uint)lootItem.Template.ItemId, (uint)lootItem.Amount);
            }
            else
            {
                ItemHandler.SendInventoryError(chr.Client, null, null, err);
            }
        }
Beispiel #20
0
 public ExtractionPlayer()
 {
     Inventory = new BaseInventory(this);
 }
Beispiel #21
0
 /// <summary>
 /// Opens the <c>BaseInventory</c> -> <paramref name="inventory"/>
 /// </summary>
 /// <param name="inventory">Inventory to open</param>
 public void InventoryOpened(BaseInventory inventory)
 {
     InventoryManager.OpenInventory   = inventory;
     InventoryManager.IsInventoryOpen = true;
 }
Beispiel #22
0
 public DeathmatchPlayer()
 {
     Inventory = new BaseInventory(this);
     EnableClientsideAnimation = true;
 }
Beispiel #23
0
Datei: Loot.cs Projekt: NVN/WCell
		/// <summary>
		/// Hands out the given LootItem to the given Character.
		/// </summary>
		/// <remarks>Adds the given container at the given slot or -if not specified- to the next free slot</remarks>
		/// <param name="chr"></param>
		/// <param name="lootItem"></param>
		/// <param name="targetCont"></param>
		/// <param name="targetSlot"></param>
		public void HandoutItem(Character chr, LootItem lootItem, BaseInventory targetCont, int targetSlot)
		{
			InventoryError err;
			var multiLooters = lootItem.MultiLooters;

			int amount;
			if (targetCont != null)
			{
				// specific slot
				amount = lootItem.Amount;
				if (!targetCont.IsValidSlot(targetSlot))
				{
					err = targetCont.TryAdd(lootItem.Template, ref amount, true);
				}
				else
				{
					err = targetCont.TryAdd(lootItem.Template, ref amount, targetSlot, true);
				}
			}
			else
			{
				// auto loot
				amount = lootItem.Amount;
				//err = chr.Inventory.TryAdd(lootItem.Template, ref amount);
				err = chr.Inventory.TryAdd(lootItem.Template, ref amount);
			}

			if (err == InventoryError.OK)
			{
				if (amount < lootItem.Amount && multiLooters == null)
				{
					// Only a part of the item stack was added, a part remains
					// TODO: Amount changed, but amount displayed to looters is still the same (SMSG_LOOT_ITEM_NOTIFY?)
					lootItem.Amount = amount;
				}

				if (multiLooters != null)
				{
					multiLooters.Remove(chr.LooterEntry);
				}
				if (multiLooters == null || multiLooters.Count == 0)
				{
					RemoveItem(lootItem);
				}
			}
			else
			{
				ItemHandler.SendInventoryError(chr.Client, null, null, err);
			}
		}
Beispiel #24
0
        public void BuyItem(Character chr, uint itemEntryId, BaseInventory bag, int amount, int slot)
        {
            if (!CheckVendorInteraction(chr))
                return;

            var item = GetVendorItem(itemEntryId);
            if (item == null)
                return;

            amount = Math.Max(amount, 1);
            if (item.BuyStackSize > 0)
            {
                amount = amount * item.BuyStackSize;
            }

            uint price;
            var buyErr = CanPlayerBuyItem(chr, item, amount, out price);
            if (buyErr != BuyItemError.Ok)
            {
                NPCHandler.SendBuyError(chr, NPC, item.Template.ItemId, buyErr);
                return;
            }

            BaseInventory inv = chr.Inventory;
            InventoryError err;
            if (inv.IsValidSlot(slot))
            {
                err = inv.TryAdd(item.Template, ref amount, slot);
            }
            else
            {
                // count will be set to the actual amount of items that found space in the inventory
                // if not all could be added, err contains the reason why
                err = inv.TryAdd(item.Template, ref amount);
            }

            if (err != InventoryError.OK)
            {
                ItemHandler.SendInventoryError(chr.Client, null, null, err);
            }

            if (amount <= 0)
            {
                // Nothing was purchased
                // Should usually never happen, but just to make sure
                ItemHandler.SendInventoryError(chr.Client, null, null, InventoryError.INVENTORY_FULL);
                return;
            }

            chr.Money -= (price * (uint)amount); // we already checked that our money is sufficient
            if (item.ExtendedCostEntry != null)
            {
                var exCost = item.ExtendedCostEntry;

                chr.HonorPoints -= exCost.HonorCost;
                chr.ArenaPoints -= exCost.ArenaPointCost;

                foreach (var reqItem in exCost.RequiredItems)
                {
                    if (reqItem.Id == ItemId.None)
                    {
                        break;
                    }

                    if (!chr.Inventory.RemoveByItemId(reqItem.Id, reqItem.Cost, false))
                    {
                        // should not happen
                        LogManager.GetCurrentClassLogger().Warn("Unable to remove required item \"{0}\" from player \"{1}\" when purchasing item: {2}",
                            reqItem.Template, chr, item.Template);
                    }
                }
            }

            // manage stock
            int remainingAmount;
            if (item.RemainingStockAmount != UnlimitedSupply)
            {
                // The vendor had a limited supply of this item, update the chr.Client with the new inventory
                remainingAmount = item.RemainingStockAmount - amount;
                //NPCHandler.SendVendorInventoryList(chr.Client, NPC.EntityId, ConstructVendorItemList(chr));
            }
            else
            {
                remainingAmount = UnlimitedSupply;
            }

            // send packet
            NPCHandler.SendBuyItem(chr.Client, NPC, item.Template.ItemId, amount, remainingAmount);
        }
Beispiel #25
0
 public void BuyItem(Character chr, uint itemEntryId, BaseInventory bag, int amount, int slot)
 {
 }
Beispiel #26
0
        public void BuyItem(Character chr, uint itemEntryId, BaseInventory bag, int amount, int slot)
        {
            if (!CheckVendorInteraction(chr))
            {
                return;
            }

            var item = GetVendorItem(itemEntryId);

            if (item == null)
            {
                return;
            }

            amount = Math.Max(amount, 1);
            if (item.BuyStackSize > 0)
            {
                amount = amount * item.BuyStackSize;
            }

            uint price;
            var  buyErr = CanPlayerBuyItem(chr, item, amount, out price);

            if (buyErr != BuyItemError.Ok)
            {
                NPCHandler.SendBuyError(chr, NPC, item.Template.ItemId, buyErr);
                return;
            }

            BaseInventory  inv = chr.Inventory;
            InventoryError err;

            if (inv.IsValidSlot(slot))
            {
                err = inv.TryAdd(item.Template, ref amount, slot);
            }
            else
            {
                // count will be set to the actual amount of items that found space in the inventory
                // if not all could be added, err contains the reason why
                err = inv.TryAdd(item.Template, ref amount);
            }

            if (err != InventoryError.OK)
            {
                ItemHandler.SendInventoryError(chr.Client, null, null, err);
            }

            if (amount <= 0)
            {
                // Nothing was purchased
                // Should usually never happen, but just to make sure
                ItemHandler.SendInventoryError(chr.Client, null, null, InventoryError.INVENTORY_FULL);
                return;
            }

            chr.Money -= (price * (uint)amount);             // we already checked that our money is sufficient
            if (item.ExtendedCostEntry != null)
            {
                var exCost = item.ExtendedCostEntry;

                chr.HonorPoints -= exCost.HonorCost;
                chr.ArenaPoints -= exCost.ArenaPointCost;

                foreach (var reqItem in exCost.RequiredItems)
                {
                    if (reqItem.Id == ItemId.None)
                    {
                        break;
                    }

                    if (!chr.Inventory.RemoveByItemId(reqItem.Id, reqItem.Cost, false))
                    {
                        // should not happen
                        LogManager.GetCurrentClassLogger().Warn("Unable to remove required item \"{0}\" from player \"{1}\" when purchasing item: {2}",
                                                                reqItem.Template, chr, item.Template);
                    }
                }
            }

            // manage stock
            int remainingAmount;

            if (item.RemainingStockAmount != UnlimitedSupply)
            {
                // The vendor had a limited supply of this item, update the chr.Client with the new inventory
                remainingAmount = item.RemainingStockAmount - amount;
                //NPCHandler.SendVendorInventoryList(chr.Client, NPC.EntityId, ConstructVendorItemList(chr));
            }
            else
            {
                remainingAmount = UnlimitedSupply;
            }

            // send packet
            NPCHandler.SendBuyItem(chr.Client, NPC, item.Template.ItemId, amount, remainingAmount);
        }
Beispiel #27
0
		/// <summary>
		/// Moves an item from one slot to another.
		/// Core method for moving items around.
		/// </summary>
		public InventoryError TrySwap(BaseInventory srcCont, int srcSlot, BaseInventory destCont, int destSlot)
		{
			var err = InventoryError.OK;
			Item srcItem = null;
			Item destItem = null;
			Item occupyingWeapon = null;

			if (!srcCont.IsValidSlot(srcSlot))
			{
				err = InventoryError.ITEM_NOT_FOUND;
			}
			else if (!destCont.IsValidSlot(destSlot))
			{
				err = InventoryError.ITEM_NOT_FOUND2;
			}
			else
			{
				srcItem = srcCont[srcSlot];
				if (srcItem == null)
				{
					err = InventoryError.SLOT_IS_EMPTY;
				}
				else if (!srcItem.CanBeUsed)
				{
					err = InventoryError.CANT_DO_RIGHT_NOW;
				}
				else if (!m_owner.CanInteract)
				{
					err = InventoryError.CANT_DO_RIGHT_NOW;
				}
				else if (srcItem.IsEquippedContainer &&
					!((Container)srcItem).BaseInventory.IsEmpty &&
					!ItemMgr.IsContainerEquipmentSlot(destSlot) &&
					!Owner.GodMode)
				{
					err = InventoryError.CAN_ONLY_DO_WITH_EMPTY_BAGS;
				}
				else
				{
					// check whether the src item may be added to the dest spot
					if (destCont == this)
					{
						if (destSlot == (int)InventorySlot.OffHand)
						{
							// unequip 2h weapon when trying to equip offhand weapon (later move to available space if possible)
							occupyingWeapon = this[EquipmentSlot.MainHand];
							if (occupyingWeapon != null && !occupyingWeapon.Template.IsTwoHandWeapon)
							{
								occupyingWeapon = null;
							}
						}
						else if (destSlot == (int)InventorySlot.MainHand && srcItem.Template.IsTwoHandWeapon)
						{
							// unequip offhand weapon when trying to equip 2h weapon (later move to available space if possible)
							occupyingWeapon = this[EquipmentSlot.OffHand];
						}
					}

					destItem = destCont[destSlot];
					if (destItem != null)
					{
						if (!destItem.CanBeUsed)
						{
							err = InventoryError.CANT_DO_RIGHT_NOW;
						}
						else
						{
							if (occupyingWeapon != null)
							{
								// need extra space for occupyingWeapon
								if (!occupyingWeapon.Unequip())
								{
									err = InventoryError.INVENTORY_FULL;
									ItemHandler.SendInventoryError(Owner.Client, srcItem, destItem, err);
									return err;
								}
								occupyingWeapon = null;
							}

							if (destItem.IsEquippedContainer)
							{
								// move into container
								var cont = ((Container)destItem).BaseInventory;
								err = cont.CheckAdd(0, destItem, destItem.Amount);
								if (err != InventoryError.OK)
								{
									ItemHandler.SendInventoryError(Owner.Client, srcItem, destItem, err);
									return err;
								}

								var slot = cont.FindFreeSlot();
								if (slot == INVALID_SLOT)
								{
									// no free slot -> don't do anything
									return InventoryError.OK;
								}
								cont.AddUnchecked(slot, destItem, false);
							}
							else
							{
								// move to occupied slot
								var destHandler = destCont.GetHandler(destSlot);
								var amount = srcItem.Amount;
								destHandler.CheckAdd(destSlot, amount, srcItem, ref err);
								if (err == InventoryError.OK)
								{
									if (!srcItem.CanStackWith(destItem))
									{
										// check whether the dest item may be added to the src spot
										var srcHandler = srcCont.GetHandler(srcSlot);
										srcHandler.CheckAdd(srcSlot, destItem.Amount, destItem, ref err);
									}
								}
							}
						}
					}
					else
					{
						// move to empty slot

						var occupyingWeaponSlot = 0;
						if (occupyingWeapon != null)
						{
							// check whether we can put the occupyingWeapon into srcSlot
							var srcHandler = srcCont.GetHandler(srcSlot);
							srcHandler.CheckAdd(srcSlot, occupyingWeapon.Amount, occupyingWeapon, ref err);
							if (err != InventoryError.OK)
							{
								ItemHandler.SendInventoryError(Owner.Client, srcItem, destItem, err);
								return err;
							}
							occupyingWeaponSlot = occupyingWeapon.Slot;
							occupyingWeapon.Remove(false);
						}

						// check whether the src item may be added to the dest spot
						var destHandler = destCont.GetHandler(destSlot);
						destHandler.CheckAdd(destSlot, srcItem.Amount, srcItem, ref err);

						if (err != InventoryError.OK && occupyingWeapon != null)
						{
							// put occupying weapon back
							AddUnchecked(occupyingWeaponSlot, occupyingWeapon, false);
						}
					}
				}
			}

			if (err != InventoryError.OK)
			{
				ItemHandler.SendInventoryError(Owner.Client, srcItem, destItem, err);
			}
			else
			{
				SwapUnchecked(srcCont, srcSlot, destCont, destSlot);
				if (occupyingWeapon != null)
				{
					// occupying weapon was removed but not added again
					srcCont.AddUnchecked(srcSlot, occupyingWeapon, false);
				}
			}

			return err;
		}
Beispiel #28
0
		/// <summary>
		/// Tries to auti-equip an item from the given slot (from within the corresponding cont)
		/// </summary>
		public InventoryError TryEquip(BaseInventory cont, int slot)
		{
			InventoryError err;
			Item item = null;
			if (cont.IsValidSlot(slot))
			{
				item = cont[slot];
				if (item != null)
				{
					if (!item.IsEquipped)
					{
						if (item.Template.EquipmentSlots == null)
						{
							err = InventoryError.ITEM_CANT_BE_EQUIPPED;
						}
						else
						{
							var equipSlot = GetEquipSlot(item.Template, false);
							if (equipSlot != InventorySlot.Invalid)
							{
								return TrySwap(cont, slot, this, (int)equipSlot);
							}
							err = InventoryError.INVENTORY_FULL;
						}
					}
					else
					{
						err = InventoryError.OK;
					}
				}
				else
				{
					err = InventoryError.ITEM_NOT_FOUND;
				}
			}
			else
			{
				err = InventoryError.ITEM_NOT_FOUND;
			}
			ItemHandler.SendInventoryError(Owner.Client, item, null, err);
			return err;
		}
Beispiel #29
0
		/// <summary>
		/// Try to loot the item at the given index of the current loot
		/// </summary>
		/// <returns>The looted Item or null if Item could not be taken</returns>
		public void TakeItem(LooterEntry entry, uint index, BaseInventory targetCont, int targetSlot)
		{
			var chr = entry.Owner;
			if (chr != null && index < Items.Length)
			{
				var lootItem = Items[index];
				var err = MayLoot(entry, lootItem);
				if (err == InventoryError.OK)
				{
					HandoutItem(chr, lootItem, targetCont, targetSlot);
				}
				else
				{
					ItemHandler.SendInventoryError(chr.Client, null, null, err);
				}
			}
		}
Beispiel #30
0
		/// <summary>
		/// Tries to unequip the item at the given slot and put it into the first available slot in the backpack or an equipped cont.
		/// </summary>
		public bool Unequip(BaseInventory container, int slot)
		{
			var item = container[slot];
			if (item == null)
			{
				return false;
			}

			return item.Unequip();
		}
Beispiel #31
0
		/// <summary>
		/// Tries to auto-equip an item from the given slot (from within the corresponding cont)
		/// </summary>
		public InventoryError TryMove(BaseInventory srcCont, int srcSlot, BaseInventory destCont)
		{
			var err = InventoryError.ITEM_NOT_FOUND;
			Item item = null;
			if (srcCont.IsValidSlot(srcSlot))
			{
				item = srcCont[srcSlot];

				if (item != null)
				{
					var slot = destCont.FindFreeSlot();
					if (slot != INVALID_SLOT)
					{
						return TrySwap(srcCont, srcSlot, destCont, slot);
					}
					err = destCont.FullError;
				}
				else
				{
					err = InventoryError.ITEM_NOT_FOUND;
				}
			}
			ItemHandler.SendInventoryError(Owner.Client, item, null, err);
			return err;
		}
Beispiel #32
0
		public void BuyItem(Character chr, uint itemEntryId, BaseInventory bag, int amount, int slot)
		{
			if (!CheckVendorInteraction(chr))
				return;

			var item = GetVendorItem(itemEntryId);
			if (item == null)
				return;

			amount = Math.Max(amount, 1);
			if (item.BuyStackSize > 0)
			{
				amount = amount * item.BuyStackSize;
			}

			if (!CheckBuyItem(chr, item, amount))
				return;

			// Does the player have enough money?
			var price = chr.Reputations.GetDiscountedCost(NPC.Faction.ReputationIndex, item.Template.BuyPrice);
			if (chr.Money < price)
			{
				NPCHandler.SendBuyError(chr, NPC, item.Template.ItemId, BuyItemError.NotEnoughMoney);
				return;
			}
			BaseInventory inv = chr.Inventory;
			InventoryError err;
			if (inv.IsValidSlot(slot))
			{
				err = inv.TryAdd(item.Template, ref amount, slot, true);
			}
			else
			{
				// count will be set to the actual amount of items that found space in the inventory
				// if not all could be added, err contains the reason why
				err = inv.TryAdd(item.Template, ref amount);
			}

			if (err != InventoryError.OK)
			{
				ItemHandler.SendInventoryError(chr.Client, null, null, err);
			}

			if (amount <= 0)
			{
				// Nothing was purchased
				// Should usually never happen, but just to make sure
				ItemHandler.SendInventoryError(chr.Client, null, null, InventoryError.INVENTORY_FULL);
				return;
			}

			chr.Money -= (price * (uint)amount); // we already checked that our money is sufficient
			if (item.ExtendedCostEntry != null)
			{
				var exCost = item.ExtendedCostEntry;

				chr.HonorPoints -= exCost.HonorCost;
				chr.ArenaPoints -= exCost.ArenaPointCost;

				foreach (var reqItem in exCost.RequiredItems)
				{
					if (reqItem.Id == ItemId.None)
					{
						break;
					}

					if (!chr.Inventory.RemoveByItemId(reqItem.Id, reqItem.Cost, false))
					{
						NPCHandler.SendBuyError(chr, NPC, item.Template.ItemId, BuyItemError.NotEnoughMoney);
						return;
					}
				}
			}

			int remainingAmount;
			if (item.RemainingStockAmount != UnlimitedSupply)
			{
				// The vendor had a limited supply of this item, update the chr.Client with the new inventory
				remainingAmount = item.RemainingStockAmount - amount;
				//NPCHandler.SendVendorInventoryList(chr.Client, NPC.EntityId, ConstructVendorItemList(chr));
			}
			else
			{
				remainingAmount = UnlimitedSupply;
			}

			NPCHandler.SendBuyItem(chr.Client, NPC, item.Template.ItemId, amount, remainingAmount);
		}
Beispiel #33
0
		public InventoryError Split(BaseInventory srcCont, int srcSlot, BaseInventory destCont, int destSlot, int amount)
		{
			var err = InventoryError.OK;

			Item srcItem = null;
			Item destItem = null;

			if (!m_owner.CanInteract)
			{
				err = InventoryError.ITEMS_CANT_BE_SWAPPED;
			}
			else if (!srcCont.IsValidSlot(srcSlot))
			{
				err = InventoryError.ITEM_NOT_FOUND;
			}
			else if (!destCont.IsValidSlot(destSlot))
			{
				err = InventoryError.ITEM_NOT_FOUND2;
			}
			else
			{
				srcItem = srcCont[srcSlot];
				if (srcItem == null)
				{
					err = InventoryError.ITEM_NOT_FOUND;
				}
				else
				{
					var template = srcItem.Template;
					if (!srcItem.CanBeUsed)
					{
						err = InventoryError.CANT_DO_RIGHT_NOW;
					}
					if (!template.IsStackable)
					{
						err = InventoryError.COULDNT_SPLIT_ITEMS;
					}
					else if (amount > srcItem.Amount)
					{
						err = InventoryError.TRIED_TO_SPLIT_MORE_THAN_COUNT;
					}
					else if (amount > 0)
					{
						destItem = destCont[destSlot];
						if (destItem == null)
						{
							// empty target spot
							var destHandler = destCont.GetHandler(destSlot);
							destHandler.CheckAdd(destSlot, amount, srcItem, ref err);
							if (err == InventoryError.OK)
							{
								destCont[destSlot] = srcItem.Split(amount);
							}
						}
						else
						{
							// occupied target spot
							if (destItem.IsContainer && destCont == this)
							{
								// move to a container
								var cont = ((Container)destItem).BaseInventory;
								//var srcAmount = srcItem.Amount;
								err = cont.TryAddAmount(srcItem, amount, false);
							}
							else if (!srcItem.CanStackWith(destItem))
							{
								// move to a different type of Item
								err = InventoryError.COULDNT_SPLIT_ITEMS;
							}
							else
							{
								// move ontop of the same type of Item
								amount = Math.Min(amount, template.MaxAmount - destItem.Amount);

								srcItem.Amount -= amount;
								destItem.Amount += amount;
							}
						}
					}
				}
			}

			if (err != InventoryError.OK)
			{
				ItemHandler.SendInventoryError(Owner.Client, srcItem, destItem, err);
			}
			return err;
		}
Beispiel #34
0
 public ProphuntPlayer()
 {
     Log.Info("Prophunt Player");
     Inventory = new BaseInventory(this);
 }
Beispiel #35
0
 public SandboxPlayer()
 {
     Inventory = new BaseInventory(this);
 }
Beispiel #36
0
 /// <summary>
 /// Try to loot the item at the given index of the current loot
 /// </summary>
 /// <returns>The looted Item or null if Item could not be taken</returns>
 public void TakeItem(LooterEntry entry, uint index, BaseInventory targetCont, int targetSlot)
 {
     LootItem lootItem = null;
     try
     {
         var chr = entry.Owner;
         if (chr != null && index < Items.Length)
         {
             lootItem = Items[index];
             var err = CheckTakeItemConditions(entry, lootItem);
             if (err == InventoryError.OK)
             {
                 HandoutItem(chr, lootItem, targetCont, targetSlot);
             }
             else
             {
                 ItemHandler.SendInventoryError(chr.Client, null, null, err);
             }
         }
     }
     catch (Exception e)
     {
         LogUtil.ErrorException(e, "{0} threw an Exception while looting \"{1}\" (index = {2}) from {3}",
             entry.Owner, lootItem, index, targetCont);
     }
 }