Added images for left and right hand, added new item-hover display, added item drag animation, v1.3.0
This commit is contained in:
@@ -16,17 +16,34 @@ namespace Assets.Scripts
|
||||
public GameObject amulet;
|
||||
public GameObject leftHand;
|
||||
public GameObject rightHand;
|
||||
public GameObject dragImage;
|
||||
public GameObject itemDisplay;
|
||||
|
||||
public GameObject[] bags;
|
||||
public GameObject[] slots;
|
||||
|
||||
Dictionary<string, int> statBoost;
|
||||
|
||||
public int currentBag = -1;
|
||||
|
||||
GameObject startDrag;
|
||||
TooltipHandler tooltip;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
statBoost = new Dictionary<string, int>();
|
||||
statBoost.Add("HP", 0);
|
||||
statBoost.Add("MP", 0);
|
||||
statBoost.Add("HPR", 0);
|
||||
statBoost.Add("MPR", 0);
|
||||
statBoost.Add("STR", 0);
|
||||
statBoost.Add("DEX", 0);
|
||||
statBoost.Add("INT", 0);
|
||||
statBoost.Add("LCK", 0);
|
||||
tooltip = GameObject.Find("TooltipHandler").GetComponent<TooltipHandler>();
|
||||
itemDisplay.transform.localScale = new Vector3(0,0,0);
|
||||
changeCurrentBag(0);
|
||||
}
|
||||
|
||||
@@ -41,15 +58,14 @@ namespace Assets.Scripts
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("SUCCESS;You got an item!");
|
||||
bool itemAdded = false;
|
||||
for (int i = 0; i < bags.Length; i++)
|
||||
{
|
||||
for (int j = 0; j < slots.Length; j++)
|
||||
{
|
||||
if (slots[j].GetComponent<InventorySlot>().getItem() == null)
|
||||
if (slots[j].GetComponent<InventorySlot>().getItem(i) == null)
|
||||
{
|
||||
slots[j].GetComponent<InventorySlot>().setItem(item);
|
||||
slots[j].GetComponent<InventorySlot>().setItem(item, i);
|
||||
itemAdded = true;
|
||||
slots[j].GetComponent<RawImage>().color = item.rarityColor;
|
||||
slots[j].GetComponent<RawImage>().texture = item.image;
|
||||
@@ -58,9 +74,14 @@ namespace Assets.Scripts
|
||||
}
|
||||
if (itemAdded)
|
||||
{
|
||||
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("SUCCESS;You got an item!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!itemAdded)
|
||||
{
|
||||
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;No inventory space left.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +105,7 @@ namespace Assets.Scripts
|
||||
Item item;
|
||||
for (int i = 0; i < slots.Length; i++)
|
||||
{
|
||||
item = slots[i].GetComponent<InventorySlot>().getItem();
|
||||
item = slots[i].GetComponent<InventorySlot>().getItem(currentBag);
|
||||
if (item != null)
|
||||
{
|
||||
slots[i].GetComponent<RawImage>().color = item.rarityColor;
|
||||
@@ -178,6 +199,37 @@ namespace Assets.Scripts
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void calculateStatBoost(Dictionary<string, int> attributes, bool isAddition)
|
||||
{
|
||||
foreach (string key in attributes.Keys)
|
||||
{
|
||||
if (isAddition)
|
||||
{
|
||||
statBoost[key] = statBoost[key] + attributes[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
statBoost[key] = statBoost[key] - attributes[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, int> getEquipmentBonus()
|
||||
{
|
||||
if (statBoost == null)
|
||||
{
|
||||
statBoost = new Dictionary<string, int>();
|
||||
statBoost.Add("HP", 0);
|
||||
statBoost.Add("MP", 0);
|
||||
statBoost.Add("HPR", 0);
|
||||
statBoost.Add("MPR", 0);
|
||||
statBoost.Add("STR", 0);
|
||||
statBoost.Add("DEX", 0);
|
||||
statBoost.Add("INT", 0);
|
||||
statBoost.Add("LCK", 0);
|
||||
}
|
||||
return statBoost;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,12 @@ namespace Assets.Scripts
|
||||
int currentBag = 0;
|
||||
public ItemPlace place;
|
||||
Item equip;
|
||||
Inventory inventory;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
tooltip = GameObject.Find("TooltipHandler").GetComponent<TooltipHandler>();
|
||||
inventory = GameObject.Find("Inventory").GetComponent<Inventory>();
|
||||
loadImages();
|
||||
}
|
||||
|
||||
@@ -26,15 +28,15 @@ namespace Assets.Scripts
|
||||
this.currentBag = currentBag;
|
||||
}
|
||||
|
||||
public void setItem(Item item)
|
||||
public void setItem(Item item, int bag)
|
||||
{
|
||||
items[currentBag] = item;
|
||||
itemRemoved[currentBag] = false;
|
||||
items[bag] = item;
|
||||
itemRemoved[bag] = false;
|
||||
}
|
||||
|
||||
public Item getItem()
|
||||
public Item getItem(int bag)
|
||||
{
|
||||
return items[currentBag];
|
||||
return items[bag];
|
||||
}
|
||||
|
||||
public void removeItem()
|
||||
@@ -45,52 +47,82 @@ namespace Assets.Scripts
|
||||
|
||||
public void showTooltip()
|
||||
{
|
||||
Item item = getItemForTooltip();
|
||||
if (item != null)
|
||||
{
|
||||
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();
|
||||
foreach (string key in attributes.Keys)
|
||||
{
|
||||
text = text + key + ": " + attributes[key] + "\r\n";
|
||||
}
|
||||
inventory.itemDisplay.transform.Find("itemStats").GetComponent<Text>().text = text;
|
||||
int changeY = 0;
|
||||
if (inventory.itemDisplay.transform.localScale == new Vector3(0,0,0))
|
||||
{
|
||||
if (Input.mousePosition.y < Screen.height / 2)
|
||||
{
|
||||
changeY = -150;
|
||||
}
|
||||
inventory.itemDisplay.transform.position = new Vector3(Input.mousePosition.x - 175, Input.mousePosition.y - changeY, 0);
|
||||
}
|
||||
inventory.itemDisplay.transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private Item getItemForTooltip()
|
||||
{
|
||||
Item item = null;
|
||||
if (place == ItemPlace.BAG)
|
||||
{
|
||||
if (items[currentBag] != null)
|
||||
{
|
||||
string text = items[currentBag].getDisplayText();
|
||||
Item equip = GameObject.Find("Inventory").GetComponent<Inventory>().getEquip(items[currentBag].getPlace());
|
||||
if (equip != null)
|
||||
{
|
||||
text = "(Current)\r\n" + equip.getDisplayText() + "----------\r\n" + text;
|
||||
}
|
||||
tooltip.showTooltip(text);
|
||||
}
|
||||
item = items[currentBag];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (equip != null)
|
||||
{
|
||||
tooltip.showTooltip(equip.getDisplayText());
|
||||
}
|
||||
item = equip;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public void hideTooltip()
|
||||
{
|
||||
tooltip.hideToolTip();
|
||||
}
|
||||
|
||||
public void onClick()
|
||||
{
|
||||
removeItem();
|
||||
tooltip.hideToolTip();
|
||||
inventory.itemDisplay.transform.localScale = new Vector3(0,0,0);
|
||||
}
|
||||
|
||||
public void OnMouseDrag()
|
||||
{
|
||||
GameObject.Find("Inventory").GetComponent<Inventory>().setDrag(gameObject);
|
||||
inventory.setDrag(gameObject);
|
||||
Item toMove;
|
||||
if (place == ItemPlace.BAG)
|
||||
{
|
||||
toMove = items[currentBag];
|
||||
}
|
||||
else
|
||||
{
|
||||
toMove = equip;
|
||||
}
|
||||
if (toMove != null)
|
||||
{
|
||||
inventory.dragImage.GetComponent<RawImage>().color = toMove.rarityColor;
|
||||
inventory.dragImage.GetComponent<RawImage>().texture = toMove.image;
|
||||
inventory.dragImage.transform.position = new Vector3(Input.mousePosition.x - 50, Input.mousePosition.y - 50, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMouseUp()
|
||||
{
|
||||
GameObject startDrag = GameObject.Find("Inventory").GetComponent<Inventory>().getDrag();
|
||||
inventory.dragImage.GetComponent<RawImage>().color = new Color(0,0,0,0);
|
||||
inventory.dragImage.GetComponent<RawImage>().texture = null;
|
||||
inventory.dragImage.transform.position = new Vector3(0,0,0);
|
||||
GameObject startDrag = inventory.getDrag();
|
||||
Item item;
|
||||
bool isSwap = false;
|
||||
if (startDrag.GetComponent<InventorySlot>().place == ItemPlace.BAG)
|
||||
{
|
||||
item = startDrag.GetComponent<InventorySlot>().getItem();
|
||||
item = startDrag.GetComponent<InventorySlot>().getItem(currentBag);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -106,10 +138,19 @@ namespace Assets.Scripts
|
||||
{
|
||||
if (items[currentBag] != null)
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().setItem(items[currentBag]);
|
||||
if (startDrag.GetComponent<InventorySlot>().place == ItemPlace.BAG)
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().setItem(items[currentBag], currentBag);
|
||||
}
|
||||
else
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().setEquip(items[currentBag]);
|
||||
inventory.calculateStatBoost(item.getAttributes(), false);
|
||||
inventory.calculateStatBoost(items[currentBag].getAttributes(), true);
|
||||
}
|
||||
isSwap = true;
|
||||
}
|
||||
setItem(item);
|
||||
setItem(item, currentBag);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -117,20 +158,23 @@ namespace Assets.Scripts
|
||||
{
|
||||
if (startDrag.GetComponent<InventorySlot>().place == ItemPlace.BAG)
|
||||
{
|
||||
startDrag.GetComponent<InventorySlot>().setItem(equip);
|
||||
startDrag.GetComponent<InventorySlot>().setItem(equip, currentBag);
|
||||
isSwap = true;
|
||||
inventory.calculateStatBoost(equip.getAttributes(), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
inventory.calculateStatBoost(item.getAttributes(), true);
|
||||
setEquip(item);
|
||||
}
|
||||
if (!isSwap)
|
||||
{
|
||||
if (startDrag.GetComponent<InventorySlot>().place != ItemPlace.BAG)
|
||||
{
|
||||
inventory.calculateStatBoost(startDrag.GetComponent<InventorySlot>().getEquip().getAttributes(), false);
|
||||
startDrag.GetComponent<InventorySlot>().removeEquip();
|
||||
}
|
||||
else
|
||||
@@ -174,7 +218,7 @@ namespace Assets.Scripts
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Boots");
|
||||
break;
|
||||
case ItemPlace.SHOULDER:
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Shoulder");
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Shoulders");
|
||||
break;
|
||||
case ItemPlace.AMULET:
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Amulet");
|
||||
|
||||
@@ -33,13 +33,59 @@ namespace Assets.Scripts
|
||||
}
|
||||
calculateAttributes(luck, numberOfAttributes);
|
||||
place = (ItemPlace)rand.Next(8);
|
||||
string replacement = "";
|
||||
if (place == ItemPlace.LEFTHAND)
|
||||
{
|
||||
switch (GameObject.Find("Player").GetComponent<Player>().getClass().classname)
|
||||
{
|
||||
case "Warrior":
|
||||
replacement = "greatshield";
|
||||
break;
|
||||
case "Thief":
|
||||
replacement = "shield";
|
||||
break;
|
||||
case "Mage":
|
||||
replacement = "orb";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (place == ItemPlace.RIGHTHAND)
|
||||
{
|
||||
switch (GameObject.Find("Player").GetComponent<Player>().getClass().classname)
|
||||
{
|
||||
case "Warrior":
|
||||
replacement = "sword";
|
||||
break;
|
||||
case "Thief":
|
||||
replacement = "dagger";
|
||||
break;
|
||||
case "Mage":
|
||||
replacement = "wand";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (itemName != null)
|
||||
{
|
||||
itemName = rarity.ToString() + " " + place.ToString() + " of " + itemName;
|
||||
if (replacement.Length > 0)
|
||||
{
|
||||
itemName = rarity.ToString() + " " + replacement + " of " + itemName;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemName = rarity.ToString() + " " + place.ToString() + " of " + itemName;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
itemName = rarity.ToString() + " " + place.ToString();
|
||||
if (replacement.Length > 0)
|
||||
{
|
||||
itemName = rarity.ToString() + " " + replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemName = rarity.ToString() + " " + place.ToString();
|
||||
}
|
||||
}
|
||||
itemName = itemName.ToLower();
|
||||
itemName = char.ToUpper(itemName[0]) + itemName.Substring(1);
|
||||
@@ -224,7 +270,7 @@ namespace Assets.Scripts
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Boots");
|
||||
break;
|
||||
case ItemPlace.SHOULDER:
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Shoulder");
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Shoulders");
|
||||
break;
|
||||
case ItemPlace.AMULET:
|
||||
image = Resources.Load<Texture>("Equipment/Inv_Amulet");
|
||||
@@ -237,6 +283,11 @@ namespace Assets.Scripts
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, int> getAttributes()
|
||||
{
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user