Pedro Gomes 9461120386 Rogue-lite progression continued (WIP)
- ability unlocks (90% done)
- class unlocks (working)
- new human base class
- bugfix small issues
2025-01-19 23:18:07 +00:00

129 lines
5.0 KiB
C#

using Kryz.CharacterStats.Examples;
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DropTable : MonoBehaviour
{
[SerializeField] private GameObject interactableDropPrefab;
[SerializeField] private GameObject interactableDropAbilityTomePagePrefab;
[SerializeField] private GameObject coinPrefab;
[SerializeField] private int coinAmount;
[SerializeField] private int extraDropChance;
[SerializeField] private GameEvent_Int onCoinDrop;
public List<EquippableItem> guaranteedItemDrop = new List<EquippableItem>();
[Header("Only one of the following list is guaranteed to drop.")]
public List<WeightedDrop> guaranteedOnlyOnePerKill = new List<WeightedDrop>();
public List<EquippableItem> extraDrops = new List<EquippableItem>();
public List<Item> nonEquippablesDrops = new List<Item>();
[Space]
[SerializeField] private List<WeightedDrop> weightedDropLootTable = new List<WeightedDrop>();
PhotonView photonView;
GameObject instantiatedDrop;
GameObject instantiatedEquippableDrop;
EquippableItemDrop equippableItemDrop;
EquippableItemDrop itemDrop;
Item possibleItem;
GameObject instantiatedCoinDrop;
CoinDrop coinDrop;
int finalCoinAmount;
Vector3 spawnPosition;
ItemInstance possibleTome;
private void Awake()
{
photonView = GetComponentInParent<PhotonView>();
}
// Start is called before the first frame update
void Start()
{
}
public bool CalculateLootDrop()
{
return Random.Range(0, 100) < (extraDropChance * (1 + GameConstants.GameBalancing.IncreasedItemDropBasedOnDifficultyMultiplier * GameDifficultyController.Instance.GetCurrentDifficultyLevel()));
}
public void DropLoot(bool lootDrop)
{
spawnPosition = this.transform.position;
spawnPosition.y = 0f;
instantiatedCoinDrop = Instantiate(coinPrefab, spawnPosition, this.transform.rotation);
coinDrop = instantiatedCoinDrop.GetComponent<CoinDrop>();
finalCoinAmount = Mathf.RoundToInt(coinAmount * (1 + GameConstants.GameBalancing.IncreasedCoinDropBasedOnDifficultyMultiplier * GameDifficultyController.Instance.GetCurrentDifficultyLevel()));
coinDrop.Init(finalCoinAmount);
onCoinDrop.Raise(finalCoinAmount);
for (int i = 0; i < guaranteedItemDrop.Count; i++)
{
instantiatedDrop = Instantiate(interactableDropPrefab, spawnPosition, this.transform.rotation);
itemDrop = instantiatedDrop.GetComponent<EquippableItemDrop>();
itemDrop.itemDrop = Item.ConvertTemplateIntoInstance(guaranteedItemDrop[i]);
}
if (guaranteedOnlyOnePerKill.Count > 0 && WeightedDrop.HaveDropsForDifficulty(weightedDropLootTable, GameDifficultyController.Instance.GetCurrentDifficultyLevel()))
{
possibleItem = WeightedDrop.GetRandomDrop(guaranteedOnlyOnePerKill, GameDifficultyController.Instance.GetCurrentDifficultyLevel());
spawnPosition = guaranteedItemDrop.Count > 0 ? this.transform.position + Vector3.one * 0.3f : this.transform.position;
spawnPosition.y = 0f;
instantiatedDrop = Instantiate(interactableDropPrefab, spawnPosition, this.transform.rotation);
itemDrop = instantiatedDrop.GetComponent<EquippableItemDrop>();
itemDrop.itemDrop = Item.ConvertTemplateIntoInstance(possibleItem);
}
else
{
if(Random.Range(0,100) > 49)
{
possibleTome = BuildLibrary.Instance.GetRandomLockedAbilityTomePageInstanceFromSpecificClass();
if(possibleTome != null)
{
spawnPosition = this.transform.position - Vector3.one * 0.3f;
spawnPosition.y = 0f;
instantiatedDrop = Instantiate(interactableDropAbilityTomePagePrefab, spawnPosition, this.transform.rotation);
itemDrop = instantiatedDrop.GetComponent<EquippableItemDrop>();
itemDrop.itemDrop = possibleTome;
}
}
}
if (!lootDrop) return;
if (weightedDropLootTable.Count <= 0) return;
if (!WeightedDrop.HaveDropsForDifficulty(weightedDropLootTable, GameDifficultyController.Instance.GetCurrentDifficultyLevel())) return;
possibleItem = WeightedDrop.GetRandomDrop(weightedDropLootTable, GameDifficultyController.Instance.GetCurrentDifficultyLevel());
if (possibleItem == null) return;
spawnPosition = this.transform.position;
if (guaranteedItemDrop.Count > 0)
{
spawnPosition += Vector3.one * 0.15f;
}
if(guaranteedOnlyOnePerKill.Count > 0)
{
spawnPosition += Vector3.one * 0.15f;
}
spawnPosition.y = 0f;
instantiatedDrop = Instantiate(interactableDropPrefab, spawnPosition, this.transform.rotation);
itemDrop = instantiatedDrop.GetComponent<EquippableItemDrop>();
itemDrop.itemDrop = Item.ConvertTemplateIntoInstance(possibleItem);
}
}