Captures the uncommitted parallel-development work (increments 46-49) on the
40250 classic client port, folded into docs/CLIENT-GAP.md + CLIENT-GAP-FIX.md.
Increment 49 (W0 interface-freeze batch, Phase 1 prerequisite) lands the
cross-workflow shared-file scaffolding so the 4 Phase 1 workflows can run in
isolated worktrees without contention:
- entity_store.{h,cpp}: Entity gains empire/affect_flags/owner_vid/state_flags;
new mut_spawn_full() (single-shot two-packet merge, §2.3), mut_ownership()
(§2.5), mut_map_bgm() + take_bgm_dirty()/bgm_name()/bgm_volume() (§9.1),
drain_dirty() (§2.1/§2.5 bare-field-update queue); mut_char_info() now stores
empire; reset_for_map_change() clears m_dirty.
- m2_client.cpp: new bgm_changed(name, volume) signal; classic + m2dev pump
loops drain drain_dirty() -> entity_info and take_bgm_dirty() -> bgm_changed;
entity_dict() exposes the 4 new keys.
- classic/classic_parser.{h,cpp}: GC_MAIN_CHARACTER3_BGM /
GC_MAIN_CHARACTER4_BGM_VOL route bgm_name/bgm_volume to mut_map_bgm() (was
discarded); new m_pending_actor staging map (W1 fills §2.2 merge logic).
- project/bgm_director.gd (new) + game_scene.gd: BGM consumption split out of
net_world.gd so W2/W4 don't collide; §8.6/§4.8 keybind convergence (digits
1-4 -> quickslots 0-3, F1-F4 -> quickslots 4-7, Ctrl+1..9 -> _emote()).
Tests: cmake --build build clean; ctest 16/16; 15 GDScript regressions green
(netbridge, gamescene, netplay, p9, p10, p2b, p8, system_menu_ui, skill,
combat_fx, skill_fx, player_motion, char_status_ui, chat, inventory), no skips.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yvAPqPivoY7vmBbzgqK4W
133 lines
4.0 KiB
GDScript
133 lines
4.0 KiB
GDScript
# GroundItems (P2) —— 世界里的掉落物:GC_ITEM_GROUND_ADD/DEL → 小物体 + 名条 + 拾取。
|
||
#
|
||
# var gi := preload("res://ui/ground_items.gd").new()
|
||
# add_child(gi)
|
||
# gi.setup(m2client, mount_node, player_getter, proto, item_list)
|
||
# # 按拾取键时: gi.try_pickup() -> 捡最近的一个(<PICKUP_RANGE m)
|
||
#
|
||
# M2Client.ground_item_added(Dict{vid,vnum,pos,owner}) / ground_item_removed(vid) 驱动。
|
||
extends Node
|
||
|
||
const PICKUP_RANGE := 3.0
|
||
|
||
var client: Node
|
||
var mount: Node3D
|
||
var proto: Node
|
||
var item_list: RefCounted
|
||
var _player_getter: Callable
|
||
var _by_vid := {} # vid -> Node3D
|
||
|
||
func setup(m2client: Node, mount_node: Node3D, player_getter: Callable,
|
||
proto_node: Node = null, il: RefCounted = null) -> void:
|
||
client = m2client
|
||
mount = mount_node
|
||
proto = proto_node
|
||
item_list = il
|
||
_player_getter = player_getter
|
||
if client.has_signal("ground_item_added"):
|
||
client.ground_item_added.connect(_on_added)
|
||
if client.has_signal("ground_item_removed"):
|
||
client.ground_item_removed.connect(_on_removed)
|
||
# 已在场的(重连)
|
||
if client.has_method("get_ground_items"):
|
||
for d in client.get_ground_items():
|
||
_on_added(d)
|
||
|
||
func _on_added(d: Dictionary) -> void:
|
||
var vid := int(d.get("vid", 0))
|
||
if vid == 0:
|
||
return
|
||
var vnum := int(d.get("vnum", 0))
|
||
var owner := String(d.get("owner", ""))
|
||
if _by_vid.has(vid):
|
||
var existing: Node3D = _by_vid[vid]
|
||
if is_instance_valid(existing):
|
||
(existing.get_node("tag") as Label3D).text = _tag_text(vnum, owner)
|
||
return
|
||
var node := Node3D.new()
|
||
node.name = "drop_%d" % vid
|
||
node.position = d.get("pos", Vector3.ZERO)
|
||
var mesh := MeshInstance3D.new()
|
||
var box := BoxMesh.new()
|
||
box.size = Vector3(0.25, 0.25, 0.25)
|
||
mesh.mesh = box
|
||
mesh.position.y = 0.3
|
||
var mat := StandardMaterial3D.new()
|
||
mat.albedo_color = Color(1.0, 0.85, 0.3)
|
||
mat.emission_enabled = true
|
||
mat.emission = Color(0.6, 0.5, 0.1)
|
||
mesh.material_override = mat
|
||
node.add_child(mesh)
|
||
var tag := Label3D.new()
|
||
tag.name = "tag"
|
||
tag.text = _tag_text(vnum, owner)
|
||
tag.position.y = 0.75
|
||
tag.billboard = BaseMaterial3D.BILLBOARD_ENABLED
|
||
tag.no_depth_test = true
|
||
tag.pixel_size = 0.005
|
||
tag.modulate = Color(1.0, 0.9, 0.5)
|
||
node.add_child(tag)
|
||
node.set_meta("vid", vid)
|
||
mount.add_child(node)
|
||
_by_vid[vid] = node
|
||
|
||
func _on_removed(vid: int) -> void:
|
||
var n: Node3D = _by_vid.get(vid, null)
|
||
if n:
|
||
_by_vid.erase(vid)
|
||
n.queue_free()
|
||
|
||
func clear_for_map_change() -> void:
|
||
for vid in _by_vid.keys():
|
||
var node: Node3D = _by_vid[vid]
|
||
if is_instance_valid(node):
|
||
node.queue_free()
|
||
_by_vid.clear()
|
||
|
||
func _process(dt: float) -> void:
|
||
var p: Node3D = _player_getter.call() if _player_getter.is_valid() else null
|
||
if p == null:
|
||
return
|
||
var t := Time.get_ticks_msec() / 1000.0
|
||
for vid in _by_vid:
|
||
var n: Node3D = _by_vid[vid]
|
||
if is_instance_valid(n):
|
||
var m := n.get_child(0) as MeshInstance3D
|
||
if m:
|
||
m.rotation.y = t * 2.0
|
||
# 近了名条高亮
|
||
var near := p.global_position.distance_to(n.global_position) <= PICKUP_RANGE
|
||
(n.get_node("tag") as Label3D).modulate = Color(0.4, 1.0, 0.4) if near else Color(1.0, 0.9, 0.5)
|
||
|
||
# 捡最近的一个(范围内)。返回捡的 vid,0 = 没有。
|
||
func try_pickup() -> int:
|
||
var p: Node3D = _player_getter.call() if _player_getter.is_valid() else null
|
||
if p == null or client == null:
|
||
return 0
|
||
var best_vid := 0
|
||
var best_d := PICKUP_RANGE
|
||
for vid in _by_vid:
|
||
var n: Node3D = _by_vid[vid]
|
||
if not is_instance_valid(n):
|
||
continue
|
||
var d := p.global_position.distance_to(n.global_position)
|
||
if d < best_d:
|
||
best_d = d
|
||
best_vid = int(vid)
|
||
if best_vid != 0:
|
||
client.pickup_item(best_vid)
|
||
return best_vid
|
||
|
||
func _name_for(vnum: int) -> String:
|
||
if proto:
|
||
var pd: Dictionary = proto.item(vnum)
|
||
if not pd.is_empty():
|
||
return String(pd.get("locale_name", pd.get("name", "item %d" % vnum)))
|
||
if item_list and item_list.has(vnum):
|
||
return item_list.type_of(vnum)
|
||
return "item %d" % vnum
|
||
|
||
func _tag_text(vnum: int, owner: String) -> String:
|
||
var text := _name_for(vnum)
|
||
return "%s (%s)" % [text, owner] if not owner.is_empty() else text
|