83 lines
3.1 KiB
C#
83 lines
3.1 KiB
C#
/*
|
||
* @Author: 白哉
|
||
* @Description:
|
||
* @Date: 2025年04月23日 星期三 21:04:18
|
||
* @Modify:
|
||
*/
|
||
|
||
|
||
using RuntimeData;
|
||
using System;
|
||
using MemoryPack;
|
||
using TH1_Logic.Core;
|
||
using UnityEngine;
|
||
|
||
|
||
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();
|
||
|
||
int viewRadius = info.DamageTarget.GetSightRange(mapData);
|
||
|
||
bool setToCity = false;
|
||
foreach (var city in citySet)
|
||
{
|
||
if (mapData.GetUnitCount(city.Id) >= city.Level) continue;
|
||
//如果是别人转化了我的单位,我这个单位的所属的城市的cityInfoRender要重新更新
|
||
var originCity = info.DamageTarget.City(mapData);
|
||
|
||
mapData.SetUnitIdToCityId(info.DamageTarget.Id, city.Id);
|
||
info.DamageTarget.Skills.Clear();
|
||
mapData.AddUnitSkill(info.DamageTarget);
|
||
//如果是我方城市增加了一个单位,更新cityinforenderer
|
||
if((city.Grid(mapData)?.InMainSight()??false))
|
||
city.CityInfoRenderer(mapData)?.InstantUpdateCityInfo();
|
||
//如果是我方城市减少了一个单位,更新cityinforenderer
|
||
if(originCity != null && (originCity.Player(mapData)?.IsSelfPlayer() ?? false))
|
||
originCity.CityInfoRenderer(mapData)?.InstantUpdateCityInfo();
|
||
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;
|
||
}
|
||
|
||
|
||
if (grid.Feature == TerrainFeature.Mountain) viewRadius = Mathf.Max(viewRadius,2);
|
||
Main.PlayerLogic.UpdateSightByRadius_LogicView(mapData,player,grid,viewRadius,true);
|
||
|
||
}
|
||
}
|
||
} |