fixed an issue regarding weapon node names causing multiplayer desync

This commit is contained in:
Lexi Quinn 2024-03-30 16:44:52 +11:00
parent 2c2962077e
commit e84496dcf8
5 changed files with 90 additions and 46 deletions

View File

@ -24,11 +24,11 @@ func _process(delta: float) -> void:
super._process(delta) super._process(delta)
if !trigger_held or time_since_firing < time_between_shots or current_energy < energy_cost: if !trigger_held or time_since_firing < time_between_shots or current_energy < energy_cost:
return return
var target_list: Array[EnemyController] = targets.duplicate() var target_list: Array[EnemyController] = []
for target: EnemyController in target_list: for target: EnemyController in targets:
if !is_instance_valid(target): if is_instance_valid(target):
targets.erase(target) target_list.append(target)
continue targets = target_list
for x: int in target_icons.size(): for x: int in target_icons.size():
if x < targets.size(): if x < targets.size():
target_icons[x].global_position = targets[x].sprite.global_position target_icons[x].global_position = targets[x].sprite.global_position

View File

@ -36,6 +36,7 @@ signal died
@export var swap_off_audio: AudioStreamPlayer @export var swap_off_audio: AudioStreamPlayer
@export var swap_on_audio: AudioStreamPlayer @export var swap_on_audio: AudioStreamPlayer
var weapons_spawn_count: int = 0 #Used to prevent node name collisions for multiplayer
var inventory_selected_index: int = 0 var inventory_selected_index: int = 0
var equipped_card: Card var equipped_card: Card
var offhand_card: Card var offhand_card: Card
@ -124,7 +125,8 @@ func _process(delta: float) -> void:
if Input.is_action_just_pressed("Equip In Gauntlet"): if Input.is_action_just_pressed("Equip In Gauntlet"):
equip_weapon() equip_weapon()
if Input.is_action_just_pressed("Secondary Fire"): if Input.is_action_just_pressed("Secondary Fire"):
swap_weapons() if equipped_card or offhand_card:
swap_weapons()
if Input.is_action_just_pressed("Select Next Card") and inventory.contents.size() > 1: if Input.is_action_just_pressed("Select Next Card") and inventory.contents.size() > 1:
increment_selected() increment_selected()
swap_card_audio.play() swap_card_audio.play()
@ -202,6 +204,8 @@ func ready_self() -> void:
edit_tool.interact_key_held = false edit_tool.interact_key_held = false
if !ready_state: if !ready_state:
ready_state = true ready_state = true
hud.place_icon.set_visible(false)
hud.swap_icon.set_visible(false)
hud.shrink_wave_start_label() hud.shrink_wave_start_label()
ready_audio.play() ready_audio.play()
networked_set_ready_state.rpc(ready_state) networked_set_ready_state.rpc(ready_state)
@ -210,6 +214,10 @@ func ready_self() -> void:
func unready_self() -> void: func unready_self() -> void:
if ready_state: if ready_state:
ready_state = false ready_state = false
if !equipped_card:
hud.place_icon.set_visible(true)
if !offhand_card:
hud.swap_icon.set_visible(true)
hud.grow_wave_start_label() hud.grow_wave_start_label()
unready_audio.play() unready_audio.play()
networked_set_ready_state(ready_state) networked_set_ready_state(ready_state)
@ -298,12 +306,12 @@ func equip_weapon() -> void:
equipped_card = inventory.remove_at(inventory_selected_index) equipped_card = inventory.remove_at(inventory_selected_index)
if !inventory.contents.has(equipped_card): if !inventory.contents.has(equipped_card):
decrement_selected() decrement_selected()
networked_equip_weapon.rpc(Data.cards.find(equipped_card))
weapon = equipped_card.weapon_scene.instantiate() weapon = equipped_card.weapon_scene.instantiate()
weapon.name = str(weapons_spawn_count)
networked_equip_weapon.rpc(Data.cards.find(equipped_card), 0, weapons_spawn_count)
weapons_spawn_count += 1
weapon.energy_changed.connect(hud.set_weapon_energy) weapon.energy_changed.connect(hud.set_weapon_energy)
#weapon.name = "weapon"
weapon.set_multiplayer_authority(multiplayer.get_unique_id()) weapon.set_multiplayer_authority(multiplayer.get_unique_id())
#gauntlet_sprite.set_visible(false)
gauntlet_card_1.set_card(equipped_card) gauntlet_card_1.set_card(equipped_card)
hud.place_icon.set_visible(false) hud.place_icon.set_visible(false)
gauntlet_card_1.view_weapon() gauntlet_card_1.view_weapon()
@ -372,7 +380,7 @@ func _on_timer_timeout() -> void:
func unequip_weapon() -> void: func unequip_weapon() -> void:
networked_unequip_weapon.rpc() networked_unequip_weapon.rpc(0)
gauntlet_card_1.set_visible(false) gauntlet_card_1.set_visible(false)
hud.place_icon.set_visible(true) hud.place_icon.set_visible(true)
#gauntlet_sprite.set_visible(true) #gauntlet_sprite.set_visible(true)
@ -391,18 +399,48 @@ func networked_set_ready_state(state: bool) -> void:
@rpc("reliable") @rpc("reliable")
func networked_equip_weapon(card_index: int) -> void: func networked_swap_weapon() -> void:
equipped_card = Data.cards[card_index] var temp: Weapon = offhand_weapon
weapon = equipped_card.weapon_scene.instantiate() var temp_card: Card = offhand_card
weapon.set_multiplayer_authority(multiplayer.get_remote_sender_id()) if weapon:
#weapon.name = "weapon" offhand_weapon = weapon
weapon.set_hero(self) offhand_card = equipped_card
right_hand.add_child(weapon) else:
offhand_weapon = null
offhand_card = null
if temp:
weapon = temp
equipped_card = temp_card
else:
weapon = null
equipped_card = null
@rpc("reliable") @rpc("reliable")
func networked_unequip_weapon() -> void: func networked_equip_weapon(card_index: int, slot: int, id: int) -> void:
weapon.queue_free() var new_card: Card = Data.cards[card_index]
weapon = null var new_weapon: Weapon = new_card.weapon_scene.instantiate()
inventory.add(equipped_card) new_weapon.set_multiplayer_authority(multiplayer.get_remote_sender_id())
equipped_card = null new_weapon.name = str(id)
new_weapon.set_hero(self)
right_hand.add_child(new_weapon)
match slot:
0:
equipped_card = new_card
weapon = new_weapon
1:
offhand_card = new_card
offhand_weapon = new_weapon
@rpc("reliable")
func networked_unequip_weapon(slot: int) -> void:
match slot:
0:
weapon.queue_free()
weapon = null
equipped_card = null
1:
offhand_weapon.queue_free()
offhand_weapon = null
offhand_card = null

