146 lines
4.4 KiB
C#
146 lines
4.4 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Gameplay.Area;
|
|
using Gameplay.Buff;
|
|
using Gameplay.Building.Data;
|
|
using Gameplay.Building.Impl.Common;
|
|
using Gameplay.Character;
|
|
using Gameplay.Performance;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
using LTGame;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.Building
|
|
{
|
|
public abstract class UnitBuild : GameUnit
|
|
{
|
|
|
|
public EFightBuildType buildType { get; private set; } = EFightBuildType.None;
|
|
|
|
public BuildConfigData configData { get; private set; }
|
|
|
|
protected NStateMachine<NBaseState> _fsm;
|
|
|
|
public UnitBuild(uint id, int troopId) : base(id, troopId, EGameUnitType.Building)
|
|
{
|
|
_fsm = new NStateMachine<NBaseState>();
|
|
}
|
|
|
|
public void InitConfig(BuildConfigData setConfig)
|
|
{
|
|
configData = setConfig;
|
|
buildType = configData.buildType;
|
|
|
|
debugShowInfo = new DebugShowInfo();
|
|
debugShowInfo.name = configData.rawConfig.Name;
|
|
debugShowInfo.configId = configData.rawConfig.Id + "";
|
|
debugShowInfo.cacheConfigId = configData.rawConfig.Id;
|
|
|
|
statusData.canBeAttack = configData.rawConfig.Hp > 0;
|
|
|
|
if (statusData.canBeAttack)
|
|
{
|
|
aliveData.maxHp = configData.rawConfig.Hp;
|
|
aliveData.currentHp = aliveData.maxHp;
|
|
}
|
|
|
|
commonData.standLevel = configData.rawConfig.StandCrossLevel;
|
|
|
|
commonData.level = configData.rawConfig.FightLevel;
|
|
fightData.baseAttack = configData.rawConfig.FightAttack;
|
|
fightData.attack = Mathf.FloorToInt(fightData.baseAttack);
|
|
fightData.baseDefense = configData.rawConfig.FightDefense;
|
|
fightData.defense = Mathf.FloorToInt(fightData.baseDefense);
|
|
|
|
_AfterInitConfig();
|
|
}
|
|
|
|
protected virtual void _AfterInitConfig()
|
|
{
|
|
|
|
}
|
|
|
|
private string _GetModelPath()
|
|
{
|
|
var modelPath = configData.rawConfig.ModelPath;
|
|
return $"Assets/Art_Out/Manual/Building/{modelPath}.prefab";
|
|
}
|
|
|
|
public async UniTask CreateAsync()
|
|
{
|
|
var modelPath = _GetModelPath();
|
|
GameUnitManager.instance.RecordLoadPath(modelPath);
|
|
var sampleObj = await AssetManager.Instance.LoadAssetAsync<GameObject>(modelPath);
|
|
if (sampleObj == null)
|
|
{
|
|
DebugUtil.LogError("加载建筑失败: {0}", modelPath);
|
|
return;
|
|
}
|
|
// 父节点已销毁
|
|
if (Node == null) return;
|
|
|
|
// 创建对象
|
|
var parent = Node.GameObject.transform;
|
|
var go = Object.Instantiate(sampleObj, parent, true);
|
|
go.transform.ResetLocals();
|
|
Node.GameObject.SetLayerEx(Node.GameObject.layer);
|
|
|
|
// 设置后处理
|
|
var obj = Node.GameObject;
|
|
var isEnemy = commonData.troopId != ETroopsId.Self;
|
|
OutlineManager.instance.AutoAddFromObj(obj, isEnemy);
|
|
|
|
PerformanceManager.instance.HandleCreateUnit(obj);
|
|
|
|
_AfterCreateView();
|
|
|
|
_InitFsm();
|
|
_fsm.ChangeState(EBuildState.Idle);
|
|
}
|
|
|
|
protected virtual void _AfterCreateView()
|
|
{
|
|
}
|
|
|
|
protected virtual void _InitFsm()
|
|
{
|
|
|
|
}
|
|
|
|
protected override void _OnEnterBattle()
|
|
{
|
|
base._OnEnterBattle();
|
|
isReady = true;
|
|
BuffManager.instance.InitBuild(this);
|
|
buffManager.TriggerEnterBattle();
|
|
|
|
if (configData.rawConfig.BlockAttack)
|
|
{
|
|
var blockData = AreaManager.instance.attackAreaManager.CreateBlockAttackCell(transData.cellIndex);
|
|
blockData.canBeAttack = statusData.canBeAttack;
|
|
}
|
|
}
|
|
|
|
protected override void _OnExitBattle()
|
|
{
|
|
base._OnExitBattle();
|
|
isReady = false;
|
|
buffManager?.TriggerExitBattle();
|
|
|
|
if (configData.rawConfig.BlockAttack)
|
|
{
|
|
AreaManager.instance.attackAreaManager.RemoveBlockAttackCell(transData.cellIndex);
|
|
}
|
|
}
|
|
|
|
protected override void _OnLogicUpdate(float dt)
|
|
{
|
|
base._OnLogicUpdate(dt);
|
|
|
|
_fsm.LogicUpdate(dt);
|
|
}
|
|
|
|
}
|
|
}
|