diff --git a/data/coin.tres b/data/coin.tres new file mode 100644 index 0000000..bddf69e --- /dev/null +++ b/data/coin.tres @@ -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 diff --git a/data/coin_flower.tres b/data/coin_flower.tres index 6875184..7a5be28 100644 --- a/data/coin_flower.tres +++ b/data/coin_flower.tres @@ -10,3 +10,4 @@ name = "Coin Flower" id = &"coin_flower" stackable = true stack_limit = 9 +sells_for = 2 diff --git a/data/water_bomb.tres b/data/water_bomb.tres index d3076b6..8d9396e 100644 --- a/data/water_bomb.tres +++ b/data/water_bomb.tres @@ -10,4 +10,6 @@ icon = ExtResource("1_g8c3q") model = ExtResource("2_5cxkh") name = "Water Bomb" id = &"water_bomb" -count = 0 +stackable = false +stack_limit = 8 +sells_for = 0 diff --git a/project.godot b/project.godot index 9a28d19..6ff05f3 100644 --- a/project.godot +++ b/project.godot @@ -28,6 +28,7 @@ window/stretch/aspect="expand" spawn_points="" voids="" +sell_boxes="" [input] diff --git a/src/ingame/ingame.gd b/src/ingame/ingame.gd index 557b870..dd8d7ca 100644 --- a/src/ingame/ingame.gd +++ b/src/ingame/ingame.gd @@ -86,7 +86,7 @@ func _input(event: InputEvent) -> void: func _process(_delta: float) -> void: # 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: diff --git a/src/ingame/ingame.tscn b/src/ingame/ingame.tscn index 99bbe72..f9bd912 100644 --- a/src/ingame/ingame.tscn +++ b/src/ingame/ingame.tscn @@ -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="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_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")] script = ExtResource("1_akuuj") _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"]] 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="pressed" from="UI/ChatPanel/ChatSendButton" to="." method="_on_chat_message_submitted"] [connection signal="timeout" from="UI/ComboTimer" to="UI" method="_on_combo_timer_timeout"] diff --git a/src/ingame/ui.gd b/src/ingame/ui.gd index fbb805f..f519f0e 100644 --- a/src/ingame/ui.gd +++ b/src/ingame/ui.gd @@ -19,10 +19,10 @@ func _ready() -> void: GameState.fetch().player_data[_id].water_combo_update.connect( func(current: int): if current == 0: - $Combo.hide() + _combo_label.hide() else: - $Combo.show() - $Combo.text = "+" + str(current) + "!" + _combo_label.show() + _combo_label.text = "+" + str(current) + "!" _last_combo_time = Time.get_ticks_msec() _combo_timer.start() ) @@ -30,4 +30,4 @@ func _ready() -> void: func _on_combo_timer_timeout() -> void: GameState.fetch().player_data[_id].reset_water_combo() - $Combo.hide() + _combo_label.hide() diff --git a/src/ingame/water_bomb.gd b/src/ingame/water_bomb.gd index 015aebc..b4d3705 100644 --- a/src/ingame/water_bomb.gd +++ b/src/ingame/water_bomb.gd @@ -40,6 +40,12 @@ func _disable_body() -> void: _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: if p_body == sender_body: return @@ -48,6 +54,13 @@ func _on_body_entered(p_body: Node3D) -> void: queue_free() 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: area.get_parent_node_3d().water.rpc_id(1, sender_id) diff --git a/src/lib/game_state.gd b/src/lib/game_state.gd index 3a278de..a96bbe6 100644 --- a/src/lib/game_state.gd +++ b/src/lib/game_state.gd @@ -5,6 +5,7 @@ const INVENTORY_ITEM_DB = { &"meat": preload("res://data/meat.tres"), &"water_bomb": preload("res://data/water_bomb.tres"), &"coin_flower": preload("res://data/coin_flower.tres"), + &"coin": preload("res://data/coin.tres"), } ## keys are multiplayer ID ints, values are PlayerData @@ -12,7 +13,6 @@ const INVENTORY_ITEM_DB = { ## keys are InventoryItem resource IDs (from db), ## values are { "item": InventoryItem, "count": int } @export var inventory := {} -@export var coins: int # TODO: might it make sense to have even them as items? static var _instance := GameState.new() @@ -25,6 +25,13 @@ static func fetch() -> GameState: 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? 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"]] diff --git a/src/lib/inventory_item.gd b/src/lib/inventory_item.gd index 1050727..d7b1652 100644 --- a/src/lib/inventory_item.gd +++ b/src/lib/inventory_item.gd @@ -7,3 +7,5 @@ class_name InventoryItem extends Resource @export var stackable := false @export var stack_limit := 8 + +@export var sells_for := 0 diff --git a/src/main/main.gd b/src/main/main.gd index 9248622..c6a6ca4 100644 --- a/src/main/main.gd +++ b/src/main/main.gd @@ -35,8 +35,6 @@ func _on_player_joined(id: int) -> void: _register_player.rpc_id(id, username) if _game_started: - set_coins.rpc_id(id, GameState.fetch().coins) - for item_id in GameState.fetch().inventory: 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() -@rpc("authority", "call_local", "reliable") -func set_coins(value: int) -> void: - GameState.fetch().coins = value - - ## Make sure it exists and all. func prepate_inventory_idem(item_id: StringName) -> void: if not GameState.fetch().inventory.has(item_id):