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 guaranteedItemDrop = new List(); [Header("Only one of the following list is guaranteed to drop.")] public List guaranteedOnlyOnePerKill = new List(); public List extraDrops = new List(); public List nonEquippablesDrops = new List(); [Space] [SerializeField] private List weightedDropLootTable = new List(); PhotonView photonView; GameObject instantiatedDrop; GameObject instantiatedEquippableDrop; EquippableItemDrop equippableItemDrop; EquippableItemDrop itemDrop; Item possibleItem; GameObject instantiatedCoinDrop; CoinDrop coinDrop; int finalCoinAmount; Vector3 spawnPosition; private void Awake() { photonView = GetComponentInParent(); } // 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(); 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(); 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(); itemDrop.itemDrop = Item.ConvertTemplateIntoInstance(possibleItem); } else { if(Random.Range(0,100) > 49) { spawnPosition = this.transform.position - Vector3.one * 0.3f; spawnPosition.y = 0f; instantiatedDrop = Instantiate(interactableDropAbilityTomePagePrefab, spawnPosition, this.transform.rotation); itemDrop = instantiatedDrop.GetComponent(); itemDrop.itemDrop = BuildLibrary.Instance.GetRandomLockedAbilityTomePageInstance(); } } 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(); itemDrop.itemDrop = Item.ConvertTemplateIntoInstance(possibleItem); } }