Add flag grabbing/carrying scoring logic

This commit is contained in:
Squinty 2024-04-24 07:45:04 +00:00
parent cfd840c2e5
commit ae75c64236
8 changed files with 65 additions and 30 deletions

View file

@ -47,7 +47,7 @@ func _enter_tree() -> void:
toolbar = Toolbar.new()
toolbar.hide()
toolbar.connect("tool_changed", _on_tool_changed)
toolbar_settings = ToolSettings.new()
toolbar_settings.connect("setting_changed", _on_setting_changed)
toolbar_settings.connect("picking", _on_picking)
@ -89,7 +89,7 @@ func set_visible(p_visible: bool) -> void:
visible = p_visible
toolbar.set_visible(p_visible and plugin.terrain)
terrain_tools.set_visible(p_visible)
if p_visible and plugin.terrain:
p_visible = plugin.editor.get_tool() != Terrain3DEditor.REGION
toolbar_settings.set_visible(p_visible and plugin.terrain)
@ -98,19 +98,19 @@ func set_visible(p_visible: bool) -> void:
func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor.Operation) -> void:
clear_picking()
if not visible or not plugin.terrain:
return
if plugin.editor:
plugin.editor.set_tool(p_tool)
plugin.editor.set_operation(p_operation)
if p_tool != Terrain3DEditor.REGION:
# Select which settings to hide. Options:
# size, opactiy, height, slope, color, roughness, (height|color|roughness) picker
var to_hide: PackedStringArray = []
if p_tool == Terrain3DEditor.HEIGHT:
to_hide.push_back("color")
to_hide.push_back("color picker")
@ -158,7 +158,7 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
to_hide.push_back("color picker")
to_hide.push_back("slope")
to_hide.push_back("enable")
elif p_tool in [ Terrain3DEditor.AUTOSHADER, Terrain3DEditor.HOLES, Terrain3DEditor.NAVIGATION ]:
to_hide.push_back("height")
to_hide.push_back("height picker")
@ -173,16 +173,16 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
toolbar_settings.hide_settings(to_hide)
toolbar_settings.set_visible(p_tool != Terrain3DEditor.REGION)
toolbar_settings.set_visible(p_tool != Terrain3DEditor.REGION)
operation_builder = null
if p_operation == Terrain3DEditor.GRADIENT:
operation_builder = GradientOperationBuilder.new()
operation_builder.tool_settings = toolbar_settings
_on_setting_changed()
plugin.update_region_grid()
func _on_setting_changed() -> void:
@ -206,7 +206,7 @@ func _on_setting_changed() -> void:
var brush_imgs: Array = toolbar_settings.get_setting("brush")
brush_data["image"] = brush_imgs[0]
brush_data["texture"] = brush_imgs[1]
update_decal()
plugin.editor.set_brush_data(brush_data)
@ -226,7 +226,7 @@ func update_decal() -> void:
else:
# Wait for cursor to recenter after right-click before revealing
# See https://github.com/godotengine/godot/issues/70098
await get_tree().create_timer(.05).timeout
await get_tree().create_timer(.05).timeout
decal.visible = true
decal.size = Vector3.ONE * brush_data["size"]
@ -250,7 +250,7 @@ func update_decal() -> void:
decal.modulate = COLOR_PICK_ROUGH
decal.modulate.a = 1.0
else:
decal.texture_albedo = brush_data["texture"]
decal.texture_albedo = brush_data["texture"]
match plugin.editor.get_tool():
Terrain3DEditor.HEIGHT:
match plugin.editor.get_operation():
@ -303,10 +303,10 @@ func update_decal() -> void:
decal.albedo_mix = 1.0
decal.cull_mask = 1 << ( plugin.terrain.get_mouse_layer() - 1 )
decal_timer.start()
for gradient_decal in gradient_decals:
gradient_decal.visible = false
if plugin.editor.get_operation() == Terrain3DEditor.GRADIENT:
var index := 0
for point in brush_data["gradient_points"]:
@ -320,7 +320,7 @@ func update_decal() -> void:
func _get_gradient_decal(index: int) -> Decal:
if gradient_decals.size() > index:
return gradient_decals[index]
var gradient_decal := Decal.new()
gradient_decal = Decal.new()
gradient_decal.texture_albedo = picker_texture
@ -329,7 +329,7 @@ func _get_gradient_decal(index: int) -> Decal:
gradient_decal.size.y = 1000.
gradient_decal.cull_mask = decal.cull_mask
add_child(gradient_decal)
gradient_decals.push_back(gradient_decal)
return gradient_decal
@ -351,10 +351,10 @@ func clear_picking() -> void:
func is_picking() -> bool:
if picking != Terrain3DEditor.TOOL_MAX:
return true
if operation_builder and operation_builder.is_picking():
return true
return false
@ -373,7 +373,7 @@ func pick(p_global_position: Vector3) -> void:
return
picking_callback.call(picking, color, p_global_position)
picking = Terrain3DEditor.TOOL_MAX
elif operation_builder and operation_builder.is_picking():
operation_builder.pick(p_global_position, plugin.terrain)

