Damage source and effect fix

This commit is contained in:
Фёдор Веселов 2024-10-06 19:55:42 +05:00
commit c89d93cf24
15 changed files with 52 additions and 34 deletions

View file

@ -5,5 +5,6 @@
[resource] [resource]
script = ExtResource("1_8md01") script = ExtResource("1_8md01")
ColorOverride = Color(0, 1, 1, 1) ColorOverride = Color(0, 1, 1, 1)
Duration = 10.0
Multiplier = 0.75 Multiplier = 0.75
Duration = 3.25
Slot = 2

View file

@ -15,6 +15,7 @@ size = Vector2(20, 44)
[sub_resource type="SegmentShape2D" id="SegmentShape2D_8iovl"] [sub_resource type="SegmentShape2D" id="SegmentShape2D_8iovl"]
[node name="Peashooter" instance=ExtResource("1_pyk3o")] [node name="Peashooter" instance=ExtResource("1_pyk3o")]
_maxHP = 100
[node name="Sprite2D" parent="." index="0"] [node name="Sprite2D" parent="." index="0"]
texture = ExtResource("2_14qlx") texture = ExtResource("2_14qlx")
@ -58,14 +59,4 @@ script = ExtResource("7_2bki8")
shape = SubResource("SegmentShape2D_8iovl") shape = SubResource("SegmentShape2D_8iovl")
script = ExtResource("8_nl4jc") script = ExtResource("8_nl4jc")
[node name="CollisionShape2D2" type="CollisionShape2D" parent="Eysight" index="1"]
position = Vector2(0, 60)
shape = SubResource("SegmentShape2D_8iovl")
script = ExtResource("8_nl4jc")
[node name="CollisionShape2D3" type="CollisionShape2D" parent="Eysight" index="2"]
position = Vector2(0, -60)
shape = SubResource("SegmentShape2D_8iovl")
script = ExtResource("8_nl4jc")
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="." index="6"] [node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="." index="6"]

View file

@ -1,9 +1,22 @@
[gd_scene load_steps=3 format=3 uid="uid://eegv1qihfv2q"] [gd_scene load_steps=5 format=3 uid="uid://eegv1qihfv2q"]
[ext_resource type="PackedScene" uid="uid://dy41q1kxray5t" path="res://scenes/entities/plants/peashooter.tscn" id="1_muntu"] [ext_resource type="PackedScene" uid="uid://dy41q1kxray5t" path="res://scenes/entities/plants/peashooter.tscn" id="1_muntu"]
[ext_resource type="Script" path="res://scripts/components/plants/ThreepeaterShooter.cs" id="2_ieami"] [ext_resource type="Script" path="res://scripts/components/plants/ThreepeaterShooter.cs" id="2_ieami"]
[ext_resource type="Script" path="res://scripts/components/plants/PlantEyesightLimiter.cs" id="3_dqn6w"]
[sub_resource type="SegmentShape2D" id="SegmentShape2D_yb26d"]
[node name="Threepeater" instance=ExtResource("1_muntu")] [node name="Threepeater" instance=ExtResource("1_muntu")]
[node name="Shooter" parent="." index="3"] [node name="Shooter" parent="." index="3"]
script = ExtResource("2_ieami") script = ExtResource("2_ieami")
[node name="CollisionShape2D2" type="CollisionShape2D" parent="Eysight" index="1"]
position = Vector2(0, 60)
shape = SubResource("SegmentShape2D_yb26d")
script = ExtResource("3_dqn6w")
[node name="CollisionShape2D3" type="CollisionShape2D" parent="Eysight" index="2"]
position = Vector2(0, -60)
shape = SubResource("SegmentShape2D_yb26d")
script = ExtResource("3_dqn6w")

View file

@ -14,6 +14,7 @@ script = ExtResource("1_fkydi")
_speed = 3.0 _speed = 3.0
_damage = 10 _damage = 10
_impactEffect = ExtResource("2_txupr") _impactEffect = ExtResource("2_txupr")
_damageType = 1
[node name="Sprite" type="Sprite2D" parent="."] [node name="Sprite" type="Sprite2D" parent="."]
texture = ExtResource("2_xt8td") texture = ExtResource("2_xt8td")

