123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979 |
- <?php
- namespace loyalsoft;
- /**
- * Description of StoreProc
- * 仓库/背包 处理流程
- * ===========================
- * 尚待处理的流程:道具售出时貌似存在多种格式....
- * @author
- */
- class StoreProc {
- /**
- * 逻辑分发
- * 所有的Proc中必须有这样一个方法
- * @param type $req
- */
- static function procMain($req) {
- switch ($req->cmd) {
- case CmdCode::cmd_store_put: # 6401 放入仓库
- return StoreProc::AddItemInStore($req);
- case CmdCode::cmd_store_singleSell: # 6402 出售单个道具
- return StoreProc::sellItem($req);
- case CmdCode::cmd_store_mutliSell: # 6403 批量出售 卖掉
- return StoreProc::sellMultiItemFromStore($req);
- case CmdCode::cmd_store_use: # 6404 使用道具
- return StoreProc::useItem($req);
- case CmdCode::cmd_store_refresh: # 6405 获取最新的仓库数据
- return StoreProc::refreshStore($req);
- // case CmdCode::cmd_store_decomposeItem: # 6406 分解道具
- // return StoreProc::decomposeItem($req);
- case CmdCode::cmd_store_Testcmd: # 6407 测试方法
- return StoreProc::Test($req);
- // case CmdCode::cmd_store_ItemUpgrade: # 6408 装备升级
- // return StoreProc::ItemUpgrade($req);
- // case CmdCode::cmd_store_GemCompose: # 6408 装备合成
- // return StoreProc::composeItem($req);
- //
- case CmdCode::cmd_store_WearEquip: # 6410 给英雄穿装备
- return StoreProc::WearEquipToHero($req);
- case CmdCode::cmd_store_UnWieldEquip: # 6411 将该装备从指定英雄上脱下
- return StoreProc::UnWieldEquip($req);
- //
- case CmdCode::cmd_store_AddMaxPacketNum: # 6412 扩展包裹格子数量
- return StoreProc::AddPacketNum($req);
- // case CmdCode::cmd_store_MeltEquip: # 6413 装备融合
- // Err(ErrCode::err_method_obsoleted);
- //// return StoreProc::MeltEquip($req);
- // case CmdCode::cmd_store_PiecesCompose: # 6415 碎片合成
- // return StoreProc::composePieces($req);
- case CmdCode::cmd_store_WearYanling: # 6416 装备言灵
- return StoreProc::WearYanlingToHero($req);
- case CmdCode::cmd_store_UnWieldYanling: # 6417 卸下言灵
- return StoreProc::UnWieldYanling($req);
- case CmdCode::cmd_store_mergeYanlingbook: # 6418 利用言灵召唤书碎片合成召唤书
- return self::MergeYanlingBook($req);
- case CmdCode::cmd_store_callyanling: # 6419 利用言灵召唤书召唤言灵
- return self::CallYanlingByBook($req);
- case CmdCode::cmd_store_yanling_upgrade: # 6420 言灵进阶
- return self::YanlingUpgrade($req);
- default:
- Err(ErrCode::cmd_err);
- }
- }
- /**
- * [6420] 言灵进阶
- * @param req $req
- */
- static function YanlingUpgrade($req) {
- list($yanlingUid) = $req->paras; # 参数 言灵uid(指定进阶的言灵实例id)
- $user = $req->userInfo->game;
- my_Assert(property_exists($user->store->yanling, $yanlingUid), "找不到这个言灵");
- $yanlingObj = $user->store->yanling->$yanlingUid;
- $yanlingMoId = $yanlingObj->typeId;
- $curGrade = property_exists($yanlingObj, "grade") ? $yanlingObj->grade : 1; # 当前等阶
- $toGrade = $curGrade + 1; # 下一等阶
- my_Assert($toGrade <= 5, ErrCode::store_yanlingGrade_max); # 已经进阶到最高
- $toGradeCfg = GameConfig::yanling_upgrade_getItem($yanlingMoId, $toGrade); # 下一阶配置
- my_Assert(null != $toGradeCfg, ErrCode::err_const_no); # 找不到言灵进阶常量
- $costs = explode(';', $toGradeCfg->cost_materials);
- my_Assert(count($costs) > 0, ErrCode::store_yanlingGrade_cfg); # 言灵进阶数据有误
- foreach ($costs as $c) {
- list($itemId, $num) = explode(',', $c); # 解析材料
- $err = self::removeItemFromStore($user->store, $itemId, $num); # 扣除 材料
- my_Assert(ErrCode::ok == $err, $err); # 防御扣除材料失败
- }
- $yanlingObj->grade = $toGrade; # 修改进阶
- $user->store->yanling->$yanlingUid = $yanlingObj; # 回写言灵数据
- UserProc::updateUserInfo(); # 回写玩家数据
- return Resp::ok(array(
- "store" => $req->userInfo->game->store, # # 目前来看只涉及到items变化
- ));
- }
- /**
- * [6418] 利用言灵召唤书碎片合成召唤书
- * @param req $req
- */
- static function MergeYanlingBook($req) {
- list($bookId) = $req->paras; # 参数 言灵召唤书id
- $user = $req->userInfo->game;
- $bookIdCfg = GameConfig::item_yanlingbook_getItem($bookId);
- my_Assert(null != $bookIdCfg, ErrCode::err_const_no); # 找不到言灵书常量
- list($segId, $num) = explode(',', $bookIdCfg->seg_num); # 解析所需碎片信息
- $err = self::removeItemFromStore($user->store, $segId, $num); # 扣除 碎片
- my_Assert(ErrCode::ok == $err, $err); # 防御扣除碎片失败
- self::PutOverlyingItemInStore($bookId); # 添加召唤书
- UserProc::updateUserInfo(); # 回写数据
- return Resp::ok(array(
- "store" => $req->userInfo->game->store, # # 目前来看只涉及到items变化
- ));
- }
- /**
- * [6419] 利用言灵召唤书召唤言灵
- * @param req $req
- */
- static function CallYanlingByBook($req) {
- list($bookId) = $req->paras; # 参数 利用的言灵召唤书id
- $user = $req->userInfo->game;
- $bookIdCfg = GameConfig::item_yanlingbook_getItem($bookId);
- my_Assert(null != $bookIdCfg, ErrCode::err_const_no); # 找不到言灵书常量
- $err = self::removeItemFromStore($user->store, $bookId); # 扣除 召唤书
- my_Assert(ErrCode::ok == $err, $err); # 防御扣除召唤书失败
- $costs = explode(';', $bookIdCfg->cost_materials);
- my_Assert(count($costs) > 0, ErrCode::store_book_info); # 召唤书数据有误
- foreach ($costs as $c) {
- list($itemId, $num) = explode(',', $c); # 解析材料
- $err = self::removeItemFromStore($user->store, $itemId, $num); # 扣除 材料
- my_Assert(ErrCode::ok == $err, $err); # 防御扣除材料失败
- }
- self::PutYanLingInStore($bookIdCfg->yanling_id, $req); # 添加言灵
- UserProc::updateUserInfo(); # 回写数据
- return Resp::ok(array(
- "store" => $req->userInfo->game->store, # # 目前来看只涉及到items变化
- ));
- }
- /**
- * 测试方法
- * @param Req $req
- * @return type
- */
- static public function Test($req) {
- // return StoreProc::MeltEquip($req);
- }
- /**
- * [6404] 使用仓库道具
- * @param Req $req
- */
- static function useItem($req) {
- Err(ErrCode::msg_method_obsoleted, "代码需更新");
- $itemId = $req->paras[0]; # 道具id
- $num = 1; # 数量, 可选参数, 默认为1
- if (count($req->paras) > 1) { # 如果传了,
- $num = $req->paras[1]; # 提取可选参数: 道具数量
- } # end 提取参数
- $typeId = substr($itemId, 0, 3); # 道具分类前缀
- switch ($typeId) { # 使用道具()
- // case '701': # 宝箱
- // $resp = Boxes::OpenBox($req); # 调用开宝箱功能
- // break;
- default : # 其他
- Err(ErrCode::store_itemcantuse);
- break;
- }
- return $resp;
- }
- /**
- * [6405] 刷新仓库列表
- * @param Req $req
- */
- static function refreshStore($req) {
- StoreProc::CheckItemNum($req);
- return Resp::ok(array('store' => $req->userInfo->game->store));
- }
- /**
- * [6409] 合成道具
- * @param Req $req
- */
- static public function composeItem($req) {
- Err(ErrCode::err_method_notimplement);
- // list($lowitemId, $usenum, $highitemId, $addnum, $gold) = $req->paras; # 提取参数: 消耗道具id, 消耗数量, 合成道具Id, 合成数量, 需要的手续费
- // my_Assert($usenum >= 3, "数量非法!");
- // $user = $req->userInfo->game; # user引用
- // $store = $user->store; # 背包引用
- //
- // $ok = StoreProc::removeItemFromStore($store, $lowitemId, $usenum); # 从仓库里移除这个道具, 支持移除指定数量
- // my_Assert(ErrCode::ok == $ok, $ok); # 如果仓库道具移出时出错,则直接返回错误
- // my_Assert(UserGameModel::Consume_Gold($user, $gold), ErrCode::notenough_gold_msg); # 扣除消耗的金币
- //
- // ActiveProc::ChangeTaskCount($req); # 更新任务计数器
- // $store->items->$highitemId += $addnum; # 添加新合成道具
- // UserProc::updateUserInfo();
- // $ret = array('resp' => "succeed!"); # 准备返回值
- // $resp = Resp::ok($ret); # 返回必须是object
- //
- // StoreProc::CheckItemNum($req);
- // return $resp;
- }
- /**
- * [6409] 合成碎片(几个碎片合成获得同品质或者更高品质的新碎片)
- * @param Req $req
- */
- static public function composePieces($req) {
- Err(ErrCode::err_method_notimplement);
- }
- // </editor-fold>
- // --------------- 以下为辅助方法 ------------------
- //
- // <editor-fold defaultstate="collapsed" desc=" 移除物品 ">
- /**
- * 从仓库中移除指定数量的物品
- * @param UserGameModel $user
- * @param type $itemId
- * @param type $itemcount
- * @return type
- */
- static function removeItemFromStore($store, $itemId, $itemcount = 1) {
- if (CommUtil::isPropertyExists($store->items, $itemId)) {
- if ($store->items->$itemId >= $itemcount) { # 数量足够
- $store->items->$itemId -= $itemcount;
- if ($store->items->$itemId == 0) {
- unset($store->items->$itemId);
- }
- return ErrCode::ok;
- } else {
- return ErrCode::store_itemnotenough; # 道具数量不足
- }
- } else {
- return ErrCode::store_itemno_err; # 没有这个道具
- }
- }
- /**
- * 从仓库移出装备
- * @param type $itemId uid
- * @param StoreModel $store
- * @return boolean
- */
- static function removeEquipFromStore($uid, $typeId, &$req) {
- $ok = false;
- echo var_export($uid);
- if (CommUtil::isPropertyExists($req->userInfo->game->store->equipment, $uid)) {
- // $con= ConstProc::getItemConst($req->mem, $req->userInfo->game->store->equipment->$uid->typeId);
- echo var_export($req->userInfo->game->store->equipment->$uid->typeId);
- if ($typeId == $req->userInfo->game->store->equipment->$uid->typeId) {
- echo "typeid相同";
- unset($req->userInfo->game->store->equipment->$uid);
- $ok = true;
- } else {
- echo "typeid检验错误";
- }
- }
- return $ok;
- }
- /**
- * 从仓库移除碎片
- * @param StoreModel $store
- * @param int $segmentId
- * @param int $num
- * @return bool 成功/失败
- */
- static function removeSegmetFromStore($store, $segmentId, $num = 1) {
- if (CommUtil::isPropertyExists($store->segement, $segmentId) #
- && $store->segement->$segmentId >= $num) {
- $store->segement->$segmentId -= $num;
- return TRUE;
- }
- return false;
- }
- /**
- * 向仓库添加碎片
- * @param StoreModel $store
- * @param int $segmentId
- * @param int $num
- */
- static function addSegmentIntoStore($store, $segmentId, $num = 1) {
- if (CommUtil::isPropertyExists($store->segement, $segmentId)) {
- $store->segement->$segmentId += $num;
- } else {
- $store->segement->$segmentId = $num;
- }
- $segMo = GameConfig::item_segment_getItem($segmentId);
- my_Assert($segMo != null, ErrCode::err_const_no);
- TaskProc::OnHeroSegmengNum($segMo->protoHeroID, $num);
- }
- /**
- * 计算玩家仓库中某种符石/道具的数量
- * @param type $map
- * @param type $stoneid
- * @return type
- */
- static function GetStoneCount($map, $stoneid) {
- $ret = 0;
- if ($map->store->stones && CommUtil::isPropertyExists($map->store->stones, $stoneid)) {
- $ret = $map->store->stones->
- $stoneid;
- }
- return $ret;
- }
- /**
- * 从仓库移除符石(道具)
- * @param MapModel $map
- * @param int $stoneid
- * @param int $num
- */
- static function RemoveStoneFromStore(&$map, $stoneid, $num = 1) {
- if ($num <= 0) {
- return $num;
- }
- $ret = 0;
- if ($map->store->stones && CommUtil::isPropertyExists($map->store->stones, $stoneid)) {
- $left = $map->store->stones->$stoneid - $num;
- if ($ret >= 0) {////这里有bug吗?应该是用$left啊,不过无所谓,反正这个函数暂时用不上,不考虑了.
- $map->store->stones->$stoneid -= $num;
- $ret = $num;
- }
- }
- return $ret;
- }
- // </editor-fold>
- //
- // <editor-fold defaultstate="collapsed" desc=" 放入物品 ">
- /**
- * 将其他物品放入仓库
- * @param type $itemId
- * @param UserGameModel $game
- */
- static function PutItemInStore($itemId, &$game) {
- if (CommUtil::isPropertyExists($game->store->items, $itemId)) {// 如果仓库中已经有这种元素,则其数目+1
- $game->store->items->$itemId += 1;
- } else {// 如果仓库中没有这种元素,则其数目置1
- $game->store->items->$itemId = 1;
- }
- }
- /**
- * 解包多种物品到玩家身上 【警告】此函数的异常处理功能残废,不安全
- * 检测如果当前物品格子大于物品总数,则可以获取战利品,否则不可以
- * @param Req $req
- * @param string $goodsStr itemid,num;itemid,num;...
- * @param int $src 1:战斗奖励, 2: 任务奖励, 3: 抽奖奖品, 4: 邮件领取, 5: 现金充值
- * @deprecated since version 0
- * @return type
- */
- public static function AddMultiItemInStore($req, $goodsStr, $src = 1) {
- // var_dump($goodsStr);
- $user = $req->userInfo->game;
- $ary = explode(";", $goodsStr);
- // var_dump($ary);
- foreach ($ary as $value) {
- $val = explode(",", $value);
- // var_dump($val);
- my_Assert(count($val) > 1, "解析奖励字符串出错");
- list( $itemId, $num) = $val; # ID, 数量
- $smItem = GameConfig::item_base_getItem($itemId); # 道具mo
- switch ($smItem->subType) { # 根据类型分别添加到容器中
- case META_EXP: # 指挥官经验
- UserGameModel::Add_Exp($user->baseInfo, $num);
- break;
- case META_GOLD_ITEMID: # 金币
- UserGameModel::Add_Gold($user->baseInfo, $num);
- break;
- case META_CASH_ITEMID: # 钻石
- UserGameModel::Add_Cash($user->baseInfo, $num);
- break;
- case META_tili_ITEMID: # 体力
- UserGameModel::Add_tili($req, $num);
- break;
- case META_FriendShipPoit_ItemId: # 友情值
- UserGameModel::Add_FriendPoint($user->baseInfo, $num);
- break;
- case META_PVPCOIN_ITEMID: # 竞技币
- $user->pvp->pvpCoins += $num;
- break;
- case META_ActivePoint_ITEMID:
- $user->task->dailyActivePoint += $num; # 每日任务活跃点
- break;
- case 101: # 武器
- StoreProc::PutEquipInStore($itemId, $req);
- CornerSignEventProc::OnBag_new_Weapon($req);
- break;
- case 401: # 言灵
- StoreProc::PutYanLingInStore($itemId, $req);
- CornerSignEventProc::OnBag_new_Yanling($req);
- break;
- case 201: # 碎片
- $segMo = GameConfig::item_segment_getItem($itemId);
- my_Assert($segMo != null, ErrCode::err_const_no);
- TaskProc::OnHeroSegmengNum($segMo->protoHeroID, $num);
- CornerSignEventProc::OnBag_new_Fragment($req);
- case 202: # 召唤书碎片
- case 312: # 言灵召唤/进阶材料
- case 351: # 言灵召唤书
- StoreProc::PutOverlyingItemInStore($itemId, $num); # 直接进包裹items
- $book = GameConfig::item_yanlingbook_getItem($itemId);
- $ylCfg = GameConfig::item_yanling_getItem($book->yanling_id);
- switch ($ylCfg->career) {
- case 1:
- CornerSignEventProc::OnCall_Warrior_new($req); #
- break;
- case 2:
- CornerSignEventProc::OnCall_Magician_new($req); #
- break;
- case 3:
- CornerSignEventProc::OnCall_Archer_new($req); #
- break;
- default :
- break;
- }
- break;
- case 321: # 进阶材料
- case 322: # 进阶材料
- case 323: # 锻造材料
- StoreProc::PutOverlyingItemInStore($itemId, $num); # 直接进包裹items
- CornerSignEventProc::OnBag_new_Material($req);
- break;
- case 311: # 基因(经验丹)
- StoreProc::PutOverlyingItemInStore($itemId, $num); # 直接进包裹items
- break;
- case 341: # 战场中掉落,不会进入包裹
- case 342:
- case 343:
- Err(ErrCode::err_innerfault, "落入包裹时,出现了非法物品");
- break;
- default :
- Err(ErrCode::err_innerfault, "落入包裹时,出现了非法物品");
- }
- }
- return ErrCode::ok; // 返回
- }
- /**
- * 向包裹中添加物品
- * @param req $req
- * @return type
- */
- public static function AddItemInStore($req) {
- Err(ErrCode::err_innerfault, "功能待开发 -王刚 2020年1月17日14:36:01");
- }
- /**
- * 将装备放入背包
- * @param type $itemId
- * @param Req $req
- */
- static function PutEquipInStore($itemId, &$req) {
- $privateState = $req->userInfo->game->privateState;
- if (!CommUtil::isPropertyExists($privateState, "currentId")) { // 如果仓库中已经有这种元素,则其数目+1
- $req->userInfo->game->privateState->currentId = 1;
- }
- $cid = $req->userInfo->game->privateState->currentId++;
- $equip = ObjectInit();
- $equip->typeId = $itemId;
- $req->userInfo->game->store->equipment->$cid = $equip;
- return $cid;
- // SystemProc::GetEquip($req->zoneid, $req->userInfo->game, $itemId); # 添加获得装备的消息
- }
- /**
- * 将言灵放入背包
- * @param type $itemId
- * @param Req $req
- */
- static function PutYanLingInStore($itemId, &$req) {
- $privateState = $req->userInfo->game->privateState;
- if (!CommUtil::isPropertyExists($privateState, "currentId")) { // 如果仓库中已经有这种元素,则其数目+1
- $req->userInfo->game->privateState->currentId = 1;
- }
- $cid = $req->userInfo->game->privateState->currentId++;
- $equip = ObjectInit();
- $equip->typeId = $itemId;
- $req->userInfo->game->store->yanling->$cid = $equip;
- return $cid;
- // SystemProc::GetEquip($req->zoneid, $req->userInfo->game, $itemId); # 添加获得装备的消息
- }
- /**
- * 将可叠加物品放入背包
- * @param int $itemId
- * @param int $num
- */
- static function PutOverlyingItemInStore($itemId, $num = 1) {
- $items = req()->userInfo->game->store->items; # dic: itemid=>number
- if (CommUtil::isPropertyExists($items, $itemId)) { # 如果仓库中已经有这种元素,则其数目+=num
- $items->$itemId += $num;
- } else { # 如果仓库中没有这种元素,则其数目置为num
- $items->$itemId = $num;
- }
- }
- /**
- * 物品包裹打散成独立道具到仓库
- * @param GoodsItemModel $itemModel
- * @param Req $req
- * @return type
- * @deprecated since version now
- */
- static function addSeprateItem($itemModel, $req) {
- Err(ErrCode::err_method_obsoleted, "未更新包裹操作");
- }
- /**
- * [6417] 给英雄装上言灵
- * @param req $req
- * @return type
- */
- static function WearYanlingToHero($req) {
- $user = $req->userInfo->game; # user引用
- list($itemtype, $yanling_uid, $herouid) = $req->paras; # 提取参数: 装备类型, 装备的UID, 英雄的UID
- if (!CommUtil::isPropertyExists($user->store->yanling, $yanling_uid)) { # 检测是否存在该言灵
- Err(ErrCode::store_itemno_err);
- }
- $yanlingVo = $user->store->yanling->$yanling_uid; # 取言灵对象
- if ($yanlingVo->herouid > 0 && $yanlingVo->herouid != $herouid) { # 检测该言灵是否装备到其他英雄身上
- Err(ErrCode::store_equipWeared_err);
- }
- $collectHeros = $user->heros->collectHeros; # 英雄集合
- if (!$collectHeros) { # 防御对象为空
- Err(ErrCode::err_innerfault);
- }
- if (!CommUtil::isPropertyExists($collectHeros, $herouid)) { # 检查英雄是否存在
- Err(ErrCode::hero_no);
- }
- $user->store->yanling->$yanling_uid->herouid = $herouid; # 言灵上添加反向引用, 避免查询时的循环
- // $arr = $collectHeros->$herouid->yanling;
- // my_Assert(count($arr) < 3, ErrCode::hero_yanling_full); # 言灵数量最多3个
- // $arr[] = $yanling_uid;
- // $collectHeros->$herouid->yanling = $arr;
- $oldYLid = $collectHeros->$herouid->yanling->$itemtype->itemuid; # 旧言灵id
- if ($oldYLid > 0) { # 代表替换操作
- $user->store->yanling->$oldYLid->herouid = 0; # 清理旧言灵的
- }
- $collectHeros->$herouid->yanling->$itemtype->itemuid = $yanling_uid; # 英雄身上添加言灵记录
- UserProc::updateUserInfo(); # 5.回写数据
- $ret = array('resp' => "succeed!");
- $resp = Resp::ok($ret); // 返回
- HeroProc::CalcUserFightPower($req->zoneid, $req->uid, $user); # 更新总战力榜
- return $resp;
- }
- /**
- * [6416] 给英雄卸下言灵
- * @param req $req
- * @return type
- * @deprecated since version 无法卸下,只能更换
- */
- static function UnWieldYanling($req) {
- $user = $req->userInfo->game; # user引用
- list($itemtype, $yanling_uid, $herouid) = $req->paras; # 提取参数: 装备类型, 装备的UID, 拥有该装备的英雄的UID
- $collectHeros = $user->heros->collectHeros;
- my_Assert(null != $collectHeros, ErrCode::err_innerfault); # 防御
- my_Assert(CommUtil::isPropertyExists($collectHeros, $herouid), ErrCode::hero_no); # 检测是否存在拥有该装备的英雄
- my_Assert(CommUtil::isPropertyExists($user->store->yanling, $yanling_uid), ErrCode::store_itemno_err); # 检测是否存在该装备
- if ($user->store->yanling->$yanling_uid->herouid == $herouid) { # 取装备对象
- $user->store->yanling->$yanling_uid->herouid = 0; # 清理反向引用
- }
- // $arr = $collectHeros->$herouid->yanling;
- // my_Assert(in_array($yanling_uid, $arr), ErrCode::hero_yanling_notfound); # 未装备此言灵
- // StlUtil::arrayRemove($arr, $yanling_uid);
- // $collectHeros->$herouid->yanling = $arr;
- my_Assert($collectHeros->$herouid->yanling->$itemtype->itemuid == $yanling_uid, ErrCode::store_noequip_err); # 防御
- $collectHeros->$herouid->yanling->$itemtype->itemuid = 0; # 卸下
- UserProc::updateUserInfo(); # 回写数据
- $resp = Resp::ok(array('resp' => "succeed!")); // 返回
- // StoreProc::CheckItemNum($req);
- return $resp;
- }
- /**
- * [6410] 给英雄穿装备
- * @param req $req
- * @return type
- */
- static function WearEquipToHero($req) {
- list($itemtype, $equipuid, $herouid) = $req->paras; # 提取参数: 装备类型, 装备的UID, 英雄的UID
- $user = $req->userInfo->game; # user引用
- my_Assert(CommUtil::isPropertyExists($user->store->equipment, $equipuid), ErrCode::store_itemno_err); # 检测是否存在该装备
- $equipVo = $user->store->equipment->$equipuid; # 取装备对象
- if ($equipVo->herouid > 0) { # 检测该装备是否装备到其他英雄身上
- my_Assert($equipVo->herouid == $herouid, ErrCode::store_equipWeared_err);
- $user->store->equipment->$equipuid->herouid = 0; # 清理原来已经装备的言灵的反指向
- }
- $collectHeros = $user->heros->collectHeros;
- my_default_Obj($collectHeros);
- my_Assert(CommUtil::isPropertyExists($collectHeros, $herouid), ErrCode::hero_no); # 检查是否存在需要装备的英雄
- $user->store->equipment->$equipuid->herouid = $herouid; # 装备上添加反向引用, 避免查询时的循环
- $oldEquipId = 0;
- switch ($itemtype) { # 添加或替换英雄该部位的装备
- case 1: # 武器
- $oldEquipId = $collectHeros->$herouid->equip->weapon->itemuid;
- $collectHeros->$herouid->equip->weapon->itemuid = $equipuid;
- break;
- case 2: # 防具
- $oldEquipId = $collectHeros->$herouid->equip->armor->itemuid;
- $collectHeros->$herouid->equip->armor->itemuid = $equipuid;
- break;
- case 3: # 饰品
- $oldEquipId = $collectHeros->$herouid->equip->ring->itemuid;
- $collectHeros->$herouid->equip->ring->itemuid = $equipuid;
- break;
- default :
- Err(ErrCode::store_equip_type);
- break;
- }
- if ($oldEquipId > 0 && $oldEquipId != $equipuid) {
- $user->store->equipment->$oldEquipId->herouid = 0;
- }
- UserProc::updateUserInfo(); // 5.回写数据
- // StoreProc::CheckItemNum($req);
- HeroProc::CalcUserFightPower($req->zoneid, $req->uid, $user); # 更新总战力榜
- return Resp::ok(array('resp' => "succeed!")); // 返回
- }
- /**
- * [6411] 给英雄脱装备
- * @deprecated since version 不能卸下装备, 只能更换.
- * @param req $req
- * @return type
- */
- static function UnWieldEquip($req) {
- list($itemtype, $equipuid, $herouid) = $req->paras; # 提取参数: 装备类型, 装备的UID, 拥有该装备的英雄的UID
- $user = $req->userInfo->game; # user引用
- $collectHeros = $user->heros->collectHeros;
- my_default_Obj($collectHeros);
- my_Assert(CommUtil::isPropertyExists($collectHeros, $herouid), ErrCode::hero_no); # 检测是否存在拥有该装备的英雄
- my_Assert(CommUtil::isPropertyExists($user->store->equipment, $equipuid), ErrCode::store_itemno_err); # 检测是否存在该装备
- if ($user->store->equipment->$equipuid->herouid == $herouid) { # 取装备对象
- $user->store->equipment->$equipuid->herouid = 0;
- }
- switch ($itemtype) { # 检测该装备是否装备在该英雄身上
- case 1: # 武器
- if ($collectHeros->$herouid->equip->weapon->itemuid != $equipuid) {
- Err(ErrCode::store_noequip_err);
- }
- $collectHeros->$herouid->equip->weapon->itemuid = 0; # 卸下
- break;
- case 2: # 防具
- if ($collectHeros->$herouid->equip->armor->itemuid != $equipuid) {
- Err(ErrCode::store_noequip_err);
- }
- $collectHeros->$herouid->equip->armor->itemuid = 0;
- break;
- case 3: # 饰品
- if ($collectHeros->$herouid->equip->ring->itemuid != $equipuid) {
- Err(ErrCode::store_noequip_err);
- }
- $collectHeros->$herouid->equip->ring->itemuid = 0;
- break;
- default :
- Err(ErrCode::store_equip_type);
- }
- UserProc::updateUserInfo(); # 回写数据
- // StoreProc::CheckItemNum($req);
- return Resp::ok(array('resp' => "succeed!")); // 返回
- }
- // </editor-fold>
- //
- // <editor-fold defaultstate="collapsed" desc=" 辅助方法 ">
- /**
- * 将宝箱放入仓库
- * @param StoreModel $store
- * @param int $boxId 宝箱类型编号
- * @param int $num 数量
- */
- static function putBoxexInStore($store, $boxId, $num) {
- Err(ErrCode::err_method_obsoleted);
- if (CommUtil::isPropertyExists($store->boxes, $boxId)) {
- $store->boxes->$boxId += $num;
- } else {
- $store->boxes->$boxId = $num;
- }
- }
- /**
- * 检查背包中物品的个数
- * @param req $req
- * @return int
- */
- public static function CheckItemNum($req) {
- $ItemObj = $req->userInfo->game->store->items;
- $EquipObj = $req->userInfo->game->store->equipment;
- $SegementObj = $req->userInfo->game->store->segement;
- $HeroObj = $req->userInfo->game->heros->collectHeros;
- $ItemNum = 0;
- ////检查宝石类可叠加物品的格子占用
- if ($ItemObj) {
- foreach ($ItemObj as $value) {
- $ItemNum++;
- }
- }
- if ($SegementObj) {
- foreach ($SegementObj as $value) {
- $ItemNum++;
- }
- }
- ////检测装备类物品格子占用
- if ($EquipObj) {
- foreach ($EquipObj as $value) {
- $ItemNum++;
- }
- }
- ////检测英雄装备到身上的情况,装备到英雄身上不占格子,要减去.
- if ($HeroObj) {
- foreach ($HeroObj as $value) {
- // echo var_dump($HeroObj);
- $HeroEquipId = $value->equip->weapon->itemuid;
- if ($HeroEquipId > 0) {
- $ItemNum--;
- }
- $HeroEquipId = $value->equip->armor->itemuid;
- if ($HeroEquipId > 0) {
- $ItemNum--;
- }
- $HeroEquipId = $value->equip->ring->itemuid;
- if ($HeroEquipId > 0) {
- $ItemNum--;
- }
- }
- }
- $req->userInfo->game->privateState->ItemNum = $ItemNum;
- return $ItemNum;
- }
- /**
- * 获取物品格子的上限值
- * @return int 上限数值
- */
- public static function GetItemMaxNum() {
- $user = req()->userInfo->game;
- if (!CommUtil::isPropertyExists($user->privateState, "maxItemNum")) {
- $user->privateState->maxItemNum = glc()->Item_Packet_MaxNum;
- }
- return $user->privateState->maxItemNum;
- }
- /**
- * 背包扩容
- * @param type $req
- * @return type
- */
- public static function AddPacketNum($req) {
- $user = $req->userInfo->game; # user引用
- if (!CommUtil::isPropertyExists($user->privateState, "maxItemNum")) {
- $user->privateState->maxItemNum = glc()->Item_Packet_MaxNum;
- }
- $costCash = glc()->Item_Packet_NumCostCash; # 钻石花费
- my_Assert($costCash > 0, ErrCode::paras_err);
- my_Assert(UserGameModel::Consume_Cash($user, $costCash), ErrCode::notenough_cash_msg); # 6.进行消耗
- $user->privateState->maxItemNum += 10; # 扩容
- UserProc::updateUserInfo(); # 保存玩家数据
- $resp = Resp::ok(array('maxItemNum' => $user->privateState->maxItemNum)); # 返回值
- StoreProc::CheckItemNum($req);
- return $resp;
- }
- // </editor-fold>
- //
- //
- //
- // <editor-fold defaultstate="collapsed" desc=" 出售 ">
- //
- /**
- * 出售单一的物品
- * @param Req $req
- * @return type
- */
- static function sellItem($req) {
- Err(ErrCode::err_method_obsoleted, "代码需要更新");
- $resp = new Resp();
- $mem = $req->mem;
- // $user = $req->userInfo->user;
- $store = $req->userInfo->game->store; //$req->userInfo->game->store->items
- //客户端参数解析
- $type = $req->paras[0]; //1=神兽 2=建筑 //需要判断是否叠加
- $itemId = $req->paras[1]; // 注意:这里不是单体的id,而是物种的id
- if ($type > 3) {
- $count = intval($req->paras[2]); // 数量
- $uid = 0;
- } else {
- $count = 1;
- $uid = $req->paras[2];
- }//物品的uid
- ////0是type 1是itemid,2是uid或者是数量
- if ($type > 3 && $type < 8) { // 从仓库出售宝石 出售可叠加的物品
- $ok = StoreProc::removeItemFromStore($store, $itemId, $count); // 支持移除指定数量
- my_Assert($ok == ErrCode::ok, $ok); //1.如果仓库道具移出时出错,则直接返回错误
- // echo "弄弄";
- $gem = GameConfig::item_getItem($itemId); // ConstProc::getItemConst($itemId);
- echo var_export($gem);
- //2.检测是否存在该物品的原始物种
- if ($gem == null) {
- Err(ErrCode::err_godpet_noconst);
- }
- // 发金币
- UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $gem->maijia * $count);
- $ret = array('resp' => "succeed!");
- $resp = Resp::ok($ret);
- UserProc::updateUserInfo();
- } else if ($type == 8) { // 从仓库出售碎片 出售可叠加的物品
- $ok = StoreProc::removeItemFromStore($store, $itemId, $count); // 支持移除指定数量
- my_Assert($ok == ErrCode::ok, $ok); //1.如果仓库道具移出时出错,则直接返回错误
- // echo "弄弄";
- $gem = GameConfig::segment_getItem($itemId); // ConstProc::getItemConst($itemId);
- // echo var_export($gem);
- //2.检测是否存在该物品的原始物种
- if ($gem == null) {
- Err(ErrCode::err_godpet_noconst);
- }
- // 发金币
- UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $gem->saleGoldPrice * $count);
- $ret = array('resp' => "succeed!");
- $resp = Resp::ok($ret);
- UserProc::updateUserInfo();
- } else if ($type < 4 && $type > 0) { # 这里是装备
- if ($count > 1) {
- Err(ErrCode::paras_err);
- }
- if ($uid < 1) {
- Err(ErrCode::paras_err);
- }
- $ok = StoreProc::removeEquipFromStore($uid, $itemId, $req); # 从背包移除
- if (!$ok) {//1.如果背包道具移出时出错,则直接返回错误
- Err(ErrCode::store_removefail);
- }
- $item = GameConfig::item_getItem($itemId); // ConstProc::getItemConst($itemId);
- if ($item == null) { //2.检测是否存在装备的原始数据
- Err(ErrCode::err_const_no);
- }
- UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $item->maijia);
- $ret = array('resp' => "succeed!");
- $resp = Resp::ok($ret); //返回必须是object
- UserProc::updateUserInfo();
- } else {
- Err(ErrCode::paras_err);
- }
- StoreProc::CheckItemNum($req);
- return $resp;
- }
- /**
- * 卖出一堆物品时候,检测每个单个物品是否符合卖的条件
- * @param Req $req
- * @return type
- */
- static function preSellSingleFromStore(&$req, $type, $itemId, $count, $uid) {
- Err(ErrCode::err_method_obsoleted, "代码需要更新");
- $resp = new Resp();
- $mem = $req->mem;
- // $user = $req->userInfo->user;
- $store = $req->userInfo->game->store; //$req->userInfo->game->store->items
- //客户端参数解析
- ////0是type 1是itemid,2是uid或者是数量
- if ($type > 3 && $type < 8) { // 从仓库出售宝石 出售可叠加的物品
- echoLine(":fs::");
- $ok = StoreProc::removeItemFromStore($store, $itemId, $count); // 支持移除指定数量
- //1.如果仓库道具移出时出错,则直接返回错误
- my_Assert($ok == ErrCode::ok, $ok);
- echo "弄弄";
- $gem = GameConfig::item_getItem($itemId); // ConstProc::getItemConst($itemId);
- echo var_export($gem);
- //2.检测是否存在该物品的原始物种
- if ($gem == null) {
- Err(ErrCode::err_godpet_noconst);
- }
- // 发金币
- UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $gem->maijia * $count);
- $ret = array('resp' => "succeed!");
- $resp = Resp::ok($ret);
- } else if ($type == 8) { // 从仓库出售碎片 出售可叠加的物品
- $ok = StoreProc::removeItemFromStore($store, $itemId, $count); // 支持移除指定数量
- //1.如果仓库道具移出时出错,则直接返回错误
- my_Assert($ok == ErrCode::ok, $ok);
- // echo "弄弄";
- $gem = GameConfig::segment_getItem($itemId); // ConstProc::getItemConst($itemId);
- // echo var_export($gem);
- //2.检测是否存在该物品的原始物种
- if ($gem == null) {
- Err(ErrCode::err_godpet_noconst);
- }
- // 发金币
- UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $gem->saleGoldPrice * $count);
- $ret = array('resp' => "succeed!");
- $resp = Resp::ok($ret);
- } else if ($type < 4 && $type > 0) { # 这里是装备
- if ($count > 1) {
- Err(ErrCode::paras_err);
- }
- if ($uid < 1) {
- Err(ErrCode::paras_err);
- }
- $ok = StoreProc::removeEquipFromStore($uid, $itemId, $req); # 从背包移除
- if (!$ok) {//1.如果背包道具移出时出错,则直接返回错误
- Err(ErrCode::store_removefail);
- }
- $item = GameConfig::item_getItem($itemId); // ConstProc::getItemConst($itemId);
- if ($item == null) { //2.检测是否存在装备的原始数据
- Err(ErrCode::err_const_no);
- }
- UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $item->maijia);
- $ret = array('resp' => "succeed!");
- $resp = Resp::ok($ret); //返回必须是object
- } else {
- Err(ErrCode::paras_err);
- }
- return $resp;
- }
- /**
- * 从背包出售多个物品
- * @param Req $req
- * @return type
- */
- static function sellMultiItemFromStore($req) {
- $resp = new Resp();
- $obj = $req->paras[0]; // 获取物品的结构数组
- foreach ($obj as $value) {
- $type = $value[0];
- $itemId = $value[1];
- ////先判断一下物品类型,如果是可叠加的,就按数量取值,如果是不可叠加的就按uid取值
- if ($type > 3) {
- $count = intval($value[2]); // 数量
- $uid = 0;
- } else {
- $count = 1;
- $uid = $value[2];
- }//物品的uid
- $resp = StoreProc:: preSellSingleFromStore($req, $type, $itemId, $count, $uid);
- }
- if (0 == $resp->err) {
- UserProc::updateUserInfo();
- }
- StoreProc::CheckItemNum($req);
- return $resp;
- }
- // </editor-fold>
- //
- }
|