| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- using UnityEngine;
- /// <summary>
- /// A single weapon class that can handle all weapon types through configuration
- /// </summary>
- 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
- }
|