调整机器人的显示计分
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 {BaseConst} from "../constants/BaseConst";
|
||||
import SkillMan from "../rooms/logic/skill/SkillMan";
|
||||
import {FormulaCfg} from "../cfg/parsers/FormulaCfg";
|
||||
|
||||
|
||||
export function initData() {
|
||||
@ -17,6 +18,7 @@ export function initData() {
|
||||
rP(BaseConst.SKILL, SkillCfg);
|
||||
rP(BaseConst.SYSTEMCARD, SystemCardCfg);
|
||||
rP(BaseConst.UNIT, UnitCfg);
|
||||
rP(BaseConst.FORMULA, FormulaCfg);
|
||||
DataParser.loadAll();
|
||||
|
||||
let map = global.$cfg.get(BaseConst.SKILL);
|
||||
|
@ -67,4 +67,5 @@ export class BaseConst {
|
||||
public static readonly SKILL = "skill";
|
||||
public static readonly SYSTEMCARD = "systemcard";
|
||||
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;
|
||||
robotCount: number;
|
||||
match: boolean;
|
||||
score: number;
|
||||
/**
|
||||
* 根据sessionId获取client
|
||||
* @param player 玩家id或者玩家的对象
|
||||
|
@ -25,6 +25,7 @@ import {createRobot} from "../common/WebApi";
|
||||
export class GeneralRoom extends Room {
|
||||
dispatcher = new Dispatcher(this);
|
||||
maxClients = 4;
|
||||
score = 0;
|
||||
battleMan = new BattleHandler();
|
||||
// 用于游戏过程中各种计时器, 使用该计时器的前提是, 只针对当前操作玩家
|
||||
gameClock: Map<string, Delayed> = new Map();
|
||||
@ -50,6 +51,9 @@ export class GeneralRoom extends Room {
|
||||
if (options.match) {
|
||||
this.match = options.match;
|
||||
}
|
||||
if (options.score) {
|
||||
this.score = options.score;
|
||||
}
|
||||
this.battleMan.init(cs, this);
|
||||
this.clock.start();
|
||||
this.state.gameState = GameStateConst.STATE_WAIT_JOIN;
|
||||
@ -113,7 +117,8 @@ export class GeneralRoom extends Room {
|
||||
let data = {
|
||||
client: client,
|
||||
accountId: options.accountid,
|
||||
seat: options.seat
|
||||
seat: options.seat,
|
||||
score: options.score,
|
||||
};
|
||||
this.dispatcher.dispatch(new OnJoinCommand(), data);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import {Client, generateId, matchMaker, Room} from "colyseus";
|
||||
import {BaseConst} from "../constants/BaseConst";
|
||||
|
||||
interface MatchmakingGroup {
|
||||
averageRank: number;
|
||||
@ -109,6 +110,7 @@ export class RankedLobbyRoom extends Room {
|
||||
* 如果找到的记录, clients已经查过2条, 则也插入一条记录
|
||||
* 如果找到的记录, clients是1, 则把当前client添加到该记录中, 同时更新rank
|
||||
*/
|
||||
const fc = global.$cfg.get(BaseConst.FORMULA);
|
||||
if (options.group) {
|
||||
let length = this.stats.length;
|
||||
let groupData;
|
||||
@ -142,7 +144,7 @@ export class RankedLobbyRoom extends Room {
|
||||
});
|
||||
} else {
|
||||
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);
|
||||
@ -299,11 +301,24 @@ export class RankedLobbyRoom extends Room {
|
||||
.map(async (group) => {
|
||||
if (group.ready) {
|
||||
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.
|
||||
*/
|
||||
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: 预处理数据, 确定座次
|
||||
let hasGroup = false;
|
||||
for (let client of group.clients) {
|
||||
|
@ -201,6 +201,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
team: player.team,
|
||||
heroid: player.heroId,
|
||||
statdata: dataObj,
|
||||
score: player.score,
|
||||
cards: cards
|
||||
});
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import {Player} from "../schema/Player";
|
||||
import {Client} from "colyseus";
|
||||
import {GameStateConst} from "../../constants/GameStateConst";
|
||||
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,
|
||||
accountId: string,
|
||||
seat?: number,
|
||||
score?: number
|
||||
}> {
|
||||
execute({client, accountId, seat} = this.payload) {
|
||||
execute({client, accountId, seat, score} = this.payload) {
|
||||
let count = this.state.players.size;
|
||||
if (count >= this.room.maxClients) {
|
||||
return;
|
||||
}
|
||||
let isRobot = false;
|
||||
if (accountId && accountId == 'robot') {
|
||||
isRobot = true;
|
||||
accountId = `robot_${client.sessionId}`;
|
||||
} else if (!accountId) {
|
||||
accountId = `player_${client.sessionId}`;
|
||||
@ -32,6 +37,15 @@ export class OnJoinCommand extends Command<CardGameState, {
|
||||
}
|
||||
let player = new Player(client.sessionId, idx, team);
|
||||
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.room.addAssistClient(client.sessionId);
|
||||
let self = this;
|
||||
|
@ -18,6 +18,12 @@ export class Player extends Schema {
|
||||
id: string;
|
||||
|
||||
accountId: string;
|
||||
/**
|
||||
* 用于显示的分
|
||||
* @type {number}
|
||||
*/
|
||||
@type("number")
|
||||
score: number;
|
||||
/**
|
||||
* 用于组队匹配时候队伍的标记
|
||||
* @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