Boxes.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. namespace loyalsoft;
  3. require_once __DIR__ . '/Lotterys.php';
  4. /**
  5. * Description of Boxes
  6. * 控制理论: 模型预测, 反馈校正, 滚动优化.
  7. * 目标: 检测游戏内部一批指定的数据, 动态调整宝箱掉落物品.
  8. * @version
  9. * 1.0.0 Created at 2017-9-13. by --gwang
  10. * @author gwang (mail@wanggangzero.cn)
  11. * @copyright ? 2017-9-13, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  12. */
  13. class Boxes {
  14. /**
  15. * 消耗宝箱
  16. * @param Req $req
  17. * @param type $boxid
  18. * @param type $num
  19. */
  20. public static function ComsumeBoxes($req, $boxid, $num = 1) {
  21. $boxes = $req->userInfo->game->store->boxes; # 预取变量
  22. if (CommUtil::isPropertyExists($boxes, $boxid) # 有这种宝箱
  23. && $boxes->$boxid >= $num) { # 且数量够
  24. $boxes->$boxid -= $num; # 扣减对应数量
  25. $req->userInfo->game->store->boxes = $boxes; # 回存数据
  26. return ErrCode::ok; # 返回成功
  27. }
  28. return ErrCode::box_not_enough; # 数量不足
  29. }
  30. public static function SubBoxCoolDown($req) {
  31. $user = $req->userInfo->game; # 预取变量
  32. if (count($req->paras) < 1) { # 提取参数
  33. return Resp::err(ErrCode::parasnotenough_msg);
  34. }
  35. echo var_dump($req);
  36. $itemId = $req->paras[0]; # 减冷却时间的物品Id
  37. $item = GameConfig::item_getItem($itemId);
  38. if ($item == null) { ////检测是否存在装备的原始数据
  39. return Resp::err(ErrCode::err_const_no);
  40. }
  41. $err = StoreProc::removeItemFromStore($req->userInfo->game->store, $itemId, 1);
  42. if ($err) { # 扣除失败
  43. return Resp::err($err);
  44. }
  45. $user->privateState->BoxCoolDownTime -= $item->level;
  46. if ($user->privateState->BoxCoolDownTime - time() > glc()->Box_Total_CoolDown) {
  47. $user->privateState->BoxLock = 1;
  48. // return ResponseVo::err($req, ErrCode::onlinegift_timenotenough);
  49. } else {
  50. $user->privateState->BoxLock = 0; ///照顾旧账号
  51. }
  52. UserProc::updateUserInfo($req);
  53. return Resp::ok(array('err' => 0, # # 返回值
  54. 'store' => $user->store, # # 仓库
  55. 'cooldown' => $user->privateState->BoxCoolDownTime, # # 冷却时间
  56. 'BoxLock' => $user->privateState->BoxLock)); #是否加锁状态
  57. }
  58. /**
  59. * 开启宝箱
  60. * @param Req $req
  61. */
  62. public static function OpenBox($req) {
  63. # 提取参数
  64. $user = $req->userInfo->game; # 预取变量
  65. if (count($req->paras) < 1) { # 提取参数
  66. return Resp::err(ErrCode::parasnotenough_msg);
  67. }
  68. $boxid = $req->paras[0]; # 宝箱Id
  69. $num = 1; # 开箱数量, 可选参数, 默认为1
  70. if (count($req->paras) > 1) { # 如果传了,
  71. $num = $req->paras[1]; # 提取可选参数:宝箱数量
  72. } # end 提取参数
  73. $Cash = 0;
  74. if (count($req->paras) > 2) { # 如果传了,
  75. $Cash = $req->paras[2]; # 提取可选参数:开宝箱用的钻石数量
  76. }
  77. # # 记录开箱子次数, (箱子也设置次数限制)
  78. $err = Lotterys::AddLotteryTimes($user->privateState->lottery, $boxid, $left_cishu, $num);
  79. if ($err) { # 发生错误
  80. return Resp::err($err);
  81. }
  82. if ($Cash > 0) {////如果传了免cd开宝箱的钻石数量,则需要扣除数量。
  83. $bDeal = UserGameModel::Consume_Cash($user, $Cash);
  84. if (!$bDeal) {
  85. return Resp::err(ErrCode::notenough_cash_msg);
  86. }
  87. } else {///如果没传免cd开宝箱的钻石数量,则需要走冷却这个限制
  88. if ($user->privateState->BoxCoolDownTime - time() > glc()->Box_Total_CoolDown) {
  89. $user->privateState->BoxLock = 1;
  90. return Resp::err(ErrCode::onlinegift_timenotenough);
  91. } else {
  92. $user->privateState->BoxLock = 0; ///照顾旧账号
  93. }
  94. }
  95. // if( $user->privateState->BoxLock==1)
  96. // {
  97. // if($user->privateState->BoxCoolDownTime>now())
  98. // {
  99. // return ResponseVo::err($req, ErrCode::onlinegift_timenotenough);
  100. // }
  101. // else
  102. // {
  103. // $user->privateState->BoxLock=0;
  104. // }
  105. // }
  106. $err = self::ComsumeBoxes($req, $boxid, $num); # 扣除抽奖花费
  107. if ($err) { # 发生错误
  108. return Resp::err($err);
  109. }
  110. $req->userInfo->game = $user; # 回写user数据,以防后续操作造成分歧
  111. $boxInfo = GameConfig::box_getItem($boxid); # box数据
  112. $Arr = GameConfig::boxpool_getItem($boxid); # 提取奖池
  113. # 过滤奖池
  114. $seqs = explode(',', $boxInfo->dropTypeSeq); # 掉落序列
  115. $rewardArr = ArrayInit(); # 结果
  116. for ($i = 0; $i < $num; $i++) {
  117. foreach ($seqs as $dropindex) {
  118. # 提取对应序列的奖池, 注意: 原始奖池Arr要保留, 因为每次循环都要从原始奖池中重新提取数据.
  119. $itemArr = array_filter($Arr, function($item) use($dropindex) {
  120. return $item->dropType == $dropindex;
  121. });
  122. # 对奖池依解锁等级进行过滤
  123. $itemArr = Lotterys::FilterPrizepool($req, $itemArr);
  124. # 掉率修正
  125. foreach ($itemArr as $item) {
  126. $profile = new UserProfile($user->profile);
  127. if ($profile->payment->GetClass() >= 3) { # 大R
  128. $prop = $item->bigR;
  129. } else {
  130. $prop = $item->normal;
  131. }
  132. // // 登录天数修正
  133. // $logins = array_filter($user->privateState->LoginDays, function ($tsday) {
  134. // return tsDay() - $tsday < 7; # 提取7日以内的登录记录
  135. // });
  136. // switch (count($logins)) {
  137. // case 1:
  138. // case 2:
  139. // $prop += $item->f_7day2on;
  140. // break;
  141. // case 3:
  142. // case 4:
  143. // $prop += $item->f_7day4on;
  144. // break;
  145. // case 5:
  146. // case 6:
  147. // $prop += $item->f_7day6on;
  148. // break;
  149. // default:
  150. // break;
  151. // }
  152. // 英雄碎片修正
  153. // ...碎片数据还没有...
  154. // ...卒
  155. if ($prop < 0) {
  156. $prop = 0;
  157. }
  158. $item->probability = $prop;
  159. }
  160. $err = Lotterys::Dice($itemArr, 1, $rewardstr); # 投骰子
  161. if ($err) { # 出错了
  162. return Resp::err($err);
  163. }
  164. if (strlen($rewardstr) <= 0) { # 抽奖结果为空
  165. return Resp::err(ErrCode::err_innerfault);
  166. }
  167. $rewardArr[] = $rewardstr;
  168. }
  169. # # 金币
  170. $gold = CommUtil::random($boxInfo->goldsMin, $boxInfo->goldsMax);
  171. array_unshift($rewardArr, META_GOLD_ITEMID . ",$gold"); # 插入金币奖励
  172. # # 经验卡
  173. foreach (GameConfig::boxJingYanCards_getItem($boxid) as $id => $card) {
  174. if (CommUtil::randomPercent($card->probability)) { # 投色子决定是否掉落此类经验卡
  175. $amt = CommUtil::random($card->cardsMin, $card->cardsMax); # 掉落数量
  176. array_push($rewardArr, $card->cardId . ",$amt"); # 追加经验卡奖励
  177. }
  178. }
  179. }
  180. $err = StoreProc::AddMultiItemInStore($req, implode(';', $rewardArr), 3); # 发放物品
  181. if (ErrCode::ok != $err) {
  182. return Resp::err($err);
  183. }
  184. ////每开一次箱子,要加上该箱子的冷却时间
  185. if ($user->privateState->BoxCoolDownTime < now()) {
  186. $user->privateState->BoxCoolDownTime = now();
  187. }
  188. if ($Cash > 0) {////如果传了免cd开宝箱的钻石数量,则开宝箱时候不累加冷却时间
  189. ///郎总说如果用钻石开宝箱去掉宝箱冷却
  190. } else {
  191. $user->privateState->BoxCoolDownTime += $boxInfo->coolDwonTime;
  192. }
  193. if ($user->privateState->BoxCoolDownTime - time() > glc()->Box_Total_CoolDown) {////如果宝箱现在冷却时间大于宝箱冷却上线,则加锁
  194. $user->privateState->BoxLock = 1; ////加宝箱锁,在一定时间内不能开启
  195. } else {
  196. $user->privateState->BoxLock = 0; ////照顾旧账号。
  197. }
  198. UserProc::updateUserInfo($req); # 回存数据
  199. return Resp::ok(array('err' => 0, # # 返回值
  200. 'store' => $user->store, # # 仓库
  201. 'heros' => $user->heros, # # 最新英雄
  202. 'cooldown' => $user->privateState->BoxCoolDownTime, # # 冷却时间
  203. 'reward' => implode(';', $rewardArr), # # 奖品
  204. 'BoxLock' => $user->privateState->BoxLock, #是否加锁状态
  205. 'baodi' => $user->privateState->lottery->baodiLotterys,
  206. 'left_cishu' => $left_cishu)); # 当天剩余次数(限次)
  207. }
  208. }