StoreProc.php 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623
  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. case CmdCode::store_clearNewGemTip: # 6440 清理背包里新宝石标识
  98. return self::clearNewGemTip();
  99. default:
  100. Err(ErrCode::cmd_err);
  101. }
  102. }
  103. /**
  104. * 6440 清理背包里新宝石标识
  105. */
  106. public static function clearNewGemTip(){
  107. list($uid) = req()->paras;
  108. if(in_array($uid, ctx()->store()->newGem_Store)){
  109. StlUtil::arrayRemove( ctx()->store()->newGem_Store, $uid);
  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. $gemStore = ctx()->store()->gemStore;
  1153. $predicateId = $gem->predicateId;
  1154. $isExistSameGem = false;
  1155. foreach ($gemStore as $uid => $gemValue) {
  1156. if($gemValue->predicateId == $predicateId){
  1157. $isExistSameGem = true;
  1158. break;
  1159. }
  1160. }
  1161. if(!$isExistSameGem){
  1162. ctx()->store()->newGem_Store[] = $gem->uid;
  1163. }
  1164. }
  1165. self::PutGemInStore($gem);
  1166. if ($src == Enum_StoreSourceType::ShopBox) {
  1167. SystemProc::GetGem_GreaterOrangeQual_ShopBox(req()->zoneid, ctx()->baseInfo->name, $gem->typeId);
  1168. }
  1169. }
  1170. break;
  1171. case 101:
  1172. //self::PutEquipInStore($itemId, $num);
  1173. for ($i = 0; $i < $num; $i++) {
  1174. FightProc::funUnlock_equip_firstTime();
  1175. $equip = self::initEquip($itemId);
  1176. $uid = $equip->uid;
  1177. ctx()->store(true)->equip->$uid = $equip;
  1178. self::$reward_equip[] = $uid;
  1179. }
  1180. break;
  1181. case 102:
  1182. for ($i = 0; $i < $num; $i++) {
  1183. $pet = self::initPet($itemId);
  1184. $uid = $pet->uid;
  1185. ctx()->store(true)->pet->$uid = $pet;
  1186. }
  1187. break;
  1188. case 701://道具宝箱
  1189. for ($i = 0; $i < $num; $i++) {
  1190. self::DistributeItemsBox($itemId);
  1191. }
  1192. break;
  1193. default:
  1194. break;
  1195. }
  1196. }
  1197. }
  1198. public static function initPet($typeId, $uid = 0) {
  1199. if ($uid == 0) {
  1200. ctx()->store->petUid += 1;
  1201. $uid = ctx()->store->petUid;
  1202. }
  1203. $ins_Pet = new Ins_Pet();
  1204. $ins_Pet->uid = $uid;
  1205. $ins_Pet->typeId = $typeId;
  1206. $ins_Pet->qual = GameConfig::pet_getItem($typeId)->qual;
  1207. return $ins_Pet;
  1208. }
  1209. /**
  1210. * 装备回存
  1211. * @param type $itemId
  1212. * @param type $num
  1213. */
  1214. public static function PutEquipInStore($itemId, $num) {
  1215. for ($i = 0; $i < $num; $i++) {
  1216. $equip = self::initEquip($itemId);
  1217. $uid = $equip->uid;
  1218. ctx()->store(true)->equip->$uid = $equip;
  1219. }
  1220. }
  1221. public static function initEquip($typeId, $uid = 0) {
  1222. if ($uid == 0) {
  1223. $uid = ctx()->store->nextUID();
  1224. }
  1225. $ins_equip = new Ins_Equip();
  1226. $ins_equip->uid = $uid;
  1227. $ins_equip->typeId = $typeId;
  1228. $ins_equip->qual = GameConfig::equip_getItem($typeId)->qual;
  1229. $mo = GameConfig::gem_slotposition_getItem(16);
  1230. $initNum_slot = $mo->initNum_slot;
  1231. $dic = new \stdClass();
  1232. for ($i = 1; $i <= $initNum_slot; $i++) {
  1233. $dic->$i = 0;
  1234. }
  1235. for ($i = $initNum_slot +1; $i <= $initNum_slot+$mo->buyNum_slot; $i++) {
  1236. $dic->$i = 1;
  1237. }
  1238. $ins_equip->gemSetSlot = $dic;
  1239. return $ins_equip;
  1240. }
  1241. public static function PutItemsInStore($itemId, $num) {
  1242. $items = ctx()->store->items;
  1243. if (StlUtil::dictHasProperty($items, $itemId)) {
  1244. $items->$itemId += $num;
  1245. } else {
  1246. $items->$itemId = $num;
  1247. }
  1248. ctx()->store->items = $items;
  1249. }
  1250. /**
  1251. * 拆分宝箱盒子
  1252. * @param type $reward
  1253. */
  1254. public static function DistributeItemsBox($itemId) {
  1255. $itemBoxMo = GameConfig::item_2023_box_getItem($itemId);
  1256. my_Assert($itemBoxMo != null, ErrCode::err_const_no);
  1257. if ($itemBoxMo->type == 1) {
  1258. $reward = self::Distribute_Rewards($itemBoxMo->contents);
  1259. self::AddMultiItemInStore($reward);
  1260. } else {
  1261. self::AddMultiItemInStore($itemBoxMo->contents);
  1262. }
  1263. }
  1264. public static function Distribute_Rewards($contents) {
  1265. $strList = explode(';', $contents);
  1266. $numList = explode('-', $strList[0]);
  1267. $randNum = rand($numList[0], $numList[1]);
  1268. $ctxList = explode(',', $strList[1]);
  1269. $per = 0;
  1270. foreach ($ctxList as $value) {
  1271. $ctx = explode(':', $value);
  1272. $per += $ctx[1];
  1273. }
  1274. $reward = "";
  1275. for ($i = 0; $i < $randNum; $i++) {
  1276. $ctxPer = rand(1, $per);
  1277. $start = 0;
  1278. $end = 0;
  1279. $id = 0;
  1280. foreach ($ctxList as $value) {
  1281. $ctx = explode(':', $value);
  1282. $end += $ctx[1];
  1283. if ($ctxPer > $start && $ctxPer <= $end) {
  1284. $id = $ctx[0];
  1285. break;
  1286. }
  1287. $start = $end;
  1288. }
  1289. if ($id != 0) {
  1290. $str = $id . ',1';
  1291. if ($reward == "") {
  1292. $reward = $str;
  1293. } else {
  1294. $reward = $reward . ';' . $str;
  1295. }
  1296. }
  1297. }
  1298. return $reward;
  1299. }
  1300. // public static function PutEquipInStore($equipId, $num) {
  1301. // if ($equipId == 0) {
  1302. // return;
  1303. // }
  1304. // $n = count((array) ctx()->store->equip) + 1;
  1305. //
  1306. // for ($index = 0; $index < $num; $index++) {
  1307. // $Equip = new Ins_Equip();
  1308. // $Equip->uid = $n;
  1309. // $Equip->typeId = $equipId;
  1310. // $Equip->qual = GameConfig::equip_getItem($equipId)->qual;
  1311. // ctx()->store->equip->$n = $Equip;
  1312. // $n += 1;
  1313. // }
  1314. // }
  1315. /**
  1316. * 得到金币或是图纸的时候校验下,是否满足装备升级条件,满足则tip字段设置为1 废弃
  1317. */
  1318. // public static function checkEquipUpgradeTip() {
  1319. // $equipDic = ctx()->store->equipPosition;
  1320. // if ($equipDic != null) {
  1321. // foreach ($equipDic as $k => &$equip) {
  1322. // $equip = new Ins_EquipPosition($equip);
  1323. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  1324. // $needGold = $lvMo->needGold;
  1325. // $needItemNum = $lvMo->needItemNum;
  1326. // $neeItemId = $equip->mo()->costTuzhiId;
  1327. //
  1328. // if (ctx()->baseInfo->gold >= $needGold && StlUtil::dictHasProperty(ctx()->store->items, $neeItemId) && ctx()->store->items->$neeItemId >= $needItemNum) {
  1329. // $equipDic->$k->tip = 1; //绿点是每次得到金币或是图纸了,只要满足升级条件都变绿
  1330. // }
  1331. // }
  1332. // }
  1333. // ctx()->store->equipPosition = $equipDic;
  1334. // }
  1335. /**
  1336. * 新宝石入库
  1337. */
  1338. public static function PutGemIdInStore($id, $num = 1) {
  1339. for ($i = 0; $i < $num; $i++) {
  1340. $gem = self::initGem($id);
  1341. $length = $gem->uid;
  1342. ctx()->store->gemStore->$length = $gem;
  1343. }
  1344. }
  1345. public static function PutGemInStore($gem, $num = 1) {
  1346. for ($i = 0; $i < $num; $i++) {
  1347. $length = $gem->uid;
  1348. ctx()->store->gemStore->$length = $gem;
  1349. }
  1350. }
  1351. public static function initGem($id) {
  1352. $length = ctx()->store->gemLength;
  1353. $length += 1;
  1354. $gem = new Ins_Gem();
  1355. $gem->uid = $length;
  1356. $gem->typeId = $id;
  1357. $gem->predicateId = self::RandomGemPredicateId($id);
  1358. $tag = self::CheckNewGemTip($gem);
  1359. $gem->isNew = $tag;
  1360. ctx()->store->gemLength = $length;
  1361. return $gem;
  1362. }
  1363. /**
  1364. * 从仓库移除宝石
  1365. */
  1366. public static function RemoveGemInStore($uid) {
  1367. if (StlUtil::dictHasProperty(ctx()->store->gemStore, $uid)) {
  1368. StlUtil::dictRemove(ctx()->store->gemStore, $uid);
  1369. }
  1370. return 0;
  1371. }
  1372. /**
  1373. * 新宝石随机词条 临时等刚哥
  1374. */
  1375. public static function RandomGemPredicateId($id) {
  1376. $mo = GameConfig::gem_getItem($id);
  1377. my_Assert(null != $mo, "找不到宝石{$id}的配置数据");
  1378. if ($mo->isfixed_predicateId == 1) {
  1379. return $mo->predicateId;
  1380. }
  1381. $posId = $mo->position;
  1382. $qual = $mo->qual;
  1383. $arr = array();
  1384. $predicateMo = GameConfig::predicate();
  1385. foreach ($predicateMo as $key => $value) {
  1386. if ($value->positions != null) {
  1387. $list = explode(',', $value->positions);
  1388. if ($value->qual == $qual && in_array($posId, $list) && $value->attachTarget == "gem") {
  1389. $arr[] = $value->id;
  1390. }
  1391. }
  1392. }
  1393. if (count($arr) <= 0) {
  1394. return 40;
  1395. }
  1396. my_Assert(count($arr) > 0, "宝石没有对应词条信息");
  1397. $n = mt_rand(0, count($arr) - 1);
  1398. return $arr[$n];
  1399. //return 40;
  1400. }
  1401. /**
  1402. * 新宝石提示
  1403. */
  1404. public static function CheckNewGemTip($gem) {
  1405. $gemStore = ctx()->store->gemStore;
  1406. $tag = false;
  1407. foreach ($gemStore as $k => $ins_gem) {
  1408. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  1409. $tag = true;
  1410. break;
  1411. }
  1412. }
  1413. return $tag == true ? 0 : 1;
  1414. }
  1415. //临时代码
  1416. // public static function InitGemInfo() {
  1417. // if(count((array)ctx()->store->gemStore) > 0){
  1418. // return;
  1419. // }
  1420. //
  1421. // $index = 0;
  1422. // $gem = GameConfig::gem();
  1423. //
  1424. // for ($i = 1; $i <=21; $i++) {
  1425. // foreach ($gem as $key => $value) {
  1426. // if($value->id == $i){
  1427. // self::PutGemInStore($value->typeId);
  1428. // }
  1429. //
  1430. // }
  1431. // }
  1432. //
  1433. //
  1434. //
  1435. //
  1436. // }
  1437. }