123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- namespace loyalsoft;
- require_once __DIR__ . '/Lotterys.php';
- /**
- * Description of Boxes
- * 控制理论: 模型预测, 反馈校正, 滚动优化.
- * 目标: 检测游戏内部一批指定的数据, 动态调整宝箱掉落物品.
- * @version
- * 1.0.0 Created at 2017-9-13. by --gwang
- * @author gwang (mail@wanggangzero.cn)
- * @copyright ? 2017-9-13, SJZ LoyalSoft Corporation & gwang. All rights reserved.
- */
- class Boxes {
- /**
- * 消耗宝箱
- * @param Req $req
- * @param type $boxid
- * @param type $num
- */
- public static function ComsumeBoxes($req, $boxid, $num = 1) {
- $boxes = $req->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();
- 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(); # 回存数据
- 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)); # 当天剩余次数(限次)
- }
- }
|