Skip to content

Commit

Permalink
Merge pull request #70 from adventureboss/sync_crates
Browse files Browse the repository at this point in the history
Multiplayer magic syncs crates
  • Loading branch information
SteveHNH authored Dec 21, 2023
2 parents 966e38a + 541b302 commit 62723df
Showing 1 changed file with 49 additions and 27 deletions.
76 changes: 49 additions & 27 deletions scenes/component/consumable_spawn_component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,31 @@ var box_tracker = {}


func _ready():
var ammo_index : Array = [0, 1, 2]
var consumable_positions = []
GameEvents.ability_pick_up.connect(on_ability_pickup)
consumable_spawn_points = get_tree().get_nodes_in_group("ConsumableSpawnPoints")
randomize()
consumable_spawn_points.shuffle()
for marker in consumable_spawn_points:
ammo_list.shuffle()
var ammo_to_spawn = ammo_list[0]
if multiplayer.get_unique_id() == GameManager.player_host:
consumable_spawn_points = get_tree().get_nodes_in_group("ConsumableSpawnPoints")
randomize()
consumable_spawn_points.shuffle()
for marker in consumable_spawn_points:
randomize()
ammo_index.shuffle()
consumable_positions.append({"position": marker.global_position, "ammo_index": ammo_index[0]})
new_spawn_at_points.rpc(consumable_positions, box_tracker)


@rpc("any_peer", "call_local")
func new_spawn_at_points(consumable_positions, tracker):
for p in consumable_positions:
if p.position in tracker and tracker[p.position] == 1:
continue
var ammo_to_spawn = ammo_list[p.ammo_index]
var pickup = ammo_to_spawn.instantiate()
add_child(pickup)
box_tracker[marker.global_position] = 1 # tracking that this position has a box
pickup.global_position = marker.global_position

tracker[p.position] = 1 # tracking that this position has a box
pickup.global_position = p.position
box_tracker = tracker
count_consumables()
timer.timeout.connect(on_timer_timeout)
timer.start()
Expand All @@ -54,37 +67,46 @@ func count_consumable_drop():
ammo_to_drop = max_ammo - current_ammo


func spawn_new_consumables():
for marker in consumable_spawn_points:
if box_tracker[marker.global_position] == 1:
func on_timer_timeout():
if multiplayer.get_unique_id() != GameManager.player_host:
return
count_consumables()
count_consumable_drop()

var ammo_index : Array = [0, 1, 2]
var consumable_positions = []
randomize()
consumable_spawn_points.shuffle()
for marker in consumable_spawn_points:
randomize()
ammo_index.shuffle()
consumable_positions.append({"position": marker.global_position, "ammo_index": ammo_index[0]})
respawn_at_points.rpc(consumable_positions, box_tracker)


@rpc("any_peer", "call_local")
func respawn_at_points(consumable_positions, tracker):
for p in consumable_positions:
if p.position in tracker and tracker[p.position] == 1:
continue
var drop = animated_drop.instantiate()
add_child(drop)
box_tracker[marker.global_position] = 1
box_tracker[p.position] = 1
var drop_hitbox = drop.find_child("HitboxComponent")
drop.global_position = marker.global_position
drop.global_position = p.position
drop_hitbox.get_parent().projectile_owner = owner # this is why the spawn node is 10101010. Stupid. FIX IT
var anim_player : AnimationPlayer = drop.find_child("AnimationPlayer")
anim_player.play("drop")
anim_player.animation_finished.connect(on_animation_finished.bind(marker.global_position))
anim_player.animation_finished.connect(on_animation_finished.bind(p.position, p.ammo_index))
box_tracker = tracker


func on_timer_timeout():
count_consumables()
count_consumable_drop()

spawn_new_consumables()

func on_ability_pickup(_ability, _id, position):
box_tracker[position] = 0


func on_animation_finished(anim_name, position):
randomize()
ammo_list.shuffle()
var ammo_to_spawn = ammo_list[0]
func on_animation_finished(anim_name, position, ammo_index):
var ammo_to_spawn = ammo_list[ammo_index]
var pickup = ammo_to_spawn.instantiate()
add_child(pickup)
pickup.global_position = position


0 comments on commit 62723df

Please sign in to comment.