StoreProc.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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. * 移除是新宝石绿点提示
  319. * @return Resp
  320. */
  321. public static function RemoveNewGemTip() {
  322. list($uid) = req()->paras; //宝石uid
  323. $user = ctx();
  324. my_Assert(StlUtil::dictHasProperty($user->store->gemStore, $uid), ErrCode::user_store_NoItem);
  325. //$ins_gem = new Ins_Gem($user->store->gemStore->$uid);
  326. $user->store->gemStore->$uid->isNew = 0;
  327. // $equipPag = $user->store->equipPag;
  328. $typeId = $user->store->gemStore->$uid->typeId;
  329. $mo = GameConfig::gem_getItem($typeId);
  330. my_Assert($mo != null, ErrCode::err_const_no);
  331. $position = $mo->position;
  332. $gemEquip = $user->store->gemEquip;
  333. //$tag = 0;
  334. foreach ($gemEquip as $pag => $val) {
  335. foreach ($val as $posId => $dic) {
  336. if ($posId != $position) {
  337. continue;
  338. }
  339. foreach ($dic as $index => $gem) {
  340. if ($gem->uid == $uid) {
  341. $user->store->gemEquip->$pag->$posId->$index->isNew = 0;
  342. break;
  343. }
  344. }
  345. }
  346. }
  347. ctx($user);
  348. UserProc::updateUserInfo();
  349. return Resp::ok(array(
  350. 'gold' => 0,
  351. 'store' => $user->store,));
  352. }
  353. /**
  354. * 移除装备可以升级绿点提示
  355. * @return Resp
  356. */
  357. public static function RemoveEquipUpgradeTip() {
  358. list($posId) = req()->paras; //装备部位
  359. $user = ctx();
  360. my_Assert(StlUtil::dictHasProperty($user->store->equipPosition, $posId), ErrCode::user_store_NoEquip);
  361. $user->store->equipPosition->$posId->tip = 0;
  362. ctx($user);
  363. UserProc::updateUserInfo();
  364. return Resp::ok(array(
  365. 'gold' => 0,
  366. 'store' => $user->store,));
  367. }
  368. /**
  369. * 6406 合成
  370. * @return type
  371. */
  372. public static function GemCompose() {
  373. list($gemIds) = req()->paras;
  374. $user = ctx();
  375. //做校验
  376. $composeArr = array();
  377. //$gemIds = substr($gemIds, 0, -1);
  378. $list = explode(';', $gemIds);
  379. krsort($list);
  380. foreach ($list as $str) {
  381. $str = substr($str, 0, -1);
  382. $gemUidList = explode(',', $str);
  383. $firstGemUId = $gemUidList[0];
  384. $qual = 0;
  385. $posId = 0;
  386. if (StlUtil::dictHasProperty($user->store->gemStore, $firstGemUId)) {
  387. $ins_gem = $user->store->gemStore->$firstGemUId;
  388. $mo = GameConfig::gem_getItem($ins_gem->typeId);
  389. $qual = $mo->qual;
  390. $posId = $mo->position;
  391. }
  392. $isCompose = true;
  393. //在做一次校验
  394. foreach ($gemUidList as $uid) {
  395. if (StlUtil::dictHasProperty($user->store->gemStore, $uid)) {
  396. $ins_gem = $user->store->gemStore->$uid;
  397. $mo = GameConfig::gem_getItem($ins_gem->typeId);
  398. if ($mo->qual != $qual || $mo->position != $posId) {
  399. $isCompose = false;
  400. break;
  401. }
  402. }
  403. }
  404. my_Assert($isCompose == true, ErrCode::user_store_GemCanotCompose);
  405. //查找要合成的宝石配置信息
  406. $gemConf = self::GemComposeSynthesis($qual, $posId);
  407. my_Assert($gemConf != null, ErrCode::err_const_no);
  408. $synthesisList = explode('_', $gemConf->synthesis);
  409. $composePosition = $synthesisList[0];
  410. $composeQual = $synthesisList[1];
  411. $composeNum = $synthesisList[2];
  412. foreach ($composeArr as $val) {
  413. $mo = GameConfig::gem_getItem($val->typeId);
  414. if ($mo->qual == $composeQual && $mo->position == $composePosition) {
  415. $gemUidList[] = $val->uid;
  416. }
  417. }
  418. if (count($gemUidList) >= $composeNum) {
  419. if ($gemConf != null) {
  420. $maxGemNum = intval(count($gemUidList) / $composeNum);
  421. $index = 0;
  422. $res = 0;
  423. foreach ($gemUidList as $uid) {
  424. my_Assert(self::GemIsCanCompose($uid) == false && $user->store->gemStore->$uid->isUnlock == 0, ErrCode::user_store_GemCanotCompose);
  425. $index += 1;
  426. self::RemoveGemInStore($uid);
  427. //$composeArr 有的话删除
  428. for ($i = 0; $i < count($composeArr); $i++) {
  429. if ($composeArr[$i]->uid == $uid) {
  430. StlUtil::arrayRemoveAt($composeArr, $i);
  431. break;
  432. }
  433. }
  434. if ($index % $composeNum == 0) {
  435. $res += 1;
  436. $composeGem = self::initGem($gemConf->typeId);
  437. self::PutGemInStore($composeGem);
  438. $composeArr[] = $composeGem; //临时放这
  439. }
  440. if ($res >= $maxGemNum) {
  441. break;
  442. }
  443. }
  444. }
  445. }
  446. }
  447. $resultArr = array();
  448. foreach ($composeArr as $value) {
  449. SystemProc::GetGem_GreaterOrangeQual_GemCompose(req()->zoneid, ctx()->baseInfo->name, $value->typeId); //广播
  450. ctx()->store->gemComposeNum += 1;
  451. $resultArr[] = $value->uid;
  452. }
  453. TaskProc::OnComposeNumGem();
  454. TaskProc::OnComposeNumGem_state();
  455. ctx($user);
  456. UserProc::updateUserInfo();
  457. return Resp::ok(array(
  458. 'composeGemIds' => $resultArr,
  459. 'store' => $user->store,
  460. 'task' => $user->task,
  461. ));
  462. }
  463. /**
  464. * 该宝石是否可以参与合成,其他页镶嵌的,已经被锁的都不能参与
  465. * @param type $uid
  466. * @return bool
  467. */
  468. private static function GemIsCanCompose($uid) {
  469. $Ins_gemItem = new Ins_Gem(ctx()->store->gemStore->$uid);
  470. $equipGemDic = ctx()->store->gemEquip;
  471. $equipPag = ctx()->store->equipPag;
  472. $isExist = false;
  473. foreach ($equipGemDic as $pag => $dic) {
  474. if ($equipPag == $pag) {
  475. continue;
  476. }
  477. if (StlUtil::dictHasProperty($dic, $Ins_gemItem->mo()->position)) {
  478. $posId = $Ins_gemItem->mo()->position;
  479. $tDic = $dic->$posId;
  480. foreach ($tDic as $index => $ins_gem) {
  481. if ($ins_gem->uid == $Ins_gemItem->uid) {
  482. $isExist = true;
  483. break;
  484. }
  485. }
  486. }
  487. if ($isExist) {
  488. break;
  489. }
  490. }
  491. return $isExist;
  492. }
  493. private static function GemComposeSynthesis($qual, $posId) {
  494. $gem = GameConfig::gem();
  495. foreach ($gem as $key => $value) {
  496. if ($value->synthesis != null) {
  497. $synthesisList = explode('_', $value->synthesis);
  498. $composePosition = $synthesisList[0];
  499. $composeQual = $synthesisList[1];
  500. $composeNum = $synthesisList[2];
  501. if ($composeQual != 0 && $composePosition != 0 && $composeQual == $qual && $posId == $composePosition && $value->isfixed_predicateId == 0) {
  502. return $value;
  503. }
  504. }
  505. }
  506. return null;
  507. }
  508. /**
  509. * 装备宝石
  510. * @return type
  511. */
  512. public static function GemSet() {
  513. list($equipUid, $uid, $type, $replaceUId) = req()->paras; //宝石uid 手动的时候记得校验u $replaceUId宝石槽坑位id
  514. my_Assert(StlUtil::dictHasProperty(ctx()->store->gemStore, $uid), ErrCode::user_store_NoItem);
  515. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $equipUid), ErrCode::user_store_NoEquip);
  516. $ins_equip = new Ins_Equip(ctx()->store->equip->$equipUid);
  517. $ins_gem = new Ins_Gem(ctx()->store->gemStore->$uid);
  518. my_Assert($ins_equip->mo()->position == $ins_gem->mo()->qual, ErrCode::user_store_PositionNotFit);
  519. $gemSetSlotDic = $ins_equip->gemSetSlot;
  520. $tag_index = 0;
  521. $tag_gem = null;
  522. foreach ($gemSetSlotDic as $slotId => $gemUid) {
  523. $gem = new Ins_Gem(ctx()->store->gemStore->$gemUid);
  524. if ($gem->predicateMo()->uniqueKey == $ins_gem->predicateMo()->uniqueKey) {
  525. $tag_index = $slotId;
  526. $tag_gem = $gem;
  527. break;
  528. }
  529. }
  530. $mo = GameConfig::gem_slotposition_getItem($ins_equip->mo()->qual);
  531. my_Assert(null != $mo, ErrCode::err_const_no);
  532. switch ($type) {
  533. case 1://镶嵌
  534. my_Assert($tag_gem == null, ErrCode::user_store_GemCanotSet);
  535. for ($i = 1; $i <= $mo->initNum_slot+$mo->buyNum_slot; $i++) {
  536. if (!StlUtil::dictHasProperty($gemSetSlotDic, $i)) {
  537. $gemSetSlotDic->$i = $ins_gem;
  538. break;
  539. }
  540. }
  541. break;
  542. case 2://替换
  543. //满不满都高替低品阶
  544. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  545. $gUid = $gemSetSlotDic->$replaceUId;
  546. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid); //这个$replaceUId是坑位的index id
  547. my_Assert($replace_ins_Gem->mo()->qual < $ins_gem->mo()->qual, ErrCode::user_store_NoExistGemReplace);
  548. $gemSetSlotDic->$replaceUId = $ins_gem;
  549. break;
  550. case 3://手动
  551. my_Assert(count((array) $gemSetSlotDic) >= $mo->initNum_slot+$mo->buyNum_slot, ErrCode::user_store_GemCanotSet);
  552. $gUid = $gemSetSlotDic->$replaceUId;
  553. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  554. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid);
  555. //$id = $replace_ins_Gem->uid;
  556. if ($tag_gem != null) {//如果有u那
  557. my_Assert($replace_ins_Gem->uid == $tag_gem->uid, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  558. //有U一样的,则点击正好是这个直接替换
  559. //$user->store->gemStore->$id = $replace_ins_Gem;
  560. $gemSetSlotDic->$tag_index = $ins_gem;
  561. } else {
  562. $go_index = 0;
  563. foreach ($gemSetSlotDic as $slotId => $gUid) {
  564. if ($gUid == $replaceUId) {
  565. $go_index = $slotId;
  566. break;
  567. }
  568. }
  569. my_Assert($go_index > 0, ErrCode::user_store_NoExistGemReplace);
  570. $gemSetSlotDic->$go_index = $ins_gem;
  571. }
  572. break;
  573. case 4://不能
  574. //1.小品阶替大品阶 或是 相等的,在不满的时候不允许 2. //满的 相等不允许替
  575. my_Assert($uid == 0, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  576. break;
  577. default:
  578. break;
  579. }
  580. $ins_equip->gemSetSlot = $gemSetSlotDic;
  581. ctx()->store(true)->equip->$equipUid = $ins_equip;
  582. TaskProc::OnSetSpecialQualGem();
  583. FightProc::Ranking_FightPower();
  584. UserProc::updateUserInfo();
  585. return Resp::ok(array(
  586. 'gold' => 0,
  587. 'store' => ctx()->store,
  588. 'task' => ctx()->task,
  589. ));
  590. }
  591. /**
  592. * 卸下装备
  593. * @return type
  594. */
  595. public static function GemRemove() {
  596. list($uid) = req()->paras; //装备宝石id
  597. $equips = ctx()->store->equip;
  598. foreach ($equips as $eUid => $ins_equip) {
  599. $dic = $ins_equip->gemSetSlot;
  600. foreach ($dic as $slotId => $gemUid) {
  601. if($uid == $gemUid){
  602. ctx()->store->equip->$eUid->gemSetSlot->$slotId = 0;
  603. }
  604. break 2;
  605. }
  606. }
  607. FightProc::Ranking_FightPower();
  608. UserProc::updateUserInfo();
  609. return Resp::ok(array(
  610. 'gold' => 0,
  611. 'store' => ctx()->store,));
  612. }
  613. /**
  614. * 6404 升级装备
  615. * @return type
  616. */
  617. public static function EquipUpgrade() {
  618. list($uid) = req()->paras; //装备uid
  619. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  620. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  621. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_equipLevelLimit);
  622. $mo = GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->mo()->qual, $ins_equip->mo()->position, $ins_equip->level);
  623. my_Assert(null != $mo, ErrCode::err_const_no);
  624. my_Assert(ctx()->baseInfo->gold >= $mo->needGold, ErrCode::notenough_gold_msg);
  625. $costTuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  626. $tuzhiNum = 0;
  627. if (StlUtil::dictHasProperty(ctx()->store->items, $costTuzhiId)) {
  628. $tuzhiNum = ctx()->store->items->$costTuzhiId;
  629. }
  630. my_Assert($tuzhiNum >= $mo->needItemNum, ErrCode::notenough_item);
  631. ctx()->store(true)->removeItem($costTuzhiId, $mo->needItemNum);
  632. ctx()->base(true)->Consume_Gold($mo->needGold);
  633. TaskProc::OnAnyEquipUpLevel_X();
  634. TaskProc::OnAllEquipUpLevel_X();
  635. TaskProc::OnEquipLevelUpNum();
  636. FightProc::Ranking_FightPower();
  637. UserProc::updateUserInfo();
  638. return Resp::ok(array(
  639. 'gold' => $user->baseInfo->gold,
  640. 'store' => $user->store,
  641. 'task' => $user->task,
  642. ));
  643. }
  644. /**
  645. * 6405 单个装备部位一键升级
  646. * @return type
  647. */
  648. public static function EquipUpgrade_MaxLv() {
  649. list($uid) = req()->paras;
  650. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  651. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  652. $maxLevel = $ins_equip->Equip_MaxLevel();
  653. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_equipLevelLimit);
  654. $tuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  655. $itemNum_store = 0;
  656. if (StlUtil::dictHasProperty(ctx()->store->items, $tuzhiId)) {
  657. $itemNum_store = ctx()->store->items->$tuzhiId;
  658. }
  659. $up_Gold = 0;
  660. $up_needItem = 0;
  661. $up_lv = 0;
  662. $noUp_gold = false;
  663. $noUp_item = false;
  664. for ($i = $ins_equip->level; $i <= $maxLevel; $i++) {
  665. $up_Gold += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->mo()->qual, $ins_equip->mo()->position, $i)->needGold;
  666. $up_needItem += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->mo()->qual, $ins_equip->mo()->position, $i)->needItemNum;
  667. if (ctx()->baseInfo->gold >= $up_Gold) {
  668. $noUp_gold = true;
  669. }
  670. if ($itemNum_store >= $up_needItem) {
  671. $noUp_item = true;
  672. }
  673. if (ctx()->baseInfo->gold >= $up_Gold && $itemNum_store >= $up_needItem) {
  674. //$need_gold = $up_Gold;
  675. //$need_item = $up_needItem;
  676. $up_lv = $i;
  677. continue;
  678. }
  679. break;
  680. }
  681. if ($up_lv == 0) {
  682. my_Assert($noUp_gold, ErrCode::notenough_gold_msg);
  683. my_Assert($noUp_item, ErrCode::notenough_item);
  684. }
  685. ctx()->base(true)->Consume_Gold($up_Gold);
  686. ctx()->store(true)->removeItem($tuzhiId, $up_needItem);
  687. if ($up_lv > 0) {
  688. ctx()->store->equip->$uid->level = $up_lv;
  689. }
  690. TaskProc::OnAnyEquipUpLevel_X();
  691. TaskProc::OnAllEquipUpLevel_X();
  692. TaskProc::OnEquipLevelUpNum();
  693. FightProc::Ranking_FightPower();
  694. UserProc::updateUserInfo();
  695. return Resp::ok(array(
  696. 'gold' => ctx()->baseInfo->gold,
  697. 'store' => ctx()->store,
  698. 'task' => ctx()->task,
  699. ));
  700. }
  701. public static function AddItemInStore() {
  702. list($rwdStr) = req()->paras; //mask = 1:表示战斗中掉落
  703. $user = ctx();
  704. $err = self::AddMultiItemInStore($rwdStr);
  705. my_Assert(ErrCode::ok == $err, $err);
  706. UserProc::updateUserInfo();
  707. return Resp::ok(array(
  708. //'gold' => $user->baseInfo->gold,
  709. //'tili' => $user->baseInfo->tili,
  710. //'cash' => $user->baseInfo->cash,
  711. 'store' => $user->store));
  712. }
  713. static $reward = array();
  714. static $reward_Gem = array();
  715. //static $reward_hero = array();
  716. /**
  717. * 具体奖励存入背包
  718. * @param type $goodsStr
  719. * @param type $src
  720. */
  721. public static function AddMultiItemInStore($goodsStr, $src = 0) {
  722. if ($goodsStr == null) {
  723. return;
  724. }
  725. $ary = explode(";", $goodsStr);
  726. foreach ($ary as $value) {
  727. $val = explode(",", $value);
  728. my_Assert(count($val) > 1, "解析奖励字符串出错");
  729. list($itemId, $num) = $val; # ID, 数量
  730. $itemMo = GameConfig::item_getItem($itemId);
  731. if ($itemMo->itemType != 701 && $itemMo->itemType != 201 && $itemMo->itemType != 502 && $src != 1) {
  732. self::$reward[] = $value;
  733. }
  734. switch ($itemMo->itemType) {
  735. case 1:
  736. ctx()->baseInfo->Add_Gold($num);
  737. //self::checkEquipUpgradeTip();//废弃
  738. break;
  739. case 2:
  740. ctx()->baseInfo->Add_Cash($num);
  741. break;
  742. case 3:
  743. ctx()->baseInfo->Add_tili($num);
  744. break;
  745. case 4:
  746. ctx()->baseInfo->Add_Exp($num);
  747. break;
  748. case 100://图纸
  749. case 103://钥匙
  750. case 401://启灵石
  751. case 301://洗练石
  752. case 501://人物碎片
  753. case 601://人身果
  754. case 801://寻宝券
  755. self::PutItemsInStore($itemId, $num);
  756. // if ($itemMo->itemType == 100) {//图纸
  757. // self::checkEquipUpgradeTip();//废弃
  758. // }
  759. break;
  760. case 502://角色卡
  761. HeroProc::RoleCardUnlockHero($itemId, $num);
  762. break;
  763. case 201://宝石
  764. for ($i = 0; $i < $num; $i++) {
  765. $gem = self::initGem($itemId);
  766. if ($src != 1) {
  767. self::$reward_Gem[] = $gem->uid;
  768. }
  769. self::PutGemInStore($gem);
  770. if ($src == Enum_StoreSourceType::ShopBox) {
  771. SystemProc::GetGem_GreaterOrangeQual_ShopBox(req()->zoneid, ctx()->baseInfo->name, $gem->typeId);
  772. }
  773. }
  774. break;
  775. case 701://道具宝箱
  776. for ($i = 0; $i < $num; $i++) {
  777. self::DistributeItemsBox($itemId);
  778. }
  779. break;
  780. default:
  781. break;
  782. }
  783. }
  784. }
  785. public static function PutItemsInStore($itemId, $num) {
  786. $items = ctx()->store->items;
  787. if (StlUtil::dictHasProperty($items, $itemId)) {
  788. $items->$itemId += $num;
  789. } else {
  790. $items->$itemId = $num;
  791. }
  792. ctx()->store->items = $items;
  793. }
  794. /**
  795. * 拆分宝箱盒子
  796. * @param type $reward
  797. */
  798. public static function DistributeItemsBox($itemId) {
  799. $itemBoxMo = GameConfig::item_2023_box_getItem($itemId);
  800. my_Assert($itemBoxMo != null, ErrCode::err_const_no);
  801. if ($itemBoxMo->type == 1) {
  802. $strList = explode(';', $itemBoxMo->contents);
  803. $numList = explode('-', $strList[0]);
  804. $randNum = rand($numList[0], $numList[1]);
  805. $ctxList = explode(',', $strList[1]);
  806. $per = 0;
  807. foreach ($ctxList as $value) {
  808. $ctx = explode(':', $value);
  809. $per += $ctx[1];
  810. }
  811. $reward = "";
  812. for ($i = 0; $i < $randNum; $i++) {
  813. $ctxPer = rand(1, $per);
  814. $start = 0;
  815. $end = 0;
  816. $id = 0;
  817. foreach ($ctxList as $value) {
  818. $ctx = explode(':', $value);
  819. $end += $ctx[1];
  820. if ($ctxPer > $start && $ctxPer <= $end) {
  821. $id = $ctx[0];
  822. break;
  823. }
  824. $start = $end;
  825. }
  826. if ($id != 0) {
  827. $str = $id . ',1';
  828. if ($reward == "") {
  829. $reward = $str;
  830. } else {
  831. $reward = $reward . ';' . $str;
  832. }
  833. }
  834. }
  835. self::AddMultiItemInStore($reward);
  836. } else {
  837. self::AddMultiItemInStore($itemBoxMo->contents);
  838. }
  839. }
  840. // public static function PutEquipInStore($equipId, $num) {
  841. // if ($equipId == 0) {
  842. // return;
  843. // }
  844. // $n = count((array) ctx()->store->equip) + 1;
  845. //
  846. // for ($index = 0; $index < $num; $index++) {
  847. // $Equip = new Ins_Equip();
  848. // $Equip->uid = $n;
  849. // $Equip->typeId = $equipId;
  850. // $Equip->qual = GameConfig::equip_getItem($equipId)->qual;
  851. // ctx()->store->equip->$n = $Equip;
  852. // $n += 1;
  853. // }
  854. // }
  855. /**
  856. * 得到金币或是图纸的时候校验下,是否满足装备升级条件,满足则tip字段设置为1 废弃
  857. */
  858. // public static function checkEquipUpgradeTip() {
  859. // $equipDic = ctx()->store->equipPosition;
  860. // if ($equipDic != null) {
  861. // foreach ($equipDic as $k => &$equip) {
  862. // $equip = new Ins_EquipPosition($equip);
  863. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  864. // $needGold = $lvMo->needGold;
  865. // $needItemNum = $lvMo->needItemNum;
  866. // $neeItemId = $equip->mo()->costTuzhiId;
  867. //
  868. // if (ctx()->baseInfo->gold >= $needGold && StlUtil::dictHasProperty(ctx()->store->items, $neeItemId) && ctx()->store->items->$neeItemId >= $needItemNum) {
  869. // $equipDic->$k->tip = 1; //绿点是每次得到金币或是图纸了,只要满足升级条件都变绿
  870. // }
  871. // }
  872. // }
  873. // ctx()->store->equipPosition = $equipDic;
  874. // }
  875. /**
  876. * 新宝石入库
  877. */
  878. public static function PutGemIdInStore($id, $num = 1) {
  879. for ($i = 0; $i < $num; $i++) {
  880. $gem = self::initGem($id);
  881. $length = $gem->uid;
  882. ctx()->store->gemStore->$length = $gem;
  883. }
  884. }
  885. public static function PutGemInStore($gem, $num = 1) {
  886. for ($i = 0; $i < $num; $i++) {
  887. $length = $gem->uid;
  888. ctx()->store->gemStore->$length = $gem;
  889. }
  890. }
  891. public static function initGem($id) {
  892. $length = ctx()->store->gemLength;
  893. $length += 1;
  894. $gem = new Ins_Gem();
  895. $gem->uid = $length;
  896. $gem->typeId = $id;
  897. $gem->predicateId = self::RandomGemPredicateId($id);
  898. $tag = self::CheckNewGemTip($gem);
  899. $gem->isNew = $tag;
  900. ctx()->store->gemLength = $length;
  901. return $gem;
  902. }
  903. /**
  904. * 从仓库移除宝石
  905. */
  906. public static function RemoveGemInStore($uid) {
  907. if (StlUtil::dictHasProperty(ctx()->store->gemStore, $uid)) {
  908. StlUtil::dictRemove(ctx()->store->gemStore, $uid);
  909. }
  910. return 0;
  911. }
  912. /**
  913. * 新宝石随机词条 临时等刚哥
  914. */
  915. public static function RandomGemPredicateId($id) {
  916. $mo = GameConfig::gem_getItem($id);
  917. my_Assert(null != $mo, "找不到宝石{$id}的配置数据");
  918. if ($mo->isfixed_predicateId == 1) {
  919. return $mo->predicateId;
  920. }
  921. $posId = $mo->position;
  922. $qual = $mo->qual;
  923. $arr = array();
  924. $predicateMo = GameConfig::predicate();
  925. foreach ($predicateMo as $key => $value) {
  926. if ($value->positions != null) {
  927. $list = explode(',', $value->positions);
  928. if ($value->qual == $qual && in_array($posId, $list) && $value->attachTarget == "gem") {
  929. $arr[] = $value->id;
  930. }
  931. }
  932. }
  933. if (count($arr) <= 0) {
  934. return 40;
  935. }
  936. my_Assert(count($arr) > 0, "宝石没有对应词条信息");
  937. $n = mt_rand(0, count($arr) - 1);
  938. return $arr[$n];
  939. //return 40;
  940. }
  941. /**
  942. * 新宝石提示
  943. */
  944. public static function CheckNewGemTip($gem) {
  945. $gemStore = ctx()->store->gemStore;
  946. $tag = false;
  947. foreach ($gemStore as $k => $ins_gem) {
  948. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  949. $tag = true;
  950. break;
  951. }
  952. }
  953. return $tag == true ? 0 : 1;
  954. }
  955. //临时代码
  956. // public static function InitGemInfo() {
  957. // if(count((array)ctx()->store->gemStore) > 0){
  958. // return;
  959. // }
  960. //
  961. // $index = 0;
  962. // $gem = GameConfig::gem();
  963. //
  964. // for ($i = 1; $i <=21; $i++) {
  965. // foreach ($gem as $key => $value) {
  966. // if($value->id == $i){
  967. // self::PutGemInStore($value->typeId);
  968. // }
  969. //
  970. // }
  971. // }
  972. //
  973. //
  974. //
  975. //
  976. // }
  977. }