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; }
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); } }
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; }
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; }
/// <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; }
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();
//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); } }
/// <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); }
public override void SetItem(BaseItemData baseItemData) { FriendItemData friendItemData = baseItemData as FriendItemData; m_FriendName.text = friendItemData.FriendName; m_FriendHead.SetRole(friendItemData.HeadID); }
public override void ReshowItem(BaseItemData baseItemData) { FriendItemData friendItemData = baseItemData as FriendItemData; m_FriendName.text = friendItemData.FriendName; m_FriendHead.ReshowItem(); }
//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); }
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); }
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); }
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); }
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); }
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); }
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); }
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(); } }
//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); } } }
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); }
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); } }
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); }
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; }
public virtual void ReshowItem(BaseItemData baseItemData) { }
public virtual void SetItem(BaseItemData baseItemData) { }
public void AddItem(BaseItemData item, int count, UnityAction <BaseItemData> OnAddingItemHasComplete = null) { item.PutToInventory(this, count, (addableItem, countToPut) => PutNewItem(item, countToPut)); OnItemsStateChanged?.Invoke(); }
private void OnItemAdded(BaseItemData item) { RefreshItems(); }
public void RemoveItem(BaseItemData item, int count, UnityAction <BaseItemData> OnRemovingItemHasComplete = null) { item.EjectFromInventory(this, count, (removableItem, countToEject) => RemoveOldItem(item, countToEject)); OnItemsStateChanged?.Invoke(); }