예제 #1
0
    public void SetData(int id, string name, ItemQuality quality, ItemType type, string description, int amount, int capacity, int buyprice, int sellprice)
    {
        ItemMaterial dataTmp = new ItemMaterial();

        dataTmp.SetData(id, name, quality, type, description, amount, capacity, buyprice, sellprice);
        data = dataTmp;
    }
예제 #2
0
    public bool AddItem(BaseItemData newItem)
    {
        ItemListItem lastExistingItem = Items.FindLast(item => item.Data.ItemName == newItem.ItemName);

        // If this item does not exist, just add to our inventory
        if (lastExistingItem == null)
        {
            Items.Add(new ItemListItem(newItem));
            return(true);
        }
        else
        {
            int countSum = Items.FindAll(item => item.Data.ItemName == newItem.ItemName).Select(x => x.Count).Sum();
            if (countSum == newItem.MaxCount)
            {
                GameManager.SendSystemMessage($"You cannot pickup any more of this item.");
                return(false);
            }

            if (lastExistingItem.Count < newItem.MaxCount || newItem.MaxCount == -1)
            {
                if (lastExistingItem.Count == newItem.MaxPerStack)
                {
                    Items.Add(new ItemListItem(newItem));
                }
                else
                {
                    lastExistingItem.Count++;
                }
            }

            return(true);
        }
    }
예제 #3
0
    public void SetData(int strength, int intellect, int agility, int stamina, EquipmentType et, int id, string name, ItemQuality quality, ItemType type, string description, int amount, int capacity, int buyprice, int sellprice)
    {
        ItemEquipment dataTmp = new ItemEquipment();

        dataTmp.SetData(strength, intellect, agility, stamina, et, id, name, quality, type, description, amount, capacity, buyprice, sellprice);
        data = dataTmp;
    }
예제 #4
0
    public void SetData(int damage, WeaponType wt, List <int> weaponEffects, int id, string name, ItemQuality quality, ItemType type, string description, int amount, int capacity, int buyprice, int sellprice)
    {
        ItemWeapon dataTmp = new ItemWeapon();

        dataTmp.SetData(damage, wt, weaponEffects, id, name, quality, type, description, amount, capacity, buyprice, sellprice);
        data = dataTmp;
    }
예제 #5
0
    /// <summary>
    /// 设置数据
    /// </summary>
    /// <param name="hp"></param>
    /// <param name="mp"></param>
    /// <param name="id"></param>
    /// <param name="name"></param>
    /// <param name="quality"></param>
    /// <param name="type"></param>
    /// <param name="description"></param>
    /// <param name="amount"></param>
    /// <param name="capacity"></param>
    /// <param name="buyprice"></param>
    /// <param name="sellprice"></param>
    /// <param name="assetId"></param>
    /// <param name="itemEffect"></param>
    public void SetData(int hp, int mp, int itemEffect, int id, string name, ItemQuality quality, ItemType type, string description, int amount, int capacity, int buyprice, int sellprice)
    {
        ItemConsumable dataTmp = new ItemConsumable();//正常里式替换原则,不可以子类转父类,但如果我们一开始分配的内存就是按父类来算的话,强转回子类也ok

        dataTmp.SetData(hp, mp, itemEffect, id, name, quality, type, description, amount, capacity, buyprice, sellprice);
        data = dataTmp;
    }
예제 #6
0
 private ItemState FindNotEmptyItemState(BaseItemData item, int count)
 => _items.Where(state => state.Data != null &&
                 state.Data.GetType() == item.GetType() &&
                 state.Data.Title == item.Title &&
                 state.ItemsCount >= count)
 .Reverse()
 .FirstOrDefault();
예제 #7
0
    //Add an already existing item to the inventory
    public void AddItem(BaseItemData item)
    {
        //check if the item already exists
        foreach (var inventoryItem in _inventoryItems)
        {
            if (inventoryItem.Item.Name == item.Name)
            {
                if (inventoryItem.Amount < item.StackSize || UnlimitedStackSize)
                {
                    if (OnItemUpdate != null)
                    {
                        OnItemUpdate(inventoryItem, 1);
                    }
                    //Item already exists so increment amount and return
                    inventoryItem.Amount++;
                    return;
                }
            }
        }

        //TODO change inventory to store a string as the item instead of the item itself
        InventoryItem newInventoryItem = new InventoryItem();

        newInventoryItem.Item   = item;
        newInventoryItem.Amount = 1;

        _inventoryItems.Add(newInventoryItem);

        //call add event
        if (OnItemAdd != null)
        {
            OnItemAdd(newInventoryItem);
        }
    }
예제 #8
0
    /// <summary>
    /// 根据id获取物品实体
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public ItemEntity GetItemEntity(int id)
    {
        BaseItemData data       = GetItemDataById(id);                                     //拷贝一份数据
        var          itemEntity = EntityModule.Instance.SpawnEntity <ItemEntity>(data.id); //获取实体

        itemEntity.SetData(data);                                                          //设置数据
        return(itemEntity);
    }
