PetProc.php 35 KB

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