Apply difficulty modifiers to damage

This commit is contained in:
Marco 2025-04-08 19:06:39 +02:00
commit bb0f17124d
15 changed files with 94 additions and 59 deletions

View file

@ -1,4 +1,5 @@
using System.Linq;
using Cirno.Scripts.Enums;
using Cirno.Scripts.Resources;
using Godot;
using Godot.Collections;
@ -60,8 +61,17 @@ public partial class GenericDamageReceiver : Area2D, IHittable
{
if (!Enabled) return;
if (Invulnerable) return;
// Change value based on difficulty
float difficultyReducedDmg = GlobalState.Instance.SessionSettings.Difficulty switch
{
DifficultyLevel.Easy => damage * 5,
DifficultyLevel.Normal => damage * 2,
DifficultyLevel.Hard or DifficultyLevel.Lunatic => damage,
_ => damage
};
var dmg = DamageResistances.Aggregate(damage, (current, resistance) => current * resistance.CalculateDamage(current, damageType));
var dmg = DamageResistances.Aggregate(difficultyReducedDmg, (current, resistance) => current * resistance.CalculateDamage(current, damageType));
HealthProvider.CurrentResource -= dmg;
}

View file

@ -184,15 +184,24 @@ public partial class PlayerDamageReceiver : Area2D
{
if (!Enabled) return;
// Change value based on difficulty
float difficultyReducedDmg = GlobalState.Instance.SessionSettings.Difficulty switch
{
DifficultyLevel.Easy => damage / 5,
DifficultyLevel.Normal => damage / 2,
DifficultyLevel.Hard or DifficultyLevel.Lunatic => damage,
_ => damage
};
// Check if the shield is empty or damage has skip attributes
if (CurrentShield <= 0 || ShieldDamageResistances.Where(x => x.DamageType == type).Any(x => x.Attribute is DamageAttribute.Skip))
{
// do not apply, go to health
ApplyDamageToHealth(damage, type);
ApplyDamageToHealth(difficultyReducedDmg, type);
}
else
{
var shieldDmg = ShieldDamageResistances.Aggregate(damage, (current, resistance) => current * resistance.CalculateDamage(current, type));
var shieldDmg = ShieldDamageResistances.Aggregate(difficultyReducedDmg, (current, resistance) => current * resistance.CalculateDamage(current, type));
// apply and get remainder
var remainder = CurrentShield - shieldDmg;
@ -205,33 +214,33 @@ public partial class PlayerDamageReceiver : Area2D
}
}
return;
// return;
if (CurrentShield > 0 && type is not DamageType.Explosive or DamageType.Acid)
{
// Reduce shield
//PlayShieldAnimation(); // Let this be handled by event
CurrentShield -= damage;
if (CurrentShield < 0)
{
CurrentHealth -= Math.Abs(CurrentShield);
CurrentShield = 0;
}
}
else
{
if (type is DamageType.Fire)
{
CurrentHealth -= damage * 2;
}
else
{
CurrentHealth -= damage;
}
//Blink(); // Let this be handled by event
}
if (!(CurrentHealth <= 0)) return;
// if (CurrentShield > 0 && type is not DamageType.Explosive or DamageType.Acid)
// {
// // Reduce shield
// //PlayShieldAnimation(); // Let this be handled by event
// CurrentShield -= damage;
// if (CurrentShield < 0)
// {
// CurrentHealth -= Math.Abs(CurrentShield);
// CurrentShield = 0;
// }
// }
// else
// {
// if (type is DamageType.Fire)
// {
// CurrentHealth -= damage * 2;
// }
// else
// {
// CurrentHealth -= damage;
// }
//
// //Blink(); // Let this be handled by event
// }
//
// if (!(CurrentHealth <= 0)) return;
}
}

View file

@ -1,4 +1,5 @@
using Cirno.Scripts.Components.Actors;
using Cirno.Scripts.Enums;
using Godot;
namespace Cirno.Scripts.Components.FSM.Player;
@ -40,7 +41,18 @@ public partial class PlayerGrazingModule : PlayerArea2DModule
bullet.Graze();
//bullet.IsGrazed = true;
Shield.CurrentResource += bullet.BulletInfo.GrazeValue;
var baseGrazeValue = bullet.BulletInfo.GrazeValue;
float grazeShield = GlobalState.Instance.SessionSettings.Difficulty switch
{
DifficultyLevel.Easy => baseGrazeValue * 5,
DifficultyLevel.Normal => baseGrazeValue * 2,
DifficultyLevel.Hard or DifficultyLevel.Lunatic => baseGrazeValue,
_ => baseGrazeValue
};
Shield.CurrentResource += grazeShield;
// check if it's grazed
// check if it's grazeable
// restore appropriate amount of shield

View file

@ -21,7 +21,7 @@ public partial class BulletResource : Resource
[Export] public DamageType DamageType = DamageType.Neutral;
[Export] public bool Controllable = false;
[Export] public bool Grazeable { get; set; } = true;
[Export] public float GrazeValue { get; set; } = 1f;
[Export] public float GrazeValue { get; set; } = 0.2f;
[Export]
public BulletCreationModifier Modifier;