Skip to content

Commit

Permalink
remove: old resource system
Browse files Browse the repository at this point in the history
  • Loading branch information
Veradictus committed Sep 18, 2023
1 parent f9c9ee5 commit 124affe
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 744 deletions.
5 changes: 4 additions & 1 deletion packages/common/network/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export enum EntityType {
Pet,
LootBag,
Effect,
Tree
Tree,
Rock,
Foraging,
FishSpot
}

export enum Interfaces {
Expand Down
4 changes: 0 additions & 4 deletions packages/common/types/map.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,4 @@ export interface ProcessedMap {
obstructing?: number[];
areas: { [name: string]: ProcessedArea[] };
cursors: { [tileId: number]: string };
trees: ProcessedResource[];
rocks: ProcessedResource[];
fishSpots: ProcessedResource[];
foraging: ProcessedResource[];
}
23 changes: 2 additions & 21 deletions packages/server/src/game/entity/character/player/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import type World from '../../../world';
import type Area from '../../../map/areas/area';
import type Regions from '../../../map/regions';
import type Connection from '../../../../network/connection';
import type Resource from '../../../globals/impl/resource';
import type Minigame from '../../../minigames/minigame';
import type Entities from '../../../../controllers/entities';
import type Packet from '@kaetram/common/network/packet';
Expand Down Expand Up @@ -158,7 +157,6 @@ export default class Player extends Character {

// Region data
public regionsLoaded: number[] = [];
public resourcesLoaded: { [instance: string]: Modules.ResourceState } = {};
public lightsLoaded: number[] = [];

// NPC talking
Expand Down Expand Up @@ -1855,15 +1853,6 @@ export default class Player extends Character {
this.regionsLoaded.push(region);
}

/**
* Adds a resource to our loaded resource instances.
* @param resource The resource we are adding.
*/

public loadResource(resource: Resource): void {
this.resourcesLoaded[resource.instance] = resource.state;
}

/**
* @param region Region id of the region we are checking.
* @returns Whether or not the region has been added to the list of loaded regions.
Expand All @@ -1874,18 +1863,10 @@ export default class Player extends Character {
}

/**
* Checks if the resource is within our loaded resources and that the state matches.
* @param resource The resource we are chceking.
* @returns If the resource is loaded and the state matches.
* @param light The light that we are checking if it exists in the list of loaded lights.
* @returns Whether or not the light has been added to the list of loaded lights.
*/

public hasLoadedResource(resource: Resource): boolean {
return (
resource.instance in this.resourcesLoaded &&
this.resourcesLoaded[resource.instance] === resource.state
);
}

public hasLoadedLight(light: number): boolean {
return this.lightsLoaded.includes(light);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ResourceText from '@kaetram/common/text/en/resource';
import { Modules } from '@kaetram/common/network';

import type Player from '../../player';
import type Resource from '../../../../../globals/impl/resource';
import type Resource from '../../../../../entity/objects/resource/resource';

export default class Fishing extends ResourceSkill {
// We want to randomize the depletion of the fishing spots.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ForagingSpots from '../../../../../../../data/foraging.json';
import { Modules } from '@kaetram/common/network';

import type Player from '../../player';
import type Resource from '../../../../../globals/impl/resource';
import type Resource from '../../../../../entity/objects/resource/resource';
import type { ResourceInfo } from '@kaetram/common/types/resource';

export default class Foraging extends ResourceSkill {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ResourceText from '@kaetram/common/text/en/resource';
import { Modules } from '@kaetram/common/network';

import type Player from '../../player';
import type Resource from '../../../../../globals/impl/resource';
import type Resource from '../../../../../entity/objects/resource/resource';

export default class Mining extends ResourceSkill {
public constructor() {
Expand All @@ -25,7 +25,7 @@ export default class Mining extends ResourceSkill {

private handleExhaust(player: Player, resource?: Resource): void {
// Use the superclass logic to handle the random item selection.
super.handleRandomItems(player, Rocks[resource!.type as keyof typeof Rocks]);
super.handleRandomItems(player, Rocks[resource!.key as keyof typeof Rocks]);
}

/**
Expand Down
30 changes: 30 additions & 0 deletions packages/server/src/game/entity/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import type Player from './character/player/player';
import type { EntityData, EntityDisplayInfo } from '@kaetram/common/types/entity';
import type LootBag from './objects/lootbag';
import type Tree from './objects/resource/impl/tree';
import type Rock from './objects/resource/impl/rock';
import type FishSpot from './objects/resource/impl/fishspot';
import type Foraging from './objects/resource/impl/foraging';

type MovementCallback = (x: number, y: number) => void;

Expand Down Expand Up @@ -304,6 +307,33 @@ abstract class Entity {
return this.type === (Modules.EntityType.Tree as number);
}

/**
* Checks whether or not the entity is a rock.
* @returns Whether the type is equal to the EntityType rock.
*/

public isRock(): this is Rock {
return this.type === (Modules.EntityType.Rock as number);
}

/**
* Checks whether or not the entity is a fish spot.
* @returns Whether the type is equal to the EntityType fish spot.
*/

public isFishSpot(): this is FishSpot {
return this.type === (Modules.EntityType.FishSpot as number);
}

/**
* Checks whether or not the entity is a foraging spot.
* @returns Whether the type is equal to the EntityType foraging spot.
*/

public isForaging(): this is Foraging {
return this.type === (Modules.EntityType.Foraging as number);
}

/**
* This is entity superclass serialization. It provides
* the absolute most basic data about the entity. Entities
Expand Down
10 changes: 10 additions & 0 deletions packages/server/src/game/entity/objects/resource/impl/fishspot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Resource from '../resource';

import Utils from '@kaetram/common/util/utils';
import { Modules } from '@kaetram/common/network';

export default class FishSpot extends Resource {
public constructor(key: string, x: number, y: number) {
super(Utils.createInstance(Modules.EntityType.FishSpot), key, x, y);
}
}
10 changes: 10 additions & 0 deletions packages/server/src/game/entity/objects/resource/impl/foraging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Resource from '../resource';

import Utils from '@kaetram/common/util/utils';
import { Modules } from '@kaetram/common/network';

export default class Foraging extends Resource {
public constructor(key: string, x: number, y: number) {
super(Utils.createInstance(Modules.EntityType.Foraging), key, x, y);
}
}
10 changes: 10 additions & 0 deletions packages/server/src/game/entity/objects/resource/impl/rock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Resource from '../resource';

import Utils from '@kaetram/common/util/utils';
import { Modules } from '@kaetram/common/network';

export default class Rock extends Resource {
public constructor(key: string, x: number, y: number) {
super(Utils.createInstance(Modules.EntityType.Rock), key, x, y);
}
}
24 changes: 0 additions & 24 deletions packages/server/src/game/globals/fishspots.ts

This file was deleted.

24 changes: 0 additions & 24 deletions packages/server/src/game/globals/foraging.ts

This file was deleted.

44 changes: 0 additions & 44 deletions packages/server/src/game/globals/globals.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import Lights from './lights';
import Signs from './signs';
import Trees from './trees';
import Rocks from './rocks';
import FishSpots from './fishspots';
import Foraging from './foraging';

import type World from '../world';

Expand All @@ -13,54 +9,14 @@ import type World from '../world';
*/

export default class Globals {
private trees: Trees;
private rocks: Rocks;
private fishSpots: FishSpots;
private foraging: Foraging;
private lights: Lights;
private signs: Signs;

public constructor(private world: World) {
this.trees = new Trees(this.world);
this.rocks = new Rocks(this.world);
this.fishSpots = new FishSpots(this.world);
this.foraging = new Foraging(this.world);
this.lights = new Lights(this.world.map);
this.signs = new Signs(this.world.map);
}

/**
* @returns The trees handler object.
*/

public getTrees(): Trees {
return this.trees;
}

/**
* @returns The rocks handler object.
*/

public getRocks(): Rocks {
return this.rocks;
}

/**
* @returns The fishing spots handler object.
*/

public getFishingSpots(): FishSpots {
return this.fishSpots;
}

/**
* @returns The foraging handler object.
*/

public getForaging(): Foraging {
return this.foraging;
}

/**
* @returns Returns the signs handler object.
*/
Expand Down
Loading

0 comments on commit 124affe

Please sign in to comment.