Added new item generation, v1.4.0

This commit is contained in:
Nicola Sovic
2022-07-09 18:38:54 +02:00
parent b3af7501a5
commit 8dbc177dcb
8 changed files with 268 additions and 145 deletions

View File

@@ -13,7 +13,7 @@ namespace Assets.Scripts
Item[] items = new Item[3];
int currentBag = 0;
public ItemPlace place;
Item equip;
Equipment equip;
Inventory inventory;
private void Start()
@@ -28,6 +28,11 @@ namespace Assets.Scripts
this.currentBag = currentBag;
}
public int getCurrentBag()
{
return currentBag;
}
public void setItem(Item item, int bag)
{
items[bag] = item;
@@ -51,21 +56,7 @@ namespace Assets.Scripts
inventory.itemDisplay.transform.Find("itemImage").GetComponent<RawImage>().texture = item.image;
inventory.itemDisplay.transform.Find("itemImage").GetComponent<RawImage>().color = item.rarityColor;
inventory.itemDisplay.transform.Find("itemName").GetComponent<Text>().text = item.getName();
string text = "Stats:\r\n";
Dictionary<string, int> attributes = item.getAttributes();
if (item.getRarity() == ItemRarity.LEGENDARY)
{
text = "All stats: +" + attributes["STR"];
}
else
{
foreach (string key in attributes.Keys)
{
text = text + key + ": +" + attributes[key] + "\r\n";
}
}
inventory.itemDisplay.transform.Find("itemStats").GetComponent<Text>().text = text;
inventory.itemDisplay.transform.Find("itemStats").GetComponent<Text>().text = item.getInformation();
int changeY = 0;
if (inventory.itemDisplay.transform.localScale == new Vector3(0,0,0))
{
@@ -125,7 +116,6 @@ namespace Assets.Scripts
inventory.dragImage.transform.position = new Vector3(0,0,0);
InventorySlot startDrag = inventory.getDrag().GetComponent<InventorySlot>();
Item item;
bool isSwap = false;
if (startDrag.place == ItemPlace.BAG)
{
item = startDrag.getItem(startDrag.currentBag);
@@ -136,71 +126,16 @@ namespace Assets.Scripts
}
if (item != null)
{
if (place != item.getPlace() && place != ItemPlace.BAG)
{
return;
}
if (place == ItemPlace.BAG)
{
if (items[currentBag] != null)
{
if (items[currentBag].getPlace() != startDrag.place)
{
return;
}
if (startDrag.place == ItemPlace.BAG)
{
startDrag.setItem(items[currentBag], currentBag);
}
else
{
startDrag.setEquip(items[currentBag]);
inventory.calculateStatBoost(item.getAttributes(), false);
inventory.calculateStatBoost(items[currentBag].getAttributes(), true);
}
isSwap = true;
}
setItem(item, currentBag);
}
else
{
if (equip != null)
{
if (startDrag.place == ItemPlace.BAG)
{
startDrag.setItem(equip, startDrag.currentBag);
isSwap = true;
inventory.calculateStatBoost(equip.getAttributes(), false);
}
else
{
return;
}
}
inventory.calculateStatBoost(item.getAttributes(), true);
setEquip(item);
}
if (!isSwap)
{
if (startDrag.place != ItemPlace.BAG)
{
inventory.calculateStatBoost(startDrag.getEquip().getAttributes(), false);
startDrag.removeEquip();
}
else
{
startDrag.removeItem();
}
}
item.move(startDrag, inventory, this);
}
}
public Item getEquip()
public Equipment getEquip()
{
return equip;
}
public void setEquip(Item item)
public void setEquip(Equipment item)
{
equip = item;
}
@@ -281,7 +216,7 @@ namespace Assets.Scripts
{
if (bag == -1)
{
equip = new Item(json);
equip = new Equipment(json);
}
else
{