StoreProc.php 61 KB

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