StoreProc.php 53 KB

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