Added inventory load, fixed inventory save, v1.3.0

This commit is contained in:
Nicola Sovic
2022-07-04 13:24:54 +02:00
parent 22137fffde
commit 349e023cbf
6 changed files with 193 additions and 39 deletions

View File

@@ -1,5 +1,7 @@
using Newtonsoft.Json.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
@@ -33,15 +35,7 @@ namespace Assets.Scripts
// 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);
createStatBoost();
tooltip = GameObject.Find("TooltipHandler").GetComponent<TooltipHandler>();
itemDisplay.transform.localScale = new Vector3(0,0,0);
changeCurrentBag(0);
@@ -54,6 +48,22 @@ namespace Assets.Scripts
checkEquipColors();
}
private void createStatBoost()
{
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);
}
}
public void addItem(Item item)
{
if (item != null)
@@ -217,18 +227,7 @@ namespace Assets.Scripts
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);
}
createStatBoost();
return statBoost;
}
@@ -307,5 +306,79 @@ namespace Assets.Scripts
result = result + "\r\n}";
return result;
}
public void loadInventory(JToken json)
{
loadEquipment(json["equipment"]);
var jsonData = JObject.Parse(json["bags"].ToString()).Children();
List<JToken> tokens = jsonData.Children().ToList();
int counter = 0;
foreach (JToken slot in tokens)
{
if (slot["bag1"].ToString() != "empty")
{
slots[counter].GetComponent<InventorySlot>().loadSlot(slot["bag1"], 0);
}
if (slot["bag2"].ToString() != "empty")
{
slots[counter].GetComponent<InventorySlot>().loadSlot(slot["bag2"], 1);
}
if (slot["bag3"].ToString() != "empty")
{
slots[counter].GetComponent<InventorySlot>().loadSlot(slot["bag3"], 2);
}
counter++;
}
}
private void loadEquipment(JToken slot)
{
GameObject equip = head;
string slotname = "";
for (int i = 0; i < 8; i++)
{
switch (i)
{
case 0:
equip = head;
slotname = "head";
break;
case 1:
equip = rightHand;
slotname = "rightHand";
break;
case 2:
equip = leftHand;
slotname = "leftHand";
break;
case 3:
equip = amulet;
slotname = "amulet";
break;
case 4:
equip = feet;
slotname = "feet";
break;
case 5:
equip = shoulders;
slotname = "shoulders";
break;
case 6:
equip = chest;
slotname = "chest";
break;
case 7:
equip = ring;
slotname = "ring";
break;
}
if (slot[slotname].ToString() != "empty")
{
equip.GetComponent<InventorySlot>().loadSlot(slot[slotname], -1);
createStatBoost();
calculateStatBoost(equip.GetComponent<InventorySlot>().getEquip().getAttributes(), true);
}
}
}
}
}