158 lines
5.2 KiB
C#
158 lines
5.2 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Continentis.MainGame.Card;
|
||
using Continentis.MainGame.Combat;
|
||
using Lean.Pool;
|
||
using NaughtyAttributes;
|
||
using SLSFramework.General;
|
||
using SLSFramework.UModAssistance;
|
||
using UnityEngine;
|
||
using Object = UnityEngine.Object;
|
||
using Random = UnityEngine.Random;
|
||
|
||
namespace Continentis.MainGame.Character
|
||
{
|
||
public enum Fraction
|
||
{
|
||
Player,
|
||
Ally,
|
||
Enemy,
|
||
Neutral
|
||
}
|
||
|
||
public interface ICardOwner
|
||
{
|
||
DeckSubmodule deckSubmodule { get; }
|
||
}
|
||
|
||
public partial class CharacterBase : ICardOwner, IGameElement
|
||
{
|
||
public Guid elementID { get; set; }
|
||
|
||
public CharacterData data;
|
||
public CharacterLogicBase logicBase;
|
||
|
||
public Fraction fraction;
|
||
public CombatTeam team;
|
||
|
||
public int actionCountThisRound;
|
||
|
||
[ShowNativeProperty]
|
||
public AttributeSubmodule attributeSubmodule { get; private set; }
|
||
|
||
[ShowNativeProperty]
|
||
public EventSubmodule eventSubmodule { get; private set; }
|
||
|
||
[ShowNativeProperty]
|
||
public EquipmentSubmodule equipmentSubmodule { get; private set; }
|
||
|
||
[ShowNativeProperty]
|
||
public DeckSubmodule deckSubmodule { get; private set; }
|
||
|
||
[ShowNativeProperty]
|
||
public IntentionSubmodule intentionSubmodule { get; private set; }
|
||
|
||
[ShowNativeProperty]
|
||
public StatusSubmodule statusSubmodule { get; private set; }
|
||
|
||
[ShowNativeProperty]
|
||
public CombatBuffSubmodule combatBuffSubmodule { get; private set; }
|
||
|
||
[ShowNativeProperty]
|
||
public RecordSubmodule recordSubmodule { get; private set; }
|
||
|
||
public CharacterBase(CharacterData data, Fraction fraction)
|
||
{
|
||
(this as IGameElement).Initialize();
|
||
|
||
this.data = data;
|
||
this.fraction = fraction;
|
||
|
||
switch (fraction)
|
||
{
|
||
case Fraction.Player:
|
||
this.team = CombatMainManager.Instance.characterController.playerTeam;
|
||
break;
|
||
case Fraction.Enemy:
|
||
this.team = CombatMainManager.Instance.characterController.enemyTeam;
|
||
break;
|
||
default:
|
||
this.team = null;
|
||
break;
|
||
}
|
||
|
||
attributeSubmodule = new AttributeSubmodule(this);
|
||
equipmentSubmodule = new EquipmentSubmodule(this);
|
||
eventSubmodule = new EventSubmodule(this);
|
||
deckSubmodule = new DeckSubmodule(this);
|
||
intentionSubmodule = new IntentionSubmodule(this);
|
||
statusSubmodule = new StatusSubmodule(this);
|
||
combatBuffSubmodule = new CombatBuffSubmodule(this);
|
||
recordSubmodule = new RecordSubmodule(this);
|
||
|
||
this.logicBase = GenerateCharacterLogic(data);
|
||
this.logicBase.Initialize(this);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 生成卡牌逻辑实例
|
||
/// </summary>
|
||
public static CharacterLogicBase GenerateCharacterLogic(CharacterData data)
|
||
{
|
||
string typeID = ModManager.GetTypeID(data.modName, "Characters", "", data.className);
|
||
Type logicType = ModManager.GetType(typeID);
|
||
|
||
if(logicType == null)
|
||
{
|
||
return new CharacterLogicBase();
|
||
}
|
||
|
||
if (Activator.CreateInstance(logicType) is CharacterLogicBase logic)
|
||
{
|
||
return logic;
|
||
}
|
||
|
||
Debug.LogError($"Card class '{typeID}' not found or could not be instantiated.");
|
||
return null;
|
||
}
|
||
}
|
||
|
||
public partial class CharacterBase
|
||
{
|
||
public CombatCharacterViewBase characterView;
|
||
}
|
||
|
||
public partial class CharacterBase
|
||
{
|
||
public CombatCharacterViewBase GenerateCharacterView(Vector3 position)
|
||
{
|
||
GameObject prefab = data.combatCharacterView;
|
||
CombatCharacterViewBase characterView = Object.Instantiate(prefab, position, Quaternion.identity).GetComponent<CombatCharacterViewBase>();
|
||
characterView.Initialize(this);
|
||
this.characterView = characterView;
|
||
return characterView;
|
||
}
|
||
|
||
public virtual void Die()
|
||
{
|
||
// TODO: 1.1c — 死亡动画命令(入队 Cmd_PlayAnimation + VFX),待动画系统完善后替换
|
||
Debug.Log($"[Combat] {data.displayName} 死亡");
|
||
|
||
CharacterBase self = this;
|
||
|
||
// 触发 onDeath 事件,供 Buff / 技能系统在角色移除前响应
|
||
CommandQueueManager.Instance.AddCommand(Cmd.Do(() =>
|
||
{
|
||
self.eventSubmodule.onDeath.Invoke();
|
||
CombatMainManager.Instance.eventCollection.onCharacterDeath.Invoke(self);
|
||
}));
|
||
|
||
// 角色移除:从战场数据结构中清理,并触发胜负检查
|
||
CommandQueueManager.Instance.AddCommand(Cmd.Do(() =>
|
||
{
|
||
CombatMainManager.Instance.characterController.RemoveCharacter(self);
|
||
}));
|
||
}
|
||
}
|
||
} |