StoreProc.php 39 KB

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