StoreProc.php 48 KB

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