PetProc.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * Description of PetProc
  5. *
  6. * @author Administrator
  7. */
  8. class PetProc {
  9. public static function InitArea() {
  10. $isUnlock = FightProc::isFunUnlock(Enum_FunType::Pet);
  11. if (!$isUnlock) {
  12. return;
  13. }
  14. $dic = GameConfig::pet_area();
  15. if ($dic != null && count(StlUtil::dictToArray(ctx()->store->exploreArea, 1)) == 0) {
  16. foreach ($dic as $areaId => $arr) {
  17. $ins_exploreArea = new Ins_ExploreArea();
  18. $ins_exploreArea->areaId = $areaId;
  19. ctx()->store()->exploreArea->$areaId = $ins_exploreArea;
  20. }
  21. }
  22. }
  23. /**
  24. * 6433 区域等级升级
  25. * @return Resp
  26. */
  27. public static function Pet_AreaLevelUpgrade() {
  28. list($areaId) = req()->paras;
  29. if (!StlUtil::dictHasProperty(ctx()->store->exploreArea, $areaId)) {
  30. $ins_ExploreArea = new Ins_ExploreArea();
  31. $ins_ExploreArea->areaId = $areaId;
  32. ctx()->store->exploreArea->$areaId = $ins_ExploreArea;
  33. }
  34. $vo = new Ins_ExploreArea(ctx()->store->exploreArea->$areaId);
  35. $vo->level += 1;
  36. my_Assert(ctx()->baseInfo->gold >= $vo->mo()->unlockArea_gold, ErrCode::notenough_gold_msg);
  37. my_Assert(ctx()->baseInfo->level >= $vo->mo()->unlockArea_userLv, ErrCode::user_levelnotenough_msg);
  38. ctx()->base()->Consume_Gold($vo->mo()->unlockArea_gold);
  39. ctx()->store->exploreArea->$areaId = $vo;
  40. UserProc::updateUserInfo();
  41. return Resp::ok(array(
  42. 'gold' => ctx()->baseInfo->gold,
  43. 'store' => ctx()->store,
  44. ));
  45. }
  46. /**
  47. *
  48. * @param Ins_ExploreArea $ins_ExploreArea
  49. */
  50. public static function GetAreaOutPutInfo(&$ins_ExploreArea, $outPut_type) {
  51. $num = $ins_ExploreArea->mo()->output_num; //等级带来的
  52. $ts = $ins_ExploreArea->mo()->output_time; //等级带来的
  53. if (count($ins_ExploreArea->explorePetList) > 0) {
  54. $list = $ins_ExploreArea->explorePetList;
  55. foreach ($list as $petUid) {
  56. $ins_pet = new Ins_Pet(ctx()->store->$petUid);
  57. $typeId = $ins_pet->mo()->type;
  58. $qual = $ins_pet->qual;
  59. $pet_exploreoutputMo = GameConfig::pet_exploreoutput_getItem($typeId, $qual);
  60. if ($pet_exploreoutputMo->exploreOutput != null) {
  61. $sList = explode(';', $pet_exploreoutputMo->exploreOutput);
  62. foreach ($sList as $str) {
  63. $s = explode(',', $str);
  64. if ((int) $s[0] == $ins_ExploreArea->areaId) {
  65. $num += (int) $s[1];
  66. $ts += (int) $s[2];
  67. }
  68. }
  69. }
  70. }
  71. }
  72. return ($outPut_type == 1) ? $num : $ts;
  73. }
  74. /**
  75. * 6434 更换派遣宠物
  76. * @return Resp
  77. */
  78. public static function ReplaceDispatchPet_old() {
  79. list($areaId, $petUid, $exploreType) = req()->paras;
  80. $vo = new Ins_ExploreArea(ctx()->store->exploreArea->$areaId);
  81. if (StlUtil::arrayContains($vo->explorePetList, $petUid)) {
  82. StlUtil::arrayRemove($vo->explorePetList, $petUid);
  83. } else {
  84. my_Assert(count($vo->explorePetList) < $vo->mo()->dispatchPetNum, ErrCode::user_store_dispatchPetNumLimit);
  85. $petDic = ctx()->store->pet;
  86. my_Assert(StlUtil::dictHasProperty($petDic, $petUid), ErrCode::user_store_NotExistPet);
  87. $ins_pet = new Ins_Pet($petDic->$petUid);
  88. $mo = GameConfig::pet_exploreoutput_getItem($ins_pet->mo()->type, $ins_pet->qual);
  89. my_Assert(null != $mo, ErrCode::err_const_no);
  90. $sList = explode(';', $mo->exploreOutput);
  91. $tag = false;
  92. foreach ($sList as $key => $value) {
  93. $str = explode(',', $value);
  94. if ($str[0] == $areaId) {
  95. $tag = true;
  96. break;
  97. }
  98. }
  99. my_Assert($tag, ErrCode::user_store_dispatchPetErr);
  100. $vo->explorePetList[] = $petUid;
  101. }
  102. my_Assert($exploreType == 1 && now() - $vo->startTs < 10 * 60, ErrCode::user_store_CannotReplaced_tsLimit);
  103. //开始探索
  104. if (count($vo->explorePetList) == 0) {
  105. $vo->startTs = 0;
  106. $vo->endTs = 0;
  107. $vo->output_num = 0;
  108. $vo->output_ts = 0;
  109. } else {
  110. if ($vo->startTs == 0) {
  111. $vo->startTs = now();
  112. }
  113. $ts = self::GetAreaOutPutInfo($vo, 2);
  114. $num = self::GetAreaOutPutInfo($vo, 1);
  115. $vo->endTs = $vo->startTs + $ts;
  116. $vo->output_num = $num;
  117. $vo->output_ts = $vo->endTs - $vo->startTs;
  118. }
  119. ctx()->store->exploreArea->$areaId = $vo;
  120. UserProc::updateUserInfo();
  121. return Resp::ok(array(
  122. 'store' => ctx()->store,
  123. ));
  124. }
  125. /**
  126. * 6434 更换派遣宠物 废弃
  127. * @return Resp
  128. */
  129. public static function ReplaceDispatchPet() {
  130. list($areaId, $petUid) = req()->paras;
  131. $vo = new Ins_ExploreArea(ctx()->store->exploreArea->$areaId);
  132. if (StlUtil::arrayContains($vo->explorePetList, $petUid)) {
  133. StlUtil::arrayRemove($vo->explorePetList, $petUid);
  134. } else {
  135. my_Assert(count($vo->explorePetList) < $vo->mo()->dispatchPetNum, ErrCode::user_store_dispatchPetNumLimit);
  136. $petDic = ctx()->store->pet;
  137. my_Assert(StlUtil::dictHasProperty($petDic, $petUid), ErrCode::user_store_NotExistPet);
  138. $ins_pet = new Ins_Pet($petDic->$petUid);
  139. $mo = GameConfig::pet_exploreoutput_getItem($ins_pet->mo()->type, $ins_pet->qual);
  140. my_Assert(null != $mo, ErrCode::err_const_no);
  141. $sList = explode(';', $mo->exploreOutput);
  142. $tag = false;
  143. foreach ($sList as $key => $value) {
  144. $str = explode(',', $value);
  145. if ($str[0] == $areaId) {
  146. $tag = true;
  147. break;
  148. }
  149. }
  150. my_Assert($tag, ErrCode::user_store_dispatchPetErr);
  151. $vo->explorePetList[] = $petUid;
  152. }
  153. my_Assert($exploreType == 1 && now() - $vo->startTs < 10 * 60, ErrCode::user_store_CannotReplaced_tsLimit);
  154. ctx()->store->exploreArea->$areaId = $vo;
  155. UserProc::updateUserInfo();
  156. return Resp::ok(array(
  157. 'store' => ctx()->store,
  158. ));
  159. }
  160. /**
  161. * 派遣宠物
  162. * @return Resp
  163. */
  164. public static function DispatchPet() {
  165. list($areaId, $petUidList) = req()->paras;
  166. $ins_ExploreArea = new Ins_ExploreArea(ctx()->store->exploreArea->$areaId);
  167. $ins_ExploreArea->explorePetList = $petUidList;
  168. if ($ins_ExploreArea->startTs > 0 && $ins_ExploreArea->endTs > 0) {//说明是更换
  169. //my_Assert(count($ins_ExploreArea->explorePetList) > 0, ErrCode::user_store_addDispatchPet);
  170. my_Assert(now() - $ins_ExploreArea->startTs < 10 * 60, ErrCode::user_store_CannotReplaced_tsLimit);
  171. }
  172. if (count($petUidList) == 0) {
  173. $ins_ExploreArea->startTs = 0;
  174. $ins_ExploreArea->endTs = 0;
  175. $ins_ExploreArea->output_num = 0;
  176. $ins_ExploreArea->output_ts = 0;
  177. } else {
  178. if ($ins_ExploreArea->startTs == 0) {
  179. $ins_ExploreArea->startTs = now();
  180. }
  181. $ts = self::GetAreaOutPutInfo($ins_ExploreArea, 2);
  182. $num = self::GetAreaOutPutInfo($ins_ExploreArea, 1);
  183. $ins_ExploreArea->endTs = $ins_ExploreArea->startTs + $ts;
  184. $ins_ExploreArea->output_num = $num;
  185. $ins_ExploreArea->output_ts = $ins_ExploreArea->endTs - $ins_ExploreArea->startTs;
  186. }
  187. ctx()->store->exploreArea->$areaId = $ins_ExploreArea;
  188. UserProc::updateUserInfo();
  189. return Resp::ok(array(
  190. 'store' => ctx()->store,
  191. ));
  192. }
  193. /**
  194. * 6435 删除全部派遣宠物
  195. */
  196. public static function RemoveDispatchPet() {
  197. list($areaId) = req()->paras;
  198. $vo = new Ins_ExploreArea(ctx()->store->exploreArea->$areaId);
  199. $vo->explorePetList = array();
  200. $vo->startTs = 0;
  201. $vo->endTs = 0;
  202. $vo->output_num = 0;
  203. $vo->output_ts = 0;
  204. ctx()->store->exploreArea->$areaId = $vo;
  205. UserProc::updateUserInfo();
  206. return Resp::ok(array(
  207. 'store' => ctx()->store,
  208. ));
  209. }
  210. /**
  211. * 6436 领取探索奖励
  212. */
  213. public static function Pet_ReceiveReward() {
  214. list($areaId) = req()->paras;
  215. $vo = new Ins_ExploreArea(ctx()->store->exploreArea->$areaId);
  216. my_Assert($vo->startTs > 0 && now() - $vo->startTs > 10 * 60, ErrCode::user_store_CannotReceiveReward);
  217. $tt = now() - $vo->startTs;
  218. if (now() >= $vo->endTs) {
  219. $tt = $vo->endTs - $vo->startTs;
  220. }
  221. $ts_n = $vo->output_ts / $vo->output_num;
  222. $num = intval($tt *= $ts_n);
  223. $goodsStr = $vo->mo()->reward_fixed . ',' . $num;
  224. StoreProc::AddMultiItemInStore($goodsStr);
  225. $reward = explode(',', $vo->mo()->reward_extra);
  226. $randNum = rand(1, $reward[2]);
  227. if ($randNum <= $reward[2]) {
  228. StoreProc::AddMultiItemInStore($reward[0] . ',' . $reward[1]);
  229. }
  230. //$vo->explorePetList = array();
  231. $vo->startTs = 0;
  232. $vo->endTs = 0;
  233. $vo->output_num = 0;
  234. $vo->output_ts = 0;
  235. ctx()->store->exploreArea->$areaId = $vo;
  236. UserProc::updateUserInfo();
  237. return Resp::ok(array(
  238. 'gold' => ctx()->baseInfo->gold,
  239. 'cash' => ctx()->baseInfo->cash,
  240. 'reward' => StoreProc::$reward,
  241. 'reward_Gem' => StoreProc::$reward_Gem,
  242. 'reward_equip' => StoreProc::$reward_equip,
  243. 'store' => ctx()->store,
  244. ));
  245. }
  246. /**
  247. * 6432 解锁孵化位置
  248. * @return Resp
  249. */
  250. public static function Pet_UnlockBreedLocation() {
  251. list($slotId) = req()->paras;
  252. $list = explode(';',GameConfig::glc2()->Pet_BreedLocationUnlockInfo);
  253. foreach ($list as $value) {
  254. $s = explode(',', $value);
  255. if($s[0] == $slotId){
  256. my_Assert(ctx()->baseInfo->cash >= $s[1], ErrCode::notenough_cash_msg);
  257. ctx()->base()->Consume_Cash($s[1]);
  258. $breed = new Ins_BreedEggSlot(ctx()->store->breedEggLocation->$slotId);
  259. $breed->unlock = 1;
  260. ctx()->store()->breedEggLocation->$slotId = $breed;
  261. break;
  262. }
  263. }
  264. UserProc::updateUserInfo();
  265. return Resp::ok(array(
  266. 'cash' => ctx()->baseInfo->cash,
  267. 'store' => ctx()->store,
  268. ));
  269. }
  270. /**
  271. * 6431 正常孵化完成点击领取
  272. * @return Resp
  273. */
  274. public static function Pet_ReceiveBreedPet() {
  275. list($slotId) = req()->paras;
  276. $ins_breed = new Ins_BreedEggSlot(ctx()->store()->breedEggLocation->$slotId);
  277. my_Assert($ins_breed->eggId != 0, ErrCode::user_store_NoExistBreedEgg);
  278. my_Assert($ins_breed->unlock == 1, ErrCode::user_store_SlotNotUnlocked);
  279. my_Assert(now() >= $ins_breed->endTs, ErrCode::user_store_NoCompleteBreed);
  280. StoreProc::AddMultiItemInStore($ins_breed->mo()->reward);
  281. //随机一个灵宠
  282. $str = explode(';', $ins_breed->mo()->per);
  283. $newPet = self::RandObtainPet($str);
  284. $uid = 0;
  285. if($newPet != null){
  286. $uid = $newPet->uid;
  287. ctx()->store()->pet->$uid = $newPet;
  288. }
  289. UserProc::updateUserInfo();
  290. return Resp::ok(array(
  291. 'cash' => ctx()->baseInfo->cash,
  292. 'store' => ctx()->store,
  293. 'newPetUid'=>$uid,
  294. ));
  295. }
  296. /**
  297. * 6430 加速孵化宠物
  298. * @return Resp
  299. */
  300. public static function Pet_FastBreedEgg() {
  301. list($slotId) = req()->paras;
  302. $ins_breed = new Ins_BreedEggSlot(ctx()->store()->breedEggLocation->$slotId);
  303. my_Assert($ins_breed->eggId != 0, ErrCode::user_store_NoExistBreedEgg);
  304. my_Assert($ins_breed->unlock == 1, ErrCode::user_store_SlotNotUnlocked);
  305. my_Assert(now() < $ins_breed->endTs, ErrCode::user_store_CompleteBreed);
  306. $num = $ins_breed->mo()->breedTs/60/10;
  307. $cash_one = $ins_breed->mo()->fastBreed_cost/$num;
  308. $ts = $ins_breed->endTs - now();
  309. $costNum = ceil($ts/60/10);
  310. my_Assert(ctx()->baseInfo->cash >= $costNum*$cash_one, ErrCode::notenough_cash_msg);
  311. ctx()->base()->Consume_Cash($costNum*$cash_one);
  312. StoreProc::AddMultiItemInStore($ins_breed->mo()->reward);
  313. //随机一个灵宠
  314. $str = explode(';', $ins_breed->mo()->per);
  315. $newPet = self::RandObtainPet($str);
  316. $uid = 0;
  317. if($newPet != null){
  318. $uid = $newPet->uid;
  319. ctx()->store()->pet->$uid = $newPet;
  320. }
  321. UserProc::updateUserInfo();
  322. return Resp::ok(array(
  323. 'cash' => ctx()->baseInfo->cash,
  324. 'store' => ctx()->store,
  325. 'newPetUid'=>$uid,
  326. ));
  327. }
  328. /**
  329. * 初始化一个宠物
  330. * @param type $rarity
  331. * @param type $qual
  332. * @param type $petType
  333. */
  334. public static function RandObtainPet($str) {
  335. //随机一个灵宠
  336. $randNum = rand(1,10000);
  337. $start = 0;
  338. $end = 0;
  339. $rarity = 0;
  340. $qual = 0;
  341. $petType = 0;
  342. foreach ($str as $key => $value) {
  343. $s = explode(',', $value);
  344. $end += $s[3]*100;
  345. if($randNum > $start && $randNum <= $end){
  346. $rarity = $s[0];
  347. $qual = $s[1];
  348. $petType = $s[2];
  349. break;
  350. }
  351. $start = $end;
  352. }
  353. $dic = GameConfig::pet();
  354. $petArr = array();
  355. foreach ($dic as $typeId => $mo) {
  356. if($mo->petType == $petType && $mo->qual == $qual && $mo->rarity == $rarity){
  357. $petArr[] = $typeId;
  358. }
  359. }
  360. $typeId = 0;
  361. if(count($petArr) > 0){
  362. $num = rand(0,count($petArr)-1);
  363. $typeId = $petArr[$num];
  364. }
  365. if($typeId != 0){
  366. return StoreProc::initPet($typeId);
  367. }
  368. return null;
  369. }
  370. /**
  371. * 6429 孵化宠物
  372. * @return Resp
  373. */
  374. public static function Pet_BreedEgg() {
  375. list($slotId,$eggId) = req()->paras;
  376. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $eggId), ErrCode::user_store_NoItem);
  377. $mo = GameConfig::item_getItem($eggId);
  378. my_Assert($mo != null, ErrCode::err_const_no);
  379. my_Assert($mo->itemType == 103, ErrCode::user_store_NoItem);
  380. $ins_breed = new Ins_BreedEggSlot(ctx()->store()->breedEggLocation->$slotId);
  381. my_Assert($ins_breed->eggId == 0 && $ins_breed->unlock == 1, ErrCode::user_store_NoBreedSlot);
  382. ctx()->store()->removeItem($eggId, 1);
  383. //$ins_breed = ctx()->store()->breedEggLocation->$slot;
  384. $ins_breed->eggId = $eggId;
  385. $ts = $ins_breed->mo()->breedTs;
  386. $ins_breed->endTs = now()+$ts;
  387. ctx()->store()->breedEggLocation->$slotId = $ins_breed;
  388. UserProc::updateUserInfo();
  389. return Resp::ok(array(
  390. //'gold' => ctx()->baseInfo->gold,
  391. 'store' => ctx()->store,
  392. ));
  393. }
  394. /**
  395. * 6428 宠物降品
  396. */
  397. public static function Pet_DownGradingQual() {
  398. list($uid) = req()->paras;
  399. $petDic = ctx()->store->pet;
  400. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  401. $ins_pet = new Ins_Pet($petDic->$uid);
  402. $NotDownGradingList = explode(',', glc()->equipQual_NotDownGrading);
  403. my_Assert(!in_array($ins_pet->qual, $NotDownGradingList), ErrCode::user_store_equip_minQual);
  404. $itemNum = 0;
  405. for ($i = 1; $i < $ins_pet->level; $i++) {
  406. $mo = GameConfig::pet_levelupgrade_getItem($ins_pet->mo()->rarity, $ins_pet->qual, $i);
  407. $itemNum += $mo->costItem;
  408. }
  409. StoreProc::AddMultiItemInStore(6 . ',' . $itemNum);
  410. self::ComposeMaterial_Fallback_Pet($ins_pet->mo()->petType, $ins_pet->qual);
  411. $ins_pet->level = 1;
  412. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  413. foreach ($sList2 as $str3) {
  414. $s = explode(',', $str3);
  415. if (in_array($ins_pet->qual, $s)) {
  416. $ins_pet->qual = $s[0];
  417. break;
  418. }
  419. }
  420. ctx()->store->pet->$uid = $ins_pet;
  421. //FightProc::Ranking_FightPower();
  422. UserProc::updateUserInfo();
  423. return Resp::ok(array(
  424. //'gold' => ctx()->baseInfo->gold,
  425. 'store' => ctx()->store,
  426. ));
  427. }
  428. private static function ComposeMaterial_Fallback_Pet($type, $qual) {
  429. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  430. foreach ($sList2 as $str) {
  431. $s = explode(',', $str);
  432. if (in_array($qual, $s)) {
  433. $max = $qual;
  434. $min = $s[0];
  435. $num = 0;
  436. for ($i = $min; $i < $max; $i++) {
  437. $mo = GameConfig::pet_compose_getItem($i);
  438. $num += explode(',', $mo->compose_condition)[2];
  439. }
  440. $typeId = StoreProc::ComposeMaterial($type, $min,902);
  441. StoreProc::AddMultiItemInStore($typeId . ',' . $num);
  442. break;
  443. }
  444. }
  445. }
  446. /*
  447. * 6427 宠物降级
  448. */
  449. public static function Pet_DownGradingLevel() {
  450. list($uid) = req()->paras; //宠物uid
  451. $petDic = ctx()->store->pet;
  452. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  453. $ins_pet = new Ins_Pet($petDic->$uid);
  454. my_Assert($ins_pet->level > 1, ErrCode::user_store_equip_minlevel);
  455. $itemNum = 0;
  456. for ($i = 1; $i < $ins_pet->level; $i++) {
  457. $mo = GameConfig::pet_levelupgrade_getItem($ins_pet->mo()->rarity, $ins_pet->qual, $i);
  458. $itemNum += $mo->costItem;
  459. }
  460. StoreProc::AddMultiItemInStore(6 . ',' . $itemNum);
  461. $ins_pet->level = 1;
  462. ctx()->store->pet->$uid = $ins_pet;
  463. //FightProc::Ranking_FightPower();
  464. UserProc::updateUserInfo();
  465. return Resp::ok(array(
  466. //'gold' => ctx()->baseInfo->gold,
  467. 'store' => ctx()->store,
  468. ));
  469. }
  470. /**
  471. * 6426 宠物一键合成
  472. * @return type
  473. */
  474. public static function Pet_OnekeyCompose() {
  475. $store = ctx()->store(true);
  476. $petDic = $store->pet;
  477. $arr = array(); # 待处理装备临时数组
  478. $composePet = array(); # 合成记录
  479. foreach ($petDic as $pet) {
  480. if ($pet->qual < 4) { # 4 品以上的不参与合成
  481. $arr[] = new Ins_Pet($pet);
  482. }
  483. }
  484. while (count($arr) > 0) { # 循环处理每一个装备
  485. $pet_compose = array_pop($arr); # 从末尾弹出一个元素做合成运算
  486. if (null == $pet_compose) { # 防御空对象
  487. break;
  488. }
  489. $eqQualCfg = GameConfig::pet_compose_getItem($pet_compose->qual); # 按照品阶查询合成配置数据
  490. my_Assert(null != $eqQualCfg, ErrCode::err_const_no); # 防御配置数据错误
  491. list($type, $costQual, $num) = explode(',', $eqQualCfg->compose_condition); # 从配置提取合成条件
  492. $composeArr = array(); # 消耗集合
  493. foreach ($arr as $v) { # 从剩余元素中查找合成所需
  494. if ($v->qual == $costQual) { # 同品阶
  495. if (($type == 1) ? $v->typeId == $pet_compose->typeId # # type: 1 与本体相同 2 同部位即可
  496. : $v->mo()->petType == $pet_compose->mo()->petType) {
  497. $composeArr[] = $v; # 成为消耗品
  498. }
  499. if (count($composeArr) >= $num) { # 达到消耗数量就停
  500. break;
  501. }
  502. }
  503. }
  504. if (count($composeArr) >= $num) { # 合成的回收 不合成的可不能给回收了
  505. $uid = $pet_compose->uid;
  506. $newPet = self::ComposeNewPet($pet_compose); # 原地合成
  507. self::petLevelChange_Material_Recovery($newPet->mo()->rarity, $newPet->qual, $newPet->level); # 回收材料
  508. $newPet->level = 1;
  509. $petDic->$uid = $newPet;
  510. $composePet[] = $uid; # 添加合成记录
  511. foreach ($composeArr as $val) { # 回收消耗的装备中所含材料
  512. self::petLevelChange_Material_Recovery($val->mo()->rarity, $val->qual, $val->level); # 回收材料
  513. StlUtil::dictRemove(ctx()->store(true)->pet, $val->uid); # 背包删除
  514. if(ctx()->store(true)->petUid_fight_position == $val->uid){
  515. ctx()->store(true)->petUid_fight_position = 0;
  516. }
  517. foreach (ctx()->store(true)->petUids_supportFight_position as $k => $pUid) {
  518. if($pUid == $val->uid){
  519. StlUtil::dictRemove(ctx()->store(true)->petUids_supportFight_position, $k);
  520. break;
  521. }
  522. }
  523. StlUtil::arrayRemove($arr, $val); # 从arr中删掉已消耗装备
  524. }
  525. }
  526. }
  527. UserProc::updateUserInfo(); # 回存玩家数据
  528. return Resp::ok(array(# # 返回给客户端的数据
  529. 'store' => ctx()->store,
  530. 'composeEquip' => $composePet,
  531. 'task' => ctx()->task,
  532. ));
  533. }
  534. /**
  535. * 6425 宠物合成
  536. * @return Resp
  537. */
  538. public static function Pet_Compose() {
  539. list($uid, $petUids_cost, $composeMaterial_typeIds) = req()->paras;
  540. $petDic = ctx()->store->pet;
  541. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  542. $ins_pet = new Ins_Pet($petDic->$uid);
  543. my_Assert($ins_pet->qual < 11, ErrCode::user_store_equip_qualMaxLimit);
  544. $composeMo = GameConfig::pet_compose_getItem($ins_pet->qual);
  545. my_Assert(null != $composeMo, ErrCode::err_const_no);
  546. $arr = explode(',', $composeMo->compose_condition);
  547. $type = $arr[0];
  548. $costQual = $arr[1];
  549. $num = $arr[2];
  550. $all_num = 0;
  551. $materialItemType = 0;
  552. $materialItemNum = 0;
  553. if ($type == 2 && $composeMaterial_typeIds != null) {//部位去校验
  554. $str = explode(',', $composeMaterial_typeIds);
  555. $materialItemType = $str[0];
  556. $materialItemNum = count($str);
  557. foreach ($str as $s) {
  558. $composeMaterial_itemTypeId = StoreProc::ComposeMaterial($ins_pet->mo()->petType, $costQual,902);
  559. my_Assert($composeMaterial_itemTypeId == $s, ErrCode::user_store_equip_composeMaterialErr);
  560. $all_num += 1;
  561. }
  562. }
  563. if ($petUids_cost != null) {
  564. $costPetsArr = explode(',', $petUids_cost);
  565. $all_num += count($costPetsArr);
  566. foreach ($costPetsArr as $pUid) {
  567. my_Assert(StlUtil::dictHasProperty($petDic, $pUid), ErrCode::user_store_NotExistPet);
  568. my_Assert(ctx()->store(true)->petUid_fight_position != $pUid, ErrCode::user_store_NotSelectPet_fight);
  569. my_Assert(!in_array($pUid, ctx()->store(true)->petUids_supportFight_position), ErrCode::user_store_NotSelectPet_supportfight);
  570. $costIns_pet = new Ins_Pet($petDic->$pUid);
  571. my_Assert($costIns_pet->qual == $costQual, ErrCode::user_store_equipMaterialQualErr);
  572. if ($type == 1) {//本体
  573. my_Assert($costIns_pet->typeId == $ins_pet->typeId, ErrCode::user_store_equipMaterialTypeErr);
  574. } else {
  575. my_Assert($costIns_pet->mo()->petType == $ins_pet->mo()->petType, ErrCode::user_store_equipMaterialTypeErr);
  576. }
  577. }
  578. }
  579. my_Assert($all_num == $num, ErrCode::user_store_equipMaterialNumErr);
  580. ctx()->store(true)->pet->$uid = self::ComposeNewPet($ins_pet);
  581. //消耗的装备 回收
  582. if ($petUids_cost != null) {
  583. $costPetsArr = explode(',', $petUids_cost);
  584. foreach ($costPetsArr as $pUid) {
  585. $costIns_Equip = new Ins_Pet($petDic->$pUid);
  586. self::petLevelChange_Material_Recovery($costIns_Equip->mo()->rarity, $costIns_Equip->qual, $costIns_Equip->level);
  587. StlUtil::dictRemove(ctx()->store(true)->pet, $pUid);
  588. }
  589. }
  590. if ($materialItemType != 0) {
  591. ctx()->store(true)->removeItem($materialItemType, $materialItemNum);
  592. }
  593. UserProc::updateUserInfo();
  594. return Resp::ok(array(
  595. 'store' => ctx()->store,
  596. 'task' => ctx()->task,
  597. ));
  598. }
  599. /**
  600. * 装备等级提升 消耗的金币图纸回收
  601. * @param type $rarity
  602. * @param type $qual
  603. * @param type $posId
  604. * @param type $level
  605. */
  606. public static function petLevelChange_Material_Recovery($rarity, $qual,$level) {
  607. $num = 0;
  608. for ($i = 1; $i <= $level - 1; $i++) {
  609. $mo = GameConfig::pet_levelupgrade_getItem($rarity, $qual, $i);
  610. $num += $mo->costItem;
  611. }
  612. if ($num > 0) {
  613. StoreProc::AddMultiItemInStore(6 . ',' . $num);
  614. }
  615. }
  616. /**
  617. * 合成一个新的装备
  618. * @param type Ins_Equip
  619. */
  620. public static function ComposeNewPet(&$ins_pet) {
  621. $newPetTypeId = $ins_pet->typeId;
  622. $qual = $ins_pet->qual + 1;
  623. if ($ins_pet->qual < 4) {
  624. //$newEquipTypeId = substr($ins_pet->typeId, 0, strlen($ins_equip->typeId) - 5);
  625. $rarity = substr($ins_pet->typeId, -2);
  626. $mo = GameConfig::pet_getItem($ins_pet->typeId);
  627. $newPetTypeId = $mo->type. "0" . $qual . $rarity;
  628. }
  629. $ins_pet->typeId = $newPetTypeId;
  630. $ins_pet->qual = $qual;
  631. return $ins_pet;
  632. }
  633. /**
  634. *6424 灵宠等级提升
  635. * @return Resp
  636. */
  637. public static function Pet_LevelUpgrade(){
  638. list($uid) = req()->paras; //装备uid
  639. my_Assert(StlUtil::dictHasProperty(ctx()->store->pet, $uid), ErrCode::user_store_NotExistPet);
  640. $ins_pet = new Ins_Pet(ctx()->store->pet->$uid);
  641. my_Assert($ins_pet->level < $ins_pet->Pet_MaxLevel(), ErrCode::user_store_LevelLimit);
  642. $mo = $ins_pet->petLevelMo();
  643. $costTuzhiId = 6;
  644. $tuzhiNum = 0;
  645. if (StlUtil::dictHasProperty(ctx()->store->items, $costTuzhiId)) {
  646. $tuzhiNum = ctx()->store->items->$costTuzhiId;
  647. }
  648. my_Assert($tuzhiNum >= $mo->costItem, ErrCode::notenough_item);
  649. ctx()->store(true)->removeItem($costTuzhiId,$mo->costItem);
  650. $ins_pet->level += 1;
  651. ctx()->store->pet->$uid = $ins_pet;
  652. UserProc::updateUserInfo();
  653. return Resp::ok(array(
  654. 'store' => ctx()->store,
  655. ));
  656. }
  657. /**
  658. * 6423 展示空闲灵宠
  659. * @return Resp
  660. */
  661. public static function Pet_SelectShowPet(){
  662. list($uid) = req()->paras;
  663. $petDic = ctx()->store->pet;
  664. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  665. my_Assert(count(ctx()->store()->mainShowPetList)< GameConfig::glc2()->Pet_MainShowPetList , ErrCode::user_store_ShowPetNumLimit);
  666. my_Assert(ctx()->store->petUid_fight_position != $uid, ErrCode::user_store_NotSelectPet_fight);
  667. my_Assert(!in_array($uid, ctx()->store->petUids_supportFight_position), ErrCode::user_store_NotSelectPet_supportfight);
  668. if(in_array($uid,ctx()->store()->mainShowPetList)){
  669. StlUtil::arrayRemove(ctx()->store()->mainShowPetList, $uid);
  670. } else {
  671. ctx()->store()->mainShowPetList[] = $uid;
  672. }
  673. UserProc::updateUserInfo();
  674. return Resp::ok(array());
  675. }
  676. /**
  677. * 6422 出战/替换/上阵
  678. */
  679. public static function Pet_ChangeFightPosition() {
  680. list($type, $uid, $index) = req()->paras;
  681. if ($type == 1) {//出战、替换
  682. ctx()->store(true)->petUid_fight_position = $uid;
  683. } else if ($type == 2) {
  684. ctx()->store(true)->petUids_supportFight_position->$index = $uid;
  685. }
  686. if ($type == 0 && $index == 0 && $uid != 0) {//上阵点击空白的地方
  687. if (ctx()->store(true)->petUid_fight_position == 0) {
  688. ctx()->store(true)->petUid_fight_position = $uid;
  689. } else {
  690. $list = StlUtil::dictToArray(ctx()->store(true)->petUids_supportFight_position);
  691. if (count($list) === 0) {
  692. $key = 1;
  693. ctx()->store(true)->petUids_supportFight_position->$key = $uid;
  694. } else {
  695. for ($i = 1; $i <= 2; $i++) {
  696. if (!StlUtil::dictHasProperty(ctx()->store(true)->petUids_supportFight_position, $i) || ctx()->store(true)->petUids_supportFight_position->$i == 0) {
  697. ctx()->store(true)->petUids_supportFight_position->$i = $uid;
  698. break;
  699. }
  700. }
  701. }
  702. }
  703. }
  704. UserProc::updateUserInfo();
  705. return Resp::ok(array());
  706. }
  707. /**
  708. * 6421 移除宠物上的新的标志
  709. */
  710. public static function Pet_RemoveNewTip() {
  711. list($uid) = req()->paras;
  712. $petDic = ctx()->store->pet;
  713. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  714. ctx()->store->pet->$uid->isNew = 0;
  715. UserProc::updateUserInfo();
  716. return Resp::ok(array());
  717. }
  718. }