479 lines
16 KiB
TypeScript
479 lines
16 KiB
TypeScript
import JInChan from "./JInChan";
|
|
import NpcMgr from "../core/NpcMgr";
|
|
import PlayerMgr from "../object/PlayerMgr";
|
|
import GTimer from "../common/GTimer";
|
|
import SKDataUtil from "../gear/SKDataUtil";
|
|
import Currency from "../activity/Currency";
|
|
import GameUtil from "../core/GameUtil";
|
|
import * as schedule from "node-schedule";
|
|
import SKLogger from "../gear/SKLogger";
|
|
import DB from "../utils/DB";
|
|
import {
|
|
BattleType,
|
|
EActionType,
|
|
EAttrCalType,
|
|
EAttrTypeL1,
|
|
EAttrTypeL2,
|
|
EEquipPos,
|
|
EEquipType,
|
|
EEventType,
|
|
ELiveingType,
|
|
ENpcCreater,
|
|
ERaceType,
|
|
ESexType,
|
|
ESkillType,
|
|
MsgCode,
|
|
Operate
|
|
} from "../role/EEnum";
|
|
import TeamMgr from "../core/TeamMgr";
|
|
import MonsterMgr from "../core/MonsterMgr";
|
|
export default class JIngChanSongFuMgr {
|
|
private static _shared: JIngChanSongFuMgr;
|
|
/**金蟾怪物列表 */
|
|
vecMonster: any[];
|
|
/**金蟾BOSS怪物列表 */
|
|
JingChanBosslist: any[];
|
|
/**变异金蟾列表 */
|
|
BianYiJIngChan: any[];
|
|
/**刷新时间 */
|
|
refresh_timer: any;
|
|
/**奖励列表 */
|
|
JiangLiList: any[];
|
|
/**限制击杀表 */
|
|
limtlist: any[];
|
|
logTime: any;
|
|
static get shared(): JIngChanSongFuMgr {
|
|
if (!this._shared) {
|
|
this._shared = new JIngChanSongFuMgr();
|
|
}
|
|
return this._shared;
|
|
}
|
|
constructor() {
|
|
this.limtlist = [];
|
|
this.vecMonster = [];
|
|
this.JingChanBosslist = [];
|
|
this.BianYiJIngChan = [];
|
|
this.refresh_timer = 0;
|
|
}
|
|
|
|
launch() {
|
|
let nCurTime = GameUtil.getTime();
|
|
let nDay = Math.floor(nCurTime / 86400);
|
|
let nHour = Math.floor(nCurTime / 3600);
|
|
this.logTime = {
|
|
nCurDay: nDay,
|
|
nCurHour: nHour,
|
|
}
|
|
this.onCreateWorldJInChan();
|
|
this.Jinchanjiangli();
|
|
|
|
}
|
|
|
|
OnNewDay() {
|
|
this.limtlist = [];
|
|
}
|
|
pushMoster() {
|
|
|
|
/**清理所有金蟾 */
|
|
if (this.vecMonster.length > 0) {
|
|
for (let it in this.vecMonster) {
|
|
let pWBomb = this.vecMonster[it];
|
|
NpcMgr.shared.DeleteNpc(pWBomb.nOnlyID);
|
|
|
|
}
|
|
this.vecMonster = [];
|
|
}
|
|
|
|
/**清理所有变异金蟾 */
|
|
// if (this.BianYiJIngChan.length > 0){
|
|
// for (let it in this.BianYiJIngChan) {
|
|
// let pWBomb = this.BianYiJIngChan[it];
|
|
// NpcMgr.shared.DeleteNpc(pWBomb.nOnlyID);
|
|
// }
|
|
// this.BianYiJIngChan = [];
|
|
// }
|
|
|
|
this.vecMonster.push(new JInChan(82041, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82042, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82043, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82044, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82045, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82046, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82047, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82048, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82049, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82050, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82051, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82052, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82053, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82054, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82055, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82056, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82057, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82058, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82059, 1212, 1, 8));
|
|
this.vecMonster.push(new JInChan(82060, 1212, 1, 8));
|
|
|
|
// 变异金蟾
|
|
this.vecMonster.push(new JInChan(82061, 1212, 3, 9));
|
|
this.vecMonster.push(new JInChan(82062, 1212, 3, 9));
|
|
this.vecMonster.push(new JInChan(82063, 1212, 3, 9));
|
|
|
|
this.BianYiJIngChan.push({ "npcId": 82061, "name": "金蟾王", "mapid": 1212, "mapName": "蓬莱仙岛", "level": 3, "type": 9 });
|
|
this.BianYiJIngChan.push({ "npcId": 82062, "name": "金蟾王", "mapid": 1212, "mapName": "蓬莱仙岛", "level": 3, "type": 9 });
|
|
this.BianYiJIngChan.push({ "npcId": 82063, "name": "金蟾王", "mapid": 1212, "mapName": "蓬莱仙岛", "level": 3, "type": 9 });
|
|
}
|
|
|
|
|
|
Jinchanjiangli() {
|
|
//读取奖励
|
|
|
|
this.JiangLiList = []; //先清空 //在读取
|
|
let sql = `SELECT * FROM prop_jinchanjiangli;`;
|
|
DB.query(sql, (error: any, rows: any) => {
|
|
if (error) {
|
|
SKLogger.debug('读取金蟾奖励奖励失败')
|
|
return;
|
|
|
|
}
|
|
|
|
for (let i = 0; i < rows.length; i++) {
|
|
|
|
this.JiangLiList.push({
|
|
id: rows[i].id,
|
|
itemid: rows[i].itemid,
|
|
rate: rows[i].rate,
|
|
name: rows[i].name,
|
|
type: rows[i].type,
|
|
num: rows[i].num,
|
|
|
|
})
|
|
}
|
|
SKLogger.debug('读取金蟾奖励数据成功!!===================================')
|
|
})
|
|
|
|
|
|
|
|
}
|
|
IsJInchan(nOnlyID: any): boolean {
|
|
for (let it in this.vecMonster) {
|
|
let pjinchan = this.vecMonster[it];
|
|
if (pjinchan.nOnlyID == nOnlyID)
|
|
return true;
|
|
}
|
|
for (let it in this.BianYiJIngChan) {
|
|
let pBoss = this.BianYiJIngChan[it];
|
|
if (pBoss.npcId == nOnlyID)
|
|
return true;
|
|
}
|
|
|
|
|
|
return false;
|
|
}
|
|
/**创建金蟾 */
|
|
onCreateWorldJInChan() {
|
|
let date = GTimer.getCurDate();
|
|
let cur_m = date.getMinutes();//获得分钟数
|
|
let cur_s = date.getSeconds();
|
|
if (cur_m >= 30) {
|
|
cur_m = cur_m - 30;//超过30分 计算超出分钟
|
|
}
|
|
let t = (29 - cur_m) * 60 + (60 - cur_s);
|
|
this.refresh_timer = setTimeout(() => {
|
|
this.refresh_timer = 0;
|
|
|
|
this.checkAndCreateWordJInChan();
|
|
}, t * 1000);//29分开始刷新
|
|
// this.checkAndCreateWordJInChan();
|
|
}
|
|
|
|
FindStar(onlyID: number): any {
|
|
// 检查金蟾
|
|
for (let key in this.vecMonster) {
|
|
let item = this.vecMonster[key];
|
|
if (item.nOnlyID == onlyID) {
|
|
return item;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
ApplyChallenge(nNpcOnlyID: any, roleId: any): number {
|
|
let bomb = this.FindStar(nNpcOnlyID);
|
|
if (bomb == null) {
|
|
return 1;
|
|
}
|
|
if (bomb.vecApply.length > 0) {
|
|
return 2;
|
|
}
|
|
//星级打怪不限制星级
|
|
// if (bomb.level > starlevel) {
|
|
// return 3;
|
|
// }
|
|
bomb.vecApply.push(roleId);
|
|
let self = this;
|
|
setTimeout(() => {
|
|
self.trigleJInChanBattle(nNpcOnlyID, roleId);
|
|
}, 500);
|
|
return 0;
|
|
}
|
|
|
|
/**挑战失败 */
|
|
ChallengeFail(npc_onlyid: any, battle: any) {
|
|
let pBomb: any = this.FindStar(npc_onlyid);
|
|
if (null == pBomb) {
|
|
return;
|
|
}
|
|
// 检查变异-如果死亡进行处罚
|
|
if (pBomb.type == 3) {
|
|
this.JinChanPunish(battle);
|
|
}
|
|
pBomb.Reset();//.push(nAccountID);
|
|
}
|
|
|
|
/**检查和创造金蟾 */
|
|
checkAndCreateWordJInChan() {
|
|
if (this.refresh_timer == 0) {
|
|
this.refresh_timer = setTimeout(() => {
|
|
this.refresh_timer = 0
|
|
this.checkAndCreateWordJInChan();
|
|
}, 60 * 30 * 1000);
|
|
}
|
|
this.pushMoster()
|
|
for (let it in this.vecMonster) {
|
|
let pWBomb = this.vecMonster[it];
|
|
pWBomb.Reset();
|
|
if (pWBomb.nOnlyID > 0) {
|
|
continue;
|
|
}
|
|
let stPos = pWBomb.GetPos();
|
|
pWBomb.nOnlyID = NpcMgr.shared.CreateNpc(pWBomb.nNpc, stPos.map, stPos.x, stPos.y, {
|
|
nKind: 0,
|
|
nID: 0
|
|
}, 0, pWBomb.level, pWBomb.type);
|
|
}
|
|
if (this.BianYiJIngChan.length > 0) {
|
|
|
|
|
|
let name = null
|
|
let mapName = null
|
|
for (let it in this.BianYiJIngChan) {
|
|
let sv: any = this.BianYiJIngChan[it];
|
|
// let pWBomb = new JInChan(sv.npcId, sv.mapid, sv.level, 9);
|
|
// pWBomb.Reset();
|
|
// if (pWBomb.nOnlyID <= 0) {
|
|
// let stPos = pWBomb.GetPos();
|
|
// pWBomb.nOnlyID = NpcMgr.shared.CreateNpc(pWBomb.nNpc, stPos.map, stPos.x, stPos.y, {
|
|
// nKind: 0,
|
|
// nID: 0
|
|
// }, 0, pWBomb.level, pWBomb.type);
|
|
// }
|
|
// this.vecMonster.push(pWBomb);
|
|
name = sv.name
|
|
mapName = sv.mapName
|
|
}
|
|
|
|
|
|
|
|
let strRichText = `<color=#0096ff >${name}</c ><color=#9f20d0 >携带大量宝物,率领众金蟾出现在</c ><color=#009f3c >${mapName}</c ><color=#9f20d0 >。求一有缘人!</c >`;
|
|
PlayerMgr.shared.broadcast('s2c_game_chat', {
|
|
msg: strRichText,
|
|
scale: 3 //播放次数
|
|
});
|
|
}
|
|
}
|
|
/**触发金蟾战斗 */
|
|
trigleJInChanBattle(npcOnlyID: any, roleId: any) {
|
|
let star = this.FindStar(npcOnlyID);
|
|
if (star == null) {
|
|
return;
|
|
}
|
|
if (star.vecApply.length <= 0) {
|
|
return;
|
|
}
|
|
let npc = NpcMgr.shared.findNpc(npcOnlyID);
|
|
if (npc == null) {
|
|
return;
|
|
}
|
|
let player = PlayerMgr.shared.getPlayerByRoleId(roleId);
|
|
if (player == null) {
|
|
return;
|
|
}
|
|
star.Reset();
|
|
if (npc.configid == 82063 || npc.configid == 82062 || npc.configid == 82061) {
|
|
let p = PlayerMgr.shared.getPlayerByRoleId(roleId);
|
|
if (p.getTeamId() > 0) {//有队伍
|
|
let team = TeamMgr.shared.getTeamPlayer(p.getTeamId());
|
|
for (let i = 0; i < team.length; i++) { //遍历队伍
|
|
const p = team[i];//队伍人员
|
|
if (this.hasLimt(p.roleid)) {//存在记录
|
|
for (let index = 0; index < this.limtlist.length; index++) {
|
|
const lim = this.limtlist[index]; //限制
|
|
if (lim.roleid == p) {
|
|
if (lim.num >= 5) {
|
|
p.send('s2c_notice', {
|
|
strRichText: '已达到最大击杀次数!'
|
|
})
|
|
return;
|
|
} else {
|
|
lim.num++;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
} else {//没有记录
|
|
let info: any = {};
|
|
info.roleid = p;
|
|
info.num = 0;
|
|
this.limtlist.push(info)
|
|
}
|
|
}
|
|
|
|
} else {
|
|
if (this.hasLimt(roleId)) {//存在记录
|
|
for (let index = 0; index < this.limtlist.length; index++) {
|
|
const lim = this.limtlist[index]; //限制
|
|
if (lim.roleid == roleId) {
|
|
if (lim.num >= 5) {
|
|
p.send('s2c_notice', {
|
|
strRichText: '已达到最大击杀次数!'
|
|
})
|
|
return;
|
|
} else {
|
|
lim.num++;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
} else {//没有记录
|
|
let info: any = {};
|
|
info.roleid = roleId;
|
|
info.num = 0;
|
|
this.limtlist.push(info)
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
let battle = player.monsterBattle(npc.monster_group, null, BattleType.JinChan, false);
|
|
if (battle == null) {
|
|
return;
|
|
}
|
|
battle.source = npcOnlyID;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
hasLimt(roleid: any): boolean {
|
|
for (let rid of this.limtlist) {
|
|
if (rid.roleid == roleid) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**清理金蟾 */
|
|
CheckWorldJInChanDead(nOnlyID: any) {
|
|
let flag = true;
|
|
for (let it in this.vecMonster) {
|
|
let pWBomb = this.vecMonster[it];
|
|
if (pWBomb.nOnlyID != nOnlyID)
|
|
continue;
|
|
pWBomb.nOnlyID = 0;
|
|
NpcMgr.shared.DeleteNpc(nOnlyID);
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
// 金蟾失败处罚
|
|
JinChanPunish(battle: any) {
|
|
if (battle != null && battle.campA != undefined) {
|
|
for (let role of battle.campA.broles) {
|
|
// 如果是玩家 并且死亡进行失败惩罚
|
|
if (role.living_type == 1 && role.isdead == true) {
|
|
let player = PlayerMgr.shared.getPlayerByOnlyId(role.onlyid)
|
|
if (player) {
|
|
if (player.relive >= 1) {
|
|
let exp: number = 10000 * player.level * 0.9 + player.relive * 15000;
|
|
player.addExp(-exp)
|
|
player.send_notice("本次战斗死亡进行惩罚!扣除经验:" + exp)
|
|
} else {
|
|
player.send_notice("你当前等级不足一转系统保护本次死亡不进行惩罚!")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/**现金奖励 */
|
|
starCurrency(battle: any, task_name: string) {
|
|
if (battle != null && battle.campA != undefined) {
|
|
for (let role of battle.campA.broles) {
|
|
// 如果是玩家
|
|
if (role.living_type == 1) {
|
|
let player = PlayerMgr.shared.getPlayerByOnlyId(role.onlyid)
|
|
if (player) {
|
|
Currency.shared.obtain_currency(player, task_name)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
sendReward(roleid: number, npcOnlyID: number, iswin: number) {
|
|
|
|
this.CheckWorldJInChanDead(npcOnlyID)
|
|
//todo处理奖励
|
|
let player = PlayerMgr.shared.getPlayerByOnlyId(roleid);
|
|
let jiangli = [];
|
|
if (npcOnlyID == 40011) {//BOSS编号
|
|
for (const key in this.JiangLiList) {
|
|
if (Object.prototype.hasOwnProperty.call(this.JiangLiList, key)) {
|
|
const element = this.JiangLiList[key];
|
|
if (element.type == 1) {
|
|
if (element.rate >= 100) {
|
|
jiangli.push(element);
|
|
} else {
|
|
let r = GameUtil.random(0, 100);
|
|
if (element.rate > r) {
|
|
jiangli.push(element);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
|
|
for (const key in this.JiangLiList) {//小怪
|
|
if (Object.prototype.hasOwnProperty.call(this.JiangLiList, key)) {
|
|
const element = this.JiangLiList[key];
|
|
if (element.type == 0) {
|
|
if (element.rate >= 100) {
|
|
jiangli.push(element);
|
|
} else {
|
|
let r = GameUtil.random(0, 100);
|
|
if (element.rate > r) {
|
|
jiangli.push(element);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for (let index = 0; index < jiangli.length; index++) {
|
|
const element = jiangli[index];
|
|
player.addBagItem(element.itemid, element.num, true);
|
|
}
|
|
}
|
|
|
|
}
|