ActiveProc.php 36 KB

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