真人进入房间后, 从gamesvr获取真实的score

This commit is contained in:
zhl 2021-01-28 18:30:27 +08:00
parent c300d8cdbb
commit 4a887bbf00
2 changed files with 13 additions and 6 deletions

View File

@ -35,8 +35,9 @@ export function getUserInfo(accountid: string) {
}) })
} }
export function randomUserInfo() { export function randomUserInfo(min: number, max: number) {
return axios.get(`${ config.info_svr }/randomrobot`) const data = {min, max}
return axios.post(`${ config.info_svr }/randomrobot`, data)
.then(function (response) { .then(function (response) {
let res = response.data let res = response.data
if (res.errcode) { if (res.errcode) {

View File

@ -23,11 +23,15 @@ export class OnJoinCommand extends Command<CardGameState, {
return; return;
} }
let isRobot = false; let isRobot = false;
let uinfo: {nickname: string, avatar: string} let uinfo: {nickname: string, avatar: string, score: number}
if (accountId && accountId != 'robot') { if (accountId && accountId != 'robot') {
uinfo = await getUserInfo(accountId) uinfo = await getUserInfo(accountId)
} else { } else {
uinfo = await randomUserInfo() const fc = global.$cfg.get(BaseConst.FORMULA);
let low = (this.room.score * fc.get(70034).number / 100) | 0;
let high = (this.room.score * fc.get(70035).number / 100) | 0;
uinfo = await randomUserInfo(low, high)
} }
if (accountId && accountId == 'robot') { if (accountId && accountId == 'robot') {
isRobot = true; isRobot = true;
@ -35,6 +39,7 @@ export class OnJoinCommand extends Command<CardGameState, {
} else if (!accountId) { } else if (!accountId) {
accountId = `player_${client.sessionId}`; accountId = `player_${client.sessionId}`;
} }
// begin of set seat and team
let idx = count; let idx = count;
let seatSet = new Set([0,1,2,3]) let seatSet = new Set([0,1,2,3])
for (let [,p] of this.state.players) { for (let [,p] of this.state.players) {
@ -51,6 +56,7 @@ export class OnJoinCommand extends Command<CardGameState, {
idx = seatSet.values().next().value idx = seatSet.values().next().value
} }
const team = (idx == 1 || idx == 2) ? 1 : 0; const team = (idx == 1 || idx == 2) ? 1 : 0;
// end of set seat and team
let player = new Player(client.sessionId, idx, team); let player = new Player(client.sessionId, idx, team);
player.accountId = accountId; player.accountId = accountId;
player.nickname = uinfo.nickname player.nickname = uinfo.nickname
@ -60,9 +66,9 @@ export class OnJoinCommand extends Command<CardGameState, {
let low = fc.get(70034).number; let low = fc.get(70034).number;
let high = fc.get(70035).number; let high = fc.get(70035).number;
let random = getRandom(high, low) / 100 ; let random = getRandom(high, low) / 100 ;
player.score = this.room.score * random | 0; player.score = this.room.score * random || 0;
} else { } else {
player.score = score; player.score = uinfo.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);