player增加头像和昵称
This commit is contained in:
parent
2743eb38b0
commit
9e306e4984
45
package-lock.json
generated
45
package-lock.json
generated
@ -212,6 +212,15 @@
|
|||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/bson": {
|
||||||
|
"version": "4.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/bson/-/bson-4.0.3.tgz",
|
||||||
|
"integrity": "sha512-mVRvYnTOZJz3ccpxhr3wgxVmSeiYinW+zlzQz3SXWaJmD1DuL05Jeq7nKw3SnbKmbleW5qrLG5vdyWe/A9sXhw==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/connect": {
|
"@types/connect": {
|
||||||
"version": "3.4.33",
|
"version": "3.4.33",
|
||||||
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.33.tgz",
|
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.33.tgz",
|
||||||
@ -274,6 +283,26 @@
|
|||||||
"integrity": "sha512-Jus9s4CDbqwocc5pOAnh8ShfrnMcPHuJYzVcSUU7lrh8Ni5HuIqX3oilL86p3dlTrk0LzHRCgA/GQ7uNCw6l2Q==",
|
"integrity": "sha512-Jus9s4CDbqwocc5pOAnh8ShfrnMcPHuJYzVcSUU7lrh8Ni5HuIqX3oilL86p3dlTrk0LzHRCgA/GQ7uNCw6l2Q==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/mongodb": {
|
||||||
|
"version": "3.6.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.6.3.tgz",
|
||||||
|
"integrity": "sha512-6YNqGP1hk5bjUFaim+QoFFuI61WjHiHE1BNeB41TA00Xd2K7zG4lcWyLLq/XtIp36uMavvS5hoAUJ+1u/GcX2Q==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/bson": "*",
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@types/mongoose": {
|
||||||
|
"version": "5.10.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/mongoose/-/mongoose-5.10.3.tgz",
|
||||||
|
"integrity": "sha512-VfdnaFImXEJZZiuL2ID/ysZs4inOIjxwrAnUgkr5eum2O2BLhFkiSI0i87AwignVva1qWTJ3H3DyM0Rf4USJ4A==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/mongodb": "*",
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "14.14.9",
|
"version": "14.14.9",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.9.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.9.tgz",
|
||||||
@ -1682,11 +1711,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mongodb": {
|
"mongodb": {
|
||||||
"version": "3.6.3",
|
"version": "3.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.3.tgz",
|
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.1.tgz",
|
||||||
"integrity": "sha512-rOZuR0QkodZiM+UbQE5kDsJykBqWi0CL4Ec2i1nrGrUI3KO11r6Fbxskqmq3JK2NH7aW4dcccBuUujAP0ERl5w==",
|
"integrity": "sha512-uH76Zzr5wPptnjEKJRQnwTsomtFOU/kQEU8a9hKHr2M7y9qVk7Q4Pkv0EQVp88742z9+RwvsdTw6dRjDZCNu1g==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"bl": "^2.2.1",
|
"bl": "^2.2.0",
|
||||||
"bson": "^1.1.4",
|
"bson": "^1.1.4",
|
||||||
"denque": "^1.4.1",
|
"denque": "^1.4.1",
|
||||||
"require_optional": "^1.0.1",
|
"require_optional": "^1.0.1",
|
||||||
@ -1695,13 +1724,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mongoose": {
|
"mongoose": {
|
||||||
"version": "5.10.15",
|
"version": "5.10.3",
|
||||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.10.15.tgz",
|
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.10.3.tgz",
|
||||||
"integrity": "sha512-3QUWCpMRdFCPIBZkjG/B2OkfMY2WLkR+hv335o4T2mn3ta9kx8qVvXeUDojp3OHMxBZVUyCA+hDyyP4/aKmHuA==",
|
"integrity": "sha512-FLemltuzcsCHlFpEZ3bYOiNhJfHful+GoS+3uRgdEWGlY0HKfOjm9xsISM/tql8vRvhjr7qveuRfoBBGO3xNtw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"bson": "^1.1.4",
|
"bson": "^1.1.4",
|
||||||
"kareem": "2.3.1",
|
"kareem": "2.3.1",
|
||||||
"mongodb": "3.6.3",
|
"mongodb": "3.6.1",
|
||||||
"mongoose-legacy-pluralize": "1.0.2",
|
"mongoose-legacy-pluralize": "1.0.2",
|
||||||
"mpath": "0.7.0",
|
"mpath": "0.7.0",
|
||||||
"mquery": "3.2.2",
|
"mquery": "3.2.2",
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
"@types/debug": "^4.1.5",
|
"@types/debug": "^4.1.5",
|
||||||
"@types/express": "^4.17.1",
|
"@types/express": "^4.17.1",
|
||||||
"@types/express-rate-limit": "^5.1.1",
|
"@types/express-rate-limit": "^5.1.1",
|
||||||
|
"@types/mongoose": "5.10.3",
|
||||||
"ts-node": "^8.1.0",
|
"ts-node": "^8.1.0",
|
||||||
"ts-node-dev": "^1.0.0-pre.63",
|
"ts-node-dev": "^1.0.0-pre.63",
|
||||||
"typescript": "^3.4.5"
|
"typescript": "^3.4.5"
|
||||||
@ -40,6 +41,7 @@
|
|||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
"express-jwt": "^5.3.1",
|
"express-jwt": "^5.3.1",
|
||||||
"express-rate-limit": "^5.2.3",
|
"express-rate-limit": "^5.2.3",
|
||||||
"fs-jetpack": "^4.1.0"
|
"fs-jetpack": "^4.1.0",
|
||||||
|
"mongoose": "5.10.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,30 @@ export function getCardGroup(accountid: string, heroid: number, cardgroup: strin
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getUserInfo(accountid: string) {
|
||||||
|
return axios.get(`${ config.info_svr }/${ accountid }/uinfo }`)
|
||||||
|
.then(function (response) {
|
||||||
|
let res = response.data
|
||||||
|
if (res.errcode) {
|
||||||
|
throw new Error(res.errmsg)
|
||||||
|
} else {
|
||||||
|
return res.data
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function randomUserInfo() {
|
||||||
|
return axios.get(`${ config.info_svr }/randomrobot }`)
|
||||||
|
.then(function (response) {
|
||||||
|
let res = response.data
|
||||||
|
if (res.errcode) {
|
||||||
|
throw new Error(res.errmsg)
|
||||||
|
} else {
|
||||||
|
return res.data
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解锁英雄
|
* 解锁英雄
|
||||||
* @param {string} accountid
|
* @param {string} accountid
|
||||||
|
@ -160,11 +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]
|
||||||
log(`discard: ${self.sessionId} ${cardIds}`);
|
log(`discard: ${self.sessionId} ${cardIds}`);
|
||||||
self.reply('discard_card_c2s', {
|
self.reply('discard_card_c2s', {
|
||||||
cards: cardIds
|
cards: cardIds
|
||||||
@ -177,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);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import {GameStateConst} from "../../constants/GameStateConst";
|
|||||||
import {GameEnv} from "../../cfg/GameEnv";
|
import {GameEnv} from "../../cfg/GameEnv";
|
||||||
import {BaseConst} from "../../constants/BaseConst";
|
import {BaseConst} from "../../constants/BaseConst";
|
||||||
import {getRandom} from "../../utils/number.util";
|
import {getRandom} from "../../utils/number.util";
|
||||||
|
import { getUserInfo, randomUserInfo } from '../../common/WebApi'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 玩家成功加入房间
|
* 玩家成功加入房间
|
||||||
@ -16,27 +17,45 @@ export class OnJoinCommand extends Command<CardGameState, {
|
|||||||
seat?: number,
|
seat?: number,
|
||||||
score?: number
|
score?: number
|
||||||
}> {
|
}> {
|
||||||
execute({client, accountId, seat, score} = this.payload) {
|
async 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;
|
let isRobot = false;
|
||||||
|
let uinfo: {nickname: string, avatar: string}
|
||||||
|
if (accountId && accountId != 'robot') {
|
||||||
|
uinfo = await getUserInfo(accountId)
|
||||||
|
} else {
|
||||||
|
uinfo = await randomUserInfo()
|
||||||
|
}
|
||||||
if (accountId && accountId == 'robot') {
|
if (accountId && accountId == 'robot') {
|
||||||
isRobot = true;
|
isRobot = true;
|
||||||
accountId = `robot_${client.sessionId}`;
|
accountId = `robot_${client.sessionId}`;
|
||||||
} else if (!accountId) {
|
} else if (!accountId) {
|
||||||
accountId = `player_${client.sessionId}`;
|
accountId = `player_${client.sessionId}`;
|
||||||
}
|
}
|
||||||
let team = 0;
|
|
||||||
let idx = count;
|
let idx = count;
|
||||||
if (seat != undefined) {
|
let seatSet = new Set([0,1,2,3])
|
||||||
idx = +seat;
|
for (let [,p] of this.state.players) {
|
||||||
} else {
|
seatSet.delete(p.idx)
|
||||||
team = (count == 1 || count == 2) ? 1 : 0;
|
|
||||||
}
|
}
|
||||||
|
if (seat != undefined) {
|
||||||
|
seat = +seat
|
||||||
|
if (seatSet.has(seat)) {
|
||||||
|
seatSet.delete(seat)
|
||||||
|
idx = seatSet.values().next().value
|
||||||
|
} else {
|
||||||
|
idx = seat;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
idx = seatSet.values().next().value
|
||||||
|
}
|
||||||
|
const team = (idx == 1 || idx == 2) ? 1 : 0;
|
||||||
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.avatar = uinfo.avatar
|
||||||
if (isRobot) {
|
if (isRobot) {
|
||||||
const fc = global.$cfg.get(BaseConst.FORMULA);
|
const fc = global.$cfg.get(BaseConst.FORMULA);
|
||||||
let low = fc.get(70034).number;
|
let low = fc.get(70034).number;
|
||||||
|
@ -85,6 +85,12 @@ export class Player extends Schema {
|
|||||||
*/
|
*/
|
||||||
@type("number")
|
@type("number")
|
||||||
extraTime: number;
|
extraTime: number;
|
||||||
|
|
||||||
|
@type("string")
|
||||||
|
nickname: string;
|
||||||
|
|
||||||
|
@type("string")
|
||||||
|
avatar: string;
|
||||||
/**
|
/**
|
||||||
* 当前游戏总抽卡数量
|
* 当前游戏总抽卡数量
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user