StoreProc.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * Description of StoreProc
  5. * 仓库/背包 处理流程
  6. * ===========================
  7. * 尚待处理的流程:道具售出时貌似存在多种格式....
  8. * @author
  9. */
  10. class StoreProc {
  11. /**
  12. * 逻辑分发
  13. * 所有的Proc中必须有这样一个方法
  14. * @param type $req
  15. */
  16. static function procMain($req) {
  17. switch ($req->cmd) {
  18. case CmdCode::cmd_store_put: # 6401 放入仓库
  19. return StoreProc::AddItemInStore($req);
  20. case CmdCode::cmd_store_singleSell: # 6402 出售单个道具
  21. return StoreProc::sellItem($req);
  22. case CmdCode::cmd_store_mutliSell: # 6403 批量出售 卖掉
  23. return StoreProc::sellMultiItemFromStore($req);
  24. case CmdCode::cmd_store_use: # 6404 使用道具
  25. return StoreProc::useItem($req);
  26. case CmdCode::cmd_store_refresh: # 6405 获取最新的仓库数据
  27. return StoreProc::refreshStore($req);
  28. // case CmdCode::cmd_store_decomposeItem: # 6406 分解道具
  29. // return StoreProc::decomposeItem($req);
  30. case CmdCode::cmd_store_Testcmd: # 6407 测试方法
  31. return StoreProc::Test($req);
  32. // case CmdCode::cmd_store_ItemUpgrade: # 6408 装备升级
  33. // return StoreProc::ItemUpgrade($req);
  34. // case CmdCode::cmd_store_GemCompose: # 6408 装备合成
  35. // return StoreProc::composeItem($req);
  36. //
  37. case CmdCode::cmd_store_WearEquip: # 6410 给英雄穿装备
  38. return StoreProc::WearEquipToHero($req);
  39. case CmdCode::cmd_store_UnWieldEquip: # 6411 将该装备从指定英雄上脱下
  40. return StoreProc::UnWieldEquip($req);
  41. //
  42. case CmdCode::cmd_store_AddMaxPacketNum: # 6412 扩展包裹格子数量
  43. return StoreProc::AddPacketNum($req);
  44. // case CmdCode::cmd_store_MeltEquip: # 6413 装备融合
  45. // Err(ErrCode::err_method_obsoleted);
  46. //// return StoreProc::MeltEquip($req);
  47. // case CmdCode::cmd_store_PiecesCompose: # 6415 碎片合成
  48. // return StoreProc::composePieces($req);
  49. case CmdCode::cmd_store_WearYanling: # 6416 装备言灵
  50. return StoreProc::WearYanlingToHero($req);
  51. case CmdCode::cmd_store_UnWieldYanling: # 6417 卸下言灵
  52. return StoreProc::UnWieldYanling($req);
  53. case CmdCode::cmd_store_mergeYanlingbook: # 6418 利用言灵召唤书碎片合成召唤书
  54. return self::MergeYanlingBook($req);
  55. case CmdCode::cmd_store_callyanling: # 6419 利用言灵召唤书召唤言灵
  56. return self::CallYanlingByBook($req);
  57. default:
  58. Err(ErrCode::cmd_err);
  59. }
  60. }
  61. /**
  62. * [6418] 利用言灵召唤书碎片合成召唤书
  63. * @param req $req
  64. */
  65. static function MergeYanlingBook($req) {
  66. list($bookId) = $req->paras; # 参数 言灵召唤书id
  67. $user = $req->userInfo->game;
  68. $bookIdCfg = GameConfig::item_yanlingbook_getItem($bookId);
  69. my_Assert(null != $bookIdCfg, ErrCode::err_const_no); # 找不到言灵书常量
  70. list($segId, $num) = explode(',', $bookIdCfg->seg_num); # 解析所需碎片信息
  71. $err = self::removeItemFromStore($user->store, $segId, $num); # 扣除 碎片
  72. my_Assert(ErrCode::ok == $err, $err); # 防御扣除碎片失败
  73. self::PutOverlyingItemInStore($bookId); # 添加召唤书
  74. UserProc::updateUserInfo(); # 回写数据
  75. return Resp::ok(array(
  76. "store" => $req->userInfo->game->store, # # 目前来看只涉及到items变化
  77. ));
  78. }
  79. /**
  80. * [6419] 利用言灵召唤书召唤言灵
  81. * @param req $req
  82. */
  83. static function CallYanlingByBook($req) {
  84. // 参数: 言灵id
  85. // 扣除并检查召唤书数量
  86. // 扣除并检查消耗材料数量
  87. // 添加言灵
  88. // 返回 新的store->item数据
  89. list($bookId) = $req->paras; # 参数 利用的言灵召唤书id
  90. $user = $req->userInfo->game;
  91. $bookIdCfg = GameConfig::item_yanlingbook_getItem($bookId);
  92. my_Assert(null != $bookIdCfg, ErrCode::err_const_no); # 找不到言灵书常量
  93. $err = self::removeItemFromStore($user->store, $bookId); # 扣除 召唤书
  94. my_Assert(ErrCode::ok == $err, $err); # 防御扣除召唤书失败
  95. $costs = explode(';', $bookIdCfg->cost_materials);
  96. my_Assert(count($costs) > 0, ErrCode::store_book_info); # 召唤书数据有误
  97. foreach ($costs as $c) {
  98. list($itemId, $num) = explode(',', $bookIdCfg->cost_materials); # 消耗材料
  99. $err = self::removeItemFromStore($user->store, $itemId, $num); # 扣除 材料
  100. my_Assert(ErrCode::ok == $err, $err); # 防御扣除材料失败
  101. }
  102. // var_dump($req->userInfo->game->store->items);
  103. self::PutYanLingInStore($bookIdCfg->yanling_id, $req); # 添加言灵
  104. // var_dump($req->userInfo->game->store->items);
  105. UserProc::updateUserInfo(); # 回写数据
  106. return Resp::ok(array(
  107. "store" => $req->userInfo->game->store, # # 目前来看只涉及到items变化
  108. ));
  109. }
  110. /**
  111. * 测试方法
  112. * @param Req $req
  113. * @return type
  114. */
  115. static public function Test($req) {
  116. // return StoreProc::MeltEquip($req);
  117. }
  118. /**
  119. * [6404] 使用仓库道具
  120. * @param Req $req
  121. */
  122. static function useItem($req) {
  123. Err(ErrCode::msg_method_obsoleted, "代码需更新");
  124. $itemId = $req->paras[0]; # 道具id
  125. $num = 1; # 数量, 可选参数, 默认为1
  126. if (count($req->paras) > 1) { # 如果传了,
  127. $num = $req->paras[1]; # 提取可选参数: 道具数量
  128. } # end 提取参数
  129. $typeId = substr($itemId, 0, 3); # 道具分类前缀
  130. switch ($typeId) { # 使用道具()
  131. // case '701': # 宝箱
  132. // $resp = Boxes::OpenBox($req); # 调用开宝箱功能
  133. // break;
  134. default : # 其他
  135. Err(ErrCode::store_itemcantuse);
  136. break;
  137. }
  138. return $resp;
  139. }
  140. /**
  141. * [6405] 刷新仓库列表
  142. * @param Req $req
  143. */
  144. static function refreshStore($req) {
  145. StoreProc::CheckItemNum($req);
  146. return Resp::ok(array('store' => $req->userInfo->game->store));
  147. }
  148. /**
  149. * [6409] 合成道具
  150. * @param Req $req
  151. */
  152. static public function composeItem($req) {
  153. Err(ErrCode::err_method_notimplement);
  154. // list($lowitemId, $usenum, $highitemId, $addnum, $gold) = $req->paras; # 提取参数: 消耗道具id, 消耗数量, 合成道具Id, 合成数量, 需要的手续费
  155. // my_Assert($usenum >= 3, "数量非法!");
  156. // $user = $req->userInfo->game; # user引用
  157. // $store = $user->store; # 背包引用
  158. //
  159. // $ok = StoreProc::removeItemFromStore($store, $lowitemId, $usenum); # 从仓库里移除这个道具, 支持移除指定数量
  160. // my_Assert(ErrCode::ok == $ok, $ok); # 如果仓库道具移出时出错,则直接返回错误
  161. // my_Assert(UserGameModel::Consume_Gold($user, $gold), ErrCode::notenough_gold_msg); # 扣除消耗的金币
  162. //
  163. // ActiveProc::ChangeTaskCount($req); # 更新任务计数器
  164. // $store->items->$highitemId += $addnum; # 添加新合成道具
  165. // UserProc::updateUserInfo();
  166. // $ret = array('resp' => "succeed!"); # 准备返回值
  167. // $resp = Resp::ok($ret); # 返回必须是object
  168. //
  169. // StoreProc::CheckItemNum($req);
  170. // return $resp;
  171. }
  172. /**
  173. * [6409] 合成碎片(几个碎片合成获得同品质或者更高品质的新碎片)
  174. * @param Req $req
  175. */
  176. static public function composePieces($req) {
  177. Err(ErrCode::err_method_notimplement);
  178. }
  179. // </editor-fold>
  180. // --------------- 以下为辅助方法 ------------------
  181. //
  182. // <editor-fold defaultstate="collapsed" desc=" 移除物品 ">
  183. /**
  184. * 从仓库中移除指定数量的物品
  185. * @param UserGameModel $user
  186. * @param type $itemId
  187. * @param type $itemcount
  188. * @return type
  189. */
  190. static function removeItemFromStore($store, $itemId, $itemcount = 1) {
  191. if (CommUtil::isPropertyExists($store->items, $itemId)) {
  192. if ($store->items->$itemId >= $itemcount) { # 数量足够
  193. $store->items->$itemId -= $itemcount;
  194. if ($store->items->$itemId == 0) {
  195. unset($store->items->$itemId);
  196. }
  197. return ErrCode::ok;
  198. } else {
  199. return ErrCode::store_itemnotenough; # 道具数量不足
  200. }
  201. } else {
  202. return ErrCode::store_itemno_err; # 没有这个道具
  203. }
  204. }
  205. /**
  206. * 从仓库移出装备
  207. * @param type $itemId uid
  208. * @param StoreModel $store
  209. * @return boolean
  210. */
  211. static function removeEquipFromStore($uid, $typeId, &$req) {
  212. $ok = false;
  213. echo var_export($uid);
  214. if (CommUtil::isPropertyExists($req->userInfo->game->store->equipment, $uid)) {
  215. // $con= ConstProc::getItemConst($req->mem, $req->userInfo->game->store->equipment->$uid->typeId);
  216. echo var_export($req->userInfo->game->store->equipment->$uid->typeId);
  217. if ($typeId == $req->userInfo->game->store->equipment->$uid->typeId) {
  218. echo "typeid相同";
  219. unset($req->userInfo->game->store->equipment->$uid);
  220. $ok = true;
  221. } else {
  222. echo "typeid检验错误";
  223. }
  224. }
  225. return $ok;
  226. }
  227. /**
  228. * 从仓库移除碎片
  229. * @param StoreModel $store
  230. * @param int $segmentId
  231. * @param int $num
  232. * @return bool 成功/失败
  233. */
  234. static function removeSegmetFromStore($store, $segmentId, $num = 1) {
  235. if (CommUtil::isPropertyExists($store->segement, $segmentId) #
  236. && $store->segement->$segmentId >= $num) {
  237. $store->segement->$segmentId -= $num;
  238. return TRUE;
  239. }
  240. return false;
  241. }
  242. /**
  243. * 向仓库添加碎片
  244. * @param StoreModel $store
  245. * @param int $segmentId
  246. * @param int $num
  247. */
  248. static function addSegmentIntoStore($store, $segmentId, $num = 1) {
  249. if (CommUtil::isPropertyExists($store->segement, $segmentId)) {
  250. $store->segement->$segmentId += $num;
  251. } else {
  252. $store->segement->$segmentId = $num;
  253. }
  254. $segMo = GameConfig::item_segment_getItem($segmentId);
  255. my_Assert($segMo != null, ErrCode::err_const_no);
  256. TaskProc::OnHeroSegmengNum($segMo->protoHeroID, $num);
  257. }
  258. /**
  259. * 计算玩家仓库中某种符石/道具的数量
  260. * @param type $map
  261. * @param type $stoneid
  262. * @return type
  263. */
  264. static function GetStoneCount($map, $stoneid) {
  265. $ret = 0;
  266. if ($map->store->stones && CommUtil::isPropertyExists($map->store->stones, $stoneid)) {
  267. $ret = $map->store->stones->
  268. $stoneid;
  269. }
  270. return $ret;
  271. }
  272. /**
  273. * 从仓库移除符石(道具)
  274. * @param MapModel $map
  275. * @param int $stoneid
  276. * @param int $num
  277. */
  278. static function RemoveStoneFromStore(&$map, $stoneid, $num = 1) {
  279. if ($num <= 0) {
  280. return $num;
  281. }
  282. $ret = 0;
  283. if ($map->store->stones && CommUtil::isPropertyExists($map->store->stones, $stoneid)) {
  284. $left = $map->store->stones->$stoneid - $num;
  285. if ($ret >= 0) {////这里有bug吗?应该是用$left啊,不过无所谓,反正这个函数暂时用不上,不考虑了.
  286. $map->store->stones->$stoneid -= $num;
  287. $ret = $num;
  288. }
  289. }
  290. return $ret;
  291. }
  292. // </editor-fold>
  293. //
  294. // <editor-fold defaultstate="collapsed" desc=" 放入物品 ">
  295. /**
  296. * 将其他物品放入仓库
  297. * @param type $itemId
  298. * @param UserGameModel $game
  299. */
  300. static function PutItemInStore($itemId, &$game) {
  301. if (CommUtil::isPropertyExists($game->store->items, $itemId)) {// 如果仓库中已经有这种元素,则其数目+1
  302. $game->store->items->$itemId += 1;
  303. } else {// 如果仓库中没有这种元素,则其数目置1
  304. $game->store->items->$itemId = 1;
  305. }
  306. }
  307. /**
  308. * 解包多种物品到玩家身上 【警告】此函数的异常处理功能残废,不安全
  309. * 检测如果当前物品格子大于物品总数,则可以获取战利品,否则不可以
  310. * @param Req $req
  311. * @param string $goodsStr itemid,num;itemid,num;...
  312. * @param int $src 1:战斗奖励, 2: 任务奖励, 3: 抽奖奖品, 4: 邮件领取, 5: 现金充值
  313. * @deprecated since version 0
  314. * @return type
  315. */
  316. public static function AddMultiItemInStore($req, $goodsStr, $src = 1) {
  317. // var_dump($goodsStr);
  318. $user = $req->userInfo->game;
  319. $ary = explode(";", $goodsStr);
  320. // var_dump($ary);
  321. foreach ($ary as $value) {
  322. $val = explode(",", $value);
  323. // var_dump($val);
  324. my_Assert(count($val) > 1, "解析奖励字符串出错");
  325. list( $itemId, $num) = $val; # ID, 数量
  326. $smItem = GameConfig::item_base_getItem($itemId); # 道具mo
  327. switch ($smItem->subType) { # 根据类型分别添加到容器中
  328. case META_EXP: # 指挥官经验
  329. UserGameModel::Add_Exp($user->baseInfo, $num);
  330. break;
  331. case META_GOLD_ITEMID: # 金币
  332. UserGameModel::Add_Gold($user->baseInfo, $num);
  333. break;
  334. case META_CASH_ITEMID: # 钻石
  335. UserGameModel::Add_Cash($user->baseInfo, $num);
  336. break;
  337. case META_tili_ITEMID: # 体力
  338. UserGameModel::Add_tili($req, $num);
  339. break;
  340. case META_FriendShipPoit_ItemId: # 友情值
  341. UserGameModel::Add_FriendPoint($user->baseInfo, $num);
  342. break;
  343. case META_PVPCOIN_ITEMID: # 竞技币
  344. $user->pvp->pvpCoins += $num;
  345. break;
  346. case 101: # 武器
  347. StoreProc::PutEquipInStore($itemId, $req);
  348. break;
  349. case 401: # 言灵
  350. StoreProc::PutYanLingInStore($itemId, $req);
  351. break;
  352. case 201: # 碎片
  353. $segMo = GameConfig::item_segment_getItem($itemId);
  354. my_Assert($segMo != null, ErrCode::err_const_no);
  355. TaskProc::OnHeroSegmengNum($segMo->protoHeroID, $num);
  356. case 311: # 基因(经验丹)
  357. StoreProc::PutOverlyingItemInStore($itemId, $num); # 直接进包裹items
  358. break;
  359. case 341: # 战场中掉落,不会进入包裹
  360. case 342:
  361. case 343:
  362. Err(ErrCode::err_innerfault, "落入包裹时,出现了非法物品");
  363. break;
  364. default :
  365. Err(ErrCode::err_innerfault, "落入包裹时,出现了非法物品");
  366. }
  367. }
  368. return ErrCode::ok; // 返回
  369. }
  370. /**
  371. * 向包裹中添加物品
  372. * @param req $req
  373. * @return type
  374. */
  375. public static function AddItemInStore($req) {
  376. Err(ErrCode::err_innerfault, "功能待开发 -王刚 2020年1月17日14:36:01");
  377. }
  378. /**
  379. * 将装备放入背包
  380. * @param type $itemId
  381. * @param Req $req
  382. */
  383. static function PutEquipInStore($itemId, &$req) {
  384. $privateState = $req->userInfo->game->privateState;
  385. if (!CommUtil::isPropertyExists($privateState, "currentId")) { // 如果仓库中已经有这种元素,则其数目+1
  386. $req->userInfo->game->privateState->currentId = 1;
  387. }
  388. $cid = $req->userInfo->game->privateState->currentId++;
  389. $equip = ObjectInit();
  390. $equip->typeId = $itemId;
  391. $req->userInfo->game->store->equipment->$cid = $equip;
  392. return $cid;
  393. // SystemProc::GetEquip($req->zoneid, $req->userInfo->game, $itemId); # 添加获得装备的消息
  394. }
  395. /**
  396. * 将言灵放入背包
  397. * @param type $itemId
  398. * @param Req $req
  399. */
  400. static function PutYanLingInStore($itemId, &$req) {
  401. $privateState = $req->userInfo->game->privateState;
  402. if (!CommUtil::isPropertyExists($privateState, "currentId")) { // 如果仓库中已经有这种元素,则其数目+1
  403. $req->userInfo->game->privateState->currentId = 1;
  404. }
  405. $cid = $req->userInfo->game->privateState->currentId++;
  406. $equip = ObjectInit();
  407. $equip->typeId = $itemId;
  408. $req->userInfo->game->store->yanling->$cid = $equip;
  409. return $cid;
  410. // SystemProc::GetEquip($req->zoneid, $req->userInfo->game, $itemId); # 添加获得装备的消息
  411. }
  412. /**
  413. * 将可叠加物品放入背包
  414. * @param int $itemId
  415. * @param int $num
  416. */
  417. static function PutOverlyingItemInStore($itemId, $num = 1) {
  418. $items = req()->userInfo->game->store->items; # dic: itemid=>number
  419. if (CommUtil::isPropertyExists($items, $itemId)) { # 如果仓库中已经有这种元素,则其数目+=num
  420. $items->$itemId += $num;
  421. } else { # 如果仓库中没有这种元素,则其数目置为num
  422. $items->$itemId = $num;
  423. }
  424. }
  425. /**
  426. * 物品包裹打散成独立道具到仓库
  427. * @param GoodsItemModel $itemModel
  428. * @param Req $req
  429. * @return type
  430. * @deprecated since version now
  431. */
  432. static function addSeprateItem($itemModel, $req) {
  433. Err(ErrCode::err_method_obsoleted, "未更新包裹操作");
  434. }
  435. /**
  436. * [6417] 给英雄装上言灵
  437. * @param req $req
  438. * @return type
  439. */
  440. static function WearYanlingToHero($req) {
  441. $user = $req->userInfo->game; # user引用
  442. list($itemtype, $yanling_uid, $herouid) = $req->paras; # 提取参数: 装备类型, 装备的UID, 英雄的UID
  443. if (!CommUtil::isPropertyExists($user->store->yanling, $yanling_uid)) { # 检测是否存在该言灵
  444. Err(ErrCode::store_itemno_err);
  445. }
  446. $yanlingVo = $user->store->yanling->$yanling_uid; # 取言灵对象
  447. if ($yanlingVo->herouid > 0 && $yanlingVo->herouid != $herouid) { # 检测该言灵是否装备到其他英雄身上
  448. Err(ErrCode::store_equipWeared_err);
  449. }
  450. $collectHeros = $user->heros->collectHeros; # 英雄集合
  451. if (!$collectHeros) { # 防御对象为空
  452. Err(ErrCode::err_innerfault);
  453. }
  454. if (!CommUtil::isPropertyExists($collectHeros, $herouid)) { # 检查英雄是否存在
  455. Err(ErrCode::hero_no);
  456. }
  457. $user->store->yanling->$yanling_uid->herouid = $herouid; # 言灵上添加反向引用, 避免查询时的循环
  458. $oldYLid = $collectHeros->$herouid->yanling->$itemtype->itemuid; # 旧言灵id
  459. if ($oldYLid > 0) { # 代表替换操作
  460. $user->store->yanling->$oldYLid->herouid = 0; # 清理旧言灵的
  461. }
  462. $collectHeros->$herouid->yanling->$itemtype->itemuid = $yanling_uid; # 英雄身上添加言灵记录
  463. UserProc::updateUserInfo(); # 5.回写数据
  464. $ret = array('resp' => "succeed!");
  465. $resp = Resp::ok($ret); // 返回
  466. HeroProc::CalcUserFightPower($req->zoneid, $req->uid, $user); # 更新总战力榜
  467. return $resp;
  468. }
  469. /**
  470. * [6416] 给英雄卸下言灵
  471. * @param req $req
  472. * @return type
  473. * @deprecated since version 无法卸下,只能更换
  474. */
  475. static function UnWieldYanling($req) {
  476. $user = $req->userInfo->game; # user引用
  477. list($itemtype, $yanling_uid, $herouid) = $req->paras; # 提取参数: 装备类型, 装备的UID, 拥有该装备的英雄的UID
  478. $collectHeros = $user->heros->collectHeros;
  479. my_Assert(null != $collectHeros, ErrCode::err_innerfault); # 防御
  480. my_Assert(CommUtil::isPropertyExists($collectHeros, $herouid), ErrCode::hero_no); # 检测是否存在拥有该装备的英雄
  481. my_Assert(CommUtil::isPropertyExists($user->store->yanling, $yanling_uid), ErrCode::store_itemno_err); # 检测是否存在该装备
  482. if ($user->store->yanling->$yanling_uid->herouid == $herouid) { # 取装备对象
  483. $user->store->yanling->$yanling_uid->herouid = 0; # 清理反向引用
  484. }
  485. my_Assert($collectHeros->$herouid->yanling->$itemtype->itemuid == $yanling_uid, ErrCode::store_noequip_err); # 防御
  486. $collectHeros->$herouid->yanling->$itemtype->itemuid = 0; # 卸下
  487. UserProc::updateUserInfo(); # 回写数据
  488. $resp = Resp::ok(array('resp' => "succeed!")); // 返回
  489. // StoreProc::CheckItemNum($req);
  490. return $resp;
  491. }
  492. /**
  493. * [6410] 给英雄穿装备
  494. * @param req $req
  495. * @return type
  496. */
  497. static function WearEquipToHero($req) {
  498. list($itemtype, $equipuid, $herouid) = $req->paras; # 提取参数: 装备类型, 装备的UID, 英雄的UID
  499. $user = $req->userInfo->game; # user引用
  500. my_Assert(CommUtil::isPropertyExists($user->store->equipment, $equipuid), ErrCode::store_itemno_err); # 检测是否存在该装备
  501. $equipVo = $user->store->equipment->$equipuid; # 取装备对象
  502. if ($equipVo->herouid > 0) { # 检测该装备是否装备到其他英雄身上
  503. my_Assert($equipVo->herouid == $herouid, ErrCode::store_equipWeared_err);
  504. $user->store->equipment->$equipuid->herouid = 0; # 清理原来已经装备的言灵的反指向
  505. }
  506. $collectHeros = $user->heros->collectHeros;
  507. my_default_Obj($collectHeros);
  508. my_Assert(CommUtil::isPropertyExists($collectHeros, $herouid), ErrCode::hero_no); # 检查是否存在需要装备的英雄
  509. $user->store->equipment->$equipuid->herouid = $herouid; # 装备上添加反向引用, 避免查询时的循环
  510. $oldEquipId = 0;
  511. switch ($itemtype) { # 添加或替换英雄该部位的装备
  512. case 1: # 武器
  513. $oldEquipId = $collectHeros->$herouid->equip->weapon->itemuid;
  514. $collectHeros->$herouid->equip->weapon->itemuid = $equipuid;
  515. break;
  516. case 2: # 防具
  517. $oldEquipId = $collectHeros->$herouid->equip->armor->itemuid;
  518. $collectHeros->$herouid->equip->armor->itemuid = $equipuid;
  519. break;
  520. case 3: # 饰品
  521. $oldEquipId = $collectHeros->$herouid->equip->ring->itemuid;
  522. $collectHeros->$herouid->equip->ring->itemuid = $equipuid;
  523. break;
  524. default :
  525. Err(ErrCode::store_equip_type);
  526. break;
  527. }
  528. if ($oldEquipId > 0 && $oldEquipId != $equipuid) {
  529. $user->store->equipment->$oldEquipId->herouid = 0;
  530. }
  531. UserProc::updateUserInfo(); // 5.回写数据
  532. // StoreProc::CheckItemNum($req);
  533. HeroProc::CalcUserFightPower($req->zoneid, $req->uid, $user); # 更新总战力榜
  534. return Resp::ok(array('resp' => "succeed!")); // 返回
  535. }
  536. /**
  537. * [6411] 给英雄脱装备
  538. * @deprecated since version 不能卸下装备, 只能更换.
  539. * @param req $req
  540. * @return type
  541. */
  542. static function UnWieldEquip($req) {
  543. list($itemtype, $equipuid, $herouid) = $req->paras; # 提取参数: 装备类型, 装备的UID, 拥有该装备的英雄的UID
  544. $user = $req->userInfo->game; # user引用
  545. $collectHeros = $user->heros->collectHeros;
  546. my_default_Obj($collectHeros);
  547. my_Assert(CommUtil::isPropertyExists($collectHeros, $herouid), ErrCode::hero_no); # 检测是否存在拥有该装备的英雄
  548. my_Assert(CommUtil::isPropertyExists($user->store->equipment, $equipuid), ErrCode::store_itemno_err); # 检测是否存在该装备
  549. if ($user->store->equipment->$equipuid->herouid == $herouid) { # 取装备对象
  550. $user->store->equipment->$equipuid->herouid = 0;
  551. }
  552. switch ($itemtype) { # 检测该装备是否装备在该英雄身上
  553. case 1: # 武器
  554. if ($collectHeros->$herouid->equip->weapon->itemuid != $equipuid) {
  555. Err(ErrCode::store_noequip_err);
  556. }
  557. $collectHeros->$herouid->equip->weapon->itemuid = 0; # 卸下
  558. break;
  559. case 2: # 防具
  560. if ($collectHeros->$herouid->equip->armor->itemuid != $equipuid) {
  561. Err(ErrCode::store_noequip_err);
  562. }
  563. $collectHeros->$herouid->equip->armor->itemuid = 0;
  564. break;
  565. case 3: # 饰品
  566. if ($collectHeros->$herouid->equip->ring->itemuid != $equipuid) {
  567. Err(ErrCode::store_noequip_err);
  568. }
  569. $collectHeros->$herouid->equip->ring->itemuid = 0;
  570. break;
  571. default :
  572. Err(ErrCode::store_equip_type);
  573. }
  574. UserProc::updateUserInfo(); # 回写数据
  575. // StoreProc::CheckItemNum($req);
  576. return Resp::ok(array('resp' => "succeed!")); // 返回
  577. }
  578. // </editor-fold>
  579. //
  580. // <editor-fold defaultstate="collapsed" desc=" 辅助方法 ">
  581. /**
  582. * 将宝箱放入仓库
  583. * @param StoreModel $store
  584. * @param int $boxId 宝箱类型编号
  585. * @param int $num 数量
  586. */
  587. static function putBoxexInStore($store, $boxId, $num) {
  588. Err(ErrCode::err_method_obsoleted);
  589. if (CommUtil::isPropertyExists($store->boxes, $boxId)) {
  590. $store->boxes->$boxId += $num;
  591. } else {
  592. $store->boxes->$boxId = $num;
  593. }
  594. }
  595. /**
  596. * 检查背包中物品的个数
  597. * @param req $req
  598. * @return int
  599. */
  600. public static function CheckItemNum($req) {
  601. $ItemObj = $req->userInfo->game->store->items;
  602. $EquipObj = $req->userInfo->game->store->equipment;
  603. $SegementObj = $req->userInfo->game->store->segement;
  604. $HeroObj = $req->userInfo->game->heros->collectHeros;
  605. $ItemNum = 0;
  606. ////检查宝石类可叠加物品的格子占用
  607. if ($ItemObj) {
  608. foreach ($ItemObj as $value) {
  609. $ItemNum++;
  610. }
  611. }
  612. if ($SegementObj) {
  613. foreach ($SegementObj as $value) {
  614. $ItemNum++;
  615. }
  616. }
  617. ////检测装备类物品格子占用
  618. if ($EquipObj) {
  619. foreach ($EquipObj as $value) {
  620. $ItemNum++;
  621. }
  622. }
  623. ////检测英雄装备到身上的情况,装备到英雄身上不占格子,要减去.
  624. if ($HeroObj) {
  625. foreach ($HeroObj as $value) {
  626. // echo var_dump($HeroObj);
  627. $HeroEquipId = $value->equip->weapon->itemuid;
  628. if ($HeroEquipId > 0) {
  629. $ItemNum--;
  630. }
  631. $HeroEquipId = $value->equip->armor->itemuid;
  632. if ($HeroEquipId > 0) {
  633. $ItemNum--;
  634. }
  635. $HeroEquipId = $value->equip->ring->itemuid;
  636. if ($HeroEquipId > 0) {
  637. $ItemNum--;
  638. }
  639. }
  640. }
  641. $req->userInfo->game->privateState->ItemNum = $ItemNum;
  642. return $ItemNum;
  643. }
  644. /**
  645. * 获取物品格子的上限值
  646. * @return int 上限数值
  647. */
  648. public static function GetItemMaxNum() {
  649. $user = req()->userInfo->game;
  650. if (!CommUtil::isPropertyExists($user->privateState, "maxItemNum")) {
  651. $user->privateState->maxItemNum = glc()->Item_Packet_MaxNum;
  652. }
  653. return $user->privateState->maxItemNum;
  654. }
  655. /**
  656. * 背包扩容
  657. * @param type $req
  658. * @return type
  659. */
  660. public static function AddPacketNum($req) {
  661. $user = $req->userInfo->game; # user引用
  662. if (!CommUtil::isPropertyExists($user->privateState, "maxItemNum")) {
  663. $user->privateState->maxItemNum = glc()->Item_Packet_MaxNum;
  664. }
  665. $costCash = glc()->Item_Packet_NumCostCash; # 钻石花费
  666. my_Assert($costCash > 0, ErrCode::paras_err);
  667. my_Assert(UserGameModel::Consume_Cash($user, $costCash), ErrCode::notenough_cash_msg); # 6.进行消耗
  668. $user->privateState->maxItemNum += 10; # 扩容
  669. UserProc::updateUserInfo(); # 保存玩家数据
  670. $resp = Resp::ok(array('maxItemNum' => $user->privateState->maxItemNum)); # 返回值
  671. StoreProc::CheckItemNum($req);
  672. return $resp;
  673. }
  674. // </editor-fold>
  675. //
  676. //
  677. //
  678. // <editor-fold defaultstate="collapsed" desc=" 出售 ">
  679. //
  680. /**
  681. * 出售单一的物品
  682. * @param Req $req
  683. * @return type
  684. */
  685. static function sellItem($req) {
  686. Err(ErrCode::err_method_obsoleted, "代码需要更新");
  687. $resp = new Resp();
  688. $mem = $req->mem;
  689. // $user = $req->userInfo->user;
  690. $store = $req->userInfo->game->store; //$req->userInfo->game->store->items
  691. //客户端参数解析
  692. $type = $req->paras[0]; //1=神兽 2=建筑 //需要判断是否叠加
  693. $itemId = $req->paras[1]; // 注意:这里不是单体的id,而是物种的id
  694. if ($type > 3) {
  695. $count = intval($req->paras[2]); // 数量
  696. $uid = 0;
  697. } else {
  698. $count = 1;
  699. $uid = $req->paras[2];
  700. }//物品的uid
  701. ////0是type 1是itemid,2是uid或者是数量
  702. if ($type > 3 && $type < 8) { // 从仓库出售宝石 出售可叠加的物品
  703. $ok = StoreProc::removeItemFromStore($store, $itemId, $count); // 支持移除指定数量
  704. my_Assert($ok == ErrCode::ok, $ok); //1.如果仓库道具移出时出错,则直接返回错误
  705. // echo "弄弄";
  706. $gem = GameConfig::item_getItem($itemId); // ConstProc::getItemConst($itemId);
  707. echo var_export($gem);
  708. //2.检测是否存在该物品的原始物种
  709. if ($gem == null) {
  710. Err(ErrCode::err_godpet_noconst);
  711. }
  712. // 发金币
  713. UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $gem->maijia * $count);
  714. $ret = array('resp' => "succeed!");
  715. $resp = Resp::ok($ret);
  716. UserProc::updateUserInfo();
  717. } else if ($type == 8) { // 从仓库出售碎片 出售可叠加的物品
  718. $ok = StoreProc::removeItemFromStore($store, $itemId, $count); // 支持移除指定数量
  719. my_Assert($ok == ErrCode::ok, $ok); //1.如果仓库道具移出时出错,则直接返回错误
  720. // echo "弄弄";
  721. $gem = GameConfig::segment_getItem($itemId); // ConstProc::getItemConst($itemId);
  722. // echo var_export($gem);
  723. //2.检测是否存在该物品的原始物种
  724. if ($gem == null) {
  725. Err(ErrCode::err_godpet_noconst);
  726. }
  727. // 发金币
  728. UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $gem->saleGoldPrice * $count);
  729. $ret = array('resp' => "succeed!");
  730. $resp = Resp::ok($ret);
  731. UserProc::updateUserInfo();
  732. } else if ($type < 4 && $type > 0) { # 这里是装备
  733. if ($count > 1) {
  734. Err(ErrCode::paras_err);
  735. }
  736. if ($uid < 1) {
  737. Err(ErrCode::paras_err);
  738. }
  739. $ok = StoreProc::removeEquipFromStore($uid, $itemId, $req); # 从背包移除
  740. if (!$ok) {//1.如果背包道具移出时出错,则直接返回错误
  741. Err(ErrCode::store_removefail);
  742. }
  743. $item = GameConfig::item_getItem($itemId); // ConstProc::getItemConst($itemId);
  744. if ($item == null) { //2.检测是否存在装备的原始数据
  745. Err(ErrCode::err_const_no);
  746. }
  747. UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $item->maijia);
  748. $ret = array('resp' => "succeed!");
  749. $resp = Resp::ok($ret); //返回必须是object
  750. UserProc::updateUserInfo();
  751. } else {
  752. Err(ErrCode::paras_err);
  753. }
  754. StoreProc::CheckItemNum($req);
  755. return $resp;
  756. }
  757. /**
  758. * 卖出一堆物品时候,检测每个单个物品是否符合卖的条件
  759. * @param Req $req
  760. * @return type
  761. */
  762. static function preSellSingleFromStore(&$req, $type, $itemId, $count, $uid) {
  763. Err(ErrCode::err_method_obsoleted, "代码需要更新");
  764. $resp = new Resp();
  765. $mem = $req->mem;
  766. // $user = $req->userInfo->user;
  767. $store = $req->userInfo->game->store; //$req->userInfo->game->store->items
  768. //客户端参数解析
  769. ////0是type 1是itemid,2是uid或者是数量
  770. if ($type > 3 && $type < 8) { // 从仓库出售宝石 出售可叠加的物品
  771. echoLine(":fs::");
  772. $ok = StoreProc::removeItemFromStore($store, $itemId, $count); // 支持移除指定数量
  773. //1.如果仓库道具移出时出错,则直接返回错误
  774. my_Assert($ok == ErrCode::ok, $ok);
  775. echo "弄弄";
  776. $gem = GameConfig::item_getItem($itemId); // ConstProc::getItemConst($itemId);
  777. echo var_export($gem);
  778. //2.检测是否存在该物品的原始物种
  779. if ($gem == null) {
  780. Err(ErrCode::err_godpet_noconst);
  781. }
  782. // 发金币
  783. UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $gem->maijia * $count);
  784. $ret = array('resp' => "succeed!");
  785. $resp = Resp::ok($ret);
  786. } else if ($type == 8) { // 从仓库出售碎片 出售可叠加的物品
  787. $ok = StoreProc::removeItemFromStore($store, $itemId, $count); // 支持移除指定数量
  788. //1.如果仓库道具移出时出错,则直接返回错误
  789. my_Assert($ok == ErrCode::ok, $ok);
  790. // echo "弄弄";
  791. $gem = GameConfig::segment_getItem($itemId); // ConstProc::getItemConst($itemId);
  792. // echo var_export($gem);
  793. //2.检测是否存在该物品的原始物种
  794. if ($gem == null) {
  795. Err(ErrCode::err_godpet_noconst);
  796. }
  797. // 发金币
  798. UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $gem->saleGoldPrice * $count);
  799. $ret = array('resp' => "succeed!");
  800. $resp = Resp::ok($ret);
  801. } else if ($type < 4 && $type > 0) { # 这里是装备
  802. if ($count > 1) {
  803. Err(ErrCode::paras_err);
  804. }
  805. if ($uid < 1) {
  806. Err(ErrCode::paras_err);
  807. }
  808. $ok = StoreProc::removeEquipFromStore($uid, $itemId, $req); # 从背包移除
  809. if (!$ok) {//1.如果背包道具移出时出错,则直接返回错误
  810. Err(ErrCode::store_removefail);
  811. }
  812. $item = GameConfig::item_getItem($itemId); // ConstProc::getItemConst($itemId);
  813. if ($item == null) { //2.检测是否存在装备的原始数据
  814. Err(ErrCode::err_const_no);
  815. }
  816. UserGameModel::Add_Gold($req->userInfo->game->baseInfo, $item->maijia);
  817. $ret = array('resp' => "succeed!");
  818. $resp = Resp::ok($ret); //返回必须是object
  819. } else {
  820. Err(ErrCode::paras_err);
  821. }
  822. return $resp;
  823. }
  824. /**
  825. * 从背包出售多个物品
  826. * @param Req $req
  827. * @return type
  828. */
  829. static function sellMultiItemFromStore($req) {
  830. $resp = new Resp();
  831. $obj = $req->paras[0]; // 获取物品的结构数组
  832. foreach ($obj as $value) {
  833. $type = $value[0];
  834. $itemId = $value[1];
  835. ////先判断一下物品类型,如果是可叠加的,就按数量取值,如果是不可叠加的就按uid取值
  836. if ($type > 3) {
  837. $count = intval($value[2]); // 数量
  838. $uid = 0;
  839. } else {
  840. $count = 1;
  841. $uid = $value[2];
  842. }//物品的uid
  843. $resp = StoreProc:: preSellSingleFromStore($req, $type, $itemId, $count, $uid);
  844. }
  845. if (0 == $resp->err) {
  846. UserProc::updateUserInfo();
  847. }
  848. StoreProc::CheckItemNum($req);
  849. return $resp;
  850. }
  851. // </editor-fold>
  852. //
  853. }