S5-04
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
using System.Collections.Generic;
|
||||
using GeometryTD.CustomUtility;
|
||||
using GeometryTD.Definition;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GeometryTD.Tests.EditMode
|
||||
{
|
||||
public sealed class ItemDescUtilityTests
|
||||
{
|
||||
[Test]
|
||||
public void BuildMuzzleDesc_Appends_Broken_Status_When_Endurance_Is_Zero()
|
||||
{
|
||||
string description = ItemDescUtility.BuildMuzzleDesc(new MuzzleCompItemData
|
||||
{
|
||||
AttackDamage = new[] { 10 },
|
||||
DamageRandomRate = 0.1f,
|
||||
AttackMethodType = AttackMethodType.NormalBullet,
|
||||
Endurance = 0f
|
||||
});
|
||||
|
||||
StringAssert.Contains("当前耐久:0", description);
|
||||
StringAssert.Contains("状态:已损坏,无法参战。", description);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildTowerDesc_Appends_Broken_Status_And_Restriction_When_Component_Is_Broken()
|
||||
{
|
||||
TowerItemData tower = CreateTower();
|
||||
Dictionary<long, MuzzleCompItemData> muzzleMap = new Dictionary<long, MuzzleCompItemData>
|
||||
{
|
||||
[10001] = new MuzzleCompItemData { InstanceId = 10001, Endurance = 0f }
|
||||
};
|
||||
Dictionary<long, BearingCompItemData> bearingMap = new Dictionary<long, BearingCompItemData>
|
||||
{
|
||||
[20001] = new BearingCompItemData { InstanceId = 20001, Endurance = 100f }
|
||||
};
|
||||
Dictionary<long, BaseCompItemData> baseMap = new Dictionary<long, BaseCompItemData>
|
||||
{
|
||||
[30001] = new BaseCompItemData { InstanceId = 30001, Endurance = 100f }
|
||||
};
|
||||
|
||||
string description = ItemDescUtility.BuildTowerDesc(tower, muzzleMap, bearingMap, baseMap);
|
||||
|
||||
StringAssert.Contains("状态:已损坏", description);
|
||||
StringAssert.Contains("参战限制:枪口组件耐久为 0,无法参战。", description);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildTowerDesc_Does_Not_Append_Broken_Status_When_Tower_Is_Valid()
|
||||
{
|
||||
TowerItemData tower = CreateTower();
|
||||
Dictionary<long, MuzzleCompItemData> muzzleMap = new Dictionary<long, MuzzleCompItemData>
|
||||
{
|
||||
[10001] = new MuzzleCompItemData { InstanceId = 10001, Endurance = 100f }
|
||||
};
|
||||
Dictionary<long, BearingCompItemData> bearingMap = new Dictionary<long, BearingCompItemData>
|
||||
{
|
||||
[20001] = new BearingCompItemData { InstanceId = 20001, Endurance = 100f }
|
||||
};
|
||||
Dictionary<long, BaseCompItemData> baseMap = new Dictionary<long, BaseCompItemData>
|
||||
{
|
||||
[30001] = new BaseCompItemData { InstanceId = 30001, Endurance = 100f }
|
||||
};
|
||||
|
||||
string description = ItemDescUtility.BuildTowerDesc(tower, muzzleMap, bearingMap, baseMap);
|
||||
|
||||
StringAssert.DoesNotContain("状态:已损坏", description);
|
||||
StringAssert.DoesNotContain("参战限制:", description);
|
||||
}
|
||||
|
||||
private static TowerItemData CreateTower()
|
||||
{
|
||||
return new TowerItemData
|
||||
{
|
||||
InstanceId = 90001,
|
||||
MuzzleComponentInstanceId = 10001,
|
||||
BearingComponentInstanceId = 20001,
|
||||
BaseComponentInstanceId = 30001,
|
||||
Stats = new TowerStatsData
|
||||
{
|
||||
AttackDamage = new[] { 10 },
|
||||
DamageRandomRate = 0.1f,
|
||||
AttackMethodType = AttackMethodType.NormalBullet,
|
||||
RotateSpeed = new[] { 1f },
|
||||
AttackRange = new[] { 2f },
|
||||
AttackSpeed = new[] { 1f },
|
||||
AttackPropertyType = AttackPropertyType.Physics
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 128f16fc0aa2493f9ffeb226f76d2661
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,85 @@
|
||||
using GeometryTD.Definition;
|
||||
using GeometryTD.Procedure;
|
||||
using GeometryTD.UI;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GeometryTD.Tests.EditMode
|
||||
{
|
||||
public sealed class ProcedureMainParticipantTowerCleanupServiceTests
|
||||
{
|
||||
[Test]
|
||||
public void RemoveBrokenParticipantTowers_Removes_Only_Broken_Participant_Towers()
|
||||
{
|
||||
BackpackInventoryData inventory = CreateInventory();
|
||||
inventory.MuzzleComponents[0].Endurance = 0f;
|
||||
inventory.ParticipantTowerInstanceIds.Add(90002);
|
||||
|
||||
ProcedureMainParticipantTowerCleanupResult result =
|
||||
ProcedureMainParticipantTowerCleanupService.RemoveBrokenParticipantTowers(inventory, 4);
|
||||
|
||||
Assert.That(result.HasAnyRemovedTower, Is.True);
|
||||
Assert.That(result.RemovedResults.Count, Is.EqualTo(1));
|
||||
Assert.That(result.RemovedResults[0].TowerInstanceId, Is.EqualTo(90001));
|
||||
CollectionAssert.AreEqual(new long[] { 90002 }, inventory.ParticipantTowerInstanceIds);
|
||||
Assert.That(inventory.Towers[0].IsParticipatingInCombat, Is.False);
|
||||
Assert.That(inventory.Towers[1].IsParticipatingInCombat, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildRemovedTowerDialogRawData_Lists_Removed_Broken_Towers()
|
||||
{
|
||||
ProcedureMainParticipantTowerCleanupResult cleanupResult = new ProcedureMainParticipantTowerCleanupResult();
|
||||
cleanupResult.RemovedResults.Add(new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = 90001,
|
||||
FailureReason = CombatParticipantTowerValidationFailureReason.BrokenMuzzleComponent
|
||||
});
|
||||
cleanupResult.RemovedResults.Add(new CombatParticipantTowerValidationResult
|
||||
{
|
||||
TowerInstanceId = 90002,
|
||||
FailureReason = CombatParticipantTowerValidationFailureReason.BrokenBaseComponent
|
||||
});
|
||||
|
||||
DialogFormRawData rawData =
|
||||
ProcedureMainParticipantTowerCleanupService.BuildRemovedTowerDialogRawData(cleanupResult);
|
||||
|
||||
Assert.That(rawData.Title, Is.EqualTo("出战塔已损坏"));
|
||||
Assert.That(
|
||||
rawData.Message,
|
||||
Is.EqualTo("以下防御塔已损坏,已自动移出参战区:\n塔 #90001 枪口组件耐久为 0,无法参战。\n塔 #90002 底座组件耐久为 0,无法参战。"));
|
||||
Assert.That(rawData.ConfirmText, Is.EqualTo("知道了"));
|
||||
}
|
||||
|
||||
private static BackpackInventoryData CreateInventory()
|
||||
{
|
||||
BackpackInventoryData inventory = new BackpackInventoryData();
|
||||
AddTower(inventory, 90001, 10001, 20001, 30001);
|
||||
AddTower(inventory, 90002, 10002, 20002, 30002);
|
||||
inventory.ParticipantTowerInstanceIds.Add(90001);
|
||||
inventory.ParticipantTowerInstanceIds.Add(90002);
|
||||
inventory.Towers[0].IsParticipatingInCombat = true;
|
||||
inventory.Towers[1].IsParticipatingInCombat = true;
|
||||
return inventory;
|
||||
}
|
||||
|
||||
private static void AddTower(
|
||||
BackpackInventoryData inventory,
|
||||
long towerId,
|
||||
long muzzleId,
|
||||
long bearingId,
|
||||
long baseId)
|
||||
{
|
||||
inventory.MuzzleComponents.Add(new MuzzleCompItemData { InstanceId = muzzleId, Endurance = 100f });
|
||||
inventory.BearingComponents.Add(new BearingCompItemData { InstanceId = bearingId, Endurance = 100f });
|
||||
inventory.BaseComponents.Add(new BaseCompItemData { InstanceId = baseId, Endurance = 100f });
|
||||
inventory.Towers.Add(new TowerItemData
|
||||
{
|
||||
InstanceId = towerId,
|
||||
MuzzleComponentInstanceId = muzzleId,
|
||||
BearingComponentInstanceId = bearingId,
|
||||
BaseComponentInstanceId = baseId,
|
||||
Stats = new TowerStatsData()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e9f19d3160e4ba2b966d46feae1e8ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,69 @@
|
||||
using GeometryTD.Definition;
|
||||
using GeometryTD.UI;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GeometryTD.Tests.EditMode
|
||||
{
|
||||
public sealed class RepoParticipantAssignDialogUtilityTests
|
||||
{
|
||||
[Test]
|
||||
public void BuildDialog_Returns_InvalidTower_Message_For_Broken_Component()
|
||||
{
|
||||
DialogFormRawData rawData = RepoParticipantAssignDialogUtility.BuildDialog(
|
||||
new ParticipantTowerAssignResult
|
||||
{
|
||||
TowerInstanceId = 90001,
|
||||
FailureReason = ParticipantTowerAssignFailureReason.InvalidTower,
|
||||
ValidationFailureReason = CombatParticipantTowerValidationFailureReason.BrokenMuzzleComponent
|
||||
},
|
||||
4);
|
||||
|
||||
Assert.That(rawData.Title, Is.EqualTo("无法加入参战区"));
|
||||
Assert.That(rawData.Message, Is.EqualTo("塔 #90001 枪口组件耐久为 0,无法参战。"));
|
||||
Assert.That(rawData.ConfirmText, Is.EqualTo("知道了"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildDialog_Returns_InvalidTower_Message_For_Missing_Component()
|
||||
{
|
||||
DialogFormRawData rawData = RepoParticipantAssignDialogUtility.BuildDialog(
|
||||
new ParticipantTowerAssignResult
|
||||
{
|
||||
TowerInstanceId = 90002,
|
||||
FailureReason = ParticipantTowerAssignFailureReason.InvalidTower,
|
||||
ValidationFailureReason = CombatParticipantTowerValidationFailureReason.MissingBaseComponent
|
||||
},
|
||||
4);
|
||||
|
||||
Assert.That(rawData.Message, Is.EqualTo("塔 #90002 缺少底座组件。"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildDialog_Returns_ParticipantAreaFull_Message()
|
||||
{
|
||||
DialogFormRawData rawData = RepoParticipantAssignDialogUtility.BuildDialog(
|
||||
new ParticipantTowerAssignResult
|
||||
{
|
||||
TowerInstanceId = 90003,
|
||||
FailureReason = ParticipantTowerAssignFailureReason.ParticipantAreaFull
|
||||
},
|
||||
4);
|
||||
|
||||
Assert.That(rawData.Message, Is.EqualTo("参战区已满,最多只能放入 4 座塔。"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildDialog_Returns_AlreadyAssigned_Message()
|
||||
{
|
||||
DialogFormRawData rawData = RepoParticipantAssignDialogUtility.BuildDialog(
|
||||
new ParticipantTowerAssignResult
|
||||
{
|
||||
TowerInstanceId = 90004,
|
||||
FailureReason = ParticipantTowerAssignFailureReason.AlreadyAssigned
|
||||
},
|
||||
4);
|
||||
|
||||
Assert.That(rawData.Message, Is.EqualTo("塔 #90004 已在参战区中。"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcce8297c0fb4a539e4ab8db1a20e165
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user