Skip to content

Commit

Permalink
fix: Make sure generated projectile ID's are unique (#270)
Browse files Browse the repository at this point in the history
Fixes #238
  • Loading branch information
elementbound authored Sep 10, 2024
1 parent d3c70d3 commit 250a836
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion addons/netfox.extras/weapon/network-weapon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class_name NetworkWeapon
var _projectiles: Dictionary = {}
var _projectile_data: Dictionary = {}
var _reconcile_buffer: Array = []
var _rng = RandomNumberGenerator.new()

static var _logger: _NetfoxLogger = _NetfoxLogger.for_extras("NetworkWeapon")

func _ready():
_rng.randomize()
NetworkTime.before_tick_loop.connect(_before_tick_loop)

## Check whether this weapon can be fired.
Expand Down Expand Up @@ -132,9 +134,12 @@ func _before_tick_loop():

func _generate_id(length: int = 12, charset: String = "abcdefghijklmnopqrstuvwxyz0123456789") -> String:
var result = ""

# Generate a random ID
for i in range(length):
var idx = randi_range(0, charset.length() - 1)
var idx = _rng.randi_range(0, charset.length() - 1)
result += charset[idx]

return result

@rpc("any_peer", "reliable", "call_remote")
Expand Down

0 comments on commit 250a836

Please sign in to comment.