StoreProc.php 53 KB

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