调整机器人的显示计分
This commit is contained in:
parent
f569e19bfd
commit
e1928f2658
@ -7,6 +7,7 @@ import {SystemCardCfg} from "../cfg/parsers/SystemCardCfg";
|
|||||||
import {UnitCfg} from "../cfg/parsers/UnitCfg";
|
import {UnitCfg} from "../cfg/parsers/UnitCfg";
|
||||||
import {BaseConst} from "../constants/BaseConst";
|
import {BaseConst} from "../constants/BaseConst";
|
||||||
import SkillMan from "../rooms/logic/skill/SkillMan";
|
import SkillMan from "../rooms/logic/skill/SkillMan";
|
||||||
|
import {FormulaCfg} from "../cfg/parsers/FormulaCfg";
|
||||||
|
|
||||||
|
|
||||||
export function initData() {
|
export function initData() {
|
||||||
@ -17,6 +18,7 @@ export function initData() {
|
|||||||
rP(BaseConst.SKILL, SkillCfg);
|
rP(BaseConst.SKILL, SkillCfg);
|
||||||
rP(BaseConst.SYSTEMCARD, SystemCardCfg);
|
rP(BaseConst.SYSTEMCARD, SystemCardCfg);
|
||||||
rP(BaseConst.UNIT, UnitCfg);
|
rP(BaseConst.UNIT, UnitCfg);
|
||||||
|
rP(BaseConst.FORMULA, FormulaCfg);
|
||||||
DataParser.loadAll();
|
DataParser.loadAll();
|
||||||
|
|
||||||
let map = global.$cfg.get(BaseConst.SKILL);
|
let map = global.$cfg.get(BaseConst.SKILL);
|
||||||
|
@ -67,4 +67,5 @@ export class BaseConst {
|
|||||||
public static readonly SKILL = "skill";
|
public static readonly SKILL = "skill";
|
||||||
public static readonly SYSTEMCARD = "systemcard";
|
public static readonly SYSTEMCARD = "systemcard";
|
||||||
public static readonly UNIT = "unit";
|
public static readonly UNIT = "unit";
|
||||||
|
public static readonly FORMULA = "formula"
|
||||||
}
|
}
|
||||||
|
1
src/global.d.ts
vendored
1
src/global.d.ts
vendored
@ -32,6 +32,7 @@ declare module "colyseus" {
|
|||||||
mainClock: Delayed;
|
mainClock: Delayed;
|
||||||
robotCount: number;
|
robotCount: number;
|
||||||
match: boolean;
|
match: boolean;
|
||||||
|
score: number;
|
||||||
/**
|
/**
|
||||||
* 根据sessionId获取client
|
* 根据sessionId获取client
|
||||||
* @param player 玩家id或者玩家的对象
|
* @param player 玩家id或者玩家的对象
|
||||||
|
@ -25,6 +25,7 @@ import {createRobot} from "../common/WebApi";
|
|||||||
export class GeneralRoom extends Room {
|
export class GeneralRoom extends Room {
|
||||||
dispatcher = new Dispatcher(this);
|
dispatcher = new Dispatcher(this);
|
||||||
maxClients = 4;
|
maxClients = 4;
|
||||||
|
score = 0;
|
||||||
battleMan = new BattleHandler();
|
battleMan = new BattleHandler();
|
||||||
// 用于游戏过程中各种计时器, 使用该计时器的前提是, 只针对当前操作玩家
|
// 用于游戏过程中各种计时器, 使用该计时器的前提是, 只针对当前操作玩家
|
||||||
gameClock: Map<string, Delayed> = new Map();
|
gameClock: Map<string, Delayed> = new Map();
|
||||||
@ -50,6 +51,9 @@ export class GeneralRoom extends Room {
|
|||||||
if (options.match) {
|
if (options.match) {
|
||||||
this.match = options.match;
|
this.match = options.match;
|
||||||
}
|
}
|
||||||
|
if (options.score) {
|
||||||
|
this.score = options.score;
|
||||||
|
}
|
||||||
this.battleMan.init(cs, this);
|
this.battleMan.init(cs, this);
|
||||||
this.clock.start();
|
this.clock.start();
|
||||||
this.state.gameState = GameStateConst.STATE_WAIT_JOIN;
|
this.state.gameState = GameStateConst.STATE_WAIT_JOIN;
|
||||||
@ -113,7 +117,8 @@ export class GeneralRoom extends Room {
|
|||||||
let data = {
|
let data = {
|
||||||
client: client,
|
client: client,
|
||||||
accountId: options.accountid,
|
accountId: options.accountid,
|
||||||
seat: options.seat
|
seat: options.seat,
|
||||||
|
score: options.score,
|
||||||
};
|
};
|
||||||
this.dispatcher.dispatch(new OnJoinCommand(), data);
|
this.dispatcher.dispatch(new OnJoinCommand(), data);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import {Client, generateId, matchMaker, Room} from "colyseus";
|
import {Client, generateId, matchMaker, Room} from "colyseus";
|
||||||
|
import {BaseConst} from "../constants/BaseConst";
|
||||||
|
|
||||||
interface MatchmakingGroup {
|
interface MatchmakingGroup {
|
||||||
averageRank: number;
|
averageRank: number;
|
||||||
@ -109,6 +110,7 @@ export class RankedLobbyRoom extends Room {
|
|||||||
* 如果找到的记录, clients已经查过2条, 则也插入一条记录
|
* 如果找到的记录, clients已经查过2条, 则也插入一条记录
|
||||||
* 如果找到的记录, clients是1, 则把当前client添加到该记录中, 同时更新rank
|
* 如果找到的记录, clients是1, 则把当前client添加到该记录中, 同时更新rank
|
||||||
*/
|
*/
|
||||||
|
const fc = global.$cfg.get(BaseConst.FORMULA);
|
||||||
if (options.group) {
|
if (options.group) {
|
||||||
let length = this.stats.length;
|
let length = this.stats.length;
|
||||||
let groupData;
|
let groupData;
|
||||||
@ -142,7 +144,7 @@ export class RankedLobbyRoom extends Room {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
groupData.clients.set(client.sessionId, {client, options});
|
groupData.clients.set(client.sessionId, {client, options});
|
||||||
groupData.rank = (groupData.rank + options.rank) / 2
|
groupData.rank = (groupData.rank + options.rank) / 2 * (1 + fc.get(70027).number / 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.send("clients", groupData.clients.size);
|
client.send("clients", groupData.clients.size);
|
||||||
@ -299,11 +301,24 @@ export class RankedLobbyRoom extends Room {
|
|||||||
.map(async (group) => {
|
.map(async (group) => {
|
||||||
if (group.ready) {
|
if (group.ready) {
|
||||||
group.confirmed = 0;
|
group.confirmed = 0;
|
||||||
|
let score = 0;
|
||||||
|
let count = 0;
|
||||||
|
group.clients.map(client => {
|
||||||
|
for (let [,data] of client.clients) {
|
||||||
|
score += (data.options?.score || 0);
|
||||||
|
count ++;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
let avaScore = score / count;
|
||||||
/**
|
/**
|
||||||
* Create room instance in the server.
|
* Create room instance in the server.
|
||||||
*/
|
*/
|
||||||
const room = await matchMaker.createRoom(this.roomToCreate, {rank: true, count: this.numClientsToMatch - group.count});
|
const room = await matchMaker.createRoom(this.roomToCreate, {
|
||||||
|
match: true,
|
||||||
|
rank: group.averageRank,
|
||||||
|
score: avaScore,
|
||||||
|
count: this.numClientsToMatch - group.count
|
||||||
|
});
|
||||||
// TODO: 预处理数据, 确定座次
|
// TODO: 预处理数据, 确定座次
|
||||||
let hasGroup = false;
|
let hasGroup = false;
|
||||||
for (let client of group.clients) {
|
for (let client of group.clients) {
|
||||||
|
@ -201,6 +201,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
|||||||
team: player.team,
|
team: player.team,
|
||||||
heroid: player.heroId,
|
heroid: player.heroId,
|
||||||
statdata: dataObj,
|
statdata: dataObj,
|
||||||
|
score: player.score,
|
||||||
cards: cards
|
cards: cards
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import {Player} from "../schema/Player";
|
|||||||
import {Client} from "colyseus";
|
import {Client} from "colyseus";
|
||||||
import {GameStateConst} from "../../constants/GameStateConst";
|
import {GameStateConst} from "../../constants/GameStateConst";
|
||||||
import {GameEnv} from "../../cfg/GameEnv";
|
import {GameEnv} from "../../cfg/GameEnv";
|
||||||
|
import {BaseConst} from "../../constants/BaseConst";
|
||||||
|
import {getRandom} from "../../utils/number.util";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 玩家成功加入房间
|
* 玩家成功加入房间
|
||||||
@ -12,13 +14,16 @@ export class OnJoinCommand extends Command<CardGameState, {
|
|||||||
client: Client,
|
client: Client,
|
||||||
accountId: string,
|
accountId: string,
|
||||||
seat?: number,
|
seat?: number,
|
||||||
|
score?: number
|
||||||
}> {
|
}> {
|
||||||
execute({client, accountId, seat} = this.payload) {
|
execute({client, accountId, seat, score} = this.payload) {
|
||||||
let count = this.state.players.size;
|
let count = this.state.players.size;
|
||||||
if (count >= this.room.maxClients) {
|
if (count >= this.room.maxClients) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let isRobot = false;
|
||||||
if (accountId && accountId == 'robot') {
|
if (accountId && accountId == 'robot') {
|
||||||
|
isRobot = true;
|
||||||
accountId = `robot_${client.sessionId}`;
|
accountId = `robot_${client.sessionId}`;
|
||||||
} else if (!accountId) {
|
} else if (!accountId) {
|
||||||
accountId = `player_${client.sessionId}`;
|
accountId = `player_${client.sessionId}`;
|
||||||
@ -32,6 +37,15 @@ export class OnJoinCommand extends Command<CardGameState, {
|
|||||||
}
|
}
|
||||||
let player = new Player(client.sessionId, idx, team);
|
let player = new Player(client.sessionId, idx, team);
|
||||||
player.accountId = accountId;
|
player.accountId = accountId;
|
||||||
|
if (isRobot) {
|
||||||
|
const fc = global.$cfg.get(BaseConst.FORMULA);
|
||||||
|
let low = fc.get(70034).number;
|
||||||
|
let high = fc.get(70035).number;
|
||||||
|
let random = getRandom(high, low) / 100 ;
|
||||||
|
player.score = this.room.score * random | 0;
|
||||||
|
} else {
|
||||||
|
player.score = score;
|
||||||
|
}
|
||||||
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;
|
||||||
|
@ -18,6 +18,12 @@ export class Player extends Schema {
|
|||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
accountId: string;
|
accountId: string;
|
||||||
|
/**
|
||||||
|
* 用于显示的分
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
@type("number")
|
||||||
|
score: number;
|
||||||
/**
|
/**
|
||||||
* 用于组队匹配时候队伍的标记
|
* 用于组队匹配时候队伍的标记
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
10
src/utils/number.util.ts
Normal file
10
src/utils/number.util.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* 随机数
|
||||||
|
* @param {number} max
|
||||||
|
* @param {number} min
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
export function getRandom(max: number, min: number): number {
|
||||||
|
min = min || 0;
|
||||||
|
return Math.floor(Math.random()*(max-min)+min);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user