mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Weapon evolution
This commit is contained in:
parent
8492c3644b
commit
f58b9646df
10 changed files with 209 additions and 68 deletions
|
|
@ -32,6 +32,9 @@ public partial class Weapon3D : Node3D
|
|||
[Signal]
|
||||
public delegate void InitializedEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void EvolvedEventHandler(WeaponResource newWeaponResource);
|
||||
|
||||
public int Ammo { get; set; } = 0;
|
||||
|
||||
private int _loadedAmmo;
|
||||
|
|
@ -59,6 +62,9 @@ public partial class Weapon3D : Node3D
|
|||
|
||||
private WeaponAmmoType _ammoType = WeaponAmmoType.Infinite;
|
||||
|
||||
// Runtime experience for this weapon instance (NOT stored in resources)
|
||||
private int _currentExperience = 0;
|
||||
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
|
|
@ -150,6 +156,42 @@ public partial class Weapon3D : Node3D
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add experience to this weapon instance. When reaching the threshold defined on the WeaponResource,
|
||||
/// evolve into the configured NextLevelWeapon. Resources are not mutated; the instance swaps its reference
|
||||
/// to the next-tier Resource to reflect the new behavior.
|
||||
/// </summary>
|
||||
/// <param name="amount">Amount of experience to add (positive integer)</param>
|
||||
public void GainExperience(int amount)
|
||||
{
|
||||
if (amount <= 0) return;
|
||||
if (WeaponData == null) return;
|
||||
|
||||
// If weapon has no progression, ignore
|
||||
if (WeaponData.ExperienceToNextLevel <= 0 || WeaponData.NextLevelWeapon == null) return;
|
||||
|
||||
_currentExperience += amount;
|
||||
|
||||
while (WeaponData.ExperienceToNextLevel > 0 && _currentExperience >= WeaponData.ExperienceToNextLevel)
|
||||
{
|
||||
// Evolve
|
||||
_currentExperience -= WeaponData.ExperienceToNextLevel;
|
||||
|
||||
var next = WeaponData.NextLevelWeapon;
|
||||
if (next == null) break;
|
||||
|
||||
WeaponData = next;
|
||||
|
||||
// Re-init to apply new capacities / rates
|
||||
Init();
|
||||
|
||||
EmitSignalEvolved(next);
|
||||
|
||||
// Continue loop in case the new tier also has immediate threshold
|
||||
if (WeaponData.ExperienceToNextLevel <= 0 || WeaponData.NextLevelWeapon == null) break;
|
||||
}
|
||||
}
|
||||
|
||||
private bool HandlePreShoot()
|
||||
{
|
||||
// Waiting on reload or Rate of Fire cooldown?
|
||||
|
|
@ -243,6 +285,9 @@ public partial class Weapon3D : Node3D
|
|||
GetBulletStrengthMultiplier(bulletData.Damage, bulletData.OriginalBulletResource.MaxDamage, 20);
|
||||
}
|
||||
|
||||
// Associate the bullet with this weapon instance so kills can be attributed
|
||||
bulletData.SourceWeapon = this;
|
||||
|
||||
bullet.Initialize(bulletData);
|
||||
|
||||
//bullet.SetDirection(ShootDirection);
|
||||
|
|
@ -252,12 +297,6 @@ public partial class Weapon3D : Node3D
|
|||
|
||||
|
||||
|
||||
//_inventoryManager.NotifyLoadedAmmoChange(WeaponData.ItemKey, LoadedAmmo);
|
||||
// if (!string.IsNullOrWhiteSpace(WeaponData?.AmmoKey))
|
||||
// {
|
||||
// // Notify hud to decrease weapon
|
||||
//
|
||||
// }
|
||||
|
||||
if (_ammoType is WeaponAmmoType.Ammo && WeaponData.AutoReload && LoadedAmmo < WeaponData.AmmoPerShot)
|
||||
{
|
||||
|
|
@ -280,11 +319,11 @@ public partial class Weapon3D : Node3D
|
|||
return Mathf.Lerp(minMultiplier, maxMultiplier, normalizedPower);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
public new void Hide()
|
||||
{
|
||||
}
|
||||
|
||||
public void Show()
|
||||
public new void Show()
|
||||
{
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue