wip sell boxes and sell mechanics, move coins to inventory items

This commit is contained in:
veclavtalica 2025-02-13 19:11:57 +03:00
parent 9747bf4d61
commit 16be17ba73
11 changed files with 69 additions and 15 deletions

13
data/coin.tres Normal file
View File

@ -0,0 +1,13 @@
[gd_resource type="Resource" script_class="InventoryItem" load_steps=3 format=3 uid="uid://dbxrlw5ggh67j"]
[ext_resource type="Texture2D" uid="uid://cb6qv3c0iojfl" path="res://icon.svg" id="1_eakc4"]
[ext_resource type="Script" path="res://src/lib/inventory_item.gd" id="2_lrh23"]
[resource]
script = ExtResource("2_lrh23")
icon = ExtResource("1_eakc4")
name = "Coin"
id = &"coin"
stackable = true
stack_limit = 100
sells_for = 0

View File

@ -10,3 +10,4 @@ name = "Coin Flower"
id = &"coin_flower" id = &"coin_flower"
stackable = true stackable = true
stack_limit = 9 stack_limit = 9
sells_for = 2

View File

@ -10,4 +10,6 @@ icon = ExtResource("1_g8c3q")
model = ExtResource("2_5cxkh") model = ExtResource("2_5cxkh")
name = "Water Bomb" name = "Water Bomb"
id = &"water_bomb" id = &"water_bomb"
count = 0 stackable = false
stack_limit = 8
sells_for = 0

View File

@ -28,6 +28,7 @@ window/stretch/aspect="expand"
spawn_points="" spawn_points=""
voids="" voids=""
sell_boxes=""
[input] [input]

View File

