Skip to content

Commit e049435

Browse files
committed
Stream progress!
1 parent 50667c0 commit e049435

File tree

11 files changed

+123
-21
lines changed

11 files changed

+123
-21
lines changed

src/game-engine/net/outbound-packets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class OutboundPackets {
126126

127127
chunkUpdates.forEach(update => {
128128
if(update.type === 'ADD') {
129-
if(update.object) {
129+
if(update.object && !update.object.reference) {
130130
const offset = this.getChunkPositionOffset(update.object.x, update.object.y, chunk);
131131
packet.put(241, 'BYTE');
132132
packet.put((update.object.type << 2) + (update.object.orientation & 3));

src/game-engine/world/action/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ export class ActionPipeline {
166166
await this.actor.waitForPathing(
167167
!gameObject ? runnableHooks.actionPosition : (gameObject as LandscapeObject));
168168
} catch(error) {
169-
logger.error(`Error pathing to hook target`, error);
169+
logger.error(`Error pathing to hook target`);
170+
logger.error(error);
170171
return;
171172
}
172173
}

src/game-engine/world/action/object-interaction.action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type objectInteractionActionHandler = (objectInteractionAction: ObjectInt
2727

2828

2929
/**
30-
* Details about an npc action being performed.
30+
* Details about an object action being performed.
3131
*/
3232
export interface ObjectInteractionAction {
3333
// The player performing the action.

src/game-engine/world/actor/actor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export abstract class Actor {
9393
*/
9494
public async waitForPathing(target: Position | LandscapeObject): Promise<void>;
9595
public async waitForPathing(target: Position | LandscapeObject): Promise<void> {
96+
console.log(target);
9697
if(this.position.withinInteractionDistance(target)) {
9798
return;
9899
}

src/game-engine/world/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { loadActionFiles } from '@engine/world/action';
1919
import { LandscapeObject } from '@runejs/filestore';
2020
import { lastValueFrom, Subject } from 'rxjs';
2121
import { take } from 'rxjs/operators';
22-
import { ConstructedRegion, getRotatedLocalX, getRotatedLocalY } from '@engine/world/map/region';
22+
import { ConstructedRegion, getTemplateLocalX, getTemplateLocalY } from '@engine/world/map/region';
2323
import { Chunk } from '@engine/world/map/chunk';
2424

2525

@@ -174,10 +174,23 @@ export class World {
174174
const mapTemplateWorldY = tileY;
175175
const mapTemplateChunk = world.chunkManager.getChunkForWorldPosition(new Position(mapTemplateWorldX, mapTemplateWorldY, objectPosition.level));
176176

177-
const templateObjectPosition = new Position(mapTemplateWorldX + getRotatedLocalX(tileOrientation, objectLocalX, objectLocalY),
178-
mapTemplateWorldY + getRotatedLocalY(tileOrientation, objectLocalX, objectLocalY), objectPosition.level);
177+
const templateObjectPosition = new Position(mapTemplateWorldX + getTemplateLocalX(tileOrientation, objectLocalX, objectLocalY),
178+
mapTemplateWorldY + getTemplateLocalY(tileOrientation, objectLocalX, objectLocalY), objectPosition.level);
179179
const realObject = mapTemplateChunk.getFilestoreLandscapeObject(objectId, templateObjectPosition);
180180

181+
realObject.x = objectPosition.x;
182+
realObject.y = objectPosition.y;
183+
realObject.level = objectPosition.level;
184+
185+
let rotation = realObject.orientation + objectTile.rotation;
186+
if(rotation > 3) {
187+
rotation -= 4;
188+
}
189+
190+
console.log(realObject.orientation, rotation);
191+
192+
realObject.orientation = rotation;
193+
181194
return realObject || null;
182195
}
183196

src/game-engine/world/instances.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,18 @@ export class WorldInstance {
324324
/**
325325
* Spawn a new game object into the instance.
326326
* @param object The game object to spawn.
327+
* @param reference Whether or not the object being spawned is a reference to an existing object or if it should
328+
* be sent to the game client for forced rendering. Defaults to false for forced rendering.
327329
*/
328-
public spawnGameObject(object: LandscapeObject): void {
330+
public spawnGameObject(object: LandscapeObject, reference: boolean = false): void {
329331
const position = new Position(object.x, object.y, object.level);
330332

331333
const { chunk: instancedChunk, mods } = this.getTileModifications(position);
332334

335+
if(mods.spawnedObjects.find(o => o.x === object.x && o.y === object.y && o.level === object.level && o.type === object.type)) {
336+
return;
337+
}
338+
333339
mods.spawnedObjects.push(object);
334340
instancedChunk.mods.set(position.key, mods);
335341

src/game-engine/world/map/chunk-manager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ export class ChunkManager {
164164
}
165165

166166
const pos = (position as Position);
167-
168167
if(this.chunkMap.has(pos.key)) {
169168
return this.chunkMap.get(pos.key);
170169
} else {

src/game-engine/world/map/chunk.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import { WorldItem } from '@engine/world/items/world-item';
77
import { LandscapeObject } from '@runejs/filestore';
88

99

10+
interface CustomLandscapeObject {
11+
reference?: boolean;
12+
}
13+
1014
export interface ChunkUpdateItem {
11-
object?: LandscapeObject;
15+
object?: LandscapeObject & CustomLandscapeObject;
1216
worldItem?: WorldItem;
1317
type: 'ADD' | 'REMOVE';
1418
}

src/game-engine/world/map/region.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,43 @@ export interface ConstructedRegion {
5050
}
5151

5252

53-
export const getRotatedLocalX = (orientation: number, localX: number, localY: number): number => {
53+
54+
export const getTemplateRotatedX = (orientation: number, localX: number, localY: number): number => {
55+
if(orientation === 0) {
56+
return localX;
57+
}
58+
if(orientation === 1) {
59+
if(localX === 7) {
60+
return localY;
61+
} else {
62+
return 7 - localY;
63+
}
64+
}
65+
if(orientation === 2) {
66+
if(localY === 0) {
67+
return localX;
68+
} else {
69+
return 7 - localX;
70+
}
71+
}
72+
return localY;
73+
};
74+
75+
export const getTemplateRotatedY = (orientation: number, localX: number, localY: number): number => {
76+
if(orientation === 0) {
77+
return localY;
78+
}
79+
if(orientation === 1) {
80+
return localX;
81+
}
82+
if(orientation === 2) {
83+
return 7 - localY;
84+
}
85+
return 7 - localX;
86+
};
87+
88+
89+
export const getTemplateLocalX = (orientation: number, localX: number, localY: number): number => {
5490
if(orientation === 0) {
5591
return localX;
5692
}
@@ -71,7 +107,7 @@ export const getRotatedLocalX = (orientation: number, localX: number, localY: nu
71107
return localY;
72108
};
73109

74-
export const getRotatedLocalY = (orientation: number, localX: number, localY: number): number => {
110+
export const getTemplateLocalY = (orientation: number, localX: number, localY: number): number => {
75111
if(orientation === 0) {
76112
return localY;
77113
}

src/plugins/skills/construction/con-house.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ export class House {
1717
}
1818
}
1919

20-
public getRoom(position: Position): Room {
21-
return this.rooms[position.level][position.x][position.y];
22-
}
23-
2420
}
2521

2622

0 commit comments

Comments
 (0)