30 lines
708 B
GDScript
30 lines
708 B
GDScript
class_name PokemonBox
|
|
extends Resource
|
|
|
|
#une boite du PC : un nombre fixe d'emplacements, chacun vide (null) ou occupe
|
|
|
|
var box_name : String = "" #vide = nom par defaut, a gerer par l'UI ("Boite 1"...)
|
|
var slots : Array[PokemonInstance] = []
|
|
|
|
func _init(p_size : int = 30) -> void:
|
|
slots.resize(p_size)
|
|
|
|
func size() -> int:
|
|
return slots.size()
|
|
|
|
func get_pokemon(slot : int) -> PokemonInstance:
|
|
return slots[slot] if slot >= 0 and slot < slots.size() else null
|
|
|
|
func first_free_slot() -> int:
|
|
for i in slots.size():
|
|
if slots[i] == null: return i
|
|
return -1
|
|
|
|
func is_full() -> bool:
|
|
return first_free_slot() == -1
|
|
|
|
func count() -> int:
|
|
var n : int = 0
|
|
for p in slots:
|
|
if p != null: n += 1
|
|
return n |