Skip to content
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

Add Run Energy depleting/restoring #423

Open
wants to merge 5 commits into
base: kotlin-experiments
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 45 additions & 14 deletions game/src/main/java/org/apollo/game/model/entity/Player.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package org.apollo.game.model.entity;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import org.apollo.game.message.impl.ConfigMessage;
Expand All @@ -27,8 +19,8 @@
import org.apollo.game.model.entity.attr.AttributeDefinition;
import org.apollo.game.model.entity.attr.AttributeMap;
import org.apollo.game.model.entity.attr.AttributePersistence;
import org.apollo.game.model.entity.attr.NumericalAttribute;
import org.apollo.game.model.entity.attr.BooleanAttribute;
import org.apollo.game.model.entity.attr.NumericalAttribute;
import org.apollo.game.model.entity.obj.DynamicGameObject;
import org.apollo.game.model.entity.setting.MembershipStatus;
import org.apollo.game.model.entity.setting.PrivacyState;
Expand Down Expand Up @@ -56,6 +48,14 @@
import org.apollo.util.CollectionUtil;
import org.apollo.util.security.PlayerCredentials;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

/**
* A {@link Mob} that a user is controlling.
*
Expand All @@ -69,6 +69,11 @@ public final class Player extends Mob {
*/
private static final int DEFAULT_VIEWING_DISTANCE = 15;

/**
* The maximum run energy.
*/
private static final double MAXIMUM_RUN_ENERGY = 100;

/**
* The current amount of appearance tickets.
*/
Expand All @@ -79,7 +84,7 @@ public final class Player extends Mob {
AttributeMap.define("muted", AttributeDefinition.forBoolean(false, AttributePersistence.PERSISTENT));

AttributeMap.define("banned", AttributeDefinition.forBoolean(false, AttributePersistence.PERSISTENT));
AttributeMap.define("run_energy", AttributeDefinition.forInt(100, AttributePersistence.PERSISTENT));
AttributeMap.define("run_energy", AttributeDefinition.forDouble(MAXIMUM_RUN_ENERGY, AttributePersistence.PERSISTENT));
}

/**
Expand Down Expand Up @@ -468,8 +473,8 @@ public PrivilegeLevel getPrivilegeLevel() {
*
* @return The run energy.
*/
public int getRunEnergy() {
Attribute<Integer> energy = attributes.get("run_energy");
public double getRunEnergy() {
Attribute<Double> energy = attributes.get("run_energy");
return energy.getValue();
}

Expand Down Expand Up @@ -893,9 +898,9 @@ public void setRegionChanged(boolean regionChanged) {
*
* @param energy The energy.
*/
public void setRunEnergy(int energy) {
public void setRunEnergy(double energy) {
attributes.set("run_energy", new NumericalAttribute(energy));
send(new UpdateRunEnergyMessage(energy));
send(new UpdateRunEnergyMessage((int) energy));
}

/**
Expand Down Expand Up @@ -1035,4 +1040,30 @@ private void initSkills() {
skillSet.addListener(new LevelUpSkillListener(this));
}

/**
* Decrement run energy.
*
* @param weight the amount of weight to be taken into account when
* determining how much run energy will be depleted.
*/
public void decrementRunEnergy(double weight) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Major- any thoughts on this being in core? Seems like it might be the responsibility of a plugin, but I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think core is correct

double decrement = (Math.min(weight, 64.0) / 100.0) + 0.64;
double outcome = Math.max(0.0, getRunEnergy() - decrement);
setRunEnergy(outcome);
}

/**
* Increment run energy.
*
* @param agilityLevel the agility level used to determine how much to
* increment the run energy by.
*/
public void incrementRunEnergy(int agilityLevel) {
double runEnergy = getRunEnergy();
if (runEnergy < MAXIMUM_RUN_ENERGY) {
double increment = (8.0 + (agilityLevel / 6.0)) / 100.0;
double outcome = Math.min(MAXIMUM_RUN_ENERGY, runEnergy + increment);
setRunEnergy(outcome);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package org.apollo.game.sync.task;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apollo.game.message.impl.ClearRegionMessage;
import org.apollo.game.message.impl.GroupedRegionUpdateMessage;
import org.apollo.game.message.impl.RegionChangeMessage;
import org.apollo.game.message.impl.RegionUpdateMessage;
import org.apollo.game.model.Direction;
import org.apollo.game.model.Position;
import org.apollo.game.model.area.Region;
import org.apollo.game.model.area.RegionCoordinates;
import org.apollo.game.model.area.RegionRepository;
import org.apollo.game.model.entity.Player;
import org.apollo.game.model.entity.Skill;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* A {@link SynchronizationTask} which does pre-synchronization work for the specified {@link Player}.
Expand Down Expand Up @@ -58,6 +60,15 @@ public void run() {
Position old = player.getPosition();
player.getWalkingQueue().pulse();

if (player.getSecondDirection() != Direction.NONE) {
Copy link
Contributor

@garyttierney garyttierney Apr 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't right. We should only decrement the run energy when the player actually moves (see WalkingQueue). The direction could be set but the collision maps said this is an invalid move.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't fond of the condition, but it seemed to be the best fitting choice for what needed to be done. Sorry if I'm wrong here and just wasting your time, but I believe the direction is only set if the collision map allows the movement (see https://github.com/apollo-rsps/apollo/blob/kotlin-experiments/game/src/main/java/org/apollo/game/model/entity/WalkingQueue.java#L156).

Also, am I wrong to assume that if I use WalkingQueue.isRunning() & WalkingQueue.size(), then I would run into the issue that you warned about? I believe when adding steps into the walking queue, it won't check for collision.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I need to re-look at the assignment of secondDirection, you may be right there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garyttierney any update on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is fine as is, and what we expect. That's the only assignment of secondDirection and the point @Tomm0017 made is valid.

// TODO: implement weight depending on carried and worn items.
double weight = 0.0;
player.decrementRunEnergy(weight);
} else {
int agilityLevel = player.getSkillSet().getCurrentLevel(Skill.AGILITY);
player.incrementRunEnergy(agilityLevel);
}

boolean local = true;

if (player.isTeleporting()) {
Expand Down