替换玩家模型素材,添加 ChildrenMap 配置挂点
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using NUnit.Framework;
|
||||
using SepCore.Components;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace VampireLike.Tests.Gameplay.EditMode
|
||||
{
|
||||
[TestFixture]
|
||||
public class ChildrenMapTests
|
||||
{
|
||||
private GameObject _rootObject;
|
||||
private ChildrenMap _childrenMap;
|
||||
private GameObject _childA;
|
||||
private GameObject _childB;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
GameFramework.GameFrameworkLog.SetLogHelper(new UnityGameFramework.Runtime.DefaultLogHelper());
|
||||
|
||||
_rootObject = new GameObject("RootTestObject");
|
||||
_childrenMap = _rootObject.AddComponent<ChildrenMap>();
|
||||
|
||||
_childA = new GameObject("ChildA");
|
||||
_childA.transform.SetParent(_rootObject.transform);
|
||||
|
||||
_childB = new GameObject("ChildB");
|
||||
_childB.transform.SetParent(_rootObject.transform);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
if (_rootObject != null)
|
||||
{
|
||||
Object.DestroyImmediate(_rootObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetEntries(List<ChildrenMap.Entry> entries)
|
||||
{
|
||||
FieldInfo field = typeof(ChildrenMap).GetField("_entries", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
Assert.IsNotNull(field);
|
||||
field.SetValue(_childrenMap, entries);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_WithValidKey_ReturnsGameObject()
|
||||
{
|
||||
SetEntries(new List<ChildrenMap.Entry>
|
||||
{
|
||||
new ChildrenMap.Entry("Socket_A", _childA),
|
||||
new ChildrenMap.Entry("Socket_B", _childB)
|
||||
});
|
||||
|
||||
GameObject resultA = _childrenMap.Get("Socket_A");
|
||||
GameObject resultB = _childrenMap.Get("Socket_B");
|
||||
|
||||
Assert.AreEqual(_childA, resultA);
|
||||
Assert.AreEqual(_childB, resultB);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_WithNonExistingKey_ReturnsNull()
|
||||
{
|
||||
SetEntries(new List<ChildrenMap.Entry>
|
||||
{
|
||||
new ChildrenMap.Entry("Socket_A", _childA)
|
||||
});
|
||||
|
||||
LogAssert.Expect(LogType.Error, new System.Text.RegularExpressions.Regex("Key 'NonExisting' not found"));
|
||||
GameObject result = _childrenMap.Get("NonExisting");
|
||||
|
||||
Assert.IsNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_WithNullOrEmptyKey_ReturnsNull()
|
||||
{
|
||||
SetEntries(new List<ChildrenMap.Entry>
|
||||
{
|
||||
new ChildrenMap.Entry("Socket_A", _childA)
|
||||
});
|
||||
|
||||
LogAssert.Expect(LogType.Error, new System.Text.RegularExpressions.Regex("Key is null or empty"));
|
||||
GameObject resultNull = _childrenMap.Get(null);
|
||||
Assert.IsNull(resultNull);
|
||||
|
||||
LogAssert.Expect(LogType.Error, new System.Text.RegularExpressions.Regex("Key is null or empty"));
|
||||
GameObject resultEmpty = _childrenMap.Get(string.Empty);
|
||||
Assert.IsNull(resultEmpty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_WithConfiguredNullTarget_ReturnsNull()
|
||||
{
|
||||
SetEntries(new List<ChildrenMap.Entry>
|
||||
{
|
||||
new ChildrenMap.Entry("NullTargetKey", null)
|
||||
});
|
||||
|
||||
LogAssert.Expect(LogType.Error, new System.Text.RegularExpressions.Regex("Target GameObject for key 'NullTargetKey' is null"));
|
||||
GameObject result = _childrenMap.Get("NullTargetKey");
|
||||
|
||||
Assert.IsNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InitMap_WithDuplicateKey_LogsErrorAndKeepsFirst()
|
||||
{
|
||||
SetEntries(new List<ChildrenMap.Entry>
|
||||
{
|
||||
new ChildrenMap.Entry("SameKey", _childA),
|
||||
new ChildrenMap.Entry("SameKey", _childB)
|
||||
});
|
||||
|
||||
LogAssert.Expect(LogType.Error, new System.Text.RegularExpressions.Regex("Duplicate key 'SameKey'"));
|
||||
GameObject result = _childrenMap.Get("SameKey");
|
||||
|
||||
Assert.AreEqual(_childA, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d779496a9b310c46a34f7d8cf1780f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using SepCore.Battle;
|
||||
using SepCore.CustomUtility;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using SepCore.UI;
|
||||
@@ -176,6 +177,109 @@ namespace VampireLike.Tests.Gameplay.EditMode
|
||||
Assert.IsTrue(tagTiersContent.Contains("(3)"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WeaponUtility_TryGetNextTierWeaponId_CalculatesAndStopsAtRed()
|
||||
{
|
||||
// 1001 = WeaponKnife White -> 1002 Blue -> 1003 Purple -> 1004 Red -> Stops
|
||||
Assert.IsTrue(WeaponUtility.TryGetNextTierWeaponId(1001, out int next1));
|
||||
Assert.AreEqual(1002, next1);
|
||||
|
||||
Assert.IsTrue(WeaponUtility.TryGetNextTierWeaponId(1002, out int next2));
|
||||
Assert.AreEqual(1003, next2);
|
||||
|
||||
Assert.IsTrue(WeaponUtility.TryGetNextTierWeaponId(1003, out int next3));
|
||||
Assert.AreEqual(1004, next3);
|
||||
|
||||
// Red (4) 无法再升阶
|
||||
Assert.IsFalse(WeaponUtility.TryGetNextTierWeaponId(1004, out int next4));
|
||||
Assert.AreEqual(0, next4);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ItemTooltipContext_CanCombineFlag_ControlsShowCombineButton()
|
||||
{
|
||||
var rawDataCombinable = new ItemTooltipRawData
|
||||
{
|
||||
Index = 0,
|
||||
ItemType = ItemType.Weapon,
|
||||
Price = 100,
|
||||
Rarity = Rarity.White,
|
||||
CanCombine = true
|
||||
};
|
||||
var contextCombinable = new ItemTooltipContext(rawDataCombinable);
|
||||
Assert.IsTrue(contextCombinable.BasicContext.ShowCombineButton);
|
||||
|
||||
var rawDataNonCombinable = new ItemTooltipRawData
|
||||
{
|
||||
Index = 0,
|
||||
ItemType = ItemType.Weapon,
|
||||
Price = 100,
|
||||
Rarity = Rarity.Red,
|
||||
CanCombine = false
|
||||
};
|
||||
var contextNonCombinable = new ItemTooltipContext(rawDataNonCombinable);
|
||||
Assert.IsFalse(contextNonCombinable.BasicContext.ShowCombineButton);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WeaponSynthesis_NestedBatchUpdate_AtomicallyReplacesMilestonesWithoutIntermediateDip()
|
||||
{
|
||||
var pipeline = new AttributePipeline();
|
||||
pipeline.SetBaseValue(StatType.MaxHp, 100f);
|
||||
|
||||
var tagTier1 = new WeaponTagConfig(CreateBufferForTagConfig(401, (int)WeaponTag.Primitive, 2, StatType.MaxHp, 5f, ModifierType.Flat));
|
||||
var tagTier2 = new WeaponTagConfig(CreateBufferForTagConfig(402, (int)WeaponTag.Primitive, 4, StatType.MaxHp, 12f, ModifierType.Flat));
|
||||
|
||||
// 初始 4 件达成 2 档:100 + 12 = 112 HP
|
||||
pipeline.AddModifier(tagTier2.StatModifierConfigs[0], tagTier2);
|
||||
Assert.AreEqual(112f, pipeline.GetValue(StatType.MaxHp), 1e-4f);
|
||||
|
||||
float currentHealth = 112f;
|
||||
int notificationCount = 0;
|
||||
|
||||
pipeline.OnStatChanged += (statType, newValue) =>
|
||||
{
|
||||
if (statType == StatType.MaxHp)
|
||||
{
|
||||
notificationCount++;
|
||||
if (currentHealth > newValue)
|
||||
{
|
||||
currentHealth = newValue;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 模拟合成流程:外层 BeginBatchUpdate 包裹
|
||||
// 合成两把武器使得件数从 4 变 3(降至 1 档 5 HP),期间移除 4 档、甚至中间可能短暂降至 0 档
|
||||
using (pipeline.BeginBatchUpdate())
|
||||
{
|
||||
// 模拟第一把武器移除时的内部刷新(嵌套 BatchUpdate)
|
||||
using (pipeline.BeginBatchUpdate())
|
||||
{
|
||||
pipeline.RemoveAllModifiersFromSource(tagTier2);
|
||||
}
|
||||
|
||||
// 此时外层尚未结束,不应触发任何 OnStatChanged,当前血量不应被扣减
|
||||
Assert.AreEqual(0, notificationCount);
|
||||
Assert.AreEqual(112f, currentHealth);
|
||||
|
||||
// 模拟新合成武器挂载后的内部刷新(嵌套 BatchUpdate)
|
||||
using (pipeline.BeginBatchUpdate())
|
||||
{
|
||||
pipeline.AddModifier(tagTier1.StatModifierConfigs[0], tagTier1);
|
||||
}
|
||||
|
||||
Assert.AreEqual(0, notificationCount);
|
||||
}
|
||||
|
||||
// 外层作用域结束后,统一结算一次变化
|
||||
Assert.AreEqual(1, notificationCount);
|
||||
// 最终生命上限为 100 + 5 = 105
|
||||
Assert.AreEqual(105f, pipeline.GetValue(StatType.MaxHp), 1e-4f);
|
||||
// 当前生命平滑裁剪至 105,而不是在中间被 100 裁剪
|
||||
Assert.AreEqual(105f, currentHealth, 1e-4f);
|
||||
}
|
||||
|
||||
private static Luban.ByteBuf CreateBufferForTagConfig(int id, int tag, int requiredCount, StatType statType, float value, ModifierType modType)
|
||||
{
|
||||
var buf = new Luban.ByteBuf();
|
||||
|
||||
Reference in New Issue
Block a user