From 75f4d23807722a3f8e9ae1c237a94a4201445273 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 25 Apr 2019 00:54:25 -0400 Subject: [PATCH 1/5] Set run_energy attribute as double instead of int If required, we can revert this and modify the formulas to multiply the values by 100 and then divide accordingly. --- .../org/apollo/game/model/entity/Player.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 76c06db95..7a46be45d 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -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; @@ -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; @@ -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. * @@ -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. */ @@ -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)); } /** @@ -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)); } /** @@ -1034,5 +1039,4 @@ private void initSkills() { skillSet.addListener(new SynchronizationSkillListener(this)); skillSet.addListener(new LevelUpSkillListener(this)); } - } \ No newline at end of file From 5975c66aec04b2dfd054565d28f41f28db6bb977 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 25 Apr 2019 01:07:30 -0400 Subject: [PATCH 2/5] Set getRunEnergy as double --- game/src/main/java/org/apollo/game/model/entity/Player.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 7a46be45d..8e957a2ae 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -473,8 +473,8 @@ public PrivilegeLevel getPrivilegeLevel() { * * @return The run energy. */ - public int getRunEnergy() { - Attribute energy = attributes.get("run_energy"); + public double getRunEnergy() { + Attribute energy = attributes.get("run_energy"); return energy.getValue(); } From 6505c2219e349256e6bae5a4eaee91525295091d Mon Sep 17 00:00:00 2001 From: = Date: Thu, 25 Apr 2019 01:08:41 -0400 Subject: [PATCH 3/5] Add increment and decrement run energy formulas --- .../org/apollo/game/model/entity/Player.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 8e957a2ae..435ff13bc 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -1039,4 +1039,30 @@ private void initSkills() { skillSet.addListener(new SynchronizationSkillListener(this)); 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) { + 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 increment = (8.0 + (agilityLevel / 6.0)) / 100.0; + double outcome = Math.min(MAXIMUM_RUN_ENERGY, getRunEnergy() + increment); + if (outcome != getRunEnergy()) { + setRunEnergy(outcome); + } + } } \ No newline at end of file From 4ab38e83465fffd158cf31c8a4a919537933ee8b Mon Sep 17 00:00:00 2001 From: = Date: Thu, 25 Apr 2019 01:10:38 -0400 Subject: [PATCH 4/5] Implement run energy depletion and restoring --- .../task/PrePlayerSynchronizationTask.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java index 33d1c7af7..0bc7c8e45 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java @@ -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}. @@ -58,6 +60,15 @@ public void run() { Position old = player.getPosition(); player.getWalkingQueue().pulse(); + if (player.getSecondDirection() != Direction.NONE) { + // 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()) { From ec165b255f65d88b365da1553ce213fb054307d9 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 25 Apr 2019 01:27:16 -0400 Subject: [PATCH 5/5] Modified condition that checks if energy restoration should occur --- .../src/main/java/org/apollo/game/model/entity/Player.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 435ff13bc..56caec479 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -1059,9 +1059,10 @@ public void decrementRunEnergy(double weight) { * increment the run energy by. */ public void incrementRunEnergy(int agilityLevel) { - double increment = (8.0 + (agilityLevel / 6.0)) / 100.0; - double outcome = Math.min(MAXIMUM_RUN_ENERGY, getRunEnergy() + increment); - if (outcome != getRunEnergy()) { + 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); } }