- 옵시디언 기준의 역할/발동 타입 분류를 스킬·젬 데이터와 장착 검증 로직에 반영 - 젬 보관 UI와 퀵슬롯 표시를 새 분류 및 실제 마나/쿨타임 계산 기준으로 갱신 - 테스트 스킬/젬 자산을 에디터 메뉴로 동기화하고 Unity 컴파일 및 플레이 검증 완료
552 lines
18 KiB
C#
552 lines
18 KiB
C#
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using Colosseum.Abnormalities;
|
|
|
|
namespace Colosseum.Skills
|
|
{
|
|
/// <summary>
|
|
/// 단일 슬롯에서 사용할 스킬과 장착된 젬 조합입니다.
|
|
/// </summary>
|
|
[System.Serializable]
|
|
public class SkillLoadoutEntry
|
|
{
|
|
private const int DefaultGemSlotCount = 2;
|
|
|
|
[Tooltip("이 슬롯의 기반 스킬")]
|
|
[SerializeField] private SkillData baseSkill;
|
|
[Tooltip("기반 스킬에 장착된 젬")]
|
|
[SerializeField] private SkillGemData[] socketedGems = new SkillGemData[DefaultGemSlotCount];
|
|
|
|
public SkillData BaseSkill => baseSkill;
|
|
public IReadOnlyList<SkillGemData> SocketedGems => socketedGems;
|
|
|
|
public static SkillLoadoutEntry CreateTemporary(SkillData skill)
|
|
{
|
|
SkillLoadoutEntry entry = new SkillLoadoutEntry();
|
|
entry.SetBaseSkill(skill);
|
|
entry.EnsureGemSlotCapacity();
|
|
return entry;
|
|
}
|
|
|
|
public SkillLoadoutEntry CreateCopy()
|
|
{
|
|
SkillLoadoutEntry copy = new SkillLoadoutEntry();
|
|
copy.baseSkill = baseSkill;
|
|
copy.socketedGems = new SkillGemData[socketedGems != null ? socketedGems.Length : DefaultGemSlotCount];
|
|
|
|
if (socketedGems != null)
|
|
{
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
copy.socketedGems[i] = socketedGems[i];
|
|
}
|
|
}
|
|
|
|
copy.SanitizeInvalidGems();
|
|
return copy;
|
|
}
|
|
|
|
public void EnsureGemSlotCapacity(int slotCount = -1)
|
|
{
|
|
if (slotCount < 0)
|
|
{
|
|
slotCount = baseSkill != null ? baseSkill.MaxGemSlotCount : DefaultGemSlotCount;
|
|
}
|
|
|
|
slotCount = Mathf.Max(0, slotCount);
|
|
if (socketedGems != null && socketedGems.Length == slotCount)
|
|
{
|
|
SanitizeInvalidGems();
|
|
return;
|
|
}
|
|
|
|
SkillGemData[] resized = new SkillGemData[slotCount];
|
|
if (socketedGems != null)
|
|
{
|
|
int copyCount = Mathf.Min(socketedGems.Length, resized.Length);
|
|
for (int i = 0; i < copyCount; i++)
|
|
{
|
|
resized[i] = socketedGems[i];
|
|
}
|
|
}
|
|
|
|
socketedGems = resized;
|
|
SanitizeInvalidGems();
|
|
}
|
|
|
|
public void SetBaseSkill(SkillData skill)
|
|
{
|
|
baseSkill = skill;
|
|
EnsureGemSlotCapacity();
|
|
SanitizeInvalidGems();
|
|
}
|
|
|
|
public void SetGem(int slotIndex, SkillGemData gem)
|
|
{
|
|
if (!TrySetGem(slotIndex, gem, out string reason) && gem != null)
|
|
{
|
|
string skillName = baseSkill != null ? baseSkill.SkillName : "(없음)";
|
|
Debug.LogWarning($"[SkillLoadout] 젬 장착 실패 | Skill={skillName} | Slot={slotIndex} | Gem={gem.GemName} | Reason={reason}");
|
|
}
|
|
}
|
|
|
|
public SkillGemData GetGem(int slotIndex)
|
|
{
|
|
EnsureGemSlotCapacity();
|
|
if (slotIndex < 0 || slotIndex >= socketedGems.Length)
|
|
return null;
|
|
|
|
return socketedGems[slotIndex];
|
|
}
|
|
|
|
/// <summary>
|
|
/// 지정한 슬롯에 젬을 장착 시도하고, 실패 이유를 반환합니다.
|
|
/// </summary>
|
|
public bool TrySetGem(int slotIndex, SkillGemData gem, out string reason)
|
|
{
|
|
reason = string.Empty;
|
|
EnsureGemSlotCapacity();
|
|
|
|
if (slotIndex < 0 || slotIndex >= socketedGems.Length)
|
|
{
|
|
reason = "유효하지 않은 젬 슬롯입니다.";
|
|
return false;
|
|
}
|
|
|
|
if (gem == null)
|
|
{
|
|
socketedGems[slotIndex] = null;
|
|
return true;
|
|
}
|
|
|
|
if (!TryValidateGemForSlot(slotIndex, gem, null, out reason))
|
|
return false;
|
|
|
|
socketedGems[slotIndex] = gem;
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 현재 로드아웃의 잘못된 젬 조합을 제거합니다.
|
|
/// </summary>
|
|
public void SanitizeInvalidGems(bool logWarnings = false)
|
|
{
|
|
if (socketedGems == null || socketedGems.Length == 0)
|
|
return;
|
|
|
|
List<SkillGemData> acceptedGems = new List<SkillGemData>(socketedGems.Length);
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
SkillGemData gem = socketedGems[i];
|
|
if (gem == null)
|
|
continue;
|
|
|
|
if (TryValidateGemForSlot(i, gem, acceptedGems, out string reason))
|
|
{
|
|
acceptedGems.Add(gem);
|
|
continue;
|
|
}
|
|
|
|
if (logWarnings)
|
|
{
|
|
string skillName = baseSkill != null ? baseSkill.SkillName : "(없음)";
|
|
Debug.LogWarning($"[SkillLoadout] 젬 장착 제약으로 제거됨 | Skill={skillName} | Slot={i} | Gem={gem.GemName} | Reason={reason}");
|
|
}
|
|
|
|
socketedGems[i] = null;
|
|
}
|
|
}
|
|
|
|
public float GetResolvedManaCost()
|
|
{
|
|
if (baseSkill == null)
|
|
return 0f;
|
|
|
|
float resolved = baseSkill.ManaCost;
|
|
if (socketedGems == null)
|
|
return resolved;
|
|
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
SkillGemData gem = socketedGems[i];
|
|
if (gem == null)
|
|
continue;
|
|
|
|
resolved *= gem.ManaCostMultiplier;
|
|
}
|
|
|
|
return resolved;
|
|
}
|
|
|
|
public float GetResolvedCooldown()
|
|
{
|
|
if (baseSkill == null)
|
|
return 0f;
|
|
|
|
float resolved = baseSkill.Cooldown;
|
|
if (socketedGems == null)
|
|
return resolved;
|
|
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
SkillGemData gem = socketedGems[i];
|
|
if (gem == null)
|
|
continue;
|
|
|
|
resolved *= gem.CooldownMultiplier;
|
|
}
|
|
|
|
return resolved;
|
|
}
|
|
|
|
public float GetResolvedAnimationSpeed()
|
|
{
|
|
if (baseSkill == null)
|
|
return 0f;
|
|
|
|
float resolved = baseSkill.AnimationSpeed;
|
|
if (socketedGems == null)
|
|
return resolved;
|
|
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
SkillGemData gem = socketedGems[i];
|
|
if (gem == null)
|
|
continue;
|
|
|
|
resolved *= gem.CastSpeedMultiplier;
|
|
}
|
|
|
|
return Mathf.Max(0.05f, resolved);
|
|
}
|
|
|
|
public float GetResolvedDamageMultiplier()
|
|
{
|
|
return GetResolvedScalarMultiplier(gem => gem.DamageMultiplier);
|
|
}
|
|
|
|
public float GetResolvedHealMultiplier()
|
|
{
|
|
return GetResolvedScalarMultiplier(gem => gem.HealMultiplier);
|
|
}
|
|
|
|
public float GetResolvedShieldMultiplier()
|
|
{
|
|
return GetResolvedScalarMultiplier(gem => gem.ShieldMultiplier);
|
|
}
|
|
|
|
public float GetResolvedThreatMultiplier()
|
|
{
|
|
return GetResolvedScalarMultiplier(gem => gem.ThreatMultiplier);
|
|
}
|
|
|
|
public int GetResolvedRepeatCount()
|
|
{
|
|
if (baseSkill == null)
|
|
return 0;
|
|
|
|
int resolved = 1;
|
|
if (socketedGems == null)
|
|
return resolved;
|
|
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
SkillGemData gem = socketedGems[i];
|
|
if (gem == null)
|
|
continue;
|
|
|
|
resolved += gem.AdditionalRepeatCount;
|
|
}
|
|
|
|
return Mathf.Max(1, resolved);
|
|
}
|
|
|
|
public void CollectCastStartEffects(List<SkillEffect> destination)
|
|
{
|
|
if (destination == null)
|
|
return;
|
|
|
|
if (baseSkill != null && baseSkill.CastStartEffects != null)
|
|
{
|
|
for (int i = 0; i < baseSkill.CastStartEffects.Count; i++)
|
|
{
|
|
SkillEffect effect = baseSkill.CastStartEffects[i];
|
|
if (effect != null)
|
|
destination.Add(effect);
|
|
}
|
|
}
|
|
|
|
if (socketedGems == null)
|
|
return;
|
|
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
SkillGemData gem = socketedGems[i];
|
|
if (gem == null || gem.CastStartEffects == null)
|
|
continue;
|
|
|
|
for (int j = 0; j < gem.CastStartEffects.Count; j++)
|
|
{
|
|
SkillEffect effect = gem.CastStartEffects[j];
|
|
if (effect != null)
|
|
destination.Add(effect);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CollectCastStartAbnormalities(List<AbnormalityData> destination)
|
|
{
|
|
if (destination == null || socketedGems == null)
|
|
return;
|
|
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
SkillGemData gem = socketedGems[i];
|
|
if (gem == null || gem.SelfAbnormalities == null)
|
|
continue;
|
|
|
|
for (int j = 0; j < gem.SelfAbnormalities.Count; j++)
|
|
{
|
|
AbnormalityData abnormality = gem.SelfAbnormalities[j];
|
|
if (abnormality != null)
|
|
destination.Add(abnormality);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CollectTriggeredEffects(Dictionary<int, List<SkillEffect>> destination)
|
|
{
|
|
if (destination == null)
|
|
return;
|
|
|
|
if (baseSkill != null && baseSkill.Effects != null)
|
|
{
|
|
for (int i = 0; i < baseSkill.Effects.Count; i++)
|
|
{
|
|
SkillEffect effect = baseSkill.Effects[i];
|
|
if (effect == null)
|
|
continue;
|
|
|
|
AddTriggeredEffect(destination, i, effect);
|
|
}
|
|
}
|
|
|
|
if (socketedGems == null)
|
|
return;
|
|
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
SkillGemData gem = socketedGems[i];
|
|
if (gem == null || gem.TriggeredEffects == null)
|
|
continue;
|
|
|
|
for (int j = 0; j < gem.TriggeredEffects.Count; j++)
|
|
{
|
|
SkillGemTriggeredEffectEntry entry = gem.TriggeredEffects[j];
|
|
if (entry == null || entry.Effects == null)
|
|
continue;
|
|
|
|
for (int k = 0; k < entry.Effects.Count; k++)
|
|
{
|
|
SkillEffect effect = entry.Effects[k];
|
|
if (effect == null)
|
|
continue;
|
|
|
|
AddTriggeredEffect(destination, entry.TriggerIndex, effect);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CollectTriggeredAbnormalities(Dictionary<int, List<AbnormalityData>> destination)
|
|
{
|
|
if (destination == null || socketedGems == null)
|
|
return;
|
|
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
SkillGemData gem = socketedGems[i];
|
|
if (gem == null || gem.OnHitAbnormalities == null)
|
|
continue;
|
|
|
|
for (int j = 0; j < gem.OnHitAbnormalities.Count; j++)
|
|
{
|
|
SkillGemTriggeredAbnormalityEntry entry = gem.OnHitAbnormalities[j];
|
|
if (entry == null || entry.Abnormalities == null)
|
|
continue;
|
|
|
|
for (int k = 0; k < entry.Abnormalities.Count; k++)
|
|
{
|
|
AbnormalityData abnormality = entry.Abnormalities[k];
|
|
if (abnormality == null)
|
|
continue;
|
|
|
|
AddTriggeredAbnormality(destination, entry.TriggerIndex, abnormality);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void AddTriggeredEffect(Dictionary<int, List<SkillEffect>> destination, int triggerIndex, SkillEffect effect)
|
|
{
|
|
if (!destination.TryGetValue(triggerIndex, out List<SkillEffect> effectList))
|
|
{
|
|
effectList = new List<SkillEffect>();
|
|
destination.Add(triggerIndex, effectList);
|
|
}
|
|
|
|
effectList.Add(effect);
|
|
}
|
|
|
|
private static void AddTriggeredAbnormality(Dictionary<int, List<AbnormalityData>> destination, int triggerIndex, AbnormalityData abnormality)
|
|
{
|
|
if (!destination.TryGetValue(triggerIndex, out List<AbnormalityData> abnormalityList))
|
|
{
|
|
abnormalityList = new List<AbnormalityData>();
|
|
destination.Add(triggerIndex, abnormalityList);
|
|
}
|
|
|
|
abnormalityList.Add(abnormality);
|
|
}
|
|
|
|
private bool TryValidateGemForSlot(int slotIndex, SkillGemData gem, IReadOnlyList<SkillGemData> acceptedGems, out string reason)
|
|
{
|
|
reason = string.Empty;
|
|
if (gem == null)
|
|
return true;
|
|
|
|
if (baseSkill == null)
|
|
{
|
|
reason = "기반 스킬이 없는 슬롯에는 젬을 장착할 수 없습니다.";
|
|
return false;
|
|
}
|
|
|
|
if (!gem.CanAttachToSkill(baseSkill))
|
|
{
|
|
string skillClassification = SkillClassificationUtility.GetSkillClassificationLabel(baseSkill);
|
|
string allowedClassification =
|
|
$"{SkillClassificationUtility.GetAllowedRoleSummary(gem.AllowedSkillRoles)}/" +
|
|
$"{SkillClassificationUtility.GetAllowedActivationSummary(gem.AllowedSkillActivationTypes)}";
|
|
reason = $"장착 가능한 스킬 조합이 아닙니다. Skill={skillClassification}, Allowed={allowedClassification}";
|
|
return false;
|
|
}
|
|
|
|
if (acceptedGems != null)
|
|
{
|
|
for (int i = 0; i < acceptedGems.Count; i++)
|
|
{
|
|
if (!TryValidateGemPair(gem, acceptedGems[i], out reason))
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
if (i == slotIndex)
|
|
continue;
|
|
|
|
SkillGemData otherGem = socketedGems[i];
|
|
if (otherGem == null)
|
|
continue;
|
|
|
|
if (!TryValidateGemPair(gem, otherGem, out reason))
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private static bool TryValidateGemPair(SkillGemData gem, SkillGemData otherGem, out string reason)
|
|
{
|
|
reason = string.Empty;
|
|
if (gem == null || otherGem == null)
|
|
return true;
|
|
|
|
if (gem == otherGem)
|
|
{
|
|
reason = "동일한 젬은 하나의 스킬에 여러 개 장착할 수 없습니다.";
|
|
return false;
|
|
}
|
|
|
|
if (gem.IsGemIncompatible(otherGem) || otherGem.IsGemIncompatible(gem))
|
|
{
|
|
reason = $"{gem.GemName}과 {otherGem.GemName}은 함께 장착할 수 없습니다.";
|
|
return false;
|
|
}
|
|
|
|
if (gem.IsCategoryIncompatible(otherGem.Category) || otherGem.IsCategoryIncompatible(gem.Category))
|
|
{
|
|
reason =
|
|
$"{SkillClassificationUtility.GetGemCategoryLabel(gem.Category)} / " +
|
|
$"{SkillClassificationUtility.GetGemCategoryLabel(otherGem.Category)} 효과 분류 조합은 허용되지 않습니다.";
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private float GetResolvedScalarMultiplier(System.Func<SkillGemData, float> selector)
|
|
{
|
|
if (baseSkill == null)
|
|
return 1f;
|
|
|
|
float resolved = 1f;
|
|
if (socketedGems == null)
|
|
return resolved;
|
|
|
|
for (int i = 0; i < socketedGems.Length; i++)
|
|
{
|
|
SkillGemData gem = socketedGems[i];
|
|
if (gem == null)
|
|
continue;
|
|
|
|
resolved *= Mathf.Max(0f, selector(gem));
|
|
}
|
|
|
|
return resolved;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 현재 시전 중인 스킬 로드아웃의 젬 보정값을 안전하게 조회하는 유틸리티입니다.
|
|
/// </summary>
|
|
public static class SkillRuntimeModifierUtility
|
|
{
|
|
public static float GetDamageMultiplier(GameObject caster)
|
|
{
|
|
return GetCurrentLoadout(caster)?.GetResolvedDamageMultiplier() ?? 1f;
|
|
}
|
|
|
|
public static float GetHealMultiplier(GameObject caster)
|
|
{
|
|
return GetCurrentLoadout(caster)?.GetResolvedHealMultiplier() ?? 1f;
|
|
}
|
|
|
|
public static float GetShieldMultiplier(GameObject caster)
|
|
{
|
|
return GetCurrentLoadout(caster)?.GetResolvedShieldMultiplier() ?? 1f;
|
|
}
|
|
|
|
public static float GetThreatMultiplier(GameObject caster)
|
|
{
|
|
return GetCurrentLoadout(caster)?.GetResolvedThreatMultiplier() ?? 1f;
|
|
}
|
|
|
|
private static SkillLoadoutEntry GetCurrentLoadout(GameObject caster)
|
|
{
|
|
if (caster == null)
|
|
return null;
|
|
|
|
SkillController skillController = caster.GetComponent<SkillController>();
|
|
if (skillController == null)
|
|
return null;
|
|
|
|
return skillController.CurrentLoadoutEntry;
|
|
}
|
|
}
|
|
}
|