StoreProc.php 58 KB

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