// ─────────────────────────────────────────────────────────────────────────────
// WLEquipStats.cs — FR 장비 능력치를 힘민지 ActorStatInfo 에 더한다 (#821)
//
// 훅 = `MyValue.cs` ActorStatInfo.Reset() 의 `Set_EquipItem();` 다음 1줄(`WL.Equip.WLEquipStats.Apply(this, m_Role);`).
// 능력치 본체(힘·민첩·지능·운·ATK·HP…)는 힘민지 그대로이고, 여기서는 **장착 중인 FR 장비**의
// ① 레벨표 수치(AttackAbility/DefenceAbility/HealthAbility → ATK/DEF/HP)
// ② 등급별 개방 옵션(FR eAbility % → WLEquipSettings.abilityMap 의 eStat)
// 만 Set_Stat(true, …) 로 더한다. 설정이 없거나 꺼져 있으면 아무것도 하지 않는다.
// 🔴 장비 능력치 체계(어떤 스탯을 줄지)는 PD 와 후속 논의 예정 — 대응표는 전부 SO 라 코드 수정 없이 바꾼다.
// ─────────────────────────────────────────────────────────────────────────────
using System.Collections.Generic;
using UnityEngine;
namespace WL.Equip
{
public static class WLEquipStats
{
public static string LastReport { get; private set; } = "";
public static int LastAppliedItems { get; private set; }
/// 마지막 Apply 에서 장착 장비 레벨표로 더한 공격력 합(기본 공격력 덮어쓰기의 가산분).
public static double LastEquipAttack { get; private set; }
public static int BaseAttackEnforced;
public static string LastEnforceLog { get; private set; } = "";
static readonly List s_tmp = new List(8);
static readonly HashSet s_mapped = new HashSet();
static bool s_mappedBuilt;
public static bool IsMapped(eFRAbility a)
{
if (!s_mappedBuilt)
{
s_mappedBuilt = true;
var cfg = WLEquipSettings.Instance;
if (cfg != null && cfg.abilityMap != null)
for (int i = 0; i < cfg.abilityMap.Count; i++) s_mapped.Add(cfg.abilityMap[i].ability);
}
return s_mapped.Contains(a);
}
/// ActorStatInfo.Reset() 안에서 부른다(PC 만).
public static void Apply(ActorStatInfo info, eRole role)
{
if (info == null || role != eRole.PC) return;
var cfg = WLEquipSettings.Instance;
if (cfg == null || cfg.enabled_ == 0) return;
if (!WLInventory.EnsureLoaded()) return;
var data = WLInventory.Data;
LastEquipAttack = 0;
if (data == null || data.equipItems.Count == 0) { LastReport = "장착 0"; LastAppliedItems = 0; return; }
var sb = new System.Text.StringBuilder();
int applied = 0;
double equipAtk = 0;
for (int i = 0; i < data.equipItems.Count; i++)
{
var item = WLInventory.FindItem(data.equipItems[i]);
if (item == null || !item.itemJson.IsEquipment) continue;
applied++;
sb.Append(item.itemJson.Item_name).Append('(').Append(WLEquipTables.GradeName(item.itemJson.ItemGrade)).Append(" Lv").Append(item.rawItem.level).Append("): ");
var lt = WLEquipTables.FindItemLevelJson(item.itemJson.ItemLvAbilityID);
var lv = lt != null ? lt.FindLevelInfo(item.rawItem.level) : null;
if (lv != null)
{
if (lv.AttackAbility != 0) { info.Set_Stat(true, cfg.levelAttackStat, lv.AttackAbility * cfg.levelStatScale); sb.Append(cfg.levelAttackStat).Append('+').Append(lv.AttackAbility).Append(' '); if (cfg.levelAttackStat == eStat.ATK) equipAtk += lv.AttackAbility * cfg.levelStatScale; }
if (lv.DefenceAbility != 0) { info.Set_Stat(true, cfg.levelDefenceStat, lv.DefenceAbility * cfg.levelStatScale); sb.Append(cfg.levelDefenceStat).Append('+').Append(lv.DefenceAbility).Append(' '); }
if (lv.HealthAbility != 0) { info.Set_Stat(true, cfg.levelHealthStat, lv.HealthAbility * cfg.levelStatScale); sb.Append(cfg.levelHealthStat).Append('+').Append(lv.HealthAbility).Append(' '); }
}
s_tmp.Clear();
WLEquipTables.CollectOpenedOptions(item.itemJson, s_tmp);
for (int o = 0; o < s_tmp.Count; o++)
{
var e = s_tmp[o];
for (int a = 0; a < e.Abilities.Count; a++)
{
var ab = e.Abilities[a];
bool any = false;
for (int m = 0; m < cfg.abilityMap.Count; m++)
{
var map = cfg.abilityMap[m];
if (map.ability != ab.Ability) continue;
info.Set_Stat(true, map.stat, ab.AbilityValue * map.scale);
sb.Append(map.stat).Append('+').Append(ab.AbilityValue * map.scale).Append(' ');
any = true;
}
if (!any) sb.Append(ab.Ability).Append("(미매핑) ");
}
}
sb.Append("| ");
}
LastAppliedItems = applied;
LastEquipAttack = equipAtk;
LastReport = sb.ToString();
if (cfg.verboseLog != 0) Debug.Log("[WL-821] 장비 스탯 적용 " + applied + "개 — " + LastReport);
}
/// PC 스탯 재계산(힘민지 EquipmentUI 와 같은 호출). 게임 밖(타이틀)에서는 아무 일도 없다.
public static void RefreshPc()
{
try
{
if (ServerInfo.Ins == null || ServerInfo.Ins.m_ServerData == null) return;
var info = MyValue.Get_ActorStatInfoorNull(eRole.PC);
EnforceBaseAttack(info);
}
catch (System.Exception ex) { Debug.LogWarning("[WL-821] PC 스탯 재계산 실패 — " + ex.Message); }
}
///
/// PD 2026-10-09 「플레이어 기본 공격력은 5」 — 힘민지 Reset 은 ATK 를 주스탯(STR/DEX/INT)×배율로 만든다(MyValue.cs:336).
/// Reset 끝에 훅이 없으므로 **재계산 뒤 사후 보정**: ATK = 기본값 + 장착 장비 공격력, BaseDmg(최종 공격력)는 같은 비율(BaseDmg/ATK)로.
/// Reset 이 다시 돌면 원본 값으로 돌아오므로 주기 폴링(WLEquipLauncher 0.5 s)에서 다시 맞춘다. 0 이면 무동작.
///
public static bool EnforceBaseAttack(ActorStatInfo info)
{
var cfg = WLEquipSettings.Instance;
if (cfg == null || cfg.enabled_ == 0 || cfg.pcBaseAttackOverride <= 0) return false;
if (info == null) return false;
double atk = info.Get_Stat(eStat.ATK);
double target = cfg.pcBaseAttackOverride + LastEquipAttack;
if (System.Math.Abs(atk - target) < 0.01) return false;
double bd = info.Get_Stat(eStat.BaseDmg);
double k = atk > 0.0001 ? bd / atk : 1.0;
info.Set_Stat(eStat.ATK, target);
info.Set_Stat(eStat.BaseDmg, target * k);
BaseAttackEnforced++;
LastEnforceLog = "ATK " + atk.ToString("F1") + " → " + target.ToString("F1") + " · BaseDmg " + bd.ToString("F1") + " → " + (target * k).ToString("F1") + " (장비 +" + LastEquipAttack + ")";
if (cfg.verboseLog != 0 && BaseAttackEnforced <= 3) Debug.Log("[WL-821] 기본 공격력 보정 — " + LastEnforceLog);
return true;
}
/// 주기 폴링용 — PC 가 있으면 현재 스탯 객체를 가져와(재계산 없이) 보정한다.
public static void EnforceBaseAttackTick()
{
try
{
if (!MyValue.bMyPC || MyValue.MyPC == null) return;
EnforceBaseAttack(MyValue.MyPC.Get_StatInfo());
}
catch { }
}
}
}