Added save for inventory, slot and item, changed item generation, fixed luck in calculation
This commit is contained in:
@@ -124,8 +124,11 @@ namespace Assets.Scripts
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
FileHandler.generateDirectory();
|
||||
string saveString = "{\r\n\"player\": {\r\n" + player.saveGame();
|
||||
saveString = saveString + "\r\n},\r\n\"world\": {\r\n" + worldGenerator.saveGame() + "\r\n}\r\n}";
|
||||
string saveString = "{\r\n";
|
||||
saveString = saveString + "\"player\": {\r\n" + player.saveGame() + "\r\n},\r\n";
|
||||
saveString = saveString + "\"world\": {\r\n" + worldGenerator.saveGame() + "\r\n},\r\n";
|
||||
saveString = saveString + "\"inventory\": {\r\n" + GameObject.Find("Inventory").GetComponent<Inventory>().saveGame() + "\r\n}\r\n";
|
||||
saveString = saveString + "\r\n}";
|
||||
FileHandler.saveGame(saveString, "./save.json");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,5 +231,81 @@ namespace Assets.Scripts
|
||||
}
|
||||
return statBoost;
|
||||
}
|
||||
|
||||
public string saveGame()
|
||||
{
|
||||
string result = "";
|
||||
int counter = 0;
|
||||
GameObject equip = head;
|
||||
string slotname = "";
|
||||
result = result + "\"equipment\": {\r\n";
|
||||
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 (equip.GetComponent<InventorySlot>().getEquip() != null)
|
||||
{
|
||||
result = result + "\""+slotname+"\": {\r\n";
|
||||
result = result + equip.GetComponent<InventorySlot>().saveGame();
|
||||
result = result + "\r\n}";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = result + "\"" + slotname + "\": \"empty\"";
|
||||
}
|
||||
if (i != 7)
|
||||
{
|
||||
result = result + ",\r\n";
|
||||
}
|
||||
}
|
||||
result = result + "\r\n},\r\n";
|
||||
result = result + "\"bags\": {\r\n";
|
||||
foreach (GameObject slot in slots)
|
||||
{
|
||||
result = result + "\"slot" + counter + "\": {\r\n";
|
||||
result = result + slot.GetComponent<InventorySlot>().saveGame();
|
||||
result = result + "\r\n}";
|
||||
if (counter < slots.Length - 1)
|
||||
{
|
||||
result = result + ",\r\n";
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
result = result + "\r\n}";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ namespace Assets.Scripts
|
||||
{
|
||||
TooltipHandler tooltip;
|
||||
Item[] items = new Item[3];
|
||||
public bool[] itemRemoved = {false, false, false};
|
||||
int currentBag = 0;
|
||||
public ItemPlace place;
|
||||
Item equip;
|
||||
@@ -31,7 +30,6 @@ namespace Assets.Scripts
|
||||
public void setItem(Item item, int bag)
|
||||
{
|
||||
items[bag] = item;
|
||||
itemRemoved[bag] = false;
|
||||
}
|
||||
|
||||
public Item getItem(int bag)
|
||||
@@ -42,7 +40,6 @@ namespace Assets.Scripts
|
||||
public void removeItem()
|
||||
{
|
||||
items[currentBag] = null;
|
||||
itemRemoved[currentBag] = true;
|
||||
}
|
||||
|
||||
public void showTooltip()
|
||||
@@ -247,5 +244,36 @@ namespace Assets.Scripts
|
||||
gameObject.GetComponent<RawImage>().texture = image;
|
||||
}
|
||||
}
|
||||
|
||||
public string saveGame()
|
||||
{
|
||||
string result = "";
|
||||
if (place == ItemPlace.BAG)
|
||||
{
|
||||
for (int i = 1; i <= items.Length;i++)
|
||||
{
|
||||
if (items[i-1] == null)
|
||||
{
|
||||
result = result + "\"bag" + i + "\": \"empty\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = result + "\"bag" + i + "\": {\r\n";
|
||||
result = result + items[i-1].saveGame();
|
||||
result = result + "\r\n}";
|
||||
}
|
||||
if (i != 3)
|
||||
{
|
||||
result = result + ",\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
result = result + equip.saveGame();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,11 @@ namespace Assets.Scripts
|
||||
loadImage();
|
||||
}
|
||||
|
||||
public Item(string save)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void calculateRarity(int luck)
|
||||
{
|
||||
int number = rand.Next(100);
|
||||
@@ -294,6 +299,24 @@ namespace Assets.Scripts
|
||||
{
|
||||
return rarity;
|
||||
}
|
||||
|
||||
public string saveGame()
|
||||
{
|
||||
string result = "";
|
||||
int counter = 0;
|
||||
result = result + FileHandler.generateJSON("rarity", "\"" + rarity + "\"") + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("place", "\"" + place + "\"") + ",\r\n";
|
||||
foreach (string key in attributes.Keys)
|
||||
{
|
||||
result = result + FileHandler.generateJSON(key, attributes[key]);
|
||||
if (counter < attributes.Count - 1)
|
||||
{
|
||||
result = result + ",\r\n";
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -321,6 +321,15 @@ namespace Assets.Scripts
|
||||
|
||||
public int[] getStats()
|
||||
{
|
||||
int luck = 0;
|
||||
if (equipment != null && equipment.ContainsKey("LCK"))
|
||||
{
|
||||
luck = this.luck + equipment["LCK"];
|
||||
}
|
||||
else
|
||||
{
|
||||
luck = this.luck;
|
||||
}
|
||||
int[] result = { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience, points, luck};
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace Assets.Scripts.Slimes
|
||||
protected int level;
|
||||
protected int experience;
|
||||
protected Item item;
|
||||
protected int luck;
|
||||
|
||||
public BasicSlime(Player player)
|
||||
{
|
||||
@@ -33,10 +34,7 @@ namespace Assets.Scripts.Slimes
|
||||
intelligence = playerStats[6];
|
||||
experience = (int)(10 + playerStats[7] * 2.5f);
|
||||
level = playerStats[7];
|
||||
if (new System.Random().Next(100) + 1 < 1000)//10 + playerStats[11])
|
||||
{
|
||||
item = new Item(playerStats[11]);
|
||||
}
|
||||
luck = playerStats[11];
|
||||
}
|
||||
|
||||
public BasicSlime(JToken json)
|
||||
@@ -102,6 +100,10 @@ namespace Assets.Scripts.Slimes
|
||||
|
||||
public Item getItem()
|
||||
{
|
||||
if (new System.Random().Next(100) + 1 < 10 + luck)
|
||||
{
|
||||
item = new Item(luck);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user