1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006 |
- <?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 501: # 限购礼包
- break;
- case 601: # 任务卡
- StoreProc::PutTaskCardInStore($itemId, $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, "落入包裹时,出现了非法物品($itemId)");
- break;
- default :
- Err(ErrCode::err_innerfault, "落入包裹时,出现了非法物品($itemId)");
- }
- }
- return ErrCode::ok; // 返回
- }
- /**
- * 向包裹中添加物品
- * @param req $req
- * @return type
- */
- public static function AddItemInStore($req) {
- list($rwdStr) = $req->paras;
- $err = self::AddMultiItemInStore($req, $rwdStr);
- my_Assert(ErrCode::ok == $err, $err);
- UserProc::updateUserInfo();
- return Resp::ok(array('store' => $req->userInfo->game->store));
- // 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 type $itemId
- * @param Req $req
- */
- static function PutTaskCardInStore($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++;
- $taskCard = new TaskCardVo();
- $taskCard->typeId = $itemId;
- $taskCard->uid = $cid;
- $req->userInfo->game->store->taskcards->$cid = $taskCard;
- 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 (isset($yanlingVo->herouid) && $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();
- // $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();
- // $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>
- //
- }
|