128 lines
3.4 KiB
TypeScript
128 lines
3.4 KiB
TypeScript
|
// 彩票管理器
|
||
|
|
||
|
import GameUtil from "./GameUtil";
|
||
|
import LotteryBox from "./LotteryBox";
|
||
|
import DB from "../utils/DB";
|
||
|
import {MsgCode} from "../role/EEnum";
|
||
|
|
||
|
export default class LotteryMgr {
|
||
|
static shared=new LotteryMgr();
|
||
|
vecItem:any[];
|
||
|
superItem:any[];
|
||
|
mapLotteryBox:any;
|
||
|
maxId:number;
|
||
|
|
||
|
constructor() {
|
||
|
this.vecItem = [];
|
||
|
this.superItem = [];
|
||
|
this.mapLotteryBox = {};
|
||
|
this.maxId = 0;
|
||
|
}
|
||
|
|
||
|
init() {
|
||
|
this.vecItem = [];
|
||
|
DB.selectLotteryData((code: any, info: any) => {
|
||
|
if (MsgCode.SUCCESS == code){
|
||
|
for (const data of info) {
|
||
|
this.vecItem.push({
|
||
|
"id": data.id,
|
||
|
"strItem": data.item,
|
||
|
"Column2": data.name,
|
||
|
"nNum": data.num,
|
||
|
"nRate": data.rate
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
DB.selectLotterySuperData((code: any, info: any) => {
|
||
|
if (MsgCode.SUCCESS == code){
|
||
|
for (const data of info) {
|
||
|
this.superItem.push({
|
||
|
"id": data.id,
|
||
|
"strItem": data.item,
|
||
|
"Column2": data.name,
|
||
|
"nNum": data.num,
|
||
|
"nRate": data.rate
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
|
||
|
CreateLotteryBox() {
|
||
|
this.maxId += 1;
|
||
|
if(this.maxId > 3000){
|
||
|
this.maxId = 0;
|
||
|
}
|
||
|
this.mapLotteryBox[this.maxId] = new LotteryBox(this.maxId, GameUtil.getTime(), this.RandSubItemList());
|
||
|
return this.mapLotteryBox[this.maxId].ToJson();
|
||
|
}
|
||
|
|
||
|
RandSubItemList() {
|
||
|
let vecTmp = this.vecItem.slice(0);
|
||
|
let vecSub = [];
|
||
|
for (let i = 0; i < 15; i++) {
|
||
|
if (vecTmp.length <= 0)
|
||
|
break;
|
||
|
|
||
|
let nIndex = GameUtil.random(0, vecTmp.length - 1);
|
||
|
vecSub.push(vecTmp[nIndex]);
|
||
|
vecTmp.splice(nIndex, 1);
|
||
|
}
|
||
|
|
||
|
return vecSub;
|
||
|
}
|
||
|
|
||
|
CreateLotterySuperBox() {
|
||
|
this.maxId += 1;
|
||
|
if(this.maxId > 3000){
|
||
|
this.maxId = 0;
|
||
|
}
|
||
|
this.mapLotteryBox[this.maxId] = new LotteryBox(this.maxId, GameUtil.getTime(), this.RandSuperSubItemList());
|
||
|
return this.mapLotteryBox[this.maxId].ToJson();
|
||
|
}
|
||
|
|
||
|
RandSuperSubItemList() {
|
||
|
let superTmp = this.superItem.slice(0);
|
||
|
let superSub = [];
|
||
|
for (let i = 0; i < 15; i++) {
|
||
|
if (superTmp.length <= 0)
|
||
|
break;
|
||
|
let nIndex = GameUtil.random(0, superTmp.length - 1);
|
||
|
superSub.push(superTmp[nIndex]);
|
||
|
superTmp.splice(nIndex, 1);
|
||
|
}
|
||
|
|
||
|
return superSub;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
CheckAndDeleteLotteryBox() {
|
||
|
let nCurTime = GameUtil.getTime();
|
||
|
|
||
|
for (var it in this.mapLotteryBox) {
|
||
|
if (nCurTime - this.mapLotteryBox[it].nCreateTime > 600) {
|
||
|
delete this.mapLotteryBox[it];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
update(dt:number){
|
||
|
if(dt % (1000 * 10) == 0){
|
||
|
this.CheckAndDeleteLotteryBox();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
GetBox(nID:any) {
|
||
|
if (this.mapLotteryBox.hasOwnProperty(nID) == false)
|
||
|
return null;
|
||
|
|
||
|
return this.mapLotteryBox[nID];
|
||
|
}
|
||
|
|
||
|
DeleteBox(nID:any) {
|
||
|
delete this.mapLotteryBox[nID];
|
||
|
}
|
||
|
}
|