StoreProc.php 53 KB

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