using UnityEngine; /// /// A single weapon class that can handle all weapon types through configuration /// public class GenericWeapon : Weapon { [Header("Weapon Configuration")] public WeaponBehaviorType behaviorType; public GameObject arrowPrefab; // For ranged weapons private WeaponItem weaponData; // Implement abstract properties from Weapon base class public override int MinDamage => weaponData?.minDamage ?? 1; public override int MaxDamage => weaponData?.maxDamage ?? 1; public override int Range => weaponData?.range ?? 1; public override int WeaponModifier { get => weaponData?.weaponModifier ?? 0; set => weaponModifier = value; // Set the base class field } public void InitializeFromItem(WeaponItem item) { weaponData = item; // Set basic weapon properties weaponName = item.itemName; description = item.description; attackSpeed = item.attackSpeed; // Determine behavior type from weapon data DetermineBehaviorType(item); // Initialize based on behavior InitializeBehavior(item); } private void DetermineBehaviorType(WeaponItem item) { // Determine behavior based on WeaponType enum or weapon name switch (item.weaponType) { case WeaponType.Fists: behaviorType = WeaponBehaviorType.Melee; break; case WeaponType.Bow: case WeaponType.Crossbow: behaviorType = WeaponBehaviorType.Ranged; if (item.arrowPrefab != null) arrowPrefab = item.arrowPrefab; break; case WeaponType.Sword: case WeaponType.Axe: case WeaponType.Mace: case WeaponType.Hammer: case WeaponType.Spear: behaviorType = WeaponBehaviorType.Melee; break; case WeaponType.Staff: behaviorType = WeaponBehaviorType.Magic; break; case WeaponType.Dagger: behaviorType = WeaponBehaviorType.FastMelee; break; default: behaviorType = WeaponBehaviorType.Melee; break; } } private void InitializeBehavior(WeaponItem item) { // Set weapon stats from item data // Assuming Weapon base class has these properties // You'll need to adjust based on your actual Weapon class structure // Example initialization: // damage = Random.Range(item.minDamage, item.maxDamage + 1); // range = item.range; // attackSpeed = item.attackSpeed; // Initialize specific behavior patterns switch (behaviorType) { case WeaponBehaviorType.Ranged: InitializeRangedWeapon(item); break; case WeaponBehaviorType.FastMelee: InitializeFastMeleeWeapon(item); break; case WeaponBehaviorType.Magic: InitializeMagicWeapon(item); break; default: InitializeMeleeWeapon(item); break; } } private void InitializeMeleeWeapon(WeaponItem item) { // Standard melee weapon setup } private void InitializeRangedWeapon(WeaponItem item) { // Ranged weapon setup if (arrowPrefab == null && item.arrowPrefab != null) { arrowPrefab = item.arrowPrefab; } } private void InitializeFastMeleeWeapon(WeaponItem item) { // Fast attack weapon setup (daggers, etc.) } private void InitializeMagicWeapon(WeaponItem item) { // Magic weapon setup (staffs, etc.) } // Override attack method to add behavior-specific logic public override void Attack(GameObject target) { // Call the base attack method first (handles all the standard logic) base.Attack(target); // Add any behavior-specific effects here if needed switch (behaviorType) { case WeaponBehaviorType.Ranged: // Could add special ranged effects here break; case WeaponBehaviorType.FastMelee: // Could add fast attack effects here break; case WeaponBehaviorType.Magic: // Could add magic effects here break; default: // Standard melee behavior break; } } } [System.Serializable] public enum WeaponBehaviorType { Melee, Ranged, FastMelee, Magic }