63 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace Assets.Scripts
{
public class Chest : MonoBehaviour
{
bool gotItem = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void interact(){
if (gotItem)
{
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;You already looted this chest");
}
else
{
gameObject.transform.parent.Find("Lid").GetComponent<Animator>().Play("ChestOpen");
Item item;
int luck = GameObject.Find("Player").GetComponent<Player>().getStats()[11];
int type = new System.Random().Next(3);
switch (type)
{
case 0:
// Maybe add luck to increase chance for equipment
item = new Equipment(luck);
break;
/*case 1:
//Removed lore for now... no idea for lore
break;*/
default:
item = new Item(luck, false);
break;
}
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(item);
}
gotItem = true;
}
public bool saveChest(){
return gotItem;
}
public void loadChest(bool gotItem){
this.gotItem = gotItem;
if(gotItem){
gameObject.transform.parent.Find("Lid").GetComponent<Animator>().Play("ChestOpen");
}
}
}
}