using UnityEngine;

namespace pdinklag.CPW.Common
{
    public class WeaponPrefab : MonoBehaviour
    {
        public delegate void AwakeListener(WeaponPrefab weaponPrefab);
        public static AwakeListener OnAwake;

        [Header("General")]
        [Tooltip("The address of the weapon's descriptor, if any.")]
        public AssetAddress Descriptor;

        [Tooltip("The weapon type.")]
        public WeaponType Type = WeaponType.Stick;

        [Header("Attachment")]
        [Tooltip("The local transform that attaches to the given POI, also controlling the weapon's rotation when held.")]
        public Transform AttachPoint;

        [Tooltip("The POI on the bearer's body to attach the weapon to.")]
        public BodyPOI POI = BodyPOI.RightHandPalm;

        [Tooltip("Center the attachment transform between the POI and second POI.")]
        public bool Center;

        [Tooltip("When centering, use this as the second POI on the bearer.")]
        public BodyPOI SecondPOI = BodyPOI.LeftHandPalm;

        [Header("Interaction")]
        [Tooltip("While not being carried, consider these objects to be walkable ground.")]
        public Transform[] GroundTransforms;

        [Tooltip("If set, wrestlers can be rolled on this weapon to this target position (if unfolded).")]
        public Transform RollOnTarget;

        [Tooltip("If set, this weapon will carve into the navigation mesh for AI wrestlers (if unfolded).")]
        public bool AIObstacle;

        [Tooltip("Can this weapon be picked up?")]
        public bool CanBePickedUp = true;

        [Tooltip("If this weapon is the result of another weapon breaking, this is the piece the former bearer holds on to.")]
        public bool HoldOnTo;

        [Tooltip("When this weapon is being placed on the floor, apply this local rotation before placing.")]
        public Vector3 FloorPlacementRotation = Vector3.zero;

        [Tooltip("When this weapon is being placed on a higher level, apply this local rotation before placing.")]
        public Vector3 HighPlacementRotation = Vector3.zero;

        [Tooltip("When placing this weapon on top of the same kind of weapon, align them properly.")]
        public bool AllowStackPlacement;

        [Header("Folding")]
        [Tooltip("Is this weapon foldable (e.g., a table or chair)?")]
        public bool Foldable;

        [Tooltip("The animation trigger to be fired when the weapon is folded.")]
        public string FoldAnimTrigger = "Fold";

        [Tooltip("The animation trigger to be fired when the weapon is unfolded.")]
        public string UnfoldAnimTrigger = "Unfold";

        [Tooltip("The colliders to activate when the weapon is folded and deactivate when it is unfolded.")]
        public Collider[] FoldedColliders;

        [Tooltip("The colliders to activate when the weapon is unfolded and deactivate when it is folded.")]
        public Collider[] UnfoldedColliders;

        [Header("IK")]
        [Tooltip("The IK target for the main hand, if any.")]
        public Transform MainHandTarget;

        [Tooltip("The IK target for the off-hand, if any.")]
        public Transform OffHandTarget;

        [Header("Damage")]
        [Tooltip("When hitting a strike with this weapon, multiply damage by this.")]
        public float DamageMultiplier = 1.0f;

        [Tooltip("When hitting a strike with this weapon, use this damage type.")]
        public AssetAddress DamageType;

        [Header("Breaking")]
        [Tooltip("How many hits can be landed with this weapon before it is automatically dropped (0 = infinite).")]
        public int AutoDropHits = 5;

        [Tooltip("How many hits this weapon survives before breaking (0 = infinite).")]
        public int HitPoints;

        [Tooltip("The impulse required by a wrestler falling into this weapon so that it breaks.")]
        public float BreakImpulse = Mathf.Infinity;

        [Tooltip("The prefab to spawn in place of the weapon when it breaks.")]
        public AssetAddress BrokenPrefab;

        [Tooltip("The sound group to play when the weapon breaks.")]
        public AssetAddress BreakSound;

        [Tooltip("The damage applied to the wrestler who breaks the weapon due to an impact.")]
        public float BreakDamage;

        [Tooltip("The damage applied to the wrestler who breaks the weapon due to an impact.")]
        public AssetAddress BreakDamageType;

        [Tooltip("Is this a broken weapon that AI players should get rid of?")]
        public bool IsBroken;

        private void Awake()
        {
            OnAwake?.Invoke(this);
        }
    }
}
