67 lines
1.8 KiB
GDScript
67 lines
1.8 KiB
GDScript
extends StaticBody3D
|
|
|
|
@onready var player: CharacterBody3D = get_tree().get_first_node_in_group("player")
|
|
@onready var player_ray: RayCast3D = get_tree().get_first_node_in_group("player_ray")
|
|
@onready var construct: Node3D = get_tree().get_first_node_in_group("Constructs")
|
|
@onready var item_1: StaticBody3D = $ItemStand1
|
|
|
|
var empty_slot: bool = false
|
|
var number: int = 1
|
|
var con_num: int = 0
|
|
var item
|
|
var item2
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
if has_node("InteractLabel"):
|
|
if player_ray.is_colliding() and player_ray.get_collider() == self:
|
|
$InteractLabel.show()
|
|
else:
|
|
$InteractLabel.hide()
|
|
|
|
func interact():
|
|
if (item == "stick" and item2 == "weight") or (item == "weight" and item2 == "stick"):
|
|
if !construct.constructs["hammer"]:
|
|
crafting("hammer")
|
|
else:
|
|
crafting(null)
|
|
|
|
elif (item == "stick" and item2 == "light") or (item == "light" and item2 == "stick"):
|
|
if !construct.constructs["flashlight"]:
|
|
crafting("flashlight")
|
|
else:
|
|
crafting(null)
|
|
|
|
else:
|
|
crafting(null)
|
|
|
|
|
|
func crafting(con_name):
|
|
if con_name != null:
|
|
$InteractLabel.hide()
|
|
construct.constructs[con_name] = true
|
|
player.get_node("Inventory/" + con_name.capitalize() + "Button").visible = true
|
|
find_empty_slot(con_name)
|
|
construct.set_construct(con_num, con_name)
|
|
$CraftLabel.text = con_name + " Get!"
|
|
else:
|
|
$CraftLabel.text = "Nothing to craft!"
|
|
|
|
$CraftLabel.show()
|
|
await get_tree().create_timer(3, false).timeout
|
|
$CraftLabel.hide()
|
|
|
|
func find_empty_slot(con_name):
|
|
|
|
while empty_slot == false and number < 11:
|
|
if construct.assigned_slot[number] != null:
|
|
number += 1
|
|
else:
|
|
construct.assigned_slot[number] = con_name
|
|
con_num = number
|
|
player.get_node("Inventory/" + con_name.capitalize() + "Button/SlotLabel").text = str(number)
|
|
empty_slot = true
|
|
|
|
number = 1
|
|
empty_slot = false
|
|
print(construct.assigned_slot)
|