@ -86,7 +86,7 @@ func _input(event: InputEvent) -> void:
func _process(_delta: float) -> void: func _process(_delta: float) -> void:
# this is fine but should this be done in response to a signal instead? # this is fine but should this be done in response to a signal instead?
_coin_label.text = "COINS: %d" % GameState.fetch().coins _coin_label.text = "COIN: %d" % GameState.get_item_count(&"coin")
func _activate_chat() -> void: func _activate_chat() -> void:

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=3 uid="uid://oyvhcwq60v2"] [gd_scene load_steps=16 format=3 uid="uid://oyvhcwq60v2"]
[ext_resource type="Script" path="res://src/ingame/ingame.gd" id="1_akuuj"] [ext_resource type="Script" path="res://src/ingame/ingame.gd" id="1_akuuj"]
[ext_resource type="PackedScene" uid="uid://cs8c570bxh6u" path="res://src/ingame/player.tscn" id="2_w1gjc"] [ext_resource type="PackedScene" uid="uid://cs8c570bxh6u" path="res://src/ingame/player.tscn" id="2_w1gjc"]
@ -32,6 +32,17 @@ sky = SubResource("Sky_ygvd3")
ambient_light_color = Color(0, 0.164706, 0.278431, 1) ambient_light_color = Color(0, 0.164706, 0.278431, 1)
ambient_light_energy = 2.0 ambient_light_energy = 2.0
[sub_resource type="BoxShape3D" id="BoxShape3D_3215c"]
size = Vector3(3, 1, 3)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vx5ut"]
transparency = 1
albedo_color = Color(1, 1, 0, 0.698039)
[sub_resource type="BoxMesh" id="BoxMesh_gygr8"]
material = SubResource("StandardMaterial3D_vx5ut")
size = Vector3(3, 1, 3)
[node name="Ingame" type="Node3D" node_paths=PackedStringArray("_soundtrack", "_players", "_chat_panel", "_chat_input", "_chat_history_scroll", "_chat_history", "_chat_panel_inactive", "_chat_history_inactive", "_chat_history_scroll_inactive", "_coin_label")] [node name="Ingame" type="Node3D" node_paths=PackedStringArray("_soundtrack", "_players", "_chat_panel", "_chat_input", "_chat_history_scroll", "_chat_history", "_chat_panel_inactive", "_chat_history_inactive", "_chat_history_scroll_inactive", "_coin_label")]
script = ExtResource("1_akuuj") script = ExtResource("1_akuuj")
_player_scene = ExtResource("2_w1gjc") _player_scene = ExtResource("2_w1gjc")
@ -303,6 +314,17 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.15702, 1.04855, 5.88574)
[node name="SpawnPoint3" type="Marker3D" parent="SpawnPoints" groups=["spawn_points"]] [node name="SpawnPoint3" type="Marker3D" parent="SpawnPoints" groups=["spawn_points"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.43229, 0.627689, 7.20138) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.43229, 0.627689, 7.20138)
[node name="SellBox" type="StaticBody3D" parent="." groups=["sell_boxes"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 0, 0)
collision_layer = 0
collision_mask = 4
[node name="CollisionShape3D" type="CollisionShape3D" parent="SellBox"]
shape = SubResource("BoxShape3D_3215c")
[node name="MeshInstance3D" type="MeshInstance3D" parent="SellBox"]
mesh = SubResource("BoxMesh_gygr8")
[connection signal="text_submitted" from="UI/ChatPanel/ChatInput" to="." method="_on_chat_message_submitted"] [connection signal="text_submitted" from="UI/ChatPanel/ChatInput" to="." method="_on_chat_message_submitted"]
[connection signal="pressed" from="UI/ChatPanel/ChatSendButton" to="." method="_on_chat_message_submitted"] [connection signal="pressed" from="UI/ChatPanel/ChatSendButton" to="." method="_on_chat_message_submitted"]
[connection signal="timeout" from="UI/ComboTimer" to="UI" method="_on_combo_timer_timeout"] [connection signal="timeout" from="UI/ComboTimer" to="UI" method="_on_combo_timer_timeout"]

View File

@ -19,10 +19,10 @@ func _ready() -> void:
GameState.fetch().player_data[_id].water_combo_update.connect( GameState.fetch().player_data[_id].water_combo_update.connect(
func(current: int): func(current: int):
if current == 0: if current == 0:
$Combo.hide() _combo_label.hide()
else: else:
$Combo.show() _combo_label.show()
$Combo.text = "+" + str(current) + "!" _combo_label.text = "+" + str(current) + "!"
_last_combo_time = Time.get_ticks_msec() _last_combo_time = Time.get_ticks_msec()
_combo_timer.start() _combo_timer.start()
) )
@ -30,4 +30,4 @@ func _ready() -> void:
func _on_combo_timer_timeout() -> void: func _on_combo_timer_timeout() -> void:
GameState.fetch().player_data[_id].reset_water_combo() GameState.fetch().player_data[_id].reset_water_combo()
$Combo.hide() _combo_label.hide()

View File

@ -40,6 +40,12 @@ func _disable_body() -> void:
_picking_area.collision_layer = 0 _picking_area.collision_layer = 0
@rpc("authority", "call_local", "reliable")
func get_sold() -> void:
var item := GameState.fetch().INVENTORY_ITEM_DB[item_bundle["item_id"]]
get_node("/root/Main").add_inventory_item(&"coin", item.sells_for * item_bundle["count"])
func _on_body_entered(p_body: Node3D) -> void: func _on_body_entered(p_body: Node3D) -> void:
if p_body == sender_body: if p_body == sender_body:
return return
@ -48,6 +54,13 @@ func _on_body_entered(p_body: Node3D) -> void:
queue_free() queue_free()
return return
if p_body.is_in_group("sell_boxes"):
var item := GameState.fetch().INVENTORY_ITEM_DB[item_bundle["item_id"]]
if item.sells_for != 0:
queue_free()
get_sold.rpc()
return
for area: Area3D in _in_splash_range: for area: Area3D in _in_splash_range:
area.get_parent_node_3d().water.rpc_id(1, sender_id) area.get_parent_node_3d().water.rpc_id(1, sender_id)

View File

@ -5,6 +5,7 @@ const INVENTORY_ITEM_DB = {
&"meat": preload("res://data/meat.tres"), &"meat": preload("res://data/meat.tres"),
&"water_bomb": preload("res://data/water_bomb.tres"), &"water_bomb": preload("res://data/water_bomb.tres"),
&"coin_flower": preload("res://data/coin_flower.tres"), &"coin_flower": preload("res://data/coin_flower.tres"),
&"coin": preload("res://data/coin.tres"),
} }
## keys are multiplayer ID ints, values are PlayerData ## keys are multiplayer ID ints, values are PlayerData
@ -12,7 +13,6 @@ const INVENTORY_ITEM_DB = {
## keys are InventoryItem resource IDs (from db), ## keys are InventoryItem resource IDs (from db),
## values are { "item": InventoryItem, "count": int } ## values are { "item": InventoryItem, "count": int }
@export var inventory := {} @export var inventory := {}
@export var coins: int # TODO: might it make sense to have even them as items?
static var _instance := GameState.new() static var _instance := GameState.new()
@ -25,6 +25,13 @@ static func fetch() -> GameState:
return _instance return _instance
static func get_item_count(p_item_id: StringName) -> int:
if GameState.fetch().inventory.has(p_item_id):
return GameState.fetch().inventory[p_item_id]["count"]
else:
return 0
# TODO: better place for those? # TODO: better place for those?
static func are_bundles_stackable(p_a_bundle: Dictionary, p_b_bundle: Dictionary) -> bool: static func are_bundles_stackable(p_a_bundle: Dictionary, p_b_bundle: Dictionary) -> bool:
var item = GameState.fetch().INVENTORY_ITEM_DB[p_a_bundle["item_id"]] var item = GameState.fetch().INVENTORY_ITEM_DB[p_a_bundle["item_id"]]

View File

@ -7,3 +7,5 @@ class_name InventoryItem extends Resource
@export var stackable := false @export var stackable := false
@export var stack_limit := 8 @export var stack_limit := 8
@export var sells_for := 0

View File

@ -35,8 +35,6 @@ func _on_player_joined(id: int) -> void:
_register_player.rpc_id(id, username) _register_player.rpc_id(id, username)
if _game_started: if _game_started:
set_coins.rpc_id(id, GameState.fetch().coins)
for item_id in GameState.fetch().inventory: for item_id in GameState.fetch().inventory:
set_inventory_item_count.rpc_id(id, item_id, GameState.fetch().inventory[item_id].count) set_inventory_item_count.rpc_id(id, item_id, GameState.fetch().inventory[item_id].count)
@ -180,11 +178,6 @@ func _on_chat_message_submitted(text := "") -> void:
_chat_input.clear() _chat_input.clear()
@rpc("authority", "call_local", "reliable")
func set_coins(value: int) -> void:
GameState.fetch().coins = value
## Make sure it exists and all. ## Make sure it exists and all.
func prepate_inventory_idem(item_id: StringName) -> void: func prepate_inventory_idem(item_id: StringName) -> void:
if not GameState.fetch().inventory.has(item_id): if not GameState.fetch().inventory.has(item_id):