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