예제 #9
0
        public override void SetItem(BaseItemData baseItemData)
        {
            FriendItemData friendItemData = baseItemData as FriendItemData;

            m_FriendName.text = friendItemData.FriendName;

            m_FriendHead.SetRole(friendItemData.HeadID);
        }
예제 #10
0
        public override void ReshowItem(BaseItemData baseItemData)
        {
            FriendItemData friendItemData = baseItemData as FriendItemData;

            m_FriendName.text = friendItemData.FriendName;

            m_FriendHead.ReshowItem();
        }
예제 #11
0
    //Buy an item from a player
    public void BuyItem(BaseItemData item)
    {
        //sell at half price
        _partyInventory.Gold += (int)(item.BaseMoneyValue / 2.0f);
        _partyInventory.Inventory.RemoveItem(item.Name);

        //add it to the shop
        Inventory.AddItem(item);
    }
예제 #12
0
    public static bool AddItem(BaseItemData item)
    {
        if (_inventory.AddItem(item))
        {
            OnItemAdded?.Invoke(item);
            return(true);
        }

        return(false);
    }
 public int FindItem(BaseItemData Item)
 {
     for (int i = 0; i < Cells.Length; i++)
     {
         if (Cells[i].Data == Item)
         {
             return(i);
         }
     }
     return(-1);
 }
예제 #14
0
        private ItemState RemoveOldItem(BaseItemData item, int count)
        {
            var state = FindNotEmptyItemState(item, count);

            if (state == null)
            {
                Debug.Log($"Not found item {item.Title}");
                return(null);
            }

            return(state);
        }
예제 #15
0
        public static bool TryTransaction(Vendor buyer, Vendor seller, BaseItemData item, string currencyName, int amount)
        {
            if (!buyer.CanBuy(currencyName, item.Price, amount) || !seller.CanSell(item.Title, amount))
            {
                return(false);
            }

            buyer.Buy(item, currencyName, amount);
            seller.Sell(item, currencyName, amount);

            return(true);
        }
예제 #16
0
    public void EquipWeapon(WeaponItemData weaponItem, Inventory partyInventory)
    {
        //check if the magic type of the item is the same as the rest
        if (weaponItem.MagicalType != _weaponMagicType)
        {
            //first check if the chracter has a magic type
            if (Character.Magic != MagicType.eNONE)
            {
                //character has a magic type, check if the weapon is the same as the characters magic
                if (Character.Magic != weaponItem.MagicalType)
                {
                    return;
                }
            }
            else if (weaponItem.MagicalType != _weaponMagicType && hasWeapon())
            {
                return;
            }
        }

        //Remove the item from the part inventory
        partyInventory.RemoveItem(weaponItem.Name);

        BaseItemData itemToRemove = null;

        //check if a weapon is already in the equipment
        foreach (var inventoryItem in _inventoryItems)
        {
            if (inventoryItem.Item.ItemType == ItemType.eWEAPON)
            {
                WeaponItemData inventoryWeaponItem = (WeaponItemData)inventoryItem.Item;
                if ((inventoryWeaponItem.IsMainHand == weaponItem.IsMainHand))
                {
                    //Weapon already equipped, add it back to the party inventory
                    partyInventory.AddItem(inventoryItem.Item);
                    //remove weapon from equipment
                    itemToRemove = inventoryItem.Item;
                    break;
                }
            }
        }

        if (itemToRemove != null)
        {
            RemoveItem(itemToRemove.Name);
        }

        //Add it to the equipment
        AddItem(weaponItem);

        _weaponMagicType = weaponItem.MagicalType;
    }
    public ItemState PutNewItem(BaseItemData item, int count)
    {
        var state = FindEmptyCell();

        if (state == null)
        {
            Debug.Log("Инвентарь полон");
            return(null);
        }
        state.Data  = item;
        state.Count = count;
        return(state);
    }
예제 #18
0
        private bool Buy(BaseItemData item, string currencyName, int amount)
        {
            if (!CanBuy(currencyName, item.Price, amount))
            {
                return(false);
            }

            var currency = Currencies[currencyName];

            currency.Amount         -= item.Price * amount;
            Currencies[currencyName] = currency;
            Inventory.AddItem(item, amount);

            return(true);
        }
예제 #19
0
    public BaseItemData GetItemData(string id)
    {
        BaseItemData data = null;
        string       path = null;

        if (!_itemData.TryGetValue(id, out data))
        {
            path = ITEMS_PATH + id;
            data = Resources.Load(path) as BaseItemData;
        }
                #if DEBUG
        Debug.Assert(data != null, "No ItemData found with id " + id + " at path " + path);
                #endif
        return(data);
    }