View File

@ -55,7 +55,7 @@ func retrieve_card(i: int, reply: Hero) -> void:
#add_child(item) #add_child(item)
button_collider.disabled = false button_collider.disabled = false
button_box.position = Vector3(0,0,0) button_box.position = Vector3(0,0,0)
$AudioStreamPlayer3D.play() $StaticBody3D/AudioStreamPlayer3D.play()
reply_player = null reply_player = null
@ -63,5 +63,5 @@ func _on_static_body_3d_button_interacted(_value: int, reply: Hero) -> void:
reply_player = reply reply_player = reply
button_collider.disabled = true button_collider.disabled = true
button_box.position = Vector3(0,0,-0.2) button_box.position = Vector3(0,0,-0.2)
$AudioStreamPlayer3D.play() $StaticBody3D/AudioStreamPlayer3D.play()
randomize_cards() randomize_cards()

View File

@ -10,7 +10,7 @@
albedo_color = Color(0.203922, 0.592157, 0.592157, 1) albedo_color = Color(0.203922, 0.592157, 0.592157, 1)
[sub_resource type="BoxShape3D" id="BoxShape3D_0ebt5"] [sub_resource type="BoxShape3D" id="BoxShape3D_0ebt5"]
size = Vector3(2.672, 1.75, 1) size = Vector3(2, 2.1, 1)
[sub_resource type="ViewportTexture" id="ViewportTexture_yf4je"] [sub_resource type="ViewportTexture" id="ViewportTexture_yf4je"]
viewport_path = NodePath("SubViewport") viewport_path = NodePath("SubViewport")
@ -24,15 +24,15 @@ viewport_path = NodePath("SubViewport3")
[sub_resource type="BoxShape3D" id="BoxShape3D_ikdwj"] [sub_resource type="BoxShape3D" id="BoxShape3D_ikdwj"]
size = Vector3(1.29447, 0.342125, 0.277604) size = Vector3(1.29447, 0.342125, 0.277604)
[sub_resource type="BoxShape3D" id="BoxShape3D_gv3t5"]
size = Vector3(0.763889, 0.773027, 0.0570252)
[sub_resource type="AudioStreamRandomizer" id="AudioStreamRandomizer_73g2w"] [sub_resource type="AudioStreamRandomizer" id="AudioStreamRandomizer_73g2w"]
random_pitch = 1.1 random_pitch = 1.1
streams_count = 1 streams_count = 1
stream_0/stream = ExtResource("5_m033a") stream_0/stream = ExtResource("5_m033a")
stream_0/weight = 1.0 stream_0/weight = 1.0
[sub_resource type="BoxShape3D" id="BoxShape3D_gv3t5"]
size = Vector3(0.617184, 0.869944, 0.0570252)
[node name="CardPrinter" type="StaticBody3D" node_paths=PackedStringArray("cards", "button_collider", "button_box", "choice_colliders")] [node name="CardPrinter" type="StaticBody3D" node_paths=PackedStringArray("cards", "button_collider", "button_box", "choice_colliders")]
script = ExtResource("1_qft15") script = ExtResource("1_qft15")
cards = [NodePath("SubViewport/Node2D"), NodePath("SubViewport2/Node2D"), NodePath("SubViewport3/Node2D")] cards = [NodePath("SubViewport/Node2D"), NodePath("SubViewport2/Node2D"), NodePath("SubViewport3/Node2D")]
@ -42,52 +42,59 @@ button_box = NodePath("StaticBody3D/CollisionShape3D2/CSGBox3D")
choice_colliders = [NodePath("StaticBody3D2/CollisionShape3D2"), NodePath("StaticBody3D3/CollisionShape3D2"), NodePath("StaticBody3D4/CollisionShape3D2")] choice_colliders = [NodePath("StaticBody3D2/CollisionShape3D2"), NodePath("StaticBody3D3/CollisionShape3D2"), NodePath("StaticBody3D4/CollisionShape3D2")]
[node name="CSGBox3D" type="CSGBox3D" parent="."] [node name="CSGBox3D" type="CSGBox3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.875, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.05, 0)
size = Vector3(2.672, 1.75, 1) size = Vector3(2, 2.1, 1)
material = SubResource("StandardMaterial3D_s02au") material = SubResource("StandardMaterial3D_s02au")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.875, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.05, 0)
shape = SubResource("BoxShape3D_0ebt5") shape = SubResource("BoxShape3D_0ebt5")
[node name="SubViewport" type="SubViewport" parent="."] [node name="SubViewport" type="SubViewport" parent="."]
transparent_bg = true transparent_bg = true
size = Vector2i(352, 512)
render_target_update_mode = 4 render_target_update_mode = 4
[node name="Node2D" parent="SubViewport" instance=ExtResource("3_wygtg")] [node name="Node2D" parent="SubViewport" instance=ExtResource("3_wygtg")]
position = Vector2(-56, 0)
[node name="SubViewport2" type="SubViewport" parent="."] [node name="SubViewport2" type="SubViewport" parent="."]
transparent_bg = true transparent_bg = true
size = Vector2i(352, 512)
render_target_update_mode = 4 render_target_update_mode = 4
[node name="Node2D" parent="SubViewport2" instance=ExtResource("3_wygtg")] [node name="Node2D" parent="SubViewport2" instance=ExtResource("3_wygtg")]
position = Vector2(-56, 0)
[node name="SubViewport3" type="SubViewport" parent="."] [node name="SubViewport3" type="SubViewport" parent="."]
transparent_bg = true transparent_bg = true
size = Vector2i(352, 512)
render_target_update_mode = 4 render_target_update_mode = 4
[node name="Node2D" parent="SubViewport3" instance=ExtResource("3_wygtg")] [node name="Node2D" parent="SubViewport3" instance=ExtResource("3_wygtg")]
position = Vector2(-56, 0)
[node name="Node3D" type="Node3D" parent="."] [node name="Node3D" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.149617, 0)
visible = false visible = false
[node name="Sprite3D" type="Sprite3D" parent="Node3D"] [node name="Sprite3D" type="Sprite3D" parent="Node3D"]
transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, -0.805106, 1.12938, 0.500052) transform = Transform3D(0.175, 0, 0, 0, 0.175, 0, 0, 0, 0.175, -0.65, 1.65, 0.506948)
texture_filter = 0 texture_filter = 0
texture = SubResource("ViewportTexture_yf4je") texture = SubResource("ViewportTexture_yf4je")
[node name="Sprite3D2" type="Sprite3D" parent="Node3D"] [node name="Sprite3D2" type="Sprite3D" parent="Node3D"]
transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0.0180808, 1.12938, 0.500052) transform = Transform3D(0.175, 0, 0, 0, 0.175, 0, 0, 0, 0.175, 0, 1.65, 0.506948)
texture_filter = 0 texture_filter = 0
texture = SubResource("ViewportTexture_3q3h0") texture = SubResource("ViewportTexture_3q3h0")
[node name="Sprite3D3" type="Sprite3D" parent="Node3D"] [node name="Sprite3D3" type="Sprite3D" parent="Node3D"]
transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0.843507, 1.12938, 0.500052) transform = Transform3D(0.175, 0, 0, 0, 0.175, 0, 0, 0, 0.175, 0.65, 1.65, 0.506948)
texture_filter = 0 texture_filter = 0
texture = SubResource("ViewportTexture_vyyy4") texture = SubResource("ViewportTexture_vyyy4")
[node name="StaticBody3D" type="StaticBody3D" parent="."] [node name="StaticBody3D" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.444448, 0.610684) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.847404, 0.610684)
collision_layer = 16 collision_layer = 16
collision_mask = 0 collision_mask = 0
script = ExtResource("4_eavi1") script = ExtResource("4_eavi1")
@ -100,20 +107,24 @@ shape = SubResource("BoxShape3D_ikdwj")
[node name="CSGBox3D" type="CSGBox3D" parent="StaticBody3D/CollisionShape3D2"] [node name="CSGBox3D" type="CSGBox3D" parent="StaticBody3D/CollisionShape3D2"]
size = Vector3(1.29447, 0.342125, 0.277604) size = Vector3(1.29447, 0.342125, 0.277604)
[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="StaticBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.010989, -0.086501)
stream = SubResource("AudioStreamRandomizer_73g2w")
bus = &"SFX"
[node name="StaticBody3D2" type="StaticBody3D" parent="."] [node name="StaticBody3D2" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.756734, 1.15772, 0.610684) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.650194, 1.50143, 0.528758)
collision_layer = 16 collision_layer = 16
collision_mask = 0 collision_mask = 0
script = ExtResource("4_eavi1") script = ExtResource("4_eavi1")
hover_text = "Select card" hover_text = "Select card"
[node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D2"] [node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0466152, -0.0297148, -0.0917365)
shape = SubResource("BoxShape3D_gv3t5") shape = SubResource("BoxShape3D_gv3t5")
disabled = true disabled = true
[node name="StaticBody3D3" type="StaticBody3D" parent="."] [node name="StaticBody3D3" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0672475, 1.15772, 0.610684) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000848182, 1.5001, 0.528758)
collision_layer = 16 collision_layer = 16
collision_mask = 0 collision_mask = 0
script = ExtResource("4_eavi1") script = ExtResource("4_eavi1")
@ -121,12 +132,11 @@ button_press_value = 1
hover_text = "Select card" hover_text = "Select card"
[node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D3"] [node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D3"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0466152, -0.0297148, -0.0917365)
shape = SubResource("BoxShape3D_gv3t5") shape = SubResource("BoxShape3D_gv3t5")
disabled = true disabled = true
[node name="StaticBody3D4" type="StaticBody3D" parent="."] [node name="StaticBody3D4" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.883877, 1.15772, 0.610684) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.648946, 1.49865, 0.528758)
collision_layer = 16 collision_layer = 16
collision_mask = 0 collision_mask = 0
script = ExtResource("4_eavi1") script = ExtResource("4_eavi1")
@ -134,15 +144,9 @@ button_press_value = 2
hover_text = "Select card" hover_text = "Select card"
[node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D4"] [node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D4"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0466152, -0.0297148, -0.0917365)
shape = SubResource("BoxShape3D_gv3t5") shape = SubResource("BoxShape3D_gv3t5")
disabled = true disabled = true
[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.433459, 0.524183)
stream = SubResource("AudioStreamRandomizer_73g2w")
bus = &"SFX"
[connection signal="button_interacted" from="StaticBody3D" to="." method="_on_static_body_3d_button_interacted"] [connection signal="button_interacted" from="StaticBody3D" to="." method="_on_static_body_3d_button_interacted"]
[connection signal="button_interacted" from="StaticBody3D2" to="." method="retrieve_card"] [connection signal="button_interacted" from="StaticBody3D2" to="." method="retrieve_card"]
[connection signal="button_interacted" from="StaticBody3D3" to="." method="retrieve_card"] [connection signal="button_interacted" from="StaticBody3D3" to="." method="retrieve_card"]

View File

@ -155,6 +155,8 @@ func build_wall() -> void:
func refund_wall(wall: TowerBase) -> void: func refund_wall(wall: TowerBase) -> void:
if !is_instance_valid(wall):
return
last_collider = null last_collider = null
if wall.has_card: if wall.has_card:
wall.remove_card() wall.remove_card()