Networked client on the existing Godot 4.7 + libgr2 renderer:
- net: m2dev wire protocol (libsodium KX + XChaCha20), auth/select/game
phases, EntityStore world model, ~all GC/CG headers. char create/delete,
private shop / mall / cube, SHOP_GC_START_EX, guild, party (+ CG_PARTY_SET_STATE),
quests, dragon soul, refine, safebox, exchange.
- UI: in-game windows migrated 1:1 from the reference uiscript/root .py —
char status (/stat), inventory+equipment, select-item ([SELECT_ITEM] quest
token), system-option + game-option + ESC system menu, private-shop 39-grid,
party info board, shop tabs, atlas, minimap, quickbar, chat, …
- EterGrnLib polish: GR2 material blend/two-sided, LOD crossfade, motion-event
dispatch, contact shadow, ray-AABB picking, weapon grip pre-transform.
Portable asset IO (A1) — all extension/libgr2/formats/mtproto reads routed
through godot::FileAccess (res:// PCK works on iOS/Android); standalone-lib
*_path() kept for the non-Godot CTests. AssetResolver + PropertyRegistry
switched to a baked index (bake_asset_index.gd) instead of std::filesystem.
Mobile builds: build-{android,ios}.sh, export-android.sh, pack-assets.sh,
gen-debug-keystore.sh. Assets ship as a zip mounted at runtime by
project/asset_pack.gd (adb push now; HTTP download is a drop-in later).
ctest 10/10, 34 GDScript suites, macOS/iOS/Android all build.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013EJxkHiNKS4kybHS3XKyAJ
40 lines
1.7 KiB
GDScript
40 lines
1.7 KiB
GDScript
# MapCoord —— 网络实体坐标 ↔ Metin2World 本地坐标。
|
||
#
|
||
# M2Client 给的实体 pos 是「全局服务器 cm」经 position_to_godot 后的结果:
|
||
# net = (sx*0.01, h, -sy*0.01) (sx/sy 含地图 BasePosition)
|
||
# 而 Metin2World 的地形/物件是「地图本地」帧(tile 0 在原点,+Z 朝南):
|
||
# world = ((sx-bx)*0.01, h, (sy-by)*0.01)
|
||
# 两者差一个 BasePosition 平移 + Z 轴翻向。没对齐时角色会飘在几公里外的黑void里。
|
||
#
|
||
# MapCoord.set_base(world.get_map_base_cm()) # Vector2,cm
|
||
# var p := MapCoord.to_world(client.get_entity(vid).pos)
|
||
# var sc := MapCoord.to_server_cm(player.position) # -> Vector2 (sx_cm, sy_cm)
|
||
class_name MapCoord
|
||
extends RefCounted
|
||
|
||
static var _bx := 0.0 # BasePosition.x, cm
|
||
static var _by := 0.0
|
||
|
||
static func set_base(base_cm: Vector2) -> void:
|
||
_bx = base_cm.x
|
||
_by = base_cm.y
|
||
|
||
static func has_base() -> bool:
|
||
return _bx != 0.0 or _by != 0.0
|
||
|
||
# net 帧 (sx*.01, h, -sy*.01) -> world 本地帧 ((sx-bx)*.01, h, (sy-by)*.01)
|
||
static func to_world(net_pos: Vector3) -> Vector3:
|
||
return Vector3(net_pos.x - _bx * 0.01, net_pos.y, -net_pos.z - _by * 0.01)
|
||
|
||
# world 本地帧 -> 服务器全局 cm (sx, sy)
|
||
static func to_server_cm(world_pos: Vector3) -> Vector2:
|
||
return Vector2(world_pos.x * 100.0 + _bx, world_pos.z * 100.0 + _by)
|
||
|
||
# 服务器 heading(度) -> world 帧 Godot yaw(弧度)。
|
||
# net 帧里南=-Z、world 帧里南=+Z,Z 翻向 -> 相对 net 帧的换算符号取反。
|
||
static func heading_to_yaw(angle_deg: float) -> float:
|
||
return deg_to_rad(angle_deg + 90.0)
|
||
|
||
static func yaw_to_heading(yaw_rad: float) -> float:
|
||
return fposmod(rad_to_deg(yaw_rad) - 90.0, 360.0)
|