From ef0e277f46c425b1503c29e7fd0e0b705247e762 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Mon, 26 Jun 2023 20:21:10 -0500 Subject: [PATCH] refactored AI variables from MBServerStatics --- src/engine/ai/MobileFSM.java | 6 ++-- src/engine/ai/MobileFSMManager.java | 24 ++++++++++---- .../ai/utilities/MovementUtilities.java | 6 ++-- src/engine/db/handlers/dbMobBaseHandler.java | 23 +++++++------- src/engine/devcmd/cmds/SetAICmd.java | 31 ++++++++++--------- src/engine/gameManager/ConfigManager.java | 4 ++- .../objects/AbstractIntelligenceAgent.java | 3 +- src/engine/objects/Mob.java | 3 +- src/engine/server/MBServerStatics.java | 27 ---------------- 9 files changed, 58 insertions(+), 69 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 3925948c..d4d2f6f7 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -174,7 +174,7 @@ public class MobileFSM { rwss.setPlayer(mob); DispatchMessage.sendToAllInRange(mob, rwss); } - int patrolDelay = ThreadLocalRandom.current().nextInt((int)(MBServerStatics.AI_PATROL_DIVISOR * 0.5f), MBServerStatics.AI_PATROL_DIVISOR) + MBServerStatics.AI_PATROL_DIVISOR; + int patrolDelay = ThreadLocalRandom.current().nextInt((int)(MobileFSMManager.AI_PATROL_DIVISOR * 0.5f), MobileFSMManager.AI_PATROL_DIVISOR) + MobileFSMManager.AI_PATROL_DIVISOR; if (mob.stopPatrolTime + (patrolDelay * 1000) > System.currentTimeMillis()) //early exit while waiting to patrol again return; @@ -270,7 +270,7 @@ public class MobileFSM { msg.setUnknown04(2); PowersManager.finishUseMobPower(msg, mob, 0, 0); // Default minimum seconds between cast = 10 - mob.nextCastTime = System.currentTimeMillis() + (MBServerStatics.AI_POWER_DIVISOR * 1000); + mob.nextCastTime = System.currentTimeMillis() + mobPower.getCooldown() + (MobileFSMManager.AI_POWER_DIVISOR * 1000); return true; } return false; @@ -500,7 +500,7 @@ public class MobileFSM { CheckForAggro(mob); } } - if(mob.getCombatTarget() != null && CombatUtilities.inRange2D(mob,mob.getCombatTarget(),MBServerStatics.AI_BASE_AGGRO_RANGE * 0.5f)){ + if(mob.getCombatTarget() != null && CombatUtilities.inRange2D(mob,mob.getCombatTarget(), MobileFSMManager.AI_BASE_AGGRO_RANGE * 0.5f)){ return; } if (mob.isPlayerGuard() && !mob.despawned) { diff --git a/src/engine/ai/MobileFSMManager.java b/src/engine/ai/MobileFSMManager.java index 0ec192e4..7c94ba2f 100644 --- a/src/engine/ai/MobileFSMManager.java +++ b/src/engine/ai/MobileFSMManager.java @@ -9,12 +9,10 @@ package engine.ai; -import engine.gameManager.MovementManager; -import engine.gameManager.SessionManager; +import engine.gameManager.ConfigManager; import engine.gameManager.ZoneManager; import engine.objects.Mob; import engine.objects.Zone; -import engine.server.MBServerStatics; import engine.util.ThreadUtils; import org.pmw.tinylog.Logger; @@ -30,6 +28,17 @@ public class MobileFSMManager { private volatile boolean alive; private long timeOfKill = -1; + //AI variables moved form mb_server_statics + public static int AI_BASE_AGGRO_RANGE = 60; + public static int AI_DROP_AGGRO_RANGE = 60; + public static int AI_RECALL_RANGE = 400; + public static int AI_PULSE_MOB_THRESHOLD = 200; + public static int AI_THREAD_SLEEP = 1000; + public static int AI_PATROL_DIVISOR = 15; + public static int AI_POWER_DIVISOR = 20; + public static float AI_MAX_ANGLE = 10f; + + private MobileFSMManager() { Runnable worker = new Runnable() { @@ -40,7 +49,10 @@ public class MobileFSMManager { }; alive = true; - + //assign the AI varibales base don difficulty scaling from config file: + float difficulty = Float.parseFloat(ConfigManager.MB_MOB_DIFFICULTY.getValue()); + AI_BASE_AGGRO_RANGE = (int)(100 * difficulty); // range at which aggressive mobs will attack you + AI_POWER_DIVISOR = (int)(20 * (1.5f-difficulty)); //duration between mob casts Thread t = new Thread(worker, "MobileFSMManager"); t.start(); } @@ -69,7 +81,7 @@ public class MobileFSMManager { //Load zone threshold once. - long mobPulse = System.currentTimeMillis() + MBServerStatics.AI_PULSE_MOB_THRESHOLD; + long mobPulse = System.currentTimeMillis() + AI_PULSE_MOB_THRESHOLD; Instant startTime; while (alive) { @@ -99,7 +111,7 @@ public class MobileFSMManager { if (executionTime.compareTo(executionMax) > 0) executionMax = executionTime; - mobPulse = System.currentTimeMillis() + MBServerStatics.AI_PULSE_MOB_THRESHOLD; + mobPulse = System.currentTimeMillis() + AI_PULSE_MOB_THRESHOLD; } } } diff --git a/src/engine/ai/utilities/MovementUtilities.java b/src/engine/ai/utilities/MovementUtilities.java index b244d355..b07d9a9a 100644 --- a/src/engine/ai/utilities/MovementUtilities.java +++ b/src/engine/ai/utilities/MovementUtilities.java @@ -13,12 +13,12 @@ import engine.Enum; import engine.Enum.GameObjectType; import engine.Enum.ModType; import engine.Enum.SourceType; +import engine.ai.MobileFSMManager; import engine.exception.MsgSendException; import engine.gameManager.MovementManager; import engine.math.Vector3fImmutable; import engine.net.client.msg.MoveToPointMsg; import engine.objects.*; -import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; import java.util.concurrent.ThreadLocalRandom; @@ -79,7 +79,7 @@ public class MovementUtilities { zoneRange = agent.getSpawnRadius(); - return distanceSquaredToTarget < sqr(MBServerStatics.AI_DROP_AGGRO_RANGE + zoneRange); + return distanceSquaredToTarget < sqr(MobileFSMManager.AI_DROP_AGGRO_RANGE + zoneRange); } @@ -89,7 +89,7 @@ public class MovementUtilities { Vector3fImmutable tl = target.getLoc(); float distanceSquaredToTarget = sl.distanceSquared2D(tl) - sqr(agent.calcHitBox() + target.calcHitBox()); //distance to center of target - float range = MBServerStatics.AI_BASE_AGGRO_RANGE; + float range = MobileFSMManager.AI_BASE_AGGRO_RANGE; if (agent.isPlayerGuard()) range = 150; diff --git a/src/engine/db/handlers/dbMobBaseHandler.java b/src/engine/db/handlers/dbMobBaseHandler.java index 7ef95c6d..307f4361 100644 --- a/src/engine/db/handlers/dbMobBaseHandler.java +++ b/src/engine/db/handlers/dbMobBaseHandler.java @@ -10,11 +10,11 @@ package engine.db.handlers; import engine.Enum.GameObjectType; +import engine.ai.MobileFSMManager; import engine.gameManager.DbManager; import engine.objects.MobBase; import engine.objects.MobBaseEffects; import engine.objects.MobBaseStats; -import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -81,12 +81,11 @@ public class dbMobBaseHandler extends dbHandlerBase { ResultSet rs = preparedStatement.executeQuery(); while (rs.next()) { - MBServerStatics.AI_BASE_AGGRO_RANGE = rs.getInt("aggro_range"); - MBServerStatics.AI_PATROL_DIVISOR = rs.getInt("patrol_chance"); - MBServerStatics.AI_DROP_AGGRO_RANGE = rs.getInt("drop_aggro_range"); - MBServerStatics.AI_POWER_DIVISOR = rs.getInt("cast_chance"); - MBServerStatics.AI_RECALL_RANGE = rs.getInt("recall_range"); - MBServerStatics.AI_PET_HEEL_DISTANCE = rs.getInt("pet_heel_distance"); + MobileFSMManager.AI_BASE_AGGRO_RANGE = rs.getInt("aggro_range"); + MobileFSMManager.AI_PATROL_DIVISOR = rs.getInt("patrol_chance"); + MobileFSMManager.AI_DROP_AGGRO_RANGE = rs.getInt("drop_aggro_range"); + MobileFSMManager.AI_POWER_DIVISOR = rs.getInt("cast_chance"); + MobileFSMManager.AI_RECALL_RANGE = rs.getInt("recall_range"); } } catch (SQLException e) { Logger.error(e); @@ -98,11 +97,11 @@ public class dbMobBaseHandler extends dbHandlerBase { try (Connection connection = DbManager.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_ai_defaults` SET `aggro_range` = ?,`patrol_chance`= ?,`drop_aggro_range`= ?,`cast_chance`= ?,`recall_range`= ? WHERE `ID` = 1")) { - preparedStatement.setInt(1, MBServerStatics.AI_BASE_AGGRO_RANGE); - preparedStatement.setInt(2, MBServerStatics.AI_PATROL_DIVISOR); - preparedStatement.setInt(3, MBServerStatics.AI_DROP_AGGRO_RANGE); - preparedStatement.setInt(4, MBServerStatics.AI_POWER_DIVISOR); - preparedStatement.setInt(5, MBServerStatics.AI_RECALL_RANGE); + preparedStatement.setInt(1, MobileFSMManager.AI_BASE_AGGRO_RANGE); + preparedStatement.setInt(2, MobileFSMManager.AI_PATROL_DIVISOR); + preparedStatement.setInt(3, MobileFSMManager.AI_DROP_AGGRO_RANGE); + preparedStatement.setInt(4, MobileFSMManager.AI_POWER_DIVISOR); + preparedStatement.setInt(5, MobileFSMManager.AI_RECALL_RANGE); return (preparedStatement.executeUpdate() > 0); diff --git a/src/engine/devcmd/cmds/SetAICmd.java b/src/engine/devcmd/cmds/SetAICmd.java index 607e1c8b..603307e6 100644 --- a/src/engine/devcmd/cmds/SetAICmd.java +++ b/src/engine/devcmd/cmds/SetAICmd.java @@ -10,6 +10,7 @@ package engine.devcmd.cmds; +import engine.ai.MobileFSMManager; import engine.devcmd.AbstractDevCmd; import engine.gameManager.DbManager; import engine.objects.AbstractGameObject; @@ -48,20 +49,20 @@ public class SetAICmd extends AbstractDevCmd { case "angle" : float angle = Float.parseFloat(words[1]); - MBServerStatics.AI_MAX_ANGLE = angle; + MobileFSMManager.AI_MAX_ANGLE = angle; break; case "aggrorange": - MBServerStatics.AI_BASE_AGGRO_RANGE = amount; + MobileFSMManager.AI_BASE_AGGRO_RANGE = amount; DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); this.throwbackInfo(pc, "Aggro Range is now set to " + amount); break; case "dropaggrorange": - MBServerStatics.AI_DROP_AGGRO_RANGE = amount; + MobileFSMManager.AI_DROP_AGGRO_RANGE = amount; DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); this.throwbackInfo(pc, "Drop Aggro Range is now set to " + amount); break; case "patroldivisor": - MBServerStatics.AI_PATROL_DIVISOR = amount; + MobileFSMManager.AI_PATROL_DIVISOR = amount; DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); this.throwbackInfo(pc, "Patrol Chance is now set to " + amount); break; @@ -70,7 +71,7 @@ public class SetAICmd extends AbstractDevCmd { this.throwbackError(pc, "pulse amount must be greather than 500 to execute."); return; } - MBServerStatics.AI_PULSE_MOB_THRESHOLD = amount; + MobileFSMManager.AI_PULSE_MOB_THRESHOLD = amount; this.throwbackInfo(pc, "Pulse is now set to " + amount); break; case "sleepthread": @@ -78,16 +79,16 @@ public class SetAICmd extends AbstractDevCmd { this.throwbackError(pc, "sleep amount must be greather than 500 to execute."); return; } - MBServerStatics.AI_THREAD_SLEEP = amount; + MobileFSMManager.AI_THREAD_SLEEP = amount; this.throwbackInfo(pc, "Thread Sleep is now set to " + amount); break; case "recallrange": - MBServerStatics.AI_RECALL_RANGE = amount; + MobileFSMManager.AI_RECALL_RANGE = amount; DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); this.throwbackInfo(pc, "Recall Range is now set to " + amount); break; case "powerdivisor": - MBServerStatics.AI_POWER_DIVISOR = amount; + MobileFSMManager.AI_POWER_DIVISOR = amount; DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS(); this.throwbackInfo(pc, "Power Divisor is now set to " + amount); break; @@ -105,13 +106,13 @@ public class SetAICmd extends AbstractDevCmd { @Override protected String _getHelpString() { String help = "Modifies Mob AI Statics. Commands:"; - help += "\n AGGRORANGE: Sets the range when a mob will aggro it's target. Aggro range is currently " + MBServerStatics.AI_BASE_AGGRO_RANGE; - help += "\n DROPAGGRORANGE: Sets the range when a mob will drop aggro from it's target. Drop aggro range is currently " + MBServerStatics.AI_DROP_AGGRO_RANGE; - help += "\n PATROLDIVISOR: Sets the Patrol Divisor for Mob AI. Setting this will give a 1/[amount] chance to parol the area. Patrol Chance is currently 1/" + MBServerStatics.AI_PATROL_DIVISOR; - help += "\n PULSE: sets how often to run mob's AI. Measured in MS. Pulse is currently " + MBServerStatics.AI_PULSE_MOB_THRESHOLD + "ms."; - help += "\n SLEEPTHREAD: Sets how long to sleep the AI for ALL mobs.Thread sleep is currently " + MBServerStatics.AI_THREAD_SLEEP + "ms."; - help += "\n RECALLRANGE: Sets the range of a mob to recall back to it's bind location. Recall range is currently " + MBServerStatics.AI_RECALL_RANGE; - help += "\n POWERDIVISOR: Sets the Power Divisor for Mob AI.Setting this will give a 1/[amount] chance to use power on a player. Power Divisor is currently " + MBServerStatics.AI_POWER_DIVISOR; + help += "\n AGGRORANGE: Sets the range when a mob will aggro it's target. Aggro range is currently " + MobileFSMManager.AI_BASE_AGGRO_RANGE; + help += "\n DROPAGGRORANGE: Sets the range when a mob will drop aggro from it's target. Drop aggro range is currently " + MobileFSMManager.AI_DROP_AGGRO_RANGE; + help += "\n PATROLDIVISOR: Sets the Patrol Divisor for Mob AI. Setting this will give a 1/[amount] chance to parol the area. Patrol Chance is currently 1/" + MobileFSMManager.AI_PATROL_DIVISOR; + help += "\n PULSE: sets how often to run mob's AI. Measured in MS. Pulse is currently " + MobileFSMManager.AI_PULSE_MOB_THRESHOLD + "ms."; + help += "\n SLEEPTHREAD: Sets how long to sleep the AI for ALL mobs.Thread sleep is currently " + MobileFSMManager.AI_THREAD_SLEEP + "ms."; + help += "\n RECALLRANGE: Sets the range of a mob to recall back to it's bind location. Recall range is currently " + MobileFSMManager.AI_RECALL_RANGE; + help += "\n POWERDIVISOR: Sets the Power Divisor for Mob AI.Setting this will give a 1/[amount] chance to use power on a player. Power Divisor is currently " + MobileFSMManager.AI_POWER_DIVISOR; help += "\n LOSEHATE: Sets the amount per second to reduce hate amount for player while they are idle. Hate Delimiter is currently " + MBServerStatics.PLAYER_HATE_DELIMITER; help += "\n HATEMODCOMBAT: sets the modifier for Hate value for Combat. Hate Value is `Damage *[HATEMODCOMBAT]`.Hate Mod Combat is currently " + MBServerStatics.PLAYER_COMBAT_HATE_MODIFIER; diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index c28b555c..08580c1c 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -86,7 +86,9 @@ public enum ConfigManager { MB_MAGICBOT_FORTOFIX, MB_MAGICBOT_RECRUIT, MB_MAGICBOT_MAGICBOX, - MB_MAGICBOT_ADMINLOG; + MB_MAGICBOT_ADMINLOG, + + MB_MOB_DIFFICULTY;//0.1(easy) - 1.0(hard) // Map to hold our config pulled in from the environment // We also use the config to point to the current message pump diff --git a/src/engine/objects/AbstractIntelligenceAgent.java b/src/engine/objects/AbstractIntelligenceAgent.java index 0ec562b3..75d4e408 100644 --- a/src/engine/objects/AbstractIntelligenceAgent.java +++ b/src/engine/objects/AbstractIntelligenceAgent.java @@ -14,6 +14,7 @@ import engine.Enum.GameObjectType; import engine.Enum.ModType; import engine.Enum.SourceType; import engine.InterestManagement.WorldGrid; +import engine.ai.MobileFSMManager; import engine.gameManager.ZoneManager; import engine.math.Vector3fImmutable; import engine.net.Dispatch; @@ -189,7 +190,7 @@ public abstract class AbstractIntelligenceAgent extends AbstractCharacter { public abstract AbstractWorldObject getFearedObject(); public float getAggroRange() { - float ret = MBServerStatics.AI_BASE_AGGRO_RANGE; + float ret = MobileFSMManager.AI_BASE_AGGRO_RANGE; if (this.bonuses != null) ret *= (1 +this.bonuses.getFloatPercentAll(ModType.ScanRange, SourceType.None)); return ret; diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 0e5124cf..794ae48e 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -13,6 +13,7 @@ import ch.claude_martin.enumbitset.EnumBitSet; import engine.Enum; import engine.Enum.*; import engine.InterestManagement.WorldGrid; +import engine.ai.MobileFSMManager; import engine.exception.SerializationException; import engine.gameManager.*; import engine.job.JobScheduler; @@ -626,7 +627,7 @@ public class Mob extends AbstractIntelligenceAgent { public static void HandleAssistedAggro(PlayerCharacter source, PlayerCharacter target) { - HashSet mobsInRange = WorldGrid.getObjectsInRangePartial(source, MBServerStatics.AI_DROP_AGGRO_RANGE, MBServerStatics.MASK_MOB); + HashSet mobsInRange = WorldGrid.getObjectsInRangePartial(source, MobileFSMManager.AI_DROP_AGGRO_RANGE, MBServerStatics.MASK_MOB); for (AbstractWorldObject awo : mobsInRange) { Mob mob = (Mob) awo; diff --git a/src/engine/server/MBServerStatics.java b/src/engine/server/MBServerStatics.java index 429d931e..cc20d2d6 100644 --- a/src/engine/server/MBServerStatics.java +++ b/src/engine/server/MBServerStatics.java @@ -428,33 +428,6 @@ public class MBServerStatics { public static final int UPDATE_GROUP_RATE = 10000; // Update group info public static float PLAYER_HATE_DELIMITER = 50; // reduces 50 hate a second public static float PLAYER_COMBAT_HATE_MODIFIER = 2; - - /* - * AI - */ - - // The min distance from players at which the AI Manager feels safe to turn - // off a mob. - public static int AI_BASE_AGGRO_RANGE = 60; - public static int AI_DROP_AGGRO_RANGE = 60; - public static int AI_RECALL_RANGE = 400; - public static int AI_PULSE_MOB_THRESHOLD = 200; - public static int AI_THREAD_SLEEP = 1000; - public static int AI_PATROL_DIVISOR = 15; - public static int AI_POWER_DIVISOR = 20; - public static int AI_PET_HEEL_DISTANCE = 10; - public static int AI_PATROL_RADIUS = 60; - public static int AI_POWER_CHANCE = 25; // set 1-100 for chance a mob will cast - - public static float AI_MAX_ANGLE = 10f; - - public static final int AI_PET_TIME_BETWEEN_JOB_TICKS_MS = 250; - - // Pet Settings - public static final float PET_TELEPORT_DISTANCE = 600; // distance a pet - public static final float PET_FOLLOW_DISTANCE = 10; // distance a pet starts - public static final float PET_REST_DISTANCE = 4; // distance a pet stops - public static final int COMBAT_SEND_DODGE = 20; public static final int COMBAT_SEND_BLOCK = 21; public static final int COMBAT_SEND_PARRY = 22;