144 lines
4.6 KiB
C#
144 lines
4.6 KiB
C#
using BumpCombat.Combat;
|
|
using BumpCombat.Core;
|
|
using BumpCombat.Enemies;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
|
|
namespace BumpCombat.Tests
|
|
{
|
|
public sealed class EnemyModelTests
|
|
{
|
|
private GameObject owner;
|
|
private EnemyDefinition definition;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
owner = new GameObject("Enemy Model Tests");
|
|
definition = ScriptableObject.CreateInstance<EnemyDefinition>();
|
|
definition.Configure(
|
|
EnemyKind.Slime,
|
|
EnemyAttackShape.Body,
|
|
100f,
|
|
4f,
|
|
12f,
|
|
1f,
|
|
0.2f,
|
|
1f,
|
|
1f,
|
|
1f,
|
|
1f,
|
|
1f,
|
|
1f,
|
|
10);
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
Object.DestroyImmediate(owner);
|
|
Object.DestroyImmediate(definition);
|
|
}
|
|
|
|
[Test]
|
|
public void EnemyModel_UsesSharedModifiersForHealthSpeedAttackAndIncomingDamage()
|
|
{
|
|
EnemyModel model = owner.AddComponent<EnemyModel>();
|
|
model.ConfigureDefinition(definition);
|
|
model.ConfigureEventMultipliers(1.1f, 1.2f, 1.3f);
|
|
CharacterModel character = model;
|
|
|
|
character.AddModifier(new StatModifier(
|
|
"max-health",
|
|
CharacterStat.MaxHealth,
|
|
ModifierOperation.Increased,
|
|
0.2f));
|
|
character.AddModifier(new StatModifier(
|
|
"move-speed-flat",
|
|
CharacterStat.MoveSpeed,
|
|
ModifierOperation.Flat,
|
|
0.5f));
|
|
character.AddModifier(new StatModifier(
|
|
"move-speed-increased",
|
|
CharacterStat.MoveSpeed,
|
|
ModifierOperation.Increased,
|
|
0.25f));
|
|
character.AddModifier(new StatModifier(
|
|
"attack-increased",
|
|
CharacterStat.AttackDamage,
|
|
ModifierOperation.Increased,
|
|
0.2f));
|
|
character.AddModifier(new StatModifier(
|
|
"incoming-flat",
|
|
CharacterStat.IncomingDamage,
|
|
ModifierOperation.Flat,
|
|
2f));
|
|
character.AddModifier(new StatModifier(
|
|
"incoming-increased",
|
|
CharacterStat.IncomingDamage,
|
|
ModifierOperation.Increased,
|
|
0.25f));
|
|
character.AddModifier(new StatModifier(
|
|
"incoming-more",
|
|
CharacterStat.IncomingDamage,
|
|
ModifierOperation.More,
|
|
0.1f));
|
|
|
|
Assert.That(character.MaxHealth, Is.EqualTo(132f).Within(0.001f));
|
|
Assert.That(character.MoveSpeed, Is.EqualTo(6.625f).Within(0.001f));
|
|
Assert.That(model.AttackDamage, Is.EqualTo(18.72f).Within(0.001f));
|
|
Assert.That(
|
|
model.CalculatePatternDamage(1.5f, true),
|
|
Is.EqualTo(28.08f).Within(0.001f));
|
|
|
|
float modifiedIncomingDamage = character.CalculateIncomingDamage(10f);
|
|
Assert.That(modifiedIncomingDamage, Is.EqualTo(16.5f).Within(0.001f));
|
|
Assert.That(
|
|
DamageCalculator.ApplyDamageTakenEffects(
|
|
modifiedIncomingDamage,
|
|
0f,
|
|
false,
|
|
0.25f,
|
|
true),
|
|
Is.EqualTo(20f));
|
|
}
|
|
|
|
[Test]
|
|
public void UnprotectedSummon_KeepsHealthMultiplierWithoutEventSpeedOrDamageTuning()
|
|
{
|
|
owner.AddComponent<Rigidbody2D>();
|
|
owner.AddComponent<BoxCollider2D>();
|
|
owner.AddComponent<SpriteRenderer>();
|
|
EnemyController enemy = owner.AddComponent<EnemyController>();
|
|
enemy.Configure(definition, null);
|
|
RunEventEnemyTuning tuning = RunEventEnemyTuning.Create(
|
|
EnemyKind.Slime,
|
|
1.5f,
|
|
10,
|
|
1f,
|
|
Color.white,
|
|
2f,
|
|
2f,
|
|
1f,
|
|
1f,
|
|
1f,
|
|
1f,
|
|
1f,
|
|
1f,
|
|
1f,
|
|
1,
|
|
1f,
|
|
1f,
|
|
1,
|
|
1f,
|
|
false);
|
|
|
|
enemy.ConfigureSummonedEnemy(null, tuning, false);
|
|
|
|
Assert.That(enemy.MaximumHealth, Is.EqualTo(150f).Within(0.001f));
|
|
Assert.That(enemy.MoveSpeed, Is.EqualTo(4f).Within(0.001f));
|
|
Assert.That(enemy.AttackDamage, Is.EqualTo(12f).Within(0.001f));
|
|
}
|
|
}
|
|
}
|