StoreProc.php 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace loyalsoft;
  8. /**
  9. * Description of StoreProc
  10. *
  11. * @author c'y'zhao
  12. */
  13. class StoreProc {
  14. /**
  15. * 逻辑分发
  16. * 所有的Proc中必须有这样一个方法
  17. * @param Req $req
  18. */
  19. public static function procMain($req) {
  20. switch ($req->cmd) {
  21. case CmdCode::cmd_store_put: # 6401 放入仓库
  22. return StoreProc::AddItemInStore();
  23. case CmdCode::cmd_store_gemSet: # 6402 装备宝石
  24. return StoreProc::GemSet();
  25. case CmdCode::cmd_store_gemRemove: # 6403 卸下装备宝石
  26. return StoreProc::GemRemove();
  27. case CmdCode::cmd_store_equipUpgrade: # 6404 装备升级
  28. return StoreProc::EquipUpgrade();
  29. case CmdCode::cmd_store_equipUpgrade_MaxLv: # 6405 一键升级(装备)
  30. return StoreProc::EquipUpgrade_MaxLv();
  31. case CmdCode::store_gemCompose: # 6406 宝石合成
  32. return StoreProc::GemCompose();
  33. case CmdCode::store_switchEquipPag: # 6408 切换装备分页
  34. return StoreProc::SwitchEquipPag();
  35. case CmdCode::store_gemLockState: # 6409 宝石开锁解锁
  36. return StoreProc::GemLockState();
  37. case CmdCode::store_equip_removeEquipUpgradeTip: # 6410 移除装备可以升级绿点提示 -------废弃
  38. return StoreProc::RemoveEquipUpgradeTip();
  39. case CmdCode::store_equip_removeNewGemTip: # 6411 移除是新宝石绿点提示
  40. return StoreProc::RemoveNewGemTip();
  41. case CmdCode::store_allEquipUpgrade: # 6412 所有装备的一键升级-----------废弃
  42. return StoreProc::AllEquipUpgrade();
  43. case CmdCode::store_gemXiLian: # 6413 洗练
  44. return StoreProc::GemXiLian();
  45. case CmdCode::store_equiped: # 6413 装备
  46. return StoreProc::Equiped();
  47. case CmdCode::store_remove_equip: # 6413 卸下装备
  48. return StoreProc::RemoveEquip();
  49. case CmdCode::store_equip_gemSlotBuy: # 6416 购买装备宝石槽
  50. return StoreProc::Gem_BuySlot();
  51. default:
  52. Err(ErrCode::cmd_err);
  53. }
  54. }
  55. /**
  56. * 6416 购买装备宝石槽
  57. * @return type
  58. */
  59. public static function Gem_BuySlot() {
  60. list($uid) = req()->paras;
  61. $equipDic = ctx()->store->equip;
  62. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  63. $ins_equip = new Ins_Equip($equipDic->$uid);
  64. $mo = GameConfig::gem_slotposition_getItem($ins_equip->mo()->qual);
  65. my_Assert(null != $mo, ErrCode::err_const_no);
  66. $initNum = $mo->initNum_slot;
  67. $buyNum = $mo->buyNum_slot;
  68. $unlockIndex = 0;
  69. if ($buyNum > 0) {
  70. for ($i = $initNum + 1; $i <= $initNum + $buyNum; $i++) {
  71. if (!StlUtil::dictHasProperty($ins_equip->gemSetSlot, $i)) {
  72. $ins_equip->gemSetSlot->$i = 0;
  73. break;
  74. }
  75. $unlockIndex += 1;
  76. }
  77. }
  78. $costArr = explode(';', $mo->cost);
  79. $cash = explode(',', $costArr[$unlockIndex]);
  80. my_Assert(ctx()->base(true)->cash >= $cash[1], ErrCode::notenough_cash_msg);
  81. ctx()->base(true)->Consume_Cash($unlockIndex);
  82. ctx()->store(true)->equip->$uid = $ins_equip;
  83. UserProc::updateUserInfo();
  84. return Resp::ok(array(
  85. 'cash' => ctx()->baseInfo->cash,
  86. 'store' => ctx()->store,
  87. ));
  88. }
  89. /**
  90. * 6413 装备
  91. * @return type
  92. */
  93. public static function Equiped() {
  94. list($uid) = req()->paras;
  95. $equipDic = ctx()->store->equip;
  96. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  97. $ins_equip = new Ins_Equip($equipDic->$uid);
  98. $posId = $ins_equip->mo()->position;
  99. ctx()->store(true)->equipLocation->$posId = $uid;
  100. UserProc::updateUserInfo();
  101. return Resp::ok(array());
  102. }
  103. /**
  104. * 6413 卸下装备
  105. * @return type
  106. */
  107. public static function RemoveEquip() {
  108. list($uid) = req()->paras;
  109. $equipDic = ctx()->store->equip;
  110. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  111. $ins_equip = new Ins_Equip($equipDic->$uid);
  112. $posId = $ins_equip->mo()->position;
  113. StlUtil::dictRemove(ctx()->store(true)->equipLocation, $posId);
  114. UserProc::updateUserInfo();
  115. return Resp::ok(array());
  116. }
  117. /**
  118. * 洗练
  119. * @return Resp
  120. */
  121. public static function GemXiLian() {
  122. list($uid) = req()->paras;
  123. //把 qual pos u一样的宝石开锁关锁
  124. $gemStore = ctx()->store->gemStore;
  125. my_Assert(StlUtil::dictHasProperty($gemStore, $uid), ErrCode::user_store_NotExistGem);
  126. $gem = new Ins_Gem($gemStore->$uid);
  127. my_Assert($gem->mo()->qual >= 5, ErrCode::user_store_XilianStoneNoEnough);
  128. $arr = explode(';', glc()->XILianGemlNeedXILianStone);
  129. $needStone = 0;
  130. $xilianStoneId = 0;
  131. foreach ($arr as $val) {
  132. $str = explode(':', $val);
  133. if ($str[0] == $gem->mo()->qual) {
  134. $s = explode(',', $str[1]);
  135. $needStone = $s[1];
  136. $xilianStoneId = $s[0];
  137. break;
  138. }
  139. }
  140. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $xilianStoneId) && ctx()->store->items->$xilianStoneId >= $needStone, ErrCode::user_store_XilianStoneNoEnough);
  141. $dic = GameConfig::predicate();
  142. $pList = array();
  143. foreach ($dic as $id => $pMo) {
  144. if ($pMo->positions != null && $pMo->qual != null) {
  145. $list = explode(',', $pMo->positions);
  146. if ($pMo->id != $gem->predicateId && $pMo->qual == $gem->mo()->qual && in_array($gem->mo()->position, $list) && $pMo->attachTarget == "gem") {
  147. $pList[] = $pMo->id;
  148. }
  149. }
  150. }
  151. my_Assert(count($pList) > 0, ErrCode::user_store_NoFindPredicate);
  152. $rand = random_int(0, count($pList) - 1);
  153. $pId = $pList[$rand];
  154. ctx()->store->gemStore->$uid->predicateId = $pId;
  155. ctx()->store->removeItem($xilianStoneId, $needStone);
  156. $xilianStoneNum = 0;
  157. if (StlUtil::dictHasProperty(ctx()->store->items, $xilianStoneId)) {
  158. $xilianStoneNum = ctx()->store->items->$xilianStoneId;
  159. }
  160. UserProc::updateUserInfo();
  161. return Resp::ok(array(
  162. 'xilianStoneId' => $xilianStoneId,
  163. 'xilianStone' => $xilianStoneNum,
  164. 'predicateId' => $pId,
  165. ));
  166. }
  167. /**
  168. * 宝石开锁解锁
  169. * @return Resp
  170. */
  171. public static function GemLockState() {
  172. list($uid) = req()->paras;
  173. $user = ctx();
  174. //把 qual pos u一样的宝石开锁关锁
  175. $gemStore = $user->store->gemStore;
  176. $gem = $gemStore->$uid;
  177. $tag = 0;
  178. if ($gem->isUnlock == 0) {
  179. $gem->isUnlock = 1;
  180. $tag = 1;
  181. } else {
  182. $gem->isUnlock = 0;
  183. $tag = 0;
  184. }
  185. $gemStore->$uid = $gem;
  186. foreach ($gemStore as $k => $ins_gem) {
  187. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  188. $gemStore->$k->isUnlock = $tag;
  189. }
  190. }
  191. $user->store->gemStore = $gemStore;
  192. ctx($user);
  193. UserProc::updateUserInfo();
  194. return Resp::ok(array(
  195. 'gold' => 0,
  196. 'store' => $user->store,
  197. ));
  198. }
  199. /**
  200. * 切换装备分页
  201. * @return Resp
  202. */
  203. public static function SwitchEquipPag() {
  204. list($index) = req()->paras;
  205. $user = ctx();
  206. $user->store->equipPag = $index;
  207. ctx($user);
  208. UserProc::updateUserInfo();
  209. return Resp::ok(array());
  210. }
  211. /**
  212. * 所有装备的一键升级
  213. * 规则:等级不同从等级小到大,等级一样按照部位顺序
  214. *
  215. * @return Resp
  216. */
  217. public static function AllEquipUpgrade() {
  218. //list() = req()->paras;
  219. //$user = ctx();
  220. // $equipDic = $user->store->equipPosition;
  221. //
  222. // $equip_levelDic = GameConfig::equip_levelupgrade();
  223. // $maxLv = count(StlUtil::dictToArray($equip_levelDic));
  224. // $arr = array();
  225. // if ($equipDic != null) {
  226. // foreach ($equipDic as $k => &$equip) {
  227. // $equip = new Ins_EquipPosition($equip);
  228. //
  229. // if ($equip->level >= $maxLv) {
  230. // continue;
  231. // }
  232. //
  233. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  234. // $needGold = $lvMo->needGold;
  235. // $needItemNum = $lvMo->needItemNum;
  236. // $neeItemId = $equip->mo()->costTuzhiId;
  237. //
  238. // if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  239. // $arr[] = $equip;
  240. // }
  241. // }
  242. // }
  243. // $upLevelArr = array();
  244. // if (count($arr) > 0) {
  245. // //进行排序
  246. // $len = count($arr);
  247. // for ($i = 0; $i < $len - 1; $i++) {
  248. // for ($j = 0; $j < $len - $i - 1; $j++) {
  249. // if ($arr[$j]->level > $arr[$j + 1]->level) {//从小到大
  250. // $temp = $arr[$j];
  251. // $arr[$j] = $arr[$j + 1];
  252. // $arr[$j + 1] = $temp;
  253. // } elseif ($arr[$j]->level == $arr[$j + 1]->level) {
  254. // $j_equip = new Ins_EquipPosition($arr[$j]);
  255. // $jj_equip = new Ins_EquipPosition($arr[$j + 1]);
  256. // if ($j_equip->mo()->position > $jj_equip->mo()->position) {
  257. // $temp = $arr[$j];
  258. // $arr[$j] = $arr[$j + 1];
  259. // $arr[$j + 1] = $temp;
  260. // }
  261. // }
  262. // }
  263. // }
  264. //升级,扣除金币和图纸
  265. // while (true) {
  266. // $tag = 9999;
  267. // foreach ($arr as $index => &$equip) {
  268. // $ins_equip = new Ins_EquipPosition($equip);
  269. // $lvMo = GameConfig::equip_levelupgrade_getItem($ins_equip->level);
  270. // $needGold = $lvMo->needGold;
  271. // $needItemNum = $lvMo->needItemNum;
  272. // $neeItemId = $ins_equip->mo()->costTuzhiId;
  273. // if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  274. // $id = $ins_equip->typeId;
  275. // if (!in_array($id, $upLevelArr)) {
  276. // $upLevelArr[] = $id;
  277. // }
  278. //
  279. // $ins_equip->level += 1;
  280. // $equipDic->$id->level += 1;
  281. // $user->baseInfo->Consume_Gold($needGold);
  282. // $user->store->removeItem($neeItemId, $needItemNum);
  283. // if ($ins_equip->level >= 99) {
  284. // $tag = $index;
  285. // break;
  286. // }
  287. // } else {
  288. // $tag = $index;
  289. // break;
  290. // }
  291. // }
  292. // if ($tag != 9999) {
  293. // if (array_key_exists($tag, $arr)) {
  294. // StlUtil::arrayRemoveAt($arr, $tag);
  295. // }
  296. // }
  297. //
  298. // if (count($arr) <= 0) {
  299. // break;
  300. // }
  301. // }
  302. // }
  303. // TaskProc::OnAnyEquipUpLevel_X();
  304. // TaskProc::OnAllEquipUpLevel_X();
  305. // TaskProc::OnEquipLevelUpNum();
  306. // ctx($user);
  307. //
  308. // FightProc::Ranking_FightPower();
  309. UserProc::updateUserInfo();
  310. return Resp::ok(array(
  311. 'upLevelArr' => $upLevelArr,
  312. 'gold' => $user->baseInfo->gold,
  313. 'store' => $user->store,
  314. 'task' => $user->task,
  315. ));
  316. }
  317. /**
  318. * 6411 移除是新宝石绿点提示
  319. * @return Resp
  320. */
  321. public static function RemoveNewGemTip() {
  322. list($uid) = req()->paras; //宝石uid
  323. my_Assert(StlUtil::dictHasProperty(ctx()->store->gemStore, $uid), ErrCode::user_store_NoItem);
  324. ctx()->store(true)->gemStore->$uid->isNew = 0;
  325. UserProc::updateUserInfo();
  326. return Resp::ok(array());
  327. }
  328. /**
  329. * 移除装备可以升级绿点提示 -------废弃
  330. * @return Resp
  331. */
  332. public static function RemoveEquipUpgradeTip() {
  333. // list($posId) = req()->paras; //装备部位
  334. // $user = ctx();
  335. //
  336. // my_Assert(StlUtil::dictHasProperty($user->store->equipPosition, $posId), ErrCode::user_store_NoEquip);
  337. //
  338. // $user->store->equipPosition->$posId->tip = 0;
  339. //
  340. // ctx($user);
  341. // UserProc::updateUserInfo();
  342. // return Resp::ok(array(
  343. // 'gold' => 0,
  344. // 'store' => $user->store,));
  345. }
  346. /**
  347. * 6406 合成
  348. * @return type
  349. */
  350. public static function GemCompose() {
  351. list($gemIds) = req()->paras;
  352. $list = explode(';', $gemIds);
  353. $gemStore = ctx()->store->gemStore;
  354. $composeArr = array();
  355. foreach ($list as $gems) {
  356. $gemArr = explode('-', $gems);
  357. $length1 = strlen($gemArr[0]);
  358. $length2 = strlen($gemArr[1]);
  359. $gem_composeCost = explode(',', substr($gemArr[0], 1, $length1 - 1)); //去掉逗号
  360. $gem_composeIds = explode(',', substr($gemArr[1], 1, $length2 - 1)); //去掉逗号
  361. $gemMo = GameConfig::gem_getItem($gem_composeIds[0]);
  362. my_Assert(null != $gemMo, ErrCode::err_const_no);
  363. $isCompose = true;
  364. foreach ($gem_composeCost as $gemUid) {
  365. if (!StlUtil::dictHasProperty($gemStore, $gemUid)) {
  366. $isCompose = false;
  367. break;
  368. }
  369. $ins_gem = new Ins_Gem($gemStore->$gemUid);
  370. if ($ins_gem->mo()->qual + 1 != $gemMo->qual || $ins_gem->mo()->position == $gemMo->position) {
  371. $isCompose = false;
  372. break;
  373. }
  374. if(!self::GemIsCanCompose($gemUid)){
  375. $isCompose = false;
  376. break;
  377. }
  378. }
  379. my_Assert($isCompose == true, ErrCode::user_store_GemCanotCompose);
  380. foreach ($gem_composeCost as $gemUid) {
  381. self::RemoveGemInStore($gemUid);
  382. }
  383. foreach ($gem_composeIds as $gemTypeId) {
  384. $composeGem = self::initGem($gemTypeId);
  385. self::PutGemInStore($composeGem);
  386. $composeArr[] = $composeGem->uid; //临时放这
  387. }
  388. }
  389. TaskProc::OnComposeNumGem();
  390. TaskProc::OnComposeNumGem_state();
  391. UserProc::updateUserInfo();
  392. return Resp::ok(array(
  393. 'composeGemIds' => $composeArr,
  394. 'store' => ctx()->store,
  395. 'task' => ctx()->task,
  396. ));
  397. }
  398. /**
  399. * 该宝石是否可以参与合成,其他页镶嵌的,已经被锁的都不能参与
  400. * @param type $uid
  401. * @return bool
  402. */
  403. private static function GemIsCanCompose($uid) {
  404. $ins_gem = new Ins_Gem($uid);
  405. if($ins_gem->isUnlock == 1){
  406. return false;
  407. }
  408. $isExist = true;
  409. $equip = ctx()->store->equip;
  410. foreach ($equip as $uid => $item) {
  411. $arr = get_object_vars($item->gemSetSlot);
  412. $values = array_values($arr);
  413. if(in_array($uid, $values)){
  414. $isExist = false;
  415. break;
  416. }
  417. }
  418. return $isExist;
  419. }
  420. /**
  421. * 装备宝石
  422. * @return type
  423. */
  424. public static function GemSet() {
  425. list($equipUid, $uid, $type, $replaceUId) = req()->paras; //宝石uid 手动的时候记得校验u $replaceUId宝石槽坑位id
  426. my_Assert(StlUtil::dictHasProperty(ctx()->store->gemStore, $uid), ErrCode::user_store_NoItem);
  427. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $equipUid), ErrCode::user_store_NoEquip);
  428. $ins_equip = new Ins_Equip(ctx()->store->equip->$equipUid);
  429. $ins_gem = new Ins_Gem(ctx()->store->gemStore->$uid);
  430. my_Assert($ins_equip->mo()->position == $ins_gem->mo()->qual, ErrCode::user_store_PositionNotFit);
  431. $gemSetSlotDic = $ins_equip->gemSetSlot;
  432. $tag_index = 0;
  433. $tag_gem = null;
  434. foreach ($gemSetSlotDic as $slotId => $gemUid) {
  435. $gem = new Ins_Gem(ctx()->store->gemStore->$gemUid);
  436. if ($gem->predicateMo()->uniqueKey == $ins_gem->predicateMo()->uniqueKey) {
  437. $tag_index = $slotId;
  438. $tag_gem = $gem;
  439. break;
  440. }
  441. }
  442. $mo = GameConfig::gem_slotposition_getItem($ins_equip->mo()->qual);
  443. my_Assert(null != $mo, ErrCode::err_const_no);
  444. switch ($type) {
  445. case 1://镶嵌
  446. my_Assert($tag_gem == null, ErrCode::user_store_GemCanotSet);
  447. for ($i = 1; $i <= $mo->initNum_slot + $mo->buyNum_slot; $i++) {
  448. if (!StlUtil::dictHasProperty($gemSetSlotDic, $i)) {
  449. $gemSetSlotDic->$i = $ins_gem;
  450. break;
  451. }
  452. }
  453. break;
  454. case 2://替换
  455. //满不满都高替低品阶
  456. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  457. $gUid = $gemSetSlotDic->$replaceUId;
  458. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid); //这个$replaceUId是坑位的index id
  459. my_Assert($replace_ins_Gem->mo()->qual < $ins_gem->mo()->qual, ErrCode::user_store_NoExistGemReplace);
  460. $gemSetSlotDic->$replaceUId = $ins_gem;
  461. break;
  462. case 3://手动
  463. my_Assert(count((array) $gemSetSlotDic) >= $mo->initNum_slot + $mo->buyNum_slot, ErrCode::user_store_GemCanotSet);
  464. $gUid = $gemSetSlotDic->$replaceUId;
  465. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  466. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid);
  467. //$id = $replace_ins_Gem->uid;
  468. if ($tag_gem != null) {//如果有u那
  469. my_Assert($replace_ins_Gem->uid == $tag_gem->uid, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  470. //有U一样的,则点击正好是这个直接替换
  471. //$user->store->gemStore->$id = $replace_ins_Gem;
  472. $gemSetSlotDic->$tag_index = $ins_gem;
  473. } else {
  474. $go_index = 0;
  475. foreach ($gemSetSlotDic as $slotId => $gUid) {
  476. if ($gUid == $replaceUId) {
  477. $go_index = $slotId;
  478. break;
  479. }
  480. }
  481. my_Assert($go_index > 0, ErrCode::user_store_NoExistGemReplace);
  482. $gemSetSlotDic->$go_index = $ins_gem;
  483. }
  484. break;
  485. case 4://不能
  486. //1.小品阶替大品阶 或是 相等的,在不满的时候不允许 2. //满的 相等不允许替
  487. my_Assert($uid == 0, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  488. break;
  489. default:
  490. break;
  491. }
  492. $ins_equip->gemSetSlot = $gemSetSlotDic;
  493. ctx()->store(true)->equip->$equipUid = $ins_equip;
  494. TaskProc::OnSetSpecialQualGem();
  495. FightProc::Ranking_FightPower();
  496. UserProc::updateUserInfo();
  497. return Resp::ok(array(
  498. 'gold' => 0,
  499. 'store' => ctx()->store,
  500. 'task' => ctx()->task,
  501. ));
  502. }
  503. /**
  504. * 卸下装备
  505. * @return type
  506. */
  507. public static function GemRemove() {
  508. list($uid) = req()->paras; //装备宝石id
  509. $equips = ctx()->store->equip;
  510. foreach ($equips as $eUid => $ins_equip) {
  511. $dic = $ins_equip->gemSetSlot;
  512. foreach ($dic as $slotId => $gemUid) {
  513. if ($uid == $gemUid) {
  514. ctx()->store->equip->$eUid->gemSetSlot->$slotId = 0;
  515. }
  516. break 2;
  517. }
  518. }
  519. FightProc::Ranking_FightPower();
  520. UserProc::updateUserInfo();
  521. return Resp::ok(array(
  522. 'gold' => 0,
  523. 'store' => ctx()->store,));
  524. }
  525. /**
  526. * 6404 升级装备
  527. * @return type
  528. */
  529. public static function EquipUpgrade() {
  530. list($uid) = req()->paras; //装备uid
  531. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  532. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  533. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_equipLevelLimit);
  534. $mo = GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->mo()->qual, $ins_equip->mo()->position, $ins_equip->level);
  535. my_Assert(null != $mo, ErrCode::err_const_no);
  536. my_Assert(ctx()->baseInfo->gold >= $mo->needGold, ErrCode::notenough_gold_msg);
  537. $costTuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  538. $tuzhiNum = 0;
  539. if (StlUtil::dictHasProperty(ctx()->store->items, $costTuzhiId)) {
  540. $tuzhiNum = ctx()->store->items->$costTuzhiId;
  541. }
  542. my_Assert($tuzhiNum >= $mo->needItemNum, ErrCode::notenough_item);
  543. ctx()->store(true)->removeItem($costTuzhiId, $mo->needItemNum);
  544. ctx()->base(true)->Consume_Gold($mo->needGold);
  545. TaskProc::OnAnyEquipUpLevel_X();
  546. TaskProc::OnAllEquipUpLevel_X();
  547. TaskProc::OnEquipLevelUpNum();
  548. FightProc::Ranking_FightPower();
  549. UserProc::updateUserInfo();
  550. return Resp::ok(array(
  551. 'gold' => $user->baseInfo->gold,
  552. 'store' => $user->store,
  553. 'task' => $user->task,
  554. ));
  555. }
  556. /**
  557. * 6405 单个装备部位一键升级
  558. * @return type
  559. */
  560. public static function EquipUpgrade_MaxLv() {
  561. list($uid) = req()->paras;
  562. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  563. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  564. $maxLevel = $ins_equip->Equip_MaxLevel();
  565. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_equipLevelLimit);
  566. $tuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  567. $itemNum_store = 0;
  568. if (StlUtil::dictHasProperty(ctx()->store->items, $tuzhiId)) {
  569. $itemNum_store = ctx()->store->items->$tuzhiId;
  570. }
  571. $up_Gold = 0;
  572. $up_needItem = 0;
  573. $up_lv = 0;
  574. $noUp_gold = false;
  575. $noUp_item = false;
  576. for ($i = $ins_equip->level; $i <= $maxLevel; $i++) {
  577. $up_Gold += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->mo()->qual, $ins_equip->mo()->position, $i)->needGold;
  578. $up_needItem += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->mo()->qual, $ins_equip->mo()->position, $i)->needItemNum;
  579. if (ctx()->baseInfo->gold >= $up_Gold) {
  580. $noUp_gold = true;
  581. }
  582. if ($itemNum_store >= $up_needItem) {
  583. $noUp_item = true;
  584. }
  585. if (ctx()->baseInfo->gold >= $up_Gold && $itemNum_store >= $up_needItem) {
  586. //$need_gold = $up_Gold;
  587. //$need_item = $up_needItem;
  588. $up_lv = $i;
  589. continue;
  590. }
  591. break;
  592. }
  593. if ($up_lv == 0) {
  594. my_Assert($noUp_gold, ErrCode::notenough_gold_msg);
  595. my_Assert($noUp_item, ErrCode::notenough_item);
  596. }
  597. ctx()->base(true)->Consume_Gold($up_Gold);
  598. ctx()->store(true)->removeItem($tuzhiId, $up_needItem);
  599. if ($up_lv > 0) {
  600. ctx()->store->equip->$uid->level = $up_lv;
  601. }
  602. TaskProc::OnAnyEquipUpLevel_X();
  603. TaskProc::OnAllEquipUpLevel_X();
  604. TaskProc::OnEquipLevelUpNum();
  605. FightProc::Ranking_FightPower();
  606. UserProc::updateUserInfo();
  607. return Resp::ok(array(
  608. 'gold' => ctx()->baseInfo->gold,
  609. 'store' => ctx()->store,
  610. 'task' => ctx()->task,
  611. ));
  612. }
  613. public static function AddItemInStore() {
  614. list($rwdStr) = req()->paras; //mask = 1:表示战斗中掉落
  615. $user = ctx();
  616. $err = self::AddMultiItemInStore($rwdStr);
  617. my_Assert(ErrCode::ok == $err, $err);
  618. UserProc::updateUserInfo();
  619. return Resp::ok(array(
  620. //'gold' => $user->baseInfo->gold,
  621. //'tili' => $user->baseInfo->tili,
  622. //'cash' => $user->baseInfo->cash,
  623. 'store' => $user->store));
  624. }
  625. static $reward = array();
  626. static $reward_Gem = array();
  627. //static $reward_hero = array();
  628. /**
  629. * 具体奖励存入背包
  630. * @param type $goodsStr
  631. * @param type $src
  632. */
  633. public static function AddMultiItemInStore($goodsStr, $src = 0) {
  634. if ($goodsStr == null) {
  635. return;
  636. }
  637. $ary = explode(";", $goodsStr);
  638. foreach ($ary as $value) {
  639. $val = explode(",", $value);
  640. my_Assert(count($val) > 1, "解析奖励字符串出错");
  641. list($itemId, $num) = $val; # ID, 数量
  642. $itemMo = GameConfig::item_getItem($itemId);
  643. if ($itemMo->itemType != 701 && $itemMo->itemType != 201 && $itemMo->itemType != 502 && $src != 1) {
  644. self::$reward[] = $value;
  645. }
  646. switch ($itemMo->itemType) {
  647. case 1:
  648. ctx()->baseInfo->Add_Gold($num);
  649. //self::checkEquipUpgradeTip();//废弃
  650. break;
  651. case 2:
  652. ctx()->baseInfo->Add_Cash($num);
  653. break;
  654. case 3:
  655. ctx()->baseInfo->Add_tili($num);
  656. break;
  657. case 4:
  658. ctx()->baseInfo->Add_Exp($num);
  659. break;
  660. case 100://图纸
  661. case 103://钥匙
  662. case 401://启灵石
  663. case 301://洗练石
  664. case 501://人物碎片
  665. case 601://人身果
  666. case 801://寻宝券
  667. self::PutItemsInStore($itemId, $num);
  668. // if ($itemMo->itemType == 100) {//图纸
  669. // self::checkEquipUpgradeTip();//废弃
  670. // }
  671. break;
  672. case 502://角色卡
  673. HeroProc::RoleCardUnlockHero($itemId, $num);
  674. break;
  675. case 201://宝石
  676. for ($i = 0; $i < $num; $i++) {
  677. $gem = self::initGem($itemId);
  678. if ($src != 1) {
  679. self::$reward_Gem[] = $gem->uid;
  680. }
  681. self::PutGemInStore($gem);
  682. if ($src == Enum_StoreSourceType::ShopBox) {
  683. SystemProc::GetGem_GreaterOrangeQual_ShopBox(req()->zoneid, ctx()->baseInfo->name, $gem->typeId);
  684. }
  685. }
  686. break;
  687. case 701://道具宝箱
  688. for ($i = 0; $i < $num; $i++) {
  689. self::DistributeItemsBox($itemId);
  690. }
  691. break;
  692. default:
  693. break;
  694. }
  695. }
  696. }
  697. public static function PutItemsInStore($itemId, $num) {
  698. $items = ctx()->store->items;
  699. if (StlUtil::dictHasProperty($items, $itemId)) {
  700. $items->$itemId += $num;
  701. } else {
  702. $items->$itemId = $num;
  703. }
  704. ctx()->store->items = $items;
  705. }
  706. /**
  707. * 拆分宝箱盒子
  708. * @param type $reward
  709. */
  710. public static function DistributeItemsBox($itemId) {
  711. $itemBoxMo = GameConfig::item_2023_box_getItem($itemId);
  712. my_Assert($itemBoxMo != null, ErrCode::err_const_no);
  713. if ($itemBoxMo->type == 1) {
  714. $strList = explode(';', $itemBoxMo->contents);
  715. $numList = explode('-', $strList[0]);
  716. $randNum = rand($numList[0], $numList[1]);
  717. $ctxList = explode(',', $strList[1]);
  718. $per = 0;
  719. foreach ($ctxList as $value) {
  720. $ctx = explode(':', $value);
  721. $per += $ctx[1];
  722. }
  723. $reward = "";
  724. for ($i = 0; $i < $randNum; $i++) {
  725. $ctxPer = rand(1, $per);
  726. $start = 0;
  727. $end = 0;
  728. $id = 0;
  729. foreach ($ctxList as $value) {
  730. $ctx = explode(':', $value);
  731. $end += $ctx[1];
  732. if ($ctxPer > $start && $ctxPer <= $end) {
  733. $id = $ctx[0];
  734. break;
  735. }
  736. $start = $end;
  737. }
  738. if ($id != 0) {
  739. $str = $id . ',1';
  740. if ($reward == "") {
  741. $reward = $str;
  742. } else {
  743. $reward = $reward . ';' . $str;
  744. }
  745. }
  746. }
  747. self::AddMultiItemInStore($reward);
  748. } else {
  749. self::AddMultiItemInStore($itemBoxMo->contents);
  750. }
  751. }
  752. // public static function PutEquipInStore($equipId, $num) {
  753. // if ($equipId == 0) {
  754. // return;
  755. // }
  756. // $n = count((array) ctx()->store->equip) + 1;
  757. //
  758. // for ($index = 0; $index < $num; $index++) {
  759. // $Equip = new Ins_Equip();
  760. // $Equip->uid = $n;
  761. // $Equip->typeId = $equipId;
  762. // $Equip->qual = GameConfig::equip_getItem($equipId)->qual;
  763. // ctx()->store->equip->$n = $Equip;
  764. // $n += 1;
  765. // }
  766. // }
  767. /**
  768. * 得到金币或是图纸的时候校验下,是否满足装备升级条件,满足则tip字段设置为1 废弃
  769. */
  770. // public static function checkEquipUpgradeTip() {
  771. // $equipDic = ctx()->store->equipPosition;
  772. // if ($equipDic != null) {
  773. // foreach ($equipDic as $k => &$equip) {
  774. // $equip = new Ins_EquipPosition($equip);
  775. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  776. // $needGold = $lvMo->needGold;
  777. // $needItemNum = $lvMo->needItemNum;
  778. // $neeItemId = $equip->mo()->costTuzhiId;
  779. //
  780. // if (ctx()->baseInfo->gold >= $needGold && StlUtil::dictHasProperty(ctx()->store->items, $neeItemId) && ctx()->store->items->$neeItemId >= $needItemNum) {
  781. // $equipDic->$k->tip = 1; //绿点是每次得到金币或是图纸了,只要满足升级条件都变绿
  782. // }
  783. // }
  784. // }
  785. // ctx()->store->equipPosition = $equipDic;
  786. // }
  787. /**
  788. * 新宝石入库
  789. */
  790. public static function PutGemIdInStore($id, $num = 1) {
  791. for ($i = 0; $i < $num; $i++) {
  792. $gem = self::initGem($id);
  793. $length = $gem->uid;
  794. ctx()->store->gemStore->$length = $gem;
  795. }
  796. }
  797. public static function PutGemInStore($gem, $num = 1) {
  798. for ($i = 0; $i < $num; $i++) {
  799. $length = $gem->uid;
  800. ctx()->store->gemStore->$length = $gem;
  801. }
  802. }
  803. public static function initGem($id) {
  804. $length = ctx()->store->gemLength;
  805. $length += 1;
  806. $gem = new Ins_Gem();
  807. $gem->uid = $length;
  808. $gem->typeId = $id;
  809. $gem->predicateId = self::RandomGemPredicateId($id);
  810. $tag = self::CheckNewGemTip($gem);
  811. $gem->isNew = $tag;
  812. ctx()->store->gemLength = $length;
  813. return $gem;
  814. }
  815. /**
  816. * 从仓库移除宝石
  817. */
  818. public static function RemoveGemInStore($uid) {
  819. if (StlUtil::dictHasProperty(ctx()->store->gemStore, $uid)) {
  820. StlUtil::dictRemove(ctx()->store->gemStore, $uid);
  821. }
  822. return 0;
  823. }
  824. /**
  825. * 新宝石随机词条 临时等刚哥
  826. */
  827. public static function RandomGemPredicateId($id) {
  828. $mo = GameConfig::gem_getItem($id);
  829. my_Assert(null != $mo, "找不到宝石{$id}的配置数据");
  830. if ($mo->isfixed_predicateId == 1) {
  831. return $mo->predicateId;
  832. }
  833. $posId = $mo->position;
  834. $qual = $mo->qual;
  835. $arr = array();
  836. $predicateMo = GameConfig::predicate();
  837. foreach ($predicateMo as $key => $value) {
  838. if ($value->positions != null) {
  839. $list = explode(',', $value->positions);
  840. if ($value->qual == $qual && in_array($posId, $list) && $value->attachTarget == "gem") {
  841. $arr[] = $value->id;
  842. }
  843. }
  844. }
  845. if (count($arr) <= 0) {
  846. return 40;
  847. }
  848. my_Assert(count($arr) > 0, "宝石没有对应词条信息");
  849. $n = mt_rand(0, count($arr) - 1);
  850. return $arr[$n];
  851. //return 40;
  852. }
  853. /**
  854. * 新宝石提示
  855. */
  856. public static function CheckNewGemTip($gem) {
  857. $gemStore = ctx()->store->gemStore;
  858. $tag = false;
  859. foreach ($gemStore as $k => $ins_gem) {
  860. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  861. $tag = true;
  862. break;
  863. }
  864. }
  865. return $tag == true ? 0 : 1;
  866. }
  867. //临时代码
  868. // public static function InitGemInfo() {
  869. // if(count((array)ctx()->store->gemStore) > 0){
  870. // return;
  871. // }
  872. //
  873. // $index = 0;
  874. // $gem = GameConfig::gem();
  875. //
  876. // for ($i = 1; $i <=21; $i++) {
  877. // foreach ($gem as $key => $value) {
  878. // if($value->id == $i){
  879. // self::PutGemInStore($value->typeId);
  880. // }
  881. //
  882. // }
  883. // }
  884. //
  885. //
  886. //
  887. //
  888. // }
  889. }