@dev-dungeon/mud-engine
Version:
TypeScript game engine library for MUDs that handles core logic, including entity creation, room management, and game interactions in a modular and extensible way.
132 lines (125 loc) • 3.62 kB
JavaScript
// src/index.ts
import "module-alias/register";
// src/domain/entities/area/Area.ts
var Area = class {
constructor(id = "", name = "", maximumLevel = 1, minimumLevel = 1, places = []) {
this.id = id;
this.name = name;
this.maximumLevel = maximumLevel;
this.minimumLevel = minimumLevel;
this.places = places;
}
addPlace(place) {
this.places.push(place);
}
removePlace(placeId) {
this.places = this.places.filter((place) => place.id !== placeId);
}
};
// src/domain/entities/place/Place.ts
var Place = class {
constructor(attrs = [], code, exits = [], id = "", isExitToOtherArea = false, npcs = [], placeType, players = [], security) {
this.attrs = attrs;
this.code = code;
this.exits = exits;
this.id = id;
this.isExitToOtherArea = isExitToOtherArea;
this.npcs = npcs;
this.placeType = placeType;
this.players = players;
this.security = security;
}
addPlayer(player) {
const playerExists = this.players.find((p) => p.id === player.id);
if (!playerExists) this.players.push(player);
}
removePlayer(playerId) {
this.players = this.players.filter((player) => player.id !== playerId);
}
addNpc(npc) {
const npcExists = this.npcs.find((npc2) => npc2.id === npc2.id);
if (!npcExists) this.npcs.push(npc);
}
removeNpc(npcName) {
this.npcs = this.npcs.filter((npc) => npc.name !== npcName);
}
addExit(exit) {
const currentPlace = this.exits.find((e) => e.id === exit.id);
if (currentPlace)
throw new Error(`the site already has an exit to ${exit.id}`);
const orientation = this.exits.find(
(e) => e.orientation === exit.orientation
);
if (orientation)
throw new Error(`the site already has an exit to ${exit.orientation}`);
this.exits.push(exit);
}
removeExit(exitId) {
this.exits = this.exits.filter((e) => e.id !== exitId);
}
getVisibleExits() {
return this.exits.filter((e) => e.visible && !e.disabled);
}
toJSON() {
return {
attrs: this.attrs,
code: this.code,
exits: this.exits,
id: this.id,
isExitToOtherArea: this.isExitToOtherArea,
npcs: this.npcs,
placeType: this.placeType,
players: this.players,
security: this.security
};
}
};
// src/domain/entities/place/Place.enums.ts
var PlaceType = /* @__PURE__ */ ((PlaceType2) => {
PlaceType2["ROOM"] = "ROOM";
PlaceType2["CITY"] = "CITY";
PlaceType2["FOREST"] = "FOREST";
return PlaceType2;
})(PlaceType || {});
var Orientation = /* @__PURE__ */ ((Orientation2) => {
Orientation2["N"] = "N";
Orientation2["S"] = "S";
Orientation2["E"] = "E";
Orientation2["W"] = "W";
Orientation2["NE"] = "NE";
Orientation2["SE"] = "SE";
Orientation2["SW"] = "SW";
Orientation2["NW"] = "NW";
Orientation2["UP"] = "UP";
Orientation2["DOWN"] = "DOWN";
return Orientation2;
})(Orientation || {});
// src/domain/factories/area/Creator.ts
var Creator = class {
};
var Creator_default = Creator;
// src/domain/factories/area/AreaFactory.ts
var AreaFactory = class extends Creator_default {
createArea(name) {
return new Area("", name, 1, 1, []);
}
};
// src/domain/factories/place/Creator.ts
var Creator2 = class {
};
var Creator_default2 = Creator2;
// src/domain/factories/place/RoomPlaceFactory.ts
var RoomPlaceFactory = class extends Creator_default2 {
createPlace(code, security) {
return new Place([], code, [], "", false, [], "ROOM" /* ROOM */, [], security);
}
};
export {
Area,
AreaFactory,
Orientation,
Place,
PlaceType,
RoomPlaceFactory
};
//# sourceMappingURL=index.js.map