PetProc.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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_count = 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_count = $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. * 6437 点击派遣宠物
  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_count = 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_count = $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. * 6438 某区域的派遣宠物信息
  195. * @return Resp
  196. */
  197. public static function ResetDispatchPet() {
  198. list($areaId) = req()->paras;
  199. $ins_ExploreArea = new Ins_ExploreArea(ctx()->store->exploreArea->$areaId);
  200. UserProc::updateUserInfo();
  201. return Resp::ok(array(
  202. 'explorePetList' =>$ins_ExploreArea->explorePetList,
  203. ));
  204. }
  205. /**
  206. * 6435 删除全部派遣宠物
  207. */
  208. public static function RemoveDispatchPet() {
  209. list($areaId) = req()->paras;
  210. $vo = new Ins_ExploreArea(ctx()->store->exploreArea->$areaId);
  211. $vo->explorePetList = array();
  212. $vo->startTs = 0;
  213. $vo->endTs = 0;
  214. $vo->output_count = 0;
  215. $vo->output_ts = 0;
  216. ctx()->store->exploreArea->$areaId = $vo;
  217. UserProc::updateUserInfo();
  218. return Resp::ok(array(
  219. 'store' => ctx()->store,
  220. ));
  221. }
  222. /**
  223. * 6436 领取探索奖励
  224. */
  225. public static function Pet_ReceiveReward() {
  226. list($areaId) = req()->paras;
  227. $vo = new Ins_ExploreArea(ctx()->store->exploreArea->$areaId);
  228. my_Assert($vo->startTs > 0 && now() - $vo->startTs > 10 * 60, ErrCode::user_store_CannotReceiveReward);
  229. $tt = now() - $vo->startTs;
  230. if (now() >= $vo->endTs) {
  231. $tt = $vo->endTs - $vo->startTs;
  232. }
  233. $ts_n = $vo->output_ts / $vo->output_count;
  234. $num = intval($tt *= $ts_n);
  235. $goodsStr = $vo->mo()->reward_fixed . ',' . $num;
  236. StoreProc::AddMultiItemInStore($goodsStr);
  237. $reward = explode(',', $vo->mo()->reward_extra);
  238. $randNum = rand(1, $reward[2]);
  239. if ($randNum <= $reward[2]) {
  240. StoreProc::AddMultiItemInStore($reward[0] . ',' . $reward[1]);
  241. }
  242. //$vo->explorePetList = array();
  243. $vo->startTs = 0;
  244. $vo->endTs = 0;
  245. $vo->output_count = 0;
  246. $vo->output_ts = 0;
  247. ctx()->store->exploreArea->$areaId = $vo;
  248. UserProc::updateUserInfo();
  249. return Resp::ok(array(
  250. 'gold' => ctx()->baseInfo->gold,
  251. 'cash' => ctx()->baseInfo->cash,
  252. 'reward' => StoreProc::$reward,
  253. 'reward_Gem' => StoreProc::$reward_Gem,
  254. 'reward_equip' => StoreProc::$reward_equip,
  255. 'store' => ctx()->store,
  256. ));
  257. }
  258. /**
  259. * 6432 解锁孵化位置
  260. * @return Resp
  261. */
  262. public static function Pet_UnlockBreedLocation() {
  263. list($slotId) = req()->paras;
  264. $list = explode(';',GameConfig::glc2()->Pet_BreedLocationUnlockInfo);
  265. foreach ($list as $value) {
  266. $s = explode(',', $value);
  267. if($s[0] == $slotId){
  268. my_Assert(ctx()->baseInfo->cash >= $s[1], ErrCode::notenough_cash_msg);
  269. ctx()->base()->Consume_Cash($s[1]);
  270. $breed = new Ins_BreedEggSlot(ctx()->store->breedEggLocation->$slotId);
  271. $breed->unlock = 1;
  272. ctx()->store()->breedEggLocation->$slotId = $breed;
  273. break;
  274. }
  275. }
  276. UserProc::updateUserInfo();
  277. return Resp::ok(array(
  278. 'cash' => ctx()->baseInfo->cash,
  279. 'store' => ctx()->store,
  280. ));
  281. }
  282. /**
  283. * 6431 正常孵化完成点击领取
  284. * @return Resp
  285. */
  286. public static function Pet_ReceiveBreedPet() {
  287. list($slotId) = req()->paras;
  288. $ins_breed = new Ins_BreedEggSlot(ctx()->store()->breedEggLocation->$slotId);
  289. my_Assert($ins_breed->eggId != 0, ErrCode::user_store_NoExistBreedEgg);
  290. my_Assert($ins_breed->unlock == 1, ErrCode::user_store_SlotNotUnlocked);
  291. my_Assert(now() >= $ins_breed->endTs, ErrCode::user_store_NoCompleteBreed);
  292. StoreProc::AddMultiItemInStore($ins_breed->mo()->reward);
  293. //随机一个灵宠
  294. $str = explode(';', $ins_breed->mo()->per);
  295. $newPet = self::RandObtainPet($str);
  296. $uid = 0;
  297. if($newPet != null){
  298. $uid = $newPet->uid;
  299. ctx()->store()->pet->$uid = $newPet;
  300. }
  301. $ins_breed->eggId = 0;
  302. $ins_breed->endTs = 0;
  303. ctx()->store()->breedEggLocation->$slotId = $ins_breed;
  304. UserProc::updateUserInfo();
  305. return Resp::ok(array(
  306. 'newPetUid'=>$uid,
  307. 'cash' => ctx()->baseInfo->cash,
  308. 'store' => ctx()->store,
  309. ));
  310. }
  311. /**
  312. * 6430 加速孵化宠物
  313. * @return Resp
  314. */
  315. public static function Pet_FastBreedEgg() {
  316. list($slotId) = req()->paras;
  317. $ins_breed = new Ins_BreedEggSlot(ctx()->store()->breedEggLocation->$slotId);
  318. my_Assert($ins_breed->eggId != 0, ErrCode::user_store_NoExistBreedEgg);
  319. my_Assert($ins_breed->unlock == 1, ErrCode::user_store_SlotNotUnlocked);
  320. my_Assert(now() < $ins_breed->endTs, ErrCode::user_store_CompleteBreed);
  321. $num = $ins_breed->mo()->breedTs/60/10;
  322. $cash_one = $ins_breed->mo()->fastBreed_cost/$num;
  323. $ts_shengyu = $ins_breed->endTs - now();
  324. $cost_Ts = $ins_breed->mo()->breedTs - $ts_shengyu;
  325. $costNum = intval($cost_Ts/60/10);
  326. $costCash = $ins_breed->mo()->fastBreed_cost - $costNum*$cash_one;
  327. my_Assert(ctx()->baseInfo->cash >= $costCash, ErrCode::notenough_cash_msg);
  328. ctx()->base()->Consume_Cash($costCash);
  329. $ins_breed->endTs = 0;
  330. ctx()->store()->breedEggLocation->$slotId = $ins_breed;
  331. //StoreProc::AddMultiItemInStore($ins_breed->mo()->reward);
  332. //随机一个灵宠
  333. //$str = explode(';', $ins_breed->mo()->per);
  334. //$newPet = self::RandObtainPet($str);
  335. // $uid = 0;
  336. // if($newPet != null){
  337. // $uid = $newPet->uid;
  338. // ctx()->store()->pet->$uid = $newPet;
  339. // }
  340. UserProc::updateUserInfo();
  341. return Resp::ok(array(
  342. 'cash' => ctx()->baseInfo->cash,
  343. 'store' => ctx()->store,
  344. //'newPetUid'=>$uid,
  345. ));
  346. }
  347. /**
  348. * 初始化一个宠物
  349. * @param type $rarity
  350. * @param type $qual
  351. * @param type $petType
  352. */
  353. public static function RandObtainPet($str) {
  354. //随机一个灵宠
  355. $randNum = rand(1,10000);
  356. $start = 0;
  357. $end = 0;
  358. $rarity = 0;
  359. $qual = 0;
  360. $petType = 0;
  361. foreach ($str as $key => $value) {
  362. $s = explode(',', $value);
  363. $end += $s[3]*100;
  364. if($randNum > $start && $randNum <= $end){
  365. $rarity = $s[0];
  366. $qual = $s[1];
  367. $petType = $s[2];
  368. break;
  369. }
  370. $start = $end;
  371. }
  372. $dic = GameConfig::pet();
  373. $petArr = array();
  374. foreach ($dic as $typeId => $mo) {
  375. if($mo->petType == $petType && $mo->qual == $qual && $mo->rarity == $rarity && $mo->type != 902){
  376. $petArr[] = $typeId;
  377. }
  378. }
  379. $typeId = 0;
  380. if(count($petArr) > 0){
  381. $num = rand(0,count($petArr)-1);
  382. $typeId = $petArr[$num];
  383. }
  384. if($typeId != 0){
  385. return StoreProc::initPet($typeId);
  386. }
  387. return null;
  388. }
  389. /**
  390. * 6429 孵化宠物
  391. * @return Resp
  392. */
  393. public static function Pet_BreedEgg() {
  394. list($slotId,$eggId) = req()->paras;
  395. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $eggId), ErrCode::user_store_NoItem);
  396. $mo = GameConfig::item_getItem($eggId);
  397. my_Assert($mo != null, ErrCode::err_const_no);
  398. my_Assert($mo->itemType == 105, ErrCode::user_store_NoItem);
  399. $ins_breed = new Ins_BreedEggSlot(ctx()->store()->breedEggLocation->$slotId);
  400. my_Assert($ins_breed->eggId == 0 && $ins_breed->unlock == 1, ErrCode::user_store_NoBreedSlot);
  401. ctx()->store()->removeItem($eggId, 1);
  402. //$ins_breed = ctx()->store()->breedEggLocation->$slot;
  403. $ins_breed->eggId = $eggId;
  404. $ts = $ins_breed->mo()->breedTs;
  405. $ins_breed->endTs = now()+$ts;
  406. ctx()->store()->breedEggLocation->$slotId = $ins_breed;
  407. UserProc::updateUserInfo();
  408. return Resp::ok(array(
  409. //'gold' => ctx()->baseInfo->gold,
  410. 'store' => ctx()->store,
  411. ));
  412. }
  413. /**
  414. * 6428 宠物降品
  415. */
  416. public static function Pet_DownGradingQual() {
  417. list($uid) = req()->paras;
  418. $petDic = ctx()->store->pet;
  419. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  420. $ins_pet = new Ins_Pet($petDic->$uid);
  421. $NotDownGradingList = explode(',', glc()->equipQual_NotDownGrading);
  422. my_Assert(!in_array($ins_pet->qual, $NotDownGradingList), ErrCode::user_store_equip_minQual);
  423. $itemNum = 0;
  424. for ($i = 1; $i < $ins_pet->level; $i++) {
  425. $mo = GameConfig::pet_levelupgrade_getItem($ins_pet->mo()->rarity, $ins_pet->qual, $i);
  426. $itemNum += $mo->costItem;
  427. }
  428. StoreProc::AddMultiItemInStore(6 . ',' . $itemNum);
  429. self::ComposeMaterial_Fallback_Pet($ins_pet->mo()->petType, $ins_pet->qual);
  430. $ins_pet->level = 1;
  431. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  432. foreach ($sList2 as $str3) {
  433. $s = explode(',', $str3);
  434. if (in_array($ins_pet->qual, $s)) {
  435. $ins_pet->qual = $s[0];
  436. break;
  437. }
  438. }
  439. ctx()->store->pet->$uid = $ins_pet;
  440. //FightProc::Ranking_FightPower();
  441. UserProc::updateUserInfo();
  442. return Resp::ok(array(
  443. //'gold' => ctx()->baseInfo->gold,
  444. 'store' => ctx()->store,
  445. ));
  446. }
  447. private static function ComposeMaterial_Fallback_Pet($type, $qual) {
  448. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  449. foreach ($sList2 as $str) {
  450. $s = explode(',', $str);
  451. if (in_array($qual, $s)) {
  452. $max = $qual;
  453. $min = $s[0];
  454. $num = 0;
  455. for ($i = $min; $i < $max; $i++) {
  456. $mo = GameConfig::pet_compose_getItem($i);
  457. $num += explode(',', $mo->compose_condition)[2];
  458. }
  459. $typeId = StoreProc::ComposeMaterial($type, $min,902);
  460. StoreProc::AddMultiItemInStore($typeId . ',' . $num);
  461. break;
  462. }
  463. }
  464. }
  465. /*
  466. * 6427 宠物降级
  467. */
  468. public static function Pet_DownGradingLevel() {
  469. list($uid) = req()->paras; //宠物uid
  470. $petDic = ctx()->store->pet;
  471. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  472. $ins_pet = new Ins_Pet($petDic->$uid);
  473. my_Assert($ins_pet->level > 1, ErrCode::user_store_equip_minlevel);
  474. $itemNum = 0;
  475. for ($i = 1; $i < $ins_pet->level; $i++) {
  476. $mo = GameConfig::pet_levelupgrade_getItem($ins_pet->mo()->rarity, $ins_pet->qual, $i);
  477. $itemNum += $mo->costItem;
  478. }
  479. StoreProc::AddMultiItemInStore(6 . ',' . $itemNum);
  480. $ins_pet->level = 1;
  481. ctx()->store->pet->$uid = $ins_pet;
  482. //FightProc::Ranking_FightPower();
  483. UserProc::updateUserInfo();
  484. return Resp::ok(array(
  485. //'gold' => ctx()->baseInfo->gold,
  486. 'store' => ctx()->store,
  487. ));
  488. }
  489. /**
  490. * 6426 宠物一键合成
  491. * @return type
  492. */
  493. public static function Pet_OnekeyCompose() {
  494. $store = ctx()->store(true);
  495. $petDic = $store->pet;
  496. $arr = array(); # 待处理装备临时数组
  497. $composePet = array(); # 合成记录
  498. foreach ($petDic as $pet) {
  499. if ($pet->qual < 4) { # 4 品以上的不参与合成
  500. $arr[] = new Ins_Pet($pet);
  501. }
  502. }
  503. while (count($arr) > 0) { # 循环处理每一个装备
  504. $pet_compose = array_pop($arr); # 从末尾弹出一个元素做合成运算
  505. if (null == $pet_compose) { # 防御空对象
  506. break;
  507. }
  508. $eqQualCfg = GameConfig::pet_compose_getItem($pet_compose->qual); # 按照品阶查询合成配置数据
  509. my_Assert(null != $eqQualCfg, ErrCode::err_const_no); # 防御配置数据错误
  510. list($type, $costQual, $num) = explode(',', $eqQualCfg->compose_condition); # 从配置提取合成条件
  511. $composeArr = array(); # 消耗集合
  512. foreach ($arr as $v) { # 从剩余元素中查找合成所需
  513. if ($v->qual == $costQual) { # 同品阶
  514. if (($type == 1) ? $v->typeId == $pet_compose->typeId # # type: 1 与本体相同 2 同部位即可
  515. : $v->mo()->petType == $pet_compose->mo()->petType) {
  516. $composeArr[] = $v; # 成为消耗品
  517. }
  518. if (count($composeArr) >= $num) { # 达到消耗数量就停
  519. break;
  520. }
  521. }
  522. }
  523. if (count($composeArr) >= $num) { # 合成的回收 不合成的可不能给回收了
  524. $uid = $pet_compose->uid;
  525. $newPet = self::ComposeNewPet($pet_compose); # 原地合成
  526. self::petLevelChange_Material_Recovery($newPet->mo()->rarity, $newPet->qual, $newPet->level); # 回收材料
  527. $newPet->level = 1;
  528. $petDic->$uid = $newPet;
  529. $composePet[] = $uid; # 添加合成记录
  530. foreach ($composeArr as $val) { # 回收消耗的装备中所含材料
  531. self::petLevelChange_Material_Recovery($val->mo()->rarity, $val->qual, $val->level); # 回收材料
  532. StlUtil::dictRemove(ctx()->store(true)->pet, $val->uid); # 背包删除
  533. if(ctx()->store(true)->petUid_fight_position == $val->uid){
  534. ctx()->store(true)->petUid_fight_position = 0;
  535. }
  536. foreach (ctx()->store(true)->petUids_supportFight_position as $k => $pUid) {
  537. if($pUid == $val->uid){
  538. StlUtil::dictRemove(ctx()->store(true)->petUids_supportFight_position, $k);
  539. break;
  540. }
  541. }
  542. StlUtil::arrayRemove($arr, $val); # 从arr中删掉已消耗装备
  543. }
  544. }
  545. }
  546. UserProc::updateUserInfo(); # 回存玩家数据
  547. return Resp::ok(array(# # 返回给客户端的数据
  548. 'store' => ctx()->store,
  549. 'composeEquip' => $composePet,
  550. 'task' => ctx()->task,
  551. ));
  552. }
  553. /**
  554. * 6425 宠物合成
  555. * @return Resp
  556. */
  557. public static function Pet_Compose() {
  558. list($uid, $petUids_cost, $composeMaterial_typeIds) = req()->paras;
  559. $petDic = ctx()->store->pet;
  560. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  561. $ins_pet = new Ins_Pet($petDic->$uid);
  562. my_Assert($ins_pet->qual < 11, ErrCode::user_store_equip_qualMaxLimit);
  563. $composeMo = GameConfig::pet_compose_getItem($ins_pet->qual);
  564. my_Assert(null != $composeMo, ErrCode::err_const_no);
  565. $arr = explode(',', $composeMo->compose_condition);
  566. $type = $arr[0];
  567. $costQual = $arr[1];
  568. $num = $arr[2];
  569. $all_num = 0;
  570. $materialItemType = 0;
  571. $materialItemNum = 0;
  572. if ($type == 2 && $composeMaterial_typeIds != null) {//部位去校验
  573. $str = explode(',', $composeMaterial_typeIds);
  574. $materialItemType = $str[0];
  575. $materialItemNum = count($str);
  576. foreach ($str as $s) {
  577. $composeMaterial_itemTypeId = StoreProc::ComposeMaterial($ins_pet->mo()->petType, $costQual,902);
  578. my_Assert($composeMaterial_itemTypeId == $s, ErrCode::user_store_equip_composeMaterialErr);
  579. $all_num += 1;
  580. }
  581. }
  582. if ($petUids_cost != null) {
  583. $costPetsArr = explode(',', $petUids_cost);
  584. $all_num += count($costPetsArr);
  585. foreach ($costPetsArr as $pUid) {
  586. my_Assert(StlUtil::dictHasProperty($petDic, $pUid), ErrCode::user_store_NotExistPet);
  587. my_Assert(ctx()->store(true)->petUid_fight_position != $pUid, ErrCode::user_store_NotSelectPet_fight);
  588. $supportDic = ctx()->store(true)->petUids_supportFight_position;
  589. if(StlUtil::dictHasProperty($supportDic, 1)){
  590. $k1 = 1;
  591. my_Assert($pUid != $supportDic->$k1, ErrCode::user_store_NotSelectPet_supportfight);
  592. }
  593. if(StlUtil::dictHasProperty($supportDic, 2)){
  594. $k2 = 2;
  595. my_Assert($pUid != $supportDic->$k2, ErrCode::user_store_NotSelectPet_supportfight);
  596. }
  597. $costIns_pet = new Ins_Pet($petDic->$pUid);
  598. my_Assert($costIns_pet->qual == $costQual, ErrCode::user_store_equipMaterialQualErr);
  599. if ($type == 1) {//本体
  600. my_Assert($costIns_pet->typeId == $ins_pet->typeId, ErrCode::user_store_equipMaterialTypeErr);
  601. } else {
  602. my_Assert($costIns_pet->mo()->petType == $ins_pet->mo()->petType, ErrCode::user_store_equipMaterialTypeErr);
  603. }
  604. }
  605. }
  606. my_Assert($all_num == $num, ErrCode::user_store_equipMaterialNumErr);
  607. ctx()->store(true)->pet->$uid = self::ComposeNewPet($ins_pet);
  608. //消耗的装备 回收
  609. if ($petUids_cost != null) {
  610. $costPetsArr = explode(',', $petUids_cost);
  611. foreach ($costPetsArr as $pUid) {
  612. $costIns_Equip = new Ins_Pet($petDic->$pUid);
  613. self::petLevelChange_Material_Recovery($costIns_Equip->mo()->rarity, $costIns_Equip->qual, $costIns_Equip->level);
  614. StlUtil::dictRemove(ctx()->store(true)->pet, $pUid);
  615. }
  616. }
  617. if ($materialItemType != 0) {
  618. ctx()->store(true)->removeItem($materialItemType, $materialItemNum);
  619. }
  620. UserProc::updateUserInfo();
  621. return Resp::ok(array(
  622. 'store' => ctx()->store,
  623. 'task' => ctx()->task,
  624. ));
  625. }
  626. /**
  627. * 装备等级提升 消耗的金币图纸回收
  628. * @param type $rarity
  629. * @param type $qual
  630. * @param type $posId
  631. * @param type $level
  632. */
  633. public static function petLevelChange_Material_Recovery($rarity, $qual,$level) {
  634. $num = 0;
  635. for ($i = 1; $i <= $level - 1; $i++) {
  636. $mo = GameConfig::pet_levelupgrade_getItem($rarity, $qual, $i);
  637. $num += $mo->costItem;
  638. }
  639. if ($num > 0) {
  640. StoreProc::AddMultiItemInStore(6 . ',' . $num);
  641. }
  642. }
  643. /**
  644. * 合成一个新的装备
  645. * @param type Ins_Equip
  646. */
  647. public static function ComposeNewPet(&$ins_pet) {
  648. $newPetTypeId = $ins_pet->typeId;
  649. $qual = $ins_pet->qual + 1;
  650. if ($ins_pet->qual < 4) {
  651. //$newEquipTypeId = substr($ins_pet->typeId, 0, strlen($ins_equip->typeId) - 5);
  652. $rarity = substr($ins_pet->typeId, -2);
  653. $mo = GameConfig::pet_getItem($ins_pet->typeId);
  654. $newPetTypeId = $mo->type. "0" . $qual . $rarity;
  655. }
  656. $ins_pet->typeId = $newPetTypeId;
  657. $ins_pet->qual = $qual;
  658. return $ins_pet;
  659. }
  660. /**
  661. *6424 灵宠等级提升
  662. * @return Resp
  663. */
  664. public static function Pet_LevelUpgrade(){
  665. list($uid) = req()->paras; //装备uid
  666. my_Assert(StlUtil::dictHasProperty(ctx()->store->pet, $uid), ErrCode::user_store_NotExistPet);
  667. $ins_pet = new Ins_Pet(ctx()->store->pet->$uid);
  668. my_Assert($ins_pet->level < $ins_pet->Pet_MaxLevel(), ErrCode::user_store_LevelLimit);
  669. $mo = $ins_pet->petLevelMo();
  670. $costTuzhiId = 6;
  671. $tuzhiNum = 0;
  672. if (StlUtil::dictHasProperty(ctx()->store->items, $costTuzhiId)) {
  673. $tuzhiNum = ctx()->store->items->$costTuzhiId;
  674. }
  675. my_Assert($tuzhiNum >= $mo->costItem, ErrCode::notenough_item);
  676. ctx()->store(true)->removeItem($costTuzhiId,$mo->costItem);
  677. $ins_pet->level += 1;
  678. ctx()->store->pet->$uid = $ins_pet;
  679. UserProc::updateUserInfo();
  680. return Resp::ok(array(
  681. 'store' => ctx()->store,
  682. ));
  683. }
  684. /**
  685. * 6423 展示空闲灵宠
  686. * @return Resp
  687. */
  688. public static function Pet_SelectShowPet(){
  689. list($uids) = req()->paras;
  690. $petDic = ctx()->store->pet;
  691. if(count($uids) == 0){
  692. ctx()->store()->mainShowPetList = $uids;
  693. } else {
  694. my_Assert(count($uids)<= GameConfig::glc2()->Pet_MainShowPetList , ErrCode::user_store_ShowPetNumLimit);
  695. foreach ($uids as $uid) {
  696. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  697. my_Assert(ctx()->store->petUid_fight_position != $uid, ErrCode::user_store_NotSelectPet_fight);
  698. $tag = false;
  699. foreach (ctx()->store->petUids_supportFight_position as $k => $val) {
  700. if($val == $uid){
  701. $tag = true;
  702. break;
  703. }
  704. }
  705. my_Assert($tag == false, ErrCode::user_store_NotSelectPet_supportfight);
  706. }
  707. ctx()->store()->mainShowPetList = $uids;
  708. }
  709. UserProc::updateUserInfo();
  710. return Resp::ok(array(
  711. 'store' => ctx()->store,
  712. ));
  713. }
  714. /**
  715. * 6422 出战/替换/上阵
  716. */
  717. public static function Pet_ChangeFightPosition() {
  718. list($type, $uid, $index) = req()->paras;
  719. $dic = ctx()->store(true)->petUids_supportFight_position;
  720. if ($type == 1) {//出战、替换
  721. ctx()->store(true)->petUid_fight_position = $uid;
  722. foreach ($dic as $k => $petUid) {
  723. if($petUid == $uid){
  724. ctx()->store(true)->petUids_supportFight_position->$k = 0;
  725. }
  726. }
  727. } else if ($type == 2) {
  728. $tag = false;
  729. foreach ($dic as $k => $petUid) {
  730. if($petUid == $uid && $k != $index){
  731. $tag = true;
  732. break;
  733. }
  734. }
  735. my_Assert(!$tag, ErrCode::user_store_NoReplacePet);
  736. ctx()->store(true)->petUids_supportFight_position->$index = $uid;
  737. if(ctx()->store(true)->petUid_fight_position == $uid){
  738. ctx()->store(true)->petUid_fight_position = 0;
  739. }
  740. }
  741. // if ($type == 0 && $index == 0 && $uid != 0) {//上阵点击空白的地方
  742. // if (ctx()->store(true)->petUid_fight_position == 0) {
  743. // ctx()->store(true)->petUid_fight_position = $uid;
  744. // } else {
  745. // $list = StlUtil::dictToArray(ctx()->store(true)->petUids_supportFight_position);
  746. // if (count($list) === 0) {
  747. // $key = 1;
  748. // ctx()->store(true)->petUids_supportFight_position->$key = $uid;
  749. // } else {
  750. // for ($i = 1; $i <= 2; $i++) {
  751. // if (!StlUtil::dictHasProperty(ctx()->store(true)->petUids_supportFight_position, $i) || ctx()->store(true)->petUids_supportFight_position->$i == 0) {
  752. // ctx()->store(true)->petUids_supportFight_position->$i = $uid;
  753. // break;
  754. // }
  755. // }
  756. // }
  757. // }
  758. // }
  759. UserProc::updateUserInfo();
  760. return Resp::ok(array());
  761. }
  762. /**
  763. * 6421 移除宠物上的新的标志
  764. */
  765. public static function Pet_RemoveNewTip() {
  766. list($uid) = req()->paras;
  767. $petDic = ctx()->store->pet;
  768. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  769. ctx()->store->pet->$uid->isNew = 0;
  770. UserProc::updateUserInfo();
  771. return Resp::ok(array());
  772. }
  773. /**
  774. * 6439 宠物休息
  775. */
  776. public static function RemoveFightPosition() {
  777. list($uid) = req()->paras;
  778. if (ctx()->store->petUid_fight_position == $uid)
  779. {
  780. ctx()->store()->petUid_fight_position = 0;
  781. }
  782. for ($i = 1; $i <= 2; $i++) {
  783. if (StlUtil::dictHasProperty(ctx()->store->petUids_supportFight_position, $i) && ctx()->store->petUids_supportFight_position->$i == $uid)
  784. {
  785. ctx()->store()->petUids_supportFight_position->$i = 0;
  786. break;
  787. }
  788. }
  789. UserProc::updateUserInfo();
  790. return Resp::ok(array());
  791. }
  792. }