Boxes.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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();
  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. $itemArr = Lotterys::FilterPrizepool($req, $itemArr); # 对奖池依解锁等级进行过滤
  123. # 掉率修正
  124. foreach ($itemArr as $item) {
  125. $profile = new UserProfile($user->profile);
  126. if ($profile->payment->GetClass() >= 3) { # 大R
  127. $prop = $item->bigR;
  128. } else {
  129. $prop = $item->normal;
  130. }
  131. // // 登录天数修正
  132. // $logins = array_filter($user->privateState->LoginDays, function ($tsday) {
  133. // return tsDay() - $tsday < 7; # 提取7日以内的登录记录
  134. // });
  135. // switch (count($logins)) {
  136. // case 1:
  137. // case 2:
  138. // $prop += $item->f_7day2on;
  139. // break;
  140. // case 3:
  141. // case 4:
  142. // $prop += $item->f_7day4on;
  143. // break;
  144. // case 5:
  145. // case 6:
  146. // $prop += $item->f_7day6on;
  147. // break;
  148. // default:
  149. // break;
  150. // }
  151. // 英雄碎片修正
  152. // ...碎片数据还没有...
  153. // ...卒
  154. if ($prop < 0) {
  155. $prop = 0;
  156. }
  157. $item->probability = $prop;
  158. }
  159. $err = Lotterys::Dice($itemArr, 1, $rewardstr); # 投骰子
  160. if ($err) { # 出错了
  161. return Resp::err($err);
  162. }
  163. if (strlen($rewardstr) <= 0) { # 抽奖结果为空
  164. return Resp::err(ErrCode::err_innerfault);
  165. }
  166. $rewardArr[] = $rewardstr;
  167. }
  168. # # 金币
  169. $gold = CommUtil::random($boxInfo->goldsMin, $boxInfo->goldsMax);
  170. array_unshift($rewardArr, META_GOLD_ITEMID . ",$gold"); # 插入金币奖励
  171. # # 经验卡
  172. foreach (GameConfig::boxJingYanCards_getItem($boxid) as $id => $card) {
  173. if (CommUtil::randomPercent($card->probability)) { # 投色子决定是否掉落此类经验卡
  174. $amt = CommUtil::random($card->cardsMin, $card->cardsMax); # 掉落数量
  175. array_push($rewardArr, $card->cardId . ",$amt"); # 追加经验卡奖励
  176. }
  177. }
  178. }
  179. $err = StoreProc::AddMultiItemInStore($req, implode(';', $rewardArr), 3); # 发放物品
  180. if (ErrCode::ok != $err) {
  181. return Resp::err($err);
  182. }
  183. if ($user->privateState->BoxCoolDownTime < now()) { # 每开一次箱子,要加上该箱子的冷却时间
  184. $user->privateState->BoxCoolDownTime = now();
  185. }
  186. if ($Cash > 0) {// //如果传了免cd开宝箱的钻石数量,则开宝箱时候不累加冷却时间
  187. ///郎总说如果用钻石开宝箱去掉宝箱冷却
  188. } else {
  189. $user->privateState->BoxCoolDownTime += $boxInfo->coolDwonTime;
  190. }
  191. if ($user->privateState->BoxCoolDownTime - time() > glc()->Box_Total_CoolDown) {# 如果宝箱现在冷却时间大于宝箱冷却上线,则加锁
  192. $user->privateState->BoxLock = 1; // //加宝箱锁,在一定时间内不能开启
  193. } else {
  194. $user->privateState->BoxLock = 0; ////照顾旧账号。
  195. }
  196. UserProc::updateUserInfo(); # 回存数据
  197. return Resp::ok(array('err' => 0, # # 返回值
  198. 'store' => $user->store, # # 仓库
  199. 'heros' => $user->heros, # # 最新英雄
  200. 'cooldown' => $user->privateState->BoxCoolDownTime, # # 冷却时间
  201. 'reward' => implode(';', $rewardArr), # # 奖品
  202. 'BoxLock' => $user->privateState->BoxLock, # # 是否加锁状态
  203. 'baodi' => $user->privateState->lottery->baodiLotterys,
  204. 'left_cishu' => $left_cishu)); # 当天剩余次数(限次)
  205. }
  206. }