ActiveProc.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. <?php
  2. namespace loyalsoft;
  3. require_once __DIR__ . '/ActiveProc/CipheredBase32.php'; # 算法库
  4. /**
  5. * 活动模块
  6. */
  7. class ActiveProc {
  8. /**
  9. * 兑换码礼包使用记录
  10. */
  11. const tab_toke_gift = 'tab_token_gift';
  12. /**
  13. * 逻辑分发
  14. * 所有的Proc中必须有这样一个方法
  15. */
  16. public static function procMain() {
  17. switch (req()->cmd) {
  18. case CmdCode::active_day7_drawreward: # 6502 领取七日签到奖励
  19. return self::Day7_DrawReward();
  20. case CmdCode::active_getzonePublicTs: # 6503 查询开服时间戳
  21. return ActiveProc::GetZonePublicTS();
  22. case CmdCode::active_getTodayOnlineInfos: # 6504 查询当天在线时长
  23. return self::getTotayOnlineInfos();
  24. case CmdCode::Task_Tili: # 6508 体力变化
  25. return ActiveProc::RecoveryTili();
  26. case CmdCode::active_token_drawReward: # 6512 兑换码礼包
  27. return self::drawActivePackageByCode();
  28. case CmdCode::active_draw_onlinegift: # 6513 领取在线(时长)礼包
  29. return self::drawOnlineGift();
  30. case CmdCode::active_draw_reggift: # 6514 领取全服注册礼包
  31. return self::drawRegGift();
  32. case CmdCode::active_presentTili: # 6515 领取在线赠送体力
  33. return self::drawTiliGift();
  34. case CmdCode::active_get_regnum: # 6516 查询当前全服注册人数
  35. return self::getRegNumber();
  36. case CmdCode::active_shenmiaoDrawPrize: # 6505 什么抽奖
  37. return self::shenmiaoDrawPrize();
  38. case CmdCode::active_GetShenmiaoData:
  39. return self::GetShenmiaoData();
  40. case CmdCode::active_BuyShenmiaoDrawTicket:
  41. return self::buyShenmiaoDrawTicket();
  42. default:
  43. return Resp::err(ErrCode::cmd_err);
  44. }
  45. }
  46. /**
  47. * 每天重置
  48. */
  49. static function DailyReset() {
  50. self::DailyResetDay7Task();
  51. self::ClearOnlineGiftTs();
  52. self::ClearDailyTiliGift();
  53. }
  54. // <editor-fold defaultstate="collapsed" desc=" 赠送体力 ">
  55. /**
  56. * 获取神庙的主界面信息
  57. */
  58. static function GetShenmiaoData() {
  59. $req = req();
  60. //$shenmiaoInfo = $req->userInfo->game->shenmiao;
  61. $shenmiaoInfo = new Info_ShenMiao($req->userInfo->game->shenmiao);
  62. $shenmiaoInfo->initActiveItem();
  63. $req->userInfo->game->shenmiao = $shenmiaoInfo;
  64. UserProc::updateUserInfo();
  65. return Resp::ok(array(# # 返回值
  66. 'shenmiaoInfo' => $shenmiaoInfo,
  67. ));
  68. }
  69. /**
  70. * 购买神庙券 临时
  71. * @return type
  72. */
  73. static function buyShenmiaoDrawTicket() {
  74. $req = req();
  75. list($costId,$num) = $req->paras;
  76. $dic = \GameConfig::shop_getItem($costId);
  77. my_Assert($dic != null, ErrCode::err_const_no);
  78. $baseInfo = $req->userInfo->game->baseInfo;
  79. $costNum = $dic->price * $num;
  80. my_Assert($baseInfo->cash == $costNum, ErrCode::notenough_cash_msg);
  81. $baseInfo->Consume_Cash($costNum);
  82. StoreProc::AddMultiItemInStore($costId.','.$num);
  83. UserProc::updateUserInfo();
  84. return Resp::ok(array(# # 返回值
  85. 'cash' => $baseInfo->cash,
  86. 'store' => $req->userInfo->game->store,
  87. ));
  88. }
  89. /**
  90. * 神庙抽奖
  91. */
  92. static function ShenmiaoDrawPrize() {
  93. $req = req();
  94. list($type,$num) = $req->paras;
  95. $shenmiaoInfo = $req->userInfo->game->shenmiao;
  96. my_Assert(StlUtil::dictHasProperty($shenmiaoInfo->activeDic, $type), ErrCode::active_activeNoExistent);
  97. $list = array();
  98. if(Enum_Active::NewWish == $type){
  99. my_Assert($shenmiaoInfo->activeDic->$type->num < glc()->UserWishNumLimit, ErrCode::active_NewUserActiveNumLimit);
  100. my_Assert($num == 10, ErrCode::active_NewUserActiveNumLimit);
  101. $shenmiaoInfo->activeDic->$type->num += $num;
  102. $shenmiaoInfo->activeDic->$type->totalNum += $num;
  103. $shenmo = GameConfig::shenmiao_getItem($shenmiaoInfo->activeDic->$type->id);
  104. self::cost($req, $shenmo,$num);
  105. $tag = false;
  106. $n = 0;
  107. for ($index = 0; $index < $num; $index++) {
  108. $n+=1;
  109. $itemType = self::activeRandom($shenmo->per, $shenmo);
  110. if($itemType >= 2){
  111. $tag = true;
  112. }
  113. if($n==10 && $tag == false && $shenmiaoInfo->activeDic->$type->totalNum > 10){
  114. $list[] =self::getActiveRandomItem(Enum_ActiveItemType::Ssr, $shenmo);//self::randSsrUr($shenmo->per)
  115. } else {
  116. if($shenmiaoInfo->activeDic->$type->totalNum <= 10){
  117. $itemType = Enum_ActiveItemType::Sr;
  118. }
  119. $nId =self::getActiveRandomItem($itemType, $shenmo);
  120. $list[] = $nId;
  121. }
  122. }
  123. if($shenmiaoInfo->activeDic->$type->totalNum == 10 && !in_array($shenmo->must, $list)){//首次10连抽有必出--临时
  124. $list[0] = $shenmo->must;
  125. }
  126. if($shenmiaoInfo->activeDic->$type->totalNum >= glc()->UserWishNumLimit){
  127. $shenmiaoInfo->isComNewWish = 1;
  128. StlUtil::dictRemove($shenmiaoInfo->activeDic, $type);
  129. }
  130. } else if(Enum_Active::OpenWish == $type){
  131. $shenmo = GameConfig::shenmiao_getItem($shenmiaoInfo->activeDic->$type->id);
  132. if($num == 1){
  133. $shenmiaoInfo->activeDic->$type->num += $num;
  134. self::cost($req, $shenmo);
  135. $list[] = self::drawOneLottery($shenmo, $type);
  136. } else {//10连抽
  137. self::cost($req, $shenmo,$num);
  138. $shenmiaoInfo->activeDic->$type->totalNum += $num;
  139. $list = self::drawTenLottery($shenmo, $type, $num);
  140. }
  141. } else {//不定期活动
  142. $shenmo = GameConfig::shenmiao_getItem($shenmiaoInfo->activeDic->$type->id);
  143. if($num == 1){
  144. self::cost($req, $shenmo,$num);
  145. $shenmiaoInfo->activeDic->$type->num += $num;
  146. $list[] = self::drawOneLottery($shenmo, $type);
  147. } else {
  148. self::cost($req, $shenmo,$num);
  149. $shenmiaoInfo->activeDic->$type->totalNum += $num;
  150. $list = self::drawTenLottery($shenmo, $type, $num);
  151. }
  152. }
  153. foreach ($list as $id) {
  154. $s = $id.',1';
  155. StoreProc::AddMultiItemInStore($s);
  156. }
  157. $req->userInfo->game->shenmiao = $shenmiaoInfo;
  158. UserProc::updateUserInfo();
  159. return Resp::ok(array(# # 返回值
  160. 'shenmiaoInfo' => $shenmiaoInfo,
  161. 'list'=>$list,
  162. 'store'=>$req->userInfo->game->store,
  163. ));
  164. }
  165. /**
  166. * 1连抽
  167. * @param type $shenmo
  168. * @param type $type
  169. * @param type $num
  170. * @return type
  171. */
  172. public static function drawOneLottery($shenmo,$type){
  173. $req = req();
  174. $shenmiaoInfo = $req->userInfo->game->shenmiao;
  175. $itemType = self::activeRandom($shenmo->per, $shenmo);
  176. if($type == Enum_Active::OpenWish){
  177. $aid =self::getActiveRandomItem($itemType, $shenmo);
  178. } else {
  179. $aid =self::getActiveRandomItem_3($itemType, $shenmo,$type);//随机出的id
  180. }
  181. if($shenmiaoInfo->activeDic->$type->num % glc()->Active_UR_Num == 0 && $itemType != Enum_ActiveItemType::Ur){
  182. if($type == Enum_Active::OpenWish){
  183. $aid =self::getActiveRandomItem(Enum_ActiveItemType::Ur, $shenmo);
  184. } else {
  185. $aid =self::getActiveRandomItem_3(Enum_ActiveItemType::Ur, $shenmo,$type);
  186. }
  187. }
  188. return $aid;
  189. }
  190. /**
  191. * 10连抽
  192. * @param type $type
  193. * @param type $num
  194. */
  195. public static function drawTenLottery($shenmo,$type,$num){
  196. $req = req();
  197. $shenmiaoInfo = $req->userInfo->game->shenmiao;
  198. $tag = false;
  199. $n = 0;
  200. $list = array();
  201. for ($index1 = 0; $index1 < $num; $index1++) {
  202. $n+=1;
  203. $itemType = self::activeRandom($shenmo->per, $shenmo);
  204. if($itemType >= 2){
  205. $tag = true;
  206. }
  207. if($n==10 && $tag == false){
  208. if($type == Enum_Active::OpenWish){
  209. $list[] =self::getActiveRandomItem(Enum_ActiveItemType::Ssr, $shenmo);//self::randSsrUr($shenmo->per)
  210. } else {
  211. $list[] =self::getActiveRandomItem_3(Enum_ActiveItemType::Ssr, $shenmo,$type);
  212. }
  213. } else {
  214. if($type == Enum_Active::OpenWish){
  215. $list[] =self::getActiveRandomItem($itemType, $shenmo);
  216. } else {
  217. $list[] =self::getActiveRandomItem_3($itemType, $shenmo,$type);
  218. }
  219. }
  220. }
  221. if($shenmiaoInfo->activeDic->$type->totalNum >= glc()->Active_UR_Num){//第90次必得
  222. if($type == Enum_Active::OpenWish){
  223. $aid =self::getActiveRandomItem(Enum_ActiveItemType::Ur, $shenmo);
  224. } else {
  225. $aid =self::getActiveRandomItem_3(Enum_ActiveItemType::Ur, $shenmo,$type);
  226. }
  227. $list[0] = $aid;
  228. $shenmiaoInfo->activeDic->$type->totalNum = 0;
  229. }
  230. return $list;
  231. }
  232. public static function prizeTypeRand($str) {
  233. if(strpos($str,';')){//包含;说明里面奖品类型不同获得的概率不同
  234. $sList = explode(';',$str);
  235. $dic= new \stdClass();
  236. $rand = rand(1,100);
  237. $start = 0;
  238. $end = 0;
  239. foreach ($sList as $val) {
  240. $itemList = explode('-', $val);
  241. $end = $itemList[1] + $start;
  242. if($rand > $start && $rand <= $end){
  243. $id = self::randList(explode(',', $itemList[0]));
  244. break;
  245. }
  246. $start = $end;
  247. }
  248. } else {
  249. $id = self::randList(explode(',',$str));
  250. }
  251. return $id;
  252. }
  253. /**
  254. * 抽奖消耗
  255. */
  256. public static function cost($req,$shenmo,$num = 1) {
  257. $sList = explode(',', $shenmo->cost);
  258. $costVal = $sList[1]*$num;
  259. if($shenmo->discount != 0){
  260. $costVal = $sList[1]*$num*$shenmo->discount/100;
  261. }
  262. StoreProc::removeItemFromStore($req->userInfo->game->store,$sList[0],$costVal);
  263. }
  264. /**
  265. *
  266. * @param type $randCtx
  267. * @param sm_shenmiao $mo
  268. * @return int
  269. */
  270. public static function activeRandom($randCtx,$mo) {
  271. $rand = rand(1,10000);
  272. $type = 1;
  273. $list = explode(',', $randCtx);
  274. $start = 0;
  275. foreach ($list as $val) {
  276. $end = $val + $start;
  277. if($rand > $start && $rand <= $end){
  278. break;
  279. }
  280. $type += 1;
  281. $start = $end;
  282. }
  283. return $type;
  284. }
  285. /**
  286. *
  287. * @param type $arr
  288. * @return type
  289. */
  290. public static function randList($arr) {
  291. $rand = rand(0, count($arr)-1);
  292. return $arr[$rand];
  293. }
  294. /**
  295. *
  296. * @param type $type
  297. * @param type $mo
  298. * @return type
  299. */
  300. public static function getActiveRandomItem($type,$mo) {
  301. $id = 0;
  302. switch ($type) {
  303. case Enum_ActiveItemType::Sr:
  304. $id = self::prizeTypeRand($mo->srList);
  305. //$id = self::randList(explode(',', $mo->srList));
  306. break;
  307. case Enum_ActiveItemType::Ssr:
  308. $id = self::prizeTypeRand($mo->ssrList);
  309. //$id = self::randList(explode(',', $mo->ssrList));
  310. break;
  311. case Enum_ActiveItemType::Ur:
  312. $id = self::prizeTypeRand($mo->urList);
  313. //$id = self::randList(explode(',', $mo->urList));
  314. break;
  315. default:
  316. break;
  317. }
  318. return $id;
  319. }
  320. /**
  321. *
  322. * @param type $type
  323. * @param sm_shenmiao $mo
  324. * @return type
  325. */
  326. public static function getActiveRandomItem_3($type,$mo,$activeType) {
  327. $shenmiaoInfo = req()->userInfo->game->shenmiao;
  328. $id = 0;
  329. switch ($type) {
  330. case Enum_ActiveItemType::Sr:
  331. $id = self::prizeTypeRand($mo->srList);
  332. //$id = self::randList(explode(',', $mo->srList));
  333. break;
  334. case Enum_ActiveItemType::Ssr:
  335. if($mo->ssrUp != null){
  336. $dic = new \stdClass();
  337. $ssrList = explode(';', $mo->ssrUp);
  338. $tNum = 0;
  339. foreach ($ssrList as $val) {
  340. $sList = explode(',', $val);
  341. $sid = $sList[0];
  342. $dic->$sid = $sList[1];
  343. $tNum += $sList[1];
  344. }
  345. if($shenmiaoInfo->activeDic->$activeType->isUpSsr == 1){
  346. $rand = rand(1,$tNum);
  347. $start = 0;
  348. foreach ($dic as $k=>$val) {
  349. $end = $val + $start;
  350. if($rand > $start && $rand <= $end){//随机到Up得id
  351. $id = $k;
  352. break;
  353. }
  354. $start = $end;
  355. }
  356. $shenmiaoInfo->activeDic->$activeType->isUpSsr = 0;
  357. } else {
  358. $rand = rand(1,10000);
  359. $start = 0;
  360. $sNum = 0;
  361. $count = StlUtil::count($dic);
  362. foreach ($dic as $k=>$val) {
  363. $sNum += 1;
  364. $end = $val + $start;
  365. if($rand > $start && $rand <= $end){//随机到Up得id
  366. $id = $k;
  367. break;
  368. }
  369. if($sNum >= $count){ //随机到普通的id
  370. $shenmiaoInfo->activeDic->$activeType->isUpSsr = 1;
  371. $id =self::prizeTypeRand($mo->ssrList);
  372. //$id = self::randList(explode(',', $mo->ssrList));
  373. break;
  374. }
  375. $start = $end;
  376. }
  377. }
  378. } else {
  379. $id =self::prizeTypeRand($mo->ssrList);
  380. //$id = self::randList(explode(',', $mo->ssrList));
  381. }
  382. break;
  383. case Enum_ActiveItemType::Ur:
  384. if($mo->ssrUp != null){
  385. $dic = new \stdClass();
  386. $urList = explode(';', $mo->urUp);
  387. $tNum = 0;
  388. foreach ($urList as $val) {
  389. $sList = explode(',', $val);
  390. $sid = $sList[0];
  391. $dic->$sid = $sList[1];
  392. $tNum += $sList[1];
  393. }
  394. if($shenmiaoInfo->activeDic->$activeType->isUpUr == 1){
  395. $rand = rand(1,$tNum);
  396. $start = 0;
  397. foreach ($dic as $k=>$val) {
  398. $end = $val + $start;
  399. if($rand > $start && $rand <= $end){//随机到Up得id
  400. $id = $k;
  401. break;
  402. }
  403. $start = $end;
  404. }
  405. $shenmiaoInfo->activeDic->$activeType->$isUpUr = 0;
  406. } else {
  407. $rand = rand(1,10000);
  408. $start = 0;
  409. $sNum = 0;
  410. $count = StlUtil::count($dic);
  411. foreach ($dic as $k=>$val) {
  412. $sNum += 1;
  413. $end = $val + $start;
  414. if($rand > $start && $rand <= $end){
  415. $id = $k;
  416. break;
  417. }
  418. if($sNum >= $count){
  419. $shenmiaoInfo->activeDic->$activeType->isUpUr = 1;
  420. $id =self::prizeTypeRand($mo->urList);
  421. //$id = self::randList(explode(',', $mo->urList));
  422. break;
  423. }
  424. $start = $end;
  425. }
  426. }
  427. } else {
  428. //$id = self::randList(explode(',', $mo->urList));
  429. $id =self::prizeTypeRand($mo->urList);
  430. }
  431. break;
  432. default:
  433. break;
  434. }
  435. return $id;
  436. }
  437. /**
  438. * 从SSr 和 uR中得一个
  439. * @param type $param
  440. */
  441. public static function randSsrUr($randCtx) {
  442. $list = explode(',', $randCtx);
  443. $list = array_splice($list,1);
  444. $total = $list[0]+$list[1];
  445. $rand = rand(1,$total);
  446. $start = 0;
  447. //$type = Enum_ActiveItemType::Ssr;
  448. $type = 2;
  449. foreach ($list as $val) {
  450. $end = $val + $start;
  451. if($rand > $start && $rand <= $end){
  452. break;
  453. }
  454. $type += 1;
  455. $start = $end;
  456. }
  457. return $type;
  458. }
  459. /**
  460. * [6515] 领取 赠送体力
  461. */
  462. static function drawTiliGift() {
  463. $user = ctx();
  464. $privateState = ctx()->privateData();
  465. $base = $user->base();
  466. $hour = date('G');
  467. my_Assert(!in_array($hour, $privateState->dailyDrawedTiliGift), ErrCode::active_hasgetted); # 判断是否已领取
  468. $arr = explode(',', glc()->activity_presentTili_times); # 判断是否满足领取条件
  469. my_Assert(in_array($hour, $arr), ErrCode::active_illegal); # 不满足条件
  470. $base->Add_tili(glc()->activity_presentTili_number); # 增加体力
  471. $privateState->dailyDrawedTiliGift[] = $hour;
  472. UserProc::updateUserInfo(); # 回存
  473. return Resp::ok(array(# # 返回值
  474. 'key' => 'ok',
  475. 'record' => $privateState->dailyDrawedTiliGift,
  476. 'tili' => $base->tili,
  477. 'time' => $user->privateState->TiliTime,
  478. ));
  479. }
  480. ////
  481. // </editor-fold>
  482. // <editor-fold defaultstate="collapsed" desc=" 全服注册礼包 ">
  483. /**
  484. * [6516] 查询当前全服注册人数
  485. */
  486. static function getRegNumber() {
  487. return Resp::ok(array(
  488. 'num' => gMem()->get(MemKey_GameRun::Stat_UserCountByZone_int(req()->zoneid))
  489. ));
  490. }
  491. /**
  492. * [6514] 领取全服注册礼包
  493. */
  494. static function drawRegGift() {
  495. $user = new Data_UserGame(req()->userInfo->game);
  496. $privateState = new Info_PrivateState($user->privateState);
  497. $giftId = req()->paras[0]; # 礼包id
  498. $giftModel = GameConfig::activity_reggift_getItem($giftId); # 取礼包常亮数据
  499. if (null == $giftModel) {
  500. return Resp::err(ErrCode::err_const_no);
  501. }
  502. if (in_array($giftId, $privateState->drawedRegGift)) { # 判断是否已领取
  503. return Resp::err(ErrCode::active_hasgetted);
  504. }
  505. // 判断是否满足领取条件
  506. if (gMem()->get(MemKey_GameRun::Stat_UserCountByZone_int(req()->zoneid)) < $giftModel->regNumber) {
  507. return Resp::err(ErrCode::active_illegal); # 不满足条件
  508. }
  509. $err = StoreProc::AddMultiItemInStore($giftModel->rewardstr); # 发放奖励
  510. if ($err) {
  511. return Resp::err($err); # 失败
  512. }
  513. $privateState->drawedRegGift[] = $giftId;
  514. $user->privateState = $privateState;
  515. req()->userInfo->game = $user;
  516. UserProc::updateUserInfo(); # 回存
  517. return Resp::ok(array(# # 返回值
  518. 'key' => 'ok',
  519. 'store' => $user->store
  520. ));
  521. }
  522. // </editor-fold>
  523. // <editor-fold defaultstate="collapsed" desc=" 在线礼包 ">
  524. /**
  525. * 【6504】查询当天在线时长信息
  526. */
  527. static function getTotayOnlineInfos() {
  528. return Resp::ok(array(
  529. "onlineGiftIDs" => req()->userInfo->game->privateState->onlineGiftIDs,
  530. "onlineGiftts" => req()->userInfo->game->privateState->onlineGiftts
  531. ));
  532. }
  533. /**
  534. * [6513] 领取连续在线礼包
  535. */
  536. static function drawOnlineGift() {
  537. $giftid = req()->paras[0]; # 提取参数: 礼包的编号
  538. $user = ctx();
  539. $privateState = ctx()->privateData();
  540. $giftData = GameConfig::activity_onlinegift_getItem($giftid); # 在线礼包常量数据
  541. my_Assert(null != $giftData, ErrCode::onlinegift_constno_err); # 防御找不到配置数据
  542. my_Assert($privateState->onlineGiftts >= $giftData->onlineSec, # # 时间未到,不可以领取
  543. ErrCode::onlinegift_timenotenough);
  544. my_default_Arr($privateState->onlineGiftIDs); # 防御未初始化领取记录
  545. my_Assert(!in_array($giftid, $privateState->onlineGiftIDs), # # 判断礼包ID是否已经领取
  546. ErrCode::active_hasgetted);
  547. $err = StoreProc::AddMultiItemInStore($giftData->rewardstr); # 发放奖励
  548. my_Assert(ErrCode::ok == $err, $err); # 发放奖励失败
  549. $privateState->onlineGiftIDs[] = $giftid; # 记录已领礼包ID
  550. UserProc::updateUserInfo(); # 回写用户数据
  551. return Resp::ok(array(
  552. 'onlineGiftts' => $privateState->onlineGiftts,
  553. 'onlineGiftIDs' => $privateState->onlineGiftIDs,
  554. "reward" => $giftData->rewardstr,
  555. 'gold' => $user->base()->gold,
  556. 'cash' => $user->base()->cash,
  557. 'tili' => $user->base()->tili,
  558. 'store' => $user->store(),
  559. 'hero' => $user->heros()
  560. )); # 设置返回值
  561. }
  562. /**
  563. * 清理/重置 在线礼包时间戳
  564. */
  565. static private function ClearOnlineGiftTs() {
  566. req()->userInfo->game->privateState->onlineGiftts = 0;
  567. req()->userInfo->game->privateState->onlineGiftIDs = array();
  568. }
  569. // </editor-fold>
  570. // <editor-fold defaultstate="collapsed" desc=" 兑换码 ">
  571. /**
  572. * [6512]凭兑换码领取礼包
  573. */
  574. static function drawActivePackageByCode() {
  575. $user = new Data_UserGame(req()->userInfo->game);
  576. $privateState = new Info_PrivateState($user->privateState); # 快速访问
  577. list( $activeId, $codestring) = req()->paras; # 取参数 活动id, 兑换码
  578. $active = GameConfig::activity_getItem($activeId); # 活动数据
  579. my_Assert(null != $active, ErrCode::active_const_no_err);
  580. my_Assert($active->startts <= now() && $active->endts >= now(), ErrCode::active_time); # 校验开放时间
  581. my_Assert(preg_match("/^[a-kmnp-z2-9]{10}$/", $codestring), ErrCode::active_activecode_format); # 基础格式校验(10个特定字符)
  582. $activeCode = CipheredBase32::Decode($codestring); # 解码
  583. $codePlatStr = GameConstants::GetPlatStringByActivteCode($activeCode); # platstr
  584. my_Assert(GameConstants::AllPlatStr == $codePlatStr # # 忽略全平台礼包
  585. || req()->userInfo->getPlatStr() == $codePlatStr, # # 平台字符串必须相符
  586. ErrCode::active_activecode_plat); # # 平台错误
  587. my_Assert(is_int($activeCode->number) # # 编号为int值
  588. && $activeCode->number >= 1 && $activeCode->number <= 50000, # # 检查 兑换码的编号范围0~50000
  589. ErrCode::active_activecode_format);
  590. $packageID = $activeCode->package; # 礼包id
  591. $packageInfo = GameConfig::tokenGift_getItem($packageID); # 礼包常量数据
  592. my_Assert(null != $packageInfo, ErrCode::err_const_no); # 防御
  593. my_Assert($packageInfo->expirets >= now() && $packageInfo->startTs <= now(),
  594. ErrCode::active_activecode_outtime); # 激活码已经失效,或者礼包尚未开启
  595. my_Assert(!in_array($packageID, $privateState->usedTokens), ErrCode::active_hasgetted); # 已经领取过该礼包了
  596. my_Assert(!self::checkActiveCodeIsUsed($activeCode), ErrCode::active_activecode_used); # 检查 该激活码是否已经使用过了
  597. $err = StoreProc::AddMultiItemInStore($packageInfo->reward); # 发放礼包
  598. my_Assert(ErrCode::ok == $err, $err); # 防御发放礼包过程出错
  599. req()->userInfo->game->privateState->usedTokens[] = $packageID; # 记录领取记录
  600. $ok = self::setActiveCodeUserRecord($activeCode, req()->uid); # 插入数据库
  601. my_Assert($ok, ErrCode::err_db); # 数据库操作失败- 重试
  602. UserProc::updateUserInfo(); # 回存玩家数据
  603. $ret = array(# # 返回值
  604. "plat" => $codePlatStr,
  605. "packageId" => $activeCode->package,
  606. "reward" => $packageInfo->reward,
  607. 'gold' => $user->base()->gold,
  608. 'cash' => $user->base()->cash,
  609. 'tili' => $user->base()->tili,
  610. 'store' => $user->store,
  611. 'hero' => $user->heros
  612. );
  613. return Resp::ok($ret); # 返回成功信息
  614. }
  615. /**
  616. * 检查兑换码是否已经使用过了
  617. * @param ActiveCode $activeCode
  618. * @return boolean true : 已经用过了, false : 激活码尚未使用过.
  619. */
  620. static function checkActiveCodeIsUsed($activeCode) {
  621. $sql = sprintf("`plat`='%d' and `package`='%d' and `number`='%d'", # # where 子句
  622. $activeCode->plat, $activeCode->package, $activeCode->number);
  623. $rows = daoInst()
  624. ->select()
  625. ->from(self::tab_toke_gift) # 表名
  626. ->where($sql)
  627. ->count();
  628. return $rows > 0;
  629. }
  630. /**
  631. * 将兑换码添加到使用记录中
  632. * @param ActiveCode $actvieCode
  633. * @param string $uid
  634. * @return boolean true: 操作成功, false: 操作失败
  635. */
  636. static function setActiveCodeUserRecord($actvieCode, $uid) {
  637. $actvieCode->uid = $uid; # 添加uid
  638. $ret = daoInst()
  639. ->insert(self::tab_toke_gift) # 表名
  640. ->data($actvieCode)
  641. ->exec();
  642. return $ret > 0;
  643. }
  644. // </editor-fold>
  645. /**
  646. * [6503] 查询当前分区开放时间戳
  647. */
  648. private static function GetZonePublicTS() {
  649. $zoneInfo = GameConfig::zonelist_getItem(req()->zoneid);
  650. return Resp::ok($zoneInfo->publicTs);
  651. }
  652. // <editor-fold defaultstate="collapsed" desc=" 体力 ">
  653. /**
  654. * [6508]
  655. */
  656. public static function RecoveryTili() {
  657. $useTili = req()->paras[0];
  658. ActiveProc::ChangeTili($useTili);
  659. UserProc::updateUserInfo();
  660. $result = array(
  661. 'time' => req()->userInfo->game->privateState->TiliTime,
  662. 'tili' => req()->userInfo->game->baseInfo->tili
  663. );
  664. $resp = Resp::ok($result);
  665. return $resp;
  666. }
  667. /**
  668. * 清理每天的赠送体力领取记录
  669. */
  670. private static function ClearDailyTiliGift() {
  671. req()->userInfo->game->privateState->dailyDrawedTiliGift = ArrayInit();
  672. }
  673. /**
  674. * 修改玩家体力
  675. * @param int $useTili $useTili>0代表增加体力, $useTili<0代表消耗体力
  676. */
  677. public static function ChangeTili($useTili) {
  678. $user = req()->userInfo->game;
  679. $moreTili = 0; # 超上限的体力值
  680. // 如果没有tilitime这个值,说明是以前老用户新登录的,为了纠错在判断里面补值.(正常用户不会进入判断内部)
  681. if (!CommUtil::isPropertyExists($user->privateState, "TiliTime")) {
  682. $user->privateState->TiliTime = time() - 120;
  683. }
  684. if ($user->baseInfo->tili > 120) { # 如果该账户体力值本身是大于上限的,获取一下超出的体力值
  685. $moreTili = $user->baseInfo->tili - 120; # 用moreTili保存一下额外的体力值
  686. }
  687. $useTime = time() - $user->privateState->TiliTime; # 距离上次修改体力值的时间
  688. if ($useTime > 300) { # 该账户超过了单位体力时间,需要重新计算体力值
  689. if ($moreTili <= 0) {
  690. $user->baseInfo->tili += (int) ( (int) ($useTime / 300));
  691. if ($user->baseInfo->tili > 120) { # 体力值上限
  692. $user->baseInfo->tili = 120;
  693. } // 这代码真烂,以后用的时候再修复吧... -gwang 20200110154858
  694. }
  695. $user->privateState->TiliTime = time();
  696. }
  697. if ($useTili < 0) { # 如果是消耗体力
  698. my_Assert(abs($useTili) < $user->baseInfo->tili, ErrCode::notenough_tili); # 体力不足
  699. $user->baseInfo->tili += $useTili; # 扣除体力
  700. } else if ($useTili > 0) { # 如果是购买增加体力
  701. $user->baseInfo->tili += $useTili;
  702. }
  703. return ErrCode::ok;
  704. }
  705. // </editor-fold>
  706. //
  707. //
  708. // <editor-fold defaultstate="collapsed" desc=" 7日签到 ">
  709. /**
  710. * 重置7日签到相关计数器
  711. */
  712. static function DailyResetDay7Task() {
  713. req()->userInfo->game->gates->Times = 0;
  714. $typeID = 6; # 7日活动
  715. $ac = GameConfig::activity_getItem($typeID);
  716. my_Assert(null != $ac, ErrCode::err_const_no);
  717. $startDay = tsDay($ac->startts);
  718. $newLoginDays = array_filter(req()->userInfo->game->privateState->LoginDays, # 剔除不符合时间的登录记录
  719. function ($tsday)use ($startDay) {
  720. return $startDay <= $tsday;
  721. }
  722. );
  723. req()->userInfo->game->privateState->LoginDays = $newLoginDays; #
  724. if (count(req()->userInfo->game->privateState->LoginDays) < 7) {
  725. req()->userInfo->game->privateState->LoginDays[] = tsDay();
  726. }
  727. }
  728. /**
  729. * [6502] 领取七日签到奖励
  730. */
  731. static function Day7_DrawReward() {
  732. // 设计7日数据结构
  733. list($day) = req()->paras; # 参数: 领取第x天的奖励
  734. $user = req()->userInfo->game;
  735. $private = new Info_PrivateState($user->privateState); # 私有数据
  736. my_Assert(count($private->LoginDays) >= $day, ErrCode::active_day7_totaldays);
  737. my_Assert(!in_array($day, $private->day7_drawed), ErrCode::active_hasgetted);
  738. $day_rwd = GameConfig::activity_day7_getItem($day); # 查询奖励数据
  739. my_Assert(null != $day_rwd, ErrCode::err_const_no); # 防御找不到配置
  740. StoreProc::AddMultiItemInStore($day_rwd->reward); # 发放奖励
  741. $private->day7_drawed[] = $day; # 添加领取记录
  742. $user->privateState = $private; # 更新数据
  743. UserProc::updateUserInfo(); # 回存
  744. return Resp::ok(array(
  745. 'gold' => $user->baseInfo->gold,
  746. 'cash' => $user->baseInfo->cash,
  747. 'tili' => $user->baseInfo->tili,
  748. 'store' => $user->store,
  749. 'hero' => $user->heros
  750. )); # 返回值
  751. }
  752. // </editor-fold>
  753. //
  754. }