StoreProc.php 39 KB

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