Skip to content

Commit

Permalink
Rework some destroyables behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGruber committed Mar 12, 2024
1 parent 76f1804 commit ee72561
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
36 changes: 25 additions & 11 deletions src/servers/ZoneServer2016/entities/destroyable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import { Effects, ModelIds } from "../models/enums";
import { AddLightweightNpc, AddSimpleNpc } from "types/zone2016packets";
import { BaseSimpleNpc } from "./basesimplenpc";

function getDestroyedModels(actorModel: string): number[] {
switch (actorModel) {
case "Common_Props_GlassWindow01.adr":
function getDestroyedModels(actorModelId: ModelIds): number[] {
switch (actorModelId) {
case ModelIds.GLASS_WINDOW_01:
return [
ModelIds.GLASS_WINDOW_DESTROYED_1,
ModelIds.GLASS_WINDOW_DESTROYED_2,
ModelIds.GLASS_WINDOW_DESTROYED_3
];
case "Common_Props_TintedWindow01.adr":
case ModelIds.TINTED_WINDOW_01:
return [
ModelIds.TINTED_WINDOW_DESTROYED_1,
ModelIds.TINTED_WINDOW_DESTROYED_2,
Expand All @@ -37,6 +37,22 @@ function getDestroyedModels(actorModel: string): number[] {
}
}

function getMaxHealth(actorModelId: ModelIds): number {
switch (actorModelId) {
case ModelIds.GLASS_WINDOW_01:
case ModelIds.TINTED_WINDOW_01:
return 2000;
case ModelIds.FENCES_WOOD_PLANKS_GREY_PLANK:
case ModelIds.FENCES_WOOD_PLANKS_GREY_POSTS_1X1:
case ModelIds.FENCES_WOOD_PLANKS_GREY_1X1:
case ModelIds.FENCES_WOOD_PLANKS_GREY_POSTS_1X2:
case ModelIds.FENCES_WOOD_PLANKS_GREY_GAP_1X1:
return 7500;
default:
return 2000;
}
}

export class Destroyable extends BaseSimpleNpc {
spawnerId: number;
maxHealth: number;
Expand All @@ -47,23 +63,22 @@ export class Destroyable extends BaseSimpleNpc {
constructor(
characterId: string,
transientId: number,
actorModelId: number,
actorModelId: ModelIds,
position: Float32Array,
rotation: Float32Array,
server: ZoneServer2016,
scale: Float32Array,
zoneId: number,
renderDistance: number,
actorModel: string
renderDistance: number
) {
super(characterId, transientId, actorModelId, position, rotation, server);
this.spawnerId = zoneId;
this.scale = scale;
this.npcRenderDistance = renderDistance;
this.destroyedModels = getDestroyedModels(actorModel);
this.destroyedModels = getDestroyedModels(this.actorModelId);
this.destroyedModel =
this.destroyedModels[(this.destroyedModels.length * Math.random()) | 0];
this.maxHealth = actorModel.toLowerCase().includes("fence") ? 30000 : 2000;
this.maxHealth = getMaxHealth(actorModelId);
this.health = this.maxHealth;
}

Expand Down Expand Up @@ -108,10 +123,9 @@ export class Destroyable extends BaseSimpleNpc {
return true;
}

// eslint-disable-next-line
OnProjectileHit(server: ZoneServer2016, damageInfo: DamageInfo) {
if (this.destroyed) return;
this.destroy(server, true);
this.damage(server, damageInfo);
}

OnMeleeHit(server: ZoneServer2016, damageInfo: DamageInfo) {
Expand Down
3 changes: 1 addition & 2 deletions src/servers/ZoneServer2016/managers/worldobjectmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,7 @@ export class WorldObjectManager {
server,
new Float32Array(propInstance.scale),
propInstance.id,
Number(propType.renderDistance),
propType.actor_file
Number(propType.renderDistance)
);
server._destroyables[characterId] = obj;
server._destroyableDTOlist.push(propInstance.id);
Expand Down
9 changes: 8 additions & 1 deletion src/servers/ZoneServer2016/models/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export enum ModelIds {
CRATE_BOX_1 = 8013,
CRATE_BOX_2 = 9088,
BARELL_1 = 9387,
GLASS_WINDOW_01 = 8026,
TINTED_WINDOW_01 = 9432,
GLASS_WINDOW_DESTROYED_1 = 8027,
GLASS_WINDOW_DESTROYED_2 = 8028,
GLASS_WINDOW_DESTROYED_3 = 8029,
Expand Down Expand Up @@ -230,7 +232,12 @@ export enum ModelIds {
UPPER_LEVEL_LARGE_SHELTER = 9411,
STRUCTURE_STAIRS = 53,
TOWER = 9493,
DECK_FOUNDATION = 9130
DECK_FOUNDATION = 9130,
FENCES_WOOD_PLANKS_GREY_POSTS_1X2 = 8037,
FENCES_WOOD_PLANKS_GREY_POSTS_1X1 = 8036,
FENCES_WOOD_PLANKS_GREY_1X1 = 8033,
FENCES_WOOD_PLANKS_GREY_PLANK = 8035,
FENCES_WOOD_PLANKS_GREY_GAP_1X1 = 8034
}

export enum StringIds {
Expand Down

0 comments on commit ee72561

Please sign in to comment.