PetProc.php 35 KB

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