Added new item generation, v1.4.0
This commit is contained in:
123
Assets/Scripts/Items/Item.cs
Normal file
123
Assets/Scripts/Items/Item.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
protected System.Random rand = new System.Random();
|
||||
protected string itemName;
|
||||
protected ItemRarity rarity;
|
||||
public Texture image;
|
||||
public Color32 rarityColor;
|
||||
|
||||
public Item(int luck)
|
||||
{
|
||||
luck = luck + GameObject.Find("Inventory").GetComponent<Inventory>().getEquipmentBonus()["LCK"];
|
||||
calculateRarity(luck);
|
||||
setColor();
|
||||
loadImage();
|
||||
}
|
||||
|
||||
public Item(JToken json)
|
||||
{
|
||||
rarity = (ItemRarity)Enum.Parse(typeof(ItemRarity), json["rarity"].ToString());
|
||||
itemName = json["itemName"].ToString();
|
||||
setColor();
|
||||
loadImage();
|
||||
}
|
||||
|
||||
private void calculateRarity(int luck)
|
||||
{
|
||||
int number = rand.Next(100);
|
||||
if (number + luck < 70)
|
||||
{
|
||||
rarity = ItemRarity.COMMON;
|
||||
}
|
||||
else if (number + luck >= 70 && number + luck < 95)
|
||||
{
|
||||
rarity = ItemRarity.RARE;
|
||||
}
|
||||
else if (number + luck >= 95 && number + luck < 120)
|
||||
{
|
||||
rarity = ItemRarity.EPIC;
|
||||
}
|
||||
else if (number + luck >= 120)
|
||||
{
|
||||
rarity = ItemRarity.LEGENDARY;
|
||||
}
|
||||
}
|
||||
|
||||
private void setColor()
|
||||
{
|
||||
switch (rarity)
|
||||
{
|
||||
case ItemRarity.COMMON:
|
||||
rarityColor = new Color32(0, 255, 20, 255);
|
||||
break;
|
||||
case ItemRarity.RARE:
|
||||
rarityColor = new Color32(0, 100, 255, 255);
|
||||
break;
|
||||
case ItemRarity.EPIC:
|
||||
rarityColor = new Color32(255, 0, 230, 255);
|
||||
break;
|
||||
case ItemRarity.LEGENDARY:
|
||||
rarityColor = new Color32(255, 230, 0, 255);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void loadImage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual string saveGame()
|
||||
{
|
||||
string result = "";
|
||||
result = result + FileHandler.generateJSON("rarity", "\"" + rarity + "\"") + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("itemName", "\"" + itemName + "\"") + ",\r\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setName(string name)
|
||||
{
|
||||
this.itemName = name;
|
||||
}
|
||||
|
||||
public string getName()
|
||||
{
|
||||
return itemName;
|
||||
}
|
||||
|
||||
public ItemRarity getRarity()
|
||||
{
|
||||
return rarity;
|
||||
}
|
||||
|
||||
public virtual string getInformation()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public virtual void move(InventorySlot startDrag, Inventory inventory, InventorySlot endDrag)
|
||||
{
|
||||
if (endDrag.place != ItemPlace.BAG)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Item item = endDrag.getItem(endDrag.getCurrentBag());
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
endDrag.setItem(this, startDrag.getCurrentBag());
|
||||
}
|
||||
startDrag.setItem(item, endDrag.getCurrentBag());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user