RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.content.skill.impl.HarvestingSkillAction Class Referenceabstract

Holds functionality for skills such as woodcutting and mining. More...

Inheritance diagram for com.runehive.content.skill.impl.HarvestingSkillAction:
Collaboration diagram for com.runehive.content.skill.impl.HarvestingSkillAction:

Classes

enum  DoubleReward
 The double onReward types. More...

Public Member Functions

final boolean canRun ()
 Determines if the task can be ran.
DoubleReward doubleReward ()
 If mob will get a double onReward.
WalkablePolicy getWalkablePolicy ()
 Gets the WalkablePolicy of this action.
 HarvestingSkillAction (Mob mob, Optional< Position > position, boolean instant)
 Creates a new Action randomevent.
 HarvestingSkillAction (Mob mob, Optional< Position > position, int delay, boolean instant)
 Creates a new Action randomevent.
abstract Item[] harvestItems ()
 The items to be harvested upon a successful harvest.
void onExecute ()
 The method which is called on intervals of the specified #delay;.
void onHarvest (Item[] items, boolean success)
 The method executed upon harvest of the items.
boolean prioritized ()
 Determines if this action is prioritized.
abstract Optional< Item[]> removeItems ()
 The items to be removed upon a successful harvest.
abstract double successFactor ()
 The success factor for the harvest.
Public Member Functions inherited from com.runehive.content.skill.SkillAction
abstract Optional< SkillAnimationanimation ()
 The skill animation to execute.
abstract boolean canInit ()
 Determines if this action can be initialized.
abstract double experience ()
 The experience given from this action.
boolean ignore ()
 Determines if future skill actions from the same type should be ignored.
abstract void init ()
 Any functionality that should be handled when this action is submitted.
abstract int skill ()
 The skill we should hand to experience to.
 SkillAction (Mob mob, Optional< Position > position, boolean instant)
 Creates a new Action randomevent.
 SkillAction (Mob mob, Optional< Position > position, int delay, boolean instant)
 Creates a new Action randomevent.
final void start ()
 Attempts to start the skill.
Public Member Functions inherited from com.runehive.game.action.Action< T extends Mob >
 Action (T mob, int delay)
 Creates a new Action randomevent.
 Action (T mob, int delay, boolean instant)
 Creates a new Action randomevent.
boolean cancellableInProgress ()
getMob ()
 Gets the player.
abstract String getName ()
 Gets the name of this action.
Public Member Functions inherited from com.runehive.game.task.Task
Task attach (Object newKey)
 Attaches a new key.
synchronized final void cancel ()
 Cancels all subsequent executions.
synchronized final void cancel (boolean logout)
 Cancels all subsequent executions.
Optional< Object > getAttachment ()
String getCreationStackTraceStr ()
int getDelay ()
Long getElapsedTimeFromRunStartTime ()
Optional< Long > getRunStartTime ()
long getTaskCreationTime ()
String getTaskId ()
boolean isInstant ()
boolean isRunning ()
void setDelay (int delay)
 Sets the cyclic delay.
void setExecutionTime ()
 Task (boolean instant, int delay)
 Creates a new Task.
 Task (int delay)
 Creates a new Task that doesn't execute instantly.

Private Attributes

final RandomGen random = new RandomGen()
 The random generator instance that will generate random numbers.

Static Private Attributes

static final int SUCCESS_FACTOR = 10
 The factor boost that determines the success rate for harvesting based on skill level.

Additional Inherited Members

Protected Member Functions inherited from com.runehive.content.skill.SkillAction
final void execute ()
 A function representing the unit of work that will be carried out.
final void onSchedule ()
 A function executed on registration.
Protected Member Functions inherited from com.runehive.game.task.Task
void baseExecute ()
boolean canSchedule ()
 A function executed on registration.
void onCancel (boolean logout)
 A function executed on cancellation.
Package Functions inherited from com.runehive.game.task.Task
void onException (Exception e)
 A function executed on thrown exceptions.
void onLoop ()
 A function executed when iterated over.
final synchronized void process ()
synchronized void setRunning (boolean running)

Detailed Description

Holds functionality for skills such as woodcutting and mining.

Author
Stand Up
Since
19-12-2016.

Definition at line 23 of file HarvestingSkillAction.java.

