-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from keshav2010/feat/territory-flag
Feat/territory flag
- Loading branch information
Showing
31 changed files
with
1,252 additions
and
493 deletions.
There are no files selected for viewing
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
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,29 @@ | ||
// OnJoinCommand.ts | ||
import { Command } from "@colyseus/command"; | ||
import { SessionRoom } from "../SessionRoom"; | ||
import { CommandPayload } from "./CommandPayloadType"; | ||
|
||
interface ICaptureFlagCreate { | ||
x: number; | ||
y: number; | ||
} | ||
|
||
export class OnCaptureFlagCreateCommand extends Command< | ||
SessionRoom, | ||
CommandPayload | ||
> { | ||
execute({ | ||
client, | ||
message, | ||
gameManager, | ||
}: CommandPayload<ICaptureFlagCreate>) { | ||
try { | ||
const sessionState = this.state; | ||
gameManager | ||
?.getPlayer(client.id) | ||
?.createCaptureFlag(message.x, message.y, sessionState, gameManager); | ||
} catch (error) { | ||
console.error(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,32 @@ | ||
// OnJoinCommand.ts | ||
import { Command } from "@colyseus/command"; | ||
import { SessionRoom } from "../SessionRoom"; | ||
import { CommandPayload } from "./CommandPayloadType"; | ||
|
||
interface ICaptureFlagDelete { | ||
captureFlagIds: string[]; | ||
} | ||
|
||
export class OnCaptureFlagDeleteCommand extends Command< | ||
SessionRoom, | ||
CommandPayload | ||
> { | ||
execute({ | ||
client, | ||
message, | ||
gameManager, | ||
}: CommandPayload<ICaptureFlagDelete>) { | ||
try { | ||
const sessionState = this.state; | ||
gameManager | ||
?.getPlayer(client.id) | ||
?.removeBulkCaptureFlag( | ||
message.captureFlagIds, | ||
sessionState, | ||
gameManager | ||
); | ||
} catch (error) { | ||
console.error(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
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
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
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
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
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
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
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,39 @@ | ||
import { Schema, type } from "@colyseus/schema"; | ||
import { VectorState } from "./VectorState"; | ||
import { nanoid } from "nanoid"; | ||
import { SessionState } from "./SessionState"; | ||
import { ISceneItem } from "../core/types/ISceneItem"; | ||
import { SceneObject } from "../core/types/SceneObject"; | ||
|
||
export enum CaptureFlagStatus { | ||
IN_PROGRESS = "in_progress", | ||
READY = "ready", | ||
} | ||
export class CaptureFlagState extends Schema implements ISceneItem { | ||
// Key : sessionId | ||
static cost: number = 30; | ||
@type("string") id = nanoid(); | ||
@type("number") health: number = 5; | ||
@type(VectorState) pos = new VectorState(); | ||
@type("string") flagState: CaptureFlagStatus = CaptureFlagStatus.IN_PROGRESS; | ||
msUntilReady: number = 10 * 1000; | ||
sceneItemRef: SceneObject; | ||
|
||
constructor(x: number, y: number) { | ||
super(); | ||
this.pos = new VectorState(x, y); | ||
this.sceneItemRef = new SceneObject(this.id, x, y, 64, "CAPTURE_FLAG", false); | ||
} | ||
setHealth(health: number) { | ||
this.health = Math.max(0,health); | ||
} | ||
getSceneItem() { | ||
return this.sceneItemRef; | ||
} | ||
tick(delta: number, sessionState: SessionState) { | ||
if (this.flagState === CaptureFlagStatus.IN_PROGRESS) { | ||
this.health = Math.min(this.health + delta * 2, 100); | ||
if (this.health === 100) this.flagState = CaptureFlagStatus.READY; | ||
} | ||
} | ||
} |
Oops, something went wrong.