reworked interactions, fixed health depleting from testing
This commit is contained in:
@@ -6,6 +6,7 @@ using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scripts.Player;
|
||||
using Assets.Scripts.InteractableObjects;
|
||||
|
||||
public class Controls : MonoBehaviour
|
||||
{
|
||||
@@ -141,22 +142,17 @@ public class Controls : MonoBehaviour
|
||||
fight.GetComponent<Fight>().startFight(worldGen.GetComponent<WorldGenerator>().getCurrentTile(), target, player);
|
||||
break;
|
||||
case "Tree":
|
||||
StartCoroutine(playAnimation(target, "Chopping"));
|
||||
player.GetComponent<PlayerGameObject>().getPlayer().getStat("TreeCount").changeAmount(1);
|
||||
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Wood"));
|
||||
break;
|
||||
case "Stone":
|
||||
StartCoroutine(playAnimation(target, "Mining"));
|
||||
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Rock"));
|
||||
break;
|
||||
case "NPC":
|
||||
target.GetComponent<NPC>().interact();
|
||||
break;
|
||||
case "Door":
|
||||
target.GetComponent<Door>().interact();
|
||||
break;
|
||||
case "Chest":
|
||||
target.GetComponent<Chest>().interact();
|
||||
break;
|
||||
case "Ore":
|
||||
if (target.name.ToLower().Contains("iron"))
|
||||
@@ -176,44 +172,13 @@ public class Controls : MonoBehaviour
|
||||
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Tin ore"));
|
||||
}
|
||||
player.GetComponent<PlayerGameObject>().getPlayer().getStat("OreCount").changeAmount(1);
|
||||
StartCoroutine(playAnimation(target, "Mining"));
|
||||
break;
|
||||
}
|
||||
target.GetComponent<InteractableObject>().OnInteraction(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator playParticle(GameObject target)
|
||||
{
|
||||
Vector3 playerPos = player.transform.position;
|
||||
playerPos.y = target.transform.position.y;
|
||||
Quaternion newRotation = Quaternion.LookRotation(playerPos - target.transform.position, target.transform.TransformDirection(Vector3.up));
|
||||
ParticleSystem particleSystem = target.GetComponent<ParticleSystem>();
|
||||
ParticleSystem.ShapeModule shape = particleSystem.shape;
|
||||
shape.rotation = newRotation.eulerAngles;
|
||||
particleSystem.Play();
|
||||
yield return new WaitUntil(() => !particleSystem.isPlaying);
|
||||
Destroy(target);
|
||||
}
|
||||
|
||||
IEnumerator playAnimation(GameObject target, string key)
|
||||
{
|
||||
player.GetComponent<Animator>().Play(key);
|
||||
Animator animator = player.GetComponent<Animator>();
|
||||
AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
|
||||
float length = 0;
|
||||
foreach (AnimationClip clip in clips)
|
||||
{
|
||||
if (clip.name.ToLower() == key.ToLower())
|
||||
{
|
||||
length = clip.length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
yield return new WaitForSeconds(length);
|
||||
Destroy(target);
|
||||
}
|
||||
|
||||
public void OnInventory()
|
||||
{
|
||||
uihandler.switchInventory();
|
||||
|
||||
@@ -5,6 +5,7 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scripts.Player;
|
||||
using Assets.Scripts.InteractableObjects;
|
||||
|
||||
public class Fight : MonoBehaviour
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Localization.Settings;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scripts.InteractableObjects;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
|
||||
8
Assets/Scripts/InteractableObjects.meta
Normal file
8
Assets/Scripts/InteractableObjects.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: abcb4e1f5010a0bde9b4bdc47563e496
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -4,24 +4,13 @@ using UnityEngine;
|
||||
using System;
|
||||
using Assets.Scripts.Player;
|
||||
|
||||
namespace Assets.Scripts
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public class Chest : MonoBehaviour
|
||||
public class Chest : InteractableObject
|
||||
{
|
||||
bool gotItem = false;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void interact(){
|
||||
public override void handleInteraction(GameObject player){
|
||||
if (gotItem)
|
||||
{
|
||||
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;"+TextHandler.getText("alreadyLooted"));
|
||||
@@ -30,7 +19,7 @@ namespace Assets.Scripts
|
||||
{
|
||||
gameObject.transform.Find("Lid").GetComponent<Animator>().Play("ChestOpen");
|
||||
Item item;
|
||||
int luck = GameObject.Find("Player").GetComponent<PlayerGameObject>().getPlayerStat("Luck").getAmount();
|
||||
int luck = player.GetComponent<PlayerGameObject>().getPlayerStat("Luck").getAmount();
|
||||
int type = new System.Random().Next(3);
|
||||
switch (type)
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 542700d30d7f9c98a910fb33e30c4174
|
||||
guid: 3a68095ee650a0b5eaefd210c9641289
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -4,26 +4,14 @@ using UnityEngine;
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Assets.Scripts
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public class Door : MonoBehaviour
|
||||
public class Door : InteractableObject
|
||||
{
|
||||
public bool hasInteracted = false;
|
||||
bool isOpen = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void interact()
|
||||
public override void handleInteraction(GameObject player)
|
||||
{
|
||||
if (hasInteracted)
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14e8c3bbd04c0574da570d1bc8d00649
|
||||
guid: 5ae65e9f2852fc2fbb96d7c9ec9cafe0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -6,17 +6,15 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public class Enemy : MonoBehaviour
|
||||
public class Enemy : InteractableObject
|
||||
{
|
||||
string enemyname;
|
||||
System.Random rand = new System.Random();
|
||||
BasicSlime slime;
|
||||
SlimeFactory factory = new SlimeFactory();
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
enemyname = gameObject.name;
|
||||
@@ -28,10 +26,9 @@ namespace Assets.Scripts
|
||||
renameEnemy();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
public override void handleInteraction(GameObject player)
|
||||
{
|
||||
|
||||
keepAlive = true;
|
||||
}
|
||||
|
||||
private void renameEnemy()
|
||||
@@ -115,7 +112,7 @@ namespace Assets.Scripts
|
||||
|
||||
public bool takeDamage(int amount)
|
||||
{
|
||||
return slime.takeDamage(amount,rand);
|
||||
return slime.takeDamage(amount, rand);
|
||||
}
|
||||
|
||||
public int getExperience()
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc3c1c0815bce34498b5dc8b199d0118
|
||||
guid: 2fe18bcd2d3d0d752ae519027875df8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
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:
|
||||
@@ -2,25 +2,15 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public class NPC : MonoBehaviour
|
||||
public class NPC : InteractableObject
|
||||
{
|
||||
bool hasQuest = true;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void interact()
|
||||
|
||||
public override void handleInteraction(GameObject player)
|
||||
{
|
||||
keepAlive = true;
|
||||
if (hasQuest)
|
||||
{
|
||||
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("SUCCESS;"+TextHandler.getText("gotQuest"));
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87ac36bb4d63c7b4f901ce681578ca4b
|
||||
guid: 502dfdd16cfb094a89708a6d31f80af2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
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:
|
||||
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scripts.InteractableObjects;
|
||||
|
||||
namespace Assets.Scripts.Player
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using Assets.Scripts.Classes;
|
||||
using Assets.Scripts.Races;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnityEngine.InputSystem;
|
||||
using Assets.Scripts.InteractableObjects;
|
||||
|
||||
namespace Assets.Scripts.Player
|
||||
{
|
||||
@@ -88,7 +89,7 @@ namespace Assets.Scripts.Player
|
||||
{
|
||||
now = DateTime.Now;
|
||||
player.regainSecondary(inventory.getEquipmentBonus()["MPR"], inventory.getEquipmentBonus()["MP"]);
|
||||
player.healPlayer(/*4 - difficulty * 2*/-20, inventory.getEquipmentBonus()["HP"]);
|
||||
player.healPlayer(4 - difficulty * 2, inventory.getEquipmentBonus()["HP"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Assets.Scripts.InteractableObjects;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Assets.Scripts.InteractableObjects;
|
||||
|
||||
public class Tile : MonoBehaviour
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user