Constructor & Destructor Documentation

◆ HarvestingSkillAction() [1/2]

com.runehive.content.skill.impl.HarvestingSkillAction.HarvestingSkillAction ( Mob mob,
Optional< Position > position,
boolean instant )

Creates a new Action randomevent.

Parameters
mobmob.
positionposition.
instantinstant.

Definition at line 52 of file HarvestingSkillAction.java.

52 {
53 super(mob, position, instant);
54 }

References com.runehive.game.task.Task.instant, com.runehive.game.action.Action< T extends Mob >.mob, and com.runehive.content.skill.SkillAction.position.

◆ HarvestingSkillAction() [2/2]

com.runehive.content.skill.impl.HarvestingSkillAction.HarvestingSkillAction ( Mob mob,
Optional< Position > position,
int delay,
boolean instant )

Creates a new Action randomevent.

Parameters
mobmob.
positionposition.
delaydelay.
instantinstant.

Definition at line 64 of file HarvestingSkillAction.java.

64 {
65 super(mob, position, delay, instant);
66 }

References com.runehive.game.task.Task.delay, com.runehive.game.task.Task.instant, com.runehive.game.action.Action< T extends Mob >.mob, and com.runehive.content.skill.SkillAction.position.

Member Function Documentation

◆ canRun()

final boolean com.runehive.content.skill.impl.HarvestingSkillAction.canRun ( )

Determines if the task can be ran.

Reimplemented from com.runehive.game.task.Task.

Definition at line 110 of file HarvestingSkillAction.java.

110 {
111 if (getMob().isPlayer()) {
112 Player player = getMob().getPlayer();
113 if (getMob().isPlayer() && getMob().getPlayer().inventory.remaining() < 1) {
114 getMob().getPlayer().send(new SendMessage("You do not have any space left in your inventory."));
115 return false;
116 }
117 if (removeItems().isPresent()) {
118 Item[] remove = removeItems().get();
119
120 if (!player.inventory.containsAll(remove)) {
121 for (Item item : remove) {
122 if (!player.inventory.contains(item)) {
123 player.send(new SendMessage("You don't have " + StringUtils.appendIndefiniteArticle(item.getName() + ".")));
124 break;
125 }
126 }
127 return false;
128 }
129 }
130 }
131 return true;
132 }

References com.runehive.util.StringUtils.appendIndefiniteArticle(), com.runehive.game.world.items.containers.ItemContainer.contains(), com.runehive.game.world.items.containers.ItemContainer.containsAll(), com.runehive.game.action.Action< T extends Mob >.getMob(), com.runehive.game.world.items.Item.getName(), com.runehive.game.world.entity.mob.Mob.getPlayer(), com.runehive.game.world.entity.mob.player.Player.inventory, removeItems(), and com.runehive.game.world.entity.mob.player.Player.send().

Here is the call graph for this function:

◆ doubleReward()

DoubleReward com.runehive.content.skill.impl.HarvestingSkillAction.doubleReward ( )

If mob will get a double onReward.

Returns
If mob will get a double onReward.

Definition at line 83 of file HarvestingSkillAction.java.

83 {
84 return DoubleReward.NONE;
85 }

References com.runehive.content.skill.impl.HarvestingSkillAction.DoubleReward.NONE.

Referenced by onExecute().

Here is the caller graph for this function:

◆ getWalkablePolicy()

WalkablePolicy com.runehive.content.skill.impl.HarvestingSkillAction.getWalkablePolicy ( )

Gets the WalkablePolicy of this action.

Returns
The walkable policy of this action.

Reimplemented from com.runehive.game.action.Action< T extends Mob >.

Definition at line 183 of file HarvestingSkillAction.java.

183 {
184 return WalkablePolicy.NON_WALKABLE;
185 }

References com.runehive.game.action.policy.WalkablePolicy.NON_WALKABLE.

◆ harvestItems()

abstract Item[] com.runehive.content.skill.impl.HarvestingSkillAction.harvestItems ( )
abstract

The items to be harvested upon a successful harvest.

Returns
the items to be harvested.

Referenced by onExecute().

Here is the caller graph for this function:

◆ onExecute()

void com.runehive.content.skill.impl.HarvestingSkillAction.onExecute ( )

The method which is called on intervals of the specified #delay;.

