2025-10-19 00:48:06 +08:00

75 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: 白哉
* @Description:
* @Date: 2025年04月23日 星期三 21:04:18
* @Modify:
*/
using RuntimeData;
using System;
using MemoryPack;
using TH1_Logic.Core;
namespace Logic.Skill
{
public partial class ConvertSkill : SkillBase
{
public ConvertSkill()
{
IsPermanent = true;
TurnsLimit = 0;
Score = 4;
}
public override SkillType GetSkillType()
{
return SkillType.CONVERT;
}
// 攻击一名单位后,将该单位变成己方单位
public override void OnDamageOther(MapData mapData, SettlementInfo info)
{
if (info == null) return;
if (info.DamageType != DamageType.ActiveAttack) return;
if (info.DamageOrigin == null || info.DamageTarget == null) return;
if (info.DamageTarget.UnitType is UnitType.Giant or UnitType.GiantJuggernaut or UnitType.KaguyaFrenchReisenIllusion or UnitType.KaguyaFrenchMokouEgg) return;
if (!mapData.GetGridDataByUnitId(info.DamageTarget.Id, out var grid)) return;
if (!mapData.GetPlayerDataByUnitId(info.DamageOrigin.Id, out var player)) return;
var citySet = mapData.GetCityDataSetByPlayerId(player.Id);
info.DamageTarget.ClearAPMPCP();
bool setToCity = false;
foreach (var city in citySet)
{
if (mapData.GetUnitCount(city.Id) >= city.Level) continue;
mapData.SetUnitIdToCityId(info.DamageTarget.Id, city.Id);
info.DamageTarget.Skills.Clear();
mapData.AddUnitSkill(info.DamageTarget);
setToCity = true;
break;
}
if(!setToCity)
foreach (var city in citySet)
{
if (!city.IsCapital) continue;
mapData.SetUnitIdToCityId(info.DamageTarget.Id, city.Id);
info.DamageTarget.Skills.Clear();
mapData.AddUnitSkill(info.DamageTarget);
break;
}
//TODO 这里用了个小trick更新视野不是立刻而是微小时间后因为视野更新要在动画结束后
//暂时没有别的办法
Timer.Instance.TimerRegister(this, () =>
{
Main.PlayerLogic.UpdateSightByRadius(mapData,player,grid,grid.Feature == TerrainFeature.Mountain? 2:1);
},0.05f,"ConvertSKillOnDamageOther");
}
}
}