Move weapon effect binding behind runtime owner
This commit is contained in:
parent
f151ecedc1
commit
63fe87a91b
9 changed files with 40 additions and 32 deletions
Binary file not shown.
|
|
@ -51,8 +51,8 @@ public class EntityInstance : MonoBehaviour
|
|||
// private (Reactor reactor, GameObject sfxSource) _reactor;
|
||||
// private Dictionary<Radiator, GameObject> _radiatorSfx = new Dictionary<Radiator, GameObject>();
|
||||
|
||||
private static Dictionary<InstantWeaponData, InstantWeaponEffectManager> _instantWeaponManagers = new Dictionary<InstantWeaponData, InstantWeaponEffectManager>();
|
||||
private static Dictionary<ConstantWeaponData, ConstantWeaponEffectManager> _constantWeaponManagers = new Dictionary<ConstantWeaponData, ConstantWeaponEffectManager>();
|
||||
private static Dictionary<string, InstantWeaponEffectManager> _instantWeaponManagers = new Dictionary<string, InstantWeaponEffectManager>();
|
||||
private static Dictionary<string, ConstantWeaponEffectManager> _constantWeaponManagers = new Dictionary<string, ConstantWeaponEffectManager>();
|
||||
|
||||
public static void ClearWeaponManagers()
|
||||
{
|
||||
|
|
@ -217,23 +217,23 @@ public class EntityInstance : MonoBehaviour
|
|||
|
||||
if (behavior is InstantWeapon instantWeapon)
|
||||
{
|
||||
var data = (InstantWeaponData) instantWeapon.Data;
|
||||
if (!_instantWeaponManagers.ContainsKey(data))
|
||||
var effectPrefab = instantWeapon.EffectPrefab;
|
||||
if (!_instantWeaponManagers.ContainsKey(effectPrefab))
|
||||
{
|
||||
var managerPrefab = UnityHelpers.LoadAsset<InstantWeaponEffectManager>(data.EffectPrefab);
|
||||
var managerPrefab = UnityHelpers.LoadAsset<InstantWeaponEffectManager>(effectPrefab);
|
||||
if(managerPrefab)
|
||||
{
|
||||
_instantWeaponManagers.Add(data, Instantiate(managerPrefab, EffectManagerParent));
|
||||
_instantWeaponManagers.Add(effectPrefab, Instantiate(managerPrefab, EffectManagerParent));
|
||||
}
|
||||
else Debug.LogError($"No InstantWeaponEffectManager prefab found at path {data.EffectPrefab}");
|
||||
else Debug.LogError($"No InstantWeaponEffectManager prefab found at path {effectPrefab}");
|
||||
}
|
||||
|
||||
instantWeapon.OnFire += () =>
|
||||
_instantWeaponManagers[data].Fire(instantWeapon, item, this, entity.Target.Value != null && ZoneRenderer.EntityInstances.ContainsKey(entity.Target.Value) ? ZoneRenderer.EntityInstances[entity.Target.Value] : null);
|
||||
_instantWeaponManagers[effectPrefab].Fire(instantWeapon, item, this, entity.Target.Value != null && ZoneRenderer.EntityInstances.ContainsKey(entity.Target.Value) ? ZoneRenderer.EntityInstances[entity.Target.Value] : null);
|
||||
|
||||
if (behavior is ChargedWeapon chargedWeapon)
|
||||
{
|
||||
var chargeManager = _instantWeaponManagers[data].GetComponent<ChargeEffectManager>();
|
||||
var chargeManager = _instantWeaponManagers[effectPrefab].GetComponent<ChargeEffectManager>();
|
||||
if (chargeManager)
|
||||
{
|
||||
chargedWeapon.OnStartCharging += () => chargeManager.StartCharging(chargedWeapon, item, this);
|
||||
|
|
@ -246,21 +246,21 @@ public class EntityInstance : MonoBehaviour
|
|||
|
||||
if (behavior is ConstantWeapon constantWeapon)
|
||||
{
|
||||
var data = (ConstantWeaponData) constantWeapon.Data;
|
||||
if (!_constantWeaponManagers.ContainsKey(data))
|
||||
var effectPrefab = constantWeapon.EffectPrefab;
|
||||
if (!_constantWeaponManagers.ContainsKey(effectPrefab))
|
||||
{
|
||||
var managerPrefab = UnityHelpers.LoadAsset<ConstantWeaponEffectManager>(data.EffectPrefab);
|
||||
var managerPrefab = UnityHelpers.LoadAsset<ConstantWeaponEffectManager>(effectPrefab);
|
||||
if(managerPrefab)
|
||||
{
|
||||
_constantWeaponManagers.Add(data, Instantiate(managerPrefab, EffectManagerParent));
|
||||
_constantWeaponManagers.Add(effectPrefab, Instantiate(managerPrefab, EffectManagerParent));
|
||||
}
|
||||
else Debug.LogError($"No ConstantWeaponEffectManager prefab found at path {data.EffectPrefab}");
|
||||
else Debug.LogError($"No ConstantWeaponEffectManager prefab found at path {effectPrefab}");
|
||||
}
|
||||
|
||||
constantWeapon.OnStartFiring += () =>
|
||||
_constantWeaponManagers[data].StartFiring(data, item, this, entity.Target.Value != null ? ZoneRenderer.EntityInstances[entity.Target.Value] : null);
|
||||
_constantWeaponManagers[effectPrefab].StartFiring(constantWeapon, item, this, entity.Target.Value != null ? ZoneRenderer.EntityInstances[entity.Target.Value] : null);
|
||||
constantWeapon.OnStopFiring += () =>
|
||||
_constantWeaponManagers[data].StopFiring(item);
|
||||
_constantWeaponManagers[effectPrefab].StopFiring(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,21 +8,21 @@ public class ConstantLaserManager : ConstantWeaponEffectManager
|
|||
|
||||
private Dictionary<EquippedItem, ConstantLaser> _lasers = new Dictionary<EquippedItem, ConstantLaser>();
|
||||
|
||||
public override void StartFiring(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
public override void StartFiring(ConstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
{
|
||||
var p = LaserPrototype.Instantiate<ConstantLaser>();
|
||||
p.SourceEntity = source.Entity;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.Range = item.Evaluate(data.Range);
|
||||
p.Range = weapon.Range;
|
||||
var t = p.transform;
|
||||
t.SetParent(barrel);
|
||||
t.forward = barrel.forward;
|
||||
t.position = barrel.position;
|
||||
p.Damage = item.Evaluate(data.Damage);
|
||||
p.Penetration = item.Evaluate(data.Penetration);
|
||||
p.Spread = item.Evaluate(data.DamageSpread);
|
||||
p.DamageType = data.DamageType;
|
||||
p.Damage = weapon.Damage;
|
||||
p.Penetration = weapon.Penetration;
|
||||
p.Spread = weapon.DamageSpread;
|
||||
p.DamageType = weapon.DamageType;
|
||||
_lasers.Add(item, p);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,18 +9,18 @@ public class ConstantLightningManager : ConstantWeaponEffectManager
|
|||
|
||||
private Dictionary<EquippedItem, ConstantLightning> _bolts = new Dictionary<EquippedItem, ConstantLightning>();
|
||||
|
||||
public override void StartFiring(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
public override void StartFiring(ConstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
{
|
||||
var p = LightningPrototype.Instantiate<ConstantLightning>();
|
||||
p.Source = source;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.Barrel = barrel;
|
||||
p.Damage = item.Evaluate(data.Damage);
|
||||
p.Range = item.Evaluate(data.Range);
|
||||
p.Penetration = item.Evaluate(data.Penetration);
|
||||
p.Spread = item.Evaluate(data.DamageSpread);
|
||||
p.DamageType = data.DamageType;
|
||||
p.Damage = weapon.Damage;
|
||||
p.Range = weapon.Range;
|
||||
p.Penetration = weapon.Penetration;
|
||||
p.Spread = weapon.DamageSpread;
|
||||
p.DamageType = weapon.DamageType;
|
||||
_bolts.Add(item, p);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ public class ConstantParticleWeaponManager : ConstantWeaponEffectManager
|
|||
|
||||
private Dictionary<EquippedItem, ConstantParticleWeapon> _weapons = new Dictionary<EquippedItem, ConstantParticleWeapon>();
|
||||
|
||||
public override void StartFiring(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
public override void StartFiring(ConstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
{
|
||||
var p = WeaponPrototype.Instantiate<ConstantParticleWeapon>();
|
||||
p.Source = source;
|
||||
|
|
@ -19,8 +19,8 @@ public class ConstantParticleWeaponManager : ConstantWeaponEffectManager
|
|||
t.SetParent(barrel);
|
||||
t.forward = barrel.forward;
|
||||
t.position = barrel.position;
|
||||
p.Damage = item.Evaluate(data.Damage);
|
||||
p.DamageType = data.DamageType;
|
||||
p.Damage = weapon.Damage;
|
||||
p.DamageType = weapon.DamageType;
|
||||
_weapons.Add(item, p);
|
||||
p.Initialize();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ using UnityEngine;
|
|||
|
||||
public abstract class ConstantWeaponEffectManager : MonoBehaviour
|
||||
{
|
||||
public abstract void StartFiring(WeaponData data, EquippedItem item, EntityInstance source, EntityInstance target);
|
||||
public abstract void StartFiring(ConstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target);
|
||||
public abstract void StopFiring(EquippedItem item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
{
|
||||
if(!_firing && !_reloading)
|
||||
{
|
||||
UpdateStats();
|
||||
_firing = true;
|
||||
OnStartFiring?.Invoke();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ public abstract class Weapon : Behavior, IActivatedBehavior
|
|||
public abstract int Ammo { get; }
|
||||
public WeaponData WeaponData => _data;
|
||||
public DamageType DamageType { get; }
|
||||
public string EffectPrefab { get; }
|
||||
|
||||
public float Damage { get; protected set; }
|
||||
public float Penetration { get; protected set; }
|
||||
|
|
@ -92,12 +93,14 @@ public abstract class Weapon : Behavior, IActivatedBehavior
|
|||
{
|
||||
_data = data;
|
||||
DamageType = data.DamageType;
|
||||
EffectPrefab = data.EffectPrefab ?? "";
|
||||
}
|
||||
|
||||
public Weapon(WeaponData data, ConsumableItemEffect item) : base(data, item)
|
||||
{
|
||||
_data = data;
|
||||
DamageType = data.DamageType;
|
||||
EffectPrefab = data.EffectPrefab ?? "";
|
||||
}
|
||||
|
||||
protected virtual void UpdateStats()
|
||||
|
|
|
|||
|
|
@ -1003,6 +1003,10 @@ First Aetheria surfaces to publish:
|
|||
- Done: move projectile, hitscan, beam, lightning, and mine effect damage
|
||||
type reads off `WeaponData` and onto `Weapon.DamageType`; effect managers
|
||||
consume live weapon metadata instead of config DTO fields.
|
||||
- Done: move weapon effect prefab lookup and constant weapon visual startup
|
||||
off `InstantWeaponData`/`ConstantWeaponData`; `EntityInstance` caches
|
||||
managers by `Weapon.EffectPrefab`, and constant effect managers consume
|
||||
live `ConstantWeapon` stats.
|
||||
- Done: delete the legacy `Behaviors` lists from `ConsumableItemData` and
|
||||
`EquippableItemData`; item DTOs can no longer carry behavior config state.
|
||||
- Done: move runtime blueprint price aggregation and conductivity restore
|
||||
|
|
|
|||
Loading…
Reference in a new issue