StoreProc.php 54 KB

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