|
@@ -33,10 +33,10 @@ class ShopProc {
|
|
|
* @return type
|
|
|
*/
|
|
|
public static function ShopBuyGift() {
|
|
|
- list($type,$typeId) = req()->paras;
|
|
|
+ list($type,$typeId,$buyNum) = req()->paras;
|
|
|
$user = ctx();
|
|
|
|
|
|
- $equipId = 0;
|
|
|
+ $equip = array();
|
|
|
switch ($type) {
|
|
|
case EnumShopGift::GateGift_Shop://章节礼包
|
|
|
my_Assert(!in_array($typeId, ctx()->privateState->gateGiftReceived), ErrCode::user_shop_NotRepeatBuy);
|
|
@@ -74,68 +74,193 @@ class ShopProc {
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case EnumShopGift::SJunBeiBox_Shop://S级军备
|
|
|
-
|
|
|
-
|
|
|
- break;
|
|
|
- case EnumShopGift::BujiBox_Shop://补给箱
|
|
|
- $mo = GameConfig::shop_supply_getItem($typeId);
|
|
|
+ case EnumShopGift::SJunBeiBox_Shop://S级军备
|
|
|
+ $mo = GameConfig::shop_junbei_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);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
|
|
|
- $user->store->removeItem($list[0], $list[1]);
|
|
|
- $user->baseInfo->Add_Cash($mo->gold);
|
|
|
-
|
|
|
- //必出
|
|
|
- $bichu = $mo->bichu;
|
|
|
- if($mo->type == 1){
|
|
|
- $num = $user->privateState->supplyShopNum_JunyongBox;
|
|
|
- } else {
|
|
|
- $num = $user->privateState->supplyShopNum_BujiBox;
|
|
|
+ $allDic = $user->privateState->junbeiShop_AllNumRecord;
|
|
|
+ if(!StlUtil::dictHasProperty($allDic, $typeId)){
|
|
|
+ $allDic->$typeId = new Ins_JunBeiShop();
|
|
|
+ $user->privateState->junbeiShop_AllNumRecord =$allDic;
|
|
|
}
|
|
|
|
|
|
- $qual = null;
|
|
|
- if($num%$bichu == 0){
|
|
|
- $qual = $mo->bichu_qual;
|
|
|
- }
|
|
|
+ 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($qual == null){
|
|
|
- $list = explode(';', $mo->percent);
|
|
|
+ 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;
|
|
|
-
|
|
|
- $result = 0;
|
|
|
+ $end = 0;
|
|
|
foreach ($list as $item) {
|
|
|
$arr = explode(',', $item);
|
|
|
-
|
|
|
$per = $arr[2]*100;
|
|
|
$end += $per;
|
|
|
- if($randNum >= $start && $randNum <$end){
|
|
|
- $qual = $arr[0].','.$arr[1];
|
|
|
+ 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_buchu1 = 0;
|
|
|
+ $tag = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($qual == $bichu2[1] && $xiyoudu == $bichu2[2]){
|
|
|
+ $resultStr = $bichu2[1].",".$bichu2[2];
|
|
|
+ $user->privateState->junbeiShop_AllNumRecord->$typeId->num_buchu2 = 0;
|
|
|
+ $tag = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$tag){//没有得到杰出或是S级杰出
|
|
|
+ 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]){
|
|
|
+ //得S级杰出
|
|
|
+ $resultStr = $bichu2[1].",".$bichu2[2];
|
|
|
+ $user->privateState->junbeiShop_AllNumRecord->$typeId->num_bichu2 = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if($resultStr != null){
|
|
|
+ $str = explode(',', $resultStr);
|
|
|
+
|
|
|
+ $equipList = array();
|
|
|
+ foreach ($dic as $tid => $item) {
|
|
|
+ if($str[0] == 1 || $str[0] == 2){//稀有度为1的装备
|
|
|
+ if($item->qual == $str[0] && $item->rarity == $str[1]){
|
|
|
+ $equipList[] = $item->typeId;
|
|
|
+ }
|
|
|
+ }elseif ($str[0] == 3) {//特定装备的
|
|
|
+ if($item->typeId == $str[0]){
|
|
|
+ $equipList[] = $item->typeId;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $rNum = rand(0, count($equipList));
|
|
|
+ $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);
|
|
|
+ $str = explode(',', $qual);
|
|
|
|
|
|
$equipList = array();
|
|
|
$dic = GameConfig::equip();
|
|
|
foreach ($dic as $tid => $item) {
|
|
|
- if($item->type == $str[0] && $item->rarity == $str[1]){
|
|
|
+ if($item->qual == $str[0] && $item->rarity == $str[1]){
|
|
|
$equipList[] = $item->typeId;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$rNum = rand(0, count($equipList));
|
|
|
$equipId = $equipList[$rNum];
|
|
|
+ StoreProc::PutEquipInStore($equipId, 1);
|
|
|
+ $equip[] = $equipId;
|
|
|
}
|
|
|
-
|
|
|
- StoreProc::PutEquipInStore($equipId, 1);
|
|
|
+
|
|
|
break;
|
|
|
case EnumShopGift::Cash_Shop://商城-钻石
|
|
|
$mo = GameConfig::shop_cash_getItem($typeId);
|
|
@@ -180,7 +305,7 @@ class ShopProc {
|
|
|
|
|
|
UserProc::updateUserInfo();
|
|
|
return Resp::ok(array(
|
|
|
- 'equip'=>$equipId,
|
|
|
+ 'equip'=>$equip,
|
|
|
'base'=>$user->baseInfo,
|
|
|
'privateState' => $user->privateState,
|
|
|
'store' => $user->store,));
|
|
@@ -193,8 +318,8 @@ class ShopProc {
|
|
|
public static function ShopDailyClear() {
|
|
|
ctx()->privateState->dailyShopReceived = array();
|
|
|
ctx()->privateState->goldShopReceived = array();
|
|
|
- ctx()->privateState->supplyShopNum_BujiBox = 0;
|
|
|
- ctx()->privateState->supplyShopNum_JunyongBox = 0;
|
|
|
+ ctx()->privateState->junbeiShopNumRecord = new \stdClass();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|