134 lines
4.3 KiB
TypeScript
134 lines
4.3 KiB
TypeScript
import DB from "../utils/DB";
|
|
import {MsgCode} from "../role/EEnum";
|
|
import PlayerMgr from "../object/PlayerMgr";
|
|
|
|
|
|
export default class SpecialEffect {
|
|
static shared = new SpecialEffect();
|
|
selist: any[];
|
|
seffectlist: any[];
|
|
|
|
constructor() {
|
|
this.selist = [];
|
|
this.seffectlist = [];
|
|
}
|
|
|
|
init() {
|
|
this.readDB();
|
|
this.seffectList()
|
|
}
|
|
|
|
readDB() {
|
|
let sql = `SELECT * FROM qy_seffect`;
|
|
DB.query(sql, (error: any, rows: any) => {
|
|
for (let i = 0; i < rows.length; i++) {
|
|
this.selist.push({
|
|
seid: rows[i].id, //特效id
|
|
sename: rows[i].name, //特效名字
|
|
setype: rows[i].effect_type, //特效类型
|
|
dazzle: rows[i].dazzle, //锦绣值
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
//获取特效类型
|
|
getSeffectType(effectid: number){
|
|
let seffecttype = 0;
|
|
for(let i = 0; i < this.selist.length; i++){
|
|
if(this.selist[i].seid == effectid){
|
|
seffecttype = this.selist[i].setype
|
|
break;
|
|
}
|
|
}
|
|
if(seffecttype == 0){
|
|
seffecttype = 3;
|
|
}
|
|
return seffecttype;
|
|
}
|
|
|
|
//获取正在使用的特效
|
|
getUseingEffect(roleid: number){
|
|
let list = [];
|
|
for(let i = 0; i < this.seffectlist.length; i++){
|
|
if(this.seffectlist[i].roleid == roleid && this.seffectlist[i].usestate == 1){
|
|
list.push(this.seffectlist[i].effectid);
|
|
}
|
|
}
|
|
return list
|
|
}
|
|
|
|
getSuiEffect(roleid: number){
|
|
for(let i = 0; i < this.seffectlist.length; i++){
|
|
if(this.seffectlist[i].roleid == roleid && this.seffectlist[i].usestate == 1 && this.seffectlist[i].effecttype == 1){
|
|
return this.seffectlist[i].effectid;
|
|
}
|
|
}
|
|
}
|
|
|
|
//所有玩家的特效
|
|
seffectList() {
|
|
let callback = (ret: any, rows: any) => {
|
|
if (ret == MsgCode.SUCCESS) {
|
|
for (let i = 0; i < rows.length; i++) {
|
|
this.seffectlist.push({
|
|
roleid: rows[i].roleid,
|
|
effectid: rows[i].effectid,
|
|
effecttype: rows[i].effecttype,
|
|
usestate: rows[i].use_state,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
DB.selectSeffect(callback);
|
|
}
|
|
|
|
// 查询玩家拥有的特效
|
|
getSeffectbyId(roleid: number){
|
|
let list = [];
|
|
for(let i = 0; i < this.seffectlist.length; i++){
|
|
if(this.seffectlist[i].roleid == roleid){
|
|
list.push(this.seffectlist[i]);
|
|
}
|
|
}
|
|
return list
|
|
}
|
|
|
|
//使用特效
|
|
useSeffect(data: any): any{
|
|
let player = PlayerMgr.shared.getPlayerByRoleId(data.roleid);
|
|
if(player){
|
|
let list = this.getSeffectbyId(data.roleid);
|
|
for(let i = 0; i < list.length; i++){
|
|
if(list[i].effectid == data.effectid && list[i].effecttype == data.effecttype){
|
|
if(list[i].usestate == 1){
|
|
list[i].usestate = 0;
|
|
DB.insertSeffect(list[i].effectid,data.roleid,list[i].usestate,data.effecttype,1)
|
|
continue;
|
|
}else{
|
|
list[i].usestate = 1;
|
|
DB.insertSeffect(list[i].effectid,data.roleid,list[i].usestate,data.effecttype,1)
|
|
continue;
|
|
}
|
|
}
|
|
if(list[i].effectid != data.effectid && list[i].effecttype == data.effecttype){
|
|
list[i].usestate = 0;
|
|
DB.insertSeffect(list[i].effectid,data.roleid,list[i].usestate,data.effecttype,1)
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
//获取正在使用的头像框
|
|
getPortraitByRoleid(roleid: number){
|
|
let portrait = 0;
|
|
for(let i = 0; i < this.seffectlist.length; i++){
|
|
if(this.seffectlist[i].roleid == roleid && this.seffectlist[i].effecttype == 3 && this.seffectlist[i].usestate == 1){
|
|
portrait = this.seffectlist[i].effectid;
|
|
}
|
|
}
|
|
return portrait;
|
|
}
|
|
} |