StoreProc.php 54 KB

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