Files
bansonic_beta_main/Assets/scripts/Data/AllyHero_SO.cs
T

376 lines
11 KiB
C#

using System;
using UnityEngine;
using System.Collections.Generic;
[CreateAssetMenu(fileName = "NewAllyHero", menuName = "SO_Data/AllyHero")]
public class AllyHero_SO : ScriptableObject
{
public static readonly string[] BehaviourAxisNames =
{
"题海战术",
"诛锄异己",
"逸乐共谋",
"完美至上",
"涵养心境",
"众志成城",
"过激行为",
"二次形变",
"自有主见",
"迷茫或凡想"
};
[Header("Inspector")]
public string ally_heroName;
public string ally_heroDesignation;
public int ally_heroID;
public bool isUnlocked;
[Header("Inspector")]
public Sprite ally_heroImage;
[Header("Inspector")]
public Sprite ally_heroProfile;
[Header("Inspector")]
public Sprite ally_heroSelectIcon;
[Header("Inspector")]
public Sprite ally_heroIcon;
[Header("Inspector")]
public Sprite ally_heroPoster;
[Header("Inspector")]
public Sprite ally_hero_HD_image;
[Header("Inspector")]
public Sprite ally_hero_squareProfile;
[Header("Inspector")]
public Color ally_heroThemeColor;
[Header("Inspector")]
[TextArea(3, 10)]
[Tooltip("Documentation text normalized.")]
public string ally_heroDescription;
[Header("Inspector")]
public List<AllyLevelInfo> levelStats = new List<AllyLevelInfo>();
[System.Serializable]
public class AllyLevelInfo
{
[Tooltip("Documentation text normalized.")]
public string levelName;
public int levelID;
[Tooltip("Documentation text normalized.")]
public int attack = 0;
[Tooltip("Documentation text normalized.")]
public int maxHP = 100;
[Tooltip("Documentation text normalized.")]
public float damageResistance = 0f;
[Tooltip("Documentation text normalized.")]
public int maxMana = 100;
[Tooltip("Documentation text normalized.")]
public float scoreEfficiency = 1f;
[Header("Inspector")]
[Tooltip("Documentation text normalized.")]
public int requiredEXP;
[Header("Inspector")]
[Tooltip("Documentation text normalized.")]
public int skill_slot_limited;
[Header("Note-hit shared parameters")]
[Tooltip("Documentation text normalized.")]
public int manaGainGood = 1;
[Tooltip("Documentation text normalized.")]
public int manaGainGreat = 2;
[Tooltip("Documentation text normalized.")]
public int manaGainPerfect = 3;
[Tooltip("Documentation text normalized.")]
public int manaGainOnMiss = 5;
[Tooltip("Documentation text normalized.")]
public float damageMultiplierGood = 0.5f;
[Tooltip("Documentation text normalized.")]
public float damageMultiplierGreat = 0.75f;
[Tooltip("Documentation text normalized.")]
public float damageMultiplierPerfect = 1f;
[Tooltip("Documentation text normalized.")]
public float missHpLossBase = 10f;
}
[System.Serializable]
public class AllyBehaviourAxis
{
public string axisName;
[Range(0, 100)] public int value;
}
[Header("Inspector")]
public int ally_currentEXP;
public int ally_growthUnlockedTierIndex;
public bool ally_autoBreakthroughEnabled;
public int ally_battleDeployCount;
public int ally_finishCount;
public int ally_mvpCount;
public long ally_joinDateUtcTicks;
[Header("Behaviour Radar")]
public List<AllyBehaviourAxis> behaviourAxes = new List<AllyBehaviourAxis>();
[Header("Skills")]
public SkillDefinition[] availableSkills;
[Tooltip("Indexes into availableSkills for preselected skills; empty means none selected")]
public int[] selectedSkillIndices = new int[0];
[Tooltip("Primary selected skill index into availableSkills (-1 = none)")]
public int primarySkillIndex = -1;
[Tooltip("Skill groups defined on this hero. Each SkillGroup has a numeric skillGroupID which can be equipped into slots to allow activation of the entire group via that ID.")]
public SkillGroup[] skillGroups = new SkillGroup[0];
[Tooltip("Equipped skill group IDs for this ally. Each int references a skillGroupID defined in skillGroups. Use 0 to indicate empty.")]
public int[] equippedSkillGroupIDs = new int[0];
public SkillDefinition GetPrimarySkill()
{
if (availableSkills == null || primarySkillIndex < 0 || primarySkillIndex >= availableSkills.Length) return null;
return availableSkills[primarySkillIndex];
}
public SkillGroup GetPrimarySkillGroup()
{
if (skillGroups == null || skillGroups.Length == 0) return null;
if (equippedSkillGroupIDs != null && equippedSkillGroupIDs.Length > 0)
{
foreach (int gid in equippedSkillGroupIDs)
{
if (gid == 0) continue;
SkillGroup group = GetSkillGroupByID(gid);
if (group != null) return group;
}
}
foreach (SkillGroup group in skillGroups)
{
if (group != null) return group;
}
return null;
}
public SkillGroup GetSkillGroupByID(int groupID)
{
if (skillGroups == null || skillGroups.Length == 0) return null;
foreach (SkillGroup group in skillGroups)
{
if (group != null && group.skillGroupID == groupID) return group;
}
return null;
}
public AllyLevelInfo GetEffectiveLevelForCurrentEXP()
{
if (levelStats == null || levelStats.Count == 0) return null;
List<AllyLevelInfo> sorted = new List<AllyLevelInfo>();
for (int i = 0; i < levelStats.Count; i++)
{
if (levelStats[i] != null)
{
sorted.Add(levelStats[i]);
}
}
if (sorted.Count == 0)
{
return null;
}
sorted.Sort((left, right) => left.requiredEXP.CompareTo(right.requiredEXP));
int unlockedTierIndex = Mathf.Clamp(ally_growthUnlockedTierIndex, 0, sorted.Count - 1);
return sorted[unlockedTierIndex];
}
[System.Serializable]
private class EquippedSkillGroupIDsPayload
{
public int[] equippedSkillGroupIDs;
}
private string GetEquippedSkillsPrefsKey()
{
return "ally_equippedSkillGroupIDs_" + ally_heroID;
}
public void SaveEquippedSkillsToLocal()
{
var payload = new EquippedSkillGroupIDsPayload { equippedSkillGroupIDs = equippedSkillGroupIDs ?? new int[0] };
string json = JsonUtility.ToJson(payload);
PlayerPrefs.SetString(GetEquippedSkillsPrefsKey(), json);
PlayerPrefs.Save();
}
public void LoadEquippedSkillsFromLocal()
{
string key = GetEquippedSkillsPrefsKey();
if (!PlayerPrefs.HasKey(key)) return;
string json = PlayerPrefs.GetString(key, "");
if (string.IsNullOrEmpty(json)) return;
var payload = JsonUtility.FromJson<EquippedSkillGroupIDsPayload>(json);
if (payload == null) return;
equippedSkillGroupIDs = payload.equippedSkillGroupIDs ?? new int[0];
}
public void ClearEquippedSkills()
{
equippedSkillGroupIDs = Array.Empty<int>();
PlayerPrefs.DeleteKey(GetEquippedSkillsPrefsKey());
PlayerPrefs.Save();
#if UNITY_EDITOR
if (!Application.isPlaying)
{
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
}
public static void ClearAllEquippedSkills()
{
HashSet<int> clearedHeroIds = new HashSet<int>();
#if UNITY_EDITOR
string[] guids = UnityEditor.AssetDatabase.FindAssets("t:AllyHero_SO", new[] { "Assets/Resources/so/ally" });
for (int i = 0; i < guids.Length; i++)
{
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[i]);
AllyHero_SO hero = UnityEditor.AssetDatabase.LoadAssetAtPath<AllyHero_SO>(path);
if (hero == null)
{
continue;
}
hero.ClearEquippedSkills();
clearedHeroIds.Add(hero.ally_heroID);
}
UnityEditor.AssetDatabase.SaveAssets();
#endif
AllyHero_SO[] runtimeHeroes = Resources.LoadAll<AllyHero_SO>("so/ally");
for (int i = 0; i < runtimeHeroes.Length; i++)
{
AllyHero_SO hero = runtimeHeroes[i];
if (hero == null || clearedHeroIds.Contains(hero.ally_heroID))
{
continue;
}
hero.ClearEquippedSkills();
}
PlayerPrefs.Save();
}
public void SetUnlocked(bool value)
{
if (isUnlocked == value) return;
isUnlocked = value;
#if UNITY_EDITOR
if (!Application.isPlaying)
{
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
}
private void OnValidate()
{
EnsureBehaviourAxes();
}
public void EnsureBehaviourAxes()
{
if (behaviourAxes == null)
{
behaviourAxes = new List<AllyBehaviourAxis>();
}
while (behaviourAxes.Count < BehaviourAxisNames.Length)
{
behaviourAxes.Add(new AllyBehaviourAxis());
}
if (behaviourAxes.Count > BehaviourAxisNames.Length)
{
behaviourAxes.RemoveRange(BehaviourAxisNames.Length, behaviourAxes.Count - BehaviourAxisNames.Length);
}
for (int i = 0; i < BehaviourAxisNames.Length; i++)
{
if (behaviourAxes[i] == null)
{
behaviourAxes[i] = new AllyBehaviourAxis();
}
behaviourAxes[i].axisName = BehaviourAxisNames[i];
behaviourAxes[i].value = Mathf.Clamp(behaviourAxes[i].value, 0, 100);
}
}
public void IncrementBattleDeployCount(int amount = 1)
{
if (amount <= 0) return;
AllyHeroDeployLedger.EnsureInstance().IncrementDeployCount(this, amount);
#if UNITY_EDITOR
if (!Application.isPlaying)
{
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
}
public void LoadBattleDeployCountFromLocal()
{
ally_battleDeployCount = AllyHeroDeployLedger.EnsureInstance().GetDeployCount(ally_heroID);
}
public void SaveBattleDeployCountToLocal()
{
AllyHeroDeployLedger.EnsureInstance().SaveNow();
}
public void IncrementFinishCount(int amount = 1)
{
if (amount <= 0) return;
AllyHeroDeployLedger.EnsureInstance().IncrementFinishCount(this, amount);
#if UNITY_EDITOR
if (!Application.isPlaying)
{
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
}
public void IncrementMvpCount(int amount = 1)
{
if (amount <= 0) return;
AllyHeroDeployLedger.EnsureInstance().IncrementMvpCount(this, amount);
#if UNITY_EDITOR
if (!Application.isPlaying)
{
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
}
public void SetJoinDateIfMissing(System.DateTime? utcTime = null)
{
AllyHeroDeployLedger.EnsureInstance().SetJoinDateIfMissing(this, utcTime);
#if UNITY_EDITOR
if (!Application.isPlaying)
{
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
}
}