userInfo->game->store->boxes; # 预取变量 if (CommUtil::isPropertyExists($boxes, $boxid) # 有这种宝箱 && $boxes->$boxid >= $num) { # 且数量够 $boxes->$boxid -= $num; # 扣减对应数量 $req->userInfo->game->store->boxes = $boxes; # 回存数据 return ErrCode::ok; # 返回成功 } return ErrCode::box_not_enough; # 数量不足 } public static function SubBoxCoolDown($req) { $user = $req->userInfo->game; # 预取变量 if (count($req->paras) < 1) { # 提取参数 return Resp::err(ErrCode::parasnotenough_msg); } echo var_dump($req); $itemId = $req->paras[0]; # 减冷却时间的物品Id $item = GameConfig::item_getItem($itemId); if ($item == null) { # 检测是否存在装备的原始数据 return Resp::err(ErrCode::err_const_no); } $err = StoreProc::removeItemFromStore($req->userInfo->game->store, $itemId, 1); if ($err) { # 扣除失败 return Resp::err($err); } $user->privateState->BoxCoolDownTime -= $item->level; if ($user->privateState->BoxCoolDownTime - time() > glc()->Box_Total_CoolDown) { $user->privateState->BoxLock = 1; // return ResponseVo::err($req, ErrCode::onlinegift_timenotenough); } else { $user->privateState->BoxLock = 0; # 照顾旧账号 } UserProc::updateUserInfo($req); return Resp::ok(array('err' => 0, # # 返回值 'store' => $user->store, # # 仓库 'cooldown' => $user->privateState->BoxCoolDownTime, # # 冷却时间 'BoxLock' => $user->privateState->BoxLock)); #是否加锁状态 } /** * 开启宝箱 * @param Req $req */ public static function OpenBox($req) { # 提取参数 $user = $req->userInfo->game; # 预取变量 if (count($req->paras) < 1) { # 提取参数 return Resp::err(ErrCode::parasnotenough_msg); } $boxid = $req->paras[0]; # 宝箱Id $num = 1; # 开箱数量, 可选参数, 默认为1 if (count($req->paras) > 1) { # 如果传了, $num = $req->paras[1]; # 提取可选参数:宝箱数量 } # end 提取参数 $Cash = 0; if (count($req->paras) > 2) { # 如果传了, $Cash = $req->paras[2]; # 提取可选参数:开宝箱用的钻石数量 } # # 记录开箱子次数, (箱子也设置次数限制) $err = Lotterys::AddLotteryTimes($user->privateState->lottery, $boxid, $left_cishu, $num); if ($err) { # 发生错误 return Resp::err($err); } if ($Cash > 0) {// //如果传了免cd开宝箱的钻石数量,则需要扣除数量。 $bDeal = UserGameModel::Consume_Cash($user, $Cash); if (!$bDeal) { return Resp::err(ErrCode::notenough_cash_msg); } } else {// //如果没传免cd开宝箱的钻石数量,则需要走冷却这个限制 if ($user->privateState->BoxCoolDownTime - time() > glc()->Box_Total_CoolDown) { $user->privateState->BoxLock = 1; return Resp::err(ErrCode::onlinegift_timenotenough); } else { $user->privateState->BoxLock = 0; // //照顾旧账号 } } // if( $user->privateState->BoxLock==1) // { // if($user->privateState->BoxCoolDownTime>now()) // { // return ResponseVo::err($req, ErrCode::onlinegift_timenotenough); // } // else // { // $user->privateState->BoxLock=0; // } // } $err = self::ComsumeBoxes($req, $boxid, $num); # 扣除抽奖花费 if ($err) { # 发生错误 return Resp::err($err); } $req->userInfo->game = $user; # 回写user数据,以防后续操作造成分歧 $boxInfo = GameConfig::box_getItem($boxid); # box数据 $Arr = GameConfig::boxpool_getItem($boxid); # 提取奖池 # 过滤奖池 $seqs = explode(',', $boxInfo->dropTypeSeq); # 掉落序列 $rewardArr = ArrayInit(); # 结果 for ($i = 0; $i < $num; $i++) { foreach ($seqs as $dropindex) { # 提取对应序列的奖池, 注意: 原始奖池Arr要保留, 因为每次循环都要从原始奖池中重新提取数据. $itemArr = array_filter($Arr, function($item) use($dropindex) { return $item->dropType == $dropindex; }); $itemArr = Lotterys::FilterPrizepool($req, $itemArr); # 对奖池依解锁等级进行过滤 # 掉率修正 foreach ($itemArr as $item) { $profile = new UserProfile($user->profile); if ($profile->payment->GetClass() >= 3) { # 大R $prop = $item->bigR; } else { $prop = $item->normal; } // // 登录天数修正 // $logins = array_filter($user->privateState->LoginDays, function ($tsday) { // return tsDay() - $tsday < 7; # 提取7日以内的登录记录 // }); // switch (count($logins)) { // case 1: // case 2: // $prop += $item->f_7day2on; // break; // case 3: // case 4: // $prop += $item->f_7day4on; // break; // case 5: // case 6: // $prop += $item->f_7day6on; // break; // default: // break; // } // 英雄碎片修正 // ...碎片数据还没有... // ...卒 if ($prop < 0) { $prop = 0; } $item->probability = $prop; } $err = Lotterys::Dice($itemArr, 1, $rewardstr); # 投骰子 if ($err) { # 出错了 return Resp::err($err); } if (strlen($rewardstr) <= 0) { # 抽奖结果为空 return Resp::err(ErrCode::err_innerfault); } $rewardArr[] = $rewardstr; } # # 金币 $gold = CommUtil::random($boxInfo->goldsMin, $boxInfo->goldsMax); array_unshift($rewardArr, META_GOLD_ITEMID . ",$gold"); # 插入金币奖励 # # 经验卡 foreach (GameConfig::boxJingYanCards_getItem($boxid) as $id => $card) { if (CommUtil::randomPercent($card->probability)) { # 投色子决定是否掉落此类经验卡 $amt = CommUtil::random($card->cardsMin, $card->cardsMax); # 掉落数量 array_push($rewardArr, $card->cardId . ",$amt"); # 追加经验卡奖励 } } } $err = StoreProc::AddMultiItemInStore($req, implode(';', $rewardArr), 3); # 发放物品 if (ErrCode::ok != $err) { return Resp::err($err); } if ($user->privateState->BoxCoolDownTime < now()) { # 每开一次箱子,要加上该箱子的冷却时间 $user->privateState->BoxCoolDownTime = now(); } if ($Cash > 0) {// //如果传了免cd开宝箱的钻石数量,则开宝箱时候不累加冷却时间 ///郎总说如果用钻石开宝箱去掉宝箱冷却 } else { $user->privateState->BoxCoolDownTime += $boxInfo->coolDwonTime; } if ($user->privateState->BoxCoolDownTime - time() > glc()->Box_Total_CoolDown) {# 如果宝箱现在冷却时间大于宝箱冷却上线,则加锁 $user->privateState->BoxLock = 1; // //加宝箱锁,在一定时间内不能开启 } else { $user->privateState->BoxLock = 0; ////照顾旧账号。 } UserProc::updateUserInfo($req); # 回存数据 return Resp::ok(array('err' => 0, # # 返回值 'store' => $user->store, # # 仓库 'heros' => $user->heros, # # 最新英雄 'cooldown' => $user->privateState->BoxCoolDownTime, # # 冷却时间 'reward' => implode(';', $rewardArr), # # 奖品 'BoxLock' => $user->privateState->BoxLock, # # 是否加锁状态 'baodi' => $user->privateState->lottery->baodiLotterys, 'left_cishu' => $left_cishu)); # 当天剩余次数(限次) } }