StoreProc.php 58 KB

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