Skip to content

Commit

Permalink
Merge pull request #203 from damian-pastorini/v4.0.0-beta.26
Browse files Browse the repository at this point in the history
- Reldens - v4.0.0-beta.26
  • Loading branch information
damian-pastorini authored May 9, 2023
2 parents e157e4d + 23b2592 commit 2db7108
Show file tree
Hide file tree
Showing 190 changed files with 9,833 additions and 2,306 deletions.
7 changes: 5 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ RELDENS_DB_LIMIT=0
# RELDENS_STORAGE_DRIVER=mikro-orm
RELDENS_STORAGE_DRIVER=objection-js
# Logs:
RELDENS_LOG_LEVEL=1
# RELDENS_ENABLE_TRACE_FOR=
RELDENS_LOG_LEVEL=9
RELDENS_ENABLE_TRACE_FOR="emergency,alert,critical,error,warning"
# Mailer:
RELDENS_MAILER_ENABLE=0
RELDENS_MAILER_SERVICE=gmail
Expand All @@ -53,6 +53,9 @@ RELDENS_MAILER_FROM=youremail@gmail.com
# RELDENS_ON_BUNDLE_COPY_ASSETS=1
# Use Express to serve static files already bundled.
RELDENS_EXPRESS_SERVE_STATICS=1
# Game Server:
RELDENS_PING_INTERVAL=5000
RELDENS_PING_MAX_RETRIES=3
# Admin:
RELDENS_ADMIN_SECURE_LOGIN=1
RELDENS_ADMIN_ROUTE_PATH="/reldens-admin"
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/.env
/.idea
/knexfile.js
/migrations/*
!/migrations/production
/node_modules
/npm-debug*
/test
Expand Down
41 changes: 22 additions & 19 deletions lib/actions/client/preloader-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

const { Logger, sc } = require('@reldens/utils');
const { GameConst } = require('../../game/constants');

class PreloaderHandler
{
Expand Down Expand Up @@ -100,8 +101,8 @@ class PreloaderHandler
if(sc.hasOwn(data.animationData, ['type', 'img']) && 'spritesheet' === data.animationData.type){
this.preloadAnimationsInDirections(data, uiScene);
}
if(data.classKey && sc.isFunction(data.classKey, 'prepareAnimation')){
data.classKey.prepareAnimation({data, uiScene, pack: this});
if(data.classKey && sc.isFunction(data.classKey['prepareAnimation'])){
data.classKey['prepareAnimation']({data, uiScene, pack: this});
}
}

Expand Down Expand Up @@ -144,24 +145,26 @@ class PreloaderHandler
{
if(sc.hasOwn(data.animationData, ['type', 'img']) && data.animationData.type === 'spritesheet'){
let animDir = sc.get(data.animationData, 'dir', 0);
if(0 < animDir){
// @TODO - BETA - Refactor and implement animDir = 1 (both): up_right, up_left, down_right,
// down_left.
uiScene.directionalAnimations[this.getAnimationKey(data)] = data.animationData.dir;
if(animDir === 1 || animDir === 2){
this.createWithDirection(data, uiScene, 'up');
this.createWithDirection(data, uiScene, 'down');
}
if(animDir === 1 || animDir === 3){
this.createWithDirection(data, uiScene, 'left');
this.createWithDirection(data, uiScene, 'right');
}
} else {
this.createWithDirection(data, uiScene);
}
0 < animDir
? this.createWithMultipleDirections(uiScene, data, animDir)
: this.createWithDirection(data, uiScene);
}
if(data.classKey && sc.isFunction(data.classKey['createAnimation'])){
data.classKey['createAnimation']({data, uiScene, pack: this});
}
if(data.classKey && sc.isFunction(data.classKey, 'createAnimation')){
data.classKey.createAnimation({data, uiScene, pack: this});
}

createWithMultipleDirections(uiScene, data, animDir) {
// @TODO - BETA - Refactor and implement animDir = 1 (both): up_right, up_left, down_right,
// down_left.
uiScene.directionalAnimations[this.getAnimationKey(data)] = data.animationData.dir;
if(1 === animDir || 2 === animDir){
this.createWithDirection(data, uiScene, GameConst.UP);
this.createWithDirection(data, uiScene, GameConst.DOWN);
}
if(1 === animDir || 3 === animDir){
this.createWithDirection(data, uiScene, GameConst.LEFT);
this.createWithDirection(data, uiScene, GameConst.RIGHT);
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/actions/client/skills-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class SkillsUi

createUiBox(codeName, depth)
{
// @TODO - BETA - Replace by UserInterface.
let {uiX, uiY} = this.uiScene.getUiConfig(codeName);
let generatedUi = this.uiScene.add.dom(uiX, uiY).createFromCache(codeName);
generatedUi.setDepth(depth);
Expand Down
24 changes: 12 additions & 12 deletions lib/actions/server/player-enricher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

const { Pvp } = require('./pvp');
const { SkillsExtraData } = require('./skills/skills-extra-data');
const { ClientWrapper } = require('../../game/server/client-wrapper');
const { Logger, sc } = require('@reldens/utils');
const { SkillConst } = require('@reldens/skills');
const { ClientWrapper } = require('../../game/server/client-wrapper');
const SkillsServer = require('@reldens/skills/lib/server');

class PlayerEnricher
Expand All @@ -29,6 +29,7 @@ class PlayerEnricher
if(!classPath){
continue;
}
// @TODO - BETA - Make label configurable.
player.additionalLabel = ' - LvL '+classPath.currentLevel+' - '+classPath.owner_full_class_path.label;
player.currentClassPathLabel = player.avatarKey = classPath.owner_full_class_path.key;
}
Expand All @@ -51,7 +52,7 @@ class PlayerEnricher
{
return async (target, executedSkill) => {
let messageData = Object.assign({skillKey: executedSkill.key}, executedSkill.owner.getPosition());
if(sc.isFunction(executedSkill.owner, 'getSkillExtraData')){
if(sc.isObjectFunction(executedSkill.owner, 'getSkillExtraData')){
let params = {skill: executedSkill, target};
Object.assign(messageData, {extraData: executedSkill.owner.getSkillExtraData(params)});
}
Expand All @@ -63,27 +64,27 @@ class PlayerEnricher
);
let from = {x: currentPlayer.state.x, y: currentPlayer.state.y};
executedSkill.initialPosition = from;
let to = {x: target.state.x, y: target.state.y};
let animData = sc.get(room.config.client.skills.animations, executedSkill.key + '_bullet', false);
if(animData){
executedSkill.animDir = sc.get(animData.animationData, 'dir', false);
}
// player disconnection would cause the physicalBody to be removed, so we need to validate it:
if(currentPlayer.physicalBody){
if(!currentPlayer.physicalBody.world){
Logger.error('PhysicalBody world is null.', currentPlayer.physicalBody.id);
return false;
}
currentPlayer.physicalBody.world.shootBullet(from, to, executedSkill);
let physicalBody = currentPlayer.physicalBody;
if(!physicalBody){
Logger.info('Player body is missing.');
return false;
}
if(!physicalBody.world){
Logger.error('Player body world is missing. Body ID: '+ physicalBody.id);
return false;
}
return false;
physicalBody.world.shootBullet(from, {x: target.state.x, y: target.state.y}, executedSkill);
};
}

static async withSkillsServerAndClassPath(props)
{
let {client, currentPlayer, room, skillsModelsManager, dataServer, events} = props;
// prepare player classPath and skills data:
let classPathData = await skillsModelsManager.prepareClassPathData(
currentPlayer,
'player_id',
Expand All @@ -100,7 +101,6 @@ class PlayerEnricher
affectedProperty: room.config.get('client/actions/skills/affectedProperty'),
client: new ClientWrapper({client, room})
});
// append skills server to player:
currentPlayer.skillsServer = new SkillsServer(classPathData);
currentPlayer.avatarKey = classPathData.key;
}
Expand Down
19 changes: 13 additions & 6 deletions lib/actions/server/pve.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Pve extends Battle
{
// @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 how the current enemy-object was implemented, for example the PVE can start when the player just
// depending on how the current enemy-object was implemented, for example the PVE can start when the player just
// collides with the enemy (instead of attack it) an aggressive enemy could start the battle automatically.
let attackResult = await super.runBattle(playerSchema, target, roomScene);
await this.events.emit('reldens.runBattlePveAfter', {playerSchema, target, roomScene, attackResult});
Expand All @@ -39,17 +39,23 @@ class Pve extends Battle
// attack for which matter we won't start the battle until the physical body hits the target.
return false;
}
0 < target.stats[roomScene.config.get('client/actions/skills/affectedProperty')]
? await this.startBattleWith(playerSchema, roomScene)
// physical attacks or effects will run the battleEnded, normal attacks or effects will hit this case:
: await this.battleEnded(playerSchema, roomScene);
if(0 < target.stats[roomScene.config.get('client/actions/skills/affectedProperty')]){
return await this.startBattleWith(playerSchema, roomScene);
}
// physical attacks or effects will run the battleEnded, normal attacks or effects will hit this case:
return await this.battleEnded(playerSchema, roomScene);
}

async startBattleWith(playerSchema, room)
{
// @TODO - BETA - Yeah... a lot could happen and this could be improved by cleaning the timers on specific
// actions like when player disconnects.
if(!room || !room.roomWorld || !playerSchema || !room.state || !room.playerByIdFromState(playerSchema.sessionId)){
if(
!room?.roomWorld
|| !room?.state
|| !playerSchema
|| !room.playerBySessionIdFromState(playerSchema.sessionId)
){
// @NOTE: leaveBattle is used for when the player can't be reached anymore or disconnected.
this.leaveBattle(playerSchema);
return false;
Expand Down Expand Up @@ -165,6 +171,7 @@ class Pve extends Battle
await this.targetObject.respawn(room);
this.sendBattleEndedActionData(room, playerSchema, actionData);
await this.events.emit(this.targetObject.getBattleEndEvent(), playerSchema, this, actionData);
await this.events.emit('reldens.battleEnded', {playerSchema, pve: this, actionData, room});
}

sendBattleEndedActionData(room, playerSchema, actionData)
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/server/skills/type-physical-attack.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class TypePhysicalAttack extends PhysicalAttack
// we already validate if one of the bodies is a bullet so the other will be always a player or an object:
let playerId = sc.get(props[defenderBodyKey], 'playerId', null);
if(null !== playerId){
return this.room.playerByIdFromState(playerId);
return this.room.playerBySessionIdFromState(playerId);
}
return props[defenderBodyKey].roomObject;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/server/skills/type-physical-effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class TypePhysicalEffect extends PhysicalEffect
{
// we already validate if one of the bodies is a bullet so the other will be always a player or an object:
return sc.hasOwn(props[defenderBodyKey], 'playerId') ?
this.room.playerByIdFromState(props[defenderBodyKey].playerId) : props[defenderBodyKey].roomObject;
this.room.playerBySessionIdFromState(props[defenderBodyKey].playerId) : props[defenderBodyKey].roomObject;
}

removeBullet(body)
Expand Down
10 changes: 8 additions & 2 deletions lib/audio/client/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ class AudioManager
{
let soundConfig = Object.assign({}, this.defaultAudioConfig, (audio.config || {}));
if(!sc.hasOwn(onScene.cache.audio.entries.entries, audio.audio_key)){
Logger.error('Audio file does not exists. Audio key:', audio.audio_key);
Logger.error(
'Audio file does not exists. Audio key: ' + audio.audio_key,
onScene.cache.audio.entries.entries
);
return false;
}
let audioInstance = onScene.sound.add(audio.audio_key, soundConfig);
Expand Down Expand Up @@ -170,7 +173,10 @@ class AudioManager
continue;
}
let audioLoader = currentScene.load.audio(audio.audio_key, filesArr);
audioLoader.on('complete', async () => {
audioLoader.on('filecomplete', async (completedFileKey) => {
if(completedFileKey !== audio.audio_key){
return false;
}
let generateAudio = this.generateAudio(currentScene, audio);
if(false === generateAudio){
Logger.error('AudioLoader can not generate the audio.', {
Expand Down
10 changes: 3 additions & 7 deletions lib/chat/cleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
*
* Reldens - Cleaner
*
* Clean chat messages.
*
*/

