(client) feat:实现健康状态定义,实现事件定义

This commit is contained in:
m0_75251201
2025-08-27 22:39:34 +08:00
parent f4ce4fcf1f
commit 9713ad9129
22 changed files with 313 additions and 32 deletions

View File

@ -27,7 +27,7 @@ Transform:
m_GameObject: {fileID: 5021031438404678310}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -6.6943, y: -0.3652, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []

View File

@ -29,7 +29,7 @@ Transform:
m_GameObject: {fileID: 2412502657045938467}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -13.67, y: -5.09, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:

View File

@ -37,7 +37,7 @@ 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: -160.92151, y: -93.26492}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &6659858081700418582

View File

@ -124,6 +124,7 @@ Transform:
- {fileID: 5549544358816209289}
- {fileID: 1697214530303839877}
- {fileID: 1404278780950315184}
- {fileID: 4504455988891581487}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3332598847335032684
@ -364,3 +365,65 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 605f185650fe46d89a6e0d60fb8fb11c, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &5211884413447499418
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 697189026367054479}
m_Modifications:
- target: {fileID: 5021031438404678310, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
propertyPath: m_Name
value: WeaponTexture
objectReference: {fileID: 0}
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
--- !u!4 &4504455988891581487 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
m_PrefabInstance: {fileID: 5211884413447499418}
m_PrefabAsset: {fileID: 0}

View File

@ -27,7 +27,7 @@ Transform:
m_GameObject: {fileID: 5309816858037840717}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -5.781, y: -0.39, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []

View File

@ -37,7 +37,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 342, y: -198}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.1, y: 0.9}
--- !u!222 &6098472552964198111

View File

@ -35,7 +35,7 @@ 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: -1.0921326, y: -54.256577}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 200, y: 14.01}
m_Pivot: {x: 0.5, y: 1}
--- !u!222 &6803973761688315705

View File

