ActiveProc.php 34 KB

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