ActiveProc.php 34 KB

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