Skip to content

Commit

Permalink
v0.1.0: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dapucita committed Nov 16, 2020
1 parent cdac70a commit bcf1d63
Show file tree
Hide file tree
Showing 47 changed files with 1,503 additions and 1,544 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ Please donate and support this project by [Patreon](https://www.patreon.com/dapu

위 페이지에서 기부하여 이 프로젝트를 지원해주세요!

## Versions
### Released Version
Not yet :)

### Schduled Version
0.1.0 for first release

## Features
launch on Multi platforms: Windows, Linux, OS X and so on

Expand Down Expand Up @@ -125,6 +118,8 @@ If you(the super admin) type a command by chat...

`!super kick ID` kicks that player whose numeric ID is ID.

`!super ban ID` bans that player whose numeric ID is ID.

`!super banclear all` clears the list of banned players.

## Emergency tools
Expand Down
1,065 changes: 81 additions & 984 deletions bot.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions controller/Action.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// DEPRECATED at v0.1.0 (legacy for under v0.0.9)


export interface ActionTicket {
type: string;
ownerPlayerID?: number;
Expand Down
620 changes: 105 additions & 515 deletions controller/Parser.ts

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions controller/RoomTools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { PlayerObject } from "../model/PlayerObject";
import { gameRule } from "../model/rules/rule";
import * as Tst from "./Translator";
import * as LangRes from "../resources/strings";

export function setDefaultStadiums(): void {
// set stadium maps as default setting
if(gameRule.statsRecord == true && window.isStatRecord == true) {
window.room.setCustomStadium(gameRule.defaultMap); // if game mode is 'stats'
} else {
window.room.setCustomStadium(gameRule.readyMap); // if game mode is 'ready'
}
}

export function roomPlayersNumberCheck(): number {
// return number of players joined this room
return window.room.getPlayerList().filter((player: PlayerObject) => player.id != 0).length;
}

export function updateAdmins(): void {
var placeholderUpdateAdmins = { // Parser.maketext(str, placeholder)
playerID: 0,
playerName: '',
gameRuleName: gameRule.ruleName,
gameRuleDescription: gameRule.ruleDescripttion,
gameRuleLimitTime: gameRule.requisite.timeLimit,
gameRuleLimitScore: gameRule.requisite.scoreLimit,
gameRuleNeedMin: gameRule.requisite.minimumPlayers,
possTeamRed: window.ballStack.possCalculate(1),
possTeamBlue: window.ballStack.possCalculate(2),
streakTeamName: window.winningStreak.getName(),
streakTeamCount: window.winningStreak.getCount()
};

// Get all players except the host (id = 0 is always the host)
var players = window.room.getPlayerList().filter((player: PlayerObject) => player.id != 0 && window.playerList.get(player.id).permissions.afkmode != true); // only no afk mode players
if (players.length == 0) return; // If no players left, do nothing.
if (players.find((player: PlayerObject) => player.admin) != null) return; // Do nothing if any admin player is still left.

placeholderUpdateAdmins.playerID = players[0].id;
placeholderUpdateAdmins.playerName = window.playerList.get(players[0].id).name;

window.room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
window.playerList.get(players[0].id).admin = true;
window.logger.i(`${window.playerList.get(players[0].id).name}#${players[0].id} has been admin(value:${window.playerList.get(players[0].id).admin},super:${window.playerList.get(players[0].id).permissions.superadmin}), because there was no admin players.`);
window.room.sendAnnouncement(Tst.maketext(LangRes.funcUpdateAdmins.newAdmin, placeholderUpdateAdmins), null, 0x00FF00, "normal", 0);
}
30 changes: 29 additions & 1 deletion controller/Statistics.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PlayerObject } from "../model/PlayerObject";

