Skip to content

Commit

Permalink
Merge branch 'feature/combat'
Browse files Browse the repository at this point in the history
  • Loading branch information
orion3dgames committed Jul 22, 2024
2 parents 5e17f3b + ef55dc8 commit 35f139f
Show file tree
Hide file tree
Showing 42 changed files with 571 additions and 352 deletions.
Binary file modified construction/Icons/Abilities-Icons.afdesign
Binary file not shown.
Binary file modified construction/Marketing/GameDevBanner-1300x300.afdesign
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified construction/Models/Characters/rat_01.blend
Binary file not shown.
Binary file modified construction/Models/Characters/rat_01.blend1
Binary file not shown.
Binary file added public/images/icons/ICON_ABILITY_slice_attack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/models/races/rat.glb
Binary file not shown.
2 changes: 1 addition & 1 deletion public/models/races/vat/humanoid.json

Large diffs are not rendered by default.

Binary file modified public/sounds/heal_1.wav
Binary file not shown.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion src/client/Controllers/AssetsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ export class AssetsController {
// set list of assets
this.assetDatabase = [
// music
{ name: "MUSIC_01", filename: "music.mp3", extension: "mp3", type: "sound" },
{ name: "MUSIC_01", filename: "music_02.mp3", extension: "mp3", type: "sound" },

// sounds
{ name: "SOUND_player_walking", filename: "player_walking.wav", extension: "wav", type: "sound" },
{ name: "SOUND_fire_attack_1", filename: "fire_attack_1.wav", extension: "wav", type: "sound" },
{ name: "SOUND_hit_a", filename: "hit_a.wav", extension: "wav", type: "sound" },
{ name: "SOUND_hit_b", filename: "hit_b.wav", extension: "wav", type: "sound" },
{ name: "SOUND_heal_1", filename: "heal_1.wav", extension: "wav", type: "sound" },
{ name: "SOUND_dialog_close", filename: "dialog_close.wav", extension: "wav", type: "sound" },
{ name: "SOUND_dialog_open", filename: "dialog_open.wav", extension: "wav", type: "sound" },

Expand Down
4 changes: 2 additions & 2 deletions src/client/Controllers/SoundController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class SoundController {
() => {
this.sounds.set(key, sound);
sound.play();
console.log("[SOUND] playing " + key, sound);
//console.log("[SOUND] playing " + key, sound);
},
{
volume: this.volume,
Expand All @@ -32,7 +32,7 @@ export class SoundController {
);
} else {
this.sounds.get(key).play(loop);
console.log("[SOUND] playing from cache " + key);
//console.log("[SOUND] playing from cache " + key);
}
}
}
2 changes: 1 addition & 1 deletion src/client/Controllers/UI/DebugBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class DebugBox {
private _room;
private _currentPlayer;
private _entities;
private ping: number = 0;
public ping: number = 0;
public _debugPanel: Rectangle;
private _debugTextUI;
private instrumentation: SceneInstrumentation;
Expand Down
1 change: 1 addition & 0 deletions src/client/Controllers/UI/EntitySelectedBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export class EntitySelectedBar {
}

if (entity) {
//console.log('[UPDATE]', entity.name, entity.health);
this.setData(entity);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/client/Controllers/UI/MainMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ export class MainMenu {
this.takeScreenshot();
},
},
debug: {
menuTitle: "Debug Scene",
click: () => {
// leave colyseus rooms
this._room.leave();
this._game.currentChat.leave();
this._game.setScene(State.DEBUG_SCENE);
},
},
quit: {
menuTitle: "Quit",
click: () => {
Expand Down
1 change: 1 addition & 0 deletions src/client/Controllers/VatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class VatController {

async fetchVAT(key) {
const url = "./models/races/vat/" + key + ".json";
console.log(url);
const response = await fetch(url);
const movies = await response.json();
return movies;
Expand Down
11 changes: 9 additions & 2 deletions src/client/Entities/Common/MeshHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ const mergeMesh = function (mesh, key = "MERGED_") {
}
};

const mergeMeshAndSkeleton = function (mesh, skeleton) {
const mergeMeshAndSkeleton = function (mesh, skeleton, name = "_MergedModel") {
// pick what you want to merge
const allChildMeshes = mesh.getChildTransformNodes(true)[0].getChildMeshes(false);

// Ignore Backpack because pf different attributes
// https://forum.babylonjs.com/t/error-during-merging-meshes-from-imported-glb/23483
// https://forum.babylonjs.com/t/mesh-merging-error/43624
//const childMeshes = allChildMeshes.filter((m) => !m.name.includes("Backpack"));

/*
allChildMeshes.forEach(element => {
console.log(element.id, element.getVerticesDataKinds());
mesh.removeVerticesData(BABYLON.VertexBuffer.ColorKind)
});*/

// multiMaterial = true
const merged = Mesh.MergeMeshes(allChildMeshes, false, true, undefined, undefined, false);
if (merged) {
merged.name = "_MergedModel";
merged.name = name;
merged.skeleton = skeleton;
}
return merged;
Expand Down
2 changes: 1 addition & 1 deletion src/client/Entities/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class Entity extends TransformNode {

// if taking damage, show damage bubble
if (this.health !== this.entity.health) {
this.nameplateController.addDamageBubble();
this.nameplateController.addDamageBubble(0.2, this._ui._DebugBox.ping);
}

if (this.type === "player" && this.anim_state !== this.entity.anim_state) {
Expand Down
67 changes: 25 additions & 42 deletions src/client/Entities/Entity/EntityActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial";
import { Tools } from "@babylonjs/core/Misc/tools";
import { nanoid } from "nanoid";
import { GameScene } from "../../Screens/GameScene";
import { EntityState } from "../../../shared/types";

export class EntityActions {
private _gamescene: GameScene;
Expand Down Expand Up @@ -48,7 +49,7 @@ export class EntityActions {

// if intersect with target mesh then display impact
if (element.projectile.intersectsMesh(targetMesh, true)) {
this.particule_impact(targetMesh, element.color);
this.particule_impact(targetMesh, element.ability);
element.projectile.dispose(true, true);
element.particleSystem.dispose(true);
element.particleSystemTrail.dispose(true);
Expand All @@ -58,32 +59,35 @@ export class EntityActions {
}

public process(player, data, ability) {
/*
let soundToPlay = this._scene.getSoundByName("sound_"+ability.key);
if(!soundToPlay){
// play sound
let soundData = this._loadedAssets[ability.sound];
let sound = new Sound("sound_"+ability.key, soundData, this._scene, function(){ sound.play(); }, {
volume: 0.3
});
}
*/

//
let source = this._entities.get(data.fromId);
let target = this._entities.get(data.targetId);

// play sound
setTimeout(() => {
this._gamescene._sound.play("SOUND_" + ability.sound);
}, ability.soundDelay);

// set effect
if (ability.effect.type === "target") {
//source.anim_state = EntityState.ATTACK;
}

// set effect
if (ability.effect.particule === "fireball") {
this.particule_fireball(source, target, ability.effect.color);
this.particule_fireball(source, target, ability);
}

if (ability.effect.particule === "heal") {
this.particule_heal(target, ability.effect.color);
this.particule_heal(target, ability);
}
}

public particule_impact(mesh, color) {
public particule_impact(mesh, ability) {
let color = ability.effect.color;

this._gamescene._sound.play("SOUND_hit_a");

//////////////////////////////////////////////
// create a particle system
var particleSystem = new ParticleSystem("particles", 1000, this._scene);
Expand Down Expand Up @@ -115,7 +119,9 @@ export class EntityActions {
//
}

public particule_heal(target, color) {
public particule_heal(target, ability) {
let color = ability.effect.color;

// get mesh
let mesh = target.mesh;

Expand Down Expand Up @@ -160,11 +166,9 @@ export class EntityActions {
//
}

public particule_fireball(source, target, color) {
// play sound
this._gamescene._sound.play("SOUND_fire_attack_1");

public particule_fireball(source, target, ability) {
// get local position
let color = ability.effect.color;
let start = source.getPosition();
let end = target.getPosition();

Expand Down Expand Up @@ -239,33 +243,12 @@ export class EntityActions {
//
this.projectiles.set(nanoid(), {
color: color,
ability: ability,
source: source,
target: target,
projectile: projectile,
particleSystem: particleSystem,
particleSystemTrail: particleSystemTrail,
});

/*
projectile.lookAt(end);
projectile.rotate(new Vector3(0, 1, 0), Tools.ToRadians(180));
var endVector = projectile.calcMovePOV(0, 0, 72).addInPlace(projectile.position);
var points = [start, endVector];
var path = new Path3D(points);
var i = 0;
var loop = this._scene.onBeforeRenderObservable.add(() => {
if (i < 1) {
projectile.position = path.getPointAt(i);
i += 0.005;
}
if (projectile.intersectsMesh(mesh, true) || i > 1) {
this.particule_impact(mesh, color);
projectile.dispose(true, true);
particleSystem.dispose(true);
particleSystemTrail.dispose(true);
this._scene.onBeforeRenderObservable.remove(loop);
}
});
*/
}
}
84 changes: 45 additions & 39 deletions src/client/Entities/Entity/EntityAnimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class EntityAnimator {
private ratio;

//animations
private _playerAnimations: AnimationGroup[];
private _animations = [];
private _idle;
private _walk;
private _attack;
Expand Down Expand Up @@ -50,49 +50,37 @@ export class EntityAnimator {
}

public refreshAnimationRatio() {
/*
this.ratio = this._entity._scene.getAnimationRatio();
// set animation speed
this._idle.speedRatio = this.entityData.animations["IDLE"].speed * this.ratio;
this._walk.speedRatio = this.entityData.animations["WALK"].speed * this.ratio;
this._attack.speedRatio = this.entityData.animations["ATTACK"].speed * this.ratio;
this._death.speedRatio = this.entityData.animations["DEATH"].speed * this.ratio;
*/
}

private _build(): void {
this._attack = {
name: "ATTACK",
index: 0,
loop: true,
speed: 1,
ranges: this.entityData.animationRanges[0],
};

this._death = {
name: "DEATH",
index: 1,
loop: false,
speed: 1,
ranges: this.entityData.animationRanges[1],
};

this._idle = {
name: "IDLE",
index: 2,
loop: true,
speed: 1,
ranges: this.entityData.animationRanges[2],
// build animation list and properties
let animations = this._entity.raceData.vat.animations ?? [];
let i = 0;
for(let key in animations){
let anim = animations[key];
anim.key = key;
anim.index = i;
anim.ranges = this.entityData.animationRanges[i],
this._animations[key] = anim;
i++;
};

this._walk = {
name: "WALK",
index: 3,
loop: true,
speed: 1,
ranges: this.entityData.animationRanges[3],
};
// set default animation
this._currentAnim = this.getAnimation('IDLE');
this._prevAnim = this.getAnimation('WALK');
}

this._currentAnim = this._idle;
this._prevAnim = this._walk;
getAnimation(key){
return this._animations[key];
}

// This method will compute the VAT offset to use so that the animation starts at frame #0 for VAT time = time passed as 3rd parameter
Expand Down Expand Up @@ -127,33 +115,51 @@ export class EntityAnimator {

// determine what animation should be played
public animate(entity): void {

let currentPos = entity.getPosition();
let nextPos = entity.moveController.getNextPosition();
entity.isMoving = false;

// if player has died
if (entity.anim_state === EntityState.DEAD) {
this._currentAnim = this._death;
this._currentAnim = this.getAnimation('DEATH');

// if player is attacking
} else if (entity.anim_state === EntityState.ATTACK_VERTICAL) {
this._currentAnim = this.getAnimation('ATTACK');

// if player is attacking
} else if (entity.anim_state === EntityState.UNARMED) {
this._currentAnim = this.getAnimation('UNARMED');

// if player is attacking
} else if (entity.anim_state === EntityState.ATTACK_HORIZONTAL) {
this._currentAnim = this.getAnimation('ATTACK_HORIZONTAL');

// if player is attacking
} else if (entity.anim_state === EntityState.SPELL_CASTING) {
this._currentAnim = this.getAnimation('SPELL_CASTING');

// if player is attacking
} else if (entity.anim_state === EntityState.ATTACK) {
this._currentAnim = this._attack;
} else if (entity.anim_state === EntityState.SPELL_CAST) {
this._currentAnim = this.getAnimation('SPELL_CAST');

// if player is moving
} else if (this.checkIfPlayerIsMoving(currentPos, nextPos) && entity.health > 0) {
//console.log("PLAYER IS STILL MOVING...");
this._currentAnim = this._walk;
this._currentAnim = this.getAnimation('WALK');
entity.isMoving = true;

// todo: I hate this, but I have no idea how to fix this in a better way at this stage...
/*
if (entity._input && !entity._input.player_can_move) {
this._currentAnim = this._idle;
this._currentAnim = this.getAnimation('IDLE');
entity.isMoving = false;
}
}*/

// else play idle
} else {
this._currentAnim = this._idle;
this._currentAnim = this.getAnimation('IDLE')
}
}

Expand Down Expand Up @@ -200,7 +206,7 @@ export class EntityAnimator {
this.setAnimationParameters(itemMesh.instancedBuffers.bakedVertexAnimationSettingsInstanced, this._currentAnim);
}

refreshAnimation(){
refreshAnimation() {
this._prevAnim = false;
}
}
Loading

0 comments on commit 35f139f

Please sign in to comment.