修复市政卡联机bug

This commit is contained in:
kawagiri 2026-04-11 15:33:43 +08:00
parent ba8c3e351d
commit 44328d9fc9
7 changed files with 107 additions and 50 deletions

View File

@ -236,6 +236,7 @@ MonoBehaviour:
TechType: 0
PlayerActionType: 0
AIParamType: 0
CultureCardType: 0
- CardType: 4
CultureType: 1
IsActive: 1
@ -321,6 +322,7 @@ MonoBehaviour:
TechType: 0
PlayerActionType: 0
AIParamType: 0
CultureCardType: 0
- CardType: 5
CultureType: 1
IsActive: 1
@ -406,6 +408,7 @@ MonoBehaviour:
TechType: 0
PlayerActionType: 0
AIParamType: 0
CultureCardType: 0
- CardType: 6
CultureType: 1
IsActive: 1
@ -477,7 +480,7 @@ MonoBehaviour:
EnableActions:
- ActionType: 1
WonderType: 0
ResourceType: 22
ResourceType: 28
FeatureType: 0
TerrainType: 0
UnitType: 0
@ -491,6 +494,7 @@ MonoBehaviour:
TechType: 0
PlayerActionType: 0
AIParamType: 0
CultureCardType: 0
- CardType: 7
CultureType: 1
IsActive: 1
@ -576,6 +580,7 @@ MonoBehaviour:
TechType: 0
PlayerActionType: 0
AIParamType: 0
CultureCardType: 0
- CardType: 8
CultureType: 3
IsActive: 1
@ -678,6 +683,7 @@ MonoBehaviour:
TechType: 0
PlayerActionType: 0
AIParamType: 0
CultureCardType: 0
- ActionType: 4
WonderType: 0
ResourceType: 0
@ -694,6 +700,7 @@ MonoBehaviour:
TechType: 0
PlayerActionType: 0
AIParamType: 0
CultureCardType: 0
- ActionType: 4
WonderType: 0
ResourceType: 0
@ -710,6 +717,7 @@ MonoBehaviour:
TechType: 0
PlayerActionType: 0
AIParamType: 0
CultureCardType: 0
- ActionType: 4
WonderType: 0
ResourceType: 0
@ -726,6 +734,7 @@ MonoBehaviour:
TechType: 0
PlayerActionType: 0
AIParamType: 0
CultureCardType: 0
- CardType: 10
CultureType: 3
IsActive: 1

View File

