Info_UserPVP.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 玩家竞技场数据
  5. * @version
  6. * 2.0.0 改自原PVP数据(内容基本全换). 2020.5.7 -- gwang
  7. * 1.0.0 Created at 2017-7-4. by --gwang
  8. * @author gwang (mail@wanggangzero.cn)
  9. * @copyright ? 2017-7-4, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  10. */
  11. class Info_UserPVP extends Object_ext {
  12. /**
  13. * @var array[string] 每日/当天已挑战对手记录(有想法设定尽量不重复当天已经刷到过的对手)
  14. */
  15. public $dailyMatchRecord = array();
  16. /**
  17. * @var object 防守阵容
  18. */
  19. public $defTeam = array("0", "0", "0");
  20. /**
  21. * @var int 竞技币
  22. */
  23. public $pvpCoins = 0;
  24. /**
  25. * @var int 竞技场挑战票
  26. */
  27. public $fightTicket = 0;
  28. /**
  29. * @var 下次刷新时间
  30. */
  31. public $fightTicketRefreshTs = 0;
  32. /**
  33. * @var int 每天有3次免费挑战次数,每天8天重置
  34. */
  35. public $freeFightTickets = 0;
  36. /**
  37. * @var int 挑战记录最后拉取时间戳(晚于此时间戳的记录为新记录,显示小红点)
  38. */
  39. public $lastCheckDefLog_ts = 0;
  40. /**
  41. * @var type 当前竞技商店内道具列表(子结构可以记录售罄状态)
  42. */
  43. public $curShopItems;
  44. /**
  45. * @var int 商店下次刷新的时间戳(24小时自动刷新, 提前刷新扣钻)
  46. */
  47. public $shopRefreshTs = 0;
  48. /**
  49. * @var 今日未发放奖励(tsDay < today =>发放奖励并同步到today)
  50. */
  51. public $haventReward_tsDay = 0;
  52. /**
  53. * @var 赛季未发放奖励(seasonId < curSeason =>发放奖励并同步到curSeason)
  54. */
  55. public $haventReward_season = 0;
  56. /**
  57. * @var ts 下次刷新对手时间戳,控制下刷新频率
  58. */
  59. public $nextRefreshTs = 0;
  60. /**
  61. * @var int 总胜利场次
  62. */
  63. public $totalWin = 0;
  64. public function refreshDailyData() {
  65. // 刷新免费挑战次数
  66. if (totalDays($this->fightTicketRefreshTs) <= totalDays()) { # 刷新时间<=今天,该刷新了
  67. $this->freeFightTickets = 3; # 重置为3, 此处的3可以改为读取配置数据
  68. $this->fightTicketRefreshTs = now() + 86400; # 刷新时间设置为明天
  69. }
  70. }
  71. /**
  72. * 发送上榜奖励(昨天的奖励,以及上一赛季的奖励)
  73. * @param type $zoneid
  74. * @param type $uid
  75. * @param type $seasonId
  76. */
  77. public function sendRewardEmail($zoneid, $uid, $seasonId) {
  78. $key = MemKey_GameRun::Game_PVPScoreByZoneSeason_zset($zoneid, $seasonId); # 积分总榜
  79. if ($this->haventReward_season >= 0 && $this->haventReward_season < $seasonId) { # 尚未发放上赛季奖励
  80. $haventKey = MemKey_GameRun::Game_PVPScoreByZoneSeason_zset($zoneid, $this->haventReward_season);
  81. // todo:发放上赛季奖励邮件
  82. $rank = PVPProc::_getRank_by_uid($uid, $haventKey); # 查询上赛季排名
  83. if ($rank <= PVPProc::pvpMaxRank) { # 防御未上榜
  84. foreach (GameConfig::pvp_rankreward() as $cfg) {
  85. isEditor() and $cfg = new \sm_pvp_rankreward();
  86. if ($rank >= $cfg->minRank && $rank <= $cfg->maxRank) { # 找到对应的名次段
  87. EmailProc::SendPvpRankReward_Season($zoneid, $uid, $rank); # 发放奖励邮件(竞技币)
  88. }
  89. }
  90. UserProc::updateUserInfo();
  91. }
  92. }
  93. $this->haventReward_season = $seasonId; # 更新待发奖赛季
  94. if ($this->haventReward_tsDay < totalDays() - 7) {
  95. $this->haventReward_tsDay = totalDays() - 7;
  96. }
  97. for ($this->haventReward_tsDay; $this->haventReward_tsDay < totalDays(); $this->haventReward_tsDay++) {
  98. // if ($this->haventReward_tsDay == tsDay() - 1) { # 尚未发放昨天奖励
  99. $haventKey_day = MemKey_GameRun::Game_PVPScoreByZone_zset_Day($zoneid, $this->haventReward_tsDay);
  100. if (!gMem()->exists($haventKey_day) && $this->haventReward_tsDay == totalDays() - 1) { # 昨天的积分记录不存在
  101. gMem()->zcopy($key, $haventKey_day); # 复制一份当前积分作为昨天的截止积分榜
  102. } else {
  103. // 不是昨天登录的, 且没有对应的数据 就不再复制当前数据了.直接未上榜处理
  104. }
  105. $rank = PVPProc::_getRank_by_uid($uid, $haventKey_day); # 查询上一天排名
  106. if ($rank <= PVPProc::pvpMaxRank) { # 防御未上榜
  107. foreach (GameConfig::pvp_rankreward() as $cfg) {
  108. isEditor() and $cfg = new \sm_pvp_rankreward();
  109. if ($rank >= $cfg->minRank && $rank <= $cfg->maxRank) { # 找到对应的名次段
  110. EmailProc::SendPvpRankReward_Lastday($zoneid, $uid, $rank); # 发放奖励邮件(竞技币)
  111. }
  112. }
  113. UserProc::updateUserInfo();
  114. }
  115. // }
  116. }
  117. $this->haventReward_tsDay = totalDays(); # 更新待发放奖励日期
  118. }
  119. public function __construct($arg = null) {
  120. parent::__construct($arg);
  121. if (null == $this->curShopItems) {
  122. $this->curShopItems = GameConfig::pvp_shop();
  123. }
  124. if ($this->defTeam[0] <= 0) {
  125. $one = 1;
  126. if (isset(req()->userInfo)) {
  127. $teamCfg = JsonUtil::decode(req()->userInfo->game->heroTeamConfig);
  128. $teams = $teamCfg->teamDic;
  129. if (isset($teams->$one->heros)) {
  130. $this->defTeam = array_slice($teams->$one->heros, 0, 3);
  131. }
  132. }
  133. }
  134. }
  135. }