StoreProc.php 38 KB

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