Skip to content

Commit

Permalink
- Reldens - v4.0.0-beta.38.3
Browse files Browse the repository at this point in the history
- Merge pull request #267 from damian-pastorini/v4.0.0-beta.38.3
  • Loading branch information
damian-pastorini authored Dec 3, 2024
2 parents 8d968e0 + 4b548d0 commit 8f0753c
Show file tree
Hide file tree
Showing 52 changed files with 3,177 additions and 2,272 deletions.
4 changes: 2 additions & 2 deletions install/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h3 class="form-title">- Storage -</h3>
<span>
Default samples:
<ul>
<li>Client: mysql - Port: 3306</li>
<li>Client: mysql (native password) / mysql2 (schema password) - Port: 3306</li>
<li>Client: mongodb - Port: 27017</li>
</ul>
</span>
Expand Down Expand Up @@ -154,7 +154,7 @@ <h3 class="form-title">- Storage -</h3>
<span class="danger">
DANGER:
<ul>
<li>The automatic installation for the basic configuration and the sample data are only available for the mysql client.</li>
<li>The automatic installation for the basic configuration and the sample data are only available for the MySQL client.</li>
<li>Uncheck this is only if you know what you are doing. <br/>Without this you will get all the tables empty, even the ones with default required values.</li>
</ul>
</span>
Expand Down
54 changes: 31 additions & 23 deletions lib/actions/server/pve.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,27 @@ class Pve extends Battle
{
//Logger.debug('Running Battle between "'+playerSchema.sessionId+'" and "'+target.id+'".', this.uid);
if(GameConst.STATUS.ACTIVE !== playerSchema.state.inState){
Logger.info('PvE inactive player.', playerSchema.state.inState);
//Logger.debug('PvE inactive player.', playerSchema.state.inState);
delete this.inBattleWith[target.id];
return false;
}
if(!this.targetObject){
// @NOTE: this will be the expected case when the player was killed in between different NPCs attacks.
// Logger.debug('Target Object reference removed.');
return false;
}
let affectedProperty = roomScene.config.get('client/actions/skills/affectedProperty');
// @TODO - BETA - Target affected property could be passed on the target object.
if(!affectedProperty){
Logger.error('Affected property configuration is missing');
return false;
}
//Logger.debug('Run Battle - Object:', this.targetObject?.uid, this.targetObject.stats[affectedProperty]);
if(0 >= this.targetObject.stats[affectedProperty]){
// Logger.debug('Target object affected property is zero.');
await this.battleEnded(playerSchema, roomScene);
return false;
}
// @TODO - BETA - Make PvP available by configuration.
// @NOTE: run battle method is for when the player attacks any target. PVE can be started in different ways,
// depending on how the current enemy-object was implemented, for example the PVE can start when the player just
Expand All @@ -46,12 +63,6 @@ class Pve extends Battle
// attack for which matter we won't start the battle until the physical body hits the target.
return false;
}
// @TODO - BETA - Target affected property could be passed on the target object.
let affectedProperty = roomScene.config.get('client/actions/skills/affectedProperty');
if(!affectedProperty){
Logger.error('Affected property configuration is missing');
return false;
}
if(!sc.hasOwn(target.stats, affectedProperty)){
Logger.error('Affected property is not present on target stats.', Object.keys(target.stats));
return false;
Expand All @@ -66,11 +77,23 @@ class Pve extends Battle

async startBattleWith(playerSchema, room)
{
//Logger.debug('Starts PvE', playerSchema?.player_id, this.targetObject?.uid);
if(!this.targetObject){
// @NOTE: this will be the expected case when the player was killed in between different NPCs attacks.
// Logger.debug('Target Object reference removed.');
return false;
}
let affectedProperty = room.config.get('client/actions/skills/affectedProperty');
// Logger.debug('Start Battle - Object:', this.targetObject?.uid, this.targetObject.stats[affectedProperty]);
if(0 >= this.targetObject.stats[affectedProperty]){
// Logger.debug('Target object affected property is zero.');
return false;
}
if(0 === (this.targetObject.actionsKeys?.length ?? 0)){
Logger.warning('Target Object does not have any actions assigned.');
this.leaveBattle(playerSchema);
return false;
}
let targetObjectWorld = this.targetObject.objectBody?.world;
let objectWorldKey = targetObjectWorld?.worldKey;
let playerWorld = playerSchema?.physicalBody?.world;
Expand Down Expand Up @@ -100,22 +123,6 @@ class Pve extends Battle
this.leaveBattle(playerSchema);
return false;
}
// @NOTE: in PVE we will have this additional method startBattleWith which is when the environment attacks the
// player.
if(!this.targetObject){
Logger.error('Undefined target object for PvE.');
this.leaveBattle(playerSchema);
return false;
}
if(0 === (this.targetObject.actionsKeys?.length ?? 0)){
Logger.warning('Target Object does not have any actions assigned.');
this.leaveBattle(playerSchema);
return false;
}
if(0 >= this.targetObject.stats[room.config.get('client/actions/skills/affectedProperty')]){
// Logger.debug('Target object affected property is zero.');
return false;
}
// if target (npc) is already in battle with another player then ignore the current attack:
let inBattleWithPlayersIds = Object.keys(this.inBattleWithPlayers);
let inBattleWithCurrentPlayer = this.inBattleWithPlayers[playerSchema.player_id];
Expand Down Expand Up @@ -263,6 +270,7 @@ class Pve extends Battle
let event = new BattleEndedEvent({playerSchema, pve: this, actionData, room});
await this.events.emit(this.targetObject.getBattleEndEvent(), event);
await this.events.emit('reldens.battleEnded', event);
return true;
}

