-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduz-sdk.ts
73 lines (59 loc) · 2.31 KB
/
arduz-sdk.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { ConnectionSystem } from "./sdk/Systems/Connection";
import { InvisibleSystem } from "./sdk/Systems/Invisible";
import { MeditationSystem } from "./sdk/Systems/Meditation";
import { ParalysisSystem } from "./sdk/Systems/Paralysis";
import { InventorySystem } from "./sdk/Systems/Inventory";
import { CombatSystem } from "./sdk/Systems/Combat";
import { SkillSystem } from "./sdk/Systems/Skill";
import { GameMapSystem } from "./sdk/Systems/GameMap";
import {
Character,
onNewCharacterObservable,
} from "./sdk/Components/Character";
import { Connection } from "./sdk/Components/Connection";
import { loadBalance } from "./sdk/Balance";
import { WalkingSystem } from "./sdk/Systems/WalkingSystem";
import { MimetismSystem } from "./sdk/Systems/Mimetism";
import { TimersSystem } from "./sdk/Systems/Timers";
export function startBaseSystems() {
engine.addSystem(new InvisibleSystem());
engine.addSystem(new MimetismSystem());
engine.addSystem(new MeditationSystem());
engine.addSystem(new ParalysisSystem());
engine.addSystem(new TimersSystem());
engine.addSystem(new SkillSystem());
engine.addSystem(new InventorySystem());
engine.addSystem(new CombatSystem());
engine.addSystem(new WalkingSystem());
}
declare function callRpc(): void;
declare function onUpdate(cb: (dt: number) => void): void;
export async function startServer(customServer: () => Promise<void>) {
if (typeof callRpc !== "undefined") {
const environment = await import("@arduz/Environment");
const network = await import("@arduz/Connections");
const config = await environment.getConfiguration();
engine.addSystem(new ConnectionSystem(network));
network.onInitialize.add(($) => {
const char = new Character();
char.addComponent(new Connection($.connectionId, $.nick));
char.position.x = 1;
char.position.y = 1;
char.body.nick = $.nick;
engine.addEntity(char);
onNewCharacterObservable.notifyObservers(char);
});
const map = engine.addSystem(new GameMapSystem(), Infinity);
await map.load(config.map);
await loadBalance();
await customServer();
await environment.startSignal();
} else {
log("SKIPPING CONNECTION SYSTEM INITIALIZATION");
}
}
if (typeof onUpdate === "function") {
onUpdate((dt) => engine.update(dt));
} else {
error("No onUpdate function");
}