StoreProc.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  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. case CmdCode::store_equip_compose: # 6417 装备合成
  52. return StoreProc::Equip_Compose();
  53. case CmdCode::store_equip_OnekeyCompose: # 6418 装备一键合成
  54. return StoreProc::Equip_OnekeyCompose();
  55. case CmdCode::store_equip_downGradingLevel: # 6419 降级
  56. return StoreProc::Equip_DownGradingLevel();
  57. case CmdCode::store_equip_downGradingQual: # 6420 降品
  58. return StoreProc::Equip_DownGradingQual();
  59. default:
  60. Err(ErrCode::cmd_err);
  61. }
  62. }
  63. /**
  64. * 6420 降品
  65. */
  66. public static function Equip_DownGradingQual() {
  67. list($uid) = req()->paras;
  68. $equipDic = ctx()->store->equip;
  69. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  70. $ins_equip = new Ins_Equip($equipDic->$uid);
  71. $NotDownGradingList = explode(',', glc()->equipQual_NotDownGrading);
  72. my_Assert(!in_array($ins_equip->qual, $NotDownGradingList), ErrCode::user_store_equip_minQual);
  73. self::GoldTuzhi_Fallback_Level($ins_equip);
  74. self::ComposeMaterial_Fallback($ins_equip->mo()->position,$ins_equip->qual);
  75. $ins_equip->level = 1;
  76. $sList2 = explode(';',glc()->equipQualUnlockSkillId);
  77. foreach ($sList2 as $str3)
  78. {
  79. $s = explode(',', $str3);
  80. if (in_array($ins_equip->qual, $s))
  81. {
  82. $ins_equip->qual = $s[0];
  83. break;
  84. }
  85. }
  86. ctx()->store->equip->$uid = $ins_equip;
  87. UserProc::updateUserInfo();
  88. return Resp::ok(array(
  89. 'gold' => ctx()->baseInfo->gold,
  90. 'store' => ctx()->store,
  91. ));
  92. }
  93. private static function ComposeMaterial_Fallback($posId,$qual) {
  94. $sList2 = explode(';',glc()->equipQualUnlockSkillId);
  95. foreach ($sList2 as $str) {
  96. $s = explode(',', $str);
  97. if(in_array($qual, $s)){
  98. $max = $qual;
  99. $min = $s[0];
  100. $num = 0;
  101. for ($i = $min+1; $i <= $max; $i++) {
  102. $mo = GameConfig::equip_compose_getItem($i);
  103. $num += explode(',', $mo->compose_condition)[2];
  104. }
  105. $typeId = self::ComposeMaterial($posId, $min);
  106. StoreProc::AddMultiItemInStore($typeId.','.$num);
  107. break;
  108. }
  109. }
  110. }
  111. private static function ComposeMaterial($posId,$qual) {
  112. $itemDic = GameConfig::item();
  113. foreach ($itemDic as $typeId => $mo) {
  114. if($mo->itemType == 901 && $typeId % 100 == $posId && floor($typeId/100)%100 == $qual){
  115. return $typeId;
  116. }
  117. }
  118. return null;
  119. }
  120. private static function GoldTuzhi_Fallback_Level($ins_equip){
  121. $gold = 0;
  122. $itemNum = 0;
  123. for ($i = 1; $i < $ins_equip->level; $i++) {
  124. $mo = GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual,$ins_equip->mo()->position,$ins_equip->level);
  125. $gold += $mo->needGold;
  126. $itemNum +=$mo->needItemNum;
  127. }
  128. $tuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  129. StoreProc::AddMultiItemInStore($tuzhiId.','.$itemNum);
  130. ctx()->base(true)->Add_Gold($gold);
  131. }
  132. /*
  133. * 6419 降级
  134. */
  135. public static function Equip_DownGradingLevel() {
  136. list($uid) = req()->paras;//装备uid
  137. $equipDic = ctx()->store->equip;
  138. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  139. $ins_equip = new Ins_Equip($equipDic->$uid);
  140. my_Assert($ins_equip->level > 1, ErrCode::user_store_equip_minlevel);
  141. self::GoldTuzhi_Fallback_Level($ins_equip);
  142. $ins_equip->level = 1;
  143. ctx()->store->equip->$uid = $ins_equip;
  144. UserProc::updateUserInfo();
  145. return Resp::ok(array(
  146. 'gold' => ctx()->baseInfo->gold,
  147. 'store' => ctx()->store,
  148. ));
  149. }
  150. /**
  151. * 6417 装备合成
  152. * @return type
  153. */
  154. public static function Equip_Compose() {
  155. list($uid, $equipUids_cost) = req()->paras;
  156. $equipDic = ctx()->store->equip;
  157. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  158. $ins_equip = new Ins_Equip($equipDic->$uid);
  159. $composeMo = GameConfig::equip_compose_getItem($ins_equip->qual);
  160. my_Assert(null != $composeMo, ErrCode::err_const_no);
  161. $arr = explode(',', $composeMo->compose_condition);
  162. $type = $arr[0];
  163. $costQual = $arr[1];
  164. $num = $arr[2];
  165. $costEquipsArr = explode(',', $equipUids_cost);
  166. my_Assert(count($costEquipsArr) == $num, ErrCode::user_store_equipMaterialNumErr);
  167. foreach ($costEquipsArr as $eqUid) {
  168. my_Assert(StlUtil::dictHasProperty($equipDic, $eqUid), ErrCode::user_store_NotExistEquip);
  169. $costIns_Equip = new Ins_Equip($equipDic->$eqUid);
  170. my_Assert($costIns_Equip->qual == $costQual, ErrCode::user_store_equipMaterialQualErr);
  171. if ($type == 1) {//本体
  172. my_Assert($costIns_Equip->typeId == $ins_equip->typeId, ErrCode::user_store_equipMaterialTypeErr);
  173. } else {
  174. my_Assert($costIns_Equip->mo()->position == $ins_equip->mo()->position, ErrCode::user_store_equipMaterialTypeErr);
  175. }
  176. }
  177. ctx()->store(true)->equip->$uid = self::ComposeNewEquip($ins_equip);
  178. //消耗的装备 回收
  179. foreach ($costEquipsArr as $eqUid) {
  180. $costIns_Equip = new Ins_Equip($equipDic->$eqUid);
  181. self::equipLevelUp_Material_Recovery($costIns_Equip->mo()->rarity, $costIns_Equip->qual, $costIns_Equip->mo()->position, $costIns_Equip->level);
  182. StlUtil::dictRemove(ctx()->store(true)->equip, $eqUid);
  183. }
  184. UserProc::updateUserInfo();
  185. return Resp::ok(array(
  186. 'gold' => ctx()->baseInfo->gold,
  187. 'store' => ctx()->store,
  188. ));
  189. }
  190. /**
  191. * 装备等级提升 消耗的金币图纸回收
  192. * @param type $rarity
  193. * @param type $qual
  194. * @param type $posId
  195. * @param type $level
  196. */
  197. public static function equipLevelUp_Material_Recovery($rarity, $qual, $posId, $level) {
  198. $gold = 0;
  199. $tuzhi = 0;
  200. $tuzhiId = GameConfig::equip_position_getItem($posId)->costTuzhiId;
  201. for ($i = 1; $i <= $level - 1; $i++) {
  202. $mo = GameConfig::equip_levelupgrade_getItem($rarity, $qual, $posId, $i);
  203. $gold += $mo->needGold;
  204. $tuzhi += $mo->needItemNum;
  205. }
  206. if ($gold > 0) {
  207. StoreProc::AddMultiItemInStore("1," . $gold);
  208. StoreProc::AddMultiItemInStore($tuzhiId . ',' . $tuzhi);
  209. }
  210. }
  211. /**
  212. * 合成一个新的装备
  213. * @param type Ins_Equip
  214. */
  215. public static function ComposeNewEquip(&$ins_equip) {
  216. $newEquipTypeId = $ins_equip->typeId;
  217. $qual = $ins_equip->qual + 1;
  218. if ($ins_equip->qual < 4) {
  219. $newEquipTypeId = substr($ins_equip->typeId, 0, strlen($ins_equip->typeId) - 6);
  220. $qual = GameConfig::equip_compose_getItem($newEquipTypeId)->qual;
  221. }
  222. $ins_equip->typeId = $newEquipTypeId;
  223. $ins_equip->qual = $qual;
  224. return $ins_equip;
  225. }
  226. public static function initEquip($typeId, $uid = 0) {
  227. if ($uid == 0) {
  228. $uid = count((array) ctx()->store->equip) + 1;
  229. }
  230. $ins_equip = new Ins_Equip();
  231. $ins_equip->uid = $uid;
  232. $ins_equip->typeId = $typeId;
  233. $ins_equip->qual = GameConfig::equip_compose_getItem($typeId)->qual;
  234. return $ins_equip;
  235. }
  236. /**
  237. * 6418 装备一键合成
  238. * @return type
  239. */
  240. public static function Equip_OnekeyCompose() {
  241. //list() = req()->paras;
  242. $equipDic = ctx()->store->equip;
  243. $arr = array();
  244. foreach ($equipDic as $uid => $equip) {
  245. $ins_equip = new Ins_Equip($equip);
  246. if ($ins_equip->qual > 4) {
  247. continue;
  248. }
  249. $arr[] = $ins_equip;
  250. }
  251. //等级从大到小
  252. $len = count($arr);
  253. for ($i = 0; $i < $len - 1; $i++) {
  254. for ($j = $len - 1; $j > $i; $j--) {
  255. if ($arr[$j]->level > $arr[$j - 1]->level) {
  256. $temp = $arr[$j];
  257. $arr[$j] = $arr[$j - 1];
  258. $arr[$j - 1] = $temp;
  259. }
  260. }
  261. }
  262. $composeEquip = array();
  263. if ($len > 0) {
  264. while (true) {
  265. $equip_compose = $arr[0];
  266. $str = explode(',', GameConfig::equip_compose_getItem($equip_compose->qual)->compose_condition);
  267. $type = $str[0];
  268. $costQual = $str[1];
  269. $num = $str[2];
  270. $n = count($arr);
  271. $composeArr = array();
  272. $tag = false;
  273. $ing_compose = false;
  274. for ($k = $n - 1; $k >= 0; $k--) {
  275. if ($arr[$k]->uid == $equip_compose->uid) {
  276. continue;
  277. }
  278. if ($type == 1 && $arr[$k]->qual == $costQual && $arr[$k]->typeId == $equip_compose->typeId) {
  279. $tag = true;
  280. } else if ($type == 2 && $arr[$k]->qual == $costQual && $arr[$k]->mo()->position == $equip_compose->mo()->position) {
  281. $tag = true;
  282. }
  283. if ($tag) {
  284. $composeArr[] = $arr[$k];
  285. if (count($composeArr) >= $num) {
  286. break;
  287. }
  288. }
  289. }
  290. if(count($composeArr) >= $num){
  291. $newEquip = self::ComposeNewEquip($equip_compose);
  292. $uid = $newEquip->uid;
  293. ctx()->store(true)->equip->$uid = $newEquip;
  294. $composeEquip[] = $uid;
  295. $ing_compose = true;
  296. }
  297. //合成的 材料不够不能合成的都要删除
  298. foreach ($composeArr as $val) {
  299. if($ing_compose){//合成的回收 不合成的可不能给回收了
  300. self::equipLevelUp_Material_Recovery($val->mo()->rarity, $val->qual,$val->mo()->position, $val->level);
  301. }
  302. StlUtil::arrayRemove($arr, $val);
  303. }
  304. StlUtil::arrayRemove($arr, $equip_compose);
  305. if (count($arr) <= 0) {
  306. break;
  307. }
  308. }
  309. }
  310. UserProc::updateUserInfo();
  311. return Resp::ok(array(
  312. 'gold' => ctx()->baseInfo->gold,
  313. 'store' => ctx()->store,
  314. 'composeEquip'=>$composeEquip,
  315. ));
  316. }
  317. /**
  318. * 6416 购买装备宝石槽
  319. * @return type
  320. */
  321. public static function Gem_BuySlot() {
  322. list($uid) = req()->paras;
  323. $equipDic = ctx()->store->equip;
  324. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  325. $ins_equip = new Ins_Equip($equipDic->$uid);
  326. $mo = GameConfig::gem_slotposition_getItem($ins_equip->qual);
  327. my_Assert(null != $mo, ErrCode::err_const_no);
  328. $initNum = $mo->initNum_slot;
  329. $buyNum = $mo->buyNum_slot;
  330. $unlockIndex = 0;
  331. if ($buyNum > 0) {
  332. for ($i = $initNum + 1; $i <= $initNum + $buyNum; $i++) {
  333. if (!StlUtil::dictHasProperty($ins_equip->gemSetSlot, $i)) {
  334. $ins_equip->gemSetSlot->$i = 0;
  335. break;
  336. }
  337. $unlockIndex += 1;
  338. }
  339. }
  340. $costArr = explode(';', $mo->cost);
  341. $cash = explode(',', $costArr[$unlockIndex]);
  342. my_Assert(ctx()->base(true)->cash >= $cash[1], ErrCode::notenough_cash_msg);
  343. ctx()->base(true)->Consume_Cash($unlockIndex);
  344. ctx()->store(true)->equip->$uid = $ins_equip;
  345. UserProc::updateUserInfo();
  346. return Resp::ok(array(
  347. 'cash' => ctx()->baseInfo->cash,
  348. 'store' => ctx()->store,
  349. ));
  350. }
  351. /**
  352. * 6413 装备
  353. * @return type
  354. */
  355. public static function Equiped() {
  356. list($uid) = req()->paras;
  357. $equipDic = ctx()->store->equip;
  358. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  359. $ins_equip = new Ins_Equip($equipDic->$uid);
  360. $posId = $ins_equip->mo()->position;
  361. ctx()->store(true)->equipLocation->$posId = $uid;
  362. UserProc::updateUserInfo();
  363. return Resp::ok(array());
  364. }
  365. /**
  366. * 6413 卸下装备
  367. * @return type
  368. */
  369. public static function RemoveEquip() {
  370. list($uid) = req()->paras;
  371. $equipDic = ctx()->store->equip;
  372. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  373. $ins_equip = new Ins_Equip($equipDic->$uid);
  374. $posId = $ins_equip->mo()->position;
  375. StlUtil::dictRemove(ctx()->store(true)->equipLocation, $posId);
  376. UserProc::updateUserInfo();
  377. return Resp::ok(array());
  378. }
  379. /**
  380. * 洗练
  381. * @return Resp
  382. */
  383. public static function GemXiLian() {
  384. list($uid) = req()->paras;
  385. //把 qual pos u一样的宝石开锁关锁
  386. $gemStore = ctx()->store->gemStore;
  387. my_Assert(StlUtil::dictHasProperty($gemStore, $uid), ErrCode::user_store_NotExistGem);
  388. $gem = new Ins_Gem($gemStore->$uid);
  389. my_Assert($gem->mo()->qual >= 5, ErrCode::user_store_XilianStoneNoEnough);
  390. $arr = explode(';', glc()->XILianGemlNeedXILianStone);
  391. $needStone = 0;
  392. $xilianStoneId = 0;
  393. foreach ($arr as $val) {
  394. $str = explode(':', $val);
  395. if ($str[0] == $gem->mo()->qual) {
  396. $s = explode(',', $str[1]);
  397. $needStone = $s[1];
  398. $xilianStoneId = $s[0];
  399. break;
  400. }
  401. }
  402. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $xilianStoneId) && ctx()->store->items->$xilianStoneId >= $needStone, ErrCode::user_store_XilianStoneNoEnough);
  403. $dic = GameConfig::predicate();
  404. $pList = array();
  405. foreach ($dic as $id => $pMo) {
  406. if ($pMo->positions != null && $pMo->qual != null) {
  407. $list = explode(',', $pMo->positions);
  408. if ($pMo->id != $gem->predicateId && $pMo->qual == $gem->mo()->qual && in_array($gem->mo()->position, $list) && $pMo->attachTarget == "gem") {
  409. $pList[] = $pMo->id;
  410. }
  411. }
  412. }
  413. my_Assert(count($pList) > 0, ErrCode::user_store_NoFindPredicate);
  414. $rand = random_int(0, count($pList) - 1);
  415. $pId = $pList[$rand];
  416. ctx()->store->gemStore->$uid->predicateId = $pId;
  417. ctx()->store->removeItem($xilianStoneId, $needStone);
  418. $xilianStoneNum = 0;
  419. if (StlUtil::dictHasProperty(ctx()->store->items, $xilianStoneId)) {
  420. $xilianStoneNum = ctx()->store->items->$xilianStoneId;
  421. }
  422. UserProc::updateUserInfo();
  423. return Resp::ok(array(
  424. 'xilianStoneId' => $xilianStoneId,
  425. 'xilianStone' => $xilianStoneNum,
  426. 'predicateId' => $pId,
  427. ));
  428. }
  429. /**
  430. * 宝石开锁解锁
  431. * @return Resp
  432. */
  433. public static function GemLockState() {
  434. list($uid) = req()->paras;
  435. $user = ctx();
  436. //把 qual pos u一样的宝石开锁关锁
  437. $gemStore = $user->store->gemStore;
  438. $gem = $gemStore->$uid;
  439. $tag = 0;
  440. if ($gem->isUnlock == 0) {
  441. $gem->isUnlock = 1;
  442. $tag = 1;
  443. } else {
  444. $gem->isUnlock = 0;
  445. $tag = 0;
  446. }
  447. $gemStore->$uid = $gem;
  448. foreach ($gemStore as $k => $ins_gem) {
  449. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  450. $gemStore->$k->isUnlock = $tag;
  451. }
  452. }
  453. $user->store->gemStore = $gemStore;
  454. ctx($user);
  455. UserProc::updateUserInfo();
  456. return Resp::ok(array(
  457. 'gold' => 0,
  458. 'store' => $user->store,
  459. ));
  460. }
  461. /**
  462. * 切换装备分页
  463. * @return Resp
  464. */
  465. public static function SwitchEquipPag() {
  466. list($index) = req()->paras;
  467. $user = ctx();
  468. $user->store->equipPag = $index;
  469. ctx($user);
  470. UserProc::updateUserInfo();
  471. return Resp::ok(array());
  472. }
  473. /**
  474. * 所有装备的一键升级
  475. * 规则:等级不同从等级小到大,等级一样按照部位顺序
  476. *
  477. * @return Resp
  478. */
  479. public static function AllEquipUpgrade() {
  480. //list() = req()->paras;
  481. //$user = ctx();
  482. // $equipDic = $user->store->equipPosition;
  483. //
  484. // $equip_levelDic = GameConfig::equip_levelupgrade();
  485. // $maxLv = count(StlUtil::dictToArray($equip_levelDic));
  486. // $arr = array();
  487. // if ($equipDic != null) {
  488. // foreach ($equipDic as $k => &$equip) {
  489. // $equip = new Ins_EquipPosition($equip);
  490. //
  491. // if ($equip->level >= $maxLv) {
  492. // continue;
  493. // }
  494. //
  495. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  496. // $needGold = $lvMo->needGold;
  497. // $needItemNum = $lvMo->needItemNum;
  498. // $neeItemId = $equip->mo()->costTuzhiId;
  499. //
  500. // if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  501. // $arr[] = $equip;
  502. // }
  503. // }
  504. // }
  505. // $upLevelArr = array();
  506. // if (count($arr) > 0) {
  507. // //进行排序
  508. // $len = count($arr);
  509. // for ($i = 0; $i < $len - 1; $i++) {
  510. // for ($j = 0; $j < $len - $i - 1; $j++) {
  511. // if ($arr[$j]->level > $arr[$j + 1]->level) {//从小到大
  512. // $temp = $arr[$j];
  513. // $arr[$j] = $arr[$j + 1];
  514. // $arr[$j + 1] = $temp;
  515. // } elseif ($arr[$j]->level == $arr[$j + 1]->level) {
  516. // $j_equip = new Ins_EquipPosition($arr[$j]);
  517. // $jj_equip = new Ins_EquipPosition($arr[$j + 1]);
  518. // if ($j_equip->mo()->position > $jj_equip->mo()->position) {
  519. // $temp = $arr[$j];
  520. // $arr[$j] = $arr[$j + 1];
  521. // $arr[$j + 1] = $temp;
  522. // }
  523. // }
  524. // }
  525. // }
  526. //升级,扣除金币和图纸
  527. // while (true) {
  528. // $tag = 9999;
  529. // foreach ($arr as $index => &$equip) {
  530. // $ins_equip = new Ins_EquipPosition($equip);
  531. // $lvMo = GameConfig::equip_levelupgrade_getItem($ins_equip->level);
  532. // $needGold = $lvMo->needGold;
  533. // $needItemNum = $lvMo->needItemNum;
  534. // $neeItemId = $ins_equip->mo()->costTuzhiId;
  535. // if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  536. // $id = $ins_equip->typeId;
  537. // if (!in_array($id, $upLevelArr)) {
  538. // $upLevelArr[] = $id;
  539. // }
  540. //
  541. // $ins_equip->level += 1;
  542. // $equipDic->$id->level += 1;
  543. // $user->baseInfo->Consume_Gold($needGold);
  544. // $user->store->removeItem($neeItemId, $needItemNum);
  545. // if ($ins_equip->level >= 99) {
  546. // $tag = $index;
  547. // break;
  548. // }
  549. // } else {
  550. // $tag = $index;
  551. // break;
  552. // }
  553. // }
  554. // if ($tag != 9999) {
  555. // if (array_key_exists($tag, $arr)) {
  556. // StlUtil::arrayRemoveAt($arr, $tag);
  557. // }
  558. // }
  559. //
  560. // if (count($arr) <= 0) {
  561. // break;
  562. // }
  563. // }
  564. // }
  565. // TaskProc::OnAnyEquipUpLevel_X();
  566. // TaskProc::OnAllEquipUpLevel_X();
  567. // TaskProc::OnEquipLevelUpNum();
  568. // ctx($user);
  569. //
  570. // FightProc::Ranking_FightPower();
  571. UserProc::updateUserInfo();
  572. return Resp::ok(array(
  573. 'upLevelArr' => $upLevelArr,
  574. 'gold' => $user->baseInfo->gold,
  575. 'store' => $user->store,
  576. 'task' => $user->task,
  577. ));
  578. }
  579. /**
  580. * 6411 移除是新宝石绿点提示
  581. * @return Resp
  582. */
  583. public static function RemoveNewGemTip() {
  584. list($uid) = req()->paras; //宝石uid
  585. my_Assert(StlUtil::dictHasProperty(ctx()->store->gemStore, $uid), ErrCode::user_store_NoItem);
  586. ctx()->store(true)->gemStore->$uid->isNew = 0;
  587. UserProc::updateUserInfo();
  588. return Resp::ok(array());
  589. }
  590. /**
  591. * 移除装备可以升级绿点提示 -------废弃
  592. * @return Resp
  593. */
  594. public static function RemoveEquipUpgradeTip() {
  595. // list($posId) = req()->paras; //装备部位
  596. // $user = ctx();
  597. //
  598. // my_Assert(StlUtil::dictHasProperty($user->store->equipPosition, $posId), ErrCode::user_store_NoEquip);
  599. //
  600. // $user->store->equipPosition->$posId->tip = 0;
  601. //
  602. // ctx($user);
  603. // UserProc::updateUserInfo();
  604. // return Resp::ok(array(
  605. // 'gold' => 0,
  606. // 'store' => $user->store,));
  607. }
  608. /**
  609. * 6406 合成
  610. * @return type
  611. */
  612. public static function GemCompose() {
  613. list($gemIds) = req()->paras;
  614. $list = explode(';', $gemIds);
  615. $gemStore = ctx()->store->gemStore;
  616. $composeArr = array();
  617. foreach ($list as $gems) {
  618. $gemArr = explode('-', $gems);
  619. $length1 = strlen($gemArr[0]);
  620. $length2 = strlen($gemArr[1]);
  621. $gem_composeCost = explode(',', substr($gemArr[0], 1, $length1 - 1)); //去掉逗号
  622. $gem_composeIds = explode(',', substr($gemArr[1], 1, $length2 - 1)); //去掉逗号
  623. $gemMo = GameConfig::gem_getItem($gem_composeIds[0]);
  624. my_Assert(null != $gemMo, ErrCode::err_const_no);
  625. $isCompose = true;
  626. foreach ($gem_composeCost as $gemUid) {
  627. if (!StlUtil::dictHasProperty($gemStore, $gemUid)) {
  628. $isCompose = false;
  629. break;
  630. }
  631. $ins_gem = new Ins_Gem($gemStore->$gemUid);
  632. if ($ins_gem->mo()->qual + 1 != $gemMo->qual || $ins_gem->mo()->position == $gemMo->position) {
  633. $isCompose = false;
  634. break;
  635. }
  636. if (!self::GemIsCanCompose($gemUid)) {
  637. $isCompose = false;
  638. break;
  639. }
  640. }
  641. my_Assert($isCompose == true, ErrCode::user_store_GemCanotCompose);
  642. foreach ($gem_composeCost as $gemUid) {
  643. self::RemoveGemInStore($gemUid);
  644. }
  645. foreach ($gem_composeIds as $gemTypeId) {
  646. $composeGem = self::initGem($gemTypeId);
  647. self::PutGemInStore($composeGem);
  648. $composeArr[] = $composeGem->uid; //临时放这
  649. }
  650. }
  651. TaskProc::OnComposeNumGem();
  652. TaskProc::OnComposeNumGem_state();
  653. UserProc::updateUserInfo();
  654. return Resp::ok(array(
  655. 'composeGemIds' => $composeArr,
  656. 'store' => ctx()->store,
  657. 'task' => ctx()->task,
  658. ));
  659. }
  660. /**
  661. * 该宝石是否可以参与合成,其他页镶嵌的,已经被锁的都不能参与
  662. * @param type $uid
  663. * @return bool
  664. */
  665. private static function GemIsCanCompose($uid) {
  666. $ins_gem = new Ins_Gem($uid);
  667. if ($ins_gem->isUnlock == 1) {
  668. return false;
  669. }
  670. $isExist = true;
  671. $equip = ctx()->store->equip;
  672. foreach ($equip as $uid => $item) {
  673. $arr = get_object_vars($item->gemSetSlot);
  674. $values = array_values($arr);
  675. if (in_array($uid, $values)) {
  676. $isExist = false;
  677. break;
  678. }
  679. }
  680. return $isExist;
  681. }
  682. /**
  683. * 装备宝石
  684. * @return type
  685. */
  686. public static function GemSet() {
  687. list($equipUid, $uid, $type, $replaceUId) = req()->paras; //宝石uid 手动的时候记得校验u $replaceUId宝石槽坑位id
  688. my_Assert(StlUtil::dictHasProperty(ctx()->store->gemStore, $uid), ErrCode::user_store_NoItem);
  689. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $equipUid), ErrCode::user_store_NoEquip);
  690. $ins_equip = new Ins_Equip(ctx()->store->equip->$equipUid);
  691. $ins_gem = new Ins_Gem(ctx()->store->gemStore->$uid);
  692. my_Assert($ins_equip->mo()->position == $ins_gem->mo()->qual, ErrCode::user_store_PositionNotFit);
  693. $gemSetSlotDic = $ins_equip->gemSetSlot;
  694. $tag_index = 0;
  695. $tag_gem = null;
  696. foreach ($gemSetSlotDic as $slotId => $gemUid) {
  697. $gem = new Ins_Gem(ctx()->store->gemStore->$gemUid);
  698. if ($gem->predicateMo()->uniqueKey == $ins_gem->predicateMo()->uniqueKey) {
  699. $tag_index = $slotId;
  700. $tag_gem = $gem;
  701. break;
  702. }
  703. }
  704. $mo = GameConfig::gem_slotposition_getItem($ins_equip->qual);
  705. my_Assert(null != $mo, ErrCode::err_const_no);
  706. switch ($type) {
  707. case 1://镶嵌
  708. my_Assert($tag_gem == null, ErrCode::user_store_GemCanotSet);
  709. for ($i = 1; $i <= $mo->initNum_slot + $mo->buyNum_slot; $i++) {
  710. if (!StlUtil::dictHasProperty($gemSetSlotDic, $i)) {
  711. $gemSetSlotDic->$i = $ins_gem;
  712. break;
  713. }
  714. }
  715. break;
  716. case 2://替换
  717. //满不满都高替低品阶
  718. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  719. $gUid = $gemSetSlotDic->$replaceUId;
  720. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid); //这个$replaceUId是坑位的index id
  721. my_Assert($replace_ins_Gem->mo()->qual < $ins_gem->mo()->qual, ErrCode::user_store_NoExistGemReplace);
  722. $gemSetSlotDic->$replaceUId = $ins_gem;
  723. break;
  724. case 3://手动
  725. my_Assert(count((array) $gemSetSlotDic) >= $mo->initNum_slot + $mo->buyNum_slot, ErrCode::user_store_GemCanotSet);
  726. $gUid = $gemSetSlotDic->$replaceUId;
  727. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  728. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid);
  729. //$id = $replace_ins_Gem->uid;
  730. if ($tag_gem != null) {//如果有u那
  731. my_Assert($replace_ins_Gem->uid == $tag_gem->uid, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  732. //有U一样的,则点击正好是这个直接替换
  733. //$user->store->gemStore->$id = $replace_ins_Gem;
  734. $gemSetSlotDic->$tag_index = $ins_gem;
  735. } else {
  736. $go_index = 0;
  737. foreach ($gemSetSlotDic as $slotId => $gUid) {
  738. if ($gUid == $replaceUId) {
  739. $go_index = $slotId;
  740. break;
  741. }
  742. }
  743. my_Assert($go_index > 0, ErrCode::user_store_NoExistGemReplace);
  744. $gemSetSlotDic->$go_index = $ins_gem;
  745. }
  746. break;
  747. case 4://不能
  748. //1.小品阶替大品阶 或是 相等的,在不满的时候不允许 2. //满的 相等不允许替
  749. my_Assert($uid == 0, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  750. break;
  751. default:
  752. break;
  753. }
  754. $ins_equip->gemSetSlot = $gemSetSlotDic;
  755. ctx()->store(true)->equip->$equipUid = $ins_equip;
  756. TaskProc::OnSetSpecialQualGem();
  757. FightProc::Ranking_FightPower();
  758. UserProc::updateUserInfo();
  759. return Resp::ok(array(
  760. 'gold' => 0,
  761. 'store' => ctx()->store,
  762. 'task' => ctx()->task,
  763. ));
  764. }
  765. /**
  766. * 卸下装备
  767. * @return type
  768. */
  769. public static function GemRemove() {
  770. list($uid) = req()->paras; //装备宝石id
  771. $equips = ctx()->store->equip;
  772. foreach ($equips as $eUid => $ins_equip) {
  773. $dic = $ins_equip->gemSetSlot;
  774. foreach ($dic as $slotId => $gemUid) {
  775. if ($uid == $gemUid) {
  776. ctx()->store->equip->$eUid->gemSetSlot->$slotId = 0;
  777. }
  778. break 2;
  779. }
  780. }
  781. FightProc::Ranking_FightPower();
  782. UserProc::updateUserInfo();
  783. return Resp::ok(array(
  784. 'gold' => 0,
  785. 'store' => ctx()->store,));
  786. }
  787. /**
  788. * 6404 升级装备
  789. * @return type
  790. */
  791. public static function EquipUpgrade() {
  792. list($uid) = req()->paras; //装备uid
  793. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  794. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  795. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_equipLevelLimit);
  796. $mo = GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $ins_equip->level);
  797. my_Assert(null != $mo, ErrCode::err_const_no);
  798. my_Assert(ctx()->baseInfo->gold >= $mo->needGold, ErrCode::notenough_gold_msg);
  799. $costTuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  800. $tuzhiNum = 0;
  801. if (StlUtil::dictHasProperty(ctx()->store->items, $costTuzhiId)) {
  802. $tuzhiNum = ctx()->store->items->$costTuzhiId;
  803. }
  804. my_Assert($tuzhiNum >= $mo->needItemNum, ErrCode::notenough_item);
  805. ctx()->store(true)->removeItem($costTuzhiId, $mo->needItemNum);
  806. ctx()->base(true)->Consume_Gold($mo->needGold);
  807. TaskProc::OnAnyEquipUpLevel_X();
  808. TaskProc::OnAllEquipUpLevel_X();
  809. TaskProc::OnEquipLevelUpNum();
  810. FightProc::Ranking_FightPower();
  811. UserProc::updateUserInfo();
  812. return Resp::ok(array(
  813. 'gold' => $user->baseInfo->gold,
  814. 'store' => $user->store,
  815. 'task' => $user->task,
  816. ));
  817. }
  818. /**
  819. * 6405 单个装备部位一键升级
  820. * @return type
  821. */
  822. public static function EquipUpgrade_MaxLv() {
  823. list($uid) = req()->paras;
  824. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  825. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  826. $maxLevel = $ins_equip->Equip_MaxLevel();
  827. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_equipLevelLimit);
  828. $tuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  829. $itemNum_store = 0;
  830. if (StlUtil::dictHasProperty(ctx()->store->items, $tuzhiId)) {
  831. $itemNum_store = ctx()->store->items->$tuzhiId;
  832. }
  833. $up_Gold = 0;
  834. $up_needItem = 0;
  835. $up_lv = 0;
  836. $noUp_gold = false;
  837. $noUp_item = false;
  838. for ($i = $ins_equip->level; $i <= $maxLevel; $i++) {
  839. $up_Gold += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $i)->needGold;
  840. $up_needItem += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $i)->needItemNum;
  841. if (ctx()->baseInfo->gold >= $up_Gold) {
  842. $noUp_gold = true;
  843. }
  844. if ($itemNum_store >= $up_needItem) {
  845. $noUp_item = true;
  846. }
  847. if (ctx()->baseInfo->gold >= $up_Gold && $itemNum_store >= $up_needItem) {
  848. //$need_gold = $up_Gold;
  849. //$need_item = $up_needItem;
  850. $up_lv = $i;
  851. continue;
  852. }
  853. break;
  854. }
  855. if ($up_lv == 0) {
  856. my_Assert($noUp_gold, ErrCode::notenough_gold_msg);
  857. my_Assert($noUp_item, ErrCode::notenough_item);
  858. }
  859. ctx()->base(true)->Consume_Gold($up_Gold);
  860. ctx()->store(true)->removeItem($tuzhiId, $up_needItem);
  861. if ($up_lv > 0) {
  862. ctx()->store->equip->$uid->level = $up_lv;
  863. }
  864. TaskProc::OnAnyEquipUpLevel_X();
  865. TaskProc::OnAllEquipUpLevel_X();
  866. TaskProc::OnEquipLevelUpNum();
  867. FightProc::Ranking_FightPower();
  868. UserProc::updateUserInfo();
  869. return Resp::ok(array(
  870. 'gold' => ctx()->baseInfo->gold,
  871. 'store' => ctx()->store,
  872. 'task' => ctx()->task,
  873. ));
  874. }
  875. public static function AddItemInStore() {
  876. list($rwdStr) = req()->paras; //mask = 1:表示战斗中掉落
  877. $user = ctx();
  878. $err = self::AddMultiItemInStore($rwdStr);
  879. my_Assert(ErrCode::ok == $err, $err);
  880. UserProc::updateUserInfo();
  881. return Resp::ok(array(
  882. //'gold' => $user->baseInfo->gold,
  883. //'tili' => $user->baseInfo->tili,
  884. //'cash' => $user->baseInfo->cash,
  885. 'store' => $user->store));
  886. }
  887. static $reward = array();
  888. static $reward_Gem = array();
  889. //static $reward_hero = array();
  890. /**
  891. * 具体奖励存入背包
  892. * @param type $goodsStr
  893. * @param type $src
  894. */
  895. public static function AddMultiItemInStore($goodsStr, $src = 0) {
  896. if ($goodsStr == null) {
  897. return;
  898. }
  899. $ary = explode(";", $goodsStr);
  900. foreach ($ary as $value) {
  901. $val = explode(",", $value);
  902. my_Assert(count($val) > 1, "解析奖励字符串出错");
  903. list($itemId, $num) = $val; # ID, 数量
  904. $itemMo = GameConfig::item_getItem($itemId);
  905. if ($itemMo->itemType != 701 && $itemMo->itemType != 201 && $itemMo->itemType != 502 && $src != 1) {
  906. self::$reward[] = $value;
  907. }
  908. switch ($itemMo->itemType) {
  909. case 1:
  910. ctx()->baseInfo->Add_Gold($num);
  911. //self::checkEquipUpgradeTip();//废弃
  912. break;
  913. case 2:
  914. ctx()->baseInfo->Add_Cash($num);
  915. break;
  916. case 3:
  917. ctx()->baseInfo->Add_tili($num);
  918. break;
  919. case 4:
  920. ctx()->baseInfo->Add_Exp($num);
  921. break;
  922. case 100://图纸
  923. case 103://钥匙
  924. case 401://启灵石
  925. case 301://洗练石
  926. case 501://人物碎片
  927. case 601://人身果
  928. case 801://寻宝券
  929. case 901:
  930. self::PutItemsInStore($itemId, $num);
  931. // if ($itemMo->itemType == 100) {//图纸
  932. // self::checkEquipUpgradeTip();//废弃
  933. // }
  934. break;
  935. case 502://角色卡
  936. HeroProc::RoleCardUnlockHero($itemId, $num);
  937. break;
  938. case 201://宝石
  939. for ($i = 0; $i < $num; $i++) {
  940. $gem = self::initGem($itemId);
  941. if ($src != 1) {
  942. self::$reward_Gem[] = $gem->uid;
  943. }
  944. self::PutGemInStore($gem);
  945. if ($src == Enum_StoreSourceType::ShopBox) {
  946. SystemProc::GetGem_GreaterOrangeQual_ShopBox(req()->zoneid, ctx()->baseInfo->name, $gem->typeId);
  947. }
  948. }
  949. break;
  950. case 701://道具宝箱
  951. for ($i = 0; $i < $num; $i++) {
  952. self::DistributeItemsBox($itemId);
  953. }
  954. break;
  955. default:
  956. break;
  957. }
  958. }
  959. }
  960. public static function PutItemsInStore($itemId, $num) {
  961. $items = ctx()->store->items;
  962. if (StlUtil::dictHasProperty($items, $itemId)) {
  963. $items->$itemId += $num;
  964. } else {
  965. $items->$itemId = $num;
  966. }
  967. ctx()->store->items = $items;
  968. }
  969. /**
  970. * 拆分宝箱盒子
  971. * @param type $reward
  972. */
  973. public static function DistributeItemsBox($itemId) {
  974. $itemBoxMo = GameConfig::item_2023_box_getItem($itemId);
  975. my_Assert($itemBoxMo != null, ErrCode::err_const_no);
  976. if ($itemBoxMo->type == 1) {
  977. $strList = explode(';', $itemBoxMo->contents);
  978. $numList = explode('-', $strList[0]);
  979. $randNum = rand($numList[0], $numList[1]);
  980. $ctxList = explode(',', $strList[1]);
  981. $per = 0;
  982. foreach ($ctxList as $value) {
  983. $ctx = explode(':', $value);
  984. $per += $ctx[1];
  985. }
  986. $reward = "";
  987. for ($i = 0; $i < $randNum; $i++) {
  988. $ctxPer = rand(1, $per);
  989. $start = 0;
  990. $end = 0;
  991. $id = 0;
  992. foreach ($ctxList as $value) {
  993. $ctx = explode(':', $value);
  994. $end += $ctx[1];
  995. if ($ctxPer > $start && $ctxPer <= $end) {
  996. $id = $ctx[0];
  997. break;
  998. }
  999. $start = $end;
  1000. }
  1001. if ($id != 0) {
  1002. $str = $id . ',1';
  1003. if ($reward == "") {
  1004. $reward = $str;
  1005. } else {
  1006. $reward = $reward . ';' . $str;
  1007. }
  1008. }
  1009. }
  1010. self::AddMultiItemInStore($reward);
  1011. } else {
  1012. self::AddMultiItemInStore($itemBoxMo->contents);
  1013. }
  1014. }
  1015. // public static function PutEquipInStore($equipId, $num) {
  1016. // if ($equipId == 0) {
  1017. // return;
  1018. // }
  1019. // $n = count((array) ctx()->store->equip) + 1;
  1020. //
  1021. // for ($index = 0; $index < $num; $index++) {
  1022. // $Equip = new Ins_Equip();
  1023. // $Equip->uid = $n;
  1024. // $Equip->typeId = $equipId;
  1025. // $Equip->qual = GameConfig::equip_getItem($equipId)->qual;
  1026. // ctx()->store->equip->$n = $Equip;
  1027. // $n += 1;
  1028. // }
  1029. // }
  1030. /**
  1031. * 得到金币或是图纸的时候校验下,是否满足装备升级条件,满足则tip字段设置为1 废弃
  1032. */
  1033. // public static function checkEquipUpgradeTip() {
  1034. // $equipDic = ctx()->store->equipPosition;
  1035. // if ($equipDic != null) {
  1036. // foreach ($equipDic as $k => &$equip) {
  1037. // $equip = new Ins_EquipPosition($equip);
  1038. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  1039. // $needGold = $lvMo->needGold;
  1040. // $needItemNum = $lvMo->needItemNum;
  1041. // $neeItemId = $equip->mo()->costTuzhiId;
  1042. //
  1043. // if (ctx()->baseInfo->gold >= $needGold && StlUtil::dictHasProperty(ctx()->store->items, $neeItemId) && ctx()->store->items->$neeItemId >= $needItemNum) {
  1044. // $equipDic->$k->tip = 1; //绿点是每次得到金币或是图纸了,只要满足升级条件都变绿
  1045. // }
  1046. // }
  1047. // }
  1048. // ctx()->store->equipPosition = $equipDic;
  1049. // }
  1050. /**
  1051. * 新宝石入库
  1052. */
  1053. public static function PutGemIdInStore($id, $num = 1) {
  1054. for ($i = 0; $i < $num; $i++) {
  1055. $gem = self::initGem($id);
  1056. $length = $gem->uid;
  1057. ctx()->store->gemStore->$length = $gem;
  1058. }
  1059. }
  1060. public static function PutGemInStore($gem, $num = 1) {
  1061. for ($i = 0; $i < $num; $i++) {
  1062. $length = $gem->uid;
  1063. ctx()->store->gemStore->$length = $gem;
  1064. }
  1065. }
  1066. public static function initGem($id) {
  1067. $length = ctx()->store->gemLength;
  1068. $length += 1;
  1069. $gem = new Ins_Gem();
  1070. $gem->uid = $length;
  1071. $gem->typeId = $id;
  1072. $gem->predicateId = self::RandomGemPredicateId($id);
  1073. $tag = self::CheckNewGemTip($gem);
  1074. $gem->isNew = $tag;
  1075. ctx()->store->gemLength = $length;
  1076. return $gem;
  1077. }
  1078. /**
  1079. * 从仓库移除宝石
  1080. */
  1081. public static function RemoveGemInStore($uid) {
  1082. if (StlUtil::dictHasProperty(ctx()->store->gemStore, $uid)) {
  1083. StlUtil::dictRemove(ctx()->store->gemStore, $uid);
  1084. }
  1085. return 0;
  1086. }
  1087. /**
  1088. * 新宝石随机词条 临时等刚哥
  1089. */
  1090. public static function RandomGemPredicateId($id) {
  1091. $mo = GameConfig::gem_getItem($id);
  1092. my_Assert(null != $mo, "找不到宝石{$id}的配置数据");
  1093. if ($mo->isfixed_predicateId == 1) {
  1094. return $mo->predicateId;
  1095. }
  1096. $posId = $mo->position;
  1097. $qual = $mo->qual;
  1098. $arr = array();
  1099. $predicateMo = GameConfig::predicate();
  1100. foreach ($predicateMo as $key => $value) {
  1101. if ($value->positions != null) {
  1102. $list = explode(',', $value->positions);
  1103. if ($value->qual == $qual && in_array($posId, $list) && $value->attachTarget == "gem") {
  1104. $arr[] = $value->id;
  1105. }
  1106. }
  1107. }
  1108. if (count($arr) <= 0) {
  1109. return 40;
  1110. }
  1111. my_Assert(count($arr) > 0, "宝石没有对应词条信息");
  1112. $n = mt_rand(0, count($arr) - 1);
  1113. return $arr[$n];
  1114. //return 40;
  1115. }
  1116. /**
  1117. * 新宝石提示
  1118. */
  1119. public static function CheckNewGemTip($gem) {
  1120. $gemStore = ctx()->store->gemStore;
  1121. $tag = false;
  1122. foreach ($gemStore as $k => $ins_gem) {
  1123. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  1124. $tag = true;
  1125. break;
  1126. }
  1127. }
  1128. return $tag == true ? 0 : 1;
  1129. }
  1130. //临时代码
  1131. // public static function InitGemInfo() {
  1132. // if(count((array)ctx()->store->gemStore) > 0){
  1133. // return;
  1134. // }
  1135. //
  1136. // $index = 0;
  1137. // $gem = GameConfig::gem();
  1138. //
  1139. // for ($i = 1; $i <=21; $i++) {
  1140. // foreach ($gem as $key => $value) {
  1141. // if($value->id == $i){
  1142. // self::PutGemInStore($value->typeId);
  1143. // }
  1144. //
  1145. // }
  1146. // }
  1147. //
  1148. //
  1149. //
  1150. //
  1151. // }
  1152. }