Skip to content

Commit 092ea73

Browse files
author
Dennis Koluris
committed
Update environment
1 parent 3fd81c6 commit 092ea73

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

src/GameServer/Actor/Actor.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@ class Actor extends ActorModel {
1212
this.skillset = new Skillset();
1313
this.backpack = new Backpack();
1414
this.automation = new Automation();
15+
1516
this.session = session;
17+
this.previousXY = undefined;
1618
}
1719

1820
destructor() {
1921
}
2022

23+
// Request packets
24+
25+
enterWorld() {
26+
invoke(path.actor).enterWorld(
27+
this.session, this
28+
);
29+
}
30+
2131
moveTo(data) {
2232
invoke(path.actor).moveTo(
2333
this.session, this, data
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function enterWorld(session, actor) {
2+
const Components = invoke(path.actor);
3+
4+
// Show NPCs based on radius
5+
Components.updatePosition(session, actor, {
6+
locX: actor.fetchLocX(),
7+
locY: actor.fetchLocY(),
8+
locZ: actor.fetchLocZ(),
9+
head: actor.fetchHead(),
10+
});
11+
}
12+
13+
module.exports = enterWorld;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const ServerResponse = invoke('GameServer/Network/Send');
2+
const World = invoke('GameServer/World/World');
3+
const SpeckMath = invoke('GameServer/SpeckMath');
4+
5+
function updateEnvironment(session, actor) {
6+
const actorArea = new SpeckMath.Circle(actor.fetchLocX(), actor.fetchLocY(), 5000);
7+
const npcs = World.npc.spawns.filter((ob) => ob.state.fetchDead() === false && actorArea.contains(new SpeckMath.Point(ob.fetchLocX(), ob.fetchLocY()))) ?? [];
8+
9+
if (new SpeckMath.Point(this.previousXY?.locX ?? 0, this.previousXY?.locY ?? 0).distance(new SpeckMath.Point(actor.fetchLocX(), actor.fetchLocY())) >= 1000) {
10+
npcs.forEach((npc) => { // Gives a sense of random NPC Animation to the actor
11+
setTimeout( () => { session.dataSend(ServerResponse.npcInfo(npc)); }, utils.randomNumber(2000));
12+
});
13+
14+
actor.previousXY = actorArea.toCoords();
15+
}
16+
}
17+
18+
module.exports = updateEnvironment;
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
const Database = invoke('Database');
2-
31
function updatePosition(session, actor, coords) {
2+
const Components = invoke(path.actor);
3+
4+
// TODO: Write less in DB about movement
45
actor.setLocXYZH(coords);
6+
7+
// Update Online users, NPCs, underwater locations
8+
Components.updateEnvironment(session, actor);
59
}
610

711
module.exports = updatePosition;
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module.exports = {
2-
moveTo: require('./MoveTo'),
3-
updatePosition: require('./UpdatePosition')
2+
enterWorld: require('./EnterWorld'),
3+
moveTo: require('./MoveTo'),
4+
updateEnvironment: require('./UpdateEnvironment'),
5+
updatePosition: require('./UpdatePosition')
46
};

0 commit comments

Comments
 (0)