Added save for inventory, slot and item, changed item generation, fixed luck in calculation
This commit is contained in:
parent
dd0251cb3e
commit
22137fffde
@ -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;
|
||||
}
|
||||
|
||||
|
||||
134
save.json
134
save.json
@ -1,29 +1,143 @@
|
||||
{
|
||||
"player": {
|
||||
"playername": "",
|
||||
"playername": "Nicola",
|
||||
"maxHealth": 110,
|
||||
"maxSecondary": 10,
|
||||
"secondary": 10,
|
||||
"secondary": 15,
|
||||
"health": 110,
|
||||
"strength": 7,
|
||||
"dexterity": 5,
|
||||
"intelligence": 3,
|
||||
"level": 0,
|
||||
"experience": 0,
|
||||
"maxExperience": 10,
|
||||
"level": 3,
|
||||
"experience": 6,
|
||||
"maxExperience": 80,
|
||||
"race": "Human",
|
||||
"role": "Warrior",
|
||||
"points": 0,
|
||||
"points": 9,
|
||||
"healthRegen": 30,
|
||||
"secondaryRegen": 5,
|
||||
"isDodging": "False",
|
||||
"killcount": 0,
|
||||
"killcount": 4,
|
||||
"luck": 26,
|
||||
"difficulty": 0
|
||||
},
|
||||
"world": {
|
||||
"cityAmount": 5,
|
||||
"maxCityAmount": 5,
|
||||
"currentTile": "0/0/0",
|
||||
"currentTile": "-1/0/1",
|
||||
"map": {
|
||||
"tile0": "./save/tile0.json",
|
||||
"tile1": "./save/tile1.json"
|
||||
}
|
||||
},
|
||||
"inventory": {
|
||||
"equipment": {
|
||||
"head": "empty",
|
||||
"rightHand": "empty",
|
||||
"leftHand": "empty",
|
||||
"amulet": "empty",
|
||||
"feet": "empty",
|
||||
"shoulders": "empty",
|
||||
"chest": "empty",
|
||||
"ring": "empty"
|
||||
},
|
||||
"bags": {
|
||||
"slot0": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": {
|
||||
"rarity": "COMMON",
|
||||
"place": "BOOTS",
|
||||
"itemName": "Common boots of mana",
|
||||
"MP": 12
|
||||
}
|
||||
},
|
||||
"slot1": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot2": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot3": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot4": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot5": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot6": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot7": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot8": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot9": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot10": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot11": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot12": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot13": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot14": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot15": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot16": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
},
|
||||
"slot17": {
|
||||
"bag1": "empty",
|
||||
"bag2": "empty",
|
||||
"bag3": "empty"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user