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",
|
"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 {
|
export interface Config {
|
||||||
redis: string;
|
redis: string;
|
||||||
mongodb: string;
|
mongodb: string;
|
||||||
|
info_svr: string;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ export class Robot {
|
|||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
try {
|
try {
|
||||||
this.room = await this.client.joinById(this.roomId);
|
this.room = await this.client.joinById(this.roomId, {rank: 1, accountid: 'robot'});
|
||||||
this.addListeners();
|
this.addListeners();
|
||||||
this.sessionId = this.room.sessionId;
|
this.sessionId = this.room.sessionId;
|
||||||
this.setReady();
|
this.setReady();
|
||||||
|
@ -103,7 +103,8 @@ export class GeneralRoom extends Room {
|
|||||||
}
|
}
|
||||||
onJoin (client: Client, options: any) {
|
onJoin (client: Client, options: any) {
|
||||||
let data = {
|
let data = {
|
||||||
client: client
|
client: client,
|
||||||
|
accountId: options.accountid,
|
||||||
};
|
};
|
||||||
this.dispatcher.dispatch(new OnJoinCommand(), data);
|
this.dispatcher.dispatch(new OnJoinCommand(), data);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ Object.defineProperties(Room.prototype, {
|
|||||||
}
|
}
|
||||||
let player2 = fromplayer ? this.state.players.get(fromplayer) : null;
|
let player2 = fromplayer ? this.state.players.get(fromplayer) : null;
|
||||||
let cards = gameUtil.drawCard(this, this.state.cardQueue, player, count, player2, extData);
|
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);
|
player2.statData.inc(StateTypeEnum.ACOUNT, cards.length);
|
||||||
}
|
}
|
||||||
let client = this.getClient(dstplayer);
|
let client = this.getClient(dstplayer);
|
||||||
|
@ -9,7 +9,11 @@ import gameUtil from "../../utils/game.util";
|
|||||||
import {Card} from "../schema/Card";
|
import {Card} from "../schema/Card";
|
||||||
import {MapSchema, SetSchema} from "@colyseus/schema";
|
import {MapSchema, SetSchema} from "@colyseus/schema";
|
||||||
import {StateTypeEnum} from "../enums/StateTypeEnum";
|
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;
|
resultData[statics] = statics;
|
||||||
|
let self = this;
|
||||||
this.room.bGameResult(resultData);
|
this.room.bGameResult(resultData);
|
||||||
this.state.updateGameState(GameStateConst.STATE_GAME_OVER);
|
this.state.updateGameState(GameStateConst.STATE_GAME_OVER);
|
||||||
//启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private
|
//启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private
|
||||||
let self = this;
|
|
||||||
let resultTimeOver = async function () {
|
let resultTimeOver = async function () {
|
||||||
// 踢出没离开并没点击重新开始的玩家
|
// 踢出没离开并没点击重新开始的玩家
|
||||||
debugRoom(`restart_schedule 倒计时结束, 有 ${self.state.restartCount} 人点击重玩`)
|
debugRoom(`restart_schedule 倒计时结束, 有 ${self.state.restartCount} 人点击重玩`)
|
||||||
@ -136,6 +140,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
|||||||
}
|
}
|
||||||
let time = new GameEnv().gameResultTime * 1000;
|
let time = new GameEnv().gameResultTime * 1000;
|
||||||
this.room.beginSchedule(time, resultTimeOver, 'restart_schedule');
|
this.room.beginSchedule(time, resultTimeOver, 'restart_schedule');
|
||||||
|
self.reportGameResult(resultData.winner);
|
||||||
this.resetAllState();
|
this.resetAllState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,4 +181,50 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
|||||||
pet.extSkills.length = 0;
|
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, {
|
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;
|
let team = (this.state.players.size == 1 || this.state.players.size == 2)? 1 : 0;
|
||||||
// 实际的team会在PlayReadyCommand中设置
|
// 实际的team会在PlayReadyCommand中设置
|
||||||
let player = new Player(client.sessionId, 0, team);
|
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.state.players.set(client.sessionId, player);
|
||||||
this.room.addAssistClient(client.sessionId);
|
this.room.addAssistClient(client.sessionId);
|
||||||
let self = this;
|
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")
|
@type("string")
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
|
accountId: string;
|
||||||
|
|
||||||
@type("number")
|
@type("number")
|
||||||
heroId: number;
|
heroId: number;
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user