119 lines
3.9 KiB
C#
119 lines
3.9 KiB
C#
using Photon.Pun;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class RiftRaidEnemySpawner : MonoBehaviour
|
|
{
|
|
[Header("ZoneData:")]
|
|
[SerializeField] private ZoneData zoneData;
|
|
|
|
[Header("Events:")]
|
|
[SerializeField] private GameEvent onMultiJobBonusRetrievedEvent;
|
|
[Header("Listeners:")]
|
|
[SerializeField] private GameEventListener_Float experienceOnDeath;
|
|
|
|
[Header("Enemies:")]
|
|
[SerializeField] private List<GameObject> enemyPrefabs = new List<GameObject>();
|
|
[Header("Boss Prefabs:")]
|
|
[SerializeField] private List<GameObject> bossPrefabs = new List<GameObject>();
|
|
[Header("Spawnpoint Variations:")]
|
|
[SerializeField] private List<Transform> spawnpoints = new List<Transform>();
|
|
[Header("Boss Spawnpoint")]
|
|
[SerializeField] private Transform bossSpawnpoint;
|
|
[Header("CloseRiftReward Spawnpoint")]
|
|
[SerializeField] private Transform closeRiftRewardSpawnpoint;
|
|
|
|
PhotonView photonView;
|
|
|
|
UnitDifficultySettings unitDifficultySettings;
|
|
UnitDifficultySetter unitDifficultySetter;
|
|
GameObject spawnedEnemy;
|
|
|
|
int spawnpointIndex;
|
|
int totalEnemies;
|
|
bool rewardSent = false;
|
|
|
|
public Dictionary<int, int> enemyType_Quantity;
|
|
|
|
private List<int[]> keyValuePairs = new List<int[]>();
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
photonView = GetComponent<PhotonView>();
|
|
|
|
enemyType_Quantity = new Dictionary<int, int>();
|
|
|
|
for (int i = 0; i < zoneData.possibleEnemies.Count; i++)
|
|
{
|
|
enemyType_Quantity.Add((int)zoneData.possibleEnemies[i], Random.Range(GameConstants.GameBalancing.GetMinimumQuantityByEnemyID(zoneData.possibleEnemies[i]), GameConstants.GameBalancing.GetMaximumQuantityByEnemyID(zoneData.possibleEnemies[i])));
|
|
}
|
|
|
|
unitDifficultySettings = GameDifficultyController.Instance.GetCurrentDifficultySettings();
|
|
|
|
experienceOnDeath.Response.AddListener(CountTowardsCompletion);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (PhotonNetwork.IsMasterClient)
|
|
StartCoroutine(SpawnEnemies());
|
|
}
|
|
|
|
IEnumerator SpawnEnemies()
|
|
{
|
|
keyValuePairs.Clear();
|
|
foreach (KeyValuePair<int, int> entry in enemyType_Quantity)
|
|
{
|
|
keyValuePairs.Add(new int[]
|
|
{
|
|
entry.Key,
|
|
entry.Value
|
|
});
|
|
}
|
|
yield return null;
|
|
|
|
for (int i = 0; i < keyValuePairs.Count; i++)
|
|
{
|
|
spawnpointIndex = i;
|
|
spawnpointIndex %= spawnpoints.Count;
|
|
|
|
for (int j = 0; j < keyValuePairs[i][1]; j++)
|
|
{
|
|
spawnedEnemy = PhotonNetwork.Instantiate("Enemies/" + enemyPrefabs[keyValuePairs[i][0]].name, spawnpoints[spawnpointIndex].position, spawnpoints[spawnpointIndex].rotation);
|
|
totalEnemies++;
|
|
unitDifficultySetter = spawnedEnemy.GetComponentInChildren<UnitDifficultySetter>(true);
|
|
unitDifficultySetter.InitializeUnitDifficulty(unitDifficultySettings);
|
|
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
spawnedEnemy = PhotonNetwork.Instantiate("Bosses/" + bossPrefabs[Random.Range(0,bossPrefabs.Count)].name, bossSpawnpoint.position, bossSpawnpoint.rotation);
|
|
totalEnemies++;
|
|
unitDifficultySetter = spawnedEnemy.GetComponentInChildren<UnitDifficultySetter>(true);
|
|
unitDifficultySetter.InitializeUnitDifficulty(unitDifficultySettings);
|
|
|
|
yield return new WaitForSeconds(0.5f);
|
|
|
|
photonView.RPC(nameof(RPC_UpdateTotalEnemies), RpcTarget.Others, totalEnemies);
|
|
}
|
|
|
|
[PunRPC]
|
|
private void RPC_UpdateTotalEnemies(int totalEnemies)
|
|
{
|
|
this.totalEnemies = totalEnemies;
|
|
}
|
|
|
|
private void CountTowardsCompletion(float exp)
|
|
{
|
|
totalEnemies--;
|
|
if(totalEnemies <= 0 && !rewardSent)
|
|
{
|
|
onMultiJobBonusRetrievedEvent.Raise();
|
|
rewardSent = true;
|
|
}
|
|
}
|
|
}
|