StoreProc.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  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. default:
  52. Err(ErrCode::cmd_err);
  53. }
  54. }
  55. /**
  56. * 6416 购买装备宝石槽
  57. * @return type
  58. */
  59. public static function Gem_BuySlot() {
  60. list($uid) = req()->paras;
  61. $equipDic = ctx()->store->equip;
  62. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  63. $ins_equip = new Ins_Equip($equipDic->$uid);
  64. $mo = GameConfig::gem_slotposition_getItem($ins_equip->mo()->qual);
  65. my_Assert(null != $mo, ErrCode::err_const_no);
  66. $initNum = $mo->initNum_slot;
  67. $buyNum = $mo->buyNum_slot;
  68. $unlockIndex = 0;
  69. if($buyNum > 0){
  70. for ($i = $initNum+1; $i <= $initNum+$buyNum; $i++) {
  71. if(!StlUtil::dictHasProperty($ins_equip->gemSetSlot, $i)){
  72. $ins_equip->gemSetSlot->$i = 0;
  73. break;
  74. }
  75. $unlockIndex += 1;
  76. }
  77. }
  78. $costArr = explode(';',$mo->cost);
  79. $cash = explode(',', $costArr[$unlockIndex]);
  80. my_Assert(ctx()->base(true)->cash >= $cash[1], ErrCode::notenough_cash_msg);
  81. ctx()->base(true)->Consume_Cash($unlockIndex);
  82. ctx()->store(true)->equip->$uid = $ins_equip;
  83. UserProc::updateUserInfo();
  84. return Resp::ok(array(
  85. 'cash'=> ctx()->baseInfo->cash,
  86. 'store'=> ctx()->store,
  87. ));
  88. }
  89. /**
  90. * 6413 装备
  91. * @return type
  92. */
  93. public static function Equiped() {
  94. list($uid) = req()->paras;
  95. $equipDic = ctx()->store->equip;
  96. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  97. $ins_equip = new Ins_Equip($equipDic->$uid);
  98. $posId = $ins_equip->mo()->position;
  99. ctx()->store(true)->equipLocation->$posId = $uid;
  100. UserProc::updateUserInfo();
  101. return Resp::ok(array());
  102. }
  103. /**
  104. * 6413 卸下装备
  105. * @return type
  106. */
  107. public static function RemoveEquip() {
  108. list($uid) = req()->paras;
  109. $equipDic = ctx()->store->equip;
  110. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  111. $ins_equip = new Ins_Equip($equipDic->$uid);
  112. $posId = $ins_equip->mo()->position;
  113. StlUtil::dictRemove(ctx()->store(true)->equipLocation, $posId);
  114. UserProc::updateUserInfo();
  115. return Resp::ok(array());
  116. }
  117. /**
  118. * 洗练
  119. * @return Resp
  120. */
  121. public static function GemXiLian() {
  122. list($uid) = req()->paras;
  123. //把 qual pos u一样的宝石开锁关锁
  124. $gemStore = ctx()->store->gemStore;
  125. my_Assert(StlUtil::dictHasProperty($gemStore, $uid), ErrCode::user_store_NotExistGem);
  126. $gem = new Ins_Gem($gemStore->$uid);
  127. my_Assert($gem->mo()->qual >= 5, ErrCode::user_store_XilianStoneNoEnough);
  128. $arr = explode(';', glc()->XILianGemlNeedXILianStone);
  129. $needStone = 0;
  130. $xilianStoneId = 0;
  131. foreach ($arr as $val) {
  132. $str = explode(':', $val);
  133. if ($str[0] == $gem->mo()->qual) {
  134. $s = explode(',', $str[1]);
  135. $needStone = $s[1];
  136. $xilianStoneId = $s[0];
  137. break;
  138. }
  139. }
  140. my_Assert(StlUtil::dictHasProperty(ctx()->store->items,$xilianStoneId) && ctx()->store->items->$xilianStoneId >= $needStone, ErrCode::user_store_XilianStoneNoEnough);
  141. $dic = GameConfig::predicate();
  142. $pList = array();
  143. foreach ($dic as $id => $pMo) {
  144. if ($pMo->positions != null && $pMo->qual != null) {
  145. $list = explode(',', $pMo->positions);
  146. if ($pMo->id != $gem->predicateId && $pMo->qual == $gem->mo()->qual && in_array($gem->mo()->position, $list) && $pMo->attachTarget == "gem") {
  147. $pList[] = $pMo->id;
  148. }
  149. }
  150. }
  151. my_Assert(count($pList) > 0, ErrCode::user_store_NoFindPredicate);
  152. $rand = random_int(0, count($pList) - 1);
  153. $pId = $pList[$rand];
  154. ctx()->store->gemStore->$uid->predicateId = $pId;
  155. ctx()->store->removeItem($xilianStoneId, $needStone);
  156. $xilianStoneNum = 0;
  157. if(StlUtil::dictHasProperty(ctx()->store->items, $xilianStoneId)){
  158. $xilianStoneNum = ctx()->store->items->$xilianStoneId;
  159. }
  160. UserProc::updateUserInfo();
  161. return Resp::ok(array(
  162. 'xilianStoneId' => $xilianStoneId,
  163. 'xilianStone' => $xilianStoneNum,
  164. 'predicateId' => $pId,
  165. ));
  166. }
  167. /**
  168. * 宝石开锁解锁
  169. * @return Resp
  170. */
  171. public static function GemLockState() {
  172. list($uid) = req()->paras;
  173. $user = ctx();
  174. //把 qual pos u一样的宝石开锁关锁
  175. $gemStore = $user->store->gemStore;
  176. $gem = $gemStore->$uid;
  177. $tag = 0;
  178. if ($gem->isUnlock == 0) {
  179. $gem->isUnlock = 1;
  180. $tag = 1;
  181. } else {
  182. $gem->isUnlock = 0;
  183. $tag = 0;
  184. }
  185. $gemStore->$uid = $gem;
  186. foreach ($gemStore as $k => $ins_gem) {
  187. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  188. $gemStore->$k->isUnlock = $tag;
  189. }
  190. }
  191. $user->store->gemStore = $gemStore;
  192. ctx($user);
  193. UserProc::updateUserInfo();
  194. return Resp::ok(array(
  195. 'gold' => 0,
  196. 'store' => $user->store,
  197. ));
  198. }
  199. /**
  200. * 切换装备分页
  201. * @return Resp
  202. */
  203. public static function SwitchEquipPag() {
  204. list($index) = req()->paras;
  205. $user = ctx();
  206. $user->store->equipPag = $index;
  207. ctx($user);
  208. UserProc::updateUserInfo();
  209. return Resp::ok(array());
  210. }
  211. /**
  212. * 所有装备的一键升级
  213. * 规则:等级不同从等级小到大,等级一样按照部位顺序
  214. *
  215. * @return Resp
  216. */
  217. public static function AllEquipUpgrade() {
  218. //list() = req()->paras;
  219. $user = ctx();
  220. $equipDic = $user->store->equipPosition;
  221. $equip_levelDic = GameConfig::equip_levelupgrade();
  222. $maxLv = count(StlUtil::dictToArray($equip_levelDic));
  223. $arr = array();
  224. if ($equipDic != null) {
  225. foreach ($equipDic as $k => &$equip) {
  226. $equip = new Ins_EquipPosition($equip);
  227. if($equip->level >= $maxLv){
  228. continue;
  229. }
  230. $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  231. $needGold = $lvMo->needGold;
  232. $needItemNum = $lvMo->needItemNum;
  233. $neeItemId = $equip->mo()->costTuzhiId;
  234. if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  235. $arr[] = $equip;
  236. }
  237. }
  238. }
  239. $upLevelArr = array();
  240. if (count($arr) > 0) {
  241. //进行排序
  242. $len = count($arr);
  243. for ($i = 0; $i < $len - 1; $i++) {
  244. for ($j = 0; $j < $len - $i - 1; $j++) {
  245. if ($arr[$j]->level > $arr[$j + 1]->level) {//从小到大
  246. $temp = $arr[$j];
  247. $arr[$j] = $arr[$j + 1];
  248. $arr[$j + 1] = $temp;
  249. } elseif ($arr[$j]->level == $arr[$j + 1]->level) {
  250. $j_equip = new Ins_EquipPosition($arr[$j]);
  251. $jj_equip = new Ins_EquipPosition($arr[$j + 1]);
  252. if ($j_equip->mo()->position > $jj_equip->mo()->position) {
  253. $temp = $arr[$j];
  254. $arr[$j] = $arr[$j + 1];
  255. $arr[$j + 1] = $temp;
  256. }
  257. }
  258. }
  259. }
  260. //升级,扣除金币和图纸
  261. while (true) {
  262. $tag = 9999;
  263. foreach ($arr as $index => &$equip) {
  264. $ins_equip = new Ins_EquipPosition($equip);
  265. $lvMo = GameConfig::equip_levelupgrade_getItem($ins_equip->level);
  266. $needGold = $lvMo->needGold;
  267. $needItemNum = $lvMo->needItemNum;
  268. $neeItemId = $ins_equip->mo()->costTuzhiId;
  269. if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  270. $id = $ins_equip->typeId;
  271. if (!in_array($id, $upLevelArr)) {
  272. $upLevelArr[] = $id;
  273. }
  274. $ins_equip->level += 1;
  275. $equipDic->$id->level += 1;
  276. $user->baseInfo->Consume_Gold($needGold);
  277. $user->store->removeItem($neeItemId, $needItemNum);
  278. if ($ins_equip->level >= 99) {
  279. $tag = $index;
  280. break;
  281. }
  282. } else {
  283. $tag = $index;
  284. break;
  285. }
  286. }
  287. if ($tag != 9999) {
  288. if (array_key_exists($tag, $arr)) {
  289. StlUtil::arrayRemoveAt($arr, $tag);
  290. }
  291. }
  292. if (count($arr) <= 0) {
  293. break;
  294. }
  295. }
  296. }
  297. TaskProc::OnAnyEquipUpLevel_X();
  298. TaskProc::OnAllEquipUpLevel_X();
  299. TaskProc::OnEquipLevelUpNum();
  300. ctx($user);
  301. FightProc::Ranking_FightPower();
  302. UserProc::updateUserInfo();
  303. return Resp::ok(array(
  304. 'upLevelArr' => $upLevelArr,
  305. 'gold' => $user->baseInfo->gold,
  306. 'store' => $user->store,
  307. 'task' => $user->task,
  308. ));
  309. }
  310. /**
  311. * 移除是新宝石绿点提示
  312. * @return Resp
  313. */
  314. public static function RemoveNewGemTip() {
  315. list($uid) = req()->paras; //宝石uid
  316. $user = ctx();
  317. my_Assert(StlUtil::dictHasProperty($user->store->gemStore, $uid), ErrCode::user_store_NoItem);
  318. //$ins_gem = new Ins_Gem($user->store->gemStore->$uid);
  319. $user->store->gemStore->$uid->isNew = 0;
  320. // $equipPag = $user->store->equipPag;
  321. $typeId = $user->store->gemStore->$uid->typeId;
  322. $mo = GameConfig::gem_getItem($typeId);
  323. my_Assert($mo != null, ErrCode::err_const_no);
  324. $position = $mo->position;
  325. $gemEquip = $user->store->gemEquip;
  326. //$tag = 0;
  327. foreach ($gemEquip as $pag => $val) {
  328. foreach ($val as $posId => $dic) {
  329. if ($posId != $position) {
  330. continue;
  331. }
  332. foreach ($dic as $index => $gem) {
  333. if ($gem->uid == $uid) {
  334. $user->store->gemEquip->$pag->$posId->$index->isNew = 0;
  335. break;
  336. }
  337. }
  338. }
  339. }
  340. ctx($user);
  341. UserProc::updateUserInfo();
  342. return Resp::ok(array(
  343. 'gold' => 0,
  344. 'store' => $user->store,));
  345. }
  346. /**
  347. * 移除装备可以升级绿点提示
  348. * @return Resp
  349. */
  350. public static function RemoveEquipUpgradeTip() {
  351. list($posId) = req()->paras; //装备部位
  352. $user = ctx();
  353. my_Assert(StlUtil::dictHasProperty($user->store->equipPosition, $posId), ErrCode::user_store_NoEquip);
  354. $user->store->equipPosition->$posId->tip = 0;
  355. ctx($user);
  356. UserProc::updateUserInfo();
  357. return Resp::ok(array(
  358. 'gold' => 0,
  359. 'store' => $user->store,));
  360. }
  361. /**
  362. * 6406 合成
  363. * @return type
  364. */
  365. public static function GemCompose() {
  366. list($gemIds) = req()->paras;
  367. $user = ctx();
  368. //做校验
  369. $composeArr = array();
  370. //$gemIds = substr($gemIds, 0, -1);
  371. $list = explode(';', $gemIds);
  372. krsort($list);
  373. foreach ($list as $str) {
  374. $str = substr($str, 0, -1);
  375. $gemUidList = explode(',', $str);
  376. $firstGemUId = $gemUidList[0];
  377. $qual = 0;
  378. $posId = 0;
  379. if (StlUtil::dictHasProperty($user->store->gemStore, $firstGemUId)) {
  380. $ins_gem = $user->store->gemStore->$firstGemUId;
  381. $mo = GameConfig::gem_getItem($ins_gem->typeId);
  382. $qual = $mo->qual;
  383. $posId = $mo->position;
  384. }
  385. $isCompose = true;
  386. //在做一次校验
  387. foreach ($gemUidList as $uid) {
  388. if (StlUtil::dictHasProperty($user->store->gemStore, $uid)) {
  389. $ins_gem = $user->store->gemStore->$uid;
  390. $mo = GameConfig::gem_getItem($ins_gem->typeId);
  391. if ($mo->qual != $qual || $mo->position != $posId) {
  392. $isCompose = false;
  393. break;
  394. }
  395. }
  396. }
  397. my_Assert($isCompose == true, ErrCode::user_store_GemCanotCompose);
  398. //查找要合成的宝石配置信息
  399. $gemConf = self::GemComposeSynthesis($qual, $posId);
  400. my_Assert($gemConf != null, ErrCode::err_const_no);
  401. $synthesisList = explode('_', $gemConf->synthesis);
  402. $composePosition = $synthesisList[0];
  403. $composeQual = $synthesisList[1];
  404. $composeNum = $synthesisList[2];
  405. foreach ($composeArr as $val) {
  406. $mo = GameConfig::gem_getItem($val->typeId);
  407. if ($mo->qual == $composeQual && $mo->position == $composePosition) {
  408. $gemUidList[] = $val->uid;
  409. }
  410. }
  411. if (count($gemUidList) >= $composeNum) {
  412. if ($gemConf != null) {
  413. $maxGemNum = intval(count($gemUidList) / $composeNum);
  414. $index = 0;
  415. $res = 0;
  416. foreach ($gemUidList as $uid) {
  417. my_Assert(self::GemIsCanCompose($uid) == false && $user->store->gemStore->$uid->isUnlock == 0, ErrCode::user_store_GemCanotCompose);
  418. $index += 1;
  419. self::RemoveGemInStore($uid);
  420. //$composeArr 有的话删除
  421. for ($i = 0; $i < count($composeArr); $i++) {
  422. if ($composeArr[$i]->uid == $uid) {
  423. StlUtil::arrayRemoveAt($composeArr, $i);
  424. break;
  425. }
  426. }
  427. if ($index % $composeNum == 0) {
  428. $res += 1;
  429. $composeGem = self::initGem($gemConf->typeId);
  430. self::PutGemInStore($composeGem);
  431. $composeArr[] = $composeGem; //临时放这
  432. }
  433. if ($res >= $maxGemNum) {
  434. break;
  435. }
  436. }
  437. }
  438. }
  439. }
  440. $resultArr = array();
  441. foreach ($composeArr as $value) {
  442. SystemProc::GetGem_GreaterOrangeQual_GemCompose(req()->zoneid, ctx()->baseInfo->name, $value->typeId);//广播
  443. ctx()->store->gemComposeNum += 1;
  444. $resultArr[] = $value->uid;
  445. }
  446. TaskProc::OnComposeNumGem();
  447. TaskProc::OnComposeNumGem_state();
  448. ctx($user);
  449. UserProc::updateUserInfo();
  450. return Resp::ok(array(
  451. 'composeGemIds' => $resultArr,
  452. 'store' => $user->store,
  453. 'task' => $user->task,
  454. ));
  455. }
  456. /**
  457. * 该宝石是否可以参与合成,其他页镶嵌的,已经被锁的都不能参与
  458. * @param type $uid
  459. * @return bool
  460. */
  461. private static function GemIsCanCompose($uid) {
  462. $Ins_gemItem = new Ins_Gem(ctx()->store->gemStore->$uid);
  463. $equipGemDic = ctx()->store->gemEquip;
  464. $equipPag = ctx()->store->equipPag;
  465. $isExist = false;
  466. foreach ($equipGemDic as $pag => $dic) {
  467. if ($equipPag == $pag) {
  468. continue;
  469. }
  470. if (StlUtil::dictHasProperty($dic, $Ins_gemItem->mo()->position)) {
  471. $posId = $Ins_gemItem->mo()->position;
  472. $tDic = $dic->$posId;
  473. foreach ($tDic as $index => $ins_gem) {
  474. if ($ins_gem->uid == $Ins_gemItem->uid) {
  475. $isExist = true;
  476. break;
  477. }
  478. }
  479. }
  480. if ($isExist) {
  481. break;
  482. }
  483. }
  484. return $isExist;
  485. }
  486. private static function GemComposeSynthesis($qual, $posId) {
  487. $gem = GameConfig::gem();
  488. foreach ($gem as $key => $value) {
  489. if ($value->synthesis != null) {
  490. $synthesisList = explode('_', $value->synthesis);
  491. $composePosition = $synthesisList[0];
  492. $composeQual = $synthesisList[1];
  493. $composeNum = $synthesisList[2];
  494. if ($composeQual != 0 && $composePosition != 0 && $composeQual == $qual && $posId == $composePosition && $value->isfixed_predicateId == 0) {
  495. return $value;
  496. }
  497. }
  498. }
  499. return null;
  500. }
  501. /**
  502. * 装备宝石
  503. * @return type
  504. */
  505. public static function GemSet() {
  506. list($equipUid, $gemUid, $slotId) = req()->paras; //宝石uid
  507. $user = ctx();
  508. my_Assert(StlUtil::dictHasProperty($user->store->gemStore, $uid), ErrCode::user_store_NoItem);
  509. $ins_gem = new Ins_Gem($user->store->gemStore->$uid);
  510. $pag = $user->store->equipPag;
  511. $posId = $ins_gem->mo()->position;
  512. $dic = $user->store->gemEquip->$pag->$posId;
  513. $tag_index = 0;
  514. $tag_gem = null;
  515. foreach ($dic as $index => &$gem) {
  516. $gem = new Ins_Gem($gem);
  517. if ($gem->predicateMo()->uniqueKey == $ins_gem->predicateMo()->uniqueKey) {
  518. $tag_index = $index;
  519. $tag_gem = $gem;
  520. break;
  521. }
  522. }
  523. switch ($type) {
  524. case 1://镶嵌
  525. my_Assert($tag_gem == null, ErrCode::user_store_GemCanotSet);
  526. for ($i = 1; $i <= 5; $i++) {
  527. if (!StlUtil::dictHasProperty($dic, $i)) {
  528. $dic->$i = $ins_gem;
  529. //StlUtil::dictRemove($user->store->gemStore, $uid);
  530. break;
  531. }
  532. }
  533. //$user->store->gemEquip->$pag->$posId = $dic;
  534. break;
  535. case 2://替换
  536. //满不满都高替低品阶
  537. my_Assert(StlUtil::dictHasProperty($dic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  538. $replace_ins_Gem = new Ins_Gem($dic->$replaceUId); //这个uid是5个坑位的index id
  539. my_Assert($replace_ins_Gem->mo()->qual < $ins_gem->mo()->qual, ErrCode::user_store_NoExistGemReplace);
  540. $dic->$replaceUId = $ins_gem;
  541. // $id = $replace_ins_Gem->uid;
  542. // $user->store->gemStore->$id = $replace_ins_Gem;
  543. // $dic->$replaceUId = $ins_gem;
  544. // StlUtil::dictRemove($user->store->gemStore, $uid);
  545. //$user->store->gemEquip->$pag->$posId = $dic;
  546. break;
  547. case 3://手动
  548. my_Assert(count((array) $dic) >= 5, ErrCode::user_store_GemCanotSet);
  549. my_Assert(StlUtil::dictHasProperty($user->store->gemStore, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  550. $replace_ins_Gem = new Ins_Gem($user->store->gemStore->$replaceUId);
  551. //$id = $replace_ins_Gem->uid;
  552. if ($tag_gem != null) {//如果有u那
  553. my_Assert($replace_ins_Gem->uid == $tag_gem->uid, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  554. //有U一样的,则点击正好是这个直接替换
  555. //$user->store->gemStore->$id = $replace_ins_Gem;
  556. $dic->$tag_index = $ins_gem;
  557. } else {
  558. $go_index = 0;
  559. foreach ($dic as $index => $g) {
  560. if ($g->uid == $replaceUId) {
  561. $go_index = $index;
  562. break;
  563. }
  564. }
  565. my_Assert($go_index > 0, ErrCode::user_store_NoExistGemReplace);
  566. $dic->$go_index = $ins_gem;
  567. }
  568. break;
  569. case 4://不能
  570. //1.小品阶替大品阶 或是 相等的,在不满的时候不允许 2. //满的 相等不允许替
  571. my_Assert($uid == 0, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  572. break;
  573. default:
  574. break;
  575. }
  576. $user->store->gemEquip->$pag->$posId = $dic;
  577. TaskProc::OnSetSpecialQualGem();
  578. FightProc::Ranking_FightPower();
  579. ctx($user);
  580. UserProc::updateUserInfo();
  581. return Resp::ok(array(
  582. 'gold' => 0,
  583. 'store' => $user->store,
  584. 'task' => $user->task,
  585. ));
  586. }
  587. /**
  588. * 卸下装备
  589. * @return type
  590. */
  591. public static function GemRemove() {
  592. list($uid) = req()->paras; //装备宝石id
  593. $user = ctx();
  594. $pag = $user->store->equipPag;
  595. $posDic = $user->store->gemEquip->$pag;
  596. $tag_pos = 0;
  597. $tag_index = 0;
  598. $tag_gem = null;
  599. foreach ($posDic as $posId => $dic) {
  600. foreach ($dic as $index => $gem) {
  601. if ($gem->uid == $uid) {
  602. $tag_pos = $posId;
  603. $tag_index = $index;
  604. $tag_gem = $gem;
  605. break 2;
  606. }
  607. }
  608. }
  609. if ($tag_index > 0 && $tag_gem != null) {
  610. StlUtil::dictRemove($posDic->$tag_pos, $tag_index);
  611. $user->store->gemEquip->$pag = $posDic;
  612. //$user->store->gemStore->$uid = $tag_gem;
  613. }
  614. ctx($user);
  615. FightProc::Ranking_FightPower();
  616. UserProc::updateUserInfo();
  617. return Resp::ok(array(
  618. 'gold' => 0,
  619. 'store' => $user->store,));
  620. }
  621. /**
  622. * 6404 升级装备
  623. * @return type
  624. */
  625. public static function EquipUpgrade() {
  626. list($uid) = req()->paras; //装备uid
  627. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  628. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  629. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_equipLevelLimit);
  630. $mo = GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity,$ins_equip->mo()->qual,$ins_equip->mo()->position,$ins_equip->level);
  631. my_Assert(null != $mo, ErrCode::err_const_no);
  632. my_Assert(ctx()->baseInfo->gold >= $mo->needGold, ErrCode::notenough_gold_msg);
  633. $costTuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  634. $tuzhiNum = 0;
  635. if (StlUtil::dictHasProperty(ctx()->store->items, $costTuzhiId)) {
  636. $tuzhiNum = ctx()->store->items->$costTuzhiId;
  637. }
  638. my_Assert($tuzhiNum >= $mo->needItemNum, ErrCode::notenough_item);
  639. ctx()->store(true)->removeItem($costTuzhiId, $mo->needItemNum);
  640. ctx()->base(true)->Consume_Gold($mo->needGold);
  641. TaskProc::OnAnyEquipUpLevel_X();
  642. TaskProc::OnAllEquipUpLevel_X();
  643. TaskProc::OnEquipLevelUpNum();
  644. FightProc::Ranking_FightPower();
  645. UserProc::updateUserInfo();
  646. return Resp::ok(array(
  647. 'gold' => $user->baseInfo->gold,
  648. 'store' => $user->store,
  649. 'task' => $user->task,
  650. ));
  651. }
  652. /**
  653. * 6405 单个装备部位一键升级
  654. * @return type
  655. */
  656. public static function EquipUpgrade_MaxLv() {
  657. list($uid) = req()->paras;
  658. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  659. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  660. $maxLevel = $ins_equip->Equip_MaxLevel();
  661. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_equipLevelLimit);
  662. $tuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  663. $itemNum_store = 0;
  664. if (StlUtil::dictHasProperty(ctx()->store->items, $tuzhiId)) {
  665. $itemNum_store = ctx()->store->items->$tuzhiId;
  666. }
  667. $up_Gold = 0;
  668. $up_needItem = 0;
  669. $up_lv = 0;
  670. $noUp_gold = false;
  671. $noUp_item = false;
  672. for ($i = $ins_equip->level; $i <= $maxLevel; $i++) {
  673. $up_Gold += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity,$ins_equip->mo()->qual,$ins_equip->mo()->position,$i)->needGold;
  674. $up_needItem += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity,$ins_equip->mo()->qual,$ins_equip->mo()->position,$i)->needItemNum;
  675. if (ctx()->baseInfo->gold >= $up_Gold) {
  676. $noUp_gold = true;
  677. }
  678. if ($itemNum_store >= $up_needItem) {
  679. $noUp_item = true;
  680. }
  681. if (ctx()->baseInfo->gold >= $up_Gold && $itemNum_store >= $up_needItem) {
  682. //$need_gold = $up_Gold;
  683. //$need_item = $up_needItem;
  684. $up_lv = $i;
  685. continue;
  686. }
  687. break;
  688. }
  689. if($up_lv == 0){
  690. my_Assert($noUp_gold, ErrCode::notenough_gold_msg);
  691. my_Assert($noUp_item, ErrCode::notenough_item);
  692. }
  693. ctx()->base(true)->Consume_Gold($up_Gold);
  694. ctx()->store(true)->removeItem($tuzhiId, $up_needItem);
  695. if($up_lv >0){
  696. ctx()->store->equip->$uid->level = $up_lv;
  697. }
  698. TaskProc::OnAnyEquipUpLevel_X();
  699. TaskProc::OnAllEquipUpLevel_X();
  700. TaskProc::OnEquipLevelUpNum();
  701. FightProc::Ranking_FightPower();
  702. UserProc::updateUserInfo();
  703. return Resp::ok(array(
  704. 'gold' => ctx()->baseInfo->gold,
  705. 'store' => ctx()->store,
  706. 'task' => ctx()->task,
  707. ));
  708. }
  709. public static function AddItemInStore() {
  710. list($rwdStr) = req()->paras; //mask = 1:表示战斗中掉落
  711. $user = ctx();
  712. $err = self::AddMultiItemInStore($rwdStr);
  713. my_Assert(ErrCode::ok == $err, $err);
  714. UserProc::updateUserInfo();
  715. return Resp::ok(array(
  716. //'gold' => $user->baseInfo->gold,
  717. //'tili' => $user->baseInfo->tili,
  718. //'cash' => $user->baseInfo->cash,
  719. 'store' => $user->store));
  720. }
  721. static $reward = array();
  722. static $reward_Gem = array();
  723. //static $reward_hero = array();
  724. /**
  725. * 具体奖励存入背包
  726. * @param type $goodsStr
  727. * @param type $src
  728. */
  729. public static function AddMultiItemInStore($goodsStr, $src = 0) {
  730. if ($goodsStr == null) {
  731. return;
  732. }
  733. $ary = explode(";", $goodsStr);
  734. foreach ($ary as $value) {
  735. $val = explode(",", $value);
  736. my_Assert(count($val) > 1, "解析奖励字符串出错");
  737. list($itemId, $num) = $val; # ID, 数量
  738. $itemMo = GameConfig::item_getItem($itemId);
  739. if($itemMo->itemType != 701 && $itemMo->itemType != 201 && $itemMo->itemType != 502 && $src != 1){
  740. self::$reward[] = $value;
  741. }
  742. switch ($itemMo->itemType) {
  743. case 1:
  744. ctx()->baseInfo->Add_Gold($num);
  745. self::checkEquipUpgradeTip();
  746. break;
  747. case 2:
  748. ctx()->baseInfo->Add_Cash($num);
  749. break;
  750. case 3:
  751. ctx()->baseInfo->Add_tili($num);
  752. break;
  753. case 4:
  754. ctx()->baseInfo->Add_Exp($num);
  755. break;
  756. case 100://图纸
  757. case 103://钥匙
  758. case 401://启灵石
  759. case 301://洗练石
  760. case 501://人物碎片
  761. case 601://人身果
  762. case 801://寻宝券
  763. self::PutItemsInStore($itemId, $num);
  764. if ($itemMo->itemType == 100) {//图纸
  765. self::checkEquipUpgradeTip();
  766. }
  767. break;
  768. case 502://角色卡
  769. HeroProc::RoleCardUnlockHero($itemId, $num);
  770. break;
  771. case 201://宝石
  772. for ($i = 0; $i < $num; $i++) {
  773. $gem = self::initGem($itemId);
  774. if($src != 1){
  775. self::$reward_Gem[] = $gem->uid;
  776. }
  777. self::PutGemInStore($gem);
  778. if ($src == Enum_StoreSourceType::ShopBox) {
  779. SystemProc::GetGem_GreaterOrangeQual_ShopBox(req()->zoneid, ctx()->baseInfo->name, $gem->typeId);
  780. }
  781. }
  782. break;
  783. case 701://道具宝箱
  784. for ($i = 0; $i < $num; $i++) {
  785. self::DistributeItemsBox($itemId);
  786. }
  787. break;
  788. default:
  789. break;
  790. }
  791. }
  792. }
  793. public static function PutItemsInStore($itemId, $num) {
  794. $items = ctx()->store->items;
  795. if (StlUtil::dictHasProperty($items, $itemId)) {
  796. $items->$itemId += $num;
  797. } else {
  798. $items->$itemId = $num;
  799. }
  800. ctx()->store->items = $items;
  801. }
  802. /**
  803. * 拆分宝箱盒子
  804. * @param type $reward
  805. */
  806. public static function DistributeItemsBox($itemId) {
  807. $itemBoxMo = GameConfig::item_2023_box_getItem($itemId);
  808. my_Assert($itemBoxMo != null, ErrCode::err_const_no);
  809. if ($itemBoxMo->type == 1) {
  810. $strList = explode(';', $itemBoxMo->contents);
  811. $numList = explode('-', $strList[0]);
  812. $randNum = rand($numList[0], $numList[1]);
  813. $ctxList = explode(',', $strList[1]);
  814. $per = 0;
  815. foreach ($ctxList as $value) {
  816. $ctx = explode(':', $value);
  817. $per += $ctx[1];
  818. }
  819. $reward = "";
  820. for ($i = 0; $i < $randNum; $i++) {
  821. $ctxPer = rand(1, $per);
  822. $start = 0;
  823. $end = 0;
  824. $id = 0;
  825. foreach ($ctxList as $value) {
  826. $ctx = explode(':', $value);
  827. $end += $ctx[1];
  828. if ($ctxPer > $start && $ctxPer <= $end) {
  829. $id = $ctx[0];
  830. break;
  831. }
  832. $start = $end;
  833. }
  834. if ($id != 0) {
  835. $str = $id . ',1';
  836. if ($reward == "") {
  837. $reward = $str;
  838. } else {
  839. $reward = $reward . ';' . $str;
  840. }
  841. }
  842. }
  843. self::AddMultiItemInStore($reward);
  844. } else {
  845. self::AddMultiItemInStore($itemBoxMo->contents);
  846. }
  847. }
  848. // public static function PutEquipInStore($equipId, $num) {
  849. // if ($equipId == 0) {
  850. // return;
  851. // }
  852. // $n = count((array) ctx()->store->equip) + 1;
  853. //
  854. // for ($index = 0; $index < $num; $index++) {
  855. // $Equip = new Ins_Equip();
  856. // $Equip->uid = $n;
  857. // $Equip->typeId = $equipId;
  858. // $Equip->qual = GameConfig::equip_getItem($equipId)->qual;
  859. // ctx()->store->equip->$n = $Equip;
  860. // $n += 1;
  861. // }
  862. // }
  863. /**
  864. * 得到金币或是图纸的时候校验下,是否满足装备升级条件,满足则tip字段设置为1
  865. */
  866. public static function checkEquipUpgradeTip() {
  867. $equipDic = ctx()->store->equipPosition;
  868. if ($equipDic != null) {
  869. foreach ($equipDic as $k => &$equip) {
  870. $equip = new Ins_EquipPosition($equip);
  871. $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  872. $needGold = $lvMo->needGold;
  873. $needItemNum = $lvMo->needItemNum;
  874. $neeItemId = $equip->mo()->costTuzhiId;
  875. if (ctx()->baseInfo->gold >= $needGold && StlUtil::dictHasProperty(ctx()->store->items, $neeItemId) && ctx()->store->items->$neeItemId >= $needItemNum) {
  876. $equipDic->$k->tip = 1; //绿点是每次得到金币或是图纸了,只要满足升级条件都变绿
  877. }
  878. }
  879. }
  880. ctx()->store->equipPosition = $equipDic;
  881. }
  882. /**
  883. * 新宝石入库
  884. */
  885. public static function PutGemIdInStore($id, $num = 1) {
  886. for ($i = 0; $i < $num; $i++) {
  887. $gem = self::initGem($id);
  888. $length = $gem->uid;
  889. ctx()->store->gemStore->$length = $gem;
  890. }
  891. }
  892. public static function PutGemInStore($gem, $num = 1) {
  893. for ($i = 0; $i < $num; $i++) {
  894. $length = $gem->uid;
  895. ctx()->store->gemStore->$length = $gem;
  896. }
  897. }
  898. public static function initGem($id) {
  899. $length = ctx()->store->gemLength;
  900. $length += 1;
  901. $gem = new Ins_Gem();
  902. $gem->uid = $length;
  903. $gem->typeId = $id;
  904. $gem->predicateId = self::RandomGemPredicateId($id);
  905. $tag = self::CheckNewGemTip($gem);
  906. $gem->isNew = $tag;
  907. ctx()->store->gemLength = $length;
  908. return $gem;
  909. }
  910. /**
  911. * 从仓库移除宝石
  912. */
  913. public static function RemoveGemInStore($uid) {
  914. if (StlUtil::dictHasProperty(ctx()->store->gemStore, $uid)) {
  915. StlUtil::dictRemove(ctx()->store->gemStore, $uid);
  916. }
  917. return 0;
  918. }
  919. /**
  920. * 新宝石随机词条 临时等刚哥
  921. */
  922. public static function RandomGemPredicateId($id) {
  923. $mo = GameConfig::gem_getItem($id);
  924. my_Assert(null != $mo, "找不到宝石{$id}的配置数据");
  925. if ($mo->isfixed_predicateId == 1) {
  926. return $mo->predicateId;
  927. }
  928. $posId = $mo->position;
  929. $qual = $mo->qual;
  930. $arr = array();
  931. $predicateMo = GameConfig::predicate();
  932. foreach ($predicateMo as $key => $value) {
  933. if ($value->positions != null) {
  934. $list = explode(',', $value->positions);
  935. if ($value->qual == $qual && in_array($posId, $list) && $value->attachTarget == "gem") {
  936. $arr[] = $value->id;
  937. }
  938. }
  939. }
  940. if (count($arr) <= 0) {
  941. return 40;
  942. }
  943. my_Assert(count($arr) > 0, "宝石没有对应词条信息");
  944. $n = mt_rand(0, count($arr) - 1);
  945. return $arr[$n];
  946. //return 40;
  947. }
  948. /**
  949. * 新宝石提示
  950. */
  951. public static function CheckNewGemTip($gem) {
  952. $gemStore = ctx()->store->gemStore;
  953. $tag = false;
  954. foreach ($gemStore as $k => $ins_gem) {
  955. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  956. $tag = true;
  957. break;
  958. }
  959. }
  960. return $tag == true ? 0 : 1;
  961. }
  962. //临时代码
  963. // public static function InitGemInfo() {
  964. // if(count((array)ctx()->store->gemStore) > 0){
  965. // return;
  966. // }
  967. //
  968. // $index = 0;
  969. // $gem = GameConfig::gem();
  970. //
  971. // for ($i = 1; $i <=21; $i++) {
  972. // foreach ($gem as $key => $value) {
  973. // if($value->id == $i){
  974. // self::PutGemInStore($value->typeId);
  975. // }
  976. //
  977. // }
  978. // }
  979. //
  980. //
  981. //
  982. //
  983. // }
  984. }