Phase 7: netfox + godot-jolt stack upgrade
Stack installed: - netfox v1.35.3 (core + extras + noray + internals) - godot-jolt v0.16.0-stable Architecture: - Server: ENet transport (works headless, no netfox deps) - Client/Editor: netfox rollback (RollbackSynchronizer, TickInterpolator) New/modified: - docs/migration-netfox-plan.md — migration architecture - scripts/network/network_manager.gd — netfox-aware ENet fallback - scripts/network/player.gd — clean base player - client/characters/player_netfox.gd — rollback player w/ WeaponManager - client/characters/input/player_net_input.gd — BaseNetInput subclass - client/characters/character/fps_character_controller.gd — netfox input feed - client/weapons/ — weapon data, registry, TacticalWeaponHitscan, WeaponManager - client/scripts/round_replicator.gd — client-side round state bridge - server/scripts/round_manager.gd — improved state machine - server/scripts/plugin_api/plugin_manager.gd — refined plugin system - config: enemy_tag, ally_tag for meatball targeting Removed: old C++ SimulationServer GDExtension (replaced by netfox rollback)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
## WeaponData — resource containing all stats for a weapon.
|
||||
##
|
||||
## Used by the weapon system to configure damage, fire rate, recoil,
|
||||
## economy pricing, and team restrictions.
|
||||
##
|
||||
## This is a pure Resource (no Node dependency) so it loads clean
|
||||
## in both client and server contexts.
|
||||
|
||||
extends Resource
|
||||
class_name WeaponData
|
||||
|
||||
enum FireMode { SEMI, AUTO, MELEE }
|
||||
|
||||
# Identification
|
||||
@export var weapon_id: int = 0
|
||||
@export var weapon_name: String = ""
|
||||
@export var slot: int = 0 # 0=melee, 1=pistol, 2=SMG, 3=rifle, 4=sniper
|
||||
|
||||
# Damage
|
||||
@export var damage: int = 30
|
||||
@export var headshot_multiplier: float = 2.0
|
||||
@export var chest_multiplier: float = 1.0
|
||||
@export var waist_multiplier: float = 0.75
|
||||
@export var leg_multiplier: float = 0.5
|
||||
@export var armor_penetration: float = 0.5 # 0.0-1.0, % damage through armor
|
||||
|
||||
# Firing
|
||||
@export var fire_mode: FireMode = FireMode.SEMI
|
||||
@export var fire_rate: float = 10.0 # rounds per second
|
||||
@export var reload_time: float = 2.0 # seconds
|
||||
@export var max_distance: float = 1000.0
|
||||
|
||||
# Magazine
|
||||
@export var magazine_size: int = 30
|
||||
@export var reserve_size: int = 90
|
||||
|
||||
# Recoil & Spread
|
||||
@export var recoil_per_shot: float = 0.5 # degrees
|
||||
@export var recoil_recovery: float = 8.0 # degrees/sec
|
||||
@export var spread_idle: float = 0.0 # degrees while standing still
|
||||
@export var spread_walking: float = 2.0 # degrees while moving
|
||||
@export var spread_sprinting: float = 6.0 # degrees while sprinting
|
||||
|
||||
# Movement
|
||||
@export var move_speed_multiplier: float = 1.0 # multiplier on base move speed
|
||||
@export var aim_speed_multiplier: float = 0.5 # move speed while aiming
|
||||
|
||||
# Economy
|
||||
@export var price: int = 0
|
||||
@export var kill_reward: int = 300
|
||||
@export var team: int = -1 # -1=both, 0=T, 1=CT
|
||||
@@ -0,0 +1,175 @@
|
||||
## WeaponRegistry — central registry of all weapon definitions.
|
||||
##
|
||||
## All weapon data is defined here as static constants. Systems that need
|
||||
## weapon stats (WeaponManager, BuyMenu, RoundManager) reference this.
|
||||
##
|
||||
## To add a new weapon: create a WeaponData resource in client/weapons/data/
|
||||
## and register it in the ALL array below.
|
||||
|
||||
extends Node
|
||||
class_name WeaponRegistry
|
||||
|
||||
# Define all weapons as convenient static getters
|
||||
static var KNIFE: WeaponData:
|
||||
get: return _knife
|
||||
static var GLOCK: WeaponData:
|
||||
get: return _glock
|
||||
static var USP: WeaponData:
|
||||
get: return _usp
|
||||
static var AK47: WeaponData:
|
||||
get: return _ak47
|
||||
static var M4A1: WeaponData:
|
||||
get: return _m4a1
|
||||
static var AWP: WeaponData:
|
||||
get: return _awp
|
||||
|
||||
# Weapon ID constants
|
||||
const ID_KNIFE: int = 0
|
||||
const ID_GLOCK: int = 1
|
||||
const ID_USP: int = 2
|
||||
const ID_AK47: int = 3
|
||||
const ID_M4A1: int = 4
|
||||
const ID_AWP: int = 5
|
||||
|
||||
## Array of all weapons for iteration
|
||||
static var ALL: Array[WeaponData] = []
|
||||
|
||||
## Map of weapon_id → WeaponData for fast lookup
|
||||
static var BY_ID: Dictionary = {}
|
||||
|
||||
## Static initializer
|
||||
static func _static_init() -> void:
|
||||
ALL = [_knife, _glock, _usp, _ak47, _m4a1, _awp]
|
||||
for w in ALL:
|
||||
BY_ID[w.weapon_id] = w
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Weapon definitions
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
static var _knife: WeaponData = _make_weapon_data({
|
||||
weapon_id = ID_KNIFE,
|
||||
weapon_name = "Knife",
|
||||
slot = 0,
|
||||
damage = 34,
|
||||
fire_mode = WeaponData.FireMode.MELEE,
|
||||
fire_rate = 0.0,
|
||||
magazine_size = 0,
|
||||
reserve_size = 0,
|
||||
move_speed_multiplier = 1.0,
|
||||
price = 0,
|
||||
kill_reward = 1500,
|
||||
armor_penetration = 0.0,
|
||||
max_distance = 3.0,
|
||||
})
|
||||
|
||||
static var _glock: WeaponData = _make_weapon_data({
|
||||
weapon_id = ID_GLOCK,
|
||||
weapon_name = "Glock-18",
|
||||
slot = 1,
|
||||
damage = 25,
|
||||
fire_rate = 6.0,
|
||||
magazine_size = 20,
|
||||
reserve_size = 120,
|
||||
recoil_per_shot = 0.4,
|
||||
move_speed_multiplier = 0.86,
|
||||
price = 200,
|
||||
kill_reward = 300,
|
||||
armor_penetration = 0.35,
|
||||
team = 0, # Terrorist default
|
||||
})
|
||||
|
||||
static var _usp: WeaponData = _make_weapon_data({
|
||||
weapon_id = ID_USP,
|
||||
weapon_name = "USP-S",
|
||||
slot = 1,
|
||||
damage = 28,
|
||||
fire_rate = 5.0,
|
||||
magazine_size = 12,
|
||||
reserve_size = 24,
|
||||
recoil_per_shot = 0.3,
|
||||
move_speed_multiplier = 0.86,
|
||||
price = 200,
|
||||
kill_reward = 300,
|
||||
armor_penetration = 0.50,
|
||||
team = 1, # CT default
|
||||
})
|
||||
|
||||
static var _ak47: WeaponData = _make_weapon_data({
|
||||
weapon_id = ID_AK47,
|
||||
weapon_name = "AK-47",
|
||||
slot = 3,
|
||||
damage = 36,
|
||||
fire_mode = WeaponData.FireMode.AUTO,
|
||||
fire_rate = 10.0,
|
||||
magazine_size = 30,
|
||||
reserve_size = 90,
|
||||
recoil_per_shot = 0.8,
|
||||
recoil_recovery = 6.0,
|
||||
spread_walking = 3.0,
|
||||
spread_sprinting = 8.0,
|
||||
move_speed_multiplier = 0.78,
|
||||
price = 2700,
|
||||
kill_reward = 300,
|
||||
armor_penetration = 0.77,
|
||||
team = 0,
|
||||
})
|
||||
|
||||
static var _m4a1: WeaponData = _make_weapon_data({
|
||||
weapon_id = ID_M4A1,
|
||||
weapon_name = "M4A1-S",
|
||||
slot = 3,
|
||||
damage = 33,
|
||||
fire_mode = WeaponData.FireMode.AUTO,
|
||||
fire_rate = 10.0,
|
||||
magazine_size = 25,
|
||||
reserve_size = 75,
|
||||
recoil_per_shot = 0.7,
|
||||
recoil_recovery = 7.0,
|
||||
spread_walking = 2.5,
|
||||
spread_sprinting = 7.0,
|
||||
move_speed_multiplier = 0.78,
|
||||
price = 2900,
|
||||
kill_reward = 300,
|
||||
armor_penetration = 0.77,
|
||||
team = 1,
|
||||
})
|
||||
|
||||
static var _awp: WeaponData = _make_weapon_data({
|
||||
weapon_id = ID_AWP,
|
||||
weapon_name = "AWP",
|
||||
slot = 4,
|
||||
damage = 115,
|
||||
fire_rate = 1.5,
|
||||
magazine_size = 10,
|
||||
reserve_size = 30,
|
||||
recoil_per_shot = 4.0,
|
||||
recoil_recovery = 1.0,
|
||||
spread_idle = 0.0,
|
||||
spread_walking = 10.0,
|
||||
spread_sprinting = 20.0,
|
||||
move_speed_multiplier = 0.57,
|
||||
price = 4750,
|
||||
kill_reward = 100,
|
||||
armor_penetration = 0.87,
|
||||
max_distance = 2000.0,
|
||||
headshot_multiplier = 5.0, # AWP one-shots through armor
|
||||
})
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Factory
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
static func _make_weapon_data(dict: Dictionary) -> WeaponData:
|
||||
var w := WeaponData.new()
|
||||
for key in dict:
|
||||
w.set(key, dict[key])
|
||||
return w
|
||||
|
||||
## Look up a weapon by its ID.
|
||||
static func get_by_id(id: int) -> WeaponData:
|
||||
return BY_ID.get(id, _knife)
|
||||
|
||||
## Get the default weapon for a team (0=T, 1=CT).
|
||||
static func get_default_weapon(team_id: int) -> WeaponData:
|
||||
return _glock if team_id == 0 else _usp
|
||||
@@ -0,0 +1,89 @@
|
||||
## TacticalWeaponHitscan — rollback-aware hitscan weapon for the tactical shooter.
|
||||
##
|
||||
## Extends NetworkWeaponHitscan3D with per-limb damage, team checks,
|
||||
## and headshot detection.
|
||||
##
|
||||
## This script is ONLY loaded from client scenes where netfox is active.
|
||||
## The server handles damage authority directly.
|
||||
|
||||
extends "res://addons/netfox.extras/weapon/network-weapon-hitscan-3d.gd"
|
||||
class_name TacticalWeaponHitscan
|
||||
|
||||
## Weapon data resource (stats) — set on spawn
|
||||
var weapon_data: WeaponData = null
|
||||
|
||||
## Weapon owner's peer ID — set on spawn
|
||||
var owner_peer_id: int = -1
|
||||
|
||||
## Cooldown tick for rate-of-fire limiting
|
||||
var _last_fire_tick: int = -1
|
||||
|
||||
func _can_fire() -> bool:
|
||||
if weapon_data == null:
|
||||
return false
|
||||
if weapon_data.fire_mode == WeaponData.FireMode.MELEE:
|
||||
return true # Melee always "can fire"
|
||||
|
||||
# Rate-of-fire check using network tick
|
||||
var nt = Engine.get_singleton(&"NetworkTime")
|
||||
if nt == null:
|
||||
return true
|
||||
var current_tick := nt.tick if nt.has_method(&"get_tick") else 0
|
||||
if _last_fire_tick >= 0:
|
||||
var tick_interval := maxi(1, int(weapon_data.fire_rate / 64.0))
|
||||
if current_tick - _last_fire_tick < tick_interval:
|
||||
return false
|
||||
return true
|
||||
|
||||
func _can_peer_use(peer_id: int) -> bool:
|
||||
return peer_id == owner_peer_id
|
||||
|
||||
func _after_fire():
|
||||
# Track fire tick for cooldown
|
||||
var nt = Engine.get_singleton(&"NetworkTime")
|
||||
if nt != null:
|
||||
_last_fire_tick = nt.tick if nt.has_method(&"get_tick") else 0
|
||||
|
||||
## Handle a raycast hit — called on ALL peers with rollback reconciliation.
|
||||
func _on_hit(result: Dictionary):
|
||||
if weapon_data == null:
|
||||
return
|
||||
if not multiplayer.is_server() and not is_multiplayer_authority():
|
||||
return # Only server/authority applies damage
|
||||
|
||||
var collider := result.get("collider")
|
||||
if collider == null:
|
||||
return
|
||||
|
||||
# Determine limb hit via collision groups
|
||||
var damage_multiplier: float = weapon_data.chest_multiplier
|
||||
var is_headshot := false
|
||||
|
||||
if collider is Node:
|
||||
if collider.is_in_group(&"head"):
|
||||
damage_multiplier = weapon_data.headshot_multiplier
|
||||
is_headshot = true
|
||||
elif collider.is_in_group(&"chest"):
|
||||
damage_multiplier = weapon_data.chest_multiplier
|
||||
elif collider.is_in_group(&"waist"):
|
||||
damage_multiplier = weapon_data.waist_multiplier
|
||||
elif collider.is_in_group(&"legs"):
|
||||
damage_multiplier = weapon_data.leg_multiplier
|
||||
|
||||
var final_damage := int(weapon_data.damage * damage_multiplier)
|
||||
|
||||
# Find the player node from the collider
|
||||
var player := _find_player(collider)
|
||||
if player != null and player.has_method(&"apply_damage"):
|
||||
if is_headshot:
|
||||
print("[TacticalWeapon] HEADSHOT on %s for %d" % [player.name, final_damage])
|
||||
player.apply_damage(final_damage, owner_peer_id, weapon_data.weapon_id)
|
||||
|
||||
## Find a player node walking up the scene tree.
|
||||
func _find_player(node: Node) -> Node:
|
||||
var current = node
|
||||
while current != null:
|
||||
if current.has_method(&"apply_damage") or current.is_in_group(&"players"):
|
||||
return current
|
||||
current = current.get_parent()
|
||||
return null
|
||||
@@ -0,0 +1,200 @@
|
||||
## WeaponManager — client-side weapon inventory with rollback-safe firing.
|
||||
##
|
||||
## Manages weapon switching, ammo tracking. Firing is handled by the
|
||||
## RollbackHitscanManager (in _rollback_tick) for lag compensation.
|
||||
##
|
||||
## This script is ONLY loaded from client scenes where netfox is active.
|
||||
|
||||
extends Node
|
||||
class_name WeaponManager
|
||||
|
||||
signal weapon_switched(old_slot: int, new_slot: int, weapon_data: WeaponData)
|
||||
signal ammo_changed(weapon_id: int, magazine: int, reserve: int)
|
||||
|
||||
# Preload the weapon scripts (only works when netfox is active)
|
||||
const _HitscanWeapon := preload("res://client/weapons/scripts/tactical_weapon_hitscan.gd")
|
||||
|
||||
## Reference to the player's weapon anchor node.
|
||||
@export var weapon_anchor: Node3D
|
||||
|
||||
## Reference to the RollbackHitscanManager (set by player).
|
||||
var rollback_hitscan_mgr: Node = null
|
||||
|
||||
## Current weapon data.
|
||||
var current_weapon: WeaponData = null
|
||||
var current_weapon_node: Node3D = null
|
||||
var current_slot: int = 1
|
||||
|
||||
## Inventory: slot → { data, node, magazine, reserve }
|
||||
var _inventory: Dictionary = {}
|
||||
|
||||
var _last_fire_time: float = 0.0
|
||||
|
||||
func add_weapon(data: WeaponData) -> void:
|
||||
var slot: int = data.slot
|
||||
if _inventory.has(slot):
|
||||
_remove_weapon(slot)
|
||||
|
||||
var weapon_node: Node3D = _create_weapon(data)
|
||||
if weapon_node == null:
|
||||
return
|
||||
weapon_node.visible = false
|
||||
add_child(weapon_node)
|
||||
|
||||
_inventory[slot] = {
|
||||
"data": data,
|
||||
"node": weapon_node,
|
||||
"magazine": data.magazine_size,
|
||||
"reserve": data.reserve_size,
|
||||
}
|
||||
|
||||
if current_weapon == null:
|
||||
switch_to_slot(slot)
|
||||
|
||||
func remove_weapon(slot: int) -> void:
|
||||
_remove_weapon(slot)
|
||||
if current_slot == slot:
|
||||
_switch_to_next_available()
|
||||
|
||||
func switch_to_slot(slot: int) -> bool:
|
||||
if not _inventory.has(slot):
|
||||
return false
|
||||
var entry = _inventory[slot]
|
||||
var old_slot := current_slot
|
||||
current_slot = slot
|
||||
current_weapon = entry["data"] as WeaponData
|
||||
current_weapon_node = entry["node"] as Node3D
|
||||
_update_visibility()
|
||||
weapon_switched.emit(old_slot, slot, current_weapon)
|
||||
|
||||
# Update the RollbackHitscanManager with the new weapon data
|
||||
_notify_hitscan_mgr_of_weapon_change(current_weapon)
|
||||
return true
|
||||
|
||||
func switch_next() -> void:
|
||||
var slots := _inventory.keys()
|
||||
slots.sort()
|
||||
var idx := slots.find(current_slot)
|
||||
if idx >= 0 and idx + 1 < slots.size():
|
||||
switch_to_slot(slots[idx + 1])
|
||||
|
||||
func switch_prev() -> void:
|
||||
var slots := _inventory.keys()
|
||||
slots.sort()
|
||||
var idx := slots.find(current_slot)
|
||||
if idx > 0:
|
||||
switch_to_slot(slots[idx - 1])
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Firing (rollback-safe — delegates to RollbackHitscanManager)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
## Called by the client to attempt firing through the rollback system.
|
||||
## Returns true if ammo was consumed.
|
||||
func fire() -> bool:
|
||||
if current_weapon_node == null or current_weapon == null:
|
||||
return false
|
||||
if current_weapon.magazine_size > 0 and _get_magazine() <= 0:
|
||||
return false
|
||||
if not _check_fire_rate():
|
||||
return false
|
||||
|
||||
# Consume ammo immediately for client prediction
|
||||
var entry = _inventory[current_slot]
|
||||
entry["magazine"] -= 1
|
||||
ammo_changed.emit(current_weapon.weapon_id, entry["magazine"], entry["reserve"])
|
||||
_last_fire_time = Time.get_ticks_msec() / 1000.0
|
||||
|
||||
# The actual raycast and damage happen in the RollbackHitscanManager's
|
||||
# process_fire() during _rollback_tick(), triggered by the shoot input.
|
||||
# This method just handles the client-side ammo tracking.
|
||||
return true
|
||||
|
||||
func reload() -> void:
|
||||
if current_weapon == null or current_weapon.magazine_size <= 0:
|
||||
return
|
||||
var entry = _inventory[current_slot]
|
||||
if entry["magazine"] >= current_weapon.magazine_size or entry["reserve"] <= 0:
|
||||
return
|
||||
var needed := current_weapon.magazine_size - entry["magazine"]
|
||||
var available := min(needed, entry["reserve"])
|
||||
entry["magazine"] += available
|
||||
entry["reserve"] -= available
|
||||
ammo_changed.emit(current_weapon.weapon_id, entry["magazine"], entry["reserve"])
|
||||
|
||||
func get_ammo() -> Vector2i:
|
||||
if current_weapon == null or not _inventory.has(current_slot):
|
||||
return Vector2i.ZERO
|
||||
var e = _inventory[current_slot]
|
||||
return Vector2i(e["magazine"], e["reserve"])
|
||||
|
||||
## Get the current weapon's maximum distance for raycasting.
|
||||
func get_max_distance() -> float:
|
||||
if current_weapon != null:
|
||||
return current_weapon.max_distance
|
||||
return 1000.0
|
||||
|
||||
## Get the current weapon ID.
|
||||
func get_weapon_id() -> int:
|
||||
if current_weapon != null:
|
||||
return current_weapon.weapon_id
|
||||
return 0
|
||||
|
||||
func get_current_weapon_data() -> WeaponData:
|
||||
return current_weapon
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Rollback integration
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
## Notify the RollbackHitscanManager when the weapon changes.
|
||||
func _notify_hitscan_mgr_of_weapon_change(wd: WeaponData) -> void:
|
||||
if rollback_hitscan_mgr != null and rollback_hitscan_mgr.has_method(&"set_weapon_data"):
|
||||
rollback_hitscan_mgr.set_weapon_data(wd)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Internal
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
func _create_weapon(data: WeaponData) -> Node3D:
|
||||
var weapon := Node3D.new()
|
||||
weapon.name = data.weapon_name
|
||||
|
||||
if data.fire_mode != WeaponData.FireMode.MELEE:
|
||||
var hs: TacticalWeaponHitscan = _HitscanWeapon.new()
|
||||
hs.name = "Hitscan"
|
||||
hs.weapon_data = data
|
||||
hs.max_distance = data.max_distance
|
||||
weapon.add_child(hs, true)
|
||||
|
||||
return weapon
|
||||
|
||||
func _get_magazine() -> int:
|
||||
var e = _inventory.get(current_slot)
|
||||
return e["magazine"] if e else 0
|
||||
|
||||
func _check_fire_rate() -> bool:
|
||||
if current_weapon.fire_rate <= 0:
|
||||
return false
|
||||
var now := Time.get_ticks_msec() / 1000.0
|
||||
return (now - _last_fire_time) >= (1.0 / current_weapon.fire_rate)
|
||||
|
||||
func _remove_weapon(slot: int) -> void:
|
||||
var e = _inventory.get(slot)
|
||||
if e and e["node"]:
|
||||
e["node"].queue_free()
|
||||
_inventory.erase(slot)
|
||||
|
||||
func _switch_to_next_available() -> void:
|
||||
var slots := _inventory.keys()
|
||||
slots.sort()
|
||||
if slots.size() > 0:
|
||||
switch_to_slot(slots[0])
|
||||
else:
|
||||
current_weapon = null
|
||||
current_weapon_node = null
|
||||
_update_visibility()
|
||||
|
||||
func _update_visibility() -> void:
|
||||
for slot in _inventory:
|
||||
_inventory[slot]["node"].visible = (slot == current_slot)
|
||||
Reference in New Issue
Block a user