class_name Gun extends Node

@onready var empty = preload("res://scripts/item/bullet/Empty/empty.gd")

const maxMagazineSize: int = 12
const minMagazineSize: int = 2
var magazineSize: int = 6

var loadedBullets: int = 0

var magazin: Array[Bullet]

var mainOwner: Player

func setOwner(_player: Player) -> void:
	mainOwner = _player

func loadBullet(_bullet: Bullet):
	if magazin.size() + 1 <= magazineSize:
		magazin.append(_bullet)

func fillEmpty():
	if magazin.size() < magazineSize:
		for i in range(0, magazineSizeLeft()):
			loadBullet(Empty.new())

func resetMagazine():
	magazin = []

func getRandomBullet() -> Bullet:
	fillEmpty()
	var randomBullet = magazin.pick_random()
	magazin.erase(randomBullet)
	return randomBullet

func getBulletAmount() -> int:
	return magazin.size()

func magazineSizeLeft() -> int:
	return magazineSize - magazin.size()
