xy-server/game/activity/OnlineRewards.ts
2025-04-23 09:34:08 +08:00

94 lines
3.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import PlayerMgr from "../object/PlayerMgr";
import SKDataUtil from "../gear/SKDataUtil";
import {MsgCode} from "../role/EEnum";
import * as schedule from "node-schedule";
import GameUtil from "../core/GameUtil";
import DB from "../utils/DB";
/**
* 在线奖励
*/
export default class OnlineRewards {
static shared = new OnlineRewards();
// 类型0 仙玉 1 绑定仙玉
type: number;
// 奖励最小仙玉
minJade: number;
// 奖励最大仙玉
maxJade: number;
// 大于等于当前仙玉 进行系统播报
middleJade: number;
// 活动状态1 开启 0 关闭)
state: number;
// 定时器
schedule_ac: any;
constructor() {
this.type = 1;
this.state = 0;
this.minJade = 13000;
this.maxJade = 30000;
this.middleJade = 25000;
this.schedule_ac = null;
}
init() {
DB.selectConfiguration("online_rewards",(code: any, info: any) => {
if (MsgCode.SUCCESS == code) {
let data = SKDataUtil.jsonBy(info.value_data);
this.type = data.type;
this.state = data.state;
this.minJade = data.minJade;
this.maxJade = data.maxJade;
this.middleJade = data.middleJade;
if (this.type == 1){
this.open();
}
}
});
}
/**
* 开启在线奖励
*/
open() {
// this.schedule_ac = schedule.scheduleJob("0 0/10 * * * ?", () => {
// let roleList = PlayerMgr.shared.player_role_list;
// for (let key in roleList) {
// let roleId = SKDataUtil.numberBy(key);
// let player = PlayerMgr.shared.getPlayerByRoleId(roleId);
// if (!player.isRobot()) {
// if (player){
// let jade: number = SKDataUtil.random(this.minJade, this.maxJade);
// if (this.type == 0) {
// player.addMoney(GameUtil.goldKind.Jade, jade, "获得在线奖励仙玉:" + jade)
// } else {
// player.addMoney(GameUtil.goldKind.BindJade, jade, "获得在线奖励绑定仙玉:" + jade)
// }
// }
// // if (jade >= this.middleJade){
// // let strRichText = `<color=#ea5b5c >恭喜玩家</c ><color=#00ff00 >${player.name}</c ><color=#ea5b5c >获得在线奖励:</c ><color=#3ce270 >${jade}</c >`;
// // PlayerMgr.shared.broadcast('s2c_game_chat', {
// // msg: strRichText,
// // scale: 3
// // });
// // }
// }
// }
// })
}
/**
* 关闭在线奖励
*/
close(){
if (this.schedule_ac != undefined && this.schedule_ac != null) {
this.schedule_ac.cancel();
}
}
}