Merge branch 'second' of http://git.kingsome.cn/node/card_svr into second
This commit is contained in:
commit
23d12fa874
@ -1,4 +1,5 @@
|
||||
{
|
||||
"redis": "redis://127.0.0.1:6379/15",
|
||||
"mongodb": "mongodb://127.0.0.1/card-development"
|
||||
"mongodb": "mongodb://127.0.0.1/card-development",
|
||||
"info_svr": "http://127.0.0.1:2987/api/record/save"
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
export interface Config {
|
||||
redis: string;
|
||||
mongodb: string;
|
||||
info_svr: string;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ export class Robot {
|
||||
|
||||
async connect() {
|
||||
try {
|
||||
this.room = await this.client.joinById(this.roomId);
|
||||
this.room = await this.client.joinById(this.roomId, {rank: 1, accountid: 'robot'});
|
||||
this.addListeners();
|
||||
this.sessionId = this.room.sessionId;
|
||||
this.setReady();
|
||||
|
@ -103,7 +103,8 @@ export class GeneralRoom extends Room {
|
||||
}
|
||||
onJoin (client: Client, options: any) {
|
||||
let data = {
|
||||
client: client
|
||||
client: client,
|
||||
accountId: options.accountid,
|
||||
};
|
||||
this.dispatcher.dispatch(new OnJoinCommand(), data);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ Object.defineProperties(Room.prototype, {
|
||||
}
|
||||
let player2 = fromplayer ? this.state.players.get(fromplayer) : null;
|
||||
let cards = gameUtil.drawCard(this, this.state.cardQueue, player, count, player2, extData);
|
||||
if (source == 2 && player2 && player2.id != player.id) {
|
||||
if (source == 1 && player2 && player2.id != player.id) {
|
||||
player2.statData.inc(StateTypeEnum.ACOUNT, cards.length);
|
||||
}
|
||||
let client = this.getClient(dstplayer);
|
||||
|
@ -9,7 +9,11 @@ import gameUtil from "../../utils/game.util";
|
||||
import {Card} from "../schema/Card";
|
||||
import {MapSchema, SetSchema} from "@colyseus/schema";
|
||||
import {StateTypeEnum} from "../enums/StateTypeEnum";
|
||||
import axios from "axios";
|
||||
import {Config} from "../../cfg/Config";
|
||||
|
||||
|
||||
let config: Config = require('../../../config/config.json');
|
||||
/**
|
||||
* 游戏结束
|
||||
*/
|
||||
@ -97,10 +101,10 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
})
|
||||
}
|
||||
resultData[statics] = statics;
|
||||
let self = this;
|
||||
this.room.bGameResult(resultData);
|
||||
this.state.updateGameState(GameStateConst.STATE_GAME_OVER);
|
||||
//启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private
|
||||
let self = this;
|
||||
let resultTimeOver = async function () {
|
||||
// 踢出没离开并没点击重新开始的玩家
|
||||
debugRoom(`restart_schedule 倒计时结束, 有 ${self.state.restartCount} 人点击重玩`)
|
||||
@ -136,6 +140,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
}
|
||||
let time = new GameEnv().gameResultTime * 1000;
|
||||
this.room.beginSchedule(time, resultTimeOver, 'restart_schedule');
|
||||
self.reportGameResult(resultData.winner);
|
||||
this.resetAllState();
|
||||
}
|
||||
|
||||
@ -176,4 +181,50 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
pet.extSkills.length = 0;
|
||||
}
|
||||
|
||||
reportGameResult(winner: number) {
|
||||
let data: any = {
|
||||
roomid: this.room.roomId,
|
||||
round: this.state.round,
|
||||
winner: winner
|
||||
}
|
||||
let players: any[] = [];
|
||||
let i = 0;
|
||||
for (let [, player] of this.state.players) {
|
||||
let cards = [...player.unitCfgs.keys()];
|
||||
let dataObj: any = {};
|
||||
for (let [key,val] of player.statData) {
|
||||
dataObj[key] = val;
|
||||
}
|
||||
players.push({
|
||||
accountid: player.accountId,
|
||||
playerid: player.id,
|
||||
index: i ++,
|
||||
team: player.team,
|
||||
heroid: player.heroId,
|
||||
statdata: dataObj,
|
||||
cards: cards
|
||||
});
|
||||
}
|
||||
data.players = players;
|
||||
let dataStr = JSON.stringify(data);
|
||||
|
||||
let reqConfig = {
|
||||
method: 'post',
|
||||
url: config.info_svr,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data : dataStr
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
axios(reqConfig)
|
||||
.then(function (response) {
|
||||
console.log(JSON.stringify(response.data));
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,12 +9,19 @@ import {GameEnv} from "../../cfg/GameEnv";
|
||||
* 玩家成功加入房间
|
||||
*/
|
||||
export class OnJoinCommand extends Command<CardGameState, {
|
||||
client: Client
|
||||
client: Client,
|
||||
accountId: string
|
||||
}> {
|
||||
execute({client} = this.payload) {
|
||||
execute({client, accountId} = this.payload) {
|
||||
let team = (this.state.players.size == 1 || this.state.players.size == 2)? 1 : 0;
|
||||
// 实际的team会在PlayReadyCommand中设置
|
||||
let player = new Player(client.sessionId, 0, team);
|
||||
if (accountId && accountId == 'robot') {
|
||||
accountId = `robot_${client.sessionId}`;
|
||||
} else if (!accountId) {
|
||||
accountId = `player_${client.sessionId}`;
|
||||
}
|
||||
player.accountId = accountId;
|
||||
this.state.players.set(client.sessionId, player);
|
||||
this.room.addAssistClient(client.sessionId);
|
||||
let self = this;
|
||||
|
@ -30,11 +30,11 @@ export enum StateTypeEnum {
|
||||
/**
|
||||
* 偷卡数量
|
||||
*/
|
||||
SCOUNT = 6,
|
||||
SCOUNT = 7,
|
||||
|
||||
/**
|
||||
* 弃卡数量
|
||||
*/
|
||||
GCOUNT = 7,
|
||||
GCOUNT = 8,
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ export class Player extends Schema {
|
||||
@type("string")
|
||||
id: string;
|
||||
|
||||
accountId: string;
|
||||
|
||||
@type("number")
|
||||
heroId: number;
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user