Skip to content

Commit

Permalink
scripts!
Browse files Browse the repository at this point in the history
  • Loading branch information
hmbanan666 committed May 14, 2024
1 parent 1b5e5df commit d0fcad0
Show file tree
Hide file tree
Showing 38 changed files with 840 additions and 432 deletions.
4 changes: 4 additions & 0 deletions EVENTS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2024-05-13

- Сценарии! Теперь юниты выполняют подготовленные наборы задач, а не "думают что им делать"

## 2024-05-09

- В деревне теперь появляются доступные Приключения. Зрители голосуют командой "!го"
Expand Down
34 changes: 17 additions & 17 deletions apps/api/src/bot/bot.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RefreshingAuthProvider } from "@twurple/auth"
import { Bot } from "@twurple/easy-bot"
import { Bot, type BotCommand } from "@twurple/easy-bot"
import { PubSubClient } from "@twurple/pubsub"
import type { Game } from "../game/game"
import { BotService } from "./bot.service"
Expand Down Expand Up @@ -35,21 +35,22 @@ export class BotController {
return authProvider
}

prepareBotCommands() {
prepareBotCommands(): BotCommand[] {
return [
this.service.commandStartGroupBuild(),
this.service.commandJoinGroup(),
this.service.commandDisbandGroup(),
this.service.commandStartChangingScene(),
this.service.commandStartCreatingNewAdventure(),
this.service.commandRefuel(),
this.service.commandChop(),
this.service.commandMine(),
this.service.commandGift(),
this.service.commandSell(),
this.service.commandBuy(),
this.service.commandHelp(),
this.service.commandDonate(),
...this.service.commandStartGroupBuild(),
...this.service.commandJoinGroup(),
...this.service.commandDisbandGroup(),
...this.service.commandStartChangingScene(),
...this.service.commandStartCreatingNewAdventure(),
...this.service.commandRefuel(),
...this.service.commandChop(),
...this.service.commandMine(),
...this.service.commandGift(),
...this.service.commandSell(),
...this.service.commandBuy(),
...this.service.commandHelp(),
...this.service.commandDonate(),
...this.service.commandGithub(),
]
}

Expand Down Expand Up @@ -83,8 +84,7 @@ export class BotController {
console.log("raid canceled!", event)
})

bot.onMessage(({ userId, userName, isAction, text }) => {
console.log("message", userId, isAction, text)
bot.onMessage(({ userId, userName, text }) => {
void this.service.reactOnMessage({ userName, userId, text })
})

Expand Down
73 changes: 44 additions & 29 deletions apps/api/src/bot/bot.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBotCommand } from "@twurple/easy-bot"
import { type BotCommand, createBotCommand } from "@twurple/easy-bot"
import type { IGameSceneAction } from "../../../../packages/api-sdk/src"
import { TWITCH_CHANNEL_REWARDS } from "../config"
import type { Game } from "../game/game"
Expand All @@ -10,73 +10,88 @@ export class BotService {
this.game = game
}

private buildCommand(commandName: string, action: IGameSceneAction) {
return createBotCommand(
commandName,
async (params, { userId, userName, reply }) => {
const result = await this.game.handleChatCommand({
action,
userId,
userName,
params,
})
if (result.message) {
void reply(result.message)
}
},
)
private buildCommand(
commandName: string[],
action: IGameSceneAction,
): BotCommand[] {
const commands = []

for (const command of commandName) {
commands.push(
createBotCommand(
command,
async (params, { userId, userName, reply }) => {
const result = await this.game.handleChatCommand({
action,
userId,
userName,
params,
})
if (result.message) {
void reply(result.message)
}
},
),
)
}

return commands
}

public commandStartChangingScene() {
return this.buildCommand("вернуться", "START_CHANGING_SCENE")
return this.buildCommand(["вернуться"], "START_CHANGING_SCENE")
}

public commandStartGroupBuild() {
return this.buildCommand("собрать", "START_GROUP_BUILD")
return this.buildCommand(["собрать"], "START_GROUP_BUILD")
}

public commandJoinGroup() {
return this.buildCommand("го", "JOIN_GROUP")
return this.buildCommand(["го"], "JOIN_GROUP")
}

public commandDisbandGroup() {
return this.buildCommand("расформировать", "DISBAND_GROUP")
return this.buildCommand(["расформировать"], "DISBAND_GROUP")
}

public commandStartCreatingNewAdventure() {
return this.buildCommand("путешествовать", "START_CREATING_NEW_ADVENTURE")
return this.buildCommand(["путешествовать"], "START_CREATING_NEW_ADVENTURE")
}

public commandRefuel() {
return this.buildCommand("заправить", "REFUEL")
return this.buildCommand(["заправить", "з"], "REFUEL")
}

public commandChop() {
return this.buildCommand("рубить", "CHOP")
return this.buildCommand(["рубить", "р"], "CHOP")
}

public commandMine() {
return this.buildCommand("добыть", "MINE")
return this.buildCommand(["добыть", "добывать", "д"], "MINE")
}

public commandGift() {
return this.buildCommand("подарить", "GIFT")
return this.buildCommand(["подарить"], "GIFT")
}

public commandSell() {
return this.buildCommand("продать", "SELL")
return this.buildCommand(["продать"], "SELL")
}

public commandBuy() {
return this.buildCommand("купить", "BUY")
return this.buildCommand(["купить"], "BUY")
}

public commandHelp() {
return this.buildCommand("помощь", "HELP")
return this.buildCommand(["помощь"], "HELP")
}

public commandDonate() {
return this.buildCommand("донат", "DONATE")
return this.buildCommand(["донат"], "DONATE")
}

public commandGithub() {
return this.buildCommand(["github"], "GITHUB")
}

public reactOnMessage({
Expand Down
7 changes: 2 additions & 5 deletions apps/api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ export const MAX_X = 2520
export const MIN_Y = 120
export const MAX_Y = 1190

export const RAIDER_CAMP_MIN_X = 3000
export const RAIDER_CAMP_MAX_X = 3500
export const RAIDER_CAMP_MIN_Y = 120
export const RAIDER_CAMP_MAX_Y = 1190

export const DONATE_URL = "https://www.donationalerts.com/r/hmbanan666"
export const DISCORD_SERVER_INVITE_URL = "https://discord.gg/B6etUajrGZ"
export const GITHUB_REPO_URL =
"https://github.com/hmbanan666/royal-madness-twitch-game"

export const TWITCH_CHANNEL_REWARDS = {
add150ViewerPointsId: "d8237822-c943-434f-9d7e-87a9f549f4c4",
Expand Down
7 changes: 6 additions & 1 deletion apps/api/src/game/chunks/gameChunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ export class GameChunk implements IGameChunk {
}

public getRandomOutPointOnRight() {
const height = this.area.area.endY - this.area.area.startY

return {
x: this.area.area.endX,
y: getRandomInRange(this.area.area.startY, this.area.area.endY),
y: getRandomInRange(
this.area.area.startY + Math.round(height / 2),
this.area.area.endY,
),
}
}

Expand Down
Loading

0 comments on commit d0fcad0

Please sign in to comment.