Use typed item keys in behavior item refs
This commit is contained in:
parent
df59a9da62
commit
95bd76ee91
10 changed files with 48 additions and 24 deletions
|
|
@ -84,7 +84,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
OnStopFiring?.Invoke();
|
||||
return false;
|
||||
}
|
||||
if (_data.AmmoType != Guid.Empty)
|
||||
if (!string.IsNullOrWhiteSpace(_data.AmmoItemKey))
|
||||
{
|
||||
if (_reloading)
|
||||
{
|
||||
|
|
@ -104,10 +104,10 @@ public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
if (_data.MagazineSize > 1 && _ammo > 0) _ammo--;
|
||||
else
|
||||
{
|
||||
var cargo = Entity.FindItemInCargo(_data.AmmoType);
|
||||
var cargo = Entity.FindItemInCargo(_data.AmmoItemKey);
|
||||
if (cargo != null)
|
||||
{
|
||||
var item = cargo.GetFirstItem(_data.AmmoType);
|
||||
var item = cargo.GetFirstItem(_data.AmmoItemKey);
|
||||
if (item is SimpleCommodity simpleCommodity)
|
||||
cargo.Remove(simpleCommodity, 1);
|
||||
|
||||
|
|
|
|||
|
|
@ -127,12 +127,12 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
}
|
||||
|
||||
var hasAmmo = true;
|
||||
if (_data.AmmoType != Guid.Empty)
|
||||
if (!string.IsNullOrWhiteSpace(_data.AmmoItemKey))
|
||||
{
|
||||
var cargo = Entity.FindItemInCargo(_data.AmmoType);
|
||||
var cargo = Entity.FindItemInCargo(_data.AmmoItemKey);
|
||||
if (cargo != null)
|
||||
{
|
||||
var item = cargo.GetFirstItem(_data.AmmoType);
|
||||
var item = cargo.GetFirstItem(_data.AmmoItemKey);
|
||||
if (item is SimpleCommodity simpleCommodity)
|
||||
cargo.Remove(simpleCommodity, 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ using System.Linq;
|
|||
[Inspectable, Order(-5)]
|
||||
public class ItemUsageConfig : RuntimeBehaviorConfig
|
||||
{
|
||||
public Guid Item;
|
||||
public string ItemKey;
|
||||
public Guid Item => AetheriaRuntimeItemReference.ToLegacyId(ItemKey);
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
|
|
@ -36,10 +37,10 @@ public class ItemUsage : Behavior
|
|||
|
||||
public override bool Execute(float dt)
|
||||
{
|
||||
var cargo = Entity.FindItemInCargo(_data.Item);
|
||||
var cargo = Entity.FindItemInCargo(_data.ItemKey);
|
||||
if (cargo == null) return false;
|
||||
|
||||
var item = cargo.GetFirstItem(_data.Item);
|
||||
var item = cargo.GetFirstItem(_data.ItemKey);
|
||||
if (item is SimpleCommodity simpleCommodity)
|
||||
cargo.Remove(simpleCommodity, 1);
|
||||
if (item is CraftedItemInstance craftedItemInstance)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ public abstract class WeaponConfig : RuntimeBehaviorConfig
|
|||
|
||||
[InspectablePrefab]
|
||||
public PerformanceStat Visibility = new PerformanceStat();
|
||||
public Guid AmmoType;
|
||||
public string AmmoItemKey;
|
||||
public Guid AmmoType => AetheriaRuntimeItemReference.ToLegacyId(AmmoItemKey);
|
||||
|
||||
[InspectablePrefab]
|
||||
public int MagazineSize;
|
||||
|
|
@ -69,9 +70,10 @@ public abstract class Weapon : Behavior, IActivatedBehavior
|
|||
public abstract int Ammo { get; }
|
||||
public DamageType DamageType { get; }
|
||||
public string EffectPrefab { get; }
|
||||
public string AmmoItemKey { get; }
|
||||
public Guid AmmoType { get; }
|
||||
public int MagazineSize { get; }
|
||||
public bool UsesAmmo => AmmoType != Guid.Empty;
|
||||
public bool UsesAmmo => !string.IsNullOrWhiteSpace(AmmoItemKey);
|
||||
public GuidedProjectileTargetMode GuidedProjectileTargeting { get; private set; }
|
||||
public bool HasGuidedProjectileProfile => GuidedProjectileTargeting != GuidedProjectileTargetMode.None;
|
||||
public float4[] GuidedProjectileGuidanceCurve { get; private set; }
|
||||
|
|
@ -102,6 +104,7 @@ public abstract class Weapon : Behavior, IActivatedBehavior
|
|||
_data = data;
|
||||
DamageType = data.DamageType;
|
||||
EffectPrefab = data.EffectPrefab ?? "";
|
||||
AmmoItemKey = data.AmmoItemKey;
|
||||
AmmoType = data.AmmoType;
|
||||
MagazineSize = data.MagazineSize;
|
||||
InitializeGuidedProjectileProfile(data);
|
||||
|
|
@ -112,6 +115,7 @@ public abstract class Weapon : Behavior, IActivatedBehavior
|
|||
_data = data;
|
||||
DamageType = data.DamageType;
|
||||
EffectPrefab = data.EffectPrefab ?? "";
|
||||
AmmoItemKey = data.AmmoItemKey;
|
||||
AmmoType = data.AmmoType;
|
||||
MagazineSize = data.MagazineSize;
|
||||
InitializeGuidedProjectileProfile(data);
|
||||
|
|
|
|||
Loading…
Reference in a new issue