const { sc } = require('@reldens/utils');

class Cleaner
{

cleanMessage(message, characterLimit)
{
// @TODO - BETA - Implement any clean feature here.
let text = message.toString().replace(/\\/g, '');
if(0 < characterLimit){
return text.substring(0, characterLimit);
}
return text;
return sc.cleanMessage(message, characterLimit);
}

}
Expand Down
7 changes: 5 additions & 2 deletions lib/chat/client/chat-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ChatUi

createUi()
{
// @TODO - BETA - Replace by UserInterface.
let {uiX, uiY} = this.uiScene.getUiConfig('chat');
this.uiChat = this.uiScene.add.dom(uiX, uiY).createFromCache('chat');
this.uiScene.elementsUi['chat'] = this.uiChat;
Expand Down Expand Up @@ -179,6 +180,8 @@ class ChatUi
box.classList.remove('hidden');
this.uiChat.setDepth(4);
this.chatOpenButton?.classList.add('hidden');
let readPanel = this.uiChat.getChildByProperty('id', ChatConst.CHAT_MESSAGES);
readPanel.scrollTo(0, readPanel.scrollHeight);
this.hideNotificationsBalloon();
}

Expand Down Expand Up @@ -245,9 +248,9 @@ class ChatUi
}
if(!this.uiChat.getChildByProperty('id', ChatConst.CHAT_UI).classList.contains('hidden')){
readPanel.scrollTo(0, readPanel.scrollHeight);
} else {
this.showNotificationBalloon();
return;
}
this.showNotificationBalloon();
}