예제 #20
0
 public void Initialize(LootTableDrop drop)
 {
     if (drop.Type == LootTableDrop.DropType.WEAPON)
     {
         WeaponTileData data = Database.Instance.GetWeaponTileData(drop.ItemId);
         _itemIcon.sprite   = data.Sprite;
         _itemQuantity.text = drop.Amount.ToString();
     }
     else if (drop.Type == LootTableDrop.DropType.CURRENCY)
     {
         BaseItemData data = Database.Instance.GetItemData(drop.ItemId);
         _itemIcon.sprite   = data.Sprite;
         _itemQuantity.text = drop.Amount.ToString();
     }
 }
예제 #21
0
    //Sell an item to the player
    public void SellItem(BaseItemData item)
    {
        int actualPrice = (int)(item.BaseMoneyValue * PriceModfier);

        //check if the party has enough Gold
        if (_partyInventory.Gold - actualPrice >= 0)
        {
            _partyInventory.Gold -= actualPrice;
            _partyInventory.Inventory.AddItem(item);

            if (!InfinateStock)
            {
                Inventory.RemoveItem(item.Name);
            }
        }
    }
예제 #22
0
        private ItemState PutNewItem(BaseItemData item, int count)
        {
            var state = FindEmptyItemState();

            if (state == null)
            {
                Debug.Log("Inventory is full");
                OnInventoryFull?.Invoke();
                return(null);
            }

            state.Data       = item;
            state.ItemsCount = count;

            return(state);
        }
예제 #23
0
    protected Inventory(SerializationInfo info, StreamingContext context)
    {
        _inventoryCapacity = info.GetInt32("capacity");
        _inventoryItems    = new List <InventoryItem>();
        int itemCount = info.GetInt32("itemCount");

        for (int i = 0; i < itemCount; i++)
        {
            int          amount = info.GetInt32("itemAmount" + i);
            BaseItemData item   = ItemDatabase.Instance.GetItemInstance(info.GetString("itemDatabaseName" + i));

            InventoryItem inventoryItem = new InventoryItem();
            inventoryItem.Item   = item;
            inventoryItem.Amount = amount;
            _inventoryItems.Add(inventoryItem);
        }
    }
예제 #24
0
        private bool Sell(BaseItemData item, string currencyName, int amount)
        {
            if (!CanSell(item.Title, amount))
            {
                return(false);
            }

            if (Currencies.ContainsKey(currencyName))
            {
                var currency = Currencies[currencyName];

                currency.Amount         += item.Price * amount;
                Currencies[currencyName] = currency;
            }

            Inventory.RemoveItem(item, amount);

            return(true);
        }
예제 #25
0
    public void EquipArmour(ArmourItemData armourItem, Inventory partyInventory)
    {
        //check if the magic type of the item is the same as the rest
        if (armourItem.MagicalType != _armourMagicType && hasArmour())
        {
            return;
        }


        //Remove the item from the part inventory
        partyInventory.RemoveItem(armourItem.Name);

        BaseItemData itemToRemove = null;

        //check if a armour is already in the equipment
        foreach (var inventoryItem in _inventoryItems)
        {
            if (inventoryItem.Item.ItemType == ItemType.eARMOUR)
            {
                ArmourItemData inventoryArmour = (ArmourItemData)inventoryItem.Item;
                if (inventoryArmour.ArmourSlotType == armourItem.ArmourSlotType)
                {
                    //armour item already equipped, add it back to the party inventory
                    partyInventory.AddItem(inventoryItem.Item);
                    //remove armour piece from equipment
                    itemToRemove = inventoryItem.Item;
                    break;
                }
            }
        }

        if (itemToRemove != null)
        {
            RemoveItem(itemToRemove.Name);
        }

        //Add it to the equipment
        AddItem(armourItem);

        _armourMagicType = armourItem.MagicalType;
    }
예제 #26
0
 public virtual void ReshowItem(BaseItemData baseItemData)
 {
 }
예제 #27
0
 public virtual void SetItem(BaseItemData baseItemData)
 {
 }
예제 #28
0
 public void AddItem(BaseItemData item, int count, UnityAction <BaseItemData> OnAddingItemHasComplete = null)
 {
     item.PutToInventory(this, count, (addableItem, countToPut) => PutNewItem(item, countToPut));
     OnItemsStateChanged?.Invoke();
 }
예제 #29
0
 private void OnItemAdded(BaseItemData item)
 {
     RefreshItems();
 }
예제 #30
0
 public void RemoveItem(BaseItemData item, int count, UnityAction <BaseItemData> OnRemovingItemHasComplete = null)
 {
     item.EjectFromInventory(this, count, (removableItem, countToEject) => RemoveOldItem(item, countToEject));
     OnItemsStateChanged?.Invoke();
 }