reworked interactions, fixed health depleting from testing
This commit is contained in:
53
Assets/Scripts/InteractableObjects/Chest.cs
Normal file
53
Assets/Scripts/InteractableObjects/Chest.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using Assets.Scripts.Player;
|
||||
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public class Chest : InteractableObject
|
||||
{
|
||||
bool gotItem = false;
|
||||
|
||||
public override void handleInteraction(GameObject player){
|
||||
if (gotItem)
|
||||
{
|
||||
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;"+TextHandler.getText("alreadyLooted"));
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject.transform.Find("Lid").GetComponent<Animator>().Play("ChestOpen");
|
||||
Item item;
|
||||
int luck = player.GetComponent<PlayerGameObject>().getPlayerStat("Luck").getAmount();
|
||||
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.Find("Lid").GetComponent<Animator>().Play("ChestOpen");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/InteractableObjects/Chest.cs.meta
Normal file
11
Assets/Scripts/InteractableObjects/Chest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a68095ee650a0b5eaefd210c9641289
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
54
Assets/Scripts/InteractableObjects/Door.cs
Normal file
54
Assets/Scripts/InteractableObjects/Door.cs
Normal 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>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/InteractableObjects/Door.cs.meta
Normal file
11
Assets/Scripts/InteractableObjects/Door.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ae65e9f2852fc2fbb96d7c9ec9cafe0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
144
Assets/Scripts/InteractableObjects/Enemy.cs
Normal file
144
Assets/Scripts/InteractableObjects/Enemy.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Player;
|
||||
using Assets.Scripts.Slimes;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public class Enemy : InteractableObject
|
||||
{
|
||||
string enemyname;
|
||||
System.Random rand = new System.Random();
|
||||
BasicSlime slime;
|
||||
SlimeFactory factory = new SlimeFactory();
|
||||
|
||||
void Start()
|
||||
{
|
||||
enemyname = gameObject.name;
|
||||
if (enemyname.Contains("("))
|
||||
{
|
||||
enemyname = enemyname.Split('(')[0];
|
||||
}
|
||||
|
||||
renameEnemy();
|
||||
}
|
||||
|
||||
public override void handleInteraction(GameObject player)
|
||||
{
|
||||
keepAlive = true;
|
||||
}
|
||||
|
||||
private void renameEnemy()
|
||||
{
|
||||
switch (enemyname)
|
||||
{
|
||||
case "SlimeMageIdle":
|
||||
enemyname = "Slime Mage";
|
||||
break;
|
||||
case "SlimeBaseIdle":
|
||||
enemyname = "Slime";
|
||||
break;
|
||||
case "SlimeMetalIdle":
|
||||
enemyname = "Slime Metal";
|
||||
break;
|
||||
case "SlimeMiniBossIdle":
|
||||
enemyname = "Slime MiniBoss";
|
||||
break;
|
||||
case "SlimeWarriorIdle":
|
||||
enemyname = "Slime Warrior";
|
||||
break;
|
||||
case "SlimeForestIdle":
|
||||
enemyname = "Slime Forest";
|
||||
break;
|
||||
case "SlimeBossIdle":
|
||||
enemyname = "Slime Boss";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void scaleEnemy(PlayerGameObject player)
|
||||
{
|
||||
if (slime == null)
|
||||
{
|
||||
switch (enemyname)
|
||||
{
|
||||
case "Slime Mage":
|
||||
slime = factory.generateMageSlime(player);
|
||||
break;
|
||||
case "Slime":
|
||||
slime = factory.generateNormalSlime(player);
|
||||
break;
|
||||
case "Slime Metal":
|
||||
slime = factory.generateMetalSlime(player);
|
||||
break;
|
||||
case "Slime MiniBoss":
|
||||
slime = factory.generateMiniBossSlime(player);
|
||||
break;
|
||||
case "Slime Warrior":
|
||||
slime = factory.generateWarriorSlime(player);
|
||||
break;
|
||||
case "Slime Forest":
|
||||
slime = factory.generateForestSlime(player);
|
||||
break;
|
||||
case "Slime Boss":
|
||||
slime = factory.generateBossSlime(player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int[] getStats()
|
||||
{
|
||||
return slime.getStats();
|
||||
}
|
||||
|
||||
public string getEnemyName()
|
||||
{
|
||||
return enemyname;
|
||||
}
|
||||
|
||||
public int calculateDamage()
|
||||
{
|
||||
return slime.calculateDamage(rand);
|
||||
}
|
||||
|
||||
public int calculateHeavy()
|
||||
{
|
||||
return slime.calculateHeavy(rand);
|
||||
}
|
||||
|
||||
public bool takeDamage(int amount)
|
||||
{
|
||||
return slime.takeDamage(amount, rand);
|
||||
}
|
||||
|
||||
public int getExperience()
|
||||
{
|
||||
return slime.getExperience();
|
||||
}
|
||||
|
||||
public Item getItem()
|
||||
{
|
||||
return slime.getItem();
|
||||
}
|
||||
|
||||
public string saveEnemy()
|
||||
{
|
||||
string result = "";
|
||||
result = result + FileHandler.generateJSON("enemyname", "\"" + enemyname + "\"");
|
||||
if (slime != null)
|
||||
{
|
||||
result = result + ",\r\n" + slime.saveSlime();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void loadEnemy(JToken json)
|
||||
{
|
||||
slime = new BasicSlime(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/InteractableObjects/Enemy.cs.meta
Normal file
11
Assets/Scripts/InteractableObjects/Enemy.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fe18bcd2d3d0d752ae519027875df8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
70
Assets/Scripts/InteractableObjects/InteractableObject.cs
Normal file
70
Assets/Scripts/InteractableObjects/InteractableObject.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public abstract class InteractableObject : MonoBehaviour
|
||||
{
|
||||
public AnimationClip clip;
|
||||
private bool particlePlayed;
|
||||
private bool animationPlayed;
|
||||
public bool keepAlive;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
particlePlayed = false;
|
||||
animationPlayed = false;
|
||||
keepAlive = false;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
destroyObject();
|
||||
}
|
||||
|
||||
public void OnInteraction(GameObject player)
|
||||
{
|
||||
StartCoroutine(playParticle(player));
|
||||
StartCoroutine(playAnimation(player));
|
||||
handleInteraction(player);
|
||||
}
|
||||
|
||||
public abstract void handleInteraction(GameObject player);
|
||||
|
||||
IEnumerator playParticle(GameObject player)
|
||||
{
|
||||
if (GetComponent<ParticleSystem>() != null)
|
||||
{
|
||||
Vector3 playerPos = player.transform.position;
|
||||
playerPos.y = transform.position.y;
|
||||
Quaternion newRotation = Quaternion.LookRotation(playerPos - transform.position, transform.TransformDirection(Vector3.up));
|
||||
ParticleSystem particleSystem = GetComponent<ParticleSystem>();
|
||||
ParticleSystem.ShapeModule shape = particleSystem.shape;
|
||||
shape.rotation = newRotation.eulerAngles;
|
||||
particleSystem.Play();
|
||||
yield return new WaitUntil(() => !particleSystem.isPlaying);
|
||||
}
|
||||
particlePlayed = true;
|
||||
}
|
||||
|
||||
IEnumerator playAnimation(GameObject player)
|
||||
{
|
||||
if (clip != null)
|
||||
{
|
||||
player.GetComponent<Animator>().Play(clip.name);
|
||||
yield return new WaitForSeconds(clip.length);
|
||||
}
|
||||
animationPlayed = true;
|
||||
}
|
||||
|
||||
public void destroyObject()
|
||||
{
|
||||
if (particlePlayed && animationPlayed && !keepAlive)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e98ea4e0e891353aa6bdff9dfb8ead8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/Scripts/InteractableObjects/NPC.cs
Normal file
43
Assets/Scripts/InteractableObjects/NPC.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public class NPC : InteractableObject
|
||||
{
|
||||
bool hasQuest = true;
|
||||
|
||||
public override void handleInteraction(GameObject player)
|
||||
{
|
||||
keepAlive = true;
|
||||
if (hasQuest)
|
||||
{
|
||||
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("SUCCESS;"+TextHandler.getText("gotQuest"));
|
||||
GameObject.Find("QuestLog").GetComponent<QuestLog>().addQuest();
|
||||
hasQuest = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;"+TextHandler.getText("noQuest"));
|
||||
}
|
||||
GameObject.Find("QuestLog").GetComponent<QuestLog>().removeQuests();
|
||||
}
|
||||
|
||||
public bool receivedQuest(){
|
||||
return !hasQuest;
|
||||
}
|
||||
|
||||
public void loadQuest(string receivedQuest){
|
||||
|
||||
this.hasQuest = !bool.Parse(receivedQuest);
|
||||
}
|
||||
|
||||
public string saveNPC(){
|
||||
string result = "";
|
||||
result = result + FileHandler.generateJSON("objectname", "\"" + name + "\",");
|
||||
result = result + FileHandler.generateJSON("receivedQuest", "\"" + !hasQuest + "\"");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/InteractableObjects/NPC.cs.meta
Normal file
11
Assets/Scripts/InteractableObjects/NPC.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 502dfdd16cfb094a89708a6d31f80af2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/InteractableObjects/Ore.cs
Normal file
14
Assets/Scripts/InteractableObjects/Ore.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public class Ore : InteractableObject
|
||||
{
|
||||
public override void handleInteraction(GameObject player)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/InteractableObjects/Ore.cs.meta
Normal file
11
Assets/Scripts/InteractableObjects/Ore.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab6955d1e578ef1b88f1ee3b6fa83051
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/InteractableObjects/Stone.cs
Normal file
14
Assets/Scripts/InteractableObjects/Stone.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public class Stone : InteractableObject
|
||||
{
|
||||
public override void handleInteraction(GameObject player)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/InteractableObjects/Stone.cs.meta
Normal file
11
Assets/Scripts/InteractableObjects/Stone.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fc88a9ab15a9238baf100c2fd070aa7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/InteractableObjects/Tree.cs
Normal file
14
Assets/Scripts/InteractableObjects/Tree.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public class Tree : InteractableObject
|
||||
{
|
||||
public override void handleInteraction(GameObject player)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/InteractableObjects/Tree.cs.meta
Normal file
11
Assets/Scripts/InteractableObjects/Tree.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d069bae9082b7b60a2a05060a98424e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user