StoreProc.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462
  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. UserProc::updateUserInfo();
  451. return Resp::ok(array());
  452. }
  453. /**
  454. * 6413 卸下装备
  455. * @return type
  456. */
  457. public static function RemoveEquip() {
  458. list($uid) = req()->paras;
  459. $equipDic = ctx()->store->equip;
  460. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  461. $ins_equip = new Ins_Equip($equipDic->$uid);
  462. $posId = $ins_equip->mo()->position;
  463. StlUtil::dictRemove(ctx()->store(true)->equipLocation, $posId);
  464. UserProc::updateUserInfo();
  465. return Resp::ok(array());
  466. }
  467. /**
  468. * 洗练
  469. * @return Resp
  470. */
  471. public static function GemXiLian() {
  472. list($uid) = req()->paras;
  473. //把 qual pos u一样的宝石开锁关锁
  474. $gemStore = ctx()->store->gemStore;
  475. my_Assert(StlUtil::dictHasProperty($gemStore, $uid), ErrCode::user_store_NotExistGem);
  476. $gem = new Ins_Gem($gemStore->$uid);
  477. my_Assert($gem->mo()->qual >= 5, ErrCode::user_store_XilianStoneNoEnough);
  478. $arr = explode(';', glc()->XILianGemlNeedXILianStone);
  479. $needStone = 0;
  480. $xilianStoneId = 0;
  481. foreach ($arr as $val) {
  482. $str = explode(':', $val);
  483. if ($str[0] == $gem->mo()->qual) {
  484. $s = explode(',', $str[1]);
  485. $needStone = $s[1];
  486. $xilianStoneId = $s[0];
  487. break;
  488. }
  489. }
  490. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $xilianStoneId) && ctx()->store->items->$xilianStoneId >= $needStone, ErrCode::user_store_XilianStoneNoEnough);
  491. $dic = GameConfig::predicate();
  492. $pList = array();
  493. foreach ($dic as $id => $pMo) {
  494. if ($pMo->positions != null && $pMo->qual != null) {
  495. $list = explode(',', $pMo->positions);
  496. if ($pMo->id != $gem->predicateId && $pMo->qual == $gem->mo()->qual && in_array($gem->mo()->position, $list) && $pMo->attachTarget == "gem") {
  497. $pList[] = $pMo->id;
  498. }
  499. }
  500. }
  501. my_Assert(count($pList) > 0, ErrCode::user_store_NoFindPredicate);
  502. $rand = random_int(0, count($pList) - 1);
  503. $pId = $pList[$rand];
  504. ctx()->store->gemStore->$uid->predicateId = $pId;
  505. ctx()->store->removeItem($xilianStoneId, $needStone);
  506. $xilianStoneNum = 0;
  507. if (StlUtil::dictHasProperty(ctx()->store->items, $xilianStoneId)) {
  508. $xilianStoneNum = ctx()->store->items->$xilianStoneId;
  509. }
  510. UserProc::updateUserInfo();
  511. return Resp::ok(array(
  512. 'xilianStoneId' => $xilianStoneId,
  513. 'xilianStone' => $xilianStoneNum,
  514. 'predicateId' => $pId,
  515. ));
  516. }
  517. /**
  518. * 宝石开锁解锁
  519. * @return Resp
  520. */
  521. public static function GemLockState() {
  522. list($uid) = req()->paras;
  523. $user = ctx();
  524. //把 qual pos u一样的宝石开锁关锁
  525. $gemStore = $user->store->gemStore;
  526. $gem = $gemStore->$uid;
  527. $tag = 0;
  528. if ($gem->isUnlock == 0) {
  529. $gem->isUnlock = 1;
  530. $tag = 1;
  531. } else {
  532. $gem->isUnlock = 0;
  533. $tag = 0;
  534. }
  535. $gemStore->$uid = $gem;
  536. foreach ($gemStore as $k => $ins_gem) {
  537. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  538. $gemStore->$k->isUnlock = $tag;
  539. }
  540. }
  541. $user->store->gemStore = $gemStore;
  542. ctx($user);
  543. UserProc::updateUserInfo();
  544. return Resp::ok(array(
  545. 'gold' => 0,
  546. 'store' => $user->store,
  547. ));
  548. }
  549. /**
  550. * 切换装备分页
  551. * @return Resp
  552. */
  553. public static function SwitchEquipPag() {
  554. list($index) = req()->paras;
  555. $user = ctx();
  556. $user->store->equipPag = $index;
  557. ctx($user);
  558. UserProc::updateUserInfo();
  559. return Resp::ok(array());
  560. }
  561. /**
  562. * 所有装备的一键升级
  563. * 规则:等级不同从等级小到大,等级一样按照部位顺序
  564. *
  565. * @return Resp
  566. */
  567. public static function AllEquipUpgrade() {
  568. //list() = req()->paras;
  569. //$user = ctx();
  570. // $equipDic = $user->store->equipPosition;
  571. //
  572. // $equip_levelDic = GameConfig::equip_levelupgrade();
  573. // $maxLv = count(StlUtil::dictToArray($equip_levelDic));
  574. // $arr = array();
  575. // if ($equipDic != null) {
  576. // foreach ($equipDic as $k => &$equip) {
  577. // $equip = new Ins_EquipPosition($equip);
  578. //
  579. // if ($equip->level >= $maxLv) {
  580. // continue;
  581. // }
  582. //
  583. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  584. // $needGold = $lvMo->needGold;
  585. // $needItemNum = $lvMo->needItemNum;
  586. // $neeItemId = $equip->mo()->costTuzhiId;
  587. //
  588. // if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  589. // $arr[] = $equip;
  590. // }
  591. // }
  592. // }
  593. // $upLevelArr = array();
  594. // if (count($arr) > 0) {
  595. // //进行排序
  596. // $len = count($arr);
  597. // for ($i = 0; $i < $len - 1; $i++) {
  598. // for ($j = 0; $j < $len - $i - 1; $j++) {
  599. // if ($arr[$j]->level > $arr[$j + 1]->level) {//从小到大
  600. // $temp = $arr[$j];
  601. // $arr[$j] = $arr[$j + 1];
  602. // $arr[$j + 1] = $temp;
  603. // } elseif ($arr[$j]->level == $arr[$j + 1]->level) {
  604. // $j_equip = new Ins_EquipPosition($arr[$j]);
  605. // $jj_equip = new Ins_EquipPosition($arr[$j + 1]);
  606. // if ($j_equip->mo()->position > $jj_equip->mo()->position) {
  607. // $temp = $arr[$j];
  608. // $arr[$j] = $arr[$j + 1];
  609. // $arr[$j + 1] = $temp;
  610. // }
  611. // }
  612. // }
  613. // }
  614. //升级,扣除金币和图纸
  615. // while (true) {
  616. // $tag = 9999;
  617. // foreach ($arr as $index => &$equip) {
  618. // $ins_equip = new Ins_EquipPosition($equip);
  619. // $lvMo = GameConfig::equip_levelupgrade_getItem($ins_equip->level);
  620. // $needGold = $lvMo->needGold;
  621. // $needItemNum = $lvMo->needItemNum;
  622. // $neeItemId = $ins_equip->mo()->costTuzhiId;
  623. // if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  624. // $id = $ins_equip->typeId;
  625. // if (!in_array($id, $upLevelArr)) {
  626. // $upLevelArr[] = $id;
  627. // }
  628. //
  629. // $ins_equip->level += 1;
  630. // $equipDic->$id->level += 1;
  631. // $user->baseInfo->Consume_Gold($needGold);
  632. // $user->store->removeItem($neeItemId, $needItemNum);
  633. // if ($ins_equip->level >= 99) {
  634. // $tag = $index;
  635. // break;
  636. // }
  637. // } else {
  638. // $tag = $index;
  639. // break;
  640. // }
  641. // }
  642. // if ($tag != 9999) {
  643. // if (array_key_exists($tag, $arr)) {
  644. // StlUtil::arrayRemoveAt($arr, $tag);
  645. // }
  646. // }
  647. //
  648. // if (count($arr) <= 0) {
  649. // break;
  650. // }
  651. // }
  652. // }
  653. // TaskProc::OnAnyEquipUpLevel_X();
  654. // TaskProc::OnAllEquipUpLevel_X();
  655. // TaskProc::OnEquipLevelUpNum();
  656. // ctx($user);
  657. //
  658. // FightProc::Ranking_FightPower();
  659. UserProc::updateUserInfo();
  660. return Resp::ok(array(
  661. 'upLevelArr' => $upLevelArr,
  662. 'gold' => $user->baseInfo->gold,
  663. 'store' => $user->store,
  664. 'task' => $user->task,
  665. ));
  666. }
  667. /**
  668. * 6411 移除是新宝石绿点提示
  669. * @return Resp
  670. */
  671. public static function RemoveNewGemTip() {
  672. list($uid) = req()->paras; //宝石uid
  673. my_Assert(StlUtil::dictHasProperty(ctx()->store->gemStore, $uid), ErrCode::user_store_NoItem);
  674. ctx()->store(true)->gemStore->$uid->isNew = 0;
  675. UserProc::updateUserInfo();
  676. return Resp::ok(array());
  677. }
  678. /**
  679. * 移除装备可以升级绿点提示 -------废弃
  680. * @return Resp
  681. */
  682. public static function RemoveEquipUpgradeTip() {
  683. // list($posId) = req()->paras; //装备部位
  684. // $user = ctx();
  685. //
  686. // my_Assert(StlUtil::dictHasProperty($user->store->equipPosition, $posId), ErrCode::user_store_NoEquip);
  687. //
  688. // $user->store->equipPosition->$posId->tip = 0;
  689. //
  690. // ctx($user);
  691. // UserProc::updateUserInfo();
  692. // return Resp::ok(array(
  693. // 'gold' => 0,
  694. // 'store' => $user->store,));
  695. }
  696. /**
  697. * 6406 合成
  698. * @return type
  699. */
  700. public static function GemCompose() {
  701. list($gemIds) = req()->paras;
  702. $list = explode(';', $gemIds);
  703. $gemStore = ctx()->store->gemStore;
  704. $composeArr = array();
  705. foreach ($list as $gems) {
  706. $gemArr = explode('-', $gems);
  707. $length1 = strlen($gemArr[0]);
  708. $length2 = strlen($gemArr[1]);
  709. $gem_composeCost = explode(',', substr($gemArr[0], 1, $length1 - 1)); //去掉逗号
  710. $gem_composeIds = explode(',', substr($gemArr[1], 1, $length2 - 1)); //去掉逗号
  711. $gemMo = GameConfig::gem_getItem($gem_composeIds[0]);
  712. my_Assert(null != $gemMo, ErrCode::err_const_no);
  713. $isCompose = true;
  714. foreach ($gem_composeCost as $gemUid) {
  715. if (!StlUtil::dictHasProperty($gemStore, $gemUid)) {
  716. $isCompose = false;
  717. break;
  718. }
  719. $ins_gem = new Ins_Gem($gemStore->$gemUid);
  720. if ($ins_gem->mo()->qual + 1 != $gemMo->qual || $ins_gem->mo()->position != $gemMo->position) {
  721. $isCompose = false;
  722. break;
  723. }
  724. if (!self::GemIsCanCompose($gemUid)) {
  725. $isCompose = false;
  726. break;
  727. }
  728. }
  729. my_Assert($isCompose == true, ErrCode::user_store_GemCanotCompose);
  730. foreach ($gem_composeCost as $gemUid) {
  731. self::RemoveGemInStore($gemUid);
  732. }
  733. foreach ($gem_composeIds as $gemTypeId) {
  734. $composeGem = self::initGem($gemTypeId);
  735. self::PutGemInStore($composeGem);
  736. $composeArr[] = $composeGem->uid; //临时放这
  737. }
  738. }
  739. TaskProc::OnComposeNumGem();
  740. TaskProc::OnComposeNumGem_state();
  741. UserProc::updateUserInfo();
  742. return Resp::ok(array(
  743. 'composeGemIds' => $composeArr,
  744. 'store' => ctx()->store,
  745. 'task' => ctx()->task,
  746. ));
  747. }
  748. /**
  749. * 该宝石是否可以参与合成,其他页镶嵌的,已经被锁的都不能参与
  750. * @param type $uid
  751. * @return bool
  752. */
  753. private static function GemIsCanCompose($uid) {
  754. $ins_gem = new Ins_Gem($uid);
  755. if ($ins_gem->isUnlock == 1) {
  756. return false;
  757. }
  758. $isExist = true;
  759. $equip = ctx()->store->equip;
  760. foreach ($equip as $uid => $item) {
  761. $arr = get_object_vars($item->gemSetSlot);
  762. $values = array_values($arr);
  763. if (in_array($uid, $values)) {
  764. $isExist = false;
  765. break;
  766. }
  767. }
  768. return $isExist;
  769. }
  770. /**
  771. * 装备宝石
  772. * @return type
  773. */
  774. public static function GemSet() {
  775. list($equipUid, $uid, $type, $replaceUId) = req()->paras; //宝石uid 手动的时候记得校验u $replaceUId宝石槽坑位id
  776. my_Assert(StlUtil::dictHasProperty(ctx()->store->gemStore, $uid), ErrCode::user_store_NoItem);
  777. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $equipUid), ErrCode::user_store_NoEquip);
  778. $ins_equip = new Ins_Equip(ctx()->store->equip->$equipUid);
  779. $ins_gem = new Ins_Gem(ctx()->store->gemStore->$uid);
  780. my_Assert($ins_equip->mo()->position == $ins_gem->mo()->position, ErrCode::user_store_PositionNotFit);
  781. $gemSetSlotDic = $ins_equip->gemSetSlot;
  782. $tag_index = 0;
  783. $tag_gem = null;
  784. foreach ($gemSetSlotDic as $slotId => $gemUid) {
  785. if ($gemUid == 0) {
  786. continue;
  787. }
  788. $gem = new Ins_Gem(ctx()->store->gemStore->$gemUid);
  789. if ($gem->predicateMo()->uniqueKey == $ins_gem->predicateMo()->uniqueKey) {
  790. $tag_index = $slotId;
  791. $tag_gem = $gem;
  792. break;
  793. }
  794. }
  795. $mo = GameConfig::gem_slotposition_getItem($ins_equip->qual);
  796. my_Assert(null != $mo, ErrCode::err_const_no);
  797. switch ($type) {
  798. case 1://镶嵌
  799. my_Assert($tag_gem == null, ErrCode::user_store_GemCanotSet);
  800. $go_index = 1;
  801. for ($i = 1; $i <= $mo->initNum_slot + $mo->buyNum_slot; $i++) {
  802. if (!StlUtil::dictHasProperty($gemSetSlotDic, $i)) {
  803. //$gemSetSlotDic->$i = $ins_gem;
  804. $go_index = $i;
  805. break;
  806. }
  807. if ($gemSetSlotDic->$i == 0) {
  808. $go_index = $i;
  809. break;
  810. }
  811. }
  812. $gemSetSlotDic->$go_index = $uid;
  813. break;
  814. case 2://替换
  815. //满不满都高替低品阶
  816. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  817. $gUid = $gemSetSlotDic->$replaceUId;
  818. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid); //这个$replaceUId是坑位的index id
  819. my_Assert($replace_ins_Gem->mo()->qual < $ins_gem->mo()->qual, ErrCode::user_store_NoExistGemReplace);
  820. //$gemSetSlotDic->$replaceUId = $ins_gem;
  821. $gemSetSlotDic->$replaceUId = $uid;
  822. break;
  823. case 3://手动
  824. my_Assert(count((array) $gemSetSlotDic) >= $mo->initNum_slot + $mo->buyNum_slot, ErrCode::user_store_GemCanotSet);
  825. $gUid = $gemSetSlotDic->$replaceUId;
  826. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  827. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid);
  828. //$id = $replace_ins_Gem->uid;
  829. if ($tag_gem != null) {//如果有u那
  830. my_Assert($replace_ins_Gem->uid == $tag_gem->uid, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  831. //有U一样的,则点击正好是这个直接替换
  832. //$gemSetSlotDic->$tag_index = $ins_gem;
  833. $gemSetSlotDic->$tag_index = $uid;
  834. } else {
  835. // $go_index = 0;
  836. // foreach ($gemSetSlotDic as $slotId => $gemUid) {
  837. // if ($slotId == $replaceUId) {
  838. // $go_index = $slotId;
  839. // break;
  840. // }
  841. // }
  842. //
  843. // my_Assert($go_index > 0, ErrCode::user_store_NoExistGemReplace);
  844. //$gemSetSlotDic->$go_index = $ins_gem;
  845. $gemSetSlotDic->$replaceUId = $uid;
  846. }
  847. break;
  848. case 4://不能
  849. //1.小品阶替大品阶 或是 相等的,在不满的时候不允许 2. //满的 相等不允许替
  850. my_Assert($uid == 0, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  851. break;
  852. default:
  853. break;
  854. }
  855. $ins_equip->gemSetSlot = $gemSetSlotDic;
  856. ctx()->store(true)->equip->$equipUid = $ins_equip;
  857. TaskProc::OnSetSpecialQualGem();
  858. FightProc::Ranking_FightPower();
  859. UserProc::updateUserInfo();
  860. return Resp::ok(array(
  861. 'gold' => 0,
  862. 'store' => ctx()->store,
  863. 'task' => ctx()->task,
  864. ));
  865. }
  866. /**
  867. * 卸下装备
  868. * @return type
  869. */
  870. public static function GemRemove() {
  871. list($uid) = req()->paras; //装备宝石id
  872. $equips = ctx()->store->equip;
  873. foreach ($equips as $eUid => $ins_equip) {
  874. $dic = $ins_equip->gemSetSlot;
  875. foreach ($dic as $slotId => $gemUid) {
  876. if ($uid == $gemUid) {
  877. ctx()->store->equip->$eUid->gemSetSlot->$slotId = 0;
  878. break 2;
  879. }
  880. }
  881. }
  882. FightProc::Ranking_FightPower();
  883. UserProc::updateUserInfo();
  884. return Resp::ok(array(
  885. 'gold' => 0,
  886. 'store' => ctx()->store,));
  887. }
  888. /**
  889. * 6404 升级装备
  890. * @return type
  891. */
  892. public static function EquipUpgrade() {
  893. list($uid) = req()->paras; //装备uid
  894. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  895. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  896. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_equipLevelLimit);
  897. $mo = GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $ins_equip->level);
  898. my_Assert(null != $mo, ErrCode::err_const_no);
  899. my_Assert(ctx()->baseInfo->gold >= $mo->needGold, ErrCode::notenough_gold_msg);
  900. $costTuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  901. $tuzhiNum = 0;
  902. if (StlUtil::dictHasProperty(ctx()->store->items, $costTuzhiId)) {
  903. $tuzhiNum = ctx()->store->items->$costTuzhiId;
  904. }
  905. my_Assert($tuzhiNum >= $mo->needItemNum, ErrCode::notenough_item);
  906. ctx()->store(true)->removeItem($costTuzhiId, $mo->needItemNum);
  907. ctx()->base(true)->Consume_Gold($mo->needGold);
  908. $ins_equip->level += 1;
  909. ctx()->store->equip->$uid = $ins_equip;
  910. TaskProc::OnAnyEquipUpLevel_X();
  911. TaskProc::OnAllEquipUpLevel_X();
  912. TaskProc::OnEquipLevelUpNum();
  913. FightProc::Ranking_FightPower();
  914. UserProc::updateUserInfo();
  915. return Resp::ok(array(
  916. 'gold' => ctx()->baseInfo->gold,
  917. 'store' => ctx()->store,
  918. 'task' => ctx()->task,
  919. ));
  920. }
  921. /**
  922. * 6405 单个装备部位一键升级
  923. * @return type
  924. */
  925. public static function EquipUpgrade_MaxLv() {
  926. list($uid) = req()->paras;
  927. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  928. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  929. $maxLevel = $ins_equip->Equip_MaxLevel();
  930. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_equipLevelLimit);
  931. $tuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  932. $itemNum_store = 0;
  933. if (StlUtil::dictHasProperty(ctx()->store->items, $tuzhiId)) {
  934. $itemNum_store = ctx()->store->items->$tuzhiId;
  935. }
  936. $up_Gold = 0;
  937. $up_needItem = 0;
  938. $up_lv = 0;
  939. $noUp_gold = false;
  940. $noUp_item = false;
  941. $need_gold = 0;
  942. $need_item = 0;
  943. for ($i = $ins_equip->level; $i <= $maxLevel; $i++) {
  944. $up_Gold += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $i)->needGold;
  945. $up_needItem += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $i)->needItemNum;
  946. if (ctx()->baseInfo->gold >= $up_Gold) {
  947. $noUp_gold = true;
  948. }
  949. if ($itemNum_store >= $up_needItem) {
  950. $noUp_item = true;
  951. }
  952. $up_lv = $i;
  953. if (ctx()->baseInfo->gold >= $up_Gold && $itemNum_store >= $up_needItem) {
  954. $need_gold = $up_Gold;
  955. $need_item = $up_needItem;
  956. continue;
  957. }
  958. break;
  959. }
  960. if ($up_lv == 0) {
  961. my_Assert($noUp_gold, ErrCode::notenough_gold_msg);
  962. my_Assert($noUp_item, ErrCode::notenough_item);
  963. }
  964. ctx()->base(true)->Consume_Gold($need_gold);
  965. ctx()->store(true)->removeItem($tuzhiId, $need_item);
  966. if ($up_lv > 0) {
  967. ctx()->store->equip->$uid->level = $up_lv;
  968. }
  969. TaskProc::OnAnyEquipUpLevel_X();
  970. TaskProc::OnAllEquipUpLevel_X();
  971. TaskProc::OnEquipLevelUpNum();
  972. FightProc::Ranking_FightPower();
  973. UserProc::updateUserInfo();
  974. return Resp::ok(array(
  975. 'gold' => ctx()->baseInfo->gold,
  976. 'store' => ctx()->store,
  977. 'task' => ctx()->task,
  978. ));
  979. }
  980. public static function AddItemInStore() {
  981. list($rwdStr) = req()->paras; //mask = 1:表示战斗中掉落
  982. $user = ctx();
  983. $err = self::AddMultiItemInStore($rwdStr);
  984. my_Assert(ErrCode::ok == $err, $err);
  985. UserProc::updateUserInfo();
  986. return Resp::ok(array(
  987. //'gold' => $user->baseInfo->gold,
  988. //'tili' => $user->baseInfo->tili,
  989. //'cash' => $user->baseInfo->cash,
  990. 'store' => $user->store));
  991. }
  992. static $reward = array();
  993. static $reward_Gem = array();
  994. static $reward_equip = array();
  995. //static $reward_hero = array();
  996. /**
  997. * 具体奖励存入背包
  998. * @param type $goodsStr
  999. * @param type $src
  1000. */
  1001. public static function AddMultiItemInStore($goodsStr, $src = 0) {
  1002. if ($goodsStr == null) {
  1003. return;
  1004. }
  1005. $ary = explode(";", $goodsStr);
  1006. foreach ($ary as $value) {
  1007. $val = explode(",", $value);
  1008. my_Assert(count($val) > 1, "解析奖励字符串出错");
  1009. list($itemId, $num) = $val; # ID, 数量
  1010. $itemMo = GameConfig::item_getItem($itemId);
  1011. if ($itemMo->itemType != 701 && $itemMo->itemType != 201 && $itemMo->itemType != 502 && $itemMo->itemType != 101 && $src != 1) {
  1012. self::$reward[] = $value;
  1013. }
  1014. switch ($itemMo->itemType) {
  1015. case 1:
  1016. ctx()->baseInfo->Add_Gold($num);
  1017. //self::checkEquipUpgradeTip();//废弃
  1018. break;
  1019. case 2:
  1020. ctx()->baseInfo->Add_Cash($num);
  1021. break;
  1022. case 3:
  1023. ctx()->baseInfo->Add_tili($num);
  1024. break;
  1025. case 4:
  1026. ctx()->baseInfo->Add_Exp($num);
  1027. break;
  1028. case 100://图纸
  1029. case 103://钥匙
  1030. case 401://启灵石
  1031. case 301://洗练石
  1032. case 501://人物碎片
  1033. case 601://人身果
  1034. case 801://寻宝券
  1035. case 901:
  1036. self::PutItemsInStore($itemId, $num);
  1037. // if ($itemMo->itemType == 100) {//图纸
  1038. // self::checkEquipUpgradeTip();//废弃
  1039. // }
  1040. break;
  1041. case 502://角色卡
  1042. HeroProc::RoleCardUnlockHero($itemId, $num);
  1043. break;
  1044. case 201://宝石
  1045. for ($i = 0; $i < $num; $i++) {
  1046. $gem = self::initGem($itemId);
  1047. if ($src != 1) {
  1048. self::$reward_Gem[] = $gem->uid;
  1049. }
  1050. self::PutGemInStore($gem);
  1051. if ($src == Enum_StoreSourceType::ShopBox) {
  1052. SystemProc::GetGem_GreaterOrangeQual_ShopBox(req()->zoneid, ctx()->baseInfo->name, $gem->typeId);
  1053. }
  1054. }
  1055. break;
  1056. case 101:
  1057. //self::PutEquipInStore($itemId, $num);
  1058. for ($i = 0; $i < $num; $i++) {
  1059. $equip = self::initEquip($itemId);
  1060. $uid = $equip->uid;
  1061. ctx()->store(true)->equip->$uid = $equip;
  1062. FightProc::funUnlock_equip_firstTime();
  1063. self::$reward_equip[] = $uid;
  1064. }
  1065. break;
  1066. case 701://道具宝箱
  1067. for ($i = 0; $i < $num; $i++) {
  1068. self::DistributeItemsBox($itemId);
  1069. }
  1070. break;
  1071. default:
  1072. break;
  1073. }
  1074. }
  1075. }
  1076. /**
  1077. * 装备回存
  1078. * @param type $itemId
  1079. * @param type $num
  1080. */
  1081. public static function PutEquipInStore($itemId, $num) {
  1082. for ($i = 0; $i < $num; $i++) {
  1083. $equip = self::initEquip($itemId);
  1084. $uid = $equip->uid;
  1085. ctx()->store(true)->equip->$uid = $equip;
  1086. }
  1087. }
  1088. public static function initEquip($typeId, $uid = 0) {
  1089. if ($uid == 0) {
  1090. $uid = ctx()->store->nextUID();
  1091. }
  1092. $ins_equip = new Ins_Equip();
  1093. $ins_equip->uid = $uid;
  1094. $ins_equip->typeId = $typeId;
  1095. $ins_equip->qual = GameConfig::equip_getItem($typeId)->qual;
  1096. return $ins_equip;
  1097. }
  1098. public static function PutItemsInStore($itemId, $num) {
  1099. $items = ctx()->store->items;
  1100. if (StlUtil::dictHasProperty($items, $itemId)) {
  1101. $items->$itemId += $num;
  1102. } else {
  1103. $items->$itemId = $num;
  1104. }
  1105. ctx()->store->items = $items;
  1106. }
  1107. /**
  1108. * 拆分宝箱盒子
  1109. * @param type $reward
  1110. */
  1111. public static function DistributeItemsBox($itemId) {
  1112. $itemBoxMo = GameConfig::item_2023_box_getItem($itemId);
  1113. my_Assert($itemBoxMo != null, ErrCode::err_const_no);
  1114. if ($itemBoxMo->type == 1) {
  1115. $reward = self::Distribute_Rewards($itemBoxMo->contents);
  1116. self::AddMultiItemInStore($reward);
  1117. } else {
  1118. self::AddMultiItemInStore($itemBoxMo->contents);
  1119. }
  1120. }
  1121. public static function Distribute_Rewards($contents) {
  1122. $strList = explode(';', $contents);
  1123. $numList = explode('-', $strList[0]);
  1124. $randNum = rand($numList[0], $numList[1]);
  1125. $ctxList = explode(',', $strList[1]);
  1126. $per = 0;
  1127. foreach ($ctxList as $value) {
  1128. $ctx = explode(':', $value);
  1129. $per += $ctx[1];
  1130. }
  1131. $reward = "";
  1132. for ($i = 0; $i < $randNum; $i++) {
  1133. $ctxPer = rand(1, $per);
  1134. $start = 0;
  1135. $end = 0;
  1136. $id = 0;
  1137. foreach ($ctxList as $value) {
  1138. $ctx = explode(':', $value);
  1139. $end += $ctx[1];
  1140. if ($ctxPer > $start && $ctxPer <= $end) {
  1141. $id = $ctx[0];
  1142. break;
  1143. }
  1144. $start = $end;
  1145. }
  1146. if ($id != 0) {
  1147. $str = $id . ',1';
  1148. if ($reward == "") {
  1149. $reward = $str;
  1150. } else {
  1151. $reward = $reward . ';' . $str;
  1152. }
  1153. }
  1154. }
  1155. return $reward;
  1156. }
  1157. // public static function PutEquipInStore($equipId, $num) {
  1158. // if ($equipId == 0) {
  1159. // return;
  1160. // }
  1161. // $n = count((array) ctx()->store->equip) + 1;
  1162. //
  1163. // for ($index = 0; $index < $num; $index++) {
  1164. // $Equip = new Ins_Equip();
  1165. // $Equip->uid = $n;
  1166. // $Equip->typeId = $equipId;
  1167. // $Equip->qual = GameConfig::equip_getItem($equipId)->qual;
  1168. // ctx()->store->equip->$n = $Equip;
  1169. // $n += 1;
  1170. // }
  1171. // }
  1172. /**
  1173. * 得到金币或是图纸的时候校验下,是否满足装备升级条件,满足则tip字段设置为1 废弃
  1174. */
  1175. // public static function checkEquipUpgradeTip() {
  1176. // $equipDic = ctx()->store->equipPosition;
  1177. // if ($equipDic != null) {
  1178. // foreach ($equipDic as $k => &$equip) {
  1179. // $equip = new Ins_EquipPosition($equip);
  1180. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  1181. // $needGold = $lvMo->needGold;
  1182. // $needItemNum = $lvMo->needItemNum;
  1183. // $neeItemId = $equip->mo()->costTuzhiId;
  1184. //
  1185. // if (ctx()->baseInfo->gold >= $needGold && StlUtil::dictHasProperty(ctx()->store->items, $neeItemId) && ctx()->store->items->$neeItemId >= $needItemNum) {
  1186. // $equipDic->$k->tip = 1; //绿点是每次得到金币或是图纸了,只要满足升级条件都变绿
  1187. // }
  1188. // }
  1189. // }
  1190. // ctx()->store->equipPosition = $equipDic;
  1191. // }
  1192. /**
  1193. * 新宝石入库
  1194. */
  1195. public static function PutGemIdInStore($id, $num = 1) {
  1196. for ($i = 0; $i < $num; $i++) {
  1197. $gem = self::initGem($id);
  1198. $length = $gem->uid;
  1199. ctx()->store->gemStore->$length = $gem;
  1200. }
  1201. }
  1202. public static function PutGemInStore($gem, $num = 1) {
  1203. for ($i = 0; $i < $num; $i++) {
  1204. $length = $gem->uid;
  1205. ctx()->store->gemStore->$length = $gem;
  1206. }
  1207. }
  1208. public static function initGem($id) {
  1209. $length = ctx()->store->gemLength;
  1210. $length += 1;
  1211. $gem = new Ins_Gem();
  1212. $gem->uid = $length;
  1213. $gem->typeId = $id;
  1214. $gem->predicateId = self::RandomGemPredicateId($id);
  1215. $tag = self::CheckNewGemTip($gem);
  1216. $gem->isNew = $tag;
  1217. ctx()->store->gemLength = $length;
  1218. return $gem;
  1219. }
  1220. /**
  1221. * 从仓库移除宝石
  1222. */
  1223. public static function RemoveGemInStore($uid) {
  1224. if (StlUtil::dictHasProperty(ctx()->store->gemStore, $uid)) {
  1225. StlUtil::dictRemove(ctx()->store->gemStore, $uid);
  1226. }
  1227. return 0;
  1228. }
  1229. /**
  1230. * 新宝石随机词条 临时等刚哥
  1231. */
  1232. public static function RandomGemPredicateId($id) {
  1233. $mo = GameConfig::gem_getItem($id);
  1234. my_Assert(null != $mo, "找不到宝石{$id}的配置数据");
  1235. if ($mo->isfixed_predicateId == 1) {
  1236. return $mo->predicateId;
  1237. }
  1238. $posId = $mo->position;
  1239. $qual = $mo->qual;
  1240. $arr = array();
  1241. $predicateMo = GameConfig::predicate();
  1242. foreach ($predicateMo as $key => $value) {
  1243. if ($value->positions != null) {
  1244. $list = explode(',', $value->positions);
  1245. if ($value->qual == $qual && in_array($posId, $list) && $value->attachTarget == "gem") {
  1246. $arr[] = $value->id;
  1247. }
  1248. }
  1249. }
  1250. if (count($arr) <= 0) {
  1251. return 40;
  1252. }
  1253. my_Assert(count($arr) > 0, "宝石没有对应词条信息");
  1254. $n = mt_rand(0, count($arr) - 1);
  1255. return $arr[$n];
  1256. //return 40;
  1257. }
  1258. /**
  1259. * 新宝石提示
  1260. */
  1261. public static function CheckNewGemTip($gem) {
  1262. $gemStore = ctx()->store->gemStore;
  1263. $tag = false;
  1264. foreach ($gemStore as $k => $ins_gem) {
  1265. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  1266. $tag = true;
  1267. break;
  1268. }
  1269. }
  1270. return $tag == true ? 0 : 1;
  1271. }
  1272. //临时代码
  1273. // public static function InitGemInfo() {
  1274. // if(count((array)ctx()->store->gemStore) > 0){
  1275. // return;
  1276. // }
  1277. //
  1278. // $index = 0;
  1279. // $gem = GameConfig::gem();
  1280. //
  1281. // for ($i = 1; $i <=21; $i++) {
  1282. // foreach ($gem as $key => $value) {
  1283. // if($value->id == $i){
  1284. // self::PutGemInStore($value->typeId);
  1285. // }
  1286. //
  1287. // }
  1288. // }
  1289. //
  1290. //
  1291. //
  1292. //
  1293. // }
  1294. }