UserPVPModel.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 UserPVPModel 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 int 总胜利场次
  58. */
  59. public $totalWin = 0;
  60. public function refreshDailyData() {
  61. // 刷新免费挑战次数
  62. if (tsDay($this->fightTicketRefreshTs) <= tsDay()) { # 刷新时间<=今天,该刷新了
  63. $this->freeFightTickets = 3; # 重置为3, 此处的3可以改为读取配置数据
  64. $this->fightTicketRefreshTs = now() + 86400; # 刷新时间设置为明天
  65. }
  66. }
  67. /**
  68. * 发送上榜奖励(昨天的奖励,以及上一赛季的奖励)
  69. * @param type $zoneid
  70. * @param type $uid
  71. * @param type $seasonId
  72. */
  73. public function sendRewardEmail($zoneid, $uid, $seasonId) {
  74. $key = MemKey_GameRun::Game_PVPScoreByZoneSeason_zset($zoneid, $seasonId); # 积分总榜
  75. if ($this->haventReward_season >= 0 && $this->haventReward_season < $seasonId) { # 尚未发放上赛季奖励
  76. $haventKey = MemKey_GameRun::Game_PVPScoreByZoneSeason_zset($zoneid, $this->haventReward_season);
  77. // todo:发放上赛季奖励邮件
  78. $rank = PVPProc::_getRank_by_uid($uid, $haventKey); # 查询上赛季排名
  79. if ($rank <= PVPProc::pvpMaxRank) { # 防御未上榜
  80. foreach (GameConfig::pvp_rankreward() as $cfg) {
  81. isEditor() and $cfg = new \sm_pvp_rankreward();
  82. if ($rank >= $cfg->minRank && $rank <= $cfg->maxRank) { # 找到对应的名次段
  83. EmailProc::SendPvpRankReward_Season($zoneid, $uid, $rank); # 发放奖励邮件(竞技币)
  84. }
  85. }
  86. UserProc::updateUserInfo();
  87. }
  88. }
  89. $this->haventReward_season = $seasonId; # 更新待发奖赛季
  90. if ($this->haventReward_tsDay < tsDay() - 7) {
  91. $this->haventReward_tsDay = tsDay() - 7;
  92. }
  93. for ($this->haventReward_tsDay; $this->haventReward_tsDay < tsDay(); $this->haventReward_tsDay++) {
  94. // if ($this->haventReward_tsDay == tsDay() - 1) { # 尚未发放昨天奖励
  95. $haventKey_day = MemKey_GameRun::Game_PVPScoreByZone_zset_Day($zoneid, $this->haventReward_tsDay);
  96. if (!gMem()->exists($haventKey_day) && $this->haventReward_tsDay == tsDay() - 1) { # 昨天的积分记录不存在
  97. gMem()->zcopy($key, $haventKey_day); # 复制一份当前积分作为昨天的截止积分榜
  98. } else {
  99. // 不是昨天登录的, 且没有对应的数据 就不再复制当前数据了.直接未上榜处理
  100. }
  101. $rank = PVPProc::_getRank_by_uid($uid, $haventKey_day); # 查询上一天排名
  102. if ($rank <= PVPProc::pvpMaxRank) { # 防御未上榜
  103. foreach (GameConfig::pvp_rankreward() as $cfg) {
  104. isEditor() and $cfg = new \sm_pvp_rankreward();
  105. if ($rank >= $cfg->minRank && $rank <= $cfg->maxRank) { # 找到对应的名次段
  106. EmailProc::SendPvpRankReward_Lastday($zoneid, $uid, $rank); # 发放奖励邮件(竞技币)
  107. }
  108. }
  109. UserProc::updateUserInfo();
  110. }
  111. // }
  112. }
  113. $this->haventReward_tsDay = tsDay(); # 更新待发放奖励日期
  114. }
  115. public function __construct($arg = null) {
  116. parent::__construct($arg);
  117. if (null == $this->curShopItems) {
  118. $this->curShopItems = GameConfig::pvp_shop();
  119. }
  120. if ($this->defTeam[0] <= 0) {
  121. $one = 1;
  122. if (isset(req()->userInfo)) {
  123. $teams = req()->userInfo->game->heroTeamConfig->teamDic;
  124. $this->defTeam = array_slice($teams->$one->heros, 0, 3);
  125. }
  126. }
  127. }
  128. }