加入武器 tag 的羁绊效果
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
"UnityEditor.TestRunner",
|
||||
"SepCore.Runtime",
|
||||
"SepCore.Base",
|
||||
"SepCore.Presentation"
|
||||
"SepCore.Presentation",
|
||||
"Luban.Runtime"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using SepCore.Battle;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using SepCore.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VampireLike.Tests.Gameplay.EditMode
|
||||
{
|
||||
[TestFixture]
|
||||
public class WeaponSynergyTests
|
||||
{
|
||||
[Test]
|
||||
public void TagMilestoneReplacement_ReplacesLowerTierWithHigherTier()
|
||||
{
|
||||
var pipeline = new AttributePipeline();
|
||||
pipeline.SetBaseValue(StatType.MeleeDamage, 10f);
|
||||
|
||||
var tier2 = new WeaponTagConfig(CreateBufferForTagConfig(101, (int)WeaponTag.Blade, 2, StatType.MeleeDamage, 1f, ModifierType.Flat));
|
||||
var tier4 = new WeaponTagConfig(CreateBufferForTagConfig(102, (int)WeaponTag.Blade, 4, StatType.MeleeDamage, 3f, ModifierType.Flat));
|
||||
|
||||
// 模拟 2 级生效
|
||||
for (int i = 0; i < tier2.StatModifierConfigs.Count; i++)
|
||||
{
|
||||
pipeline.AddModifier(tier2.StatModifierConfigs[i], tier2);
|
||||
}
|
||||
Assert.AreEqual(11f, pipeline.GetValue(StatType.MeleeDamage), 1e-4f);
|
||||
|
||||
// 升级到 4 级:卸载 tier2,挂载 tier4
|
||||
pipeline.RemoveAllModifiersFromSource(tier2);
|
||||
for (int i = 0; i < tier4.StatModifierConfigs.Count; i++)
|
||||
{
|
||||
pipeline.AddModifier(tier4.StatModifierConfigs[i], tier4);
|
||||
}
|
||||
|
||||
// 验证不是 10 + 1 + 3 = 14,而是最高档生效 10 + 3 = 13
|
||||
Assert.AreEqual(13f, pipeline.GetValue(StatType.MeleeDamage), 1e-4f);
|
||||
|
||||
// 降级回 2 级:卸载 tier4,重新挂载 tier2
|
||||
pipeline.RemoveAllModifiersFromSource(tier4);
|
||||
for (int i = 0; i < tier2.StatModifierConfigs.Count; i++)
|
||||
{
|
||||
pipeline.AddModifier(tier2.StatModifierConfigs[i], tier2);
|
||||
}
|
||||
Assert.AreEqual(11f, pipeline.GetValue(StatType.MeleeDamage), 1e-4f);
|
||||
|
||||
// 全部卸载
|
||||
pipeline.RemoveAllModifiersFromSource(tier2);
|
||||
Assert.AreEqual(10f, pipeline.GetValue(StatType.MeleeDamage), 1e-4f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ItemTooltipContext_ConstructsBasicAndDetailProperly()
|
||||
{
|
||||
var rawData = new ItemTooltipRawData
|
||||
{
|
||||
Index = 0,
|
||||
ItemType = ItemType.Weapon,
|
||||
Price = 100,
|
||||
Rarity = Rarity.Blue,
|
||||
TargetPos = new Vector3(100f, 200f, 0f),
|
||||
LastWaveDamage = 361,
|
||||
CurrentTagCounts = new Dictionary<WeaponTag, int>
|
||||
{
|
||||
{ WeaponTag.Gun, 6 }
|
||||
}
|
||||
};
|
||||
|
||||
var context = new ItemTooltipContext(rawData);
|
||||
|
||||
Assert.IsNotNull(context.BasicContext);
|
||||
Assert.IsNotNull(context.DetailContext);
|
||||
Assert.AreEqual(100, context.BasicContext.Price);
|
||||
Assert.AreEqual(361, context.DetailContext.LastWaveDamage);
|
||||
Assert.IsTrue(context.DetailContext.HasLastWaveDamage);
|
||||
Assert.IsTrue(context.DetailContext.HasAnyContent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ItemTooltipContext_WithoutLastWaveDamage_HidesDamageCard()
|
||||
{
|
||||
var rawData = new ItemTooltipRawData
|
||||
{
|
||||
Index = 1,
|
||||
ItemType = ItemType.Prop,
|
||||
Price = 50,
|
||||
Rarity = Rarity.White,
|
||||
LastWaveDamage = 0 // 无上一轮伤害
|
||||
};
|
||||
|
||||
var context = new ItemTooltipContext(rawData);
|
||||
|
||||
Assert.IsFalse(context.DetailContext.HasLastWaveDamage);
|
||||
Assert.IsFalse(context.DetailContext.HasTagSynergy);
|
||||
Assert.IsFalse(context.DetailContext.HasAnyContent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BatchUpdate_AtomicModifierReplacement_PreventsHealthClamping()
|
||||
{
|
||||
var pipeline = new AttributePipeline();
|
||||
pipeline.SetBaseValue(StatType.MaxHp, 100f);
|
||||
|
||||
var tier1 = new WeaponTagConfig(CreateBufferForTagConfig(201, (int)WeaponTag.Primitive, 2, StatType.MaxHp, 3f, ModifierType.Flat));
|
||||
var tier2 = new WeaponTagConfig(CreateBufferForTagConfig(202, (int)WeaponTag.Primitive, 3, StatType.MaxHp, 6f, ModifierType.Flat));
|
||||
|
||||
// 初始达成 2 件套:最大生命 100 + 3 = 103,当前生命满血 103
|
||||
pipeline.AddModifier(tier1.StatModifierConfigs[0], tier1);
|
||||
Assert.AreEqual(103f, pipeline.GetValue(StatType.MaxHp), 1e-4f);
|
||||
|
||||
float currentHealth = 103f;
|
||||
int notificationCount = 0;
|
||||
|
||||
// 模拟 HealthComponent 的监听逻辑:当 MaxHp 发生变化时,如果当前生命大于新的上限,则裁剪到新的上限
|
||||
pipeline.OnStatChanged += (statType, newValue) =>
|
||||
{
|
||||
if (statType == StatType.MaxHp)
|
||||
{
|
||||
notificationCount++;
|
||||
if (currentHealth > newValue)
|
||||
{
|
||||
currentHealth = newValue;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 羁绊换档 2→3 件(升级):使用 BeginBatchUpdate 原子性替换
|
||||
using (pipeline.BeginBatchUpdate())
|
||||
{
|
||||
pipeline.RemoveAllModifiersFromSource(tier1);
|
||||
pipeline.AddModifier(tier2.StatModifierConfigs[0], tier2);
|
||||
}
|
||||
|
||||
// 验证:
|
||||
// 1. 最终最大生命为 100 + 6 = 106
|
||||
Assert.AreEqual(106f, pipeline.GetValue(StatType.MaxHp), 1e-4f);
|
||||
// 2. 只触发了一次通知,直接通知 106
|
||||
Assert.AreEqual(1, notificationCount);
|
||||
// 3. 当前生命未被临时下降的 100 裁剪,仍为 103!
|
||||
Assert.AreEqual(103f, currentHealth, 1e-4f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildTagSynergyInfo_MultiTagWeapon_RendersAllTagsAndTiers()
|
||||
{
|
||||
var configs = new List<WeaponTagConfig>
|
||||
{
|
||||
new(CreateBufferForTagConfig(301, (int)WeaponTag.Blade, 2, StatType.MeleeDamage, 2f, ModifierType.Flat)),
|
||||
new(CreateBufferForTagConfig(302, (int)WeaponTag.Blade, 4, StatType.MeleeDamage, 6f, ModifierType.Flat)),
|
||||
new(CreateBufferForTagConfig(303, (int)WeaponTag.Precise, 2, StatType.CritChance, 0.05f, ModifierType.Flat)),
|
||||
new(CreateBufferForTagConfig(304, (int)WeaponTag.Precise, 3, StatType.CritChance, 0.10f, ModifierType.Flat))
|
||||
};
|
||||
|
||||
var tags = new List<WeaponTag> { WeaponTag.Blade, WeaponTag.Precise };
|
||||
var tagCounts = new Dictionary<WeaponTag, int>
|
||||
{
|
||||
{ WeaponTag.Blade, 2 },
|
||||
{ WeaponTag.Precise, 2 }
|
||||
};
|
||||
|
||||
SepCore.CustomUtility.ItemDescUtility.BuildTagSynergyInfo(tags, tagCounts, configs, out string tagTitle, out string tagTiersContent);
|
||||
|
||||
// 双标签时,tagTitle 应留空由 tagTiersContent 渲染各标签标题
|
||||
Assert.IsEmpty(tagTitle);
|
||||
Assert.IsNotEmpty(tagTiersContent);
|
||||
|
||||
// 验证同时包含了 刀剑 和 精准 两个标签的标题
|
||||
Assert.IsTrue(tagTiersContent.Contains("刀剑"));
|
||||
Assert.IsTrue(tagTiersContent.Contains("精准"));
|
||||
|
||||
// 验证两者的 2 阶档位均处于激活高亮状态(包含绿色高亮标签 #38E038)
|
||||
Assert.IsTrue(tagTiersContent.Contains("#38E038"));
|
||||
Assert.IsTrue(tagTiersContent.Contains("(2)"));
|
||||
Assert.IsTrue(tagTiersContent.Contains("(4)"));
|
||||
Assert.IsTrue(tagTiersContent.Contains("(3)"));
|
||||
}
|
||||
|
||||
private static Luban.ByteBuf CreateBufferForTagConfig(int id, int tag, int requiredCount, StatType statType, float value, ModifierType modType)
|
||||
{
|
||||
var buf = new Luban.ByteBuf();
|
||||
buf.WriteInt(id);
|
||||
buf.WriteInt(tag);
|
||||
buf.WriteInt(requiredCount);
|
||||
buf.WriteSize(1); // 1 modifier
|
||||
buf.WriteInt((int)statType);
|
||||
buf.WriteFloat(value);
|
||||
buf.WriteInt((int)modType);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de6d96ad6bc606843a32d734b9323b93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user