Skip to content

Commit

Permalink
Merge pull request #521 from Sehrentos/entity-aura-configs
Browse files Browse the repository at this point in the history
#511 EntityAura and configs
  • Loading branch information
MrAntares authored Feb 27, 2025
2 parents 7484603 + 20801ce commit ca95767
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 88 deletions.
5 changes: 4 additions & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ This guide has the goal to help you to Setup/Play RoBrowser. If there's any trou
- [4.2 Serving Game: Development](#42-serving-game-development)
- [4.3 Serving Game: using Browser](#43-serving-game-using-browser)
- [5. Add game assets](#5-add-game-assets)
- [Local Assets](#local-assets)
- [Remote Client](#remote-client)
- [6. Adding Custom Plugins](#6-adding-custom-plugins)
- [7. ROBrowser Settings Overview](#7-robrowser-settings-overview)
- [8. Play the Game](#8-play-the-game)
Expand Down Expand Up @@ -319,7 +321,8 @@ function initialize() {
renewal: true, // Must match your game server's type (true/false). When using clientinfo.xml you can add the <renewal>true</renewal> custom tag.
packetKeys: false, // Packet encryption keys ( not implemented?? )
socketProxy: "ws://127.0.0.1:5999/", // The websocket proxy's address you set up previously for robrowser (wsproxy)
adminList: [2000000] // List admins' account IDs here like: [2000000, 2000001, 2000002 .... etc]
adminList: [2000000], // List admins' account IDs here like: [2000000, 2000001, 2000002 .... etc]
aura: { defaultLv: 99 } // optional aura levels
}],

// OTHER CONFIG - These can be part of the server config as well, thus making them adjustable per server
Expand Down
12 changes: 12 additions & 0 deletions src/Controls/ProcessCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ define(function (require) {
);
MapPreferences.aura = isSimplified ? 1 : 2;
MapPreferences.save();

var EntityManager = getModule("Renderer/EntityManager");
var EffectManager = getModule("Renderer/EffectManager");
EntityManager.forEach(function (entity) {
entity.aura.load(EffectManager);
});
return;
},
},
Expand All @@ -131,6 +137,12 @@ define(function (require) {
);
MapPreferences.aura = MapPreferences.aura ? 0 : 1;
MapPreferences.save();

var EntityManager = getModule("Renderer/EntityManager");
var EffectManager = getModule("Renderer/EffectManager");
EntityManager.forEach(function (entity) {
entity.aura.load(EffectManager);
});
return;
},
},
Expand Down
195 changes: 108 additions & 87 deletions src/Renderer/Entity/EntityAura.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,101 +6,122 @@
* This file is part of ROBrowser, (http://www.robrowser.com/).
*
* @author Gulfaraz Rahman
*
* @typedef {Object} TMapPreferencesAura
* @prop {number} aura - 0: no aura, 1: only aura, 2: aura and aura2
*
* @typedef {Object} TAuraSettings - default settings for aura (can be overridden by server config)
* @prop {number} defaultLv - default aura level
* @prop {number} babyLv - Baby class aura level
* @prop {number} secondLv - Second class aura level
* @prop {number} thirdLv - Third class aura level
* @prop {number} homunLv - Homun class aura level
* @prop {number} bossLv - Boss class aura level
*/
define(['DB/Effects/EffectConst', 'Preferences/Map'],
function(EffectConst, MapPreferences)
{
'use strict';
define(['DB/Effects/EffectConst', 'Preferences/Map', 'Core/Configs'],
function (EffectConst, /** @type {TMapPreferencesAura} */MapPreferences, Configs) {
'use strict';

var normalEffects = [
EffectConst.EF_LEVEL99,
EffectConst.EF_LEVEL99_2,
EffectConst.EF_LEVEL99_3
];
/** @type {TAuraSettings} */
var _auraSettings = {
defaultLv: 99,
// babyLv: 99, // TODO implement other aura levels
// secondLv: 99,
// thirdLv: 175,
// homunLv: 99,
// bossLv: 99,
};

var simpleEffects = [
EffectConst.EF_LEVEL99_3
];
var normalEffects = [
EffectConst.EF_LEVEL99,
EffectConst.EF_LEVEL99_2,
EffectConst.EF_LEVEL99_3
];

/**
* Aura class
*
* @constructor
* @param {object} entity
*/
function Aura( entity )
{
this.isLoaded = false; // to avoid duplicate aura effects
this.entity = entity; // reference to attached entity
this.lastAuraState = 0; // save last aura state to track changes on aura/aura2 command
}
var simpleEffects = [
EffectConst.EF_LEVEL99_3
];

/**
* Show aura
*/
Aura.prototype.load = function load( effectManager )
{
// check if qualifies for aura and /aura2 preference
if( MapPreferences.aura > 0 && this.entity.clevel >= 99) {
// check if entity is visible
if(this.entity.isVisible()) {
// check if aura state has changed
if(this.lastAuraState !== MapPreferences.aura && this.isLoaded)
this.remove( effectManager );
if(!this.isLoaded) {
// aura is already loaded
// select effects based on /aura preference
var effects = MapPreferences.aura < 2 ? simpleEffects : normalEffects;
// add aura effects
for (let effectIndex = 0; effectIndex < effects.length; effectIndex++) {
effectManager.spam( {
ownerAID: this.entity.GID,
position: this.entity.position,
effectId: effects[effectIndex]
} );
/**
* Aura class
*
* @constructor
* @param {object} entity
*/
function Aura(entity) {
this.isLoaded = false; // to avoid duplicate aura effects
this.entity = entity; // reference to attached entity
this.lastAuraState = 0; // save last aura state to track changes on aura/aura2 command
}

/**
* Show aura
*/
Aura.prototype.load = function load(effectManager) {
var server = Configs.getServer(); // find aura from servers config

/** @type {TAuraSettings} - merge server aura config with default settings */
var settings = server != null ? Object.assign({}, _auraSettings, server.aura) : Object.assign({}, _auraSettings);

// check if qualifies for aura and /aura2 preference
if (MapPreferences.aura > 0 && this.entity.clevel >= settings.defaultLv) {
// check if entity is visible
if (this.entity.isVisible()) {
// check if aura state has changed
if (this.lastAuraState !== MapPreferences.aura && this.isLoaded) {
this.remove(effectManager);
}
if (!this.isLoaded) {
// aura is already loaded
// select effects based on /aura preference
var effects = MapPreferences.aura < 2 ? simpleEffects : normalEffects;
// add aura effects
for (let effectIndex = 0; effectIndex < effects.length; effectIndex++) {
effectManager.spam({
ownerAID: this.entity.GID,
position: this.entity.position,
effectId: effects[effectIndex]
});
}
// set flag to avoid duplicate aura effects
this.isLoaded = true;
// save current aura state
this.lastAuraState = MapPreferences.aura;
}
// set flag to avoid duplicate aura effects
this.isLoaded = true;
// save current aura state
this.lastAuraState = MapPreferences.aura;
} else {
// remove aura if entity is invisible
this.remove(effectManager);
}
} else {
// remove aura if entity is invisible
this.remove( effectManager );
} else if (this.isLoaded) {
// remove aura if entity does not qualify
this.remove(effectManager);
// save current aura state
this.lastAuraState = MapPreferences.aura;
}
} else if (this.isLoaded) {
// remove aura if entity does not qualify
this.remove( effectManager );
// save current aura state
this.lastAuraState = MapPreferences.aura;
}
};
};

/**
* Hide aura
*/
Aura.prototype.remove = function remove( effectManager )
{
// remove aura effects
effectManager.remove( null, this.entity.GID, normalEffects );
// free aura - needs to be separate to avoid circular dependency
this.free();
};
/**
* Hide aura
*/
Aura.prototype.remove = function remove(effectManager) {
// remove aura effects
effectManager.remove(null, this.entity.GID, normalEffects);
// free aura - needs to be separate to avoid circular dependency
this.free();
};

/**
* Hide aura
*/
Aura.prototype.free = function free()
{
// reset flag to allow aura to be loaded
this.isLoaded = false;
};
/**
* Hide aura
*/
Aura.prototype.free = function free() {
// reset flag to allow aura to be loaded
this.isLoaded = false;
};

/**
* Export
*/
return function init()
{
this.aura = new Aura(this);
};
});
/**
* Export
*/
return function init() {
this.aura = new Aura(this);
};
});

0 comments on commit ca95767

Please sign in to comment.