Skip to content

Commit

Permalink
v0.5.0
Browse files Browse the repository at this point in the history
v0.5.0 pr
  • Loading branch information
dapucita authored Mar 21, 2021
2 parents 4ceb50f + 7589bab commit 29041f9
Show file tree
Hide file tree
Showing 23 changed files with 590 additions and 174 deletions.
29 changes: 19 additions & 10 deletions core/game/bot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Haxbotron
// This is main part of the bot

// Haxbotron by dapucita
// MAIN OF THE BOT
// ====================================================================================================
// import modules
import * as LangRes from "./resource/strings";
import * as eventListener from "./controller/events/eventListeners";
Expand All @@ -15,14 +15,22 @@ import { TeamID } from "./model/GameObject/TeamID";
import { EmergencyTools } from "./model/ExposeLibs/EmergencyTools";
import { refreshBanVoteCache } from "./model/OperateHelper/Vote";
import { GameRoomConfig } from "./model/Configuration/GameRoomConfig";

// ====================================================================================================
// load initial configurations
const loadedConfig: GameRoomConfig = JSON.parse(localStorage.getItem('_initConfig')!);

window.gameRoom = {
_room: window.HBInit(loadedConfig._config)
,config: loadedConfig
,link: ''
,social: {
discordWebhook: {
feed: false
,replayUpload: false
,id: ''
,token: ''
}
}
,stadiumData: {
default: localStorage.getItem('_defaultMap')!
,training: localStorage.getItem('_readyMap')!
Expand Down Expand Up @@ -62,9 +70,10 @@ console.log(`Haxbotron loaded bot script. (UID ${window.gameRoom.config._RUID},
window.document.title = `Haxbotron ${window.gameRoom.config._RUID}`;

makeRoom();
// ====================================================================================================
// set scheduling timers

// set schedulers
var advertisementTimer = setInterval(() => {
var scheduledTimer60 = setInterval(() => {
window.gameRoom._room.sendAnnouncement(LangRes.scheduler.advertise, null, 0x777777, "normal", 0); // advertisement

refreshBanVoteCache(); // update banvote status cache
Expand All @@ -79,9 +88,9 @@ var advertisementTimer = setInterval(() => {
}
window.gameRoom._room.sendAnnouncement(Tst.maketext(LangRes.scheduler.banVoteAutoNotify, placeholderVote), null, 0x00FF00, "normal", 0); //notify it
}
}, 60000) // 1min
}, 60000); // 60secs

var scheduledTimer = setInterval(() => {
var scheduledTimer5 = setInterval(() => {
const nowTimeStamp: number = getUnixTimestamp(); //get timestamp

let placeholderScheduler = {
Expand Down Expand Up @@ -131,8 +140,8 @@ var scheduledTimer = setInterval(() => {
}
}
});
}, 5000); // by 5seconds

}, 5000); // 5secs
// ====================================================================================================
// declare functions
function makeRoom(): void {
window.gameRoom.logger.i('initialisation', `The game room is opened at ${window.gameRoom.config._LaunchDate.toLocaleString()}.`);
Expand Down
106 changes: 65 additions & 41 deletions core/game/controller/commands/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import * as StatCalc from "../Statistics";
import { PlayerObject } from "../../model/GameObject/PlayerObject";
import { decideTier, getAvatarByTier, Tier } from "../../model/Statistics/Tier";

/**
* Check if this player plays this match
* @param id Player's ID
*/
function isOnMatchNow(id: number): boolean {
if (window.gameRoom.isGamingNow && window.gameRoom.isStatRecord && window.gameRoom.playerList.get(id)?.team !== 0) return true;
else return false;
}

export function cmdStats(byPlayer: PlayerObject, message?: string): void {
if (message !== undefined) {
//stats for other player who are on this room
Expand All @@ -12,59 +21,74 @@ export function cmdStats(byPlayer: PlayerObject, message?: string): void {
if (isNaN(targetStatsID) != true && window.gameRoom.playerList.has(targetStatsID) == true) { // if the value is not NaN and there's the player
let placeholder = {
ticketTarget: targetStatsID
,targetName: window.gameRoom.playerList.get(targetStatsID)!.name
,targetAfkReason: window.gameRoom.playerList.get(targetStatsID)!.permissions.afkreason
,targetStatsRatingAvatar: getAvatarByTier( // set avatar
, targetName: window.gameRoom.playerList.get(targetStatsID)!.name
, targetAfkReason: window.gameRoom.playerList.get(targetStatsID)!.permissions.afkreason
, targetStatsRatingAvatar: getAvatarByTier( // set avatar
(window.gameRoom.playerList.get(targetStatsID)!.stats.totals < window.gameRoom.config.HElo.factor.placement_match_chances)
? Tier.TierNew
: decideTier(window.gameRoom.playerList.get(targetStatsID)!.stats.rating))
,targetStatsRating: window.gameRoom.playerList.get(targetStatsID)!.stats.rating
,targetStatsTotal: window.gameRoom.playerList.get(targetStatsID)!.stats.totals
,targetStatsDisconns: window.gameRoom.playerList.get(targetStatsID)!.stats.disconns
,targetStatsWins: window.gameRoom.playerList.get(targetStatsID)!.stats.wins
,targetStatsGoals: window.gameRoom.playerList.get(targetStatsID)!.stats.goals
,targetStatsAssists: window.gameRoom.playerList.get(targetStatsID)!.stats.assists
,targetStatsOgs: window.gameRoom.playerList.get(targetStatsID)!.stats.ogs
,targetStatsLosepoints: window.gameRoom.playerList.get(targetStatsID)!.stats.losePoints
,targetStatsWinRate: StatCalc.calcWinsRate(window.gameRoom.playerList.get(targetStatsID)!.stats.totals, window.gameRoom.playerList.get(targetStatsID)!.stats.wins)
,targetStatsPassSuccess: StatCalc.calcPassSuccessRate(window.gameRoom.playerList.get(targetStatsID)!.stats.balltouch, window.gameRoom.playerList.get(targetStatsID)!.stats.passed)
,targetStatsGoalsPerGame: StatCalc.calcGoalsPerGame(window.gameRoom.playerList.get(targetStatsID)!.stats.totals, window.gameRoom.playerList.get(targetStatsID)!.stats.goals)
,targetStatsAssistsPerGame: StatCalc.calcAssistsPerGame(window.gameRoom.playerList.get(targetStatsID)!.stats.totals, window.gameRoom.playerList.get(targetStatsID)!.stats.assists)
,targetStatsOgsPerGame: StatCalc.calcOGsPerGame(window.gameRoom.playerList.get(targetStatsID)!.stats.totals, window.gameRoom.playerList.get(targetStatsID)!.stats.ogs)
,targetStatsLostGoalsPerGame: StatCalc.calcLoseGoalsPerGame(window.gameRoom.playerList.get(targetStatsID)!.stats.totals, window.gameRoom.playerList.get(targetStatsID)!.stats.losePoints)
? Tier.TierNew
: decideTier(window.gameRoom.playerList.get(targetStatsID)!.stats.rating))
, targetStatsRating: window.gameRoom.playerList.get(targetStatsID)!.stats.rating
, targetStatsTotal: window.gameRoom.playerList.get(targetStatsID)!.stats.totals
, targetStatsDisconns: window.gameRoom.playerList.get(targetStatsID)!.stats.disconns
, targetStatsWins: window.gameRoom.playerList.get(targetStatsID)!.stats.wins
, targetStatsGoals: window.gameRoom.playerList.get(targetStatsID)!.stats.goals
, targetStatsAssists: window.gameRoom.playerList.get(targetStatsID)!.stats.assists
, targetStatsOgs: window.gameRoom.playerList.get(targetStatsID)!.stats.ogs
, targetStatsLosepoints: window.gameRoom.playerList.get(targetStatsID)!.stats.losePoints
, targetStatsWinRate: StatCalc.calcWinsRate(window.gameRoom.playerList.get(targetStatsID)!.stats.totals, window.gameRoom.playerList.get(targetStatsID)!.stats.wins)
, targetStatsPassSuccess: StatCalc.calcPassSuccessRate(window.gameRoom.playerList.get(targetStatsID)!.stats.balltouch, window.gameRoom.playerList.get(targetStatsID)!.stats.passed)
, targetStatsGoalsPerGame: StatCalc.calcGoalsPerGame(window.gameRoom.playerList.get(targetStatsID)!.stats.totals, window.gameRoom.playerList.get(targetStatsID)!.stats.goals)
, targetStatsAssistsPerGame: StatCalc.calcAssistsPerGame(window.gameRoom.playerList.get(targetStatsID)!.stats.totals, window.gameRoom.playerList.get(targetStatsID)!.stats.assists)
, targetStatsOgsPerGame: StatCalc.calcOGsPerGame(window.gameRoom.playerList.get(targetStatsID)!.stats.totals, window.gameRoom.playerList.get(targetStatsID)!.stats.ogs)
, targetStatsLostGoalsPerGame: StatCalc.calcLoseGoalsPerGame(window.gameRoom.playerList.get(targetStatsID)!.stats.totals, window.gameRoom.playerList.get(targetStatsID)!.stats.losePoints)
, targetStatsNowGoals: isOnMatchNow(targetStatsID) ? window.gameRoom.playerList.get(targetStatsID)!.matchRecord.goals : 0
, targetStatsNowAssists: isOnMatchNow(targetStatsID) ? window.gameRoom.playerList.get(targetStatsID)!.matchRecord.assists : 0
, targetStatsNowOgs: isOnMatchNow(targetStatsID) ? window.gameRoom.playerList.get(targetStatsID)!.matchRecord.ogs : 0
, targetStatsNowPassSuccess: isOnMatchNow(targetStatsID) ? StatCalc.calcPassSuccessRate(window.gameRoom.playerList.get(targetStatsID)!.matchRecord.balltouch, window.gameRoom.playerList.get(targetStatsID)!.matchRecord.passed) : 0
}
window.gameRoom._room.sendAnnouncement(Tst.maketext(LangRes.command.stats.statsMsg, placeholder), byPlayer.id, 0x479947, "normal", 1);
let resultMsg: string = (isOnMatchNow(targetStatsID))
? Tst.maketext(LangRes.command.stats.statsMsg + '\n' + LangRes.command.stats.matchAnalysis, placeholder)
: Tst.maketext(LangRes.command.stats.statsMsg, placeholder)
window.gameRoom._room.sendAnnouncement(resultMsg, byPlayer.id, 0x479947, "normal", 1);
} else {
window.gameRoom._room.sendAnnouncement(LangRes.command.stats._ErrorNoPlayer, byPlayer.id, 0xFF7777, "normal", 2);
}
} else {
window.gameRoom._room.sendAnnouncement(LangRes.command.stats._ErrorNoPlayer, byPlayer.id, 0xFF7777, "normal", 2);
}
} else {
//stats for him/herself
//stats for self
let placeholder = {
ticketTarget: byPlayer.id
,targetName: window.gameRoom.playerList.get(byPlayer.id)!.name
,targetAfkReason: window.gameRoom.playerList.get(byPlayer.id)!.permissions.afkreason
,targetStatsRatingAvatar: getAvatarByTier( // set avatar
, targetName: window.gameRoom.playerList.get(byPlayer.id)!.name
, targetAfkReason: window.gameRoom.playerList.get(byPlayer.id)!.permissions.afkreason
, targetStatsRatingAvatar: getAvatarByTier( // set avatar
(window.gameRoom.playerList.get(byPlayer.id)!.stats.totals < window.gameRoom.config.HElo.factor.placement_match_chances)
? Tier.TierNew
: decideTier(window.gameRoom.playerList.get(byPlayer.id)!.stats.rating))
,targetStatsRating: window.gameRoom.playerList.get(byPlayer.id)!.stats.rating
,targetStatsTotal: window.gameRoom.playerList.get(byPlayer.id)!.stats.totals
,targetStatsDisconns: window.gameRoom.playerList.get(byPlayer.id)!.stats.disconns
,targetStatsWins: window.gameRoom.playerList.get(byPlayer.id)!.stats.wins
,targetStatsGoals: window.gameRoom.playerList.get(byPlayer.id)!.stats.goals
,targetStatsAssists: window.gameRoom.playerList.get(byPlayer.id)!.stats.assists
,targetStatsOgs: window.gameRoom.playerList.get(byPlayer.id)!.stats.ogs
,targetStatsLosepoints: window.gameRoom.playerList.get(byPlayer.id)!.stats.losePoints
,targetStatsWinRate: StatCalc.calcWinsRate(window.gameRoom.playerList.get(byPlayer.id)!.stats.totals, window.gameRoom.playerList.get(byPlayer.id)!.stats.wins)
,targetStatsPassSuccess: StatCalc.calcPassSuccessRate(window.gameRoom.playerList.get(byPlayer.id)!.stats.balltouch, window.gameRoom.playerList.get(byPlayer.id)!.stats.passed)
,targetStatsGoalsPerGame: StatCalc.calcGoalsPerGame(window.gameRoom.playerList.get(byPlayer.id)!.stats.totals, window.gameRoom.playerList.get(byPlayer.id)!.stats.goals)
,targetStatsAssistsPerGame: StatCalc.calcAssistsPerGame(window.gameRoom.playerList.get(byPlayer.id)!.stats.totals, window.gameRoom.playerList.get(byPlayer.id)!.stats.assists)
,targetStatsOgsPerGame: StatCalc.calcOGsPerGame(window.gameRoom.playerList.get(byPlayer.id)!.stats.totals, window.gameRoom.playerList.get(byPlayer.id)!.stats.ogs)
,targetStatsLostGoalsPerGame: StatCalc.calcLoseGoalsPerGame(window.gameRoom.playerList.get(byPlayer.id)!.stats.totals, window.gameRoom.playerList.get(byPlayer.id)!.stats.losePoints)
? Tier.TierNew
: decideTier(window.gameRoom.playerList.get(byPlayer.id)!.stats.rating))
, targetStatsRating: window.gameRoom.playerList.get(byPlayer.id)!.stats.rating
, targetStatsTotal: window.gameRoom.playerList.get(byPlayer.id)!.stats.totals
, targetStatsDisconns: window.gameRoom.playerList.get(byPlayer.id)!.stats.disconns
, targetStatsWins: window.gameRoom.playerList.get(byPlayer.id)!.stats.wins
, targetStatsGoals: window.gameRoom.playerList.get(byPlayer.id)!.stats.goals
, targetStatsAssists: window.gameRoom.playerList.get(byPlayer.id)!.stats.assists
, targetStatsOgs: window.gameRoom.playerList.get(byPlayer.id)!.stats.ogs
, targetStatsLosepoints: window.gameRoom.playerList.get(byPlayer.id)!.stats.losePoints
, targetStatsWinRate: StatCalc.calcWinsRate(window.gameRoom.playerList.get(byPlayer.id)!.stats.totals, window.gameRoom.playerList.get(byPlayer.id)!.stats.wins)
, targetStatsPassSuccess: StatCalc.calcPassSuccessRate(window.gameRoom.playerList.get(byPlayer.id)!.stats.balltouch, window.gameRoom.playerList.get(byPlayer.id)!.stats.passed)
, targetStatsGoalsPerGame: StatCalc.calcGoalsPerGame(window.gameRoom.playerList.get(byPlayer.id)!.stats.totals, window.gameRoom.playerList.get(byPlayer.id)!.stats.goals)
, targetStatsAssistsPerGame: StatCalc.calcAssistsPerGame(window.gameRoom.playerList.get(byPlayer.id)!.stats.totals, window.gameRoom.playerList.get(byPlayer.id)!.stats.assists)
, targetStatsOgsPerGame: StatCalc.calcOGsPerGame(window.gameRoom.playerList.get(byPlayer.id)!.stats.totals, window.gameRoom.playerList.get(byPlayer.id)!.stats.ogs)
, targetStatsLostGoalsPerGame: StatCalc.calcLoseGoalsPerGame(window.gameRoom.playerList.get(byPlayer.id)!.stats.totals, window.gameRoom.playerList.get(byPlayer.id)!.stats.losePoints)
, targetStatsNowGoals: isOnMatchNow(byPlayer.id) ? window.gameRoom.playerList.get(byPlayer.id)!.matchRecord.goals : 0
, targetStatsNowAssists: isOnMatchNow(byPlayer.id) ? window.gameRoom.playerList.get(byPlayer.id)!.matchRecord.assists : 0
, targetStatsNowOgs: isOnMatchNow(byPlayer.id) ? window.gameRoom.playerList.get(byPlayer.id)!.matchRecord.ogs : 0
, targetStatsNowPassSuccess: isOnMatchNow(byPlayer.id) ? StatCalc.calcPassSuccessRate(window.gameRoom.playerList.get(byPlayer.id)!.matchRecord.balltouch, window.gameRoom.playerList.get(byPlayer.id)!.matchRecord.passed) : 0
}
window.gameRoom._room.sendAnnouncement(Tst.maketext(LangRes.command.stats.statsMsg, placeholder), byPlayer.id, 0x479947, "normal", 1);
let resultMsg: string = (isOnMatchNow(byPlayer.id))
? Tst.maketext(LangRes.command.stats.statsMsg + '\n' + LangRes.command.stats.matchAnalysis, placeholder)
: Tst.maketext(LangRes.command.stats.statsMsg, placeholder)

window.gameRoom._room.sendAnnouncement(resultMsg, byPlayer.id, 0x479947, "normal", 1);
}
}
4 changes: 4 additions & 0 deletions core/game/controller/events/onGameStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,9 @@ export function onGameStartListener(byPlayer: PlayerObject | null): void {
} else {
window.gameRoom._room.sendAnnouncement(Tst.maketext(LangRes.onStart.stopRecord, placeholderStart), null, 0x00FF00, "normal", 0);
}

// replay record start
window.gameRoom._room.startRecording();

window.gameRoom.logger.i('onGameStart', msg);
}
19 changes: 19 additions & 0 deletions core/game/controller/events/onGameStop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import * as Tst from "../Translator";
import * as LangRes from "../../resource/strings";
import { PlayerObject } from "../../model/GameObject/PlayerObject";
import { convertTeamID2Name, TeamID } from "../../model/GameObject/TeamID";
import { recuritBothTeamFully } from "../../model/OperateHelper/Quorum";
import { setDefaultRoomLimitation, setDefaultStadiums } from "../RoomTools";


Expand Down Expand Up @@ -41,8 +44,24 @@ export function onGameStopListener(byPlayer: PlayerObject): void {
window.gameRoom.ballStack.clear(); // clear the stack.
window.gameRoom.ballStack.possClear(); // clear possession count

// stop replay record and send it
const replay = window.gameRoom._room.stopRecording();

if(replay && window.gameRoom.social.discordWebhook.feed && window.gameRoom.social.discordWebhook.replayUpload && window.gameRoom.social.discordWebhook.id && window.gameRoom.social.discordWebhook.token) {
const placeholder = {
roomName: window.gameRoom.config._config.roomName
,replayDate: Date().toLocaleString()
}

window._feedSocialDiscordWebhook(window.gameRoom.social.discordWebhook.id, window.gameRoom.social.discordWebhook.token, "replay", {
message: Tst.maketext(LangRes.onStop.feedSocialDiscordWebhook.replayMessage, placeholder)
,data: JSON.stringify(Array.from(replay))
});
}

// when auto emcee mode is enabled
if(window.gameRoom.config.rules.autoOperating === true) {
recuritBothTeamFully();
window.gameRoom._room.startGame(); // start next new game
}
}
4 changes: 2 additions & 2 deletions core/game/controller/events/onGameUnpause.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PlayerObject } from "../../model/GameObject/PlayerObject";
import { putTeamNewPlayerFullify } from "../../model/OperateHelper/Quorum";
import { recuritBothTeamFully } from "../../model/OperateHelper/Quorum";

export function onGameUnpauseListener(byPlayer: PlayerObject | null): void {
window.gameRoom.isGamingNow = true; // turn on

// if auto emcee mode is enabled
if(window.gameRoom.config.rules.autoOperating === true) {
if(window.gameRoom.isGamingNow === true) { // when game is in match
putTeamNewPlayerFullify();
recuritBothTeamFully();
}
}
}
4 changes: 2 additions & 2 deletions core/game/controller/events/onPlayerJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { convertToPlayerStorage, getBanlistDataFromDB, getPlayerDataFromDB, remo
import { getUnixTimestamp } from "../Statistics";
import { setDefaultStadiums, updateAdmins } from "../RoomTools";
import { convertTeamID2Name, TeamID } from "../../model/GameObject/TeamID";
import { putTeamNewPlayerConditional, roomActivePlayersNumberCheck } from "../../model/OperateHelper/Quorum";
import { recuritByOne, roomActivePlayersNumberCheck, roomTeamPlayersNumberCheck } from "../../model/OperateHelper/Quorum";
import { decideTier, getAvatarByTier, Tier } from "../../model/Statistics/Tier";
import { isExistNickname, isIncludeBannedWords } from "../TextFilter";

Expand Down Expand Up @@ -241,7 +241,7 @@ export async function onPlayerJoinListener(player: PlayerObject): Promise<void>

// when auto emcee mode is enabled
if (window.gameRoom.config.rules.autoOperating === true) {
putTeamNewPlayerConditional(player.id); // move team
recuritByOne();
if (window.gameRoom.isGamingNow === false) {
// if game is not started then start the game for active players
setDefaultStadiums(); // set stadium
Expand Down
Loading

0 comments on commit 29041f9

Please sign in to comment.