mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 00:05:53 +00:00
Weapon evolution
This commit is contained in:
parent
8492c3644b
commit
f58b9646df
10 changed files with 209 additions and 68 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Cirno.Scripts.Weapons;
|
||||
using Cirno.Scripts.Components.FSM.Enemy._3D;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
|
|
@ -55,14 +56,24 @@ public partial class DamageReceiver3D : Area3D, IHittable
|
|||
return;
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
if (BulletGroup is BulletOwner.None)
|
||||
{
|
||||
this.Hit(bullet.Damage, bullet.DamageType);
|
||||
|
||||
EmitSignalBulletHit(bullet, area.GlobalPosition, (this.GlobalPosition - area.GlobalPosition).Normalized());
|
||||
|
||||
// Attribute XP if this hit was lethal
|
||||
if (HealthProvider.CurrentResource <= 0 && bullet.BulletInfo?.SourceWeapon != null)
|
||||
{
|
||||
int xp = 0;
|
||||
if (GetParent() is EnemyProxy3D enemyProxy && enemyProxy.EnemyResource is not null)
|
||||
{
|
||||
xp = (int)System.Math.Round(enemyProxy.EnemyResource.MotivationReward);
|
||||
}
|
||||
|
||||
bullet.BulletInfo.SourceWeapon.GainExperience(xp);
|
||||
}
|
||||
|
||||
bullet.RequestCollisionDestruction();
|
||||
return;
|
||||
}
|
||||
|
|
@ -73,6 +84,18 @@ public partial class DamageReceiver3D : Area3D, IHittable
|
|||
|
||||
EmitSignalBulletHit(bullet, area.GlobalPosition, (this.GlobalPosition - area.GlobalPosition).Normalized());
|
||||
|
||||
// Attribute XP on lethal hit
|
||||
if (HealthProvider.CurrentResource <= 0 && bullet.BulletInfo?.SourceWeapon != null)
|
||||
{
|
||||
int xp = 0;
|
||||
if (GetParent() is EnemyProxy3D enemyProxy && enemyProxy.EnemyResource is not null)
|
||||
{
|
||||
xp = (int)System.Math.Round(enemyProxy.EnemyResource.MotivationReward);
|
||||
}
|
||||
|
||||
bullet.BulletInfo.SourceWeapon.GainExperience(xp);
|
||||
}
|
||||
|
||||
bullet.RequestCollisionDestruction();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,15 @@ public partial class DamageReceiverActorModule : ActorModule, IHittable
|
|||
if (BulletGroup is BulletOwner.None)
|
||||
{
|
||||
this.Hit(bullet.Damage, bullet.DamageType);
|
||||
|
||||
// If this hit killed the actor, attribute XP to the source weapon if present
|
||||
if (HealthProvider.CurrentResource <= 0 && bullet.BulletInfo?.SourceWeapon != null)
|
||||
{
|
||||
// Award XP equal to actor's MotivationReward rounded to int, or a fixed value.
|
||||
var xp = (int)System.Math.Round(_actor.EnemyData?.MotivationReward ?? 0f);
|
||||
bullet.BulletInfo.SourceWeapon.GainExperience(xp);
|
||||
}
|
||||
|
||||
bullet.RequestCollisionDestruction();
|
||||
return;
|
||||
}
|
||||
|
|
@ -55,6 +64,14 @@ public partial class DamageReceiverActorModule : ActorModule, IHittable
|
|||
if (bullet.BulletInfo.Owner == BulletGroup) return;
|
||||
|
||||
this.Hit(bullet.Damage, bullet.DamageType);
|
||||
|
||||
// Attribute XP on lethal hit
|
||||
if (HealthProvider.CurrentResource <= 0 && bullet.BulletInfo?.SourceWeapon != null)
|
||||
{
|
||||
var xp = (int)System.Math.Round(_actor.EnemyData?.MotivationReward ?? 0f);
|
||||
bullet.BulletInfo.SourceWeapon.GainExperience(xp);
|
||||
}
|
||||
|
||||
bullet.RequestCollisionDestruction();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using Cirno.Scripts.Actors._3D;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Cirno.Scripts.Weapons;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components;
|
||||
|
|
@ -49,4 +50,9 @@ public class BulletInfo(BulletResource originalBulletResource)
|
|||
public Color PreFireColor { get; set; } = new Color(1, 0, 0, 0.5f);
|
||||
public Color LethalColor { get; set; } = new Color(1, 0, 0, 1.0f);
|
||||
#endregion
|
||||
|
||||
// Runtime: reference to the Weapon instance that fired this bullet.
|
||||
// This is NOT a Resource and will not be serialized; it simply lets
|
||||
// hit handlers attribute kills to a particular weapon instance.
|
||||
public Weapon3D SourceWeapon { get; set; }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue