StoreProc.php 54 KB

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