Scriptum/Assets/Scripts/Enemies' Scprits/Cave/BossThug.cs

173 lines
6.0 KiB
C#
Raw Normal View History

2022-10-02 18:45:58 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System;
public enum BossThugEnum
{
Pending=0, //waiting for npcs to die
Talking=1,
Attacking=2
}
[RequireComponent(typeof(NpcDialogueManager))]
2022-10-02 18:45:58 +02:00
public class BossThug : MonoBehaviour
{
public GameObject npc1;
public GameObject npc2;
private GameObject player;
private GameObject doorway;
2022-10-24 12:31:09 +02:00
public Animator animator;
private Rigidbody2D rb;
public RuntimeAnimatorController newController;
2022-10-02 18:45:58 +02:00
2022-10-20 23:30:19 +02:00
public bool isAfterConversation = false; // drop it if you can...
public bool isDuringConversation = false;
2022-10-02 18:45:58 +02:00
public BossThugEnum state = BossThugEnum.Pending;
// Start is called before the first frame update
public void Awake()
{
gameObject.GetComponent<NpcDialogueManager>().OpenInDefaultWay = false;
}
2022-10-02 18:45:58 +02:00
void Start()
{
2022-10-24 12:31:09 +02:00
rb = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
2022-10-02 18:45:58 +02:00
npc1 = GameObject.FindObjectsOfType<GameObject>(true).Where(sr => sr.gameObject.name == "ThugBob" && sr.gameObject.tag == "Enemy").ToArray()[0];
npc2 = GameObject.FindObjectsOfType<GameObject>(true).Where(sr => sr.gameObject.name == "ThugBen" && sr.gameObject.tag == "Enemy").ToArray()[0];
player = GameObject.FindGameObjectWithTag("Player");
doorway = GameObject.FindObjectsOfType<GameObject>(true).Where(sr => sr.gameObject.name == "DoorToHell" && sr.gameObject.tag == "SceneTransition").ToArray()[0];
if (npc1 == null || npc2 == null || player == null || doorway == null)
{
throw new Exception("Object has not been found in the scene");
}
}
// Update is called once per frame
void Update()
{
if (
(npc1.GetComponent<Enemy>().health <= 0 && npc1.GetComponent<Enemy>().isKilled == 1) &&
(npc2.GetComponent<Enemy>().health <= 0 && npc2.GetComponent<Enemy>().isKilled == 1) &&
2022-10-02 18:45:58 +02:00
state == BossThugEnum.Pending)
{
state = BossThugEnum.Talking; // UZUPELNIC DIALOG
}
else if (state == BossThugEnum.Attacking && player.GetComponent<Player>().currentHealth <= 0)
{
// 3. Save additional controls
SkillsUIManager.Instance.keyToOpen = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("Skills"));
DisplayExpStatus.keyToExp = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("EXP HEALTH"));
DisplayHealthStatus.keyToHealth = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("EXP HEALTH"));
DisplayExpStatus.keyToExp = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("ExpHlth"));
DisplayHealthStatus.keyToHealth = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("ExpHlth"));
PlayerPrefs.Save();
2022-10-02 18:45:58 +02:00
doorway.GetComponent<DoorBehaviour>().ScenetToMoveTo();
PlayerPrefs.SetFloat("health-S", 10.0f);
PlayerPrefs.SetFloat("health-S", 10.0f);
2022-10-02 18:45:58 +02:00
}
switch (state)
{
case BossThugEnum.Attacking:
{
ActivateKillingMode();
break;
}
case BossThugEnum.Talking:
{
ActivateDialogueMode(); //later add trigger events etc
break;
}
}
}
private void ActivateKillingMode()
{
// set lower radious in order to less attack distance
2023-01-15 23:28:30 +01:00
gameObject.GetComponent<CircleCollider2D>().radius = 1f;
Debug.Log(gameObject.GetComponent<CircleCollider2D>().radius);
2022-10-02 18:45:58 +02:00
gameObject.GetComponent<FollowingEnemy>().enabled=true;
2022-10-24 12:31:09 +02:00
animator.runtimeAnimatorController = Resources.Load("SampleScene/Enemies/BossThugAnimator.controller") as RuntimeAnimatorController;
2022-10-20 23:30:19 +02:00
gameObject.GetComponent<FollowingEnemy>().baseAttack=1000f;
2022-10-02 18:45:58 +02:00
}
private void ActivateDialogueMode()
{
gameObject.GetComponent<CircleCollider2D>().radius = 4f;
2022-10-20 23:30:19 +02:00
}
public void ChanegStatusToAttack()
{
2022-12-04 18:42:34 +01:00
BreakConversation();
SetEndConversation();
2022-10-20 23:30:19 +02:00
state = BossThugEnum.Attacking;
2022-10-02 18:45:58 +02:00
}
public void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player" && state == BossThugEnum.Talking && !isAfterConversation && !isDuringConversation)
{
//gameObject.GetComponent<CircleCollider2D>().enabled = false;
//gameObject.GetComponent<CircleCollider2D>().radius = 2f;
isDuringConversation = true;
2022-12-04 18:42:34 +01:00
gameObject.GetComponent<NpcDialogueManager>().Dialogue.StartDialogue();
}
}
2022-12-04 18:42:34 +01:00
/*public void OnTriggerStay2D(Collider2D other)
2022-10-20 23:30:19 +02:00
{
if (other.tag == "Player" && state == BossThugEnum.Talking && !isAfterConversation && !isDuringConversation)
{
isDuringConversation = true;
2022-12-04 18:42:34 +01:00
gameObject.GetComponent<NpcDialogueManager>().Dialogue.StartDialogue();
}
2022-12-04 18:42:34 +01:00
}*/
public void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "Player" && state == BossThugEnum.Talking && !isAfterConversation && isDuringConversation)
2022-10-20 23:30:19 +02:00
{
//gameObject.GetComponent<CircleCollider2D>().enabled = true;
//gameObject.GetComponent<CircleCollider2D>().radius = 2f;
2022-10-20 23:30:19 +02:00
isDuringConversation = false;
2022-10-20 23:30:19 +02:00
2022-12-06 21:35:17 +01:00
gameObject.GetComponent<NpcDialogueManager>().Dialogue.BreakDialogueStep();
2022-10-20 23:30:19 +02:00
//TODO break dialogue after leaving collider range!!!
2022-10-20 23:30:19 +02:00
}
}
/// <summary>
/// Set as action invoked in event after 'NpcDialogueManager::SetNextDialogue()' function to adjust Trigger2D event listening
/// </summary>
public void BreakConversation()
{
isDuringConversation = false;
}
2022-12-04 18:42:34 +01:00
/// <summary>
/// Mark conversation as finished
/// </summary>
public void SetEndConversation()
{
isAfterConversation = true;
}
2022-10-02 18:45:58 +02:00
}