export function calcWinsRate(totalGames: number, winGames: number): number {
// calculate the given Player's winning games rate
if(totalGames == 0) {
Expand Down Expand Up @@ -51,6 +53,32 @@ export function calcExpectedWinRate(wins: number, loses: number): number { // Py
return Math.round((winsPow / (winsPow + losesPow)) * 100);
}

export function calcCombatPower() {
export function calcCombatPower() { //TODO: implement this

}

export function getTeamWinningExpectation(): number[] {
if (window.isStatRecord == true) { // if the game mode is stats
// init for count
let goalsCount: number[] = [
0, 0, 0 // spec, red, blue team
];
let losesCount: number[] = [
0, 0, 0 // spec, red, blue team
]

window.room.getPlayerList().filter((player: PlayerObject) => player.id != 0).forEach((player: PlayerObject) => {
// count win and lose games
goalsCount[player.team] += window.playerList.get(player.id).stats.goals;
losesCount[player.team] += window.playerList.get(player.id).stats.losePoints;
});

return [
calcExpectedWinRate(goalsCount[0], losesCount[0]),
calcExpectedWinRate(goalsCount[1], losesCount[1]),
calcExpectedWinRate(goalsCount[2], losesCount[2])
];
} else {
return [0, 0, 0];
}
}
16 changes: 16 additions & 0 deletions controller/Translator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function maketext(str: string, placeholder: any): string {
// find placeholer, and interpolate it.
// if property not found string is not replaced
// from https://stackoverflow.com/questions/19896511/how-to-replace-specific-parts-in-string-with-javascript-with-values-from-object
return String(str).replace((/\\?\{([^{}]+)\}/g), function(match, name) {
return (placeholder[name] != null) ? placeholder[name] : match;
});
/* usage
var content ="Looks like you have {no_email} or {no_code} provided";
var Lang = {
'no_email' : "No email",
'no_code' : "No code"
}
var formatted = replace(content, lang);
*/
}
10 changes: 10 additions & 0 deletions controller/commands/about.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { PlayerObject } from "../../model/PlayerObject";
import * as LangRes from "../../resources/strings";
import * as Tst from "../Translator";

export function cmdAbout(byPlayer: PlayerObject): void {
var placeholder ={
_LaunchTime: localStorage.getItem('_LaunchTime')
}
window.room.sendAnnouncement(Tst.maketext(LangRes.command.about, placeholder), byPlayer.id, 0x479947, "normal", 1);
}
28 changes: 28 additions & 0 deletions controller/commands/afk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { PlayerObject } from "../../model/PlayerObject";
import * as LangRes from "../../resources/strings";
import * as Tst from "../Translator";

export function cmdAfk(byPlayer: PlayerObject, message?: string): void {
var placeholder = {
targetName: byPlayer.name
,ticketTarget: byPlayer.id
,targetAfkReason: ''
}
if (window.playerList.get(byPlayer.id).permissions.afkmode == true) {
window.playerList.get(byPlayer.id).permissions.afkmode = false; // return to active mode
window.playerList.get(byPlayer.id).permissions.afkreason = ''; // init
window.playerList.get(byPlayer.id).afktrace = { exemption: false, count: 0 }; // reset for afk trace
window.room.sendAnnouncement(Tst.maketext(LangRes.command.afk.unAfk, placeholder), null, 0x479947, "normal", 1);
} else {
window.room.setPlayerTeam(byPlayer.id, 0); // Moves this player to Spectators team.
window.room.setPlayerAdmin(byPlayer.id, false); // disqulify admin permission
window.playerList.get(byPlayer.id).admin = false;
window.playerList.get(byPlayer.id).permissions.afkmode = true; // set afk mode
window.playerList.get(byPlayer.id).afktrace = { exemption: false, count: 0}; // reset for afk trace
if(message !== undefined) { // if the reason is not skipped
window.playerList.get(byPlayer.id).permissions.afkreason = message; // set reason
placeholder.targetAfkReason = message; // update placeholder
}
window.room.sendAnnouncement(Tst.maketext(LangRes.command.afk.setAfk, placeholder), null, 0x479947, "normal", 1);
}
}
16 changes: 16 additions & 0 deletions controller/commands/freeze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PlayerObject } from "../../model/PlayerObject";
import * as LangRes from "../../resources/strings";

export function cmdFreeze(byPlayer: PlayerObject): void {
if(window.playerList.get(byPlayer.id).admin == true) {
if(window.isMuteAll == true) {
window.isMuteAll = false; //off
window.room.sendAnnouncement(LangRes.command.freeze.offFreeze, null, 0x479947, "normal", 1);
} else {
window.isMuteAll = true; //on
window.room.sendAnnouncement(LangRes.command.freeze.onFreeze, null, 0x479947, "normal", 1);
}
} else {
window.room.sendAnnouncement(LangRes.command.freeze._ErrorNoPermission, byPlayer.id, 0xFF7777, "normal", 2);
}
}
63 changes: 63 additions & 0 deletions controller/commands/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { PlayerObject } from "../../model/PlayerObject";
import * as LangRes from "../../resources/strings";

export function cmdHelp(byPlayer: PlayerObject, message?: string): void {
if(message !== undefined) {
switch(message) {
case "about": {
window.room.sendAnnouncement(LangRes.command.helpman.about, byPlayer.id, 0x479947, "normal", 1);
break;
}
case "help": {
window.room.sendAnnouncement(LangRes.command.helpman.help, byPlayer.id, 0x479947, "normal", 1);
break;
}
case "stats": {
window.room.sendAnnouncement(LangRes.command.helpman.stats, byPlayer.id, 0x479947, "normal", 1);
break;
}
case "statsreset": {
window.room.sendAnnouncement(LangRes.command.helpman.statsreset, byPlayer.id, 0x479947, "normal", 1);
break;
}
case "streak": {
window.room.sendAnnouncement(LangRes.command.helpman.streak, byPlayer.id, 0x479947, "normal", 1);
break;
}
case "scout": {
window.room.sendAnnouncement(LangRes.command.helpman.scout, byPlayer.id, 0x479947, "normal", 1);
break;
}
case "poss": {
window.room.sendAnnouncement(LangRes.command.helpman.poss, byPlayer.id, 0x479947, "normal", 1);
break;
}
case "afk": {
window.room.sendAnnouncement(LangRes.command.helpman.afk, byPlayer.id, 0x479947, "normal", 1);
break;
}
case "list": {
window.room.sendAnnouncement(LangRes.command.helpman.list, byPlayer.id, 0x479947, "normal", 1);
break;
}
case "freeze": {
window.room.sendAnnouncement(LangRes.command.helpman.freeze, byPlayer.id, 0x479947, "normal", 1);
break;
}
case "mute": {
window.room.sendAnnouncement(LangRes.command.helpman.mute, byPlayer.id, 0x479947, "normal", 1);
break;
}
case "admin": {
window.room.sendAnnouncement(LangRes.command.helpadmin, byPlayer.id, 0x479947, "normal", 1);
break;
}
default: {
window.room.sendAnnouncement(LangRes.command.helpman._ErrorWrongMan, byPlayer.id, 0xFF7777, "normal", 2);
break;
}
}
} else {
window.room.sendAnnouncement(LangRes.command.help, byPlayer.id, 0x479947, "normal", 1);
}
}
61 changes: 61 additions & 0 deletions controller/commands/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { PlayerObject } from "../../model/PlayerObject";
import * as LangRes from "../../resources/strings";
import * as Tst from "../Translator";

export function cmdList(byPlayer: PlayerObject, message?: string): void {
if (message !== undefined) {
var placeholder = {
whoisResult: LangRes.command.list._ErrorNoOne
}
switch (message) {
case "red": {
let players = window.room.getPlayerList().filter((player: PlayerObject) => player.id != 0 && player.team == 1);
if (players.length >= 1) {
players.forEach((player: PlayerObject) => {
let muteFlag: string = '';
if (window.playerList.get(player.id).permissions.mute == true) {
muteFlag = '🔇';
}
placeholder.whoisResult += player.name + '#' + player.id + muteFlag + ', ';
});
}
window.room.sendAnnouncement(Tst.maketext(LangRes.command.list.whoisList, placeholder), byPlayer.id, 0x479947, "normal", 1);
break;
}
case "blue": {
let players = window.room.getPlayerList().filter((player: PlayerObject) => player.id != 0 && player.team == 2);
if (players.length >= 1) {
players.forEach((player: PlayerObject) => {
let muteFlag: string = '';
if (window.playerList.get(player.id).permissions.mute == true) {
muteFlag = '🔇';
}
placeholder.whoisResult += player.name + '#' + player.id + muteFlag + ', ';
});
}
window.room.sendAnnouncement(Tst.maketext(LangRes.command.list.whoisList, placeholder), byPlayer.id, 0x479947, "normal", 1);
break;
}
case "spec": {
let players = window.room.getPlayerList().filter((player: PlayerObject) => player.id != 0 && player.team == 0);
if (players.length >= 1) {
players.forEach((player: PlayerObject) => {
let muteFlag: string = '';
if (window.playerList.get(player.id).permissions.mute == true) {
muteFlag = '🔇';
}
placeholder.whoisResult += player.name + '#' + player.id + muteFlag + ', ';
});
}
window.room.sendAnnouncement(Tst.maketext(LangRes.command.list.whoisList, placeholder), byPlayer.id, 0x479947, "normal", 1);
break;
}
default: {
window.room.sendAnnouncement(LangRes.command.list._ErrorNoTeam, byPlayer.id, 0xFF7777, "normal", 2);
break;
}
}
} else {
window.room.sendAnnouncement(LangRes.command.list._ErrorNoTeam, byPlayer.id, 0xFF7777, "normal", 2);
}
}
30 changes: 30 additions & 0 deletions controller/commands/mute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { PlayerObject } from "../../model/PlayerObject";
import * as LangRes from "../../resources/strings";
import * as Tst from "../Translator";

export function cmdMute(byPlayer: PlayerObject, message?: string): void {
if(window.playerList.get(byPlayer.id).admin == true) {
if(message !== undefined && message.charAt(0) == "#") {
let target: number = parseInt(message.substr(1), 10);
if(isNaN(target) != true && window.playerList.has(target) == true) {
var placeholder = {
targetName: window.playerList.get(target).name
,ticketTarget: target
}
if(window.playerList.get(target).permissions.mute == true) {
window.playerList.get(target).permissions.mute = false;
window.room.sendAnnouncement(Tst.maketext(LangRes.command.mute.successUnmute, placeholder), null, 0x479947, "normal", 1);
} else {
window.playerList.get(target).permissions.mute = true;
window.room.sendAnnouncement(Tst.maketext(LangRes.command.mute.successMute, placeholder), null, 0x479947, "normal", 1);
}
} else {
window.room.sendAnnouncement(LangRes.command.mute._ErrorNoPlayer, byPlayer.id, 0xFF7777, "normal", 2);
}
} else {
window.room.sendAnnouncement(LangRes.command.mute._ErrorNoPlayer, byPlayer.id, 0xFF7777, "normal", 2);
}
} else {
window.room.sendAnnouncement(LangRes.command.mute._ErrorNoPermission, byPlayer.id, 0xFF7777, "normal", 2);
}
}
13 changes: 13 additions & 0 deletions controller/commands/poss.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PlayerObject } from "../../model/PlayerObject";
import * as LangRes from "../../resources/strings";
import * as Tst from "../Translator";
import * as StatCalc from "../../controller/Statistics";
import { gameRule } from "../../model/rules/rule";

export function cmdPoss(byPlayer: PlayerObject): void {
let placeholder = {
possTeamRed: window.ballStack.possCalculate(1)
,possTeamBlue: window.ballStack.possCalculate(2),
}
window.room.sendAnnouncement(Tst.maketext(LangRes.command.poss, placeholder), byPlayer.id, 0x479947, "normal", 1);
}
20 changes: 20 additions & 0 deletions controller/commands/scout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { PlayerObject } from "../../model/PlayerObject";
import * as LangRes from "../../resources/strings";
import * as Tst from "../Translator";
import * as StatCalc from "../../controller/Statistics";
import { gameRule } from "../../model/rules/rule";

export function cmdScout(byPlayer: PlayerObject): void {
if (gameRule.statsRecord == true && window.isStatRecord == true) {
let expectations: number[] = StatCalc.getTeamWinningExpectation();
let placeholder = {
teamExpectationSpec: expectations[0]
,teamExpectationRed: expectations[1]
,teamExpectationBlue: expectations[2]
}
window.room.sendAnnouncement(Tst.maketext(LangRes.command.scout.scouting, placeholder), byPlayer.id, 0x479947, "normal", 1);
} else {
window.room.sendAnnouncement(LangRes.command.scout._ErrorNoMode, byPlayer.id, 0xFF7777, "normal", 2);
}

}
Loading

0 comments on commit bcf1d63

Please sign in to comment.