开发记录
角色登入
选择角色进入游戏并能走动(处理来自客户端的登入请求C_OPCODE_LOGINTOSERVER = 55 # 請求登錄角色
)
Nov 17, 2016 10:40:21 AM l1j.server.server.ClientThread run
INFO: [Recv C]
0000: 37 54 65 73 74 00 f0 37 7Test..7 C_OPCODE_LOGINTOSERVER
Nov 17, 2016 10:40:21 AM l1j.server.server.clientpackets.C_LoginToServer <init>
INFO: 【進入遊戲】 角色名稱:Test 玩家帳號:fwdssg 玩家IP:192.168.30.192
[Send C]:
0000: 79 04 00 00 04 00 00 00 y....... S_OPCODE_HOUSEMAP
[Send C]:
0000: 29 03 00 f7 ad 74 00 e5 )....t.. S_OPCODE_LOGINTOGAME
[Send C]:
[Send C]:
0000: 64 14 69 d.i S_OPCODE_PACKETBOX
[Send C]:
0000: 64 57 00 00 00 00 00 00 dW...... S_OPCODE_PACKETBOX
[Send C]:
0000: 22 c5 42 2f 13 01 00 00 00 00 10 08 09 0c 12 0c ".B/............ S_OPCODE_OWNCHARSTATUS
0010: 10 00 10 00 01 00 01 00 0a 44 f3 f5 96 28 00 00 .........D...(..
0020: 00 00 00 00 00 .....
[Send C]:
0000: 20 45 00 00 00 00 00 00 00 00 00 00 E.......... S_OPCODE_MAPID
[Send C]:
0000: 37 ca 7f 6d 80 c5 42 2f 13 3d 00 00 05 00 00 00 7.m..B/.=...... S_OPCODE_CHARPACK
0010: 00 00 00 00 00 54 65 73 74 00 00 04 00 00 00 00 .....Test.......
0020: 00 00 00 ff 00 00 00 ff ff .........
[Send C]:
0000: 53 00 00 00 S... S_OPCODE_SPMR
[Send C]:
0000: 6c c5 42 2f 13 00 00 00 l.B/.... S_OPCODE_CHARTITLE
[Send C]:
0000: 4f 04 00 00 O... S_OPCODE_WEATHER
[Send C]:
0000: 45 0c c6 42 2f 13 ff 00 05 00 01 20 a1 07 00 00 E..B/...... .... S_OPCODE_INVLIST
0010: bd f0 b1 d2 20 28 35 30 30 30 30 30 29 00 00 c7 .... (500000)...
0020: 42 2f 13 00 00 1a 07 01 e8 03 00 00 00 ba da c9 B/..............
0030: ab c3 d7 cb f7 c0 f2 bc fd 20 28 31 30 30 30 29 ......... (1000)
0040: 00 00 cd 42 2f 13 00 00 6d 02 01 1e 00 00 00 00 ...B/...m.......
0050: c7 bf bb af d7 d4 ce d2 bc d3 cb d9 d2 a9 cb ae ................
0060: 20 28 33 30 29 00 00 ce 42 2f 13 00 00 8b 04 01 (30)...B/......
0070: c8 00 00 00 00 b9 c5 b4 fa d6 d5 bc ab cc e5 c1 ................
0080: a6 bb d6 b8 b4 bc c1 20 28 32 30 30 29 00 00 d3 ....... (200)...
0090: 42 2f 13 10 00 d8 01 01 c8 00 00 00 00 b1 e4 d0 B/..............
00a0: ce be ed d6 e1 20 28 32 30 30 29 00 00 d4 42 2f ..... (200)...B/
00b0: 13 00 00 e0 06 01 01 00 00 00 00 cb b5 bb b0 be ................
00c0: ed d6 e1 00 00 d5 42 2f 13 06 00 d9 01 01 f4 01 ......B/........
00d0: 00 00 00 cb b2 bc e4 d2 c6 b6 af be ed d6 e1 20 ...............
00e0: 28 35 30 30 29 00 00 d9 42 2f 13 00 00 2e 0a 01 (500)...B/......
00f0: c8 00 00 00 00 c4 a7 b7 a8 bd e1 be a7 cc e5 20 ...............
0100: 28 32 30 30 29 00 00 dd 42 2f 13 00 00 46 06 01 (200)...B/...F..
0110: 01 00 00 00 00 bc c6 cb e3 bb fa 00 00 de 42 2f ..............B/
0120: 13 17 00 72 02 01 01 00 00 00 00 c3 f0 c4 a7 bd ...r............
0130: e4 d6 b8 00 00 df 42 2f 13 17 00 72 02 01 01 00 ......B/...r....
0140: 00 00 00 c3 f0 c4 a7 bd e4 d6 b8 00 00 e7 42 2f ..............B/
0150: 13 01 00 17 01 01 01 00 00 00 00 c1 d4 c8 cb d6 ................
0160: ae b9 ad 00 00 .....
[Send C]:
0000: 66 c5 42 2f 13 00 00 00 f.B/.... S_OPCODE_LIGHT
[Send C]:
[Send C]:
0000: 22 c5 42 2f 13 01 00 00 00 00 10 08 09 0c 12 0c ".B/............ S_OPCODE_OWNCHARSTATUS
0010: 10 00 10 00 01 00 01 00 0a 44 f3 f5 96 28 00 00 .........D...(..
0020: 00 00 00 00 00 .....
[Send C]:
0000: 37 cb 7f 73 80 55 01 30 13 db 03 00 05 0e 00 00 7.s.U.0........ S_OPCODE_DROPITEM
0010: 00 00 00 00 00 cc e1 b0 c2 00 00 00 00 00 00 00 ................
0020: 00 00 00 ff 00 01 00 ff ff .........
[Send C]:
0000: 37 c2 7f 69 80 d7 44 2f 13 e6 03 00 05 00 00 05 7.i..D/........ S_OPCODE_DROPITEM
0010: 00 00 00 01 80 cd c3 d7 d3 00 00 00 00 00 00 00 ................
0020: 00 00 00 ff 00 02 00 ff ff .........
[Send C]:
0000: 37 cf 7f 69 80 d5 44 2f 13 e6 03 00 01 00 00 05 7.i..D/........ S_OPCODE_DROPITEM
0010: 00 00 00 01 80 cd c3 d7 d3 00 00 00 00 00 00 00 ................
0020: 00 00 00 ff 00 02 00 ff ff .........
[Send C]:
0000: 3e d7 44 2f 13 c2 7f 69 80 03 81 00 00 00 00 00 >.D/..i........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 37 c7 7f 73 80 d6 44 2f 13 e6 03 00 05 00 00 05 7.s..D/........ S_OPCODE_DROPITEM
0010: 00 00 00 01 80 cd c3 d7 d3 00 00 00 00 00 00 00 ................
0020: 00 00 00 ff 00 02 00 ff ff .........
[Send C]:
0000: 37 cc 7f 61 80 ac 01 30 13 ac 03 00 05 0e 00 00 7.a...0........ S_OPCODE_DROPITEM
0010: 00 00 00 00 00 c0 d7 bf cb c2 fc 00 00 00 00 00 ................
0020: 00 00 00 00 00 ff 00 00 00 ff ff ...........
[Send C]:
0000: 37 c2 7f 71 80 aa ff 2f 13 5d 08 00 06 0e 00 00 7.q.../.]...... S_OPCODE_DROPITEM
0010: 00 00 00 00 00 b3 f5 bc b6 b4 ab cb cd ca a6 00 ................
0020: 00 00 00 00 00 00 00 00 00 ff 00 00 00 ff ff ...............
[Send C]:
0000: 3e d5 44 2f 13 cf 7f 69 80 04 81 00 00 00 00 00 >.D/..i........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d7 44 2f 13 c3 7f 6a 80 03 81 00 00 00 00 00 >.D/..j........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d5 44 2f 13 cf 7f 6a 80 04 81 00 00 00 00 00 >.D/..j........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d7 44 2f 13 c4 7f 6b 80 03 81 00 00 00 00 00 >.D/..k........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d5 44 2f 13 cf 7f 6b 80 04 81 00 00 00 00 00 >.D/..k........ S_OPCODE_MOVEOBJECT
INFO: [Recv C]
0000: 6a 00 00 00 j... C_OPCODE_KEEPALIVE
INFO: [Recv C]
0000: 72 06 01 00 r... C_OPCODE_LOGINTOSERVEROK
INFO: [Recv C]
0000: 72 09 00 d7 r... C_OPCODE_LOGINTOSERVEROK
INFO: [Recv C]
0000: 72 0a 01 7a r..z C_OPCODE_LOGINTOSERVEROK
INFO: [Recv C]
0000: 23 0d 01 0b #... C_OPCODE_SENDLOCATION
[Send C]:
0000: 3e d6 44 2f 13 c7 7f 73 80 06 81 00 00 00 00 00 >.D/..s........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d7 44 2f 13 c5 7f 6c 80 03 81 00 00 00 00 00 >.D/..l........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d5 44 2f 13 cf 7f 6c 80 04 81 00 00 00 00 00 >.D/..l........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d6 44 2f 13 c6 7f 73 80 06 81 00 00 00 00 00 >.D/..s........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d7 44 2f 13 c6 7f 6d 80 03 81 00 00 00 00 00 >.D/..m........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d6 44 2f 13 c5 7f 73 80 06 81 00 00 00 00 00 >.D/..s........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d7 44 2f 13 c7 7f 6e 80 03 81 00 00 00 00 00 >.D/..n........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d6 44 2f 13 c4 7f 73 80 06 81 00 00 00 00 00 >.D/..s........ S_OPCODE_MOVEOBJECT
[Send C]:
0000: 3e d7 44 2f 13 c8 7f 6f 80 00 81 00 00 00 00 00 >.D/..o........ S_OPCODE_MOVEOBJECT
INFO: [Recv C]
0000: 2b 38 00 00 +8.. C_OPCODE_QUITGAME
经过测试其中角色进入游戏需要发送的最少数据包及顺序如下:
- S_OPCODE_HOUSEMAP
- S_OPCODE_LOGINTOGAME
- 4个空字节
- S_OPCODE_OWNCHARSTATUS
- S_OPCODE_MAPID
- S_OPCODE_CHARPACK
- S_OPCODE_CHARTITLE
- S_OPCODE_OWNCHARSTATUS
接下来分析对应处理代码,将可以延后实现的代码注释,列举核心功能点
C_OPCODE_LOGINTOSERVER
需要实现:
- 世界系统(所有游戏对象的存储和删除):World.py
- 复活点系统(重新登入或者使用回家卷轴返回的位置):GetBackRestartTable.py、GetBackRestart.py、GetBackTable.py
- 村庄位置系统(返回每个村庄的回城点):TownLocation.py
S_OPCODE_HOUSEMAP
需要实现:S_InitialAbilityGrowth.py
S_OPCODE_LOGINTOGAME
需要实现:S_LoginToGame.py
S_OPCODE_OWNCHARSTATUS
需要实现:
- 游戏时钟系统(游戏时间和现实时间的相互映射):GameTime.py、GameTimeClock.py
- 玩家仓库系统(玩家仓库道具的添加、更新和删除,以及道具重量和数目的统计;初期可以跳过道具的相关操作的具体实现,只需返回空即可):Inventory.py、PcInventory.py
S_OPCODE_MAPID
需要实现:S_MapID.py
S_OPCODE_CHARPACK
需要实现:S_OwnCharPack.py
S_OPCODE_CHARTITLE
需要实现:S_CharTitle.py
延后实现:
- 道具系统
- 仓库系统
- 战争管理
- 视觉效果显示(中毒、水下)
- 祝福经验
- 血盟系统
- 结婚系统
- 地狱系统
- 在线奖励系统
- GM监视系统
- 角色封号系统
- 记忆坐标系统
- 服务器时间系统
- 灯光系统
- 技能系统
- 宠物系统
- 聊天系统
- 税收系统
- 装备道具系统
世界系统
World
实现游戏世界对象的存储,
获取游戏范围的可见对象
- 直线上的可见游戏对象:两个游戏对象间的可见对象(游戏地图可以看做一个大的二维数组矩阵,二维数组中任意两个元素相连,计算连线经过的所有二维元素,源码的
createLineMap
函数使用的是Bresenham
画线算法) - 矩形内的可见游戏对象:游戏玩家面向的前方矩形范围内的可见对象(源码的
getVisibleBoxObjects
主要用到了二维坐标系转换算法,以当前玩家位置为原点,朝向为X轴正方向建立坐标系,并将其他游戏对象的坐标都转换到此坐标系中) - 圆内的可见游戏对象:游戏玩家周围范围内的可见对象(源码的
getVisiblePlayer
函数用的是近似算法,算的其实是圆的外切正方形内所有可见对象)
时钟系统
GameTime
实现现实世界时间到游戏时间的相互映射
角色仓库使用
前面角色登入后背包内是没有道具的,现在我们要实现仓库系统,角色登入后可打开背包查看道具,借用下角色登入时候的仓库封包
[Send C]:
0000: 45 0c c6 42 2f 13 ff 00 05 00 01 20 a1 07 00 00 E..B/...... .... S_OPCODE_INVLIST
0010: bd f0 b1 d2 20 28 35 30 30 30 30 30 29 00 00 c7 .... (500000)...
0020: 42 2f 13 00 00 1a 07 01 e8 03 00 00 00 ba da c9 B/..............
0030: ab c3 d7 cb f7 c0 f2 bc fd 20 28 31 30 30 30 29 ......... (1000)
0040: 00 00 cd 42 2f 13 00 00 6d 02 01 1e 00 00 00 00 ...B/...m.......
0050: c7 bf bb af d7 d4 ce d2 bc d3 cb d9 d2 a9 cb ae ................
0060: 20 28 33 30 29 00 00 ce 42 2f 13 00 00 8b 04 01 (30)...B/......
0070: c8 00 00 00 00 b9 c5 b4 fa d6 d5 bc ab cc e5 c1 ................
0080: a6 bb d6 b8 b4 bc c1 20 28 32 30 30 29 00 00 d3 ....... (200)...
0090: 42 2f 13 10 00 d8 01 01 c8 00 00 00 00 b1 e4 d0 B/..............
00a0: ce be ed d6 e1 20 28 32 30 30 29 00 00 d4 42 2f ..... (200)...B/
00b0: 13 00 00 e0 06 01 01 00 00 00 00 cb b5 bb b0 be ................
00c0: ed d6 e1 00 00 d5 42 2f 13 06 00 d9 01 01 f4 01 ......B/........
00d0: 00 00 00 cb b2 bc e4 d2 c6 b6 af be ed d6 e1 20 ...............
00e0: 28 35 30 30 29 00 00 d9 42 2f 13 00 00 2e 0a 01 (500)...B/......
00f0: c8 00 00 00 00 c4 a7 b7 a8 bd e1 be a7 cc e5 20 ...............
0100: 28 32 30 30 29 00 00 dd 42 2f 13 00 00 46 06 01 (200)...B/...F..
0110: 01 00 00 00 00 bc c6 cb e3 bb fa 00 00 de 42 2f ..............B/
0120: 13 17 00 72 02 01 01 00 00 00 00 c3 f0 c4 a7 bd ...r............
0130: e4 d6 b8 00 00 df 42 2f 13 17 00 72 02 01 01 00 ......B/...r....
0140: 00 00 00 c3 f0 c4 a7 bd e4 d6 b8 00 00 e7 42 2f ..............B/
0150: 13 01 00 17 01 01 01 00 00 00 00 c1 d4 c8 cb d6 ................
0160: ae b9 ad 00 00 .....
道具系统
仓库系统存储的是道具,所以在实现仓库系统前必须先实现道具系统
Item
道具模板对象抽象:
属性:
- 描述属性(材质、种类、强化等级、使用职业、道具本身的属性加层)
方法:
- 获取对应描述属性
Item.py、Weapon.py、EtcItem.py、Armor.py
ItemInstance
道具实例对象抽象:
属性:
- 个数
- 道具模板
- 重量
- 使用状态
- 强化状态(武卷强化、防卷强化、饰品强化)
- 道具强化后的属性加成(人物属性加成、人物抗性加成)
方法:
- 道具名称显示 => 火灵 +10 匕首(挥舞)
- 道具魔法加持效果(延后实现)
ItemInstance.py
ItemTable
道具系统管理对象抽象:
属性:
- 道具模板集合
方法:
- 从数据库加载道具模板到内存(材料道具、武器道具、防具道具)
- 使用道具模板创建道具实例
ItemTable.py
仓库系统
Inventory
仓库对象抽象:
属性:
- 仓库物品集合
方法:
- 计算仓库内物品的总数、重量
- 添加道具
- 删除道具
- 更新道具数目
- 消耗道具(武卷防卷强化、黑魔石提炼、魔法宝石)
- 交易道具(延后实现)
Inventory.py、DwarfInventory.py、DwarfForElfInventory.py
PcInventory
玩家背包对象抽象:
属性:
- 背包所属游戏对象
- 优先使用的箭矢
方法:
- 道具耐久和损坏度计算
- 道具耐久和损坏修复
PcInventory.py
以上完成后可补充前面的角色创建的初始赠送道具的流程