修改结算数据

This commit is contained in:
zhl 2021-01-18 19:38:27 +08:00
parent 82f0a7d79e
commit 24ac49fafb
5 changed files with 40 additions and 24 deletions

View File

@ -38,7 +38,7 @@ export function requestUnlockHero(accountid: string, heroid: number | string) {
*
* @param data
*/
export function reportGameResult(data: any) {
export async function reportGameResult(data: any) {
let dataStr = JSON.stringify(data);
let reqConfig = {
@ -51,13 +51,7 @@ export function reportGameResult(data: any) {
};
// @ts-ignore
axios(reqConfig)
.then(function (response) {
debugRoom(JSON.stringify(response.data));
})
.catch(function (err) {
error(err);
});
return axios(reqConfig)
}
/**

View File

@ -48,9 +48,7 @@ export class GeneralRoom extends Room {
if (options.count) {
this.robotCount = Math.min(Math.max(0, options.count), this.maxClients - 1);
}
if (options.match) {
this.match = options.match;
}
this.match = !!options.match || false;
if (options.score) {
this.score = options.score;
}

View File

@ -126,8 +126,8 @@ Object.defineProperties(Room.prototype, {
let dstHp = player.hp + (hp | 0);
let sourceP = this.state.players.get(fromplayer);
if (sourceP && hp < 0) {
sourceP.statData.inc(StateTypeEnum.DMG, hp);
player.statData.inc(StateTypeEnum.TDMG, hp);
sourceP.statData.inc(StateTypeEnum.DMG, Math.min(-hp, player.hp));
player.statData.inc(StateTypeEnum.TDMG, Math.min(-hp, player.hp));
}
debugRoom(`更新血量: ${player.id} ${player.hp} -> ${hp}, reason: ${reason}`);
if (dstHp <= 0) {
@ -200,6 +200,7 @@ Object.defineProperties(Room.prototype, {
if (!player || !targetPlayer) {
error(`updatePetStat, player or targetPlayer is null ${!!player} ${!!targetPlayer}`);
}
debugRoom(`updatePetStat, val change, old: ${valOld}, new: ${valNew}`);
if (valNew < valOld) {
player?.statData.inc(StateTypeEnum.DMG, valOld - valNew);
targetPlayer?.statData.inc(StateTypeEnum.TDMG, valOld - valNew);

View File

@ -22,6 +22,7 @@ class GameResult{
public mvpScore: number
public scoreChange: number
public scoreOld: number
public stat: any;
constructor(player: Player) {
this.id = player.id;
@ -30,6 +31,7 @@ class GameResult{
this.alive = player.state != PlayerStateConst.PLAYER_DEAD;
this.ap = gameUtil.calcTotalAp(player);
this.scoreOld = player.score;
this.stat = {};
}
}
/**
@ -111,6 +113,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
if (type >= scores.length) {
continue;
}
result.stat[type] = val;
val = val * scores[type];
s += val;
if (resultMap.has(type)) {
@ -136,19 +139,23 @@ export class GameResultCommand extends Command<CardGameState, {}> {
}
}
let mvp;
for (let [p, val] of scoreMap) {
let mvpRate = p.team == winner ? fc.get(70051).number : fc.get(70052).number;
let data = results.get(p);
data.mvpScore = val * mvpRate; // mvp分
if (!mvp) {
mvp = p;
} else {
if (data.mvpScore > results.get(mvp).mvpScore) {
mvp = p;
}
}
}
let resultData: any = {
winner: winner,
results: [...results.values()],
statics: statics
};
let self = this;
this.room.bGameResult(resultData);
this.state.updateGameState(GameStateConst.STATE_GAME_OVER);
//启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private
let resultTimeOver = async function () {
@ -186,7 +193,15 @@ export class GameResultCommand extends Command<CardGameState, {}> {
}
let time = new GameEnv().gameResultTime * 1000;
this.room.beginSchedule(time, resultTimeOver, 'restart_schedule');
self.reportGameResult(resultData.winner);
let seasonData = (await self.reportGameResult(winner, mvp.id, results.get(mvp).mvpScore, results)).data.data;
let resultData: any = {
winner: winner,
mvp: mvp.id,
results: [...results.values()],
statics: statics,
seasonData
};
this.room.bGameResult(resultData);
this.resetAllState();
}
@ -230,13 +245,15 @@ export class GameResultCommand extends Command<CardGameState, {}> {
/**
* info-svr上报游戏结果
* @param {number} winner
* @param mvp
* @param mvpScore
*/
reportGameResult(winner: number) {
async reportGameResult(winner: number, mvp: string, mvpScore: number, results: Map<Player, GameResult>) {
let data: any = {
roomid: this.room.roomId,
round: this.state.round,
winner: winner,
season: 0,
season: this.room.match ? 1: 0
}
let players: any[] = [];
let i = 0;
@ -246,6 +263,9 @@ export class GameResultCommand extends Command<CardGameState, {}> {
for (let [key,val] of player.statData) {
dataObj[key] = val;
}
if (player.id == mvp) {
data.mvp = player.accountId ;
}
players.push({
accountid: player.accountId,
playerid: player.id,
@ -254,11 +274,13 @@ export class GameResultCommand extends Command<CardGameState, {}> {
heroid: player.heroId,
statdata: dataObj,
score: player.score,
cards: cards
cards: cards,
scoreChange: results.get(player).scoreChange,
mvpscore: player.id == mvp ? mvpScore : 0
});
}
data.players = players;
reportGameResult(data);
return reportGameResult(data);
}
}

View File

@ -48,6 +48,7 @@ export class SelectHeroCommand extends Command<CardGameState, { client: Client,
heroPet.ap = unitData.powernum;
heroPet.state = 1;
heroPet.id = unitData.id;
player.petData.set(0, heroPet.ap);
if (unitData.base_skill1id) heroPet.skills.push(unitData.base_skill1id);
if (unitData.base_skill2id) heroPet.skills.push(unitData.base_skill2id);
if (unitData.base_skill3id) heroPet.skills.push(unitData.base_skill3id);