Role.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * Role.php UTF-8
  4. * 角色处理
  5. *
  6. * @date : 2018/5/30 16:48
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\queue;
  13. use huo\controller\member\MemCache;
  14. use huo\controller\request\Channel;
  15. use huo\controller\request\Device;
  16. use huo\controller\request\Game;
  17. use huo\controller\request\Mem as MemRq;
  18. use huo\controller\request\Role as RoleRq;
  19. use huolib\constant\MemConst;
  20. use huolib\queue\constant\EventConst;
  21. class Role extends SdkQueue {
  22. /**huo\controller\request
  23. * 角色创建
  24. * 记录玩家创建角色时刻的日志。
  25. * 在创角界面,输入完角色名后,系统显示“创角成功”即可调用该接口。
  26. * http://doc.1tsdk.com/138?page_id=3383
  27. *
  28. * @param Device $device_rq
  29. * @param Game $game_rq
  30. * @param Channel $agent_rq
  31. * @param MemRq $mem_rq
  32. * @param RoleRq $role_rq
  33. *
  34. * @return array
  35. */
  36. public function create(Device $device_rq, Game $game_rq, Channel $agent_rq, MemRq $mem_rq, RoleRq $role_rq) {
  37. $this->param['event'] = EventConst::EVENT_ROLE_CREATE;
  38. $this->setParamDevice($device_rq);
  39. $this->setParamGame($game_rq);
  40. $this->setParamChannel($agent_rq);
  41. $this->setParamRole($role_rq);
  42. $this->setParamMem($mem_rq);
  43. return $this->pushQueue();
  44. }
  45. /**
  46. * 角色登录
  47. * 记录玩家角色登录的日志。此处应与账户登录区分。
  48. *
  49. * 在角色界面,点击“登录游戏”后进入到游戏界面时调用该接口。
  50. *
  51. * ①一个服务器下只有一个角色,没有“登录游戏”按钮,以角色登录到游戏界面时调用接口;
  52. *
  53. * ②一个服务器下可有多个角色,以执行“登录游戏”操作进入游戏界面时调用接口。
  54. * http://doc.1tsdk.com/138?page_id=3384
  55. *
  56. * @param Device $device_rq
  57. * @param Game $game_rq
  58. * @param Channel $agent_rq
  59. * @param MemRq $mem_rq
  60. * @param RoleRq $role_rq
  61. *
  62. * @return array
  63. */
  64. public function online(Device $device_rq, Game $game_rq, Channel $agent_rq, MemRq $mem_rq, RoleRq $role_rq) {
  65. $this->param['event'] = EventConst::EVENT_ROLE_ONLINE;
  66. $this->setParamDevice($device_rq);
  67. $this->setParamGame($game_rq);
  68. $this->setParamChannel($agent_rq);
  69. $this->setParamRole($role_rq);
  70. $this->setParamMem($mem_rq);
  71. return $this->pushQueue();
  72. }
  73. /**
  74. * 角色升级
  75. * 记录玩家升级的日志。玩家升级的时候调用该接口。
  76. * http://doc.1tsdk.com/138?page_id=3385
  77. *
  78. * @param Device $device_rq
  79. * @param Game $game_rq
  80. * @param Channel $agent_rq
  81. * @param MemRq $mem_rq
  82. * @param RoleRq $role_rq
  83. *
  84. * @return array
  85. */
  86. public function levelup(Device $device_rq, Game $game_rq, Channel $agent_rq, MemRq $mem_rq, RoleRq $role_rq) {
  87. $this->param['event'] = EventConst::EVENT_ROLE_LEVELUP;
  88. $this->setParamDevice($device_rq);
  89. $this->setParamGame($game_rq);
  90. $this->setParamChannel($agent_rq);
  91. $this->setParamRole($role_rq);
  92. $this->setParamMem($mem_rq);
  93. return $this->pushQueue();
  94. }
  95. /**
  96. * 角色退出
  97. * 记录玩家角色登出的日志。此处应与账户登出区分。
  98. *
  99. * ①一个服务器只存在一个角色且不能重建的情况下,返回“选择服务器”界面即可调用该接口。
  100. *
  101. * ②一个服务器可存在多个角色,返回“选择角色”界面即可调用该接口。
  102. * http://doc.1tsdk.com/138?page_id=3386
  103. *
  104. * @param Device $device_rq
  105. * @param Game $game_rq
  106. * @param Channel $agent_rq
  107. * @param MemRq $mem_rq
  108. * @param RoleRq $role_rq
  109. *
  110. * @return array
  111. */
  112. public function offline(Device $device_rq, Game $game_rq, Channel $agent_rq, MemRq $mem_rq, RoleRq $role_rq) {
  113. $this->param['event'] = EventConst::EVENT_ROLE_OFFLINE;
  114. $this->setParamDevice($device_rq);
  115. $this->setParamGame($game_rq);
  116. $this->setParamChannel($agent_rq);
  117. $this->setParamRole($role_rq);
  118. $this->setParamMem($mem_rq);
  119. return $this->pushQueue();
  120. }
  121. /**
  122. * http://doc.1tsdk.com/138?page_id=2907
  123. *
  124. * @param Game $game_rq
  125. * @param MemRq $mem_rq
  126. * @param RoleRq $role_rq
  127. *
  128. * @param Device|null $device_rq
  129. *
  130. * @return array
  131. */
  132. public function upRole(Game $game_rq, MemRq $mem_rq, RoleRq $role_rq, Device $device_rq = null) {
  133. $agent_rq = new Channel();
  134. $agent_rq->setCh($mem_rq->getAgentId());
  135. $_mem_info = MemCache::ins()->getInfoById($mem_rq->getMemId());
  136. switch ($role_rq->getEvent()) {
  137. case 1:
  138. /* 角色登录 */
  139. $role_rq->setLastLoginTime(time());
  140. if (isset($_mem_info['status']) && $_mem_info['status'] == MemConst::STATUS_TRY) {
  141. $mem_rq->setStatus(MemConst::STATUS_NORMAL);
  142. }
  143. return $this->online($device_rq, $game_rq, $agent_rq, $mem_rq, $role_rq);
  144. case 2:
  145. /* 创建角色 */
  146. $role_rq->setLastLoginTime(time());
  147. if (isset($_mem_info['status']) && $_mem_info['status'] == MemConst::STATUS_TRY) {
  148. $mem_rq->setStatus(MemConst::STATUS_NORMAL);
  149. }
  150. return $this->create($device_rq, $game_rq, $agent_rq, $mem_rq, $role_rq);
  151. case 3:
  152. /* 提升等级 */
  153. return $this->levelup($device_rq, $game_rq, $agent_rq, $mem_rq, $role_rq);
  154. case 4:
  155. /* 角色退出 */
  156. return $this->offline($device_rq, $game_rq, $agent_rq, $mem_rq, $role_rq);
  157. default:
  158. $role_rq->setLastLoginTime(time());
  159. if (isset($_mem_info['status']) && $_mem_info['status'] == MemConst::STATUS_TRY) {
  160. $mem_rq->setStatus(MemConst::STATUS_NORMAL);
  161. }
  162. return $this->online($device_rq, $game_rq, $agent_rq, $mem_rq, $role_rq);
  163. }
  164. }
  165. }