优化武器商品描述文本、修复敌人子弹无法击中玩家的bug

This commit is contained in:
2026-09-26 22:55:52 +08:00
parent 051c075183
commit 91b8e177c5
5 changed files with 75 additions and 79 deletions
@@ -3,6 +3,7 @@ using SepCore.CustomUtility;
using SepCore.Definition; using SepCore.Definition;
using SepCore.Entity; using SepCore.Entity;
using UnityEngine; using UnityEngine;
using UnityGameFramework.Runtime;
namespace SepCore.UI namespace SepCore.UI
{ {
@@ -12,12 +13,14 @@ namespace SepCore.UI
public Rarity Rarity; public Rarity Rarity;
public Sprite Icon; public Sprite Icon;
public ItemType ItemType; public ItemType ItemType;
public string TypeName;
public string Description; public string Description;
public int Price; public int Price;
public GoodsItemContext() public GoodsItemContext()
{ {
Name = string.Empty; Name = string.Empty;
TypeName = string.Empty;
Description = string.Empty; Description = string.Empty;
Rarity = Rarity.White; Rarity = Rarity.White;
Price = 0; Price = 0;
@@ -33,22 +36,49 @@ namespace SepCore.UI
if (ItemType == ItemType.Weapon) if (ItemType == ItemType.Weapon)
{ {
DamageType damageType;
if (rawData.DataRow is WeaponConfig weaponConfig) if (rawData.DataRow is WeaponConfig weaponConfig)
{ {
Name = weaponConfig.WeaponType.ToString(); Name = weaponConfig.WeaponType.ToString();
Description = ItemDescUtility.CreateWeaponDescription(weaponConfig); Description = ItemDescUtility.CreateWeaponDescription(weaponConfig);
damageType = weaponConfig.DamageType;
} }
else if (rawData.DataRow is WeaponData weaponData) else if (rawData.DataRow is WeaponData weaponData)
{ {
Name = weaponData.Title; Name = weaponData.Title;
Description = ItemDescUtility.CreateWeaponDescription(weaponData); Description = ItemDescUtility.CreateWeaponDescription(weaponData);
damageType = weaponData.DamageType;
}
else
{
Log.Error("Weapon data row is invalid.");
return;
}
TypeName = damageType switch
{
DamageType.Melee => "近战武器",
DamageType.Ranged => "远程武器",
DamageType.Element => "元素武器",
_ => "武器"
};
}
else if (ItemType == ItemType.Prop)
{
if (rawData.DataRow is PropConfig prop)
{
Name = prop.Name;
Description = ItemDescUtility.CreatePropDescription(prop.StatModifierConfigs);
TypeName = "道具";
}
else
{
Log.Error("Prop data row is invalid.");
} }
} }
else else
{ {
var prop = (PropConfig)rawData.DataRow; Log.Error("Unsupported goods item type '{0}'.", ItemType);
Name = prop.Name;
Description = ItemDescUtility.CreatePropDescription(prop.StatModifierConfigs);
} }
} }
} }
@@ -29,13 +29,7 @@ namespace SepCore.UI
_iconArea.OnInit(data.Icon, data.Rarity); _iconArea.OnInit(data.Icon, data.Rarity);
_titleText.text = data.Name; _titleText.text = data.Name;
_typeText.text = data.ItemType switch _typeText.text = data.TypeName;
{
ItemType.None => "error",
ItemType.Weapon => "武器",
ItemType.Prop => "道具",
_ => throw new ArgumentOutOfRangeException()
};
_descriptionText.text = data.Description; _descriptionText.text = data.Description;
_costText.text = $"{data.Price} <sprite name=\"coin\" index=0>"; _costText.text = $"{data.Price} <sprite name=\"coin\" index=0>";
} }
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using SepCore.Definition; using SepCore.Definition;
@@ -9,18 +8,9 @@ namespace SepCore.CustomUtility
{ {
public static class ItemDescUtility public static class ItemDescUtility
{ {
private static readonly Dictionary<ParamType, string> _paramTypeNames = new()
{
{ ParamType.HitRadius, "攻击半宽" },
{ ParamType.SectorAngle, "攻击角度" },
{ ParamType.HitHalfWidth, "横向半宽" },
{ ParamType.PierceLength, "前戳距离" },
{ ParamType.HitHeight, "判定高度" },
};
private static readonly string[] _statTypeNames = private static readonly string[] _statTypeNames =
{ {
"无效", // None = 0 "无效", // None = 0
"最大生命", // MaxHp = 1 "最大生命", // MaxHp = 1
"生命恢复", // HpRegen = 2 "生命恢复", // HpRegen = 2
"生命窃取", // LifeSteal = 3 "生命窃取", // LifeSteal = 3
@@ -35,8 +25,8 @@ namespace SepCore.CustomUtility
"护甲", // Armor = 12 "护甲", // Armor = 12
"闪避率", // Dodge = 13 "闪避率", // Dodge = 13
"移动速度", // MoveSpeed = 14 "移动速度", // MoveSpeed = 14
"收获", // Harvesting = 15 "收获", // Harvesting = 15
"幸运" // Luck = 16 "幸运" // Luck = 16
}; };
public static string Describe(StatModifierConfig statModifierConfig) public static string Describe(StatModifierConfig statModifierConfig)
@@ -110,80 +100,53 @@ namespace SepCore.CustomUtility
public static string CreateWeaponDescription(WeaponConfig weaponConfig) public static string CreateWeaponDescription(WeaponConfig weaponConfig)
{ {
if (weaponConfig == null)
{
return null;
}
return CreateWeaponDescription(weaponConfig.Attack, weaponConfig.Cooldown, return CreateWeaponDescription(weaponConfig.Attack, weaponConfig.Cooldown,
weaponConfig.AttackRange, weaponConfig.StatModifierConfigs, weaponConfig.Parameters); weaponConfig.AttackRange, weaponConfig.StatModifierConfigs);
} }
public static string CreateWeaponDescription(WeaponBase weapon)
{
if (weapon == null || weapon.WeaponData == null)
{
return null;
}
return CreateWeaponDescription(weapon.WeaponData);
}
public static string CreateWeaponDescription(WeaponData weaponData) public static string CreateWeaponDescription(WeaponData weaponData)
{ {
if (weaponData == null) if (weaponData == null)
{ {
return null; Log.Error("Weapon data is invalid.");
return string.Empty;
} }
return CreateWeaponDescription(weaponData.Attack, weaponData.Cooldown, return CreateWeaponDescription(weaponData.Attack, weaponData.Cooldown,
weaponData.AttackRange, weaponData.Modifiers, weaponData.Parameters); weaponData.AttackRange, weaponData.Modifiers);
} }
public static string CreatePropDescription(PropItem prop) public static string CreatePropDescription(PropItem prop)
{ {
if (prop == null) if (prop == null)
{ {
return null; Log.Error("Prop is invalid.");
return string.Empty;
} }
return CreatePropDescription(prop.Modifiers); return CreatePropDescription(prop.Modifiers);
} }
private static string CreateWeaponDescription(int attack, float cooldown, float attackRange, public static string CreateWeaponDescription(int attack, float cooldown, float attackRange,
IEnumerable<StatModifierConfig> modifiers, IReadOnlyDictionary<ParamType, float> parameters) IEnumerable<StatModifierConfig> modifiers = null)
{ {
float baseCrit = GameEntry.Luban.Global.WeaponBaseCrit;
float critMult = GameEntry.Luban.Global.CritMultiplier;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.AppendLine($"攻击: {attack}"); sb.AppendLine($"伤害: {attack}");
sb.AppendLine($"冷却: {cooldown}"); sb.AppendLine($"暴击: x{critMult:0.##} ({baseCrit * 100:0.##}%)");
sb.AppendLine($"范围: {attackRange}"); sb.AppendLine($"冷却: {cooldown:0.##}s");
sb.AppendLine($"范围: {attackRange:0.##}");
string modifiersDesc = CreatePropDescription(modifiers); string modifiersDesc = CreatePropDescription(modifiers);
if (!string.IsNullOrEmpty(modifiersDesc)) if (!string.IsNullOrEmpty(modifiersDesc))
{ {
sb.Append(modifiersDesc); sb.AppendLine();
sb.Append(modifiersDesc.TrimEnd());
} }
if (parameters == null || parameters.Count == 0) return sb.ToString().TrimEnd();
{
return sb.ToString();
}
foreach (var kvp in parameters)
{
if (!_paramTypeNames.TryGetValue(kvp.Key, out string paramName))
{
paramName = kvp.Key.ToString();
}
string valStr = kvp.Key == ParamType.SectorAngle
? kvp.Value.ToString()
: kvp.Value.ToString("0.##");
sb.AppendLine($"{paramName}: {valStr}");
}
return sb.ToString();
} }
} }
} }
@@ -115,10 +115,7 @@ namespace SepCore.Simulation
query.SourceOwnerEntityId != PlayerTargetEntityId) query.SourceOwnerEntityId != PlayerTargetEntityId)
{ {
float3 playerPosition = PlayerPosition; float3 playerPosition = PlayerPosition;
if (query.SourceType == SimulationCollision.SourceTypeArea) playerPosition.y = query.Position.y;
{
playerPosition.y = query.Position.y;
}
float3 playerDelta = playerPosition - query.Position; float3 playerDelta = playerPosition - query.Position;
float playerSqrDistance = math.lengthsq(playerDelta); float playerSqrDistance = math.lengthsq(playerDelta);
+18 -6
View File
@@ -3,33 +3,45 @@
--- !u!159 &1 --- !u!159 &1
EditorSettings: EditorSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 9 serializedVersion: 12
m_ExternalVersionControlSupport: Visible Meta Files
m_SerializationMode: 2 m_SerializationMode: 2
m_LineEndingsForNewScripts: 2 m_LineEndingsForNewScripts: 2
m_DefaultBehaviorMode: 0 m_DefaultBehaviorMode: 0
m_PrefabRegularEnvironment: {fileID: 0} m_PrefabRegularEnvironment: {fileID: 0}
m_PrefabUIEnvironment: {fileID: 0} m_PrefabUIEnvironment: {fileID: 0}
m_SpritePackerMode: 0 m_SpritePackerMode: 0
m_SpritePackerCacheSize: 10
m_SpritePackerPaddingPower: 1 m_SpritePackerPaddingPower: 1
m_Bc7TextureCompressor: 0
m_EtcTextureCompressorBehavior: 1 m_EtcTextureCompressorBehavior: 1
m_EtcTextureFastCompressor: 1 m_EtcTextureFastCompressor: 1
m_EtcTextureNormalCompressor: 2 m_EtcTextureNormalCompressor: 2
m_EtcTextureBestCompressor: 4 m_EtcTextureBestCompressor: 4
m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;asmref;rsp m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;asmref;rsp
m_ProjectGenerationRootNamespace: m_ProjectGenerationRootNamespace:
m_CollabEditorSettings:
inProgressEnabled: 1
m_EnableTextureStreamingInEditMode: 1 m_EnableTextureStreamingInEditMode: 1
m_EnableTextureStreamingInPlayMode: 1 m_EnableTextureStreamingInPlayMode: 1
m_EnableEditorAsyncCPUTextureLoading: 0
m_AsyncShaderCompilation: 1 m_AsyncShaderCompilation: 1
m_EnterPlayModeOptionsEnabled: 0 m_PrefabModeAllowAutoSave: 1
m_EnterPlayModeOptionsEnabled: 1
m_EnterPlayModeOptions: 3 m_EnterPlayModeOptions: 3
m_ShowLightmapResolutionOverlay: 1 m_GameObjectNamingDigits: 1
m_GameObjectNamingScheme: 0
m_AssetNamingUsesSpace: 1
m_InspectorUseIMGUIDefaultInspector: 0
m_UseLegacyProbeSampleCount: 0 m_UseLegacyProbeSampleCount: 0
m_SerializeInlineMappingsOnOneLine: 0
m_DisableCookiesInLightmapper: 1
m_AssetPipelineMode: 1 m_AssetPipelineMode: 1
m_RefreshImportMode: 0
m_CacheServerMode: 0 m_CacheServerMode: 0
m_CacheServerEndpoint: m_CacheServerEndpoint:
m_CacheServerNamespacePrefix: default m_CacheServerNamespacePrefix: default
m_CacheServerEnableDownload: 1 m_CacheServerEnableDownload: 1
m_CacheServerEnableUpload: 1 m_CacheServerEnableUpload: 1
m_CacheServerEnableAuth: 0
m_CacheServerEnableTls: 0
m_CacheServerValidationMode: 2
m_CacheServerDownloadBatchSize: 128
m_EnableEnlightenBakedGI: 0