Files
bansonic_beta_main/Assets/_eqpmtSys/equipmentRandomConfigSO.cs
T
2026-03-27 08:02:55 +08:00

543 lines
16 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "NewEquipmentRandomConfig", menuName = "Equipment/Equipment Random Config")]
public class equipmentRandomConfigSO : ScriptableObject
{
public enum RandomBasicAttributeType
{
MaxHp,
Attack,
MaxMana,
DamageResistance,
ScoreEfficiency
}
public enum RandomSpecialEffectType
{
MaxHp,
Attack,
MaxMana,
DamageResistance,
ScoreEfficiency
}
public enum RandomIllusionEffectType
{
MaxHp,
Attack,
MaxMana,
DamageResistance,
ScoreEfficiency,
HitManaRecovery,
HitDamageMultiplier,
HpLoseBase
}
[Serializable]
public class SpecialEffectRandomRange
{
public RandomSpecialEffectType effectType;
public float minValue;
public float maxValue;
public void Normalize()
{
if (maxValue < minValue)
{
float cached = minValue;
minValue = maxValue;
maxValue = cached;
}
}
}
[Serializable]
public class BasicAttributeRandomRange
{
public RandomBasicAttributeType attributeType;
public float minValue;
public float maxValue;
public void Normalize()
{
if (maxValue < minValue)
{
float cached = minValue;
minValue = maxValue;
maxValue = cached;
}
}
}
[Serializable]
public class IllusionEffectRandomRange
{
public RandomIllusionEffectType effectType;
public float minValue;
public float maxValue;
public void Normalize()
{
if (maxValue < minValue)
{
float cached = minValue;
minValue = maxValue;
maxValue = cached;
}
}
}
[Serializable]
public class SpecialSkillPoolEntry
{
public equipmentSO.EquipmentSkillType skillType;
public List<int> skillIds = new List<int>();
public void Normalize()
{
if (skillIds == null)
{
skillIds = new List<int>();
}
for (int i = 0; i < skillIds.Count; i++)
{
skillIds[i] = Mathf.Max(0, skillIds[i]);
}
}
}
[Header("Random Base Attributes")]
[Min(0)] public int randomBasicAttributeCount = 0;
public List<BasicAttributeRandomRange> basicAttributeRanges = new List<BasicAttributeRandomRange>();
[Header("Special Effect Rules")]
public bool onlyProduceSameTypeAttributes = false;
[Header("Special Effect Count Probabilities")]
[Range(0f, 1f)] public float se01p = 0.6f;
[Range(0f, 1f)] public float se02p = 0.35f;
[Range(0f, 1f)] public float se03p = 0.05f;
[Range(0f, 1f)] public float sesp = 0.03f;
[Header("Illusion Effect Skill Probabilities")]
[Range(0f, 1f)] public float ies01 = 0.2f;
[Range(0f, 1f)] public float ies02 = 0.35f;
[Range(0f, 1f)] public float ies03 = 0.5f;
[Range(0f, 1f)] public float ies04 = 0.65f;
[Header("Special Effect Random Ranges")]
public List<SpecialEffectRandomRange> specialEffectRanges = new List<SpecialEffectRandomRange>();
[Header("Type Same Effect Random Ranges")]
public List<SpecialEffectRandomRange> typeSameEffectRanges = new List<SpecialEffectRandomRange>();
[Header("Illusion Effect Random Ranges")]
public List<IllusionEffectRandomRange> illusionEffectRanges = new List<IllusionEffectRandomRange>();
[Header("Special Skill Pool")]
public List<SpecialSkillPoolEntry> specialSkillPool = new List<SpecialSkillPoolEntry>();
[Header("Illusion Skill Pool")]
public List<int> illusionSkillPool = new List<int>();
private void OnValidate()
{
NormalizeRuntimeData();
}
public void NormalizeRuntimeData()
{
randomBasicAttributeCount = Mathf.Max(0, randomBasicAttributeCount);
se01p = Mathf.Clamp01(se01p);
se02p = Mathf.Clamp01(se02p);
se03p = Mathf.Clamp01(se03p);
sesp = Mathf.Clamp01(sesp);
ies01 = Mathf.Clamp01(ies01);
ies02 = Mathf.Clamp01(ies02);
ies03 = Mathf.Clamp01(ies03);
ies04 = Mathf.Clamp01(ies04);
EnsureBasicAttributeRanges();
EnsureSpecialEffectRanges();
EnsureTypeSameEffectRanges();
EnsureIllusionEffectRanges();
EnsureSpecialSkillPool();
NormalizeIllusionSkillPool();
}
public bool TryGetSpecialRange(RandomSpecialEffectType effectType, out float minValue, out float maxValue)
{
SpecialEffectRandomRange range = FindSpecialRange(effectType);
if (range != null)
{
minValue = range.minValue;
maxValue = range.maxValue;
return true;
}
minValue = 0f;
maxValue = 0f;
return false;
}
public bool TryGetTypeSameEffectRange(RandomSpecialEffectType effectType, out float minValue, out float maxValue)
{
SpecialEffectRandomRange range = FindTypeSameEffectRange(effectType);
if (range != null)
{
minValue = range.minValue;
maxValue = range.maxValue;
return true;
}
minValue = 0f;
maxValue = 0f;
return false;
}
public bool TryGetBasicRange(RandomBasicAttributeType attributeType, out float minValue, out float maxValue)
{
BasicAttributeRandomRange range = FindBasicRange(attributeType);
if (range != null)
{
minValue = range.minValue;
maxValue = range.maxValue;
return true;
}
minValue = 0f;
maxValue = 0f;
return false;
}
public bool TryGetIllusionRange(RandomIllusionEffectType effectType, out float minValue, out float maxValue)
{
IllusionEffectRandomRange range = FindIllusionRange(effectType);
if (range != null)
{
minValue = range.minValue;
maxValue = range.maxValue;
return true;
}
minValue = 0f;
maxValue = 0f;
return false;
}
public bool TryGetIllusionEffectRange(RandomIllusionEffectType effectType, out float minValue, out float maxValue)
{
return TryGetIllusionRange(effectType, out minValue, out maxValue);
}
public bool TryGetIllusionEffectRange(equipmentSO.EquipmentSpecialEffectType effectType, out float minValue, out float maxValue)
{
if (TryMapToIllusionEffectType(effectType, out RandomIllusionEffectType mappedType))
{
return TryGetIllusionRange(mappedType, out minValue, out maxValue);
}
minValue = 0f;
maxValue = 0f;
return false;
}
public bool TryGetSpecialSkillId(equipmentSO.EquipmentSkillType skillType, out int skillId)
{
NormalizeRuntimeData();
for (int i = 0; i < specialSkillPool.Count; i++)
{
SpecialSkillPoolEntry entry = specialSkillPool[i];
if (entry != null && entry.skillType == skillType && entry.skillIds != null && entry.skillIds.Count > 0)
{
skillId = entry.skillIds[UnityEngine.Random.Range(0, entry.skillIds.Count)];
return true;
}
}
skillId = 0;
return false;
}
public bool TryGetIllusionSkillId(out int skillId)
{
NormalizeRuntimeData();
if (illusionSkillPool == null || illusionSkillPool.Count == 0)
{
skillId = 0;
return false;
}
var validIds = new List<int>();
for (int i = 0; i < illusionSkillPool.Count; i++)
{
if (illusionSkillPool[i] > 0)
{
validIds.Add(illusionSkillPool[i]);
}
}
if (validIds.Count == 0)
{
skillId = 0;
return false;
}
skillId = validIds[UnityEngine.Random.Range(0, validIds.Count)];
return true;
}
private static bool TryMapToIllusionEffectType(equipmentSO.EquipmentSpecialEffectType effectType, out RandomIllusionEffectType mappedType)
{
switch (effectType)
{
case equipmentSO.EquipmentSpecialEffectType.MaxHp:
mappedType = RandomIllusionEffectType.MaxHp;
return true;
case equipmentSO.EquipmentSpecialEffectType.Attack:
mappedType = RandomIllusionEffectType.Attack;
return true;
case equipmentSO.EquipmentSpecialEffectType.MaxMana:
mappedType = RandomIllusionEffectType.MaxMana;
return true;
case equipmentSO.EquipmentSpecialEffectType.DamageResistance:
mappedType = RandomIllusionEffectType.DamageResistance;
return true;
case equipmentSO.EquipmentSpecialEffectType.ScoreEfficiency:
mappedType = RandomIllusionEffectType.ScoreEfficiency;
return true;
case equipmentSO.EquipmentSpecialEffectType.HitManaRecovery:
mappedType = RandomIllusionEffectType.HitManaRecovery;
return true;
case equipmentSO.EquipmentSpecialEffectType.HitDamageMultiplier:
mappedType = RandomIllusionEffectType.HitDamageMultiplier;
return true;
case equipmentSO.EquipmentSpecialEffectType.HpLoseBase:
mappedType = RandomIllusionEffectType.HpLoseBase;
return true;
default:
mappedType = default;
return false;
}
}
private void EnsureBasicAttributeRanges()
{
if (basicAttributeRanges == null)
{
basicAttributeRanges = new List<BasicAttributeRandomRange>();
}
var normalized = new List<BasicAttributeRandomRange>();
Array attributeTypes = Enum.GetValues(typeof(RandomBasicAttributeType));
for (int i = 0; i < attributeTypes.Length; i++)
{
RandomBasicAttributeType attributeType = (RandomBasicAttributeType)attributeTypes.GetValue(i);
BasicAttributeRandomRange existing = FindBasicRange(attributeType);
if (existing == null)
{
existing = new BasicAttributeRandomRange { attributeType = attributeType };
}
existing.attributeType = attributeType;
existing.Normalize();
normalized.Add(existing);
}
basicAttributeRanges = normalized;
}
private void EnsureSpecialEffectRanges()
{
if (specialEffectRanges == null)
{
specialEffectRanges = new List<SpecialEffectRandomRange>();
}
var normalized = new List<SpecialEffectRandomRange>();
Array effectTypes = Enum.GetValues(typeof(RandomSpecialEffectType));
for (int i = 0; i < effectTypes.Length; i++)
{
RandomSpecialEffectType effectType = (RandomSpecialEffectType)effectTypes.GetValue(i);
SpecialEffectRandomRange existing = FindSpecialRange(effectType);
if (existing == null)
{
existing = new SpecialEffectRandomRange { effectType = effectType };
}
existing.effectType = effectType;
existing.Normalize();
normalized.Add(existing);
}
specialEffectRanges = normalized;
}
private void EnsureTypeSameEffectRanges()
{
if (typeSameEffectRanges == null)
{
typeSameEffectRanges = new List<SpecialEffectRandomRange>();
}
var normalized = new List<SpecialEffectRandomRange>();
Array effectTypes = Enum.GetValues(typeof(RandomSpecialEffectType));
for (int i = 0; i < effectTypes.Length; i++)
{
RandomSpecialEffectType effectType = (RandomSpecialEffectType)effectTypes.GetValue(i);
SpecialEffectRandomRange existing = FindTypeSameEffectRange(effectType);
if (existing == null)
{
existing = new SpecialEffectRandomRange { effectType = effectType };
}
existing.effectType = effectType;
existing.Normalize();
normalized.Add(existing);
}
typeSameEffectRanges = normalized;
}
private void EnsureIllusionEffectRanges()
{
if (illusionEffectRanges == null)
{
illusionEffectRanges = new List<IllusionEffectRandomRange>();
}
var normalized = new List<IllusionEffectRandomRange>();
Array effectTypes = Enum.GetValues(typeof(RandomIllusionEffectType));
for (int i = 0; i < effectTypes.Length; i++)
{
RandomIllusionEffectType effectType = (RandomIllusionEffectType)effectTypes.GetValue(i);
IllusionEffectRandomRange existing = FindIllusionRange(effectType);
if (existing == null)
{
existing = new IllusionEffectRandomRange { effectType = effectType };
}
existing.effectType = effectType;
existing.Normalize();
normalized.Add(existing);
}
illusionEffectRanges = normalized;
}
private void EnsureSpecialSkillPool()
{
if (specialSkillPool == null)
{
specialSkillPool = new List<SpecialSkillPoolEntry>();
}
var normalized = new List<SpecialSkillPoolEntry>();
Array skillTypes = Enum.GetValues(typeof(equipmentSO.EquipmentSkillType));
for (int i = 0; i < skillTypes.Length; i++)
{
equipmentSO.EquipmentSkillType skillType = (equipmentSO.EquipmentSkillType)skillTypes.GetValue(i);
SpecialSkillPoolEntry existing = FindSpecialSkillPoolEntry(skillType);
if (existing == null)
{
existing = new SpecialSkillPoolEntry { skillType = skillType };
}
existing.skillType = skillType;
existing.Normalize();
normalized.Add(existing);
}
specialSkillPool = normalized;
}
private void NormalizeIllusionSkillPool()
{
if (illusionSkillPool == null)
{
illusionSkillPool = new List<int>();
return;
}
for (int i = 0; i < illusionSkillPool.Count; i++)
{
illusionSkillPool[i] = Mathf.Max(0, illusionSkillPool[i]);
}
}
private SpecialEffectRandomRange FindSpecialRange(RandomSpecialEffectType effectType)
{
for (int i = 0; i < specialEffectRanges.Count; i++)
{
SpecialEffectRandomRange range = specialEffectRanges[i];
if (range != null && range.effectType == effectType)
{
return range;
}
}
return null;
}
private BasicAttributeRandomRange FindBasicRange(RandomBasicAttributeType attributeType)
{
for (int i = 0; i < basicAttributeRanges.Count; i++)
{
BasicAttributeRandomRange range = basicAttributeRanges[i];
if (range != null && range.attributeType == attributeType)
{
return range;
}
}
return null;
}
private SpecialEffectRandomRange FindTypeSameEffectRange(RandomSpecialEffectType effectType)
{
for (int i = 0; i < typeSameEffectRanges.Count; i++)
{
SpecialEffectRandomRange range = typeSameEffectRanges[i];
if (range != null && range.effectType == effectType)
{
return range;
}
}
return null;
}
private IllusionEffectRandomRange FindIllusionRange(RandomIllusionEffectType effectType)
{
for (int i = 0; i < illusionEffectRanges.Count; i++)
{
IllusionEffectRandomRange range = illusionEffectRanges[i];
if (range != null && range.effectType == effectType)
{
return range;
}
}
return null;
}
private SpecialSkillPoolEntry FindSpecialSkillPoolEntry(equipmentSO.EquipmentSkillType skillType)
{
for (int i = 0; i < specialSkillPool.Count; i++)
{
SpecialSkillPoolEntry entry = specialSkillPool[i];
if (entry != null && entry.skillType == skillType)
{
return entry;
}
}
return null;
}
}