Hello Brian,
here it is. Just note that the previous image is StatsEquipableItem, not a WeaponConfig itself (even though it should inherit from it)
namespace Game.Combat
{
[CreateAssetMenu(fileName = "Weapon", menuName = "Items/Weapon", order = 0)]
public class WeaponConfig : EquipableItem, IModifierProvider
{
[SerializeField] private Weapon weaponPrefab = null;
[SerializeField] private AnimatorOverrideController weaponOverrideAnimatorController = null;
[SerializeField] private float weaponRange = 2f;
[SerializeField] private float weaponDamage = 10f;
[SerializeField] private float damageBonus = 0;
[SerializeField] private float percentageBonus = 0;
[SerializeField] private bool isRightHanded = true;
[SerializeField] private Missile missile = null;
private const string weaponName = "Weapon";
public Weapon Spawn(Transform rightHand, Transform leftHand, Animator animator)
{
DestroyPreviousWeapon(rightHand, leftHand);
Weapon weapon = null;
if (weaponPrefab != null)
{
Transform handTransform = GetHandTransform(rightHand, leftHand);
weapon = Instantiate(weaponPrefab, handTransform);
weapon.gameObject.name = weaponName;
}
var overrideController = animator.runtimeAnimatorController as AnimatorOverrideController;
if (weaponOverrideAnimatorController != null)
{
animator.runtimeAnimatorController = weaponOverrideAnimatorController;
}
else if (overrideController != null)
{
animator.runtimeAnimatorController = overrideController.runtimeAnimatorController;
}
return weapon;
}
private void DestroyPreviousWeapon(Transform rightHand, Transform leftHand)
{
Transform previousWeapon = rightHand.Find(weaponName);
if (previousWeapon == null)
{
previousWeapon = leftHand.Find(weaponName);
}
if (previousWeapon == null) return;
previousWeapon.name = "Weapon_DESTROYED";
Destroy(previousWeapon.gameObject);
}
private Transform GetHandTransform(Transform rightHand, Transform leftHand)
{
Transform handTransform;
if (isRightHanded)
{
handTransform = rightHand;
}
else
{
handTransform = leftHand;
}
return handTransform;
}
public float GetDamageBonus()
{
return damageBonus;
}
public float GetPercentageBonus()
{
return percentageBonus;
}
public float GetWeaponRange()
{
return weaponRange;
}
public float GetWeaponDamage()
{
return weaponDamage;
}
public bool HasMissile()
{
return missile != null;
}
public void LaunchMissile(Transform rightHand, Transform leftHand, Health target, GameObject instigator, float calculatedDamage)
{
Missile missileInstance = Instantiate(missile, GetHandTransform(rightHand, leftHand).position, Quaternion.identity);
missileInstance.SetTarget(target, instigator, calculatedDamage);
}
public IEnumerable<float> GetAdditiveModifiers(Stat stat)
{
if (stat == Stat.AttackDamage)
{
yield return weaponDamage;
}
}
public IEnumerable<float> GetPercentageModifiers(Stat stat)
{
if (stat == Stat.AttackDamage)
{
yield return percentageBonus;
}
}
}
}
namespace Game.Inventories
{
[CreateAssetMenu(menuName = ("Inventory/Stats Equipable Item"))]
public class StatsEquipableItem : EquipableItem, IModifierProvider
{
[SerializeField]
private Modifier[] additiveModifiers;
[SerializeField]
private Modifier[] percentageModifiers;
[System.Serializable]
private struct Modifier
{
public Stat stat;
public float value;
}
public IEnumerable<float> GetAdditiveModifiers(Stat stat)
{
foreach (var modifier in additiveModifiers)
{
if (modifier.stat == stat)
{
yield return modifier.value;
}
}
}
public IEnumerable<float> GetPercentageModifiers(Stat stat)
{
foreach (var modifier in percentageModifiers)
{
if (modifier.stat == stat)
{
yield return modifier.value;
}
}
}
}
}
It should be identicatl with the code that is available in github repo.
Thank you for reaching out so fast.