109 lines
2.8 KiB
TypeScript
109 lines
2.8 KiB
TypeScript
import {Client, Room} from "colyseus";
|
|
import {IMsg} from "../message/IMsg";
|
|
import {PetInfoMsg} from "../message/PetInfo";
|
|
import {SkillInfoMsg} from "../message/SkillInfo";
|
|
|
|
/**
|
|
* 一些封装了的下发消息的方法
|
|
*/
|
|
Object.defineProperties(Room.prototype, {
|
|
bUserJoin: {
|
|
value: function (data?: any, options?: any) {
|
|
this.broadcast("player_join", data, options);
|
|
},
|
|
writable: true
|
|
},
|
|
sSelectHero: {
|
|
value: function (client: Client, data?: any) {
|
|
client.send('select_hero_s2c', data);
|
|
},
|
|
writable: true
|
|
},
|
|
bSelectHero: {
|
|
value: function (data?: any) {
|
|
this.broadcast("select_hero_s2c", data);
|
|
},
|
|
writable: true
|
|
},
|
|
sDrawCard: {
|
|
value: function (client: Client, data?: any) {
|
|
client.send('draw_card_s2c', data);
|
|
}
|
|
},
|
|
bDrawCard: {
|
|
value: function (data?: any, options?: any) {
|
|
this.broadcast('draw_card_s2c', data, options);
|
|
}
|
|
},
|
|
bPartResult: {
|
|
value: function (data?: any) {
|
|
this.send("", data);
|
|
}
|
|
},
|
|
|
|
bAddPet: {
|
|
value: function (data?: PetInfoMsg) {
|
|
let obj = data.data;
|
|
let pid = obj.player;
|
|
let player = this.state.players.get(pid);
|
|
let pet = player.pets.get(obj.pos);
|
|
pet.id = obj.id;
|
|
pet.ap = obj.ap;
|
|
pet.extAp = obj.extAp;
|
|
pet.harmReduce = obj.harmReduce;
|
|
pet.skills.length = 0;
|
|
if (obj.skills) {
|
|
for (let s of obj.skills) {
|
|
pet.skills.push(s);
|
|
}
|
|
}
|
|
pet.extSkills.length = 0;
|
|
if (obj.extSkills) {
|
|
for (let s of obj.extSkills) {
|
|
pet.extSkills.push(s);
|
|
}
|
|
}
|
|
this.broadcast("pet_info_s2c", data);
|
|
}
|
|
},
|
|
|
|
sMsgQueue: {
|
|
value: function (client:Client, datas?: PetInfoMsg) {
|
|
client.send("msg_queue_s2c", datas);
|
|
}
|
|
},
|
|
|
|
bMsgQueue: {
|
|
value: function (datas?: PetInfoMsg, options?: any) {
|
|
this.broadcast("msg_queue_s2c", datas, options);
|
|
}
|
|
},
|
|
|
|
bCastSkill: {
|
|
value: function (data?: SkillInfoMsg) {
|
|
this.broadcast("cast_skill_s2c", data);
|
|
}
|
|
},
|
|
|
|
bStealCard: {
|
|
value: function (data?: any, options?: any) {
|
|
this.broadcast("steal_card_s2c", data, options);
|
|
}
|
|
},
|
|
|
|
sStealCard: {
|
|
value: function (client: Client, data?: any) {
|
|
client.send("steal_card_s2c", data);
|
|
}
|
|
},
|
|
|
|
bRemoveCard: {
|
|
value: function (client: Client, data?: any) {
|
|
client.send("remove_card_s2c", data);
|
|
}
|
|
},
|
|
|
|
|
|
|
|
});
|