using UnityEngine;
[CreateAssetMenu(fileName = "New Weapon", menuName = "RPG/Items/Weapon")]
[System.Serializable]
public class WeaponItem : Item
{
[Header("Weapon Stats")]
public int minDamage;
public int maxDamage;
public int range;
public int weaponModifier;
public float attackSpeed;
public WeaponType weaponType;
[Header("Weapon Behavior")]
// weaponClassName is no longer needed - behavior determined by weaponType enum
[Header("Weapon Prefabs")]
public GameObject weaponPrefab; // 3D model prefab for the weapon
public GameObject arrowPrefab; // For ranged weapons
public WeaponItem()
{
itemType = ItemType.Weapon;
}
///
/// Creates an actual Weapon component instance from this WeaponItem data
/// This is the updated method that works with the enhanced weapon classes
///
/// Parent transform to attach the weapon to
/// The instantiated Weapon component
public Weapon CreateWeaponInstance(Transform parent)
{
GameObject weaponObject = new GameObject(itemName);
weaponObject.transform.SetParent(parent, false);
// Use GenericWeapon for all weapons - it will configure itself based on WeaponType
GenericWeapon weaponComponent = weaponObject.AddComponent();
if (weaponComponent != null)
{
weaponComponent.InitializeFromItem(this);
Debug.Log($"Created weapon instance: {itemName} of type {weaponType}");
}
else
{
Debug.LogError($"Failed to create GenericWeapon component for: {itemName}");
DestroyImmediate(weaponObject);
return null;
}
return weaponComponent;
}
public override bool MatchesSearch(string searchTerm)
{
if (base.MatchesSearch(searchTerm)) return true;
// Additional weapon-specific search terms
if (string.IsNullOrEmpty(searchTerm)) return true;
searchTerm = searchTerm.ToLower();
// Check weapon type
if (weaponType.ToString().ToLower().Contains(searchTerm)) return true;
return false;
}
}
[System.Serializable]
public enum WeaponType
{
Fists,
Sword,
Bow,
Crossbow,
Dagger,
Mace,
Staff,
Spear,
Axe,
Hammer
}