public bool EquipWeapon(InventoryItemObject inventoryItemObject) { // ensure the stat requirements are met foreach (Attributes.Stat stat in (inventoryItemObject.GetItem() as Weapon).GetStatRequirements()) { if (_attributes.GetStat(stat.statType).value < stat.value) { Debug.Log("Stat requirements not met -- " + stat.statType); return(false); } } // level requirements if (inventoryItemObject.GetItem().GetLevelRequirement() > _level) { Debug.Log($"Requires level {inventoryItemObject.GetItem().GetLevelRequirement()}, you are level {_level}"); return(false); } // actually equip the item _equipment.Equip(inventoryItemObject, ref _attributes); // place weapon on characters back/hip as appropriate // update stats UpdateStatDisplay(); return(true); }
public void SortShop() { List <InventoryItemObject> items = new List <InventoryItemObject> (); foreach (Transform slot in shopInventory.slots) { InventoryItemObject item = GetItemObjectInSlot(slot); if (item != null) { items.Add(item); item.Take(); item.transform.parent = null; } } List <InventoryItemObject> sortedItems; //sortedItems = items.OrderByDescending(go=>go.info.uiInfo.size.x*go.info.uiInfo.size.y).ToList(); //sortedItems = items.OrderBy(go=>go.info.name).ToList(); sortedItems = items.OrderBy(go => go.info.costInfo.timePrice).ToList(); //sortedItems.Reverse(); foreach (InventoryItemObject itemObj in sortedItems) { itemObj.Place(FindEmptySlot(itemObj, SlotType.Shop)); //InventoryItem item = ItemDatabase.reference.FindByIndex(itemObj.info.databaseIndex); //InitItem (item, SlotType.Shop); // need to be initialized in shop inventory, not player inventory } }
public void ShowItemDescription(InventoryItemObject itemObject) { DescriptionWindow.ShowItemDescription (itemObject); if (itemToCompare != null) CompareWindow.ShowItemDescription (itemToCompare, DescriptionWindow.transform.localPosition); }
public int GetItemTotalPrice(InventoryItemObject item) { if (!IsShopActive()) { //Debug.Log ("shop is not active"); return(item.info.costInfo.timePrice); } Transform slot = item.GetSlot(); if (slot == null) { return(0); } WagonInventoryUI inventory = slot.parent.parent.GetComponent <WagonInventoryUI>(); if (inventory == shopInventory) { return(item.GetBuyPrice()); } else { if (vendorShopInfo.FindInfoByIndex(item.info.databaseIndex) != null) { return(item.GetSellPrice()); } else { //Debug.Log ("vendor is not interested"); return(0); } } }
public bool EquipArmor(InventoryItemObject inventoryItemObject) // right click equip { // ensure the stat requirements are met foreach (Attributes.Stat stat in (inventoryItemObject.GetItem() as Armor).GetStatRequirements()) { if (_attributes.GetStat(stat.statType).value < stat.value) { Debug.Log("Stat requirements not met -- " + stat.statType); return(false); } } // level requirements if (inventoryItemObject.GetItem().GetLevelRequirement() > _level) { Debug.Log($"Requires level {inventoryItemObject.GetItem().GetLevelRequirement()}, you are level {_level}"); return(false); } // actually equip the item _equipment.Equip(inventoryItemObject, ref _attributes); // place item in applicable location on character UpdateStatDisplay(); return(true); }
bool HavePenaltyDurability(InventoryItemObject item) { if (PlayerSaveData.reference.trainData.bonusEquipmentDurability >= 0) return false; if (InventorySystem.reference.GetSlotInfo (item.GetSlot ()).type == InventorySystem.SlotType.Shop) return false; return true; }
public void ShowItemDescription(InventoryItemObject itemObject) { DescriptionWindow.ShowItemDescription(itemObject); if (itemToCompare != null) { CompareWindow.ShowItemDescription(itemToCompare, DescriptionWindow.transform.localPosition); } }
public bool CanPutInSlot(Transform slotToPut, Vector2 itemSize) { // first, check that item not going through right side of wagon if (slots.IndexOf(slotToPut) % sizeX + itemSize.x - 1 > sizeX) { return(false); } for (int slotIndex = 0; slotIndex < slots.IndexOf(slotToPut); slotIndex++) { // dont need to check slots righter than right side of item if (slotIndex % sizeX > slots.IndexOf(slotToPut) % sizeX + itemSize.x - 1) { continue; } Transform slot = slots[slotIndex]; if (!InventorySystem.reference.IsSlotEmpty(slot)) { InventoryItemObject itemInCheckingSlot = InventorySystem.reference.GetItemObjectInSlot(slot); Vector2 checkingItemSize = itemInCheckingSlot.info.uiInfo.size; int checkingSlotIndex = slots.IndexOf(slot); int potentialSlotIndex = slots.IndexOf(slotToPut); if (checkingItemSize.x + checkingSlotIndex % sizeX >= potentialSlotIndex % sizeX + 1 && checkingItemSize.y + checkingSlotIndex / sizeX >= potentialSlotIndex / sizeX + 1) { //Debug.Log ("cant put item in slot "+slotToPut); return(false); } } } int currentSlotIndex = slots.IndexOf(slotToPut); for (int XIndex = 0; XIndex < itemSize.x; XIndex++) { for (int YIndex = 0; YIndex < itemSize.y; YIndex++) { int slotToCheckIndex = currentSlotIndex + XIndex + YIndex * sizeX; if (slotToCheckIndex >= slots.Count) { return(false); } int firstSlotRow = currentSlotIndex / sizeX + YIndex; int slotToCheckRow = slotToCheckIndex / sizeX; if (firstSlotRow != slotToCheckRow) { return(false); } Transform slotToCheck = slots[slotToCheckIndex]; if (!InventorySystem.reference.IsSlotEmpty(slotToCheck)) { return(false); } } } return(true); }
void RemoveItem(string name) { InventoryItemObject item = InventorySystem.reference.FindItem(name); if (item != null) { Destroy(item.gameObject); } }
public InventoryItemObject Unequip(Item.EquipmentSlot eSlot, ref Attributes playerAttributes) { InventoryItemObject oldItem = null;// new InventoryItemObject(); // retrieve the slot that takes that type of item int slot = Convert.ToInt32(eSlot); if (_equipmentSlots[slot].GetItem() != null) { oldItem = _equipmentSlots[slot]?.GetInventoryItemObject(); } // retrieve the old stats and remove them from the attributes if (_equipmentSlots[slot].GetItem()?.GetItemType() == Item.ItemType.Weapon) { foreach (Weapon.Stat stat in (_equipmentSlots[slot].GetItem() as Weapon).GetStats()) { if (stat._isBasicStat) { string enumString = stat._stat.ToString(); Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString); playerAttributes.DecrementStat(new Attributes.Stat(statType, (int)stat._value)); } else { Weapon.Stat weapStat = playerAttributes.GetWeaponStats().Find(x => x._stat == stat._stat); weapStat -= stat; playerAttributes.SetWeaponStat(weapStat); } } _equipmentSlots[slot].SetItemNull(); } else if (_equipmentSlots[slot].GetItem()?.GetItemType() == Item.ItemType.Armor) { foreach (Armor.Stat stat in (_equipmentSlots[slot].GetItem() as Armor).GetStats()) { if (stat._isBasicStat) { string enumString = stat._stat.ToString(); Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString); playerAttributes.DecrementStat(new Attributes.Stat(statType, (int)stat._value)); } else { Armor.Stat armorStat = playerAttributes.GetArmorStats().Find(x => x._stat == stat._stat); armorStat -= stat; playerAttributes.SetArmorStat(armorStat); } } _equipmentSlots[slot].SetItemNull(); } return(oldItem); }
bool IsRectangle(int slotIndex) { Transform slot = slots[slotIndex]; if (InventorySystem.reference.IsSlotEmpty(slot)) { return(false); } InventoryItemObject item = InventorySystem.reference.GetItemObjectInSlot(slot); if (item.info.name != itemForSignName) { return(false); } if (item.IsBroken()) { return(false); } int itemRowIndex = slotIndex % sizeX; int cycleIterations = sizeX - 1 - itemRowIndex; for (int signHeight = 1; signHeight <= cycleIterations; signHeight++) { // rectangle sign check if (slotIndex + sizeX * signHeight + signHeight >= slots.Count) { continue; } if (InventorySystem.reference.IsSlotEmpty(slots[slotIndex + signHeight]) || InventorySystem.reference.IsSlotEmpty(slots[slotIndex + sizeX * signHeight]) || InventorySystem.reference.IsSlotEmpty(slots[slotIndex + sizeX * signHeight + signHeight])) { continue; } if ((slotIndex) / sizeX != (slotIndex + signHeight) / sizeX) { continue; } if (InventorySystem.reference.GetItemObjectInSlot(slots[slotIndex + signHeight]).info.name == itemForSignName && InventorySystem.reference.GetItemObjectInSlot(slots[slotIndex + sizeX * signHeight]).info.name == itemForSignName && InventorySystem.reference.GetItemObjectInSlot(slots[slotIndex + sizeX * signHeight + signHeight]).info.name == itemForSignName) { if (InventorySystem.reference.GetItemObjectInSlot(slots[slotIndex + signHeight]).IsBroken() || InventorySystem.reference.GetItemObjectInSlot(slots[slotIndex + sizeX * signHeight]).IsBroken() || InventorySystem.reference.GetItemObjectInSlot(slots[slotIndex + sizeX * signHeight + signHeight]).IsBroken()) { continue; } else { return(true); //Debug.Log ("has rectangle"); } } } return(false); }
public int FindEmptySlotForItem(InventoryItemObject item) { foreach (Transform slot in slots) { if (CanPutInSlot(slot, item.info.uiInfo.size)) { return(slots.IndexOf(slot)); } } return(-1); }
public void SetItem(InventoryItemObject item) { _item = item.GetItem(); item.transform.SetParent(transform.parent); Image image = GetComponent <Image>(); item.SetScale(image.rectTransform.localScale, image.rectTransform.sizeDelta); item.transform.position = image.transform.position; _inventoryItem = item; }
bool HavePenaltyDurability(InventoryItemObject item) { if (PlayerSaveData.reference.trainData.bonusEquipmentDurability >= 0) { return(false); } if (InventorySystem.reference.GetSlotInfo(item.GetSlot()).type == InventorySystem.SlotType.Shop) { return(false); } return(true); }
public void SetParentAndSize(InventoryItemObject item) { item.transform.SetParent(transform); // set size of image int wid = item.GetItem().GetItemSize()._width; int hig = item.GetItem().GetItemSize()._height; item.GetComponent <Image>().rectTransform.localScale = Vector3.one; item.SetSize(localSizeOfTile * wid, localSizeOfTile * hig); /* * item.GetImage().rectTransform.localScale = Vector3.one; * item.GetImage().rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, localSizeOfTile * wid); * item.GetImage().rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, localSizeOfTile * hig); */ }
public void InitItem(GameObject item) { InventoryItemObject itemObject = item.GetComponent <InventoryItemObject>(); Transform slot = null; foreach (SlotInfo info in slots) { if (info.type == itemObject.info.type) { slot = info.slot; } } if (slot == null) { Debug.Log("wrong item to init!"); return; } itemObject.Place(slot); }
public IEnumerator InitShop() { foreach (Transform slot in shopInventory.slots) { InventoryItemObject item = GetItemObjectInSlot(slot); if (item != null) { Destroy(item.gameObject); } } yield return(null); foreach (VendorShop.ItemInfo info in vendorShopInfo.items) { for (int itemCounter = 0; itemCounter < info.quantity; itemCounter++) { InventoryItem item = ItemDatabase.reference.FindByIndex(info.index); InitItem(item, SlotType.Shop); // need to be initialized in shop inventory, not player inventory } } Debug.Log("init shop done"); }
public void Equip() { Debug.Log("tryimg to equip item"); if (info.type == InventoryItem.Type.NonEquippable) { Debug.Log("Item cant be equipped!"); return; } int equipmentSlotIndex = GetEquipmentSlotIndex(); InventoryItemObject equippedItem = PlayerSaveData.reference.trainData.equippedItems [equipmentSlotIndex]; if (equippedItem != null) { if (GetLastSlot() != null) { Transform potentialSlot = InventorySystem.reference.FindEmptySlot(this, InventorySystem.SlotType.Wagon); if (potentialSlot != null) { equippedItem.Place(potentialSlot); } else { equippedItem.Place(GetLastSlot()); } } } RemoveStats(); PlayerSaveData.reference.trainData.equippedItems[equipmentSlotIndex] = this; ApplyStats(); if (info.bonusInfo.equipmentDurability == 0) { info.durabilityInfo.max *= (100 + PlayerSaveData.reference.trainData.bonusEquipmentDurability) / 100; info.durabilityInfo.current *= (100 + PlayerSaveData.reference.trainData.bonusEquipmentDurability) / 100; } }
public void AddExistingItem(InventoryItemObject itemObject) { Image img = itemObject.GetComponent <Image>(); // add to first available for (int r = 0; r < _height; r++) { for (int c = 0; c < _width; c++) { Index nx = new Index(c, r); if (TryFit(itemObject.GetItem(), nx)) { AddToSlot(itemObject.GetItem(), nx); img.transform.SetParent(transform); Item item = itemObject.GetItem(); img.GetComponent <InventoryItemObject>().init(item, nx); // set size of image int wid = item.GetItemSize()._width; int hig = item.GetItemSize()._height; img.rectTransform.localScale = Vector3.one; itemObject.SetSize(localSizeOfTile * wid, localSizeOfTile * hig); /* * img.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, localSizeOfTile * wid); * img.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, localSizeOfTile * hig); */ // set position of image img.rectTransform.localPosition = PositionAtIndex(nx._x, nx._y) - HalfTile(); return; } } } }
public void Clear() { foreach (WagonInventoryUI wagonUI in wagonUIs) { foreach (Transform slot in wagonUI.slots) { InventoryItemObject item = GetItemObjectInSlot(slot); if (item != null) { Destroy(item.gameObject); } } } foreach (InventoryEquipmentUI.SlotInfo info in equipmentUI.slots) { Transform slot = info.slot; InventoryItemObject item = GetItemObjectInSlot(slot); if (item != null) { Destroy(item.gameObject); } } }
public bool CanPutInSlot(Transform slotToPut, InventoryItemObject item) { SlotInfo slotInfo = GetSlotInfo(slotToPut); if (slotInfo.type == SlotType.Equipment) { if (item.info.type == equipmentUI.GetSlotType(slotToPut)) { return(true); } return(false); } else if (slotInfo.type == SlotType.Wagon) { WagonInventoryUI wagon = wagonUIs [slotInfo.wagonIndex]; return(wagon.CanPutInSlot(slotToPut, item.info.uiInfo.size)); } else if (slotInfo.type == SlotType.Shop) { WagonInventoryUI wagon = shopInventory; return(wagon.CanPutInSlot(slotToPut, item.info.uiInfo.size)); } return(false); }
public int FindEmptySlotForItem(InventoryItemObject item) { foreach(Transform slot in slots) { if(CanPutInSlot (slot, item.info.uiInfo.size)) return slots.IndexOf(slot); } return -1; }
public bool IsEmptySlotForItem(int slotIndex, InventoryItemObject item) { Transform slot = slots [slotIndex]; return CanPutInSlot (slot, item.info.uiInfo.size); }
public void ShowItemDescription (InventoryItemObject itemObject, Vector3 offset = new Vector3()) { gameObject.SetActive (true); InventoryItem info = itemObject.info; int siblingIndex = 0; Name.value.text = info.name; if (Name.gameObject.activeSelf) { Name.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } //Price.gameObject.SetActive (IsShowStatInfo (InventorySystem.reference.GetItemTotalPrice (itemObject))); Price.value.text = InventorySystem.reference.GetItemTotalPrice (itemObject).ToString (); if (Price.gameObject.activeSelf) { Price.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } Weight.value.text = info.costInfo.weight.ToString (); if (Weight.gameObject.activeSelf) { Weight.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } PassengerSpace.gameObject.SetActive (IsShowStatInfo (info.costInfo.passengerSpace)); PassengerSpace.value.text = info.costInfo.passengerSpace.ToString (); if (PassengerSpace.gameObject.activeSelf) { PassengerSpace.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } Corruption.value.text = Mathf.Round((info.durabilityInfo.current*10f))/10f + " /"; Corruption.penalty.text = info.durabilityInfo.max.ToString(); if (HaveBonusDurability(itemObject)) Corruption.penalty.color = Color.green; else if (HavePenaltyDurability(itemObject)) Corruption.penalty.color = Color.red; else Corruption.penalty.color = Color.black; if (Corruption.gameObject.activeSelf) { Corruption.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } BonusPower.gameObject.SetActive (IsShowStatInfo (info.bonusInfo.power)); BonusPower.value.text = info.bonusInfo.power.ToString (); if (BonusPower.gameObject.activeSelf) { BonusPower.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } BonusMaxWeight.gameObject.SetActive (IsShowStatInfo (info.bonusInfo.maxWeight)); BonusMaxWeight.value.text = info.bonusInfo.maxWeight.ToString (); if (BonusMaxWeight.gameObject.activeSelf) { BonusMaxWeight.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } BonusLuxury.gameObject.SetActive (IsShowStatInfo (info.bonusInfo.attraction)); BonusLuxury.value.text = info.bonusInfo.attraction.ToString (); if (BonusLuxury.gameObject.activeSelf) { BonusLuxury.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } BonusMaxPassengerSpace.gameObject.SetActive (IsShowStatInfo (info.bonusInfo.maxPassengerSpace)); BonusMaxPassengerSpace.value.text = info.bonusInfo.maxPassengerSpace.ToString (); if (BonusMaxPassengerSpace.gameObject.activeSelf) { BonusMaxPassengerSpace.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } BonusMagicPower.gameObject.SetActive (IsShowStatInfo (info.bonusInfo.magicPower)); BonusMagicPower.value.text = info.bonusInfo.magicPower.ToString (); if (BonusMagicPower.gameObject.activeSelf) { BonusMagicPower.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } BonusMaxSpeed.gameObject.SetActive (IsShowStatInfo (info.bonusInfo.maxSpeed)); BonusMaxSpeed.value.text = info.bonusInfo.maxSpeed.ToString (); if (BonusMaxSpeed.gameObject.activeSelf) { BonusMaxSpeed.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } BonusEquipmentCorruption.gameObject.SetActive (IsShowStatInfo (info.bonusInfo.equipmentDurability)); BonusEquipmentCorruption.value.text = info.bonusInfo.equipmentDurability.ToString ()+"%"; if (BonusEquipmentCorruption.gameObject.activeSelf) { BonusEquipmentCorruption.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } BonusTradePrices.gameObject.SetActive (IsShowStatInfo (info.bonusInfo.tradePricePercent)); BonusTradePrices.value.text = info.bonusInfo.tradePricePercent.ToString ()+"%"; if (BonusTradePrices.gameObject.activeSelf) { BonusTradePrices.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } BonusRepairPrices.gameObject.SetActive (IsShowStatInfo (info.bonusInfo.repairPricePercent)); BonusRepairPrices.value.text = info.bonusInfo.repairPricePercent.ToString ()+"%"; if (BonusRepairPrices.gameObject.activeSelf) { BonusRepairPrices.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } Description.value.text = info.uiInfo.description; if (Description.gameObject.activeSelf) { Description.transform.SetSiblingIndex (siblingIndex); siblingIndex += 1; } grid.Reposition (); /* if (isCompareWindow) { CompareWindow.transform.position = DescriptionWindow.transform.position; CompareWindow.transform.localPosition -= new Vector3(CompareWindow.transform.FindChild("Background").GetComponent<UISprite>().localSize.x,0,0); } else {*/ // set window near mouse transform.position = UICamera.lastHit.point; transform.localPosition += new Vector3 (10, 10, 0); transform.localPosition += new Vector3 (0,transform.FindChild("Background").GetComponent<UISprite>().localSize.y,0); if (IsCompare) { transform.localPosition = offset; transform.localPosition -= new Vector3 (transform.FindChild ("Background").GetComponent<UISprite> ().localSize.x, 0, 0); return; } UIRoot root = null; Transform currentObject = transform; while (true) { if (currentObject.GetComponent<UIRoot> ()) { root = currentObject.GetComponent<UIRoot> (); break; } currentObject = currentObject.parent; } //Debug.Log (root.manualWidth); if (transform.localPosition.x - 10 + transform.FindChild ("Background").GetComponent<UISprite> ().localSize.x > root.manualWidth / 2) { transform.localPosition += new Vector3 (-transform.FindChild ("Background").GetComponent<UISprite> ().localSize.x, 0, 0); } if (transform.localPosition.y + 10 > root.manualHeight / 2) { transform.localPosition += new Vector3 (0, -transform.FindChild ("Background").GetComponent<UISprite> ().localSize.y - 60, 0); } }
public bool IsEmptySlotForItem(int slotIndex, InventoryItemObject item) { Transform slot = slots [slotIndex]; return(CanPutInSlot(slot, item.info.uiInfo.size)); }
public static void ResetItemToCompare() { //Debug.Log ("item to compare set"); itemToCompare = null; }
public void ShowItemDescription(InventoryItemObject itemObject, Vector3 offset = new Vector3()) { gameObject.SetActive(true); InventoryItem info = itemObject.info; int siblingIndex = 0; Name.value.text = info.name; if (Name.gameObject.activeSelf) { Name.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } //Price.gameObject.SetActive (IsShowStatInfo (InventorySystem.reference.GetItemTotalPrice (itemObject))); Price.value.text = InventorySystem.reference.GetItemTotalPrice(itemObject).ToString(); if (Price.gameObject.activeSelf) { Price.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } Weight.value.text = info.costInfo.weight.ToString(); if (Weight.gameObject.activeSelf) { Weight.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } PassengerSpace.gameObject.SetActive(IsShowStatInfo(info.costInfo.passengerSpace)); PassengerSpace.value.text = info.costInfo.passengerSpace.ToString(); if (PassengerSpace.gameObject.activeSelf) { PassengerSpace.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } Corruption.value.text = Mathf.Round((info.durabilityInfo.current * 10f)) / 10f + " /"; Corruption.penalty.text = info.durabilityInfo.max.ToString(); if (HaveBonusDurability(itemObject)) { Corruption.penalty.color = Color.green; } else if (HavePenaltyDurability(itemObject)) { Corruption.penalty.color = Color.red; } else { Corruption.penalty.color = Color.black; } if (Corruption.gameObject.activeSelf) { Corruption.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } BonusPower.gameObject.SetActive(IsShowStatInfo(info.bonusInfo.power)); BonusPower.value.text = info.bonusInfo.power.ToString(); if (BonusPower.gameObject.activeSelf) { BonusPower.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } BonusMaxWeight.gameObject.SetActive(IsShowStatInfo(info.bonusInfo.maxWeight)); BonusMaxWeight.value.text = info.bonusInfo.maxWeight.ToString(); if (BonusMaxWeight.gameObject.activeSelf) { BonusMaxWeight.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } BonusLuxury.gameObject.SetActive(IsShowStatInfo(info.bonusInfo.attraction)); BonusLuxury.value.text = info.bonusInfo.attraction.ToString(); if (BonusLuxury.gameObject.activeSelf) { BonusLuxury.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } BonusMaxPassengerSpace.gameObject.SetActive(IsShowStatInfo(info.bonusInfo.maxPassengerSpace)); BonusMaxPassengerSpace.value.text = info.bonusInfo.maxPassengerSpace.ToString(); if (BonusMaxPassengerSpace.gameObject.activeSelf) { BonusMaxPassengerSpace.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } BonusMagicPower.gameObject.SetActive(IsShowStatInfo(info.bonusInfo.magicPower)); BonusMagicPower.value.text = info.bonusInfo.magicPower.ToString(); if (BonusMagicPower.gameObject.activeSelf) { BonusMagicPower.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } BonusMaxSpeed.gameObject.SetActive(IsShowStatInfo(info.bonusInfo.maxSpeed)); BonusMaxSpeed.value.text = info.bonusInfo.maxSpeed.ToString(); if (BonusMaxSpeed.gameObject.activeSelf) { BonusMaxSpeed.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } BonusEquipmentCorruption.gameObject.SetActive(IsShowStatInfo(info.bonusInfo.equipmentDurability)); BonusEquipmentCorruption.value.text = info.bonusInfo.equipmentDurability.ToString() + "%"; if (BonusEquipmentCorruption.gameObject.activeSelf) { BonusEquipmentCorruption.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } BonusTradePrices.gameObject.SetActive(IsShowStatInfo(info.bonusInfo.tradePricePercent)); BonusTradePrices.value.text = info.bonusInfo.tradePricePercent.ToString() + "%"; if (BonusTradePrices.gameObject.activeSelf) { BonusTradePrices.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } BonusRepairPrices.gameObject.SetActive(IsShowStatInfo(info.bonusInfo.repairPricePercent)); BonusRepairPrices.value.text = info.bonusInfo.repairPricePercent.ToString() + "%"; if (BonusRepairPrices.gameObject.activeSelf) { BonusRepairPrices.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } Description.value.text = info.uiInfo.description; if (Description.gameObject.activeSelf) { Description.transform.SetSiblingIndex(siblingIndex); siblingIndex += 1; } grid.Reposition(); /* * if (isCompareWindow) * { * CompareWindow.transform.position = DescriptionWindow.transform.position; * CompareWindow.transform.localPosition -= new Vector3(CompareWindow.transform.FindChild("Background").GetComponent<UISprite>().localSize.x,0,0); * } * else * {*/ // set window near mouse transform.position = UICamera.lastHit.point; transform.localPosition += new Vector3(10, 10, 0); transform.localPosition += new Vector3(0, transform.FindChild("Background").GetComponent <UISprite>().localSize.y, 0); if (IsCompare) { transform.localPosition = offset; transform.localPosition -= new Vector3(transform.FindChild("Background").GetComponent <UISprite> ().localSize.x, 0, 0); return; } UIRoot root = null; Transform currentObject = transform; while (true) { if (currentObject.GetComponent <UIRoot> ()) { root = currentObject.GetComponent <UIRoot> (); break; } currentObject = currentObject.parent; } //Debug.Log (root.manualWidth); if (transform.localPosition.x - 10 + transform.FindChild("Background").GetComponent <UISprite> ().localSize.x > root.manualWidth / 2) { transform.localPosition += new Vector3(-transform.FindChild("Background").GetComponent <UISprite> ().localSize.x, 0, 0); } if (transform.localPosition.y + 10 > root.manualHeight / 2) { transform.localPosition += new Vector3(0, -transform.FindChild("Background").GetComponent <UISprite> ().localSize.y - 60, 0); } }
public static void SetItemToCompare(InventoryItemObject item) { //Debug.Log ("item to compare set"); itemToCompare = item; }
public Transform FindEmptySlot(InventoryItemObject item, SlotType type, int wagonIndex = -1, int slotIndex = -1) { WagonInventoryUI wagon = null; if (type == SlotType.Wagon) { if (wagonIndex > -1 && wagonIndex < wagonUIs.Count) wagon = wagonUIs [wagonIndex]; else wagon = wagonUIs [0]; } else if (type == SlotType.Shop) wagon = shopInventory; if (wagonIndex > -1 && wagonIndex < wagonUIs.Count) { if (slotIndex > -1 && slotIndex < wagonUIs[wagonIndex].slots.Count) { // if slot and wagon indexes is correct then return specific slot if (wagon.IsEmptySlotForItem(slotIndex, item)) { // all right //SetupUIItem(item, wagonIndex, slotIndex); return GetSlot(type, slotIndex, wagonIndex); } } // if only wagon index is correct then return first empty slot in that wagon int emptySlotIndex = wagon.FindEmptySlotForItem(item); if (emptySlotIndex != -1) { // all right //SetupUIItem(item, wagonIndex, emptySlotIndex); return GetSlot(type, emptySlotIndex, wagonIndex); } } // else return completely first empty slot // should work only with player wagons, not shop for (int checkingWagonIndex = 0; checkingWagonIndex < wagonUIs.Count; checkingWagonIndex++) { if (type == SlotType.Wagon) { wagon = wagonUIs [checkingWagonIndex]; } int emptySlotIndex = wagon.FindEmptySlotForItem(item); if (emptySlotIndex != -1) { //SetupUIItem(item, checkingWagonIndex, emptySlotIndex); return GetSlot(type, emptySlotIndex, checkingWagonIndex); } } Debug.Log ("no inventory space for item"); return null; }
void IPointerUpHandler.OnPointerUp(PointerEventData eventData) { if (_dragging) { bool foundHome = false; // check if inside a droppable area foreach (InventoryCanvas.InventoryCanvasContainer inv in InventoryCanvas.Inventories) { GraphicRaycaster raycaster = inv.inventoryCanvas._raycaster; PointerEventData pointerEventData = new PointerEventData(_eventSystem); pointerEventData.position = Input.mousePosition; List <RaycastResult> results = new List <RaycastResult>(); raycaster.Raycast(pointerEventData, results); foreach (RaycastResult result in results) { if (result.gameObject.GetComponent <IDroppableArea>() != null) { Inventory.Index newIndex; if (inv.inventory.TryMove(_item, _index, pointerEventData.position, out newIndex)) { if (isEquipped) { //unequip the item! inv.inventory.SetParentAndSize(this); if (_item is Weapon) { player.Unequip(Item.EquipmentSlot.Weapon); } else { player.Unequip(((Armor)_item).GetEquipmentSlot()); } isEquipped = false; } else { transform.SetParent(lastParent); } // move the item inv.inventory.UpdatePosition(this, newIndex); _index = newIndex; foundHome = true; } } } } // check the equipment areas, maybe trying to equip //TODO TODO bool toDestroy = false; if (!foundHome) { if (!UIManager.instance._isOverUI) // not over UI, drop item on ground { Vector3 dropPos = player.transform.position; GameObject groundItem = Instantiate(groundItemPrefab, dropPos, Quaternion.identity); groundItem.GetComponent <GroundItem>().SetItem(_item); if (!isEquipped) // if equipped, dont need to remove from slot because its not in an inventory { lastParent.GetComponent <Inventory>().RemoveFromSlot(_item, _index); } //TODO //transform.parent.GetComponent<Inventory>().RemoveFromSlot(_item, _index); //Destroy(gameObject); toDestroy = true; } else // still within UI, return to original position { // else return to original position transform.SetParent(lastParent); transform.localPosition = _originalPosition; } } // return opaqueness Color c = _image.color; c.a = 1f; _image.color = c; _dragging = false; DraggedObject = null; GetComponent <Image>().raycastTarget = true; if (toDestroy) { Destroy(gameObject); } } }
void IPointerDownHandler.OnPointerDown(PointerEventData eventData) { if (_pointerInside) { if (eventData.button == PointerEventData.InputButton.Right) { //determine the type of item if (_item is Weapon) { if (isEquipped) { // item is equipped, either do nothing or unequip TODO } else if (!isEquipped) { isEquipped = true; player.GetInventory().RemoveFromSlot(_item, _index); if (!player.EquipWeapon(this)) { player.GetInventory().AddToSlot(_item, _index); } } } else if (_item is Armor) { if (isEquipped) { // item is equipped, either do nothing or unequip } else if (!isEquipped) { isEquipped = true; player.GetInventory().RemoveFromSlot(_item, _index); if (!player.EquipArmor(this)) { player.GetInventory().AddToSlot(_item, _index); isEquipped = false; } } } } else { _dragging = true; _originalPosition = transform.localPosition; DraggedObject = this; // reparent to show on top of other items //_image.transform.SetAsLastSibling(); lastParent = transform.parent; transform.SetParent(TooltipCanvas.instance.transform); GetComponent <Image>().raycastTarget = false; // make semi-transparent Color c = _image.color; c.a = 0.75f; _image.color = c; } } }
public void Save() { BinaryFormatter bf = new BinaryFormatter(); if (IsSaveExists(3)) { File.Delete(Application.persistentDataPath + "/Save3.sav"); } if (IsSaveExists(2)) { File.Move(Application.persistentDataPath + "/Save2.sav", Application.persistentDataPath + "/Save3.sav"); } if (IsSaveExists(1)) { File.Move(Application.persistentDataPath + "/Save1.sav", Application.persistentDataPath + "/Save2.sav"); } FileStream file = File.Create(Application.persistentDataPath + "/Save1.sav"); SaveData saveData = new SaveData(); //save quests data foreach (JournalQuest quest in quests) { QuestData data = new QuestData(); data.index = JournalQuestsDatabase.reference.GetIndexOf(quest); data.currentStage = quest.currentStage; saveData.quests.Add(data); } //save time data saveData.time.minutes = time.minutes; //save passengers data saveData.passengerData.passengers = passengerData.passengers; //save train equipment data for (int itemIndex = 0; itemIndex < saveData.equippedItems.Length; itemIndex++) { ItemData equippedItemData = new ItemData(); InventoryItemObject item = trainData.equippedItems [itemIndex]; if (item != null) { equippedItemData.index = item.info.databaseIndex; equippedItemData.currentDurabilityPercent = (item.info.durabilityInfo.current / item.info.durabilityInfo.max) * 100; } saveData.equippedItems[itemIndex] = equippedItemData; } //save wagon items data for (int wagonIndex = 0; wagonIndex < wagonData.Count; wagonIndex++) { foreach (InventoryItemObject item in wagonData[wagonIndex].items) { ItemData itemData = new ItemData(); itemData.index = item.info.databaseIndex; itemData.currentDurabilityPercent = (item.info.durabilityInfo.current / item.info.durabilityInfo.max) * 100; itemData.wagonIndex = item.wagonIndex; itemData.slotIndex = item.slotIndex; saveData.items.Add(itemData); } } saveData.townName = townName; saveData.worldData.mailData.remainingTime = MailQuestsController.reference.timeForQuest; saveData.worldData.mailData.canComplete = MailQuestsController.reference.canComplete; saveData.worldData.mailData.inProgress = MailQuestsController.reference.inProgress; saveData.questParameters = QuestsController.globalParameters; bf.Serialize(file, saveData); file.Close(); Debug.Log("Saved!" + " " + Application.persistentDataPath); }
public void Equip(InventoryItemObject item, ref Attributes playerAttributes) { Item.EquipmentSlot eSlot; Item newItem = item.GetItem(); if (newItem is Weapon) { eSlot = Item.EquipmentSlot.Weapon; } else { eSlot = ((Armor)item.GetItem()).GetEquipmentSlot(); } int slot = Convert.ToInt32(eSlot); InventoryItemObject oldItem = Unequip(eSlot, ref playerAttributes); // add the new stats if (item.GetItem()?.GetItemType() == Item.ItemType.Weapon) { foreach (Weapon.Stat stat in (item.GetItem() as Weapon).GetStats()) { if (stat._isBasicStat) { string enumString = stat._stat.ToString(); Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString); playerAttributes.IncrementStat(new Attributes.Stat(statType, (int)stat._value)); } else { Weapon.Stat weapStat = playerAttributes.GetWeaponStats().Find(x => x._stat == stat._stat); if (stat._flatValue) { weapStat += stat; } else { weapStat *= (1 + (stat._value / 100f)); } playerAttributes.SetWeaponStat(weapStat); } } } else if (item.GetItem()?.GetItemType() == Item.ItemType.Armor) { foreach (Armor.Stat stat in (item.GetItem() as Armor).GetStats()) { if (stat._isBasicStat) { string enumString = stat._stat.ToString(); Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString); playerAttributes.IncrementStat(new Attributes.Stat(statType, (int)stat._value)); } else { Armor.Stat armorStat = playerAttributes.GetArmorStats().Find(x => x._stat == stat._stat); if (stat._flatValue) { armorStat += stat; } else { armorStat *= (1 + (stat._value / 100f)); } playerAttributes.SetArmorStat(armorStat); } } } // equip it _equipmentSlots[slot].SetItem(item); item.SetEquipped(true); if (oldItem != null) { oldItem.SetEquipped(false); _player.GetInventory().AddExistingItem(oldItem); // put the old item back into the inventory } }
public void UpdatePosition(InventoryItemObject itemObject, Index ndx) { itemObject.transform.localPosition = PositionAtIndex(ndx._x, ndx._y) - HalfTile(); //OutputInventoryState(); // TODO Take this out }
public void BreakItem(InventoryItemObject item, float value) { item.Break (value); }
public int GetItemTotalPrice(InventoryItemObject item) { if (!IsShopActive ()) { //Debug.Log ("shop is not active"); return item.info.costInfo.timePrice; } Transform slot = item.GetSlot(); if (slot == null) return 0; WagonInventoryUI inventory = slot.parent.parent.GetComponent<WagonInventoryUI>(); if (inventory == shopInventory) { return item.GetBuyPrice (); } else { if (vendorShopInfo.FindInfoByIndex (item.info.databaseIndex) != null) { return item.GetSellPrice (); } else { //Debug.Log ("vendor is not interested"); return 0; } } }
public void BreakItem(InventoryItemObject item, float value) { item.Break(value); }
/*public void BreakWholeInventory(float value) * { * BreakWagon (0, value); * for(int wagonIndex = 0; wagonIndex < PlayerSaveData.reference.wagonData.Count; wagonIndex++) * { * BreakWagon (1 + wagonIndex, value); * } * }*/ IEnumerator UpdateItemsToBreak() { while (true) { while (itemsToBreak.Count != 1 + PlayerSaveData.reference.wagonData.Count) { if (itemsToBreak.Count < 1 + PlayerSaveData.reference.wagonData.Count) { itemsToBreak.Add(null); } else if (itemsToBreak.Count > 1 + PlayerSaveData.reference.wagonData.Count) { itemsToBreak.RemoveAt(itemsToBreak.Count - 1); } } //if (itemsToBreak [0] == null || itemsToBreak [0].IsBroken() || !itemsToBreak [0].IsEquipped()) { for (int itemIndex = PlayerSaveData.reference.trainData.equippedItems.Length - 1; itemIndex >= 0; itemIndex--) { InventoryItemObject equippedItem = PlayerSaveData.reference.trainData.equippedItems [itemIndex]; if (equippedItem != null && !equippedItem.IsBroken()) { itemsToBreak [0] = equippedItem; break; } } for (int wagonIndex = 0; wagonIndex < PlayerSaveData.reference.wagonData.Count; wagonIndex++) { if (itemsToBreak [wagonIndex + 1] == null || itemsToBreak [wagonIndex + 1].IsBroken() || !PlayerSaveData.reference.wagonData [wagonIndex].items.Contains(itemsToBreak [wagonIndex + 1])) { PlayerSaveData.WagonData wagonData = PlayerSaveData.reference.wagonData [wagonIndex]; if (wagonData.items.Count == 0) { continue; } int repairedItemsCount = 0; foreach (InventoryItemObject item in wagonData.items) { if (!item.IsBroken()) { repairedItemsCount += 1; } } if (repairedItemsCount == 0) { continue; } int itemIndex = Random.Range(0, repairedItemsCount); foreach (InventoryItemObject item in wagonData.items) { if (!item.IsBroken()) { if (itemIndex == 0) { itemsToBreak [wagonIndex + 1] = item; break; } itemIndex -= 1; } } } } yield return(null); } }
public void RepairItem(InventoryItemObject item) { TrainTimeScript.reference.SimulateWaitForPassengers (item.GetRepairCost()); item.Repair (); selectingItemToRepair = false; }
public bool CanPutInSlot(Transform slotToPut, InventoryItemObject item) { SlotInfo slotInfo = GetSlotInfo (slotToPut); if (slotInfo.type == SlotType.Equipment) { if (item.info.type == equipmentUI.GetSlotType (slotToPut)) return true; return false; }else if (slotInfo.type == SlotType.Wagon) { WagonInventoryUI wagon = wagonUIs [slotInfo.wagonIndex]; return wagon.CanPutInSlot (slotToPut,item.info.uiInfo.size); }else if (slotInfo.type == SlotType.Shop) { WagonInventoryUI wagon = shopInventory; return wagon.CanPutInSlot (slotToPut,item.info.uiInfo.size); } return false; }