-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first try to add a demo to main page
- Loading branch information
1 parent
c4b836f
commit d5df937
Showing
199 changed files
with
9,241 additions
and
23 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export function getDatePlusMinutes(minutes: number) { | ||
const milliseconds = minutes * 60 * 1000 | ||
return new Date(new Date().getTime() + milliseconds) | ||
} | ||
|
||
export function getDateMinusMinutes(minutes: number) { | ||
const milliseconds = minutes * 60 * 1000 | ||
return new Date(new Date().getTime() - milliseconds) | ||
} | ||
|
||
export function getDatePlusSeconds(seconds: number) { | ||
const milliseconds = seconds * 1000 | ||
return new Date(new Date().getTime() + milliseconds) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { IGameAction, IGameActionResponse, } from "$lib/game/types" | ||
import type { Player } from "../objects/units" | ||
|
||
interface IActionOptions { | ||
command: IGameAction["command"] | ||
commandDescription: IGameAction["commandDescription"] | ||
} | ||
|
||
export class Action implements IGameAction { | ||
public command: string | ||
public commandDescription: string | ||
|
||
public live!: ( | ||
player: Player, | ||
params: string[], | ||
) => Promise<IGameActionResponse> | ||
|
||
constructor({ command, commandDescription }: IActionOptions) { | ||
this.command = command | ||
this.commandDescription = commandDescription | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Village } from "../chunks" | ||
import type { Warehouse } from "../objects/buildings/warehouse" | ||
import type { Player } from "../objects/units" | ||
import type { GameScene } from "../scenes/gameScene" | ||
import { Action } from "./action" | ||
import { ANSWER } from "$lib/game/services/actionService"; | ||
|
||
interface IDonateWoodToVillageActionOptions { | ||
scene: GameScene | ||
} | ||
|
||
export class DonateWoodToVillageAction extends Action { | ||
private scene: GameScene | ||
|
||
constructor({ scene }: IDonateWoodToVillageActionOptions) { | ||
super({ command: "donate", commandDescription: "!donate [quantity]" }) | ||
|
||
this.scene = scene | ||
this.live = this.initLive | ||
} | ||
|
||
async initLive(player: Player, params: string[]) { | ||
const amount = this.scene.actionService.getAmountFromChatCommand(params[0]) | ||
if (!amount) { | ||
return ANSWER.WRONG_AMOUNT_ERROR | ||
} | ||
|
||
let warehouse: Warehouse | undefined | ||
if (this.scene.chunkNow instanceof Village) { | ||
warehouse = this.scene.chunkNow.getWarehouse() | ||
} | ||
|
||
const isSuccess = await player.inventory.reduceOrDestroyItem("WOOD", amount) | ||
if (!isSuccess) { | ||
return ANSWER.NOT_ENOUGH_WOOD_ERROR | ||
} | ||
|
||
await warehouse?.inventory.addOrCreateItem("WOOD", amount) | ||
await player.addReputation(amount) | ||
|
||
return ANSWER.DONATE_WOOD_OK | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Village } from "../chunks" | ||
import type { Player } from "../objects/units" | ||
import type { GameScene } from "../scenes" | ||
import { PlantNewTreeScript } from "../scripts/plantNewTreeScript" | ||
import { Action } from "./action" | ||
import { ANSWER } from "$lib/game/services/actionService"; | ||
|
||
interface IPlantTreeActionOptions { | ||
scene: GameScene | ||
} | ||
|
||
export class PlantTreeAction extends Action { | ||
private scene: GameScene | ||
|
||
constructor({ scene }: IPlantTreeActionOptions) { | ||
super({ command: "plant", commandDescription: "!plant" }) | ||
|
||
this.scene = scene | ||
this.live = this.initLive | ||
} | ||
|
||
async initLive(player: Player) { | ||
if (player.script && !player.script.isInterruptible) { | ||
return ANSWER.BUSY_ERROR | ||
} | ||
|
||
if (this.scene.chunkNow instanceof Village) { | ||
const target = this.scene.chunkNow.checkIfNeedToPlantTree() | ||
if (!target) { | ||
return ANSWER.NO_SPACE_AVAILABLE_ERROR | ||
} | ||
|
||
const plantNewTreeFunc = () => { | ||
if (this.scene.chunkNow instanceof Village) { | ||
this.scene.chunkNow.plantNewTree(target) | ||
} | ||
} | ||
|
||
player.script = new PlantNewTreeScript({ | ||
object: player, | ||
target, | ||
plantNewTreeFunc, | ||
}) | ||
|
||
return ANSWER.OK | ||
} | ||
|
||
return ANSWER.ERROR | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Poll } from "../common" | ||
import type { Player } from "../objects/units" | ||
import { Action } from "./action" | ||
import { ANSWER } from "$lib/game/services/actionService"; | ||
|
||
interface IVoteActionOptions { | ||
poll: Poll | ||
} | ||
|
||
export class VoteAction extends Action { | ||
private poll: Poll | ||
private readonly id: string | ||
|
||
constructor({ poll }: IVoteActionOptions) { | ||
super({ command: "go", commandDescription: "!go" }) | ||
|
||
this.id = poll.generatePollId() | ||
|
||
this.command = `go ${this.id}` | ||
this.commandDescription = `!go ${this.id}` | ||
|
||
this.poll = poll | ||
this.live = this.initLive | ||
} | ||
|
||
async initLive(player: Player) { | ||
const isSuccess = this.poll.vote(player) | ||
if (!isSuccess) { | ||
return ANSWER.ALREADY_VOTED_ERROR | ||
} | ||
|
||
return ANSWER.VOTED_OK | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { type IGameChunkTheme, type IGameForestChunk, } from "$lib/game/types" | ||
import { Stone, Tree } from "../objects" | ||
import type { GameScene } from "../scenes/gameScene.ts" | ||
import { GameChunk } from "./gameChunk" | ||
import { getRandomInRange } from "$lib/random"; | ||
|
||
interface IForestOptions { | ||
center: IGameForestChunk["center"] | ||
width: number | ||
height: number | ||
theme: IGameChunkTheme | ||
scene: GameScene | ||
} | ||
|
||
export class Forest extends GameChunk implements IGameForestChunk { | ||
constructor({ width, height, center, theme, scene }: IForestOptions) { | ||
super({ | ||
title: "Grand Wood", | ||
type: "FOREST", | ||
width, | ||
height, | ||
center, | ||
theme, | ||
scene, | ||
}) | ||
|
||
const treesToPrepare = Math.round( | ||
(this.area.area.endX - this.area.area.startX) / 10, | ||
) | ||
this.initTrees(treesToPrepare) | ||
this.initStones(3) | ||
} | ||
|
||
live() { | ||
super.live() | ||
|
||
for (const obj of this.objects) { | ||
void obj.live() | ||
} | ||
} | ||
|
||
initTrees(count: number) { | ||
for (let i = 0; i < count; i++) { | ||
const point = this.getRandomPoint() | ||
const size = getRandomInRange(75, 90) | ||
const tree = new Tree({ | ||
scene: this.scene, | ||
x: point.x, | ||
y: point.y, | ||
size, | ||
resource: 1, | ||
health: 20, | ||
variant: this.area.theme, | ||
}) | ||
this.objects.push(tree) | ||
} | ||
} | ||
|
||
initStones(count: number) { | ||
for (let i = 0; i < count; i++) { | ||
const point = this.getRandomPoint() | ||
const stone = new Stone({ | ||
scene: this.scene, | ||
x: point.x, | ||
y: point.y, | ||
resource: 1, | ||
}) | ||
this.objects.push(stone) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { createId } from "@paralleldrive/cuid2" | ||
import { type IGameChunk, type IGameChunkTheme, } from "$lib/game/types" | ||
import { Area, type GameObject, Tree } from "../objects" | ||
import type { GameScene } from "../scenes/gameScene.ts" | ||
import { getRandomInRange } from "$lib/random"; | ||
|
||
interface IGameChunkOptions { | ||
center: IGameChunk["center"] | ||
title: IGameChunk["title"] | ||
type: IGameChunk["type"] | ||
theme: IGameChunkTheme | ||
width: number | ||
height: number | ||
scene: GameScene | ||
} | ||
|
||
export class GameChunk implements IGameChunk { | ||
public id: string | ||
public title: string | ||
public type: IGameChunk["type"] | ||
public center!: IGameChunk["center"] | ||
public area!: Area | ||
|
||
public scene: GameScene | ||
public objects: GameObject[] = [] | ||
|
||
constructor({ | ||
title, | ||
type, | ||
theme, | ||
width, | ||
height, | ||
center, | ||
scene, | ||
}: IGameChunkOptions) { | ||
this.id = createId() | ||
this.center = center | ||
this.title = title | ||
this.type = type | ||
|
||
this.scene = scene | ||
|
||
this.initArea({ width, height, theme }) | ||
} | ||
|
||
public live() { | ||
} | ||
|
||
private initArea({ | ||
width, | ||
height, | ||
theme, | ||
}: { | ||
width: number | ||
height: number | ||
theme: IGameChunkTheme | ||
}) { | ||
const halfWidth = Math.round(width / 2) | ||
const halfHeight = Math.round(height / 2) | ||
|
||
const area = { | ||
startX: this.center.x - halfWidth, | ||
endX: this.center.x + halfWidth, | ||
startY: this.center.y - halfHeight, | ||
endY: this.center.y + halfHeight, | ||
} | ||
|
||
this.area = new Area({ scene: this.scene, theme, area }) | ||
} | ||
|
||
public getRandomPoint() { | ||
return { | ||
x: getRandomInRange(this.area.area.startX, this.area.area.endX), | ||
y: getRandomInRange(this.area.area.startY, this.area.area.endY), | ||
} | ||
} | ||
|
||
public getRandomOutPoint() { | ||
const height = this.area.area.endY - this.area.area.startY | ||
const offsetFromTop = Math.round(height / 4) | ||
|
||
return { | ||
x: this.area.area.endX, | ||
y: getRandomInRange( | ||
this.area.area.startY + offsetFromTop, | ||
this.area.area.endY, | ||
), | ||
} | ||
} | ||
|
||
public checkIfPointIsInArea(point: { x: number; y: number }): boolean { | ||
if (point.x >= this.area.area.startX && point.x <= this.area.area.endX) { | ||
if (point.y >= this.area.area.startY && point.y <= this.area.area.endY) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
removeObject(object: GameObject) { | ||
const index = this.objects.indexOf(object) | ||
this.objects.splice(index, 1) | ||
} | ||
|
||
getAvailableTree(): Tree | undefined { | ||
const trees = this.objects.filter( | ||
(obj) => | ||
obj instanceof Tree && | ||
obj.state !== "DESTROYED" && | ||
!obj.isReserved && | ||
obj.isReadyToChop, | ||
) | ||
if (!trees || !trees.length) { | ||
return undefined | ||
} | ||
|
||
return trees[Math.floor(Math.random() * trees.length)] as Tree | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { Forest } from "./forest" | ||
export { GameChunk } from "./gameChunk" | ||
export { Village } from "./village" | ||
export { LakeChunk } from "./lake" |
Oops, something went wrong.