StoreProc.php 79 KB

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