sendBattleEndedActionData(room, playerSchema, actionData)
Expand Down
6 changes: 5 additions & 1 deletion lib/admin/server/admin-manager-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
*/

const { MapsImporter } = require('../../import/server/maps-importer');
const { ObjectsImporter } = require('../../import/server/objects-importer');
const { SkillsImporter } = require('../../import/server/skills-importer');
const { PropertiesHandler } = require('../../game/properties-handler');

class AdminManagerConfig extends PropertiesHandler
{

constructor(serverManager)
{
super();
Expand All @@ -25,6 +27,8 @@ class AdminManagerConfig extends PropertiesHandler
this.applicationFramework = serverManager?.appServerFactory?.applicationFramework;
this.fileStorageManager = serverManager?.appServerFactory?.fileStorageManager;
this.mapsImporter = new MapsImporter(serverManager);
this.objectsImporter = new ObjectsImporter(serverManager);
this.skillsImporter = new SkillsImporter(serverManager);
this.bodyParser = serverManager?.appServerFactory?.bodyParser;
this.session = serverManager?.appServerFactory?.session;
this.broadcastCallback = (props) => {
Expand Down
126 changes: 126 additions & 0 deletions lib/admin/server/admin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class AdminManager
applicationFramework = null;
fileStorageManager = null;
mapsImporter = null;
objectsImporter = null;
skillsImporter = null;
bodyParser = null;
session = null;
broadcastCallback = null;
Expand Down Expand Up @@ -71,6 +73,8 @@ class AdminManager
this.deletePath = '/delete';
this.managementPath = '/management';
this.mapsWizardPath = '/maps-wizard';
this.objectsImportPath = '/objects-import';
this.skillsImportPath = '/skills-import';
this.adminEntitiesGenerator = new AdminEntitiesGenerator();
this.uploaderFactory = new UploaderFactory();
this.mapsWizardHandlers = {
Expand Down Expand Up @@ -157,6 +161,8 @@ class AdminManager
this.adminContents.dashboard = await this.buildDashboard();
this.adminContents.management = await this.buildManagement();
this.adminContents.mapsWizard = await this.buildMapsWizard();
this.adminContents.objectsImport = await this.buildObjectsImport();
this.adminContents.skillsImport = await this.buildSkillsImport();
this.adminContents.entities = await this.buildEntitiesContents();
}

Expand All @@ -183,6 +189,14 @@ class AdminManager
[this.translations.labels['mapsWizard']]: await this.render(
this.adminFilesContents.sideBarItem,
{name: this.translations.labels['mapsWizard'], path: this.rootPath+this.mapsWizardPath}
),
[this.translations.labels['objectsImport']]: await this.render(
this.adminFilesContents.sideBarItem,
{name: this.translations.labels['objectsImport'], path: this.rootPath+this.objectsImportPath}
),
[this.translations.labels['skillsImport']]: await this.render(
this.adminFilesContents.sideBarItem,
{name: this.translations.labels['skillsImport'], path: this.rootPath+this.skillsImportPath}
)
}
};
Expand Down Expand Up @@ -271,6 +285,28 @@ class AdminManager
return await this.renderRoute(pageContent, this.adminContents.sideBar);
}

async buildObjectsImport()
{
let pageContent = await this.render(
this.adminFilesContents.objectsImport,
{
actionPath: this.rootPath+this.objectsImportPath
}
);
return await this.renderRoute(pageContent, this.adminContents.sideBar);
}

async buildSkillsImport()
{
let pageContent = await this.render(
this.adminFilesContents.skillsImport,
{
actionPath: this.rootPath+this.skillsImportPath
}
);
return await this.renderRoute(pageContent, this.adminContents.sideBar);
}

async buildEntitiesContents()
{
let entitiesContents = {};
Expand Down Expand Up @@ -566,6 +602,8 @@ class AdminManager
return res.redirect(redirectManagementPath+'?result=success');
});
this.setupMapsWizardRoutes();
this.setupObjectsImporterRoutes();
this.setupSkillsImporterRoutes();
// apply the adminRouter to the /admin path:
this.app.use(this.rootPath, this.adminRouter);
}
Expand Down Expand Up @@ -622,6 +660,48 @@ class AdminManager
);
}

