ActiveProc.php 34 KB

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