StoreProc.php 57 KB

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