StoreProc.php 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078
  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: # 6415 卸下装备
  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. case CmdCode::store_pet_removeNewTip: # 6421 移除宠物上的新的标志
  60. return StoreProc::Pet_RemoveNewTip();
  61. case CmdCode::store_pet_changeFightPosition: # 6422 出战/替换/上阵
  62. return StoreProc::Pet_ChangeFightPosition();
  63. case CmdCode::store_pet_selectShowPet: # 6423 展示空闲灵宠
  64. return StoreProc::Pet_SelectShowPet();
  65. case CmdCode::store_pet_levelUpgrade: # 6424 灵宠等级提升
  66. return StoreProc::Pet_LevelUpgrade();
  67. case CmdCode::store_pet_compose: # 6425 宠物合成
  68. return StoreProc::Pet_Compose();
  69. case CmdCode::store_pet_onekeyCompose: # 6426 宠物一键合成
  70. return StoreProc::Pet_OnekeyCompose();
  71. case CmdCode::store_pet_downGradingLevel: # 6427 宠物降级
  72. return StoreProc::Pet_DownGradingLevel();
  73. case CmdCode::store_pet_downGradingQual: # 6428 宠物降品
  74. return StoreProc::Pet_DownGradingQual();
  75. case CmdCode::store_pet_breedEgg: # 6429 孵化宠物
  76. return StoreProc::Pet_BreedEgg();
  77. case CmdCode::store_pet_fastBreedEgg: # 6430 加速孵化宠物
  78. return StoreProc::Pet_FastBreedEgg();
  79. case CmdCode::store_pet_receiveBreedPet: # 6431 正常孵化完成点击领取
  80. return StoreProc::Pet_ReceiveBreedPet();
  81. case CmdCode::store_pet_unlockBreedLocation: # 6432 解锁孵化位置
  82. return StoreProc::Pet_UnlockBreedLocation();
  83. default:
  84. Err(ErrCode::cmd_err);
  85. }
  86. }
  87. /**
  88. * 6432 解锁孵化位置
  89. * @return Resp
  90. */
  91. public static function Pet_UnlockBreedLocation() {
  92. list($slotId) = req()->paras;
  93. $list = explode(';',GameConfig::glc2()->Pet_BreedLocationUnlockInfo);
  94. foreach ($list as $value) {
  95. $s = explode(',', $value);
  96. if($s[0] == $slotId){
  97. my_Assert(ctx()->baseInfo->cash >= $s[1], ErrCode::notenough_cash_msg);
  98. ctx()->base()->Consume_Cash($s[1]);
  99. $breed = new Ins_BreedEggSlot(ctx()->store->breedEggLocation->$slotId);
  100. $breed->unlock = 1;
  101. ctx()->store()->breedEggLocation->$slotId = $breed;
  102. break;
  103. }
  104. }
  105. UserProc::updateUserInfo();
  106. return Resp::ok(array(
  107. 'cash' => ctx()->baseInfo->cash,
  108. 'store' => ctx()->store,
  109. ));
  110. }
  111. /**
  112. * 6431 正常孵化完成点击领取
  113. * @return Resp
  114. */
  115. public static function Pet_ReceiveBreedPet() {
  116. list($slotId) = req()->paras;
  117. $ins_breed = new Ins_BreedEggSlot(ctx()->store()->breedEggLocation->$slotId);
  118. my_Assert($ins_breed->eggId != 0, ErrCode::user_store_NoExistBreedEgg);
  119. my_Assert($ins_breed->unlock == 1, ErrCode::user_store_SlotNotUnlocked);
  120. my_Assert(now() >= $ins_breed->endTs, ErrCode::user_store_NoCompleteBreed);
  121. StoreProc::AddMultiItemInStore($ins_breed->mo()->reward);
  122. //随机一个灵宠
  123. $str = explode(';', $ins_breed->mo()->per);
  124. $newPet = self::RandObtainPet($str);
  125. $uid = 0;
  126. if($newPet != null){
  127. $uid = $newPet->uid;
  128. ctx()->store()->pet->$uid = $newPet;
  129. }
  130. UserProc::updateUserInfo();
  131. return Resp::ok(array(
  132. 'cash' => ctx()->baseInfo->cash,
  133. 'store' => ctx()->store,
  134. 'newPetUid'=>$uid,
  135. ));
  136. }
  137. /**
  138. * 6430 加速孵化宠物
  139. * @return Resp
  140. */
  141. public static function Pet_FastBreedEgg() {
  142. list($slotId) = req()->paras;
  143. $ins_breed = new Ins_BreedEggSlot(ctx()->store()->breedEggLocation->$slotId);
  144. my_Assert($ins_breed->eggId != 0, ErrCode::user_store_NoExistBreedEgg);
  145. my_Assert($ins_breed->unlock == 1, ErrCode::user_store_SlotNotUnlocked);
  146. my_Assert(now() < $ins_breed->endTs, ErrCode::user_store_CompleteBreed);
  147. $num = $ins_breed->mo()->breedTs/60/10;
  148. $cash_one = $ins_breed->mo()->fastBreed_cost/$num;
  149. $ts = $ins_breed->endTs - now();
  150. $costNum = ceil($ts/60/10);
  151. my_Assert(ctx()->baseInfo->cash >= $costNum*$cash_one, ErrCode::notenough_cash_msg);
  152. ctx()->base()->Consume_Cash($costNum*$cash_one);
  153. StoreProc::AddMultiItemInStore($ins_breed->mo()->reward);
  154. //随机一个灵宠
  155. $str = explode(';', $ins_breed->mo()->per);
  156. $newPet = self::RandObtainPet($str);
  157. $uid = 0;
  158. if($newPet != null){
  159. $uid = $newPet->uid;
  160. ctx()->store()->pet->$uid = $newPet;
  161. }
  162. UserProc::updateUserInfo();
  163. return Resp::ok(array(
  164. 'cash' => ctx()->baseInfo->cash,
  165. 'store' => ctx()->store,
  166. 'newPetUid'=>$uid,
  167. ));
  168. }
  169. /**
  170. * 初始化一个宠物
  171. * @param type $rarity
  172. * @param type $qual
  173. * @param type $petType
  174. */
  175. public static function RandObtainPet($str) {
  176. //随机一个灵宠
  177. $randNum = rand(1,10000);
  178. $start = 0;
  179. $end = 0;
  180. $rarity = 0;
  181. $qual = 0;
  182. $petType = 0;
  183. foreach ($str as $key => $value) {
  184. $s = explode(',', $value);
  185. $end += $s[3]*100;
  186. if($randNum > $start && $randNum <= $end){
  187. $rarity = $s[0];
  188. $qual = $s[1];
  189. $petType = $s[2];
  190. break;
  191. }
  192. $start = $end;
  193. }
  194. $dic = GameConfig::pet();
  195. $petArr = array();
  196. foreach ($dic as $typeId => $mo) {
  197. if($mo->petType == $petType && $mo->qual == $qual && $mo->rarity == $rarity){
  198. $petArr[] = $typeId;
  199. }
  200. }
  201. $typeId = 0;
  202. if(count($petArr) > 0){
  203. $num = rand(0,count($petArr)-1);
  204. $typeId = $petArr[$num];
  205. }
  206. if($typeId != 0){
  207. return self::initPet($typeId);
  208. }
  209. return null;
  210. }
  211. /**
  212. * 6429 孵化宠物
  213. * @return Resp
  214. */
  215. public static function Pet_BreedEgg() {
  216. list($slotId,$eggId) = req()->paras;
  217. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $eggId), ErrCode::user_store_NoItem);
  218. $mo = GameConfig::item_getItem($eggId);
  219. my_Assert($mo != null, ErrCode::err_const_no);
  220. my_Assert($mo->itemType == 103, ErrCode::user_store_NoItem);
  221. $ins_breed = new Ins_BreedEggSlot(ctx()->store()->breedEggLocation->$slotId);
  222. my_Assert($ins_breed->eggId == 0 && $ins_breed->unlock == 1, ErrCode::user_store_NoBreedSlot);
  223. ctx()->store()->removeItem($eggId, 1);
  224. //$ins_breed = ctx()->store()->breedEggLocation->$slot;
  225. $ins_breed->eggId = $eggId;
  226. $ts = $ins_breed->mo()->breedTs;
  227. $ins_breed->endTs = now()+$ts;
  228. ctx()->store()->breedEggLocation->$slotId = $ins_breed;
  229. UserProc::updateUserInfo();
  230. return Resp::ok(array(
  231. //'gold' => ctx()->baseInfo->gold,
  232. 'store' => ctx()->store,
  233. ));
  234. }
  235. /**
  236. * 6428 宠物降品
  237. */
  238. public static function Pet_DownGradingQual() {
  239. list($uid) = req()->paras;
  240. $petDic = ctx()->store->pet;
  241. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  242. $ins_pet = new Ins_Pet($petDic->$uid);
  243. $NotDownGradingList = explode(',', glc()->equipQual_NotDownGrading);
  244. my_Assert(!in_array($ins_pet->qual, $NotDownGradingList), ErrCode::user_store_equip_minQual);
  245. $itemNum = 0;
  246. for ($i = 1; $i < $ins_pet->level; $i++) {
  247. $mo = GameConfig::pet_levelupgrade_getItem($ins_pet->mo()->rarity, $ins_pet->qual, $i);
  248. $itemNum += $mo->costItem;
  249. }
  250. StoreProc::AddMultiItemInStore(6 . ',' . $itemNum);
  251. self::ComposeMaterial_Fallback_Pet($ins_pet->mo()->petType, $ins_pet->qual);
  252. $ins_pet->level = 1;
  253. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  254. foreach ($sList2 as $str3) {
  255. $s = explode(',', $str3);
  256. if (in_array($ins_pet->qual, $s)) {
  257. $ins_pet->qual = $s[0];
  258. break;
  259. }
  260. }
  261. ctx()->store->pet->$uid = $ins_pet;
  262. //FightProc::Ranking_FightPower();
  263. UserProc::updateUserInfo();
  264. return Resp::ok(array(
  265. //'gold' => ctx()->baseInfo->gold,
  266. 'store' => ctx()->store,
  267. ));
  268. }
  269. private static function ComposeMaterial_Fallback_Pet($type, $qual) {
  270. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  271. foreach ($sList2 as $str) {
  272. $s = explode(',', $str);
  273. if (in_array($qual, $s)) {
  274. $max = $qual;
  275. $min = $s[0];
  276. $num = 0;
  277. for ($i = $min; $i < $max; $i++) {
  278. $mo = GameConfig::pet_compose_getItem($i);
  279. $num += explode(',', $mo->compose_condition)[2];
  280. }
  281. $typeId = self::ComposeMaterial($type, $min,902);
  282. StoreProc::AddMultiItemInStore($typeId . ',' . $num);
  283. break;
  284. }
  285. }
  286. }
  287. /*
  288. * 6427 宠物降级
  289. */
  290. public static function Pet_DownGradingLevel() {
  291. list($uid) = req()->paras; //宠物uid
  292. $petDic = ctx()->store->pet;
  293. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  294. $ins_pet = new Ins_Pet($petDic->$uid);
  295. my_Assert($ins_pet->level > 1, ErrCode::user_store_equip_minlevel);
  296. $itemNum = 0;
  297. for ($i = 1; $i < $ins_pet->level; $i++) {
  298. $mo = GameConfig::pet_levelupgrade_getItem($ins_pet->mo()->rarity, $ins_pet->qual, $i);
  299. $itemNum += $mo->costItem;
  300. }
  301. StoreProc::AddMultiItemInStore(6 . ',' . $itemNum);
  302. $ins_pet->level = 1;
  303. ctx()->store->pet->$uid = $ins_pet;
  304. //FightProc::Ranking_FightPower();
  305. UserProc::updateUserInfo();
  306. return Resp::ok(array(
  307. //'gold' => ctx()->baseInfo->gold,
  308. 'store' => ctx()->store,
  309. ));
  310. }
  311. /**
  312. * 6426 宠物一键合成
  313. * @return type
  314. */
  315. public static function Pet_OnekeyCompose() {
  316. $store = ctx()->store(true);
  317. $petDic = $store->pet;
  318. $arr = array(); # 待处理装备临时数组
  319. $composePet = array(); # 合成记录
  320. foreach ($petDic as $pet) {
  321. if ($pet->qual < 4) { # 4 品以上的不参与合成
  322. $arr[] = new Ins_Pet($pet);
  323. }
  324. }
  325. while (count($arr) > 0) { # 循环处理每一个装备
  326. $pet_compose = array_pop($arr); # 从末尾弹出一个元素做合成运算
  327. if (null == $pet_compose) { # 防御空对象
  328. break;
  329. }
  330. $eqQualCfg = GameConfig::pet_compose_getItem($pet_compose->qual); # 按照品阶查询合成配置数据
  331. my_Assert(null != $eqQualCfg, ErrCode::err_const_no); # 防御配置数据错误
  332. list($type, $costQual, $num) = explode(',', $eqQualCfg->compose_condition); # 从配置提取合成条件
  333. $composeArr = array(); # 消耗集合
  334. foreach ($arr as $v) { # 从剩余元素中查找合成所需
  335. if ($v->qual == $costQual) { # 同品阶
  336. if (($type == 1) ? $v->typeId == $pet_compose->typeId # # type: 1 与本体相同 2 同部位即可
  337. : $v->mo()->petType == $pet_compose->mo()->petType) {
  338. $composeArr[] = $v; # 成为消耗品
  339. }
  340. if (count($composeArr) >= $num) { # 达到消耗数量就停
  341. break;
  342. }
  343. }
  344. }
  345. if (count($composeArr) >= $num) { # 合成的回收 不合成的可不能给回收了
  346. $uid = $pet_compose->uid;
  347. $newPet = self::ComposeNewPet($pet_compose); # 原地合成
  348. self::petLevelChange_Material_Recovery($newPet->mo()->rarity, $newPet->qual, $newPet->level); # 回收材料
  349. $newPet->level = 1;
  350. $petDic->$uid = $newPet;
  351. $composePet[] = $uid; # 添加合成记录
  352. foreach ($composeArr as $val) { # 回收消耗的装备中所含材料
  353. self::petLevelChange_Material_Recovery($val->mo()->rarity, $val->qual, $val->level); # 回收材料
  354. StlUtil::dictRemove(ctx()->store(true)->pet, $val->uid); # 背包删除
  355. if(ctx()->store(true)->petUid_fight_position == $val->uid){
  356. ctx()->store(true)->petUid_fight_position = 0;
  357. }
  358. foreach (ctx()->store(true)->petUids_supportFight_position as $k => $pUid) {
  359. if($pUid == $val->uid){
  360. StlUtil::dictRemove(ctx()->store(true)->petUids_supportFight_position, $k);
  361. break;
  362. }
  363. }
  364. StlUtil::arrayRemove($arr, $val); # 从arr中删掉已消耗装备
  365. }
  366. }
  367. }
  368. UserProc::updateUserInfo(); # 回存玩家数据
  369. return Resp::ok(array(# # 返回给客户端的数据
  370. 'store' => ctx()->store,
  371. 'composeEquip' => $composePet,
  372. 'task' => ctx()->task,
  373. ));
  374. }
  375. /**
  376. * 6425 宠物合成
  377. * @return Resp
  378. */
  379. public static function Pet_Compose() {
  380. list($uid, $petUids_cost, $composeMaterial_typeIds) = req()->paras;
  381. $petDic = ctx()->store->pet;
  382. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  383. $ins_pet = new Ins_Pet($petDic->$uid);
  384. my_Assert($ins_pet->qual < 11, ErrCode::user_store_equip_qualMaxLimit);
  385. $composeMo = GameConfig::pet_compose_getItem($ins_pet->qual);
  386. my_Assert(null != $composeMo, ErrCode::err_const_no);
  387. $arr = explode(',', $composeMo->compose_condition);
  388. $type = $arr[0];
  389. $costQual = $arr[1];
  390. $num = $arr[2];
  391. $all_num = 0;
  392. $materialItemType = 0;
  393. $materialItemNum = 0;
  394. if ($type == 2 && $composeMaterial_typeIds != null) {//部位去校验
  395. $str = explode(',', $composeMaterial_typeIds);
  396. $materialItemType = $str[0];
  397. $materialItemNum = count($str);
  398. foreach ($str as $s) {
  399. $composeMaterial_itemTypeId = self::ComposeMaterial($ins_pet->mo()->petType, $costQual,902);
  400. my_Assert($composeMaterial_itemTypeId == $s, ErrCode::user_store_equip_composeMaterialErr);
  401. $all_num += 1;
  402. }
  403. }
  404. if ($petUids_cost != null) {
  405. $costPetsArr = explode(',', $petUids_cost);
  406. $all_num += count($costPetsArr);
  407. foreach ($costPetsArr as $pUid) {
  408. my_Assert(StlUtil::dictHasProperty($petDic, $pUid), ErrCode::user_store_NotExistPet);
  409. my_Assert(ctx()->store(true)->petUid_fight_position != $pUid, ErrCode::user_store_NotSelectPet_fight);
  410. my_Assert(!in_array($pUid, ctx()->store(true)->petUids_supportFight_position), ErrCode::user_store_NotSelectPet_supportfight);
  411. $costIns_pet = new Ins_Pet($petDic->$pUid);
  412. my_Assert($costIns_pet->qual == $costQual, ErrCode::user_store_equipMaterialQualErr);
  413. if ($type == 1) {//本体
  414. my_Assert($costIns_pet->typeId == $ins_pet->typeId, ErrCode::user_store_equipMaterialTypeErr);
  415. } else {
  416. my_Assert($costIns_pet->mo()->petType == $ins_pet->mo()->petType, ErrCode::user_store_equipMaterialTypeErr);
  417. }
  418. }
  419. }
  420. my_Assert($all_num == $num, ErrCode::user_store_equipMaterialNumErr);
  421. ctx()->store(true)->pet->$uid = self::ComposeNewPet($ins_pet);
  422. //消耗的装备 回收
  423. if ($petUids_cost != null) {
  424. $costPetsArr = explode(',', $petUids_cost);
  425. foreach ($costPetsArr as $pUid) {
  426. $costIns_Equip = new Ins_Pet($petDic->$pUid);
  427. self::petLevelChange_Material_Recovery($costIns_Equip->mo()->rarity, $costIns_Equip->qual, $costIns_Equip->level);
  428. StlUtil::dictRemove(ctx()->store(true)->pet, $pUid);
  429. }
  430. }
  431. if ($materialItemType != 0) {
  432. ctx()->store(true)->removeItem($materialItemType, $materialItemNum);
  433. }
  434. UserProc::updateUserInfo();
  435. return Resp::ok(array(
  436. 'store' => ctx()->store,
  437. 'task' => ctx()->task,
  438. ));
  439. }
  440. /**
  441. * 装备等级提升 消耗的金币图纸回收
  442. * @param type $rarity
  443. * @param type $qual
  444. * @param type $posId
  445. * @param type $level
  446. */
  447. public static function petLevelChange_Material_Recovery($rarity, $qual,$level) {
  448. $num = 0;
  449. for ($i = 1; $i <= $level - 1; $i++) {
  450. $mo = GameConfig::pet_levelupgrade_getItem($rarity, $qual, $i);
  451. $num += $mo->costItem;
  452. }
  453. if ($num > 0) {
  454. StoreProc::AddMultiItemInStore(6 . ',' . $num);
  455. }
  456. }
  457. /**
  458. * 合成一个新的装备
  459. * @param type Ins_Equip
  460. */
  461. public static function ComposeNewPet(&$ins_pet) {
  462. $newPetTypeId = $ins_pet->typeId;
  463. $qual = $ins_pet->qual + 1;
  464. if ($ins_pet->qual < 4) {
  465. //$newEquipTypeId = substr($ins_pet->typeId, 0, strlen($ins_equip->typeId) - 5);
  466. $rarity = substr($ins_pet->typeId, -2);
  467. $mo = GameConfig::pet_getItem($ins_pet->typeId);
  468. $newPetTypeId = $mo->type. "0" . $qual . $rarity;
  469. }
  470. $ins_pet->typeId = $newPetTypeId;
  471. $ins_pet->qual = $qual;
  472. return $ins_pet;
  473. }
  474. /**
  475. *6424 灵宠等级提升
  476. * @return Resp
  477. */
  478. public static function Pet_LevelUpgrade(){
  479. list($uid) = req()->paras; //装备uid
  480. my_Assert(StlUtil::dictHasProperty(ctx()->store->pet, $uid), ErrCode::user_store_NotExistPet);
  481. $ins_pet = new Ins_Pet(ctx()->store->pet->$uid);
  482. my_Assert($ins_pet->level < $ins_pet->Pet_MaxLevel(), ErrCode::user_store_LevelLimit);
  483. $mo = $ins_pet->petLevelMo();
  484. $costTuzhiId = 6;
  485. $tuzhiNum = 0;
  486. if (StlUtil::dictHasProperty(ctx()->store->items, $costTuzhiId)) {
  487. $tuzhiNum = ctx()->store->items->$costTuzhiId;
  488. }
  489. my_Assert($tuzhiNum >= $mo->costItem, ErrCode::notenough_item);
  490. ctx()->store(true)->removeItem($costTuzhiId,$mo->costItem);
  491. $ins_pet->level += 1;
  492. ctx()->store->pet->$uid = $ins_pet;
  493. UserProc::updateUserInfo();
  494. return Resp::ok(array(
  495. 'store' => ctx()->store,
  496. ));
  497. }
  498. /**
  499. * 6423 展示空闲灵宠
  500. * @return Resp
  501. */
  502. public static function Pet_SelectShowPet(){
  503. list($uid) = req()->paras;
  504. $petDic = ctx()->store->pet;
  505. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  506. my_Assert(count(ctx()->store()->mainShowPetList)< GameConfig::glc2()->Pet_MainShowPetList , ErrCode::user_store_ShowPetNumLimit);
  507. my_Assert(ctx()->store->petUid_fight_position != $uid, ErrCode::user_store_NotSelectPet_fight);
  508. my_Assert(!in_array($uid, ctx()->store->petUids_supportFight_position), ErrCode::user_store_NotSelectPet_supportfight);
  509. if(in_array($uid,ctx()->store()->mainShowPetList)){
  510. StlUtil::arrayRemove(ctx()->store()->mainShowPetList, $uid);
  511. } else {
  512. ctx()->store()->mainShowPetList[] = $uid;
  513. }
  514. UserProc::updateUserInfo();
  515. return Resp::ok(array());
  516. }
  517. /**
  518. * 6422 出战/替换/上阵
  519. */
  520. public static function Pet_ChangeFightPosition() {
  521. list($type, $uid, $index) = req()->paras;
  522. if ($type == 1) {//出战、替换
  523. ctx()->store(true)->petUid_fight_position = $uid;
  524. } else if ($type == 2) {
  525. ctx()->store(true)->petUids_supportFight_position->$index = $uid;
  526. }
  527. if ($type == 0 && $index == 0 && $uid != 0) {//上阵点击空白的地方
  528. if (ctx()->store(true)->petUid_fight_position == 0) {
  529. ctx()->store(true)->petUid_fight_position = $uid;
  530. } else {
  531. if (count(StlUtil::dictToArray(ctx()->store(true)->petUids_supportFight_position)) == 0) {
  532. $key = 1;
  533. ctx()->store(true)->petUids_supportFight_position->$key = $uid;
  534. } else {
  535. for ($i = 1; $i <= 2; $i++) {
  536. if (!StlUtil::dictHasProperty(ctx()->store(true)->petUids_supportFight_position, $i) || ctx()->store(true)->petUids_supportFight_position->$i == 0) {
  537. ctx()->store(true)->petUids_supportFight_position->$i = $uid;
  538. break;
  539. }
  540. }
  541. }
  542. }
  543. }
  544. UserProc::updateUserInfo();
  545. return Resp::ok(array());
  546. }
  547. /**
  548. * 6421 移除宠物上的新的标志
  549. */
  550. public static function Pet_RemoveNewTip() {
  551. list($uid) = req()->paras;
  552. $petDic = ctx()->store->pet;
  553. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  554. ctx()->store->pet->$uid->isNew = 0;
  555. UserProc::updateUserInfo();
  556. return Resp::ok(array());
  557. }
  558. /**
  559. * 6420 降品
  560. */
  561. public static function Equip_DownGradingQual() {
  562. list($uid) = req()->paras;
  563. $equipDic = ctx()->store->equip;
  564. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  565. $ins_equip = new Ins_Equip($equipDic->$uid);
  566. $NotDownGradingList = explode(',', glc()->equipQual_NotDownGrading);
  567. my_Assert(!in_array($ins_equip->qual, $NotDownGradingList), ErrCode::user_store_equip_minQual);
  568. self::GoldTuzhi_Fallback_Level($ins_equip);
  569. self::ComposeMaterial_Fallback($ins_equip->mo()->position, $ins_equip->qual);
  570. $ins_equip->level = 1;
  571. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  572. foreach ($sList2 as $str3) {
  573. $s = explode(',', $str3);
  574. if (in_array($ins_equip->qual, $s)) {
  575. $ins_equip->qual = $s[0];
  576. break;
  577. }
  578. }
  579. ctx()->store->equip->$uid = $ins_equip;
  580. FightProc::Ranking_FightPower();
  581. UserProc::updateUserInfo();
  582. return Resp::ok(array(
  583. 'gold' => ctx()->baseInfo->gold,
  584. 'store' => ctx()->store,
  585. ));
  586. }
  587. private static function ComposeMaterial_Fallback($posId, $qual) {
  588. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  589. foreach ($sList2 as $str) {
  590. $s = explode(',', $str);
  591. if (in_array($qual, $s)) {
  592. $max = $qual;
  593. $min = $s[0];
  594. $num = 0;
  595. for ($i = $min; $i < $max; $i++) {
  596. $mo = GameConfig::equip_compose_getItem($i);
  597. $num += explode(',', $mo->compose_condition)[2];
  598. }
  599. $typeId = self::ComposeMaterial($posId, $min);
  600. StoreProc::AddMultiItemInStore($typeId . ',' . $num);
  601. break;
  602. }
  603. }
  604. }
  605. private static function ComposeMaterial($posId, $qual,$type = 901) {
  606. $itemDic = GameConfig::item();
  607. foreach ($itemDic as $typeId => $mo) {
  608. if ($mo->itemType == $type && $typeId % 100 == $posId && floor($typeId / 100) % 100 == $qual) {
  609. return $typeId;
  610. }
  611. }
  612. return null;
  613. }
  614. private static function GoldTuzhi_Fallback_Level($ins_equip) {
  615. $gold = 0;
  616. $itemNum = 0;
  617. for ($i = 1; $i < $ins_equip->level; $i++) {
  618. $mo = GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $i);
  619. $gold += $mo->needGold;
  620. $itemNum += $mo->needItemNum;
  621. }
  622. $tuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  623. StoreProc::AddMultiItemInStore($tuzhiId . ',' . $itemNum);
  624. ctx()->base(true)->Add_Gold($gold);
  625. }
  626. /*
  627. * 6419 降级
  628. */
  629. public static function Equip_DownGradingLevel() {
  630. list($uid) = req()->paras; //装备uid
  631. $equipDic = ctx()->store->equip;
  632. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  633. $ins_equip = new Ins_Equip($equipDic->$uid);
  634. my_Assert($ins_equip->level > 1, ErrCode::user_store_equip_minlevel);
  635. self::GoldTuzhi_Fallback_Level($ins_equip);
  636. $ins_equip->level = 1;
  637. ctx()->store->equip->$uid = $ins_equip;
  638. FightProc::Ranking_FightPower();
  639. UserProc::updateUserInfo();
  640. return Resp::ok(array(
  641. 'gold' => ctx()->baseInfo->gold,
  642. 'store' => ctx()->store,
  643. ));
  644. }
  645. /**
  646. * 6417 装备合成
  647. * @return type
  648. */
  649. public static function Equip_Compose() {
  650. list($uid, $equipUids_cost, $composeMaterial_typeIds) = req()->paras;
  651. $store = ctx()->store(true);
  652. $equipDic = ctx()->store->equip;
  653. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  654. $ins_equip = new Ins_Equip($equipDic->$uid);
  655. my_Assert($ins_equip->qual < 16, ErrCode::user_store_equip_qualMaxLimit);
  656. $composeMo = GameConfig::equip_compose_getItem($ins_equip->qual);
  657. my_Assert(null != $composeMo, ErrCode::err_const_no);
  658. $arr = explode(',', $composeMo->compose_condition);
  659. $type = $arr[0];
  660. $costQual = $arr[1];
  661. $num = $arr[2];
  662. $all_num = 0;
  663. $materialItemType = 0;
  664. $materialItemNum = 0;
  665. if ($type == 2 && $composeMaterial_typeIds != null) {//部位去校验
  666. $str = explode(',', $composeMaterial_typeIds);
  667. $materialItemType = $str[0];
  668. $materialItemNum = count($str);
  669. foreach ($str as $s) {
  670. $composeMaterial_itemTypeId = self::ComposeMaterial($ins_equip->mo()->position, $costQual);
  671. my_Assert($composeMaterial_itemTypeId == $s, ErrCode::user_store_equip_composeMaterialErr);
  672. $all_num += 1;
  673. }
  674. }
  675. if ($equipUids_cost != null) {
  676. $costEquipsArr = explode(',', $equipUids_cost);
  677. $all_num += count($costEquipsArr);
  678. foreach ($costEquipsArr as $eqUid) {
  679. my_Assert(StlUtil::dictHasProperty($equipDic, $eqUid), ErrCode::user_store_NotExistEquip);
  680. $costIns_Equip = new Ins_Equip($equipDic->$eqUid);
  681. my_Assert($costIns_Equip->qual == $costQual, ErrCode::user_store_equipMaterialQualErr);
  682. if ($type == 1) {//本体
  683. my_Assert($costIns_Equip->typeId == $ins_equip->typeId, ErrCode::user_store_equipMaterialTypeErr);
  684. } else {
  685. my_Assert($costIns_Equip->mo()->position == $ins_equip->mo()->position, ErrCode::user_store_equipMaterialTypeErr);
  686. }
  687. }
  688. }
  689. my_Assert($all_num == $num, ErrCode::user_store_equipMaterialNumErr);
  690. ctx()->store(true)->equip->$uid = self::ComposeNewEquip($ins_equip);
  691. //消耗的装备 回收
  692. if ($equipUids_cost != null) {
  693. $costEquipsArr = explode(',', $equipUids_cost);
  694. foreach ($costEquipsArr as $eqUid) {
  695. $costIns_Equip = new Ins_Equip($equipDic->$eqUid);
  696. self::equipLevelUp_Material_Recovery($costIns_Equip->mo()->rarity, $costIns_Equip->qual, $costIns_Equip->mo()->position, $costIns_Equip->level);
  697. StlUtil::dictRemove(ctx()->store(true)->equip, $eqUid);
  698. for ($i = 1; $i <= 6; $i++) { # 清理装备信息
  699. if ($store->equipLocation->$i == $eqUid) {
  700. StlUtil::dictRemove($store->equipLocation, $i);
  701. }
  702. }
  703. }
  704. }
  705. if ($materialItemType != 0) {
  706. ctx()->store(true)->removeItem($materialItemType, $materialItemNum);
  707. }
  708. TaskProc::OnEquipComposeNum();
  709. FightProc::Ranking_FightPower();
  710. UserProc::updateUserInfo();
  711. return Resp::ok(array(
  712. 'gold' => ctx()->baseInfo->gold,
  713. 'store' => ctx()->store,
  714. 'task' => ctx()->task,
  715. ));
  716. }
  717. /**
  718. * 装备等级提升 消耗的金币图纸回收
  719. * @param type $rarity
  720. * @param type $qual
  721. * @param type $posId
  722. * @param type $level
  723. */
  724. public static function equipLevelUp_Material_Recovery($rarity, $qual, $posId, $level) {
  725. $gold = 0;
  726. $tuzhi = 0;
  727. $tuzhiId = GameConfig::equip_position_getItem($posId)->costTuzhiId;
  728. for ($i = 1; $i <= $level - 1; $i++) {
  729. $mo = GameConfig::equip_levelupgrade_getItem($rarity, $qual, $posId, $i);
  730. $gold += $mo->needGold;
  731. $tuzhi += $mo->needItemNum;
  732. }
  733. if ($gold > 0) {
  734. StoreProc::AddMultiItemInStore("1," . $gold);
  735. StoreProc::AddMultiItemInStore($tuzhiId . ',' . $tuzhi);
  736. }
  737. }
  738. /**
  739. * 合成一个新的装备
  740. * @param type Ins_Equip
  741. */
  742. public static function ComposeNewEquip(&$ins_equip) {
  743. $newEquipTypeId = $ins_equip->typeId;
  744. $qual = $ins_equip->qual + 1;
  745. if ($ins_equip->qual < 4) {
  746. $newEquipTypeId = substr($ins_equip->typeId, 0, strlen($ins_equip->typeId) - 5);
  747. $rarity = substr($ins_equip->typeId, -3);
  748. $newEquipTypeId = $newEquipTypeId . "0" . $qual . $rarity;
  749. }
  750. $ins_equip->typeId = $newEquipTypeId;
  751. $ins_equip->qual = $qual;
  752. return $ins_equip;
  753. }
  754. /**
  755. * 6418 装备一键合成 (gwang 2024年11月16日)
  756. * @return type
  757. */
  758. public static function Equip_OnekeyCompose_new() {
  759. $store = ctx()->store(true);
  760. $equipDic = $store->equip;
  761. $arr = array(); # 待处理装备临时数组
  762. $composeEquip = array(); # 合成记录
  763. foreach ($equipDic as $equip) {
  764. if ($equip->qual < 4) { # 4 品以上的不参与合成
  765. $arr[] = new Ins_Equip($equip);
  766. }
  767. }
  768. usort($arr, function ($a, $b) { # 按等级大小排序, 等级大的放最后
  769. if ($a->level > $b->level) {
  770. return 1;
  771. } else if ($a->level == $b->level) {
  772. return 0;
  773. } else {
  774. return -1;
  775. }
  776. });
  777. while (count($arr) > 0) { # 循环处理每一个装备
  778. $equip_compose = array_pop($arr); # 从末尾弹出一个元素做合成运算
  779. if (null == $equip_compose) { # 防御空对象
  780. continue;
  781. }
  782. $eqQualCfg = GameConfig::equip_compose_getItem($equip_compose->qual); # 按照品阶查询合成配置数据
  783. my_Assert(null != $eqQualCfg, ErrCode::err_const_no); # 防御配置数据错误
  784. list($type, $costQual, $num) = explode(',', $eqQualCfg->compose_condition); # 从配置提取合成条件
  785. $composeArr = array(); # 消耗集合
  786. foreach ($arr as $v) { # 从剩余元素中查找合成所需
  787. if ($v->qual == $costQual) { # 同品阶
  788. if (($type == 1) ? $v->typeId == $equip_compose->typeId # # type: 1 与本体相同 2 同部位即可
  789. : $v->mo()->position == $equip_compose->mo()->position) {
  790. $composeArr[] = $v; # 成为消耗品
  791. }
  792. if (count($composeArr) >= $num) { # 达到消耗数量就停
  793. break;
  794. }
  795. }
  796. }
  797. if (count($composeArr) >= $num) { # 合成的回收 不合成的可不能给回收了
  798. $uid = $equip_compose->uid;
  799. $newEquip = self::ComposeNewEquip($equip_compose); # 原地合成
  800. self::equipLevelUp_Material_Recovery($newEquip->mo()->rarity, $newEquip->qual, $newEquip->mo()->position, $newEquip->level); # 回收材料
  801. $newEquip->level = 1;
  802. $equipDic->$uid = $newEquip;
  803. $composeEquip[] = $uid; # 添加合成记录
  804. foreach ($composeArr as $val) { # 回收消耗的装备中所含材料
  805. self::equipLevelUp_Material_Recovery($val->mo()->rarity, $val->qual, $val->mo()->position, $val->level); # 回收材料
  806. StlUtil::dictRemove(ctx()->store(true)->equip, $val->uid); # 背包删除
  807. for ($i = 1; $i <= 6; $i++) { # 清理装备信息
  808. if ($store->equipLocation->$i == $val->uid) {
  809. StlUtil::dictRemove($store->equipLocation, $i);
  810. }
  811. }
  812. StlUtil::arrayRemove($arr, $val); # 从arr中删掉已消耗装备
  813. }
  814. }
  815. }
  816. TaskProc::OnEquipComposeNum();
  817. FightProc::Ranking_FightPower();
  818. UserProc::updateUserInfo(); # 回存玩家数据
  819. return Resp::ok(array(# # 返回给客户端的数据
  820. 'gold' => ctx()->baseInfo->gold,
  821. 'store' => ctx()->store,
  822. 'composeEquip' => $composeEquip,
  823. 'task' => ctx()->task,
  824. ));
  825. }
  826. /**
  827. * 6418 装备一键合成
  828. * @return type
  829. */
  830. public static function Equip_OnekeyCompose() {
  831. //list() = req()->paras;
  832. $equipDic = ctx()->store->equip;
  833. $arr = array();
  834. foreach ($equipDic as $uid => $equip) {
  835. $ins_equip = new Ins_Equip($equip);
  836. if ($ins_equip->qual > 4) {
  837. continue;
  838. }
  839. $arr[] = $ins_equip;
  840. }
  841. //等级从大到小
  842. $len = count($arr);
  843. for ($i = 0; $i < $len - 1; $i++) {
  844. for ($j = $len - 1; $j > $i; $j--) {
  845. if ($arr[$j]->level > $arr[$j - 1]->level) {
  846. $temp = $arr[$j];
  847. $arr[$j] = $arr[$j - 1];
  848. $arr[$j - 1] = $temp;
  849. }
  850. }
  851. }
  852. $composeEquip = array();
  853. if ($len > 0) {
  854. while (true) {
  855. $equip_compose = $arr[0];
  856. $str = explode(',', GameConfig::equip_compose_getItem($equip_compose->qual)->compose_condition);
  857. $type = $str[0];
  858. $costQual = $str[1];
  859. $num = $str[2];
  860. $n = count($arr);
  861. $composeArr = array();
  862. $tag = false;
  863. $ing_compose = false;
  864. for ($k = $n - 1; $k >= 0; $k--) {
  865. if ($arr[$k]->uid == $equip_compose->uid) {
  866. continue;
  867. }
  868. if ($type == 1 && $arr[$k]->qual == $costQual && $arr[$k]->typeId == $equip_compose->typeId) {
  869. $tag = true;
  870. } else if ($type == 2 && $arr[$k]->qual == $costQual && $arr[$k]->mo()->position == $equip_compose->mo()->position) {
  871. $tag = true;
  872. }
  873. if ($tag) {
  874. $composeArr[] = $arr[$k];
  875. if (count($composeArr) >= $num) {
  876. break;
  877. }
  878. }
  879. }
  880. if (count($composeArr) >= $num) {
  881. $newEquip = self::ComposeNewEquip($equip_compose);
  882. $uid = $newEquip->uid;
  883. ctx()->store(true)->equip->$uid = $newEquip;
  884. $composeEquip[] = $uid;
  885. $ing_compose = true;
  886. }
  887. //合成的 材料不够不能合成的都要删除
  888. foreach ($composeArr as $val) {
  889. if ($ing_compose) {//合成的回收 不合成的可不能给回收了
  890. self::equipLevelUp_Material_Recovery($val->mo()->rarity, $val->qual, $val->mo()->position, $val->level);
  891. StlUtil::dictRemove(ctx()->store(true)->equip, $val->uid);
  892. }
  893. StlUtil::arrayRemove($arr, $val);
  894. }
  895. StlUtil::arrayRemove($arr, $equip_compose);
  896. if (count($arr) <= 0) {
  897. break;
  898. }
  899. }
  900. }
  901. UserProc::updateUserInfo();
  902. return Resp::ok(array(
  903. 'gold' => ctx()->baseInfo->gold,
  904. 'store' => ctx()->store,
  905. 'composeEquip' => $composeEquip,
  906. ));
  907. }
  908. /**
  909. * 6416 购买装备宝石槽
  910. * @return type
  911. */
  912. public static function Gem_BuySlot() {
  913. list($uid) = req()->paras;
  914. $equipDic = ctx()->store->equip;
  915. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  916. $ins_equip = new Ins_Equip($equipDic->$uid);
  917. $mo = GameConfig::gem_slotposition_getItem($ins_equip->qual);
  918. my_Assert(null != $mo, ErrCode::err_const_no);
  919. $initNum = $mo->initNum_slot;
  920. $buyNum = $mo->buyNum_slot;
  921. $unlockIndex = 0;
  922. if ($buyNum > 0) {
  923. for ($i = $initNum + 1; $i <= $initNum + $buyNum; $i++) {
  924. if (!StlUtil::dictHasProperty($ins_equip->gemSetSlot, $i)) {
  925. $ins_equip->gemSetSlot->$i = 0;
  926. break;
  927. }
  928. $unlockIndex += 1;
  929. }
  930. }
  931. $costArr = explode(';', $mo->cost);
  932. $cash = explode(',', $costArr[$unlockIndex]);
  933. my_Assert(ctx()->base(true)->cash >= $cash[1], ErrCode::notenough_cash_msg);
  934. ctx()->base(true)->Consume_Cash($cash[1]);
  935. ctx()->store(true)->equip->$uid = $ins_equip;
  936. UserProc::updateUserInfo();
  937. return Resp::ok(array(
  938. 'cash' => ctx()->baseInfo->cash,
  939. 'store' => ctx()->store,
  940. ));
  941. }
  942. /**
  943. * 6414 装备
  944. * @return type
  945. */
  946. public static function Equiped() {
  947. list($uid) = req()->paras;
  948. $equipDic = ctx()->store->equip;
  949. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  950. $ins_equip = new Ins_Equip($equipDic->$uid);
  951. $posId = $ins_equip->mo()->position;
  952. ctx()->store(true)->equipLocation->$posId = $uid;
  953. FightProc::Ranking_FightPower();
  954. GuideProc::GateFight_Guide_Trigger();
  955. UserProc::updateUserInfo();
  956. return Resp::ok(array());
  957. }
  958. /**
  959. * 6415 卸下装备
  960. * @return type
  961. */
  962. public static function RemoveEquip() {
  963. list($uid) = req()->paras;
  964. $equipDic = ctx()->store->equip;
  965. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  966. $ins_equip = new Ins_Equip($equipDic->$uid);
  967. $posId = $ins_equip->mo()->position;
  968. StlUtil::dictRemove(ctx()->store(true)->equipLocation, $posId);
  969. FightProc::Ranking_FightPower();
  970. UserProc::updateUserInfo();
  971. return Resp::ok(array());
  972. }
  973. /**
  974. * 洗练
  975. * @return Resp
  976. */
  977. public static function GemXiLian() {
  978. list($uid) = req()->paras;
  979. //把 qual pos u一样的宝石开锁关锁
  980. $gemStore = ctx()->store->gemStore;
  981. my_Assert(StlUtil::dictHasProperty($gemStore, $uid), ErrCode::user_store_NotExistGem);
  982. $gem = new Ins_Gem($gemStore->$uid);
  983. my_Assert($gem->mo()->qual >= 5, ErrCode::user_store_XilianStoneNoEnough);
  984. $arr = explode(';', glc()->XILianGemlNeedXILianStone);
  985. $needStone = 0;
  986. $xilianStoneId = 0;
  987. foreach ($arr as $val) {
  988. $str = explode(':', $val);
  989. if ($str[0] == $gem->mo()->qual) {
  990. $s = explode(',', $str[1]);
  991. $needStone = $s[1];
  992. $xilianStoneId = $s[0];
  993. break;
  994. }
  995. }
  996. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $xilianStoneId) && ctx()->store->items->$xilianStoneId >= $needStone, ErrCode::user_store_XilianStoneNoEnough);
  997. $dic = GameConfig::predicate();
  998. $pList = array();
  999. foreach ($dic as $id => $pMo) {
  1000. if ($pMo->positions != null && $pMo->qual != null) {
  1001. $list = explode(',', $pMo->positions);
  1002. if ($pMo->id != $gem->predicateId && $pMo->qual == $gem->mo()->qual && in_array($gem->mo()->position, $list) && $pMo->attachTarget == "gem") {
  1003. $pList[] = $pMo->id;
  1004. }
  1005. }
  1006. }
  1007. my_Assert(count($pList) > 0, ErrCode::user_store_NoFindPredicate);
  1008. $rand = random_int(0, count($pList) - 1);
  1009. $pId = $pList[$rand];
  1010. ctx()->store->gemStore->$uid->predicateId = $pId;
  1011. ctx()->store->removeItem($xilianStoneId, $needStone);
  1012. $xilianStoneNum = 0;
  1013. if (StlUtil::dictHasProperty(ctx()->store->items, $xilianStoneId)) {
  1014. $xilianStoneNum = ctx()->store->items->$xilianStoneId;
  1015. }
  1016. FightProc::Ranking_FightPower();
  1017. UserProc::updateUserInfo();
  1018. return Resp::ok(array(
  1019. 'xilianStoneId' => $xilianStoneId,
  1020. 'xilianStone' => $xilianStoneNum,
  1021. 'predicateId' => $pId,
  1022. ));
  1023. }
  1024. /**
  1025. * 宝石开锁解锁
  1026. * @return Resp
  1027. */
  1028. public static function GemLockState() {
  1029. list($uid) = req()->paras;
  1030. $user = ctx();
  1031. //把 qual pos u一样的宝石开锁关锁
  1032. $gemStore = $user->store->gemStore;
  1033. $gem = $gemStore->$uid;
  1034. $tag = 0;
  1035. if ($gem->isUnlock == 0) {
  1036. $gem->isUnlock = 1;
  1037. $tag = 1;
  1038. } else {
  1039. $gem->isUnlock = 0;
  1040. $tag = 0;
  1041. }
  1042. $gemStore->$uid = $gem;
  1043. foreach ($gemStore as $k => $ins_gem) {
  1044. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  1045. $gemStore->$k->isUnlock = $tag;
  1046. }
  1047. }
  1048. $user->store->gemStore = $gemStore;
  1049. ctx($user);
  1050. UserProc::updateUserInfo();
  1051. return Resp::ok(array(
  1052. 'gold' => 0,
  1053. 'store' => $user->store,
  1054. ));
  1055. }
  1056. /**
  1057. * 切换装备分页
  1058. * @return Resp
  1059. */
  1060. public static function SwitchEquipPag() {
  1061. list($index) = req()->paras;
  1062. $user = ctx();
  1063. $user->store->equipPag = $index;
  1064. ctx($user);
  1065. UserProc::updateUserInfo();
  1066. return Resp::ok(array());
  1067. }
  1068. /**
  1069. * 所有装备的一键升级
  1070. * 规则:等级不同从等级小到大,等级一样按照部位顺序
  1071. *
  1072. * @return Resp
  1073. */
  1074. public static function AllEquipUpgrade() {
  1075. //list() = req()->paras;
  1076. //$user = ctx();
  1077. // $equipDic = $user->store->equipPosition;
  1078. //
  1079. // $equip_levelDic = GameConfig::equip_levelupgrade();
  1080. // $maxLv = count(StlUtil::dictToArray($equip_levelDic));
  1081. // $arr = array();
  1082. // if ($equipDic != null) {
  1083. // foreach ($equipDic as $k => &$equip) {
  1084. // $equip = new Ins_EquipPosition($equip);
  1085. //
  1086. // if ($equip->level >= $maxLv) {
  1087. // continue;
  1088. // }
  1089. //
  1090. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  1091. // $needGold = $lvMo->needGold;
  1092. // $needItemNum = $lvMo->needItemNum;
  1093. // $neeItemId = $equip->mo()->costTuzhiId;
  1094. //
  1095. // if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  1096. // $arr[] = $equip;
  1097. // }
  1098. // }
  1099. // }
  1100. // $upLevelArr = array();
  1101. // if (count($arr) > 0) {
  1102. // //进行排序
  1103. // $len = count($arr);
  1104. // for ($i = 0; $i < $len - 1; $i++) {
  1105. // for ($j = 0; $j < $len - $i - 1; $j++) {
  1106. // if ($arr[$j]->level > $arr[$j + 1]->level) {//从小到大
  1107. // $temp = $arr[$j];
  1108. // $arr[$j] = $arr[$j + 1];
  1109. // $arr[$j + 1] = $temp;
  1110. // } elseif ($arr[$j]->level == $arr[$j + 1]->level) {
  1111. // $j_equip = new Ins_EquipPosition($arr[$j]);
  1112. // $jj_equip = new Ins_EquipPosition($arr[$j + 1]);
  1113. // if ($j_equip->mo()->position > $jj_equip->mo()->position) {
  1114. // $temp = $arr[$j];
  1115. // $arr[$j] = $arr[$j + 1];
  1116. // $arr[$j + 1] = $temp;
  1117. // }
  1118. // }
  1119. // }
  1120. // }
  1121. //升级,扣除金币和图纸
  1122. // while (true) {
  1123. // $tag = 9999;
  1124. // foreach ($arr as $index => &$equip) {
  1125. // $ins_equip = new Ins_EquipPosition($equip);
  1126. // $lvMo = GameConfig::equip_levelupgrade_getItem($ins_equip->level);
  1127. // $needGold = $lvMo->needGold;
  1128. // $needItemNum = $lvMo->needItemNum;
  1129. // $neeItemId = $ins_equip->mo()->costTuzhiId;
  1130. // if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  1131. // $id = $ins_equip->typeId;
  1132. // if (!in_array($id, $upLevelArr)) {
  1133. // $upLevelArr[] = $id;
  1134. // }
  1135. //
  1136. // $ins_equip->level += 1;
  1137. // $equipDic->$id->level += 1;
  1138. // $user->baseInfo->Consume_Gold($needGold);
  1139. // $user->store->removeItem($neeItemId, $needItemNum);
  1140. // if ($ins_equip->level >= 99) {
  1141. // $tag = $index;
  1142. // break;
  1143. // }
  1144. // } else {
  1145. // $tag = $index;
  1146. // break;
  1147. // }
  1148. // }
  1149. // if ($tag != 9999) {
  1150. // if (array_key_exists($tag, $arr)) {
  1151. // StlUtil::arrayRemoveAt($arr, $tag);
  1152. // }
  1153. // }
  1154. //
  1155. // if (count($arr) <= 0) {
  1156. // break;
  1157. // }
  1158. // }
  1159. // }
  1160. // TaskProc::OnAnyEquipUpLevel_X();
  1161. // TaskProc::OnAllEquipUpLevel_X();
  1162. // TaskProc::OnEquipLevelUpNum();
  1163. // ctx($user);
  1164. //
  1165. // FightProc::Ranking_FightPower();
  1166. UserProc::updateUserInfo();
  1167. return Resp::ok(array(
  1168. 'upLevelArr' => $upLevelArr,
  1169. 'gold' => $user->baseInfo->gold,
  1170. 'store' => $user->store,
  1171. 'task' => $user->task,
  1172. ));
  1173. }
  1174. /**
  1175. * 6411 移除是新宝石绿点提示
  1176. * @return Resp
  1177. */
  1178. public static function RemoveNewGemTip() {
  1179. list($uid) = req()->paras; //宝石uid
  1180. my_Assert(StlUtil::dictHasProperty(ctx()->store->gemStore, $uid), ErrCode::user_store_NoItem);
  1181. ctx()->store(true)->gemStore->$uid->isNew = 0;
  1182. UserProc::updateUserInfo();
  1183. return Resp::ok(array());
  1184. }
  1185. /**
  1186. * 移除装备可以升级绿点提示 -------废弃
  1187. * @return Resp
  1188. */
  1189. public static function RemoveEquipUpgradeTip() {
  1190. // list($posId) = req()->paras; //装备部位
  1191. // $user = ctx();
  1192. //
  1193. // my_Assert(StlUtil::dictHasProperty($user->store->equipPosition, $posId), ErrCode::user_store_NoEquip);
  1194. //
  1195. // $user->store->equipPosition->$posId->tip = 0;
  1196. //
  1197. // ctx($user);
  1198. // UserProc::updateUserInfo();
  1199. // return Resp::ok(array(
  1200. // 'gold' => 0,
  1201. // 'store' => $user->store,));
  1202. }
  1203. /**
  1204. * 6406 合成
  1205. * @return type
  1206. */
  1207. public static function GemCompose() {
  1208. list($gemIds) = req()->paras;
  1209. $list = explode(';', $gemIds);
  1210. $gemStore = ctx()->store->gemStore;
  1211. $composeArr = array();
  1212. foreach ($list as $gems) {
  1213. $gemArr = explode('-', $gems);
  1214. $length1 = strlen($gemArr[0]);
  1215. $length2 = strlen($gemArr[1]);
  1216. $gem_composeCost = explode(',', substr($gemArr[0], 1, $length1 - 1)); //去掉逗号
  1217. $gem_composeIds = explode(',', substr($gemArr[1], 1, $length2 - 1)); //去掉逗号
  1218. $gemMo = GameConfig::gem_getItem($gem_composeIds[0]);
  1219. my_Assert(null != $gemMo, ErrCode::err_const_no);
  1220. $isCompose = true;
  1221. foreach ($gem_composeCost as $gemUid) {
  1222. if (!StlUtil::dictHasProperty($gemStore, $gemUid)) {
  1223. $isCompose = false;
  1224. break;
  1225. }
  1226. $ins_gem = new Ins_Gem($gemStore->$gemUid);
  1227. if ($ins_gem->mo()->qual + 1 != $gemMo->qual || $ins_gem->mo()->position != $gemMo->position) {
  1228. $isCompose = false;
  1229. break;
  1230. }
  1231. if (!self::GemIsCanCompose($gemUid)) {
  1232. $isCompose = false;
  1233. break;
  1234. }
  1235. }
  1236. my_Assert($isCompose == true, ErrCode::user_store_GemCanotCompose);
  1237. foreach ($gem_composeCost as $gemUid) {
  1238. self::RemoveGemInStore($gemUid);
  1239. }
  1240. foreach ($gem_composeIds as $gemTypeId) {
  1241. $composeGem = self::initGem($gemTypeId);
  1242. self::PutGemInStore($composeGem);
  1243. $composeArr[] = $composeGem->uid; //临时放这
  1244. }
  1245. }
  1246. TaskProc::OnComposeNumGem();
  1247. TaskProc::OnComposeNumGem_state();
  1248. UserProc::updateUserInfo();
  1249. return Resp::ok(array(
  1250. 'composeGemIds' => $composeArr,
  1251. 'store' => ctx()->store,
  1252. 'task' => ctx()->task,
  1253. ));
  1254. }
  1255. /**
  1256. * 该宝石是否可以参与合成,其他页镶嵌的,已经被锁的都不能参与
  1257. * @param type $uid
  1258. * @return bool
  1259. */
  1260. private static function GemIsCanCompose($uid) {
  1261. $ins_gem = new Ins_Gem($uid);
  1262. if ($ins_gem->isUnlock == 1) {
  1263. return false;
  1264. }
  1265. $isExist = true;
  1266. $equip = ctx()->store->equip;
  1267. foreach ($equip as $uid => $item) {
  1268. $arr = get_object_vars($item->gemSetSlot);
  1269. $values = array_values($arr);
  1270. if (in_array($uid, $values)) {
  1271. $isExist = false;
  1272. break;
  1273. }
  1274. }
  1275. return $isExist;
  1276. }
  1277. /**
  1278. * 装备宝石
  1279. * @return type
  1280. */
  1281. public static function GemSet() {
  1282. list($equipUid, $uid, $type, $replaceUId) = req()->paras; //宝石uid 手动的时候记得校验u $replaceUId宝石槽坑位id
  1283. my_Assert(StlUtil::dictHasProperty(ctx()->store->gemStore, $uid), ErrCode::user_store_NoItem);
  1284. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $equipUid), ErrCode::user_store_NoEquip);
  1285. $ins_equip = new Ins_Equip(ctx()->store->equip->$equipUid);
  1286. $ins_gem = new Ins_Gem(ctx()->store->gemStore->$uid);
  1287. my_Assert($ins_equip->mo()->position == $ins_gem->mo()->position, ErrCode::user_store_PositionNotFit);
  1288. $gemSetSlotDic = $ins_equip->gemSetSlot;
  1289. $tag_index = 0;
  1290. $tag_gem = null;
  1291. foreach ($gemSetSlotDic as $slotId => $gemUid) {
  1292. if ($gemUid == 0) {
  1293. continue;
  1294. }
  1295. $gem = new Ins_Gem(ctx()->store->gemStore->$gemUid);
  1296. if ($gem->predicateMo()->uniqueKey == $ins_gem->predicateMo()->uniqueKey) {
  1297. $tag_index = $slotId;
  1298. $tag_gem = $gem;
  1299. break;
  1300. }
  1301. }
  1302. $mo = GameConfig::gem_slotposition_getItem($ins_equip->qual);
  1303. my_Assert(null != $mo, ErrCode::err_const_no);
  1304. switch ($type) {
  1305. case 1://镶嵌
  1306. my_Assert($tag_gem == null, ErrCode::user_store_GemCanotSet);
  1307. $go_index = 1;
  1308. for ($i = 1; $i <= $mo->initNum_slot + $mo->buyNum_slot; $i++) {
  1309. if (!StlUtil::dictHasProperty($gemSetSlotDic, $i)) {
  1310. //$gemSetSlotDic->$i = $ins_gem;
  1311. $go_index = $i;
  1312. break;
  1313. }
  1314. if ($gemSetSlotDic->$i == 0) {
  1315. $go_index = $i;
  1316. break;
  1317. }
  1318. }
  1319. $gemSetSlotDic->$go_index = $uid;
  1320. break;
  1321. case 2://替换
  1322. //满不满都高替低品阶
  1323. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  1324. $gUid = $gemSetSlotDic->$replaceUId;
  1325. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid); //这个$replaceUId是坑位的index id
  1326. my_Assert($replace_ins_Gem->mo()->qual < $ins_gem->mo()->qual, ErrCode::user_store_NoExistGemReplace);
  1327. //$gemSetSlotDic->$replaceUId = $ins_gem;
  1328. $gemSetSlotDic->$replaceUId = $uid;
  1329. break;
  1330. case 3://手动
  1331. //my_Assert(count((array) $gemSetSlotDic) >= $mo->initNum_slot + $mo->buyNum_slot, ErrCode::user_store_GemCanotSet);
  1332. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  1333. $gUid = $gemSetSlotDic->$replaceUId;
  1334. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  1335. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid);
  1336. //$id = $replace_ins_Gem->uid;
  1337. if ($tag_gem != null) {//如果有u那
  1338. my_Assert($replace_ins_Gem->uid == $tag_gem->uid, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  1339. //有U一样的,则点击正好是这个直接替换
  1340. //$gemSetSlotDic->$tag_index = $ins_gem;
  1341. $gemSetSlotDic->$tag_index = $uid;
  1342. } else {
  1343. // $go_index = 0;
  1344. // foreach ($gemSetSlotDic as $slotId => $gemUid) {
  1345. // if ($slotId == $replaceUId) {
  1346. // $go_index = $slotId;
  1347. // break;
  1348. // }
  1349. // }
  1350. //
  1351. // my_Assert($go_index > 0, ErrCode::user_store_NoExistGemReplace);
  1352. //$gemSetSlotDic->$go_index = $ins_gem;
  1353. $gemSetSlotDic->$replaceUId = $uid;
  1354. }
  1355. break;
  1356. case 4://不能
  1357. //1.小品阶替大品阶 或是 相等的,在不满的时候不允许 2. //满的 相等不允许替
  1358. my_Assert($uid == 0, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  1359. break;
  1360. default:
  1361. break;
  1362. }
  1363. $ins_equip->gemSetSlot = $gemSetSlotDic;
  1364. ctx()->store(true)->equip->$equipUid = $ins_equip;
  1365. TaskProc::OnSetSpecialQualGem();
  1366. FightProc::Ranking_FightPower();
  1367. UserProc::updateUserInfo();
  1368. return Resp::ok(array(
  1369. 'gold' => 0,
  1370. 'store' => ctx()->store,
  1371. 'task' => ctx()->task,
  1372. ));
  1373. }
  1374. /**
  1375. * 卸下装备
  1376. * @return type
  1377. */
  1378. public static function GemRemove() {
  1379. list($uid) = req()->paras; //装备宝石id
  1380. $equips = ctx()->store->equip;
  1381. foreach ($equips as $eUid => $ins_equip) {
  1382. $dic = $ins_equip->gemSetSlot;
  1383. foreach ($dic as $slotId => $gemUid) {
  1384. if ($uid == $gemUid) {
  1385. ctx()->store->equip->$eUid->gemSetSlot->$slotId = 0;
  1386. break 2;
  1387. }
  1388. }
  1389. }
  1390. FightProc::Ranking_FightPower();
  1391. UserProc::updateUserInfo();
  1392. return Resp::ok(array(
  1393. 'gold' => 0,
  1394. 'store' => ctx()->store,));
  1395. }
  1396. /**
  1397. * 6404 升级装备
  1398. * @return type
  1399. */
  1400. public static function EquipUpgrade() {
  1401. list($uid) = req()->paras; //装备uid
  1402. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  1403. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  1404. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_LevelLimit);
  1405. $mo = GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $ins_equip->level);
  1406. my_Assert(null != $mo, ErrCode::err_const_no);
  1407. my_Assert(ctx()->baseInfo->gold >= $mo->needGold, ErrCode::notenough_gold_msg);
  1408. $costTuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  1409. $tuzhiNum = 0;
  1410. if (StlUtil::dictHasProperty(ctx()->store->items, $costTuzhiId)) {
  1411. $tuzhiNum = ctx()->store->items->$costTuzhiId;
  1412. }
  1413. my_Assert($tuzhiNum >= $mo->needItemNum, ErrCode::notenough_item);
  1414. ctx()->store(true)->removeItem($costTuzhiId, $mo->needItemNum);
  1415. ctx()->base(true)->Consume_Gold($mo->needGold);
  1416. $ins_equip->level += 1;
  1417. ctx()->store->equip->$uid = $ins_equip;
  1418. TaskProc::OnAnyEquipUpLevel_X();
  1419. TaskProc::OnAllEquipUpLevel_X();
  1420. TaskProc::OnEquipLevelUpNum();
  1421. FightProc::Ranking_FightPower();
  1422. UserProc::updateUserInfo();
  1423. return Resp::ok(array(
  1424. 'gold' => ctx()->baseInfo->gold,
  1425. 'store' => ctx()->store,
  1426. 'task' => ctx()->task,
  1427. ));
  1428. }
  1429. /**
  1430. * 6405 单个装备部位一键升级
  1431. * @return type
  1432. */
  1433. public static function EquipUpgrade_MaxLv() {
  1434. list($uid) = req()->paras;
  1435. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  1436. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  1437. $maxLevel = $ins_equip->Equip_MaxLevel();
  1438. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_LevelLimit);
  1439. $tuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  1440. $itemNum_store = 0;
  1441. if (StlUtil::dictHasProperty(ctx()->store->items, $tuzhiId)) {
  1442. $itemNum_store = ctx()->store->items->$tuzhiId;
  1443. }
  1444. $up_Gold = 0;
  1445. $up_needItem = 0;
  1446. $up_lv = 0;
  1447. $noUp_gold = false;
  1448. $noUp_item = false;
  1449. $need_gold = 0;
  1450. $need_item = 0;
  1451. for ($i = $ins_equip->level; $i <= $maxLevel; $i++) {
  1452. $up_Gold += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $i)->needGold;
  1453. $up_needItem += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $i)->needItemNum;
  1454. if (ctx()->baseInfo->gold >= $up_Gold) {
  1455. $noUp_gold = true;
  1456. }
  1457. if ($itemNum_store >= $up_needItem) {
  1458. $noUp_item = true;
  1459. }
  1460. $up_lv = $i;
  1461. if (ctx()->baseInfo->gold >= $up_Gold && $itemNum_store >= $up_needItem) {
  1462. $need_gold = $up_Gold;
  1463. $need_item = $up_needItem;
  1464. continue;
  1465. }
  1466. break;
  1467. }
  1468. if ($up_lv == 0) {
  1469. my_Assert($noUp_gold, ErrCode::notenough_gold_msg);
  1470. my_Assert($noUp_item, ErrCode::notenough_item);
  1471. }
  1472. ctx()->base(true)->Consume_Gold($need_gold);
  1473. ctx()->store(true)->removeItem($tuzhiId, $need_item);
  1474. if ($up_lv > 0) {
  1475. ctx()->store->equip->$uid->level = $up_lv;
  1476. }
  1477. TaskProc::OnAnyEquipUpLevel_X();
  1478. TaskProc::OnAllEquipUpLevel_X();
  1479. TaskProc::OnEquipLevelUpNum();
  1480. FightProc::Ranking_FightPower();
  1481. UserProc::updateUserInfo();
  1482. return Resp::ok(array(
  1483. 'gold' => ctx()->baseInfo->gold,
  1484. 'store' => ctx()->store,
  1485. 'task' => ctx()->task,
  1486. ));
  1487. }
  1488. public static function AddItemInStore() {
  1489. list($rwdStr) = req()->paras; //mask = 1:表示战斗中掉落
  1490. $user = ctx();
  1491. $err = self::AddMultiItemInStore($rwdStr);
  1492. my_Assert(ErrCode::ok == $err, $err);
  1493. UserProc::updateUserInfo();
  1494. return Resp::ok(array(
  1495. //'gold' => $user->baseInfo->gold,
  1496. //'tili' => $user->baseInfo->tili,
  1497. //'cash' => $user->baseInfo->cash,
  1498. 'store' => $user->store));
  1499. }
  1500. static $reward = array();
  1501. static $reward_Gem = array();
  1502. static $reward_equip = array();
  1503. //static $reward_hero = array();
  1504. /**
  1505. * 具体奖励存入背包
  1506. * @param type $goodsStr
  1507. * @param type $src
  1508. */
  1509. public static function AddMultiItemInStore($goodsStr, $src = 0) {
  1510. if ($goodsStr == null) {
  1511. return;
  1512. }
  1513. $ary = explode(";", $goodsStr);
  1514. foreach ($ary as $value) {
  1515. $val = explode(",", $value);
  1516. my_Assert(count($val) > 1, "解析奖励字符串出错");
  1517. list($itemId, $num) = $val; # ID, 数量
  1518. $itemMo = GameConfig::item_getItem($itemId);
  1519. if ($itemMo->itemType != 701 && $itemMo->itemType != 201 && $itemMo->itemType != 502 && $itemMo->itemType != 101 && $src != 1) {
  1520. self::$reward[] = $value;
  1521. }
  1522. switch ($itemMo->itemType) {
  1523. case 1:
  1524. ctx()->baseInfo->Add_Gold($num);
  1525. //self::checkEquipUpgradeTip();//废弃
  1526. break;
  1527. case 2:
  1528. ctx()->baseInfo->Add_Cash($num);
  1529. break;
  1530. case 3:
  1531. ctx()->baseInfo->Add_tili($num);
  1532. break;
  1533. case 4:
  1534. ctx()->baseInfo->Add_Exp($num);
  1535. break;
  1536. case 100://图纸
  1537. case 103://钥匙
  1538. case 401://启灵石
  1539. case 301://洗练石
  1540. case 501://人物碎片
  1541. case 601://人身果
  1542. case 801://寻宝券
  1543. case 602://灵蛇果
  1544. case 802://灵蛇贺岁券
  1545. case 901:
  1546. self::PutItemsInStore($itemId, $num);
  1547. // if ($itemMo->itemType == 100) {//图纸
  1548. // self::checkEquipUpgradeTip();//废弃
  1549. // }
  1550. break;
  1551. case 502://角色卡
  1552. HeroProc::RoleCardUnlockHero($itemId, $num);
  1553. break;
  1554. case 201://宝石
  1555. for ($i = 0; $i < $num; $i++) {
  1556. $gem = self::initGem($itemId);
  1557. if ($src != 1) {
  1558. self::$reward_Gem[] = $gem->uid;
  1559. }
  1560. self::PutGemInStore($gem);
  1561. if ($src == Enum_StoreSourceType::ShopBox) {
  1562. SystemProc::GetGem_GreaterOrangeQual_ShopBox(req()->zoneid, ctx()->baseInfo->name, $gem->typeId);
  1563. }
  1564. }
  1565. break;
  1566. case 101:
  1567. //self::PutEquipInStore($itemId, $num);
  1568. for ($i = 0; $i < $num; $i++) {
  1569. FightProc::funUnlock_equip_firstTime();
  1570. $equip = self::initEquip($itemId);
  1571. $uid = $equip->uid;
  1572. ctx()->store(true)->equip->$uid = $equip;
  1573. self::$reward_equip[] = $uid;
  1574. }
  1575. break;
  1576. case 701://道具宝箱
  1577. for ($i = 0; $i < $num; $i++) {
  1578. self::DistributeItemsBox($itemId);
  1579. }
  1580. break;
  1581. default:
  1582. break;
  1583. }
  1584. }
  1585. }
  1586. public static function initPet($typeId, $uid = 0) {
  1587. if ($uid == 0) {
  1588. $uid = ctx()->store->petUid+1;
  1589. }
  1590. $ins_Pet = new Ins_Pet();
  1591. $ins_Pet->uid = $uid;
  1592. $ins_Pet->typeId = $typeId;
  1593. $ins_Pet->qual = GameConfig::pet_getItem($typeId)->qual;
  1594. return $ins_Pet;
  1595. }
  1596. /**
  1597. * 装备回存
  1598. * @param type $itemId
  1599. * @param type $num
  1600. */
  1601. public static function PutEquipInStore($itemId, $num) {
  1602. for ($i = 0; $i < $num; $i++) {
  1603. $equip = self::initEquip($itemId);
  1604. $uid = $equip->uid;
  1605. ctx()->store(true)->equip->$uid = $equip;
  1606. }
  1607. }
  1608. public static function initEquip($typeId, $uid = 0) {
  1609. if ($uid == 0) {
  1610. $uid = ctx()->store->nextUID();
  1611. }
  1612. $ins_equip = new Ins_Equip();
  1613. $ins_equip->uid = $uid;
  1614. $ins_equip->typeId = $typeId;
  1615. $ins_equip->qual = GameConfig::equip_getItem($typeId)->qual;
  1616. return $ins_equip;
  1617. }
  1618. public static function PutItemsInStore($itemId, $num) {
  1619. $items = ctx()->store->items;
  1620. if (StlUtil::dictHasProperty($items, $itemId)) {
  1621. $items->$itemId += $num;
  1622. } else {
  1623. $items->$itemId = $num;
  1624. }
  1625. ctx()->store->items = $items;
  1626. }
  1627. /**
  1628. * 拆分宝箱盒子
  1629. * @param type $reward
  1630. */
  1631. public static function DistributeItemsBox($itemId) {
  1632. $itemBoxMo = GameConfig::item_2023_box_getItem($itemId);
  1633. my_Assert($itemBoxMo != null, ErrCode::err_const_no);
  1634. if ($itemBoxMo->type == 1) {
  1635. $reward = self::Distribute_Rewards($itemBoxMo->contents);
  1636. self::AddMultiItemInStore($reward);
  1637. } else {
  1638. self::AddMultiItemInStore($itemBoxMo->contents);
  1639. }
  1640. }
  1641. public static function Distribute_Rewards($contents) {
  1642. $strList = explode(';', $contents);
  1643. $numList = explode('-', $strList[0]);
  1644. $randNum = rand($numList[0], $numList[1]);
  1645. $ctxList = explode(',', $strList[1]);
  1646. $per = 0;
  1647. foreach ($ctxList as $value) {
  1648. $ctx = explode(':', $value);
  1649. $per += $ctx[1];
  1650. }
  1651. $reward = "";
  1652. for ($i = 0; $i < $randNum; $i++) {
  1653. $ctxPer = rand(1, $per);
  1654. $start = 0;
  1655. $end = 0;
  1656. $id = 0;
  1657. foreach ($ctxList as $value) {
  1658. $ctx = explode(':', $value);
  1659. $end += $ctx[1];
  1660. if ($ctxPer > $start && $ctxPer <= $end) {
  1661. $id = $ctx[0];
  1662. break;
  1663. }
  1664. $start = $end;
  1665. }
  1666. if ($id != 0) {
  1667. $str = $id . ',1';
  1668. if ($reward == "") {
  1669. $reward = $str;
  1670. } else {
  1671. $reward = $reward . ';' . $str;
  1672. }
  1673. }
  1674. }
  1675. return $reward;
  1676. }
  1677. // public static function PutEquipInStore($equipId, $num) {
  1678. // if ($equipId == 0) {
  1679. // return;
  1680. // }
  1681. // $n = count((array) ctx()->store->equip) + 1;
  1682. //
  1683. // for ($index = 0; $index < $num; $index++) {
  1684. // $Equip = new Ins_Equip();
  1685. // $Equip->uid = $n;
  1686. // $Equip->typeId = $equipId;
  1687. // $Equip->qual = GameConfig::equip_getItem($equipId)->qual;
  1688. // ctx()->store->equip->$n = $Equip;
  1689. // $n += 1;
  1690. // }
  1691. // }
  1692. /**
  1693. * 得到金币或是图纸的时候校验下,是否满足装备升级条件,满足则tip字段设置为1 废弃
  1694. */
  1695. // public static function checkEquipUpgradeTip() {
  1696. // $equipDic = ctx()->store->equipPosition;
  1697. // if ($equipDic != null) {
  1698. // foreach ($equipDic as $k => &$equip) {
  1699. // $equip = new Ins_EquipPosition($equip);
  1700. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  1701. // $needGold = $lvMo->needGold;
  1702. // $needItemNum = $lvMo->needItemNum;
  1703. // $neeItemId = $equip->mo()->costTuzhiId;
  1704. //
  1705. // if (ctx()->baseInfo->gold >= $needGold && StlUtil::dictHasProperty(ctx()->store->items, $neeItemId) && ctx()->store->items->$neeItemId >= $needItemNum) {
  1706. // $equipDic->$k->tip = 1; //绿点是每次得到金币或是图纸了,只要满足升级条件都变绿
  1707. // }
  1708. // }
  1709. // }
  1710. // ctx()->store->equipPosition = $equipDic;
  1711. // }
  1712. /**
  1713. * 新宝石入库
  1714. */
  1715. public static function PutGemIdInStore($id, $num = 1) {
  1716. for ($i = 0; $i < $num; $i++) {
  1717. $gem = self::initGem($id);
  1718. $length = $gem->uid;
  1719. ctx()->store->gemStore->$length = $gem;
  1720. }
  1721. }
  1722. public static function PutGemInStore($gem, $num = 1) {
  1723. for ($i = 0; $i < $num; $i++) {
  1724. $length = $gem->uid;
  1725. ctx()->store->gemStore->$length = $gem;
  1726. }
  1727. }
  1728. public static function initGem($id) {
  1729. $length = ctx()->store->gemLength;
  1730. $length += 1;
  1731. $gem = new Ins_Gem();
  1732. $gem->uid = $length;
  1733. $gem->typeId = $id;
  1734. $gem->predicateId = self::RandomGemPredicateId($id);
  1735. $tag = self::CheckNewGemTip($gem);
  1736. $gem->isNew = $tag;
  1737. ctx()->store->gemLength = $length;
  1738. return $gem;
  1739. }
  1740. /**
  1741. * 从仓库移除宝石
  1742. */
  1743. public static function RemoveGemInStore($uid) {
  1744. if (StlUtil::dictHasProperty(ctx()->store->gemStore, $uid)) {
  1745. StlUtil::dictRemove(ctx()->store->gemStore, $uid);
  1746. }
  1747. return 0;
  1748. }
  1749. /**
  1750. * 新宝石随机词条 临时等刚哥
  1751. */
  1752. public static function RandomGemPredicateId($id) {
  1753. $mo = GameConfig::gem_getItem($id);
  1754. my_Assert(null != $mo, "找不到宝石{$id}的配置数据");
  1755. if ($mo->isfixed_predicateId == 1) {
  1756. return $mo->predicateId;
  1757. }
  1758. $posId = $mo->position;
  1759. $qual = $mo->qual;
  1760. $arr = array();
  1761. $predicateMo = GameConfig::predicate();
  1762. foreach ($predicateMo as $key => $value) {
  1763. if ($value->positions != null) {
  1764. $list = explode(',', $value->positions);
  1765. if ($value->qual == $qual && in_array($posId, $list) && $value->attachTarget == "gem") {
  1766. $arr[] = $value->id;
  1767. }
  1768. }
  1769. }
  1770. if (count($arr) <= 0) {
  1771. return 40;
  1772. }
  1773. my_Assert(count($arr) > 0, "宝石没有对应词条信息");
  1774. $n = mt_rand(0, count($arr) - 1);
  1775. return $arr[$n];
  1776. //return 40;
  1777. }
  1778. /**
  1779. * 新宝石提示
  1780. */
  1781. public static function CheckNewGemTip($gem) {
  1782. $gemStore = ctx()->store->gemStore;
  1783. $tag = false;
  1784. foreach ($gemStore as $k => $ins_gem) {
  1785. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  1786. $tag = true;
  1787. break;
  1788. }
  1789. }
  1790. return $tag == true ? 0 : 1;
  1791. }
  1792. //临时代码
  1793. // public static function InitGemInfo() {
  1794. // if(count((array)ctx()->store->gemStore) > 0){
  1795. // return;
  1796. // }
  1797. //
  1798. // $index = 0;
  1799. // $gem = GameConfig::gem();
  1800. //
  1801. // for ($i = 1; $i <=21; $i++) {
  1802. // foreach ($gem as $key => $value) {
  1803. // if($value->id == $i){
  1804. // self::PutGemInStore($value->typeId);
  1805. // }
  1806. //
  1807. // }
  1808. // }
  1809. //
  1810. //
  1811. //
  1812. //
  1813. // }
  1814. }