123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- namespace loyalsoft;
- /**
- * Description of ShopProc
- *
- * @author c'y'zhao
- */
- class ShopProc {
- /**
- * 逻辑分发
- * 所有的Proc中必须有这样一个方法
- * @param Req $req
- */
- public static function procMain($req) {
- switch ($req->cmd) {
- case CmdCode::cmd_shop_BuyGift: # 6501 商城购买东西
- return ShopProc::ShopBuyGift();
- default:
- Err(ErrCode::cmd_err);
- }
- }
-
- /**
- * 商城购买东西
- * @return type
- */
- public static function ShopBuyGift() {
- list($type,$typeId,$buyNum) = req()->paras;
- $user = ctx();
- $equip = array();
- $gateGift = array();
- switch ($type) {
- case EnumShopGift::GateGift_Shop://章节礼包
- my_Assert(!in_array($typeId, ctx()->privateState->gateGiftReceived), ErrCode::user_shop_NotRepeatBuy);
-
- $mo = GameConfig::shop_gategift_getItem($typeId);
- my_Assert($mo != null, ErrCode::err_const_no);
-
- $price = explode(';', $mo->reward);
- foreach ($price as $value) {
- $item = explode(',', $value);
- if(GameConfig::item_getItem($item[0])->itemType == EnumItemType::tuzhiBox){
- $dic = GameConfig::item();
- $list = array();
- foreach ($dic as $id => $val) {
- if($val->itemType == EnumItemType::tuzhi){
- $list[] = $val->typeId;
- }
- }
-
- $randNum = rand(0, count($list)-1);
- $tuzhiId = $list[$randNum];
- $gateGift[] = $tuzhiId.',1';
-
- } else {
- $gateGift[] = $value;
- }
- }
-
- foreach ($gateGift as $str) {
- StoreProc::AddMultiItemInStore($str);
- }
-
- ctx()->privateState->gateGiftReceived[] = $typeId;
-
- ctx()->baseInfo->charge_amt += $mo->curPrice;
- break;
- case EnumShopGift::Daily_Shop://每日商店
- $mo = GameConfig::shop_daily_getItem($typeId);
- my_Assert($mo != null, ErrCode::err_const_no);
-
- my_Assert(in_array($typeId, $user->privateState->dailyShopRandItems), ErrCode::err_const_no);
- my_Assert(!in_array($typeId, $user->privateState->dailyShopReceived), ErrCode::user_shop_NotRepeatBuy);
-
- switch ($mo->costType) {
- case EnumShopCost::Gold:
- my_Assert($user->baseInfo->gold>= $mo->costNum, ErrCode::notenough_gold_msg);
- ctx()->baseInfo->Consume_Gold($mo->costNum);
- break;
- case EnumShopCost::Cash:
- my_Assert($user->baseInfo->cash>= $mo->costNum, ErrCode::notenough_cash_msg);
- ctx()->baseInfo->Consume_Cash($mo->costNum);
- break;
- default:
- break;
- }
-
- StoreProc::AddMultiItemInStore($mo->reward);
- ctx()->privateState->dailyShopReceived[] = $typeId;
-
- break;
-
- case EnumShopGift::SJunBeiBox_Shop://S级军备
- $mo = GameConfig::shop_junbei_getItem($typeId);
- my_Assert($mo != null, ErrCode::err_const_no);
-
- my_Assert(now()>=$mo->startTs && now() < $mo->endTs, ErrCode::user_shop_activeExpire); //活动过期
- $numDic = $user->privateState->junbeiShopNumRecord;
- if(!StlUtil::dictHasProperty($numDic, $typeId)){
- $numDic->$typeId = 0;
- $user->privateState->junbeiShopNumRecord =$numDic;
- }
-
- $allDic = $user->privateState->junbeiShop_AllNumRecord;
- if(!StlUtil::dictHasProperty($allDic, $typeId)){
- $junbei = new Ins_JunBeiShop();
- $junbei->typeId = $typeId;
- $allDic->$typeId = $junbei;
- $user->privateState->junbeiShop_AllNumRecord =$allDic;
- }
-
- my_Assert($numDic->$typeId + $buyNum <= $mo->limitNum, ErrCode::user_shop_LimitNum);
- $costArr = explode(',', $mo->cost_item);
- $costId = $costArr[0];
- $costNum = $costArr[1];
-
- $cash = 0;
- if($buyNum == 1){//买一次
- $user->privateState->junbeiShopNumRecord->$typeId += 1;
- $cash = $mo->cost_one;
- } else {//买10次
- $user->privateState->junbeiShopNumRecord->$typeId += 10;
- $cash = $mo->cost_ten;
- $costNum *= 10;
- }
-
- if(StlUtil::dictHasProperty($user->store->items, $costId) && $user->store->items->$costId >= $costNum){
- $user->store->removeItem($costId, $costNum);
- } else {
- //判断下钻石是否充足
- my_Assert($user->baseInfo->cash >= $cash, ErrCode::notenough_cash_msg);
- $user->baseInfo->Consume_Cash($cash);
- }
- $bichu = explode(',', $mo->bichu_1);
- $bichu2 = explode(',', $mo->bichu_2);
- $dic = GameConfig::equip();
- $list = explode(';', $mo->percent);
-
- for ($i = 0; $i < $buyNum; $i++) {
- $qual = 0;
- $xiyoudu = 0;
- $randNum = rand(0,10000);
- $start = 0;
- $end = 0;
- foreach ($list as $item) {
- $arr = explode(',', $item);
- $per = $arr[2]*100;
- $end += $per;
- if($randNum >= $start && $randNum <$end){
- $qual = $arr[0];
- $xiyoudu = $arr[1];
- break;
- }
- $start = $end;
- }
-
- $user->privateState->junbeiShop_AllNumRecord->$typeId->num_bichu1 += 1;
- $user->privateState->junbeiShop_AllNumRecord->$typeId->num_bichu2 += 1;
-
- $resultStr = $qual.",".$xiyoudu;
- $tag = false;
- if($qual == $bichu[1] && $xiyoudu == $bichu[2]){
- $resultStr = $bichu[1].",".$bichu[2];
- $user->privateState->junbeiShop_AllNumRecord->$typeId->num_bichu1 = 0;
- //$tag = true;
- }
-
- if($qual == $bichu2[1] && $xiyoudu == $bichu2[2]){
- $resultStr = $bichu2[1].",".$bichu2[2];
- $user->privateState->junbeiShop_AllNumRecord->$typeId->num_bichu2 = 0;
- if($user->privateState->junbeiShop_AllNumRecord->$typeId->num_bichu1 == $bichu[0]){
- $user->privateState->junbeiShop_AllNumRecord->$typeId->num_bichu1 = 0;
- }
- //$tag = true;
- }
-
- // if($tag){
- // }
-
- if($user->privateState->junbeiShop_AllNumRecord->$typeId->num_bichu1 == $bichu[0]){
- $resultStr = $bichu[1].",".$bichu[2];//得杰出
- $user->privateState->junbeiShop_AllNumRecord->$typeId->num_bichu1 = 0;
- }
-
- if($user->privateState->junbeiShop_AllNumRecord->$typeId->num_bichu2 == $bichu2[0]){
- $resultStr = $bichu2[1].",".$bichu2[2];//得S级杰出
- $user->privateState->junbeiShop_AllNumRecord->$typeId->num_bichu2 = 0;
- }
-
- if($resultStr != null){
- $str = explode(',', $resultStr);
-
- $equipList = array();
- foreach ($dic as $tid => $item) {
- if($str[1] == 1 || $str[1] == 2){//稀有度为1的装备
- if($item->qual == $str[0] && $item->rarity == $str[1]){
- $equipList[] = $item->typeId;
- }
- }elseif ($str[1] == 3) {//特定装备的
- if($item->typeId == $str[0]){
- $equipList[] = $item->typeId;
- }
- }
- }
- $rNum = rand(0, count($equipList)-1);
- $equipId = $equipList[$rNum];
- StoreProc::PutEquipInStore($equipId, 1);
- $equip[] = $equipId;
- }
-
- }
-
- $user->baseInfo->Add_Gold($mo->gold*$buyNum);
-
- break;
- case EnumShopGift::BujiBox_Shop://补给箱
- $mo = GameConfig::shop_supply_getItem($typeId);
- my_Assert($mo != null, ErrCode::err_const_no);
-
- $list = explode(',', $mo->cost);
- my_Assert(StlUtil::dictHasProperty($user->store->items, $list[0]), ErrCode::notenough_item);
-
- $user->store->removeItem($list[0], $list[1]);
- $user->baseInfo->Add_Gold($mo->gold);
- if(!StlUtil::dictHasProperty($user->privateState->junbeiShopNumRecord, $typeId)){
- $user->privateState->junbeiShopNumRecord->$typeId = 0;
- }
- $num = $user->privateState->junbeiShopNumRecord->$typeId += 1;
-
- if(!StlUtil::dictHasProperty($user->privateState->supplyBichuDic, $typeId)){
- $user->privateState->supplyBichuDic->$typeId = 0;
- }
- $user->privateState->supplyBichuDic->$typeId += 1;
-
- my_Assert($num <= $mo->limitNum, ErrCode::user_shop_LimitNum);
- $list = explode(';', $mo->percent);
- $randNum = rand(0,10000);
- $start = 0;
- $end = 0;
- $qual = null;
- foreach ($list as $item) {
- $arr = explode(',', $item);
- $per = $arr[2]*100;
- $end += $per;
- if($randNum >= $start && $randNum <$end){
- $qual = $arr[0].','.$arr[1];//品阶,稀有度
- break;
- }
- $start = $end;
- }
- //必出
- $bichu = explode(',', $mo->bichu);
- $qArr = explode(',', $qual);
- if($qArr[0]==$bichu[1] && $qArr[1] == $bichu[2]){//得到必出,重置数量记录
- $user->privateState->supplyBichuDic->$typeId = 0;
- $qual = $bichu[1].','.$bichu[2];
- } else {
- if($user->privateState->supplyBichuDic->$typeId == $bichu[0]){
- $qual = $bichu[1].','.$bichu[2];
- $user->privateState->supplyBichuDic->$typeId = 0;
- }
- }
-
- if($qual != null){
- $str = explode(',', $qual);
-
- $equipList = array();
- $dic = GameConfig::equip();
- foreach ($dic as $tid => $item) {
- if($item->qual == $str[0] && $item->rarity == $str[1]){
- $equipList[] = $item->typeId;
- }
- }
-
- $rNum = rand(0, count($equipList)-1);
- $equipId = $equipList[$rNum];
- StoreProc::PutEquipInStore($equipId, 1);
- $equip[] = $equipId;
- }
-
- break;
- case EnumShopGift::Cash_Shop://商城-钻石
- $mo = GameConfig::shop_cash_getItem($typeId);
- my_Assert($mo != null, ErrCode::err_const_no);
-
- $tag = false;
- if(in_array($typeId,$user->privateState->cashShopReceived)){
- $tag = true;
- }
-
- $reward = $mo->reward;
- if(!$tag){
- $reward = $mo->reward.';'.$mo->reward;
- }
-
- StoreProc::AddMultiItemInStore($reward);
- $user->baseInfo->charge_amt += $mo->price;
- $user->privateState->cashShopReceived[] = $typeId;
-
- break;
- case EnumShopGift::Gold_Shop://商城-金币--可以多次购买
- $mo = GameConfig::shop_gold_getItem($typeId);
- my_Assert($mo != null, ErrCode::err_const_no);
-
- $tempNum = 0;
- foreach ($user->privateState->goldShopReceived as $key) {
- if($key == $typeId){
- $tempNum += 1;
- }
- }
-
- if($tempNum >= $mo->freeNum){
- my_Assert($user->baseInfo->cash>= $mo->costNum, ErrCode::notenough_cash_msg);
- ctx()->baseInfo->Consume_Cash($mo->price);
- }
-
- $user->privateState->goldShopReceived[] = $typeId;
-
- StoreProc::AddMultiItemInStore($mo->reward);
-
- break;
- default:
- break;
- }
-
- if(ctx()->baseInfo->charge_amt > 0 && ctx()->baseInfo->fRechargePriceReceived == 0){
- StoreProc::AddMultiItemInStore(GameConfig::globalsettings()->FirstRechargePrice);
- ctx()->baseInfo->fRechargePriceReceived = 1;
- }
-
-
- ctx($user);
- UserProc::updateUserInfo();
- return Resp::ok(array(
- 'gateGift'=>$gateGift,
- 'equip'=>$equip,
- 'cash'=>$user->baseInfo->cash,
- 'gold'=>$user->baseInfo->gold,
- 'privateState' => $user->privateState,
- 'store' => $user->store,));
-
- }
-
- /**
- * 商城每日重置
- */
- public static function ShopDailyClear() {
- ctx()->privateState->dailyShopReceived = array();
- ctx()->privateState->goldShopReceived = array();
- ctx()->privateState->junbeiShopNumRecord = new \stdClass();
-
- }
-
- /**
- * 每日商城随机6个道具
- * @return type
- */
- public static function DailyShopItemRand() {
- $dataDic = new \stdClass();
-
- $dic = GameConfig::shop_daily();
- if($dic == null){
- return;
- }
-
- foreach ($dic as $typeId => $mo) {
- $type = $mo->type;
- if(StlUtil::dictHasProperty($dataDic,$type) ){
- $list = $dataDic->$type;
- $list[] = $typeId;
- $dataDic->$type = $list;
- } else {
- $list = array();
- $list[] = $typeId;
- $dataDic->$type = $list;
- }
- }
- $result = array();
- $arrType = array(1,2,3,2,4,3);
- foreach ($arrType as $k) {
- if(StlUtil::dictHasProperty($dataDic,$k) && count($dataDic->$k) > 0){
- $arr2 = $dataDic->$k;
- $num = rand(0, count($arr2)-1);
- $result[] = $arr2[$num];
- unset($arr2[$num]);
-
- $dataDic->$k = array_values($arr2);
- }
- }
-
-
- ctx()->privateState->dailyShopRandItems = $result;
- UserProc::updateUserInfo();
- }
- }
|