113 lines
3.5 KiB
C#
113 lines
3.5 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年04月23日 星期三 21:04:18
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using RuntimeData;
|
|
using System;
|
|
using MemoryPack;
|
|
using TH1_Anim.Fragments;
|
|
using TH1_Core.Managers;
|
|
using TH1_Logic.Core;
|
|
using TH1Renderer;
|
|
|
|
|
|
namespace Logic.Skill
|
|
{
|
|
public partial class SurpriseSkill : SkillBase
|
|
{
|
|
public SurpriseSkill()
|
|
{
|
|
IsPermanent = true;
|
|
TurnsLimit = 0;
|
|
Score = 4;
|
|
}
|
|
|
|
public override SkillType GetSkillType()
|
|
{
|
|
return SkillType.SURPRISE;
|
|
}
|
|
|
|
public override bool IsLimitTargetCounterAttack(UnitData self, MapData mapData)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public override void AfterActiveAttackOther(MapData mapData, AttackInfo attackInfo)
|
|
{
|
|
if (mapData == null || attackInfo?.DamageOrigin == null || attackInfo.DamageOriginGrid == null) return;
|
|
if (!mapData.GetPlayerIdByUnitId(attackInfo.DamageOrigin.Id, out var selfPlayerId)) return;
|
|
if (!IsEnemyTerritoryOrAdjacent(mapData, attackInfo.DamageOriginGrid, selfPlayerId)) return;
|
|
|
|
attackInfo.DamageOrigin.AddSkill_Legacy(
|
|
SkillType.MOVERANGEUP,
|
|
mapData,
|
|
false,
|
|
0,
|
|
false,
|
|
-1,
|
|
false,
|
|
SpecialAddSkillType.AddTurnLimit,
|
|
attackInfo.DamageOrigin.Id);
|
|
RefreshOriginVisualAfterAttack(mapData, attackInfo.DamageOrigin);
|
|
}
|
|
|
|
private static void RefreshOriginVisualAfterAttack(MapData mapData, UnitData origin)
|
|
{
|
|
if (mapData != Main.MapData) return;
|
|
|
|
var scope = PresentationManager.CurrentScope;
|
|
if (scope != null)
|
|
{
|
|
if (MapRenderer.Instance != null &&
|
|
MapRenderer.Instance.ROUnitMap.TryGetValue(origin.Id, out var unitRenderer))
|
|
{
|
|
scope.Add(new FragmentStep
|
|
{
|
|
Phase = AnimPhase.AttackImpact + 50,
|
|
Duration = 0.1f,
|
|
Execute = () => { unitRenderer.InstantUpdateUnit(false); }
|
|
});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (MapRenderer.Instance != null &&
|
|
MapRenderer.Instance.ROUnitMap.TryGetValue(origin.Id, out var unitRenderer))
|
|
{
|
|
unitRenderer.RenderUpdateUnitImage();
|
|
}
|
|
}
|
|
}
|
|
|
|
private static bool IsEnemyTerritoryOrAdjacent(MapData mapData, GridData originGrid, uint selfPlayerId)
|
|
{
|
|
if (IsEnemyTerritory(mapData, originGrid, selfPlayerId)) return true;
|
|
|
|
var aroundBuf = RentAroundBuf();
|
|
mapData.GridMap.GetAroundGridData(1, 1, originGrid, aroundBuf);
|
|
foreach (var grid in aroundBuf)
|
|
{
|
|
if (grid.Id == originGrid.Id) continue;
|
|
if (!IsEnemyTerritory(mapData, grid, selfPlayerId)) continue;
|
|
|
|
ReturnAroundBuf();
|
|
return true;
|
|
}
|
|
|
|
ReturnAroundBuf();
|
|
return false;
|
|
}
|
|
|
|
private static bool IsEnemyTerritory(MapData mapData, GridData grid, uint selfPlayerId)
|
|
{
|
|
return grid != null
|
|
&& mapData.GetPlayerDataByTerritoryGridId(grid.Id, out var territoryPlayer)
|
|
&& !mapData.SameUnion(selfPlayerId, territoryPlayer.Id);
|
|
}
|
|
}
|
|
}
|