|
@@ -0,0 +1,147 @@
|
|
|
+<?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 StoreProc::ShopBuyGift();
|
|
|
+ default:
|
|
|
+ Err(ErrCode::cmd_err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 装备
|
|
|
+ * @return type
|
|
|
+ */
|
|
|
+ public static function ShopBuyGift() {
|
|
|
+ list($type,$typeId) = req()->paras;
|
|
|
+ $user = ctx();
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ StoreProc::AddMultiItemInStore($mo->reward);
|
|
|
+ ctx()->privateState->gateGiftReceived[] = $typeId;
|
|
|
+ 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);
|
|
|
+
|
|
|
+ $index = 0;
|
|
|
+ if(in_array($typeId, $user->privateState->dailyShopReceived)){
|
|
|
+ foreach ($user->privateState->dailyShopReceived as $val) {
|
|
|
+ if($val == $typeId){
|
|
|
+ $index += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ my_Assert($index<= $mo->limitNum, ErrCode::user_shop_LimitNum);
|
|
|
+
|
|
|
+ $str = $typeId.',1';
|
|
|
+ StoreProc::AddMultiItemInStore($str);
|
|
|
+ ctx()->privateState->dailyShopReceived[] = $typeId;
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case EnumShopGift::SJunBeiBox_Shop://S级军备
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ case EnumShopGift::BujiBox_Shop://补给箱
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ case EnumShopGift::Cash_Shop://商城-钻石
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ case EnumShopGift::Gold_Shop://商城-金币
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //my_Assert(StlUtil::dictHasProperty($user->store->equip, $uid), ErrCode::user_store_NoEquip);
|
|
|
+
|
|
|
+
|
|
|
+ UserProc::updateUserInfo();
|
|
|
+ return Resp::ok(array(
|
|
|
+ 'privateState' => $user->privateState,
|
|
|
+ 'store' => $user->store,));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商城每日重置
|
|
|
+ */
|
|
|
+ public static function ShopDailyClear() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每日商城随机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,$mo->type) ){
|
|
|
+ $list = $dataDic->$type;
|
|
|
+ $list[] = $typeId;
|
|
|
+ } else {
|
|
|
+ $list = array();
|
|
|
+ $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 = $arr2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ctx()->privateState->dailyShopRandItems = $result;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|