不管是机器人还是玩家,信息都从服务器获取
This commit is contained in:
parent
4a887bbf00
commit
36bbf13410
@ -35,8 +35,8 @@ export function getUserInfo(accountid: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export function randomUserInfo(min: number, max: number) {
|
||||
const data = {min, max}
|
||||
export function randomUserInfo(min: number, max: number, accounts: string[]) {
|
||||
const data = {min, max, accounts}
|
||||
return axios.post(`${ config.info_svr }/randomrobot`, data)
|
||||
.then(function (response) {
|
||||
let res = response.data
|
||||
|
@ -160,12 +160,12 @@ export class Robot {
|
||||
private async discard() {
|
||||
let self = this;
|
||||
let cardArr = [...self.player.cards.values()];
|
||||
// let cards = assistantUtil.checkTriple(cardArr);
|
||||
// if (!cards) {
|
||||
// return;
|
||||
// }
|
||||
// let cardIds = cards.map(o => o.id);
|
||||
let cardIds = [cardArr[0].id]
|
||||
let cards = assistantUtil.checkTriple(cardArr);
|
||||
if (!cards) {
|
||||
return;
|
||||
}
|
||||
let cardIds = cards.map(o => o.id);
|
||||
// let cardIds = [cardArr[0].id]
|
||||
log(`discard: ${self.sessionId} ${cardIds}`);
|
||||
self.reply('discard_card_c2s', {
|
||||
cards: cardIds
|
||||
@ -178,19 +178,19 @@ export class Robot {
|
||||
*/
|
||||
@wait('maxEatTime')
|
||||
private async eatOrGiveUp() {
|
||||
// let targetCard = [...this.room.state.cards.values()][0];
|
||||
// let cardArr = [...this.player.cards.values()];
|
||||
// let tmpCards = assistantUtil.checkTriple(cardArr, targetCard);
|
||||
let targetCard = [...this.room.state.cards.values()][0];
|
||||
let cardArr = [...this.player.cards.values()];
|
||||
let tmpCards = assistantUtil.checkTriple(cardArr, targetCard);
|
||||
let next = this.giveup.bind(this);
|
||||
// if (tmpCards.length > 1 && targetCard.type === 1) {
|
||||
// let cardIds: number[] = [];
|
||||
// for (let card of tmpCards) {
|
||||
// if (card.id !== targetCard.id) {
|
||||
// cardIds.push(card.id);
|
||||
// }
|
||||
// }
|
||||
// next = this.eatCard.bind(this, cardIds, targetCard.id);
|
||||
// }
|
||||
if (tmpCards.length > 1 && targetCard.type === 1) {
|
||||
let cardIds: number[] = [];
|
||||
for (let card of tmpCards) {
|
||||
if (card.id !== targetCard.id) {
|
||||
cardIds.push(card.id);
|
||||
}
|
||||
}
|
||||
next = this.eatCard.bind(this, cardIds, targetCard.id);
|
||||
}
|
||||
|
||||
next.apply(this);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ export class RobotClient implements Client {
|
||||
this.onMessageHandlers = onMessageHandlers;
|
||||
this.addListeners();
|
||||
|
||||
log(`new robot with session: ${sessionId}`);
|
||||
log(`new assist with session: ${sessionId}`);
|
||||
}
|
||||
addListeners() {
|
||||
this.listenerState = this.svrstate.listen('gameState', this.gameSateUpdate.bind(this));
|
||||
|
@ -23,27 +23,13 @@ export class OnJoinCommand extends Command<CardGameState, {
|
||||
return;
|
||||
}
|
||||
let isRobot = false;
|
||||
let uinfo: {nickname: string, avatar: string, score: number}
|
||||
if (accountId && accountId != 'robot') {
|
||||
uinfo = await getUserInfo(accountId)
|
||||
} else {
|
||||
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') {
|
||||
isRobot = true;
|
||||
accountId = `robot_${client.sessionId}`;
|
||||
} else if (!accountId) {
|
||||
accountId = `player_${client.sessionId}`;
|
||||
}
|
||||
// begin of set seat and team
|
||||
let idx = count;
|
||||
let seatSet = new Set([0,1,2,3])
|
||||
let accounts: string[] = []
|
||||
for (let [,p] of this.state.players) {
|
||||
seatSet.delete(p.idx)
|
||||
accounts.push(p.accountId)
|
||||
}
|
||||
if (seat != undefined) {
|
||||
seat = +seat
|
||||
@ -55,21 +41,30 @@ export class OnJoinCommand extends Command<CardGameState, {
|
||||
} else {
|
||||
idx = seatSet.values().next().value
|
||||
}
|
||||
let uinfo: {nickname: string, avatar: string, score: number, accountid: string}
|
||||
if (accountId && accountId != 'robot') {
|
||||
uinfo = await getUserInfo(accountId)
|
||||
} else {
|
||||
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, accounts)
|
||||
}
|
||||
if (accountId && accountId == 'robot') {
|
||||
isRobot = true;
|
||||
accountId = uinfo.accountid
|
||||
} else if (!accountId) {
|
||||
accountId = uinfo.accountid
|
||||
}
|
||||
|
||||
const team = (idx == 1 || idx == 2) ? 1 : 0;
|
||||
// end of set seat and team
|
||||
let player = new Player(client.sessionId, idx, team);
|
||||
player.accountId = accountId;
|
||||
player.nickname = uinfo.nickname
|
||||
player.avatar = uinfo.avatar
|
||||
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 = uinfo.score;
|
||||
}
|
||||
player.score = uinfo.score
|
||||
|
||||
this.state.players.set(client.sessionId, player);
|
||||
this.room.addAssistClient(client.sessionId);
|
||||
let self = this;
|
||||
|
Loading…
x
Reference in New Issue
Block a user