PetProc.php 35 KB

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