148 lines
6.3 KiB
C#
148 lines
6.3 KiB
C#
/*
|
||
* @Author: 白哉
|
||
* @Description: 古明地恐惧技能
|
||
* @Date: 2026年03月06日
|
||
* @Modify:
|
||
*/
|
||
|
||
|
||
using RuntimeData;
|
||
using Logic.CrashSight;
|
||
using System.Text;
|
||
using TH1_Logic.Core;
|
||
using TH1Renderer;
|
||
|
||
|
||
namespace Logic.Skill
|
||
{
|
||
public partial class KomeijiRiderTransSkill : SkillBase
|
||
{
|
||
public KomeijiRiderTransSkill()
|
||
{
|
||
IsPermanent = true;
|
||
TurnsLimit = 0;
|
||
Score = 4;
|
||
}
|
||
|
||
public override SkillType GetSkillType()
|
||
{
|
||
return SkillType.KomeijiRiderTrans;
|
||
}
|
||
|
||
public override void OnDamageOther(MapData mapData, SettlementInfo info)
|
||
{
|
||
if (!info.IsKill || info.IsDeathReplaced) return;
|
||
if (info.DamageOrigin == null || info.DamageTarget == null) return;
|
||
if (info.DamageTarget.UnitFullType.UnitType == UnitType.Giant) return;
|
||
if (info.DamageTarget.TreatedAsHero(mapData,info.DamageOrigin)) return;
|
||
if (info.DamageTargetGrid == null || info.DamageTargetGrid.Terrain != TerrainType.Land) return;
|
||
var city = info.DamageOrigin.City(mapData);
|
||
if (city == null) return;
|
||
var spawnFullType = info.DamageTarget.UnitFullType;
|
||
var targetLandType = info.DamageTarget.GetLandType();
|
||
var fixedBoatOnLand = false;
|
||
if (targetLandType is LandType.WaterAndAshore or LandType.WaterOnly)
|
||
{
|
||
var carryFullType = info.DamageTarget.CarryUnitFullType;
|
||
if (carryFullType.UnitType != UnitType.None && mapData.CheckLandTypeForGrid(carryFullType, info.DamageTargetGrid))
|
||
{
|
||
spawnFullType = carryFullType;
|
||
fixedBoatOnLand = true;
|
||
ReportBoatOnLandTransform(mapData, info, spawnFullType, "UseCarryUnitFullType");
|
||
}
|
||
else
|
||
{
|
||
ReportBoatOnLandTransform(mapData, info, spawnFullType, "BlockedNoValidCarry");
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (!mapData.CheckLandTypeForGrid(spawnFullType, info.DamageTargetGrid)) return;
|
||
info.IsDeathReplaced = true;
|
||
int originHealth = info.DamageOrigin.Health;
|
||
var originRenderer = info.DamageOrigin.Renderer(mapData);
|
||
var originGrid = info.DamageOrigin.Grid(mapData);
|
||
Main.UnitLogic.UnitUnnaturalDie(mapData, info.DamageOrigin);
|
||
if (mapData == Main.MapData)
|
||
{
|
||
originRenderer?.Die();
|
||
originGrid?.Renderer(mapData)?.InstantUpdateGrid();
|
||
}
|
||
if (mapData.AddUnitData(info.DamageTargetGrid.Id, city.Id, spawnFullType, out var newUnit))
|
||
{
|
||
// 如果击杀目标携带了Carry信息,将其传给新单位
|
||
if (!fixedBoatOnLand && info.DamageTarget.CarryUnitType != UnitType.None)
|
||
newUnit.CarryUnitFullType = info.DamageTarget.CarryUnitFullType;
|
||
|
||
int maxHealth = newUnit.GetMaxHealth();
|
||
newUnit.Health = System.Math.Min(10, maxHealth);
|
||
|
||
// 更新新单位的视野
|
||
if (mapData.GetPlayerDataByUnitId(newUnit.Id, out var newPlayer))
|
||
{
|
||
Main.PlayerLogic.UpdateSight_LogicView(mapData, newPlayer,
|
||
mapData.GridMap.GetAroundGridIdList(newUnit.GetSightRange(mapData), info.DamageTargetGrid));
|
||
}
|
||
|
||
if (mapData == Main.MapData)
|
||
{
|
||
info.DamageTargetGrid.Renderer(mapData)?.InstantUpdateGrid();
|
||
newUnit.Renderer(mapData)?.RenderUpdateUnitImage();
|
||
}
|
||
}
|
||
}
|
||
|
||
private static void ReportBoatOnLandTransform(MapData mapData, SettlementInfo info, UnitFullType spawnFullType, string result)
|
||
{
|
||
try
|
||
{
|
||
if (mapData == null || info?.DamageTarget == null || info.DamageTargetGrid == null) return;
|
||
|
||
var sb = new StringBuilder(1024);
|
||
sb.AppendLine("[KomeijiRiderTransBoatOnLand] KomeijiRiderTrans尝试在陆地复生船形态Unit");
|
||
sb.Append("Result=").Append(result)
|
||
.Append(", MapId=").Append(mapData.MapID)
|
||
.Append(", ActionIndex=").Append(mapData.Net?.Actions?.Count ?? 0)
|
||
.Append(", OriginUnitId=").Append(info.DamageOrigin?.Id ?? 0)
|
||
.Append(", TargetUnitId=").Append(info.DamageTarget.Id)
|
||
.Append(", TargetGridId=").Append(info.DamageTargetGrid.Id)
|
||
.Append(", TargetGridTerrain=").Append(info.DamageTargetGrid.Terrain)
|
||
.Append(", TargetGridResource=").Append(info.DamageTargetGrid.Resource)
|
||
.Append(", TargetGridPos=(").Append(info.DamageTargetGrid.Pos.X).Append(",").Append(info.DamageTargetGrid.Pos.Y).Append(")")
|
||
.AppendLine();
|
||
|
||
sb.Append("TargetType=").Append(FormatUnitFullType(info.DamageTarget.UnitFullType))
|
||
.Append(", TargetLandType=").Append(info.DamageTarget.GetLandType())
|
||
.Append(", TargetCarry=").Append(FormatUnitFullType(info.DamageTarget.CarryUnitFullType))
|
||
.Append(", SpawnType=").Append(FormatUnitFullType(spawnFullType))
|
||
.AppendLine();
|
||
|
||
var actions = mapData.Net?.Actions;
|
||
if (actions != null && actions.Count > 0)
|
||
{
|
||
var action = actions[^1];
|
||
sb.AppendLine("CurrentAction:");
|
||
if (action?.ActionId != null)
|
||
sb.AppendLine(action.ActionId.GetStringLog());
|
||
if (action?.Param != null)
|
||
{
|
||
sb.AppendLine("CurrentParam:");
|
||
sb.AppendLine(action.Param.GetStringLog());
|
||
}
|
||
}
|
||
|
||
LogSystem.LogError(sb.ToString());
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
LogSystem.LogWarning($"KomeijiRiderTransBoatOnLand diagnostic failed: {e}");
|
||
}
|
||
}
|
||
|
||
private static string FormatUnitFullType(UnitFullType fullType)
|
||
{
|
||
return $"{fullType.UnitType}/{fullType.GiantType}/{fullType.UnitLevel}";
|
||
}
|
||
}
|
||
}
|