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

287 lines
10 KiB
TypeScript

// 幸运转盘
import DB from "../utils/DB";
import {MsgCode} from "../role/EEnum";
import GameUtil from "../core/GameUtil";
import SKDataUtil from "../gear/SKDataUtil";
import SKLogger from "../gear/SKLogger";
import PlayerMgr from "../object/PlayerMgr";
import GTimer from "../common/GTimer";
import GameConf from "../../conf/GameConf";
export default class DialMgr {
static shared = new DialMgr();
// 转盘数据
vecItem: any[];
// 风雨宝箱数据
boxItem: any[];
// 单次消耗玉
jade_one: number;
// 五次消耗玉
jade_five: number;
// 凰羽
item_id: number;
// 五次抽奖总消耗
five: number;
// 模式二消耗道具
goods_id: number;
constructor() {
this.vecItem = [];
this.boxItem = [];
this.five = 4800;
this.jade_one = 1000;
this.jade_five = 960;
this.item_id = 50017;
this.goods_id = 50019;
}
init() {
this.vecItem = [];
this.boxItem = [];
DB.selectDialData((code: any, info: any) => {
if (MsgCode.SUCCESS == code) {
for (const data of info) {
if (data.flag == 0) {
this.vecItem.push({
"itemId": data.item_id,
"itemName": data.item_name,
"type": data.type,
"num": data.num,
"flag": data.flag,
"rate": data.rate
});
} else {
this.boxItem.push({
"itemId": data.item_id,
"itemName": data.item_name,
"type": data.type,
"num": data.num,
"flag": data.flag,
"rate": data.rate
});
}
}
}
});
}
// 获取风雨转盘数据
CreateDial(player: any, type: any, genre: number) {
let jade: number = this.jade_one;
// 单次
let one = this.jade_one;
// 五次
let five = this.five;
// 如果模式为道具则获取当前角色的道具
if(GameConf.model != 2) {
// 判断消耗品
if (genre == 1) {
if (player.dial_num == 0) {
player.send_notice("您的免费次数已用完!");
return;
} else {
player.dial_num -= 1;
jade = 0;
player.dial_date = GTimer.getYearMonthDay();
}
} else {
// 单抽
if (genre == 2) {
if (player.jade < this.jade_one) {
player.send_notice("您的仙玉不足,请先补充仙玉再来吧少侠!");
return;
}
} else if (genre == 3) { // 五连抽
if (player.jade < this.jade_five) {
player.send_notice("您的仙玉不足,请先补充仙玉再来吧少侠!");
return;
}
jade = this.jade_five;
}
}
}else {
one = player.getBagItemNum(this.goods_id);
five = player.getBagItemNum(this.goods_id);
// 单抽
if (genre == 2) {
if (one < 1) {
player.send_notice("您的凤羽不足,请先补充凤羽再来吧少侠!");
player.send('s2c_dial_info', {
one: one,
five: five,
dialData: "",
model: GameConf.model,
dialNum: player.dial_num,
dialCount: player.dial_count,
dialBoxNum: player.getBagItemNum(this.item_id),
});
return;
}
}
}
// 判断背包是否已满
if (player.getBagItemAllKindNum() + 1 >= player.bagKindNum) {
player.send_notice("背包已满,无法抽奖!");
player.send('s2c_dial_info', {
one: one,
five: five,
dialData: "",
model: GameConf.model,
dialNum: player.dial_num,
dialCount: player.dial_count,
dialBoxNum: player.getBagItemNum(this.item_id),
});
SKLogger.debug(`玩家[${player.roleid}:${player.name}]背包已满,无法抽奖!`);
}
// 获取本次风雨转盘数据
let value: any = {};
let elements = GameUtil.getRandomArrayElements(this.vecItem, 8);
for (const element of elements) {
value[this.vecItem.indexOf(element)] = element;
}
player.dial_count += 1;
if (player.dial_count >= 150) {
player.dial_count = 0;
// 发送风雨宝箱钥匙
player.addItem(this.item_id, 1, false, "凰羽");
}
// 如果模式为道具则获取当前角色的道具
if(GameConf.model != 2) {
// 仙玉模式扣除仙玉
player.addMoney(GameUtil.goldKind.Jade, -jade, '风雨同舟', MsgCode.FAILED);
}else {
// 道具模式扣除道具
player.addItem(this.goods_id, -1, false, "凤羽");
one = player.getBagItemNum(this.goods_id);
five = player.getBagItemNum(this.goods_id);
}
// 数据发送前端
player.send('s2c_dial_info', {
one: one,
five: five,
dialData: SKDataUtil.toJson(value, "{}"),
dialNum: player.dial_num,
dialCount: player.dial_count,
type: type,
model: GameConf.model,
dialBoxNum: player.getBagItemNum(this.item_id),
});
}
// 获取宝箱数据
CreateDialBox(player: any, type: any) {
// 获取本次风雨宝箱数据
let value: any = {};
let elements = GameUtil.getRandomArrayElements(this.boxItem, this.boxItem.length);
for (const element of elements) {
value[this.boxItem.indexOf(element)] = element;
}
// 单次
let one = this.jade_one;
// 五次
let five = this.five;
// 如果模式为道具则获取当前角色的道具
if(GameConf.model == 2){
one = player.getBagItemNum(this.goods_id);
five = player.getBagItemNum(this.goods_id);
}
// 数据发送前端
player.send('s2c_dial_info', {
one: one,
five: five,
dialData: SKDataUtil.toJson(value, "{}"),
dialNum: player.dial_num,
dialCount: player.dial_count,
type: type,
model: GameConf.model,
dialBoxNum: player.getBagItemNum(this.item_id),
});
}
// 获取中奖数据
GetDial(player: any, id: any, type: any) {
// 单次
let one = this.jade_one;
// 五次
let five = this.five;
// 如果模式为道具则获取当前角色的道具
if(GameConf.model == 2){
one = player.getBagItemNum(this.goods_id);
five = player.getBagItemNum(this.goods_id);
}
// 转盘数据
if (type == 2) {
if (this.vecItem.hasOwnProperty(id) == false) {
player.send_notice("物品已失效");
player.send('s2c_dial_result', {
one: one,
five: five,
flag: MsgCode.FAILED,
type: type,
model: GameConf.model,
dialNum: player.dial_num,
dialCount: player.dial_count,
dialBoxNum: player.getBagItemNum(this.item_id),
});
return;
} else {
// 通知前端(掉落物品到背包)
player.send('s2c_dial_result', {
one: one,
five: five,
flag: MsgCode.SUCCESS,
type: type,
model: GameConf.model,
dialNum: player.dial_num,
dialCount: player.dial_count,
dialBoxNum: player.getBagItemNum(this.item_id),
});
// 发送物品给玩家
GameUtil.givePlayerPrize(player, this.vecItem[id].itemId, parseInt(this.vecItem[id].num), false);
}
}
// 宝箱数据
else {
if (this.boxItem.hasOwnProperty(id) == false) {
player.send_notice("物品已失效");
return;
}
if (player.getBagItemNum(this.item_id) <= 0){
player.send_notice("您背包没有凰羽");
return;
}
player.addItem(this.item_id, -1, false, "凰羽");
player.send('s2c_dial_result', {
one: one,
five:five,
flag: MsgCode.SUCCESS,
type: type,
model: GameConf.model,
dialNum: player.dial_num,
dialCount: player.dial_count,
dialBoxNum: player.getBagItemNum(this.item_id),
});
// 发送物品给玩家
GameUtil.givePlayerPrize(player, this.boxItem[id].itemId, parseInt(this.boxItem[id].num), false);
// 获得大奖通知世界
if (this.boxItem[id].type == 1){
let strRichText = `<color=#1ba5a6 >恭喜玩家</c ><color=#0096ff >${player.name}</c ><color=#1ba5a6 >在本期</c ><color=#009f3c >风雨同舟</c ><color=#1ba5a6 >宝箱中获得 </c ><color=#d780ff >${this.boxItem[id].itemName}</c ><color=#e8641b >x${this.boxItem[id].num}</c >`;
PlayerMgr.shared.broadcast('s2c_game_chat', {
msg: strRichText,
scale: 3
});
}
}
// 存档
player.saveDial();
}
}