extends Node3D
class_name Weapon

const MAX_CLIP = 5
var damage = 25
var clip = 444444
@export var initialPos : Transform3D
@export var transition_speed = 1.0
var initialTransform : Transform3D


const DEFAULT = 0
const INITIAL = 1
const SHOOT = 2
const RELOAD = 3

var state = DEFAULT

func _ready():
	var tween = create_tween()
	tween.set_trans(Tween.TRANS_CIRC)
	tween.set_ease(Tween.EASE_IN_OUT)
	tween.tween_callback(InitialPos).set_delay(2)
	
	
func InitialPos():
	var tween = create_tween()
	tween.set_trans(Tween.TRANS_CIRC)
	tween.set_ease(Tween.EASE_IN_OUT)
	tween.set_parallel(true)
	tween.tween_property($Revolver, "position", initialPos.origin, 0.4)
	tween.tween_property($Revolver, "rotation", Vector3.ZERO, 0.4)
	tween.tween_callback(func(): state = INITIAL).set_delay(0.3)



func Shoot():
	if clip > 0 && state == INITIAL:
		clip -= 1
		state = SHOOT;
		var tween = create_tween()
		tween.set_trans(Tween.TRANS_ELASTIC)
		tween.set_ease(Tween.EASE_OUT)
		tween.set_parallel(true)
		tween.tween_property($Revolver, "position", get_node("Revolver").transform.origin + Vector3(.0, 0.3, -.3), 0.3)
		tween.tween_property($Revolver, "rotation", Vector3(deg_to_rad(-60),.0,.0),0.3)
		tween.tween_callback(InitialPos).set_delay(0.3)
		return true
	return false

	

func Reload():
	if(clip < MAX_CLIP && state == INITIAL):
		state = RELOAD
		
		return true
	return false
