ActiveProc.php 34 KB

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