StoreProc.php 52 KB

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