reworked interactions, fixed health depleting from testing

This commit is contained in:
TAASONI3
2023-12-29 17:29:03 +01:00
parent 661aa6704b
commit f57389e8a4
42 changed files with 325 additions and 105 deletions

View File

@@ -0,0 +1,54 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Newtonsoft.Json.Linq;
namespace Assets.Scripts.InteractableObjects
{
public class Door : InteractableObject
{
public bool hasInteracted = false;
bool isOpen = false;
public override void handleInteraction(GameObject player)
{
if (hasInteracted)
{
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;"+TextHandler.getText("triedHouse"));
}
else
{
int openChance = new System.Random().Next(4);
if(openChance == 0){
gameObject.GetComponent<Animator>().Play("DoorOpen");
Destroy(gameObject.GetComponent<BoxCollider>());
isOpen = true;
}
else{
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;"+TextHandler.getText("lockedHouse"));
}
}
hasInteracted = true;
}
public string saveHouse(){
string result = "";
result = result + FileHandler.generateJSON("objectname", "\"" + transform.parent.name + "\",\r\n");
result = result + FileHandler.generateJSON("hasInteracted", "\"" + hasInteracted + "\",\r\n");
result = result + FileHandler.generateJSON("isOpen", "\"" + isOpen + "\",\r\n");
result = result + FileHandler.generateJSON("gotItem", "\"" + transform.parent.Find("chest").Find("Body").GetComponent<Chest>().saveChest() + "\"");
return result;
}
public void loadHouse(JToken json){
hasInteracted = bool.Parse(json["hasInteracted"].ToString());
isOpen = bool.Parse(json["isOpen"].ToString());
transform.parent.Find("chest").Find("Body").GetComponent<Chest>().loadChest(bool.Parse(json["gotItem"].ToString()));
if(isOpen){
gameObject.GetComponent<Animator>().Play("DoorOpen");
Destroy(gameObject.GetComponent<BoxCollider>());
}
}
}
}