StoreProc.php 53 KB

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