@ -0,0 +1,124 @@
using Entity;
namespace Data
{
public class AttributesOffsetDef : Define
{
// ======================================================================
// 绝对值偏移 (Added/Subtracted directly)
// ======================================================================
public float healthOffset = 0f;
public float moveSpeedOffset = 0f;
public float attackOffset = 0f;
public float defenseOffset = 0f;
public float attackSpeedOffset = 0f;
public float attackRangeOffset = 0f;
public float attackTargetCountOffset = 0f;
// ======================================================================
// 百分比偏移 (Multiplied as a factor, e.g., 0.1 for +10%)
// ======================================================================
// 注意:百分比偏移通常是乘法因子。
// 0f 表示没有百分比变化0.1f 表示增加10%-0.1f 表示减少10%。
// 应用时: baseValue * (1 + percentageOffset)
// 或者对于更直接的乘法,可以直接用 multiplyRatio例如 1.1 表示增加 10%。
public float healthPercentOffset = 0f; // 例如 0.1 表示 +10%
public float moveSpeedPercentOffset = 0f;
public float attackPercentOffset = 0f;
public float defensePercentOffset = 0f;
public float attackSpeedPercentOffset = 0f;
public float attackRangePercentOffset = 0f;
public float attackTargetCountPercentOffset = 0f;
// ======================================================================
// 数组偏移 / 集合偏移 (更复杂的情况,如果原始属性是数组/集合)
// 因为你的Attributes类目前都是单一值所以这里先按单一值处理。
// 如果 future Attributes.attackTargets 变成 List<string> 或者 int[]
// 这里就需要 List<string> addedAttackTargets 或 List<int> addedAttackTargetCounts
// 来表示要添加/移除的元素。
// 示例:如果将来有一个属性是效果列表,这里可以定义要添加的效果
// public List<string> addedEffects = new List<string>();
// public List<string> removedEffects = new List<string>();
// 如果 `attackTargetCount` 实际代表可以攻击的目标ID数组那么
// public List<int> addedAttackTargets = new List<int>();
// public List<int> removedAttackTargets = new List<int>();
// 注意:对于 `attackTargetCount` 来说,它本身是一个 int
// 上面的 `attackTargetCountOffset` 已经足够处理“增加攻击目标数量”的需求。
// "数组偏移"通常指的是当原始属性本身是一个集合时,你想要修改这个集合的元素。
// 如果 `Attributes` 类保持其当前形式 (都是单一数值),那么不需要专门的数组偏移。
// ======================================================================
// 构造函数 (可选,用于方便初始化)
// ======================================================================
public AttributesOffsetDef()
{
}
// 可以添加带参数的构造函数,方便快速设置
public AttributesOffsetDef(float healthAbs = 0f, float moveSpeedAbs = 0f, float attackAbs = 0f,
float defenseAbs = 0f, float attackSpeedAbs = 0f, float attackRangeAbs = 0f,
float attackTargetCountAbs = 0f,
float healthPct = 0f, float moveSpeedPct = 0f, float attackPct = 0f,
float defensePct = 0f, float attackSpeedPct = 0f, float attackRangePct = 0f,
float attackTargetCountPct = 0f)
{
healthOffset = healthAbs;
moveSpeedOffset = moveSpeedAbs;
attackOffset = attackAbs;
defenseOffset = defenseAbs;
attackSpeedOffset = attackSpeedAbs;
attackRangeOffset = attackRangeAbs;
attackTargetCountOffset = attackTargetCountAbs;
healthPercentOffset = healthPct;
moveSpeedPercentOffset = moveSpeedPct;
attackPercentOffset = attackPct;
defensePercentOffset = defensePct;
attackSpeedPercentOffset = attackSpeedPct;
attackRangePercentOffset = attackRangePct;
attackTargetCountPercentOffset = attackTargetCountPct;
}
// ======================================================================
// 应用偏移的方法
// ======================================================================
/// <summary>
/// 将此偏移应用到给定的Attributes实例上。
/// </summary>
/// <param name="baseAttributes">要应用偏移的基础Attributes。</param>
/// <returns>应用偏移后的新Attributes实例。</returns>
public Attributes ApplyTo(Attributes baseAttributes)
{
// 创建一个新的Attributes实例以避免修改原始实例
// 或者如果需要直接修改,可以返回 void
Attributes modifiedAttributes = new Attributes
{
health = baseAttributes.health,
moveSpeed = baseAttributes.moveSpeed,
attack = baseAttributes.attack,
defense = baseAttributes.defense,
attackSpeed = baseAttributes.attackSpeed,
attackRange = baseAttributes.attackRange,
attackTargetCount = baseAttributes.attackTargetCount
};
// 首先应用百分比偏移
modifiedAttributes.health = (int)(modifiedAttributes.health * (1f + healthPercentOffset));
modifiedAttributes.moveSpeed *= (1f + moveSpeedPercentOffset);
modifiedAttributes.attack = (int)(modifiedAttributes.attack * (1f + attackPercentOffset));
modifiedAttributes.defense = (int)(modifiedAttributes.defense * (1f + defensePercentOffset));
modifiedAttributes.attackSpeed = (int)(modifiedAttributes.attackSpeed * (1f + attackSpeedPercentOffset));
modifiedAttributes.attackRange = (int)(modifiedAttributes.attackRange * (1f + attackRangePercentOffset));
modifiedAttributes.attackTargetCount =
(int)(modifiedAttributes.attackTargetCount * (1f + attackTargetCountPercentOffset));
// 然后应用绝对值偏移
modifiedAttributes.health += (int)healthOffset;
modifiedAttributes.moveSpeed += moveSpeedOffset;
modifiedAttributes.attack += (int)attackOffset;
modifiedAttributes.defense += (int)defenseOffset;
modifiedAttributes.attackSpeed += (int)attackSpeedOffset;
modifiedAttributes.attackRange += (int)attackRangeOffset;
modifiedAttributes.attackTargetCount += (int)attackTargetCountOffset;
return modifiedAttributes;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fb6190c213d44e04946784c3a5063e83
timeCreated: 1756302637

View File

@ -231,7 +231,7 @@ namespace Data
public List<DrawNodeDef> nodes = new();
public string nodeName;
public Vector2 position = new(0, 0);
public float FPS = 0.5f;
public float FPS = 1f;
public override bool Init(XElement xmlDef)
{

View File

@ -0,0 +1,9 @@
namespace Data
{
public class FactionRequirementDef:Define
{
public string factionDefName; // 目标的派系DefName
public bool forAllPawnsInFaction = false; // 是否为该派系的所有Pawns添加Hediff
public int specificPawnCount = 1; // 如果不是所有Pawns指定数量
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d495178bf0c943fe9da8009592e20400
timeCreated: 1756305417

View File

@ -0,0 +1,17 @@
using System;
using System.Xml.Linq;
namespace Data
{
public class HediffCompDef:Define
{
public Type compClass;
public override bool Init(XElement xmlDef)
{
base.Init(xmlDef);
var name = xmlDef.Attribute("class")?.Value??"";
compClass=Type.GetType(name);
return true;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 92779af4b74648a99930c10376760af6
timeCreated: 1756303386

View File

@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace Data
{
public class HediffDef:Define
{
// 默认安装的身体部位 (例如 "Lung", "Heart")
public string defaultInstallPart = null;
// 是否阻止肺部疾病 (例如肺腐烂)
public bool preventsLungRot = false;
// Hediff的发展阶段列表
public List<HediffStageDef> stages = new List<HediffStageDef>();
// 附加的组件列表
public List<HediffCompDef> comps = new List<HediffCompDef>();
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a4311115be2f4da8a5a27e1bb298928e
timeCreated: 1756303757

View File

@ -0,0 +1,8 @@
namespace Data
{
public class HediffStageDef:Define
{
public float start;
public AffiliationDef attributesOffset = new();
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 59d3b562e68e40fdaa65e5e6431c58e0
timeCreated: 1756304101

View File

@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace Data
{
public class LocationRangeDef:Define
{
public float minRadius = 0f; // 最小距离(以格数单位)
public float maxRadius = 10f; // 最大距离(以格数单位)
public int width = 5; // 宽度(以格数单位),指定一个方形区域
public int height = 5; // 高度(以格数单位)
public bool allowNearWalls = true; // 是否允许靠近墙壁生成
public bool allowSpawnOnPawn = false; // 是否允许直接生成在角色身上
// 可以添加更多约束,如:
public List<string> allowedTerrainTags; // 允许生成的地形标签
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9b4cf168bf1e41d4a63e78cb734453bd
timeCreated: 1756305435

View File

@ -25,6 +25,7 @@ namespace Entity
var maxIndex = Inventory != null && Inventory.Capacity > 0 ? Inventory.Capacity - 1 : 0;
var clampedValue = Mathf.Clamp(value, 0, maxIndex);
_currentSelected = clampedValue;
InitWeaponAnimator();
}
}
@ -68,29 +69,6 @@ namespace Entity
return remainingQuantity;
}
// public override void TryAttack()
// {
// if (IsAttacking)
// return;
// if (!DefineManager.Instance.defines.TryGetValue(nameof(BulletDef), out var def))
// return;
// // 修正First() 可能会在一个空的 Values 集合上抛出异常。
// // 更好的做法是使用 TryGetValue 或 FirstOrDefault 并检查结果。
// // 这里假设至少有一个 BulletDef 存在,如果不是,需要更复杂的错误处理。
// var bulletDefEntry = def.Values.FirstOrDefault();
// if (bulletDefEntry == null)
// {
// Debug.LogError("No BulletDef found in DefineManager. Cannot attack.");
// return;
// }
//
// var bulletDef = (BulletDef)bulletDefEntry;
//
// Vector3 dir = MousePosition.GetWorldPosition();
// EntityManage.Instance.GenerateBulletEntity(Program.Instance.FocusedDimensionId, bulletDef, Position,
// dir - Position, this);
// }
public override WeaponResource GetCurrentWeapon()
{
var currentSelectItem = Inventory.GetSlot(CurrentSelected);

View File

@ -32,6 +32,12 @@ namespace Entity
public EntityPrefab entityPrefab;
public EntityDef entityDef;
/// <summary>
/// 手上拿着显示的贴图
/// </summary>
public GameObject weaponAnimator;
public ITick[] weaponAnimatorNodeList;
/// <summary>
/// 人工智能行为树,定义实体的行为逻辑。
@ -183,13 +189,32 @@ namespace Entity
this.entityDef = entityDef;
HideHealthBar();
InitWeaponAnimator();
}
protected virtual void InitWeaponAnimator()
{
for (var i = 0; i < weaponAnimator.transform.childCount; i++)
{
Destroy(weaponAnimator.transform.GetChild(i).gameObject);
weaponAnimatorNodeList = null;
}
var weapon = GetCurrentWeapon();
if (weapon == null)
{
weaponAnimator.SetActive(false);
return;
}
var weaponAnimation = weapon.InstantiateAttackAnimation(weaponAnimator.transform);
weaponAnimatorNodeList = weaponAnimation.animationComponents;
}
/// <summary>
/// 初始化实体的身体部分,包括不同朝向下的绘图节点。
/// </summary>
/// <param name="drawingOrder">绘制顺序定义。</param>
public virtual void InitBody(DrawingOrderDef drawingOrder)
protected virtual void InitBody(DrawingOrderDef drawingOrder)
{
// 预缓存枚举值(避免每次循环重复调用 Enum.GetValues
var states = Enum.GetValues(typeof(EntityState)).Cast<EntityState>().ToArray();
@ -295,7 +320,7 @@ namespace Entity
/// <param name="drawNode">绘图节点定义。</param>
/// <param name="parent">父节点对象。</param>
/// <returns>创建的GameObject如果失败则返回null</returns>
public virtual GameObject InitBodyPart(DrawNodeDef drawNode, GameObject parent)
protected virtual GameObject InitBodyPart(DrawNodeDef drawNode, GameObject parent)
{
try
{
@ -470,6 +495,13 @@ namespace Entity
}
}
if (weaponAnimatorNodeList != null)
{
foreach (var tick in weaponAnimatorNodeList)
{
tick.Tick();
}
}
if (IsShowingHealthBarUI)
{
_hitBarUIShowTimer -= Time.deltaTime;