117 lines
4.3 KiB
C#
117 lines
4.3 KiB
C#
/*
|
||
* @Author: 白哉
|
||
* @Description: 可隐匿技能
|
||
* 同时承担"移动前后 HideState 状态变化检测 + 出发格播 Fog"职责:
|
||
* BeforeMove → 快照 HideState 状态 + 出发格 id
|
||
* OnAnyUnitMove → 比对状态变化,必要时在出发格播 Fog
|
||
* (不放在 HideStateSkill 是因为"本无 HideState → 移动后获得"的场景下 HideStateSkill 此时还没挂在单位身上)
|
||
* @Date: 2026年03月06日
|
||
* @Modify:
|
||
*/
|
||
|
||
using RuntimeData;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using MemoryPack;
|
||
using TH1Renderer;
|
||
using UnityEngine;
|
||
|
||
namespace Logic.Skill
|
||
{
|
||
public partial class CanHideSkill : SkillBase
|
||
{
|
||
[MemoryPackIgnore]
|
||
private bool _hasMovedThisTurn;
|
||
|
||
// 移动前是否处于 HideState:用于在 OnAnyUnitMove 派发完毕后比对状态变化
|
||
[MemoryPackIgnore]
|
||
private bool _hideStateBeforeMove;
|
||
|
||
// 移动前的出发格 GridId:状态变化时用它定位 Fog 播放位置
|
||
[MemoryPackIgnore]
|
||
private uint _startGridIdBeforeMove;
|
||
|
||
public CanHideSkill()
|
||
{
|
||
IsPermanent = true;
|
||
TurnsLimit = 0;
|
||
Score = 4;
|
||
_hasMovedThisTurn = false;
|
||
}
|
||
|
||
public override SkillType GetSkillType()
|
||
{
|
||
return SkillType.CanHide;
|
||
}
|
||
|
||
public override void OnTurnStart(IdentifierBase self, MapData mapData)
|
||
{
|
||
_hasMovedThisTurn = false;
|
||
}
|
||
|
||
// 在所有 OnMove 派发之前快照 HideState 与出发格
|
||
public override void BeforeMove(UnitData self, GridData grid, MapData mapData, MoveType moveType, List<Vector2Int> path = null)
|
||
{
|
||
_hideStateBeforeMove = self.GetSkill(SkillType.HideState, out _);
|
||
var fromGrid = self.Grid(mapData);
|
||
_startGridIdBeforeMove = fromGrid?.Id ?? 0;
|
||
}
|
||
|
||
public override void OnMove(UnitData self, GridData grid, MapData mapData, MoveType moveType, List<Vector2Int> path = null)
|
||
{
|
||
if (_hasMovedThisTurn)
|
||
return;
|
||
|
||
_hasMovedThisTurn = true;
|
||
|
||
// 走到敌方军营上不能隐身(军营会破除潜行)
|
||
if (grid.Resource is ResourceType.Military or ResourceType.RemiliaMilitary or ResourceType.MoriyaMilitary)
|
||
{
|
||
if (grid.Player(mapData, out var gridPlayer) && self.Player(mapData, out var selfPlayer))
|
||
{
|
||
if (!mapData.SameUnion(gridPlayer.Id, selfPlayer.Id))
|
||
return;
|
||
}
|
||
}
|
||
|
||
// 走到敌方城市中心不能隐身(与军营同语义)
|
||
if (grid.Resource == ResourceType.CityCenter)
|
||
{
|
||
if (mapData.GetCityDataByGid(grid.Id, out var city)
|
||
&& city.Player(mapData, out var cityPlayer)
|
||
&& self.Player(mapData, out var selfPlayer)
|
||
&& !mapData.SameUnion(cityPlayer.Id, selfPlayer.Id))
|
||
return;
|
||
}
|
||
|
||
// 添加 HideState。视觉刷新在 HideStateSkill.OnSkillAdd 中处理,
|
||
// Fog 特效由本类 OnAnyUnitMove 中的状态变化检测统一播放
|
||
self.AddOrOverrideSkill(SkillType.HideState, mapData, self.Id);
|
||
}
|
||
|
||
// OnAnyUnitMove 在 MoveToLogic 中位于所有 OnMove 派发之后,HideState 最终状态此时已稳定
|
||
public override void OnAnyUnitMove(MapData map, IdentifierBase identifier, UnitData moveUnit, GridData target, MoveType moveType)
|
||
{
|
||
if (identifier is not UnitData self) return;
|
||
if (moveUnit == null || moveUnit.Id != self.Id) return;
|
||
|
||
bool hideStateAfterMove = self.GetSkill(SkillType.HideState, out _);
|
||
if (_hideStateBeforeMove == hideStateAfterMove)
|
||
{
|
||
_startGridIdBeforeMove = 0;
|
||
return;
|
||
}
|
||
|
||
// 状态变化 → 在出发格播 Fog
|
||
if (_startGridIdBeforeMove != 0
|
||
&& map.GridMap.GetGridDataByGid(_startGridIdBeforeMove, out var startGrid)
|
||
&& self.InMainSight())
|
||
{
|
||
startGrid.Renderer(map)?.PlayVFXInSight(new GridVFXParams(GridVFXType.Fog));
|
||
}
|
||
_startGridIdBeforeMove = 0;
|
||
}
|
||
}
|
||
}
|