@ -200,6 +200,7 @@ MonoBehaviour:
UnitInfoName: {fileID: 5648530559652216814}
InfoGroup: {fileID: 125257996137627304}
HideAround: {fileID: 6396779587332902180}
DamagePreviewPanel: {fileID: 4944763982188101153}
DamagePreviewText: {fileID: 4691325173353209094}
StatusAreaContainer: {fileID: 4128611394455241087}
StatusIconPrefab: {fileID: 3019578617163145481, guid: e56989dd6da795d47b8a070582368a93, type: 3}
@ -801,7 +802,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &6365787046893573031
RectTransform:
m_ObjectHideFlags: 0
@ -819,8 +820,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 1.9276, y: 0.31589997}
m_SizeDelta: {x: 2.0275, y: 1.1787}
m_AnchoredPosition: {x: 1.95, y: 0.6}
m_SizeDelta: {x: 1.9304, y: 1.7799}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &471150048766387148
CanvasRenderer:
@ -1656,8 +1657,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -0.000025272, y: 0.00000077486}
m_SizeDelta: {x: 2.0275, y: 1.1787}
m_AnchoredPosition: {x: -0.024294, y: -0.0000028908}
m_SizeDelta: {x: 1.979, y: 1.7799}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7779047267693778439
CanvasRenderer:
@ -1696,8 +1697,8 @@ MonoBehaviour:
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4278190335
m_fontColor: {r: 1, g: 0, b: 0, a: 1}
rgba: 4278222032
m_fontColor: {r: 0.81761, g: 0.48681653, b: 0, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
@ -1714,12 +1715,12 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 1
m_fontSize: 1.2
m_fontSizeBase: 1
m_fontWeight: 400
m_enableAutoSizing: 1
m_fontSizeMin: 0.2
m_fontSizeMax: 1
m_fontSizeMax: 1.2
m_fontStyle: 0
m_HorizontalAlignment: 2
m_VerticalAlignment: 512

View File

@ -500,7 +500,7 @@ namespace Logic.Action
commonActionId = new CommonActionId { ActionType = CommonActionType.PlayerSurrender };
ActionLogicDict[commonActionId] = new SurrenderAction(commonActionId);
for (int i = (int)CultureCardType.SecondHero; i < (int)AIParamControlType.Max; i++)
for (int i = (int)CultureCardType.SecondHero; i < (int)CultureCardType.Max; i++)
{
commonActionId = new CommonActionId
{

View File

@ -6,6 +6,8 @@ using UnityEngine.SceneManagement;
using RuntimeData;
using Logic;
using Logic.Action;
using Logic.AI;
using Logic.CrashSight;
using TH1_Anim;
using TH1_Core.Managers;
@ -331,17 +333,41 @@ namespace TH1Renderer
// 必须在视野内
if (!selfPlayer.Sight.CheckIsInSight(hoverGrid.Id)) return;
// 计算预测伤害
int myDmg = Table.Instance.CalcDamage(_mapData, SelectUnitData, targetUnit);
int counterDmg = Table.Instance.CalcCounterDamage(_mapData, SelectUnitData, targetUnit);
bool canCounter = Main.UnitLogic.CanCounter(_mapData, SelectUnitData, targetUnit);
// 通过DeepCopy map + 模拟真实攻击来获取准确伤害预测
int attackerHpBefore = SelectUnitData.Health;
int defenderHpBefore = targetUnit.Health;
// 显示:敌方头上显示我方对其伤害(红色),我方头上显示反击伤害(橙色)
if (ROUnitMap.TryGetValue(targetUnit.Id, out var targetRenderer))
targetRenderer.ShowDamagePreview(myDmg, Color.red);
AIActionScoreCalculator.RefreshCalMap(_mapData);
var calMap = AIActionScoreCalculator.CalMap;
calMap.DeepCopy(_mapData);
if (canCounter && ROUnitMap.TryGetValue(SelectUnitData.Id, out var selfRenderer))
selfRenderer.ShowDamagePreview(counterDmg, new Color(1f, 0.5f, 0f));
if (!calMap.GetPlayerDataByUnitId(SelectUnitData.Id, out var calPlayer)) return;
if (!calMap.UnitMap.GetUnitDataByUnitId(SelectUnitData.Id, out var calAttacker)) return;
if (!calMap.UnitMap.GetUnitDataByUnitId(targetUnit.Id, out var calDefender)) return;
var attackId = new CommonActionId { ActionType = CommonActionType.UnitAttack };
var attackAction = new UnitAttackAction(attackId);
var param = new CommonActionParams(
mapData: calMap,
playerData: calPlayer,
unitData: calAttacker,
targetUnit: calDefender,
mainObjectType: MainObjectType.Unit
);
param.OnParamChanged();
attackAction.CompleteExecute(param);
// 从模拟结果读取双方实际伤害
int dmgToTarget = defenderHpBefore - (calDefender.IsAlive() ? calDefender.Health : 0);
int dmgToSelf = attackerHpBefore - (calAttacker.IsAlive() ? calAttacker.Health : 0);
// 显示:敌方头上显示我方对其伤害(红色)
if (dmgToTarget > 0 && ROUnitMap.TryGetValue(targetUnit.Id, out var targetRenderer))
targetRenderer.ShowDamagePreview(dmgToTarget, Color.red);
// 己方头上显示反击伤害(橙色)
if (dmgToSelf > 0 && ROUnitMap.TryGetValue(SelectUnitData.Id, out var selfRenderer))
selfRenderer.ShowDamagePreview(dmgToSelf, new Color(1f, 0.5f, 0f));
_dmgPreviewShowing = true;
_dmgPreviewSelfUnitId = SelectUnitData.Id;

View File

@ -26,7 +26,9 @@ public class UnitMono : MonoBehaviour
public Image HideAround;
[Header("Damage Preview")]
[Tooltip("伤害预测文本")]
[Tooltip("伤害预测面板(含背景Image)")]
public GameObject DamagePreviewPanel;
[Tooltip("伤害预测文本(挂在Panel下)")]
public TextMeshProUGUI DamagePreviewText;
[Header("Status Area")]

View File

@ -483,16 +483,16 @@ namespace TH1_Renderer
public void ShowDamagePreview(int damage, Color color)
{
if (_unitMono?.DamagePreviewText == null) return;
_unitMono.DamagePreviewText.gameObject.SetActive(true);
if (_unitMono?.DamagePreviewPanel == null || _unitMono?.DamagePreviewText == null) return;
_unitMono.DamagePreviewPanel.SetActive(true);
_unitMono.DamagePreviewText.text = "-" + damage;
_unitMono.DamagePreviewText.color = color;
}
public void HideDamagePreview()
{
if (_unitMono?.DamagePreviewText == null) return;
_unitMono.DamagePreviewText.gameObject.SetActive(false);
if (_unitMono?.DamagePreviewPanel == null) return;
_unitMono.DamagePreviewPanel.SetActive(false);
}
#endregion