- 删除中间契约(BattleStartRequest/BattlePlayerInput/BattleReturnPlan/桥接与策略接口/FlowState),收敛为 BattleViewState/BattleStep/一层 BattleEvent - 新增内部 BattleRuntime/BattleUnit/BattleStatus 共享上下文;TurnBattleComponent 成为唯一外部入口,吸收启动/暂停/回写职责 - 内核支持 1v1 攻击闭环:效果公式、HP/MP 钳制、阵亡、Victory/TotalDefeat、敌人随机决策;敌人行动间歇 0.6s 由组件协程编排并经 StepListener 推送 - UI:玩家卡片/敌人槽/回合槽按战局重建,图标配置驱动(含新增 EnemyConfig.Icon),每轮刷新一次 TurnSlots 且轮内只移动高亮 - 新增 Tests 程序集 + InternalsVisibleTo,25 个 BattleRuntime 纯逻辑用例全部通过
92 lines
2.7 KiB
C#
92 lines
2.7 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using SepCore.AsyncTask;
|
|
using SepCore.Battle;
|
|
using SepCore.Definition;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace SepCore.UI
|
|
{
|
|
[DisallowMultipleComponent]
|
|
public sealed class BattleEnemySlotItem : MonoBehaviour
|
|
{
|
|
[SerializeField] private Button targetButton;
|
|
[SerializeField] private GameObject selectedMarker;
|
|
[SerializeField] private Image icon;
|
|
[SerializeField] private Image hpFill;
|
|
[SerializeField] private TextMeshProUGUI enemyName;
|
|
[SerializeField] private TextMeshProUGUI hpText;
|
|
|
|
private int _iconVersion;
|
|
|
|
/// <summary>
|
|
/// 用战斗单位视图填充敌人槽:名称、HP 数值与血条、配置图标和当前行动者标记。
|
|
/// 阵亡或已逃跑目标不可选。
|
|
/// </summary>
|
|
public void SetEnemy(BattleUnitView unit, bool isCurrentActor)
|
|
{
|
|
if (unit == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (enemyName != null)
|
|
{
|
|
enemyName.text = BattleUnitViewHelper.GetDisplayName(unit);
|
|
}
|
|
|
|
if (hpText != null)
|
|
{
|
|
hpText.text = unit.CurrentHp + " / " + unit.MaxHp;
|
|
}
|
|
|
|
SetBar(hpFill, unit.CurrentHp, unit.MaxHp);
|
|
|
|
if (selectedMarker != null)
|
|
{
|
|
selectedMarker.SetActive(isCurrentActor);
|
|
}
|
|
|
|
if (targetButton != null)
|
|
{
|
|
targetButton.interactable = !unit.IsDefeated && !unit.IsEscaped;
|
|
}
|
|
|
|
_iconVersion++;
|
|
ShowIconAsync(BattleUnitViewHelper.GetEnemyIconConfig(unit.ConfigId), _iconVersion).Forget();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 异步加载敌人图标;iconVersion 用于防止复用格子时旧加载结果覆盖新内容。
|
|
/// </summary>
|
|
private async UniTaskVoid ShowIconAsync(SpriteConfig iconConfig, int iconVersion)
|
|
{
|
|
if (iconConfig == null || icon == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Sprite sprite = await SpriteLoader.LoadSpriteAsync(iconConfig);
|
|
if (sprite == null || _iconVersion != iconVersion)
|
|
{
|
|
return;
|
|
}
|
|
|
|
icon.sprite = sprite;
|
|
icon.gameObject.SetActive(true);
|
|
}
|
|
|
|
private static void SetBar(Image fill, int current, int max)
|
|
{
|
|
if (fill == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
float ratio = max > 0 ? Mathf.Clamp01((float)current / max) : 0f;
|
|
fill.rectTransform.anchorMax = new Vector2(ratio, 1f);
|
|
}
|
|
}
|
|
} |