123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?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 StoreProc
- *
- * @author c'y'zhao
- */
- class StoreProc {
- /**
- * 逻辑分发
- * 所有的Proc中必须有这样一个方法
- * @param Req $req
- */
- public static function procMain($req) {
- switch ($req->cmd) {
- case CmdCode::cmd_store_put: # 6401 放入仓库
- return StoreProc::AddItemInStore();
- default:
- Err(ErrCode::cmd_err);
- }
- }
-
- public static function AddItemInStore() {
- list($rwdStr) = req()->paras; //mask = 1:表示战斗中掉落
- $user = ctx();
- $err = self::AddMultiItemInStore($rwdStr);
- my_Assert(ErrCode::ok == $err, $err);
-
- UserProc::updateUserInfo();
- return Resp::ok(array(
- //'gold' => $user->baseInfo->gold,
- //'tili' => $user->baseInfo->tili,
- //'cash' => $user->baseInfo->cash,
- 'store' => $user->store));
-
- }
-
- /**
- * 具体奖励存入背包
- * @param type $goodsStr
- * @param type $src
- */
- public static function AddMultiItemInStore($goodsStr, $src = 1) {
- $ary = explode(";", $goodsStr);
- foreach ($ary as $value) {
- $val = explode(",", $value);
- my_Assert(count($val) > 1, "解析奖励字符串出错");
- list($itemId, $num) = $val; # ID, 数量
- $itemMo = GameConfig::item_getItem($itemId);
- switch ($itemMo->itemType) {
- case 1:
- self::PutItemsInStore($itemId, $num);
- break;
- case 2:
- self::PutEquipInStore($itemId, $num);
- break;
- default:
- break;
- }
- }
- }
-
- public static function PutItemsInStore($itemId,$num) {
- $items = ctx()->store->items;
- if(StlUtil::dictHasProperty($items, $itemId)){
- $items->$itemId += $num;
- } else {
- $items->$itemId = $num;
- }
-
- ctx()->store->items = $items;
- }
-
- public static function PutEquipInStore($equipId,$num) {
- $n = count((array)ctx()->store->equip);
-
- for ($index = 0; $index < $num; $index++) {
- $Equip = new Ins_Equip();
- ctx()->store->equip->$n = $Equip;
- }
- }
- }
|