EventProc.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 事件模块.
  5. * @version
  6. * 1.0.0 Created at 2017-8-28. by --gwang
  7. * @author gwang (mail@wanggangzero.cn)
  8. * @copyright ? 2017-8-28, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  9. */
  10. class EventProc {
  11. public static function procMain($req) {
  12. switch ($req->cmd) {
  13. case CmdCode::cmd_event_GetNotifications: # 7201 拉取角标通知列表
  14. return self::GetCornerSignNotifications($req);
  15. default:
  16. return Resp::err(ErrCode::cmd_err);
  17. }
  18. }
  19. /**
  20. * [7201] 拉取角标通知
  21. * @param req $req
  22. */
  23. static function GetCornerSignNotifications($req) {
  24. // 这里直接返回, 将来开发对应的触发逻辑, 给数组中添加相应的值
  25. $arr = array_values(array_unique($req->userInfo->game->privateState->cornerSignNotifications)); # 返回值去重
  26. $req->userInfo->game->privateState->cornerSignNotifications = []; # 清理记录
  27. UserProc::updateUserInfo();
  28. return Resp::ok(array("notifications" => $arr)); # 返回
  29. }
  30. static function Init() {
  31. Event::register('onpay', array(new Data_UserProfile(req()->userInfo->game->profile), "OnPay"));
  32. }
  33. /**
  34. * 收到请求
  35. */
  36. static function OnRequest() {
  37. }
  38. /**
  39. * 处理完毕准备返回
  40. */
  41. static function AfterResponse() {
  42. }
  43. /**
  44. * 当天第一次登录
  45. */
  46. static function OnNewDay() {
  47. }
  48. /**
  49. * 当周第一次登录(周一)
  50. */
  51. static function OnNewWeek() {
  52. }
  53. /**
  54. * 当玩家等级变更
  55. * @param type $old
  56. * @param type $new
  57. */
  58. static function OnUserLevelup($old, $new) {
  59. // 处理逻辑,
  60. $ubs = req()->userInfo->game->privateState->unlockedBuild;
  61. foreach (GameConfig::build() as $id => $b) {
  62. isEditor() and $b = new \sm_build();
  63. if (!in_array($id, $ubs)) { # 尚未解锁的建筑,判断,已解锁的跳过
  64. if ($b->playerLevelLimit <= $new) { # 符合解锁条件
  65. req()->userInfo->game->privateState->unlockedBuild[] = $id; # 插入解锁记录
  66. NormalEventProc::OnUnlockBuild($id, null); # 插入事件
  67. }
  68. }
  69. }
  70. // NormalEventProc::OnHelloWorld($arg1, $arg2); # 添加升级事件,算了这个暂时没人关注
  71. }
  72. }