Scriptum/Assets/Scripts/REFACTORING/Application/Tools/CounterRespowner.cs

104 lines
2.4 KiB
C#
Raw Normal View History

2022-12-29 21:03:40 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using System.Collections;
class CounterRespowner : MonoBehaviour
{
public const string RESPOWNER_NAME = "DungeonRespowner";
public bool Respown = true;
public int Counter = 20;
public List<GameObject> minions;
public List<GameObject> respownPoints;
public int killedMinions = 0;
private IEnumerator coroutine;
2023-01-07 20:21:00 +01:00
public GameObject associatedChest;
2022-12-29 21:03:40 +01:00
public void Start()
{
2023-01-07 20:21:00 +01:00
2022-12-29 21:03:40 +01:00
}
public void Update()
{
2023-01-07 20:21:00 +01:00
if(associatedChest == null)
{
associatedChest = GameObject.FindGameObjectWithTag("ChestCollection").transform.Find("Prize Chest")?.gameObject;
if(associatedChest != null)
associatedChest.GetComponent<ChestWrapper>().Lock();
}
2022-12-29 21:03:40 +01:00
if(Respown && Counter > 0)
{
Respown = false;
if (killedMinions < 4 && Counter > 20)
{
coroutine = SpownWithDelay(1.5f);
} else if(Counter <= 20 && killedMinions >= 4)
{
coroutine = SpownWithDelay(3.0f);
} else
{
Debug.Log(Counter);
coroutine = SpownWithDelay(0.5f);
2022-12-29 21:03:40 +01:00
}
StartCoroutine(coroutine);
}
2023-01-07 20:21:00 +01:00
if (Counter <= 0 && killedMinions >= 30)
associatedChest.GetComponent<ChestWrapper>().Unlock();
2022-12-29 21:03:40 +01:00
}
// najpier 10
// a potem w wiekszych dstepach kolejne 20
private IEnumerator SpownWithDelay(float waitTime)
{
yield return new WaitForSeconds(waitTime);
RespownMinion();
Counter -= 1;
Respown = true;
}
public void RespownMinion()
{
GameObject minion = null;
Vector3 spowner = Vector3.zero;
// Draw minion
minion = minions
.ElementAt(UnityEngine.Random.Range(0, minions.Count()))
;
// Decide which spowner use
GameObject spownerObject = null;
2022-12-29 21:03:40 +01:00
do
2022-12-29 21:03:40 +01:00
{
spownerObject = respownPoints
.ElementAt(UnityEngine.Random.Range(0, respownPoints.Count()));
} while (spownerObject.GetComponent<MinionRespowner>().Blocked == true);
2022-12-29 21:03:40 +01:00
// Spawn object
spownerObject.GetComponent<MinionRespowner>().Respown(minion);
2022-12-29 21:03:40 +01:00
}
2022-12-29 21:03:40 +01:00
}