View file

@ -21,6 +21,7 @@ class_name FlagCarryComponent extends Node
@export var max_throw_speed : float = 10.0
@export var attachment : Node3D
@export var sensor : Area3D
@export var carrier : Player
var _carried_flag : Flag
@ -34,7 +35,7 @@ func _process(_delta : float) -> void:
func _grab(flag : Flag) -> void:
if not _is_carrying():
flag.grab()
flag.grab(carrier)
_carried_flag = flag
func _release(inherited_velocity : Vector3, throw_speed : float) -> void:

View file

@ -4,14 +4,26 @@ enum FlagState { FLAG_STATE_ON_STAND, FLAG_STATE_DROPPED, FLAG_STATE_TAKEN }
@export var flag_state : FlagState = FlagState.FLAG_STATE_ON_STAND
signal grabbed(grabber : Player)
signal regrabbed
signal dropped
var last_carrier : Player = null
func can_be_grabbed() -> bool:
return flag_state != FlagState.FLAG_STATE_TAKEN
func grab() -> void:
func grab(grabber : Player) -> void:
if flag_state != FlagState.FLAG_STATE_TAKEN:
flag_state = FlagState.FLAG_STATE_TAKEN
if (last_carrier == null) or (grabber != last_carrier):
grabbed.emit(grabber)
last_carrier = grabber
else:
regrabbed.emit()
func drop() -> void:
if flag_state == FlagState.FLAG_STATE_TAKEN:
flag_state = FlagState.FLAG_STATE_DROPPED
dropped.emit()

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=7 format=3 uid="uid://c88l3h0ph00c7"]
[ext_resource type="Script" path="res://entities/flag/flag.gd" id="1_y7d3d"]
[ext_resource type="PackedScene" path="res://entities/flag/assets/flag.glb" id="2_i78em"]
[ext_resource type="PackedScene" uid="uid://d3l7fvbdg6m5g" path="res://entities/flag/assets/flag.glb" id="2_i78em"]
[ext_resource type="PackedScene" uid="uid://bcgkc5fhhyauv" path="res://entities/flag/waypoint.tscn" id="3_tu6jg"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_4ymrw"]

View file

@ -130,9 +130,10 @@ shape = ExtResource("2_vjqny")
[node name="CollisionShape3D" type="CollisionShape3D" parent="HealthComponent"]
shape = ExtResource("2_vjqny")
[node name="FlagCarryComponent" parent="." node_paths=PackedStringArray("attachment", "sensor") instance=ExtResource("7_e7s1a")]
[node name="FlagCarryComponent" parent="." node_paths=PackedStringArray("attachment", "sensor", "carrier") instance=ExtResource("7_e7s1a")]
attachment = NodePath("../Smoothing/SpringArm3D/FlagCarryAttachment")
sensor = NodePath("../Sensor")
carrier = NodePath("..")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {

View file

@ -54,7 +54,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.42967, 0)
height = 5.0
[node name="FlagStand" type="Marker3D" parent="Terrain3D/FlagPillar/CSGCylinder3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.42315, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.53822, 0)
[node name="Sunlight" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.866024, -0.433016, 0.25, 0, 0.499998, 0.866027, -0.500003, 0.75, -0.43301, 0, 100, 0)

View file

@ -28,10 +28,17 @@ class_name Multiplayer extends Node
@onready var scoreboard_ui : Node = $ScoreboardUI
var _map_manager : Map
var _flag : Flag
var _flag_carrier_scoring_timer : Timer = Timer.new()
signal connected_to_server
signal connection_failed
func _ready() -> void:
_flag_carrier_scoring_timer.wait_time = 10.0
_flag_carrier_scoring_timer.timeout.connect(_on_flag_carrier_scoring_timer_timeout)
add_child(_flag_carrier_scoring_timer)
func start_server(port : int, nickname : String) -> void:
var peer : ENetMultiplayerPeer = ENetMultiplayerPeer.new()
peer.create_server(port, MAX_CLIENTS)
@ -101,9 +108,11 @@ func _load_map(scene : PackedScene, nickname : String) -> void:
map.add_child(map_scene)
func _add_flag() -> void:
var flag : Flag = FLAG.instantiate()
flag.global_position = _map_manager.get_flagstand().global_position
objectives.add_child(flag)
_flag = FLAG.instantiate()
_flag.grabbed.connect(_on_flag_grabbed)
_flag.dropped.connect(_on_flag_dropped)
_flag.global_position = _map_manager.get_flagstand().global_position
objectives.add_child(_flag)
func _unhandled_input(event : InputEvent) -> void:
if event.is_action_pressed("scoreboard"):
@ -123,6 +132,18 @@ func _join_match(nickname : String) -> void:
if is_multiplayer_authority():
add_player(multiplayer.get_remote_sender_id(), nickname)
func _on_flag_grabbed(grabber : Player) -> void:
scoreboard.add_score_to_player(grabber, 10)
scoreboard.broadcast_player_score_update(grabber)
_flag_carrier_scoring_timer.start()
func _on_flag_dropped() -> void:
_flag_carrier_scoring_timer.stop()
func _on_flag_carrier_scoring_timer_timeout() -> void:
scoreboard.add_score_to_player(_flag.last_carrier, 10)
scoreboard.broadcast_player_score_update(_flag.last_carrier)
func _exit_tree() -> void:
if is_multiplayer_authority():
multiplayer.peer_disconnected.disconnect(remove_player)

View file

@ -1,13 +1,13 @@
[gd_scene load_steps=6 format=3 uid="uid://bvwxfgygm2xb8"]
[ext_resource type="Script" path="res://modes/multiplayer.gd" id="1_4t1ad"]
[ext_resource type="PackedScene" uid="uid://chbno00ugl6te" path="res://maps/genesis/genesis.tscn" id="1_nulvv"]
[ext_resource type="Script" path="res://modes/multiplayer.gd" id="1_r1kd6"]
[ext_resource type="PackedScene" uid="uid://cbhx1xme0sb7k" path="res://entities/player/player.tscn" id="2_og1vb"]
[ext_resource type="PackedScene" uid="uid://c88l3h0ph00c7" path="res://entities/flag/flag.tscn" id="3_h0rie"]
[ext_resource type="Script" path="res://modes/scoreboard.gd" id="4_n0mhp"]
[node name="Multiplayer" type="Node"]
script = ExtResource("1_4t1ad")
script = ExtResource("1_r1kd6")
MAP = ExtResource("1_nulvv")
PLAYER = ExtResource("2_og1vb")
FLAG = ExtResource("3_h0rie")