I / 50 摘要 本文主要阐述网络回合制战斗系统的实现,包括回合制战斗系统的整个流程(战斗开始、玩家下达战斗指令、战斗动画、战斗结束),和网络回合制战斗系统常见的主要功能(攻击、使用技能、使用物品)的实现,并且在游戏项目《PKer》中进行实践和测试。在开发环境方面,服务器采用国IOCP高性能开源框架“HP-Socket”(Windows平台),并且连接到Mysql数据库,客户端采用近年比较火热的强大跨平台引擎Unity3D(2D,C#)并且使用Sqlite作为嵌入式数据库。除此以外,本文还对战斗系统实现所涉与到的相关技术如Unity引擎的协同程序、单例设计模式和分包算法进行简要介绍。 关键词 回合制战斗系统, 网络游戏,Unity3D,协同程序,游戏编程 ABSTRACTThis article mainly expounds the implementation of network turn-based combat system, including the whole process of turn-based combat system (battle begins, the players fighting instructions, combat animation, battle ends), and the main function of common (attack, using skills, using items) implementation, and in the game "PKer" in practice and test of the project. In the aspect of development environment, C++ IOCP server with Windows platform and connect to the Mysql database, the client uses Unity3D (2D, C#) and uses Sqlite as an embedded database. In addition to this, this article also involved to combat system related technologies such as the Unity engine coroutines, singleton design pattern and the subcontract algorithm are briefly introduced. KEYWORDS Turn-based combat system, online game, Unity3D, Coroutine, Singleton design pattern 目 录 前 言1 第1章 绪论2 回合制游戏简介2 II / 50 广义上的回合制游戏2 狭义上的回合制游戏2 回合制战斗系统简介2 实践项目《PKer》简介2 第2章 开发环境和部分涉与技术简介4 开发环境简介4 Unity协同程序4 Unity协同程序简介4 Unity协同程序的运用4 单例设计模式5 单例设计模式5 单例设计模式的运用6 单例设计模式在Unity中的运用7 分包算法7 分包的原因7 环形缓冲区(Circular Buffer)7 分包算法流程图9 第3章 战斗动画实现方案的研究与对比11 研究背景11 实现方案一:有限状态机11 实现方案二:协同程序(Coroutine)12 方案抉择结论13 第4章 回合制网游战斗系统设计14 回合制网游战斗系统设计14 回合制网游战斗系统服务器实现思路15 回合制网游战斗系统客户端实现思路15 战斗系统框架结构(以实践项目《PKer》为例)16 第5章 回合制战斗系统实现18 III / 50 战斗系统相关消息结构体的定义18 服务器战斗系统的实现20 服务器战斗系统相关结构体20 初始化一个战局23 接收客户端的战斗指令消息23 处理战斗指令并发送动画消息24 说明27 客户端战斗系统的实现27 客户端战斗系统功能模块28 客户端战斗系