Reimplemented from com.runehive.content.skill.SkillAction.

Definition at line 135 of file HarvestingSkillAction.java.

135 {
136 Preconditions.checkState(SUCCESS_FACTOR >= 0 && SUCCESS_FACTOR <= 99, "Invalid success factor for harvesting!");
137 int factor = (getMob().skills.getSkills()[skill()].getLevel() / SUCCESS_FACTOR);
138 double boost = (factor * 0.01);
139 if (random.success(successFactor() + boost)) {
140 Optional<Item[]> removeItems = removeItems();
141 Item[] harvestItems = harvestItems();
142
143 if (getMob().isPlayer()) {
144 removeItems.ifPresent(getMob().getPlayer().inventory::removeAll);
145 if (harvestItems != null)
146 getMob().getPlayer().inventory.addAll(harvestItems);
147 if (experience() != -1)
148 getMob().skills.addExperience(skill(), experience());
149 onHarvest(harvestItems, true);
150
151 if (doubleReward() == DoubleReward.ITEM) {
152 getMob().getPlayer().inventory.addAll(harvestItems);
153 } else if (doubleReward() == DoubleReward.EXPERIENCE) {
154 getMob().skills.addExperience(skill(), experience());
155 } else if (doubleReward() == DoubleReward.ALL) {
156 getMob().getPlayer().inventory.addAll(harvestItems);
157 getMob().skills.addExperience(skill(), experience());
158 }
159 }
160 } else {
161 onHarvest(null, false);
162 }
163 }

References com.runehive.content.skill.impl.HarvestingSkillAction.DoubleReward.ALL, doubleReward(), com.runehive.content.skill.impl.HarvestingSkillAction.DoubleReward.EXPERIENCE, com.runehive.content.skill.SkillAction.experience(), com.runehive.game.action.Action< T extends Mob >.getMob(), harvestItems(), com.runehive.content.skill.impl.HarvestingSkillAction.DoubleReward.ITEM, onHarvest(), random, removeItems(), com.runehive.content.skill.SkillAction.skill(), SUCCESS_FACTOR, and successFactor().

Here is the call graph for this function:

◆ onHarvest()

void com.runehive.content.skill.impl.HarvestingSkillAction.onHarvest ( Item[] items,
boolean success )

The method executed upon harvest of the items.

Parameters
itemsthe items being harvested.
successdetermines if the harvest was successful or not.

Definition at line 74 of file HarvestingSkillAction.java.

74 {
75
76 }

Referenced by onExecute().

Here is the caller graph for this function:

◆ prioritized()

boolean com.runehive.content.skill.impl.HarvestingSkillAction.prioritized ( )

Determines if this action is prioritized.

When making an action prioritized, the next action will be ignored if not queued.

Returns
true if this action is prioritized, false otherwise.

Reimplemented from com.runehive.game.action.Action< T extends Mob >.

Definition at line 173 of file HarvestingSkillAction.java.

173 {
174 return false;
175 }

◆ removeItems()

abstract Optional< Item[]> com.runehive.content.skill.impl.HarvestingSkillAction.removeItems ( )
abstract

The items to be removed upon a successful harvest.

Returns
the items to be removed.

Referenced by canRun(), and onExecute().

Here is the caller graph for this function:

◆ successFactor()

abstract double com.runehive.content.skill.impl.HarvestingSkillAction.successFactor ( )
abstract

The success factor for the harvest.

The higher the number means the more frequently harvest will be obtained.

Returns
the success factor.

Referenced by onExecute().

Here is the caller graph for this function:

Member Data Documentation

◆ random

final RandomGen com.runehive.content.skill.impl.HarvestingSkillAction.random = new RandomGen()
private

The random generator instance that will generate random numbers.

Definition at line 43 of file HarvestingSkillAction.java.

Referenced by onExecute().

◆ SUCCESS_FACTOR

final int com.runehive.content.skill.impl.HarvestingSkillAction.SUCCESS_FACTOR = 10
staticprivate

The factor boost that determines the success rate for harvesting based on skill level.

The higher the number the less frequently harvest will be obtained. A value higher than 99 or lower than 0 will throw an IllegalStateException.

Definition at line 38 of file HarvestingSkillAction.java.

Referenced by onExecute().


The documentation for this class was generated from the following file: