StoreProc.php 60 KB

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