setupObjectsImporterRoutes()
{
// step-1, import options:
this.adminRouter.get(this.objectsImportPath, this.isAuthenticated.bind(this), async (req, res) => {
let rendererContent = await this.render(this.adminContents.objectsImport, this.fetchShuttingDownData());
return res.send(rendererContent);
});
let fields = [{name: 'generatorJsonFiles'}];
let buckets = {generatorJsonFiles: this.themeManager.projectGeneratedDataPath};
let allowedFileTypes = {generatorJsonFiles: AllowedFileTypes.TEXT};
this.adminRouter.post(
this.objectsImportPath,
this.isAuthenticated.bind(this),
this.uploaderFactory.createUploader(fields, buckets, allowedFileTypes),
async (req, res) => {
// step-2, import:
return res.redirect(await this.importObjects(req));
}
);
}

setupSkillsImporterRoutes()
{
// step-1, import options:
this.adminRouter.get(this.skillsImportPath, this.isAuthenticated.bind(this), async (req, res) => {
let rendererContent = await this.render(this.adminContents.skillsImport, this.fetchShuttingDownData());
return res.send(rendererContent);
});
let fields = [{name: 'generatorJsonFiles'}];
let buckets = {generatorJsonFiles: this.themeManager.projectGeneratedDataPath};
let allowedFileTypes = {generatorJsonFiles: AllowedFileTypes.TEXT};
this.adminRouter.post(
this.skillsImportPath,
this.isAuthenticated.bind(this),
this.uploaderFactory.createUploader(fields, buckets, allowedFileTypes),
async (req, res) => {
// step-2, import:
return res.redirect(await this.importSkills(req));
}
);
}

async generateMaps(req, res)
{
let selectedHandler = req?.body?.mapsWizardAction;
Expand Down Expand Up @@ -755,6 +835,52 @@ class AdminManager
return this.rootPath+this.mapsWizardPath+'?result=success';
}

async importObjects(req)
{
let generateObjectsData = sc.toJson(req?.body?.generatorData);
if(!generateObjectsData){
let fileName = req.files?.generatorJsonFiles?.shift()?.originalname;
if(!fileName){
return this.rootPath+this.skillsImportPath+'?result=objectsImportMissingDataError';
}
generateObjectsData = sc.toJson(await FileHandler.fetchFileContents(
FileHandler.joinPaths(this.themeManager.projectGeneratedDataPath, fileName)
));
if(!generateObjectsData){
return this.rootPath+this.objectsImportPath+'?result=objectsImportDataError';
}
}
let importResult = await this.objectsImporter.import(generateObjectsData);
if(!importResult){
let errorCode = this.objectsImporter.errorCode || 'objectsImportError'
return this.rootPath+this.objectsImportPath+'?result='+errorCode;
}
return this.rootPath+this.objectsImportPath+'?result=success';
}

async importSkills(req)
{
let generateSkillsData = sc.toJson(req?.body?.generatorData);
if(!generateSkillsData){
let fileName = req.files?.generatorJsonFiles?.shift()?.originalname;
if(!fileName){
return this.rootPath+this.skillsImportPath+'?result=skillsImportMissingDataError';
}
generateSkillsData = sc.toJson(await FileHandler.fetchFileContents(
FileHandler.joinPaths(this.themeManager.projectGeneratedDataPath, fileName)
));
if(!generateSkillsData){
return this.rootPath+this.skillsImportPath+'?result=skillsImportDataError';
}
}
let importResult = await this.skillsImporter.import(generateSkillsData);
if(!importResult){
let errorCode = this.skillsImporter.errorCode || 'skillsImportError'
return this.rootPath+this.skillsImportPath+'?result='+errorCode;
}
return this.rootPath+this.skillsImportPath+'?result=success';
}

mapGeneratedMapsDataForImport(data)
{
if(!data.selectedMaps){
Expand Down
2 changes: 2 additions & 0 deletions lib/admin/server/admin-translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class AdminTranslations
pages: 'Server Management',
management: 'Management',
mapsWizard: 'Maps Generation and Import',
objectsImport: 'Objects Import',
skillsImport: 'Skills Import',
shuttingDown: 'Server is shutting down in:',
submitShutdownLabel: 'Shutdown Server',
submitCancelLabel: 'Cancel Server Shutdown',
Expand Down
2 changes: 2 additions & 0 deletions lib/admin/server/templates-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports.TemplatesList = {
management: 'management.html',
mapsWizard: 'maps-wizard.html',
mapsWizardMapsSelection: 'maps-wizard-maps-selection.html',
objectsImport: 'objects-import.html',
skillsImport: 'skills-import.html',
list: 'list.html',
listContent: 'list-content.html',
view: 'view.html',
Expand Down
2 changes: 1 addition & 1 deletion lib/admin/server/uploader-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UploaderFactory
createUploader(fields, buckets, allowedFileTypes)
{
let storage = multer.diskStorage({
destination: (req,file,cb) => {
destination: (req, file, cb) => {
cb(null, buckets[file.fieldname]);
},
filename: (req,file,cb) => {
Expand Down
Loading

0 comments on commit 8f0753c

Please sign in to comment.