extends Area2D

var type = 0
var desired_drink = 0
var rng = RandomNumberGenerator.new()
var candrink = false

func take_drink():
	if !candrink:
		for i in get_overlapping_bodies():
			if i.name == "Player":
				if i.inventory.has(desired_drink):
					for slot in range(3): 
						if i.inventory[slot] == desired_drink: 
							i.inventory[slot] = 0
							i.inventory_change(0, slot)
							print(self.name + " took a drink " + str(i.inventory))
							candrink = true
							break
				else: 
					get_node("Bubble").visible = true
					match(desired_drink):
						1:
							get_node("Bubble").get_node("0").visible = true
						2:
							get_node("Bubble").get_node("1").visible = true
						3:
							get_node("Bubble").get_node("2").visible = true
	if candrink: drink()

func drink():
	
	get_node("Bubble").get_node("Heart").visible = true
	
	match(type):
		0:
			get_node("Body").animation = "DrinkH"
		1:
			get_node("Body").animation = "DrinkN"
		2: 
			get_node("Body").animation = "DrinkM"
	yield(get_tree().create_timer(15.0 + rng.randf_range(-10, 3)), "timeout")
	pay()
	queue_free()
	
	pass

func pay():
	get_parent().get_parent().get_parent().get_node("Player").monet += 10
	get_parent().get_parent().get_parent().get_node("Player").get_node("Camera2D").get_node("UI").get_node("HBoxContainer").get_node("Label").update()
	pass

func _ready():
	rng.randomize()
	desired_drink = rng.randi_range(1, 3)
	pass

