ActiveProc.php 34 KB

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