StoreProc.php 53 KB

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