isValidMessageType(messageType)
Expand Down
7 changes: 6 additions & 1 deletion lib/chat/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ module.exports.ChatConst = {
CHAT_SYSTEM: 's',
CHAT_PRIVATE: 'p',
CHAT_DAMAGE: 'd',
CHAT_REWARD: 'r',
CHAT_SKILL: 'ss',
CHAT_TEAMS: 'ct',
// @TODO - BETA - Refactor to CHAT_TYPE: {}
CHAT_TYPE_NORMAL: 'ctn',
CHAT_TYPE_PRIVATE_FROM: 'ctpf',
Expand All @@ -36,6 +38,8 @@ module.exports.ChatConst = {
CHAT_TYPE_SYSTEM_ERROR: 'ctse',
CHAT_TYPE_SYSTEM_BATTLE: 'ctse',
CHAT_TYPE_SYSTEM_BATTLE_MODIFIERS: 'ctsem',
CHAT_TYPE_REWARD: 'ctr',
CHAT_TYPE_TEAMS: 'ctt',
// @TODO - BETA - Refactor to COLORS.
colors: {
ctn: '#ffffff',
Expand All @@ -50,6 +54,7 @@ module.exports.ChatConst = {
MESSAGES: {
ON: ' on ',
HIT_ON: ' hit on ',
DODGED: ' dodged '
DODGED: ' dodged ',
REWARD: 'You obtained %dropQuantity %itemLabel'
}
};
1 change: 0 additions & 1 deletion lib/chat/server/event-listener/npc-skills.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class NpcSkills
this.listenDamageEvent(attackSkill, chatConfig, chatManager);
this.listenModifiersEvent(effectSkill, chatConfig, chatManager);
this.listenAfterRunLogicEvent((attackSkill || effectSkill), chatConfig, chatManager);

}

static listenDamageEvent(attackSkill, chatConfig, chatManager)
Expand Down
2 changes: 1 addition & 1 deletion lib/chat/server/message-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

const { ChatManager } = require('./manager');
const { Cleaner } = require('../cleaner');
const { Logger, sc } = require('@reldens/utils');
const { ChatConst } = require('../constants');
const { GameConst } = require('../../game/constants');
const { Logger, sc } = require('@reldens/utils');

class ChatMessageActions
{
Expand Down
6 changes: 3 additions & 3 deletions lib/chat/server/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class ChatPlugin extends PluginInterface
setup(props)
{
this.events = sc.get(props, 'events', false);
if(!this.events){
if (!this.events) {
Logger.error('EventsManager undefined in ChatPlugin.');
}
this.dataServer = sc.get(props, 'dataServer', false);
if(!this.dataServer){
if (!this.dataServer) {
Logger.error('DataServer undefined in ChatPlugin.');
}
this.chatManager = new ChatManager({dataServer: this.dataServer});
Expand All @@ -31,7 +31,7 @@ class ChatPlugin extends PluginInterface
// then we can use the event manager to append the feature in every action required:
this.events.on('reldens.roomsDefinition', (roomsList) => {
// here we are adding the chat room to be defined in the game server:
roomsList.push({roomName: 'chat', room: RoomChat});
roomsList.push({ roomName: 'chat', room: RoomChat });
});
this.events.on('reldens.serverConfigFeaturesReady', (props) => {
this.chatConfig = props.configProcessor.get('client/ui/chat');
Expand Down
Loading

0 comments on commit 2db7108

Please sign in to comment.