PetProc.php 34 KB

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