StoreProc.php 44 KB

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