StoreProc.php 54 KB

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