View file

@ -14,7 +14,9 @@ public class Utility
// //
#region Enums #region Enums
public enum EffectSlots {FREEZE, STUN, POISON}; public enum EffectSlots {FREEZE, STUN, POISON, BEBRA};
public enum DamageTypes {PHYSICAL, ICE};
#endregion #endregion

View file

@ -14,7 +14,7 @@ public partial class FlashComponent : CanvasGroup
_shaderMaterial = Material as ShaderMaterial; _shaderMaterial = Material as ShaderMaterial;
} }
public void DamageFlash(int damage) public void DamageFlash(int damage,Node origin)
{ {
Flash(); Flash();
} }

View file

@ -1,3 +1,5 @@
using Godot;
namespace Newlon.Components; namespace Newlon.Components;
// //
@ -7,6 +9,7 @@ public interface IEntity
{ {
public int Hp { get; } public int Hp { get; }
public int MaxHp { get; } public int MaxHp { get; }
public void TakeDamage(int amount); public void TakeDamage(int amount,Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL);
public void Heal(int amount); public void Heal(int amount, Node origin);
} }

View file

@ -15,8 +15,12 @@ public partial class LinearProjectile : Area2D, IProjectile
private int _damage; private int _damage;
[Export] [Export]
private Effect _impactEffect; private Effect _impactEffect;
[Export]
private Utility.DamageTypes _damageType = Utility.DamageTypes.PHYSICAL;
private int _line; private int _line;
private bool used = false;
public int Line { get => _line; set { _line = value; } } public int Line { get => _line; set { _line = value; } }
public override void _PhysicsProcess(double delta) public override void _PhysicsProcess(double delta)
{ {
@ -25,10 +29,12 @@ public partial class LinearProjectile : Area2D, IProjectile
public void OnAreaEntered(Area2D area) public void OnAreaEntered(Area2D area)
{ {
if (used == true) return;
var entity = area.GetParent<IEntity>(); var entity = area.GetParent<IEntity>();
if (entity != null) if (entity != null)
{ {
entity.TakeDamage(_damage); entity.TakeDamage(_damage,this,_damageType);
used = true;
if (entity is IEffectHandler effectHandler && _impactEffect != null) if (entity is IEffectHandler effectHandler && _impactEffect != null)
effectHandler.GiveEffect(_impactEffect); effectHandler.GiveEffect(_impactEffect);
QueueFree(); QueueFree();

View file

@ -12,7 +12,7 @@ public partial class AreaAttack : Area2D
foreach (var zombie in GetOverlappingAreas()) foreach (var zombie in GetOverlappingAreas())
{ {
var zombieData = zombie.GetParent<RuntimeZombieData>(); var zombieData = zombie.GetParent<RuntimeZombieData>();
zombieData?.TakeDamage(_damage); zombieData?.TakeDamage(_damage,GetParent());
} }
} }
} }

View file

@ -12,7 +12,7 @@ public partial class ExplosionComponent : Area2D
foreach(var zombie in GetOverlappingAreas()) foreach(var zombie in GetOverlappingAreas())
{ {
var zombieData = zombie.GetParent<RuntimeZombieData>(); var zombieData = zombie.GetParent<RuntimeZombieData>();
zombieData?.TakeDamage(damage); zombieData?.TakeDamage(damage,GetParent());
} }
GetParent<RuntimePlantData>().Kill(); GetParent<RuntimePlantData>().Kill();

View file

@ -18,18 +18,18 @@ public partial class RuntimePlantData : Node2D, IEntity
public PlantResource Resource; public PlantResource Resource;
[Signal] [Signal]
public delegate void OnHPChangedEventHandler(int amount); public delegate void OnHPChangedEventHandler(int amount,Node origin);
public override void _Ready() public override void _Ready()
{ {
_hp = _maxHP; _hp = _maxHP;
} }
public void Heal(int amount) public void Heal(int amount,Node origin)
{ {
_hp += amount; _hp += amount;
EmitSignal(SignalName.OnHPChanged,amount); EmitSignal(SignalName.OnHPChanged,amount,origin);
if (MaxHp > 0) if (MaxHp > 0)
{ {
@ -37,11 +37,11 @@ public partial class RuntimePlantData : Node2D, IEntity
} }
} }
public void TakeDamage(int amount) public void TakeDamage(int amount,Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL)
{ {
_hp -= amount; _hp -= amount;
EmitSignal(SignalName.OnHPChanged,-amount); EmitSignal(SignalName.OnHPChanged,-amount, origin);
if (_hp <= 0) if (_hp <= 0)
{ {

View file

@ -24,7 +24,7 @@ public partial class AloeBehaviour : Node
{ {
if((float)plantData.Hp / (float)plantData.MaxHp < _hpTreshold) if((float)plantData.Hp / (float)plantData.MaxHp < _hpTreshold)
{ {
plantData.Heal(3000 + 25 * plantData.MaxHp); plantData.Heal(3000 + 25 * plantData.MaxHp,GetParent());
_charge = false; _charge = false;
_player.Play("aloe/heal"); _player.Play("aloe/heal");
_player.Queue("aloe/idle_used"); _player.Queue("aloe/idle_used");

View file

@ -4,7 +4,7 @@ namespace Newlon.Components.Zombies;
public partial class AudioDamage : AudioStreamPlayer2D public partial class AudioDamage : AudioStreamPlayer2D
{ {
public void OnDamaged(int amount) public void OnDamaged(int amount, Node origin)
{ {
Play(); Play();
} }

View file

@ -15,7 +15,7 @@ public partial class EatBox : Area2D
public void Bite() public void Bite()
{ {
plant.TakeDamage(_damage); plant?.TakeDamage(_damage,GetParent());
} }
public void OnAreaEntered(Area2D area) public void OnAreaEntered(Area2D area)

View file

@ -7,7 +7,7 @@ namespace Newlon.Components.Zombies;
public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffectHandler public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffectHandler
{ {
[Signal] [Signal]
public delegate void OnHPChangedEventHandler(int deltaHP); public delegate void OnHPChangedEventHandler(int deltaHP, Node origin);
[Signal] [Signal]
public delegate void OnLocalTimescaleChangedEventHandler(int currentTimescale); public delegate void OnLocalTimescaleChangedEventHandler(int currentTimescale);
@ -45,14 +45,15 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
var timer = new Timer() {Autostart = false, OneShot = true}; var timer = new Timer() {Autostart = false, OneShot = true};
_effectSlotTimers[i] = timer; _effectSlotTimers[i] = timer;
AddChild(timer); AddChild(timer);
timer.Timeout += () => {EndEffectAtSlot(i);}; int current_index = i;
timer.Timeout += () => {EndEffectAtSlot(current_index);};
} }
} }
public void Heal(int amount) public void Heal(int amount,Node origin)
{ {
_hp += amount; _hp += amount;
EmitSignal(SignalName.OnHPChanged,amount); EmitSignal(SignalName.OnHPChanged,amount,origin);
if (MaxHp > 0) if (MaxHp > 0)
{ {
@ -60,10 +61,10 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
} }
} }
public void TakeDamage(int amount) public void TakeDamage(int amount, Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL)
{ {
_hp -= amount; _hp -= amount;
EmitSignal(SignalName.OnHPChanged,-amount); EmitSignal(SignalName.OnHPChanged,-amount, origin);
if (_hp <= 0) if (_hp <= 0)
{ {
@ -101,7 +102,7 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe
public void ProcessEffects() public void ProcessEffects()
{ {
for(int i = 0; i < Utility.EffectSlotCount; i++) for(int i = 0; i < Utility.EffectSlotCount; i++)
_activeEffectSlots[i].Process(this); _activeEffectSlots[i]?.Process(this);
} }
private void EndEffectAtSlot(int slot) private void EndEffectAtSlot(int slot)