-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: fishing skill #390
base: develop
Are you sure you want to change the base?
feat: fishing skill #390
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"npc": "rs:fishing_spot_bait_a", | ||
"spawn_x": 3239, | ||
"spawn_y": 3241, | ||
"spawn_level": 0, | ||
"movement_radius": 0, | ||
"face": "WEST" | ||
}, | ||
{ | ||
"npc": "rs:fishing_spot_bait_a", | ||
"spawn_x": 3239, | ||
"spawn_y": 3244, | ||
"spawn_level": 0, | ||
"movement_radius": 0, | ||
"face": "WEST" | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rs:fishing_spot_bait_a": { | ||
"game_id": 233 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { LandscapeObject } from '@runejs/filestore'; | ||
import { activeWorld, Position } from '@engine/world'; | ||
import { Actor } from '@engine/world/actor'; | ||
import { ActorWalkToTask } from './actor-walk-to-task'; | ||
|
||
/** | ||
* A task for an {@link Actor} to interact with another {@link Actor}. | ||
* | ||
* This task extends {@link ActorWalkToTask} and will walk the actor to the object. | ||
* Once the actor is within range of the target Actor, the task will expose the `otherActor` property | ||
* | ||
* @author jameshallam | ||
*/ | ||
export abstract class ActorActorInteractionTask<TActor extends Actor = Actor, TOtherActor extends Actor = Actor> extends ActorWalkToTask<TActor, Position> { | ||
/* | ||
* TODO (jameskmonger) consider exposing this, currently people must always access it through `otherActor` | ||
* or through their own constructor | ||
*/ | ||
private _targetActor: TOtherActor; | ||
|
||
/** | ||
* Gets the {@link TOtherActor} that this task is interacting with. | ||
* | ||
* @returns The target actor, if is still present, and if the actor is at the destination. | ||
* Otherwise, `null`. | ||
* | ||
* TODO (jameskmonger) unit test this | ||
*/ | ||
protected get otherActor(): TOtherActor | null { | ||
if (!this.atDestination) { | ||
return null; | ||
} | ||
|
||
if (!this._targetActor) { | ||
return null; | ||
} | ||
|
||
return this._targetActor; | ||
} | ||
|
||
/** | ||
* Get the position of this task's target npc | ||
* | ||
* @returns The position of this task's target npc, or `null` if the npc is not present | ||
*/ | ||
protected get otherActorPosition(): Position { | ||
if (!this._targetActor) { | ||
return null; | ||
} | ||
return this._targetActor.position | ||
} | ||
|
||
/** | ||
* @param actor The actor executing this task. | ||
* @param targetActor The `TOtherActor` to interact with. | ||
* @param sizeX The size of the target TOtherActor in the X direction. | ||
* @param sizeY The size of the target TOtherActor in the Y direction. | ||
*/ | ||
constructor ( | ||
actor: TActor, | ||
targetActor: TOtherActor, | ||
sizeX: number = 1, | ||
sizeY: number = 1 | ||
) { | ||
super( | ||
actor, | ||
// TODO (jameskmonger) this doesn't currently account for a moving NPC target | ||
targetActor.position, | ||
Math.max(sizeX, sizeY) | ||
); | ||
|
||
if (!targetActor) { | ||
this.stop(); | ||
return; | ||
} | ||
|
||
this._targetActor = targetActor; | ||
} | ||
|
||
/** | ||
* Checks for the continued presence of the target {@link Actor}, and stops the task if it is no longer present. | ||
* | ||
* TODO (jameskmonger) unit test this | ||
*/ | ||
public execute() { | ||
super.execute(); | ||
|
||
if (!this.isActive || !this.atDestination) { | ||
return; | ||
} | ||
|
||
// stop the task if the actor no longer exists | ||
if (!this._targetActor) { | ||
this.stop(); | ||
return; | ||
} | ||
|
||
// TODO: check npc still exists | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to investigate what happens when NPCs die/are removed I suspect we need to do something similar to the |
||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,6 +12,10 @@ import { ActorWalkToTask } from './actor-walk-to-task'; | |||||
* @author jameskmonger | ||||||
*/ | ||||||
export abstract class ActorLandscapeObjectInteractionTask<TActor extends Actor = Actor> extends ActorWalkToTask<TActor, LandscapeObject> { | ||||||
/* | ||||||
* TODO (jameskmonger) consider exposing this, currently people must always access it through `otherActor` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
my bad |
||||||
* or through their own constructor | ||||||
*/ | ||||||
private _landscapeObject: LandscapeObject; | ||||||
private _objectPosition: Position; | ||||||
|
||||||
|
@@ -24,9 +28,6 @@ export abstract class ActorLandscapeObjectInteractionTask<TActor extends Actor = | |||||
* TODO (jameskmonger) unit test this | ||||||
*/ | ||||||
protected get landscapeObject(): LandscapeObject | null { | ||||||
// TODO (jameskmonger) consider if we want to do these checks rather than delegating to the child task | ||||||
// as currently the subclass has to store it in a subclass property if it wants to use it | ||||||
// without these checks | ||||||
if (!this.atDestination) { | ||||||
return null; | ||||||
} | ||||||
|
@@ -91,11 +92,13 @@ export abstract class ActorLandscapeObjectInteractionTask<TActor extends Actor = | |||||
return; | ||||||
} | ||||||
|
||||||
// stop the task if the object no longer exists | ||||||
if (!this._landscapeObject) { | ||||||
this.stop(); | ||||||
return; | ||||||
} | ||||||
|
||||||
// find the object in the world and validate that it still exists | ||||||
const { object: worldObject } = activeWorld.findObjectAtLocation(this.actor, this._landscapeObject.objectId, this._objectPosition); | ||||||
|
||||||
if (!worldObject) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should change
ActorWalkToTask
to also acceptActor
rather than passing the position in manually, that way we can easily defer the "tracking" of moving targets easily.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then this would just be