Browse Source

last minute cleanup, added cast chance to mobs

master
FatBoy-DOTC 1 year ago
parent
commit
9f162e9ed0
  1. 7
      src/engine/ai/MobileFSM.java
  2. 2
      src/engine/ai/MobileFSMManager.java
  3. 39
      src/engine/db/handlers/dbMobBaseHandler.java
  4. 129
      src/engine/devcmd/cmds/SetAICmd.java
  5. 1
      src/engine/gameManager/DevCmdManager.java
  6. 2
      src/engine/server/world/WorldServer.java

7
src/engine/ai/MobileFSM.java

@ -225,6 +225,10 @@ public class MobileFSM {
mob.setCombatTarget(null); mob.setCombatTarget(null);
return false; return false;
} }
int castRoll = ThreadLocalRandom.current().nextInt(101);
if(castRoll <= MobileFSMManager.AI_POWER_DIVISOR){
return false;
}
if (mob.nextCastTime == 0) if (mob.nextCastTime == 0)
mob.nextCastTime = System.currentTimeMillis(); mob.nextCastTime = System.currentTimeMillis();
return mob.nextCastTime <= System.currentTimeMillis(); return mob.nextCastTime <= System.currentTimeMillis();
@ -286,7 +290,8 @@ public class MobileFSM {
msg.setUnknown04(2); msg.setUnknown04(2);
PowersManager.finishUseMobPower(msg, mob, 0, 0); PowersManager.finishUseMobPower(msg, mob, 0, 0);
// Default minimum seconds between cast = 10 // Default minimum seconds between cast = 10
mob.nextCastTime = System.currentTimeMillis() + mobPower.getCooldown() + (MobileFSMManager.AI_POWER_DIVISOR * 1000); float randomCooldown = (ThreadLocalRandom.current().nextInt(150) + 100) * 0.01f;
mob.nextCastTime = System.currentTimeMillis() + (long)((mobPower.getCooldown() + (MobileFSMManager.AI_POWER_DIVISOR * 1000)) * randomCooldown);
return true; return true;
} }
return false; return false;

2
src/engine/ai/MobileFSMManager.java

@ -33,10 +33,8 @@ public class MobileFSMManager {
public static int AI_DROP_AGGRO_RANGE = 60; public static int AI_DROP_AGGRO_RANGE = 60;
public static int AI_RECALL_RANGE = 400; public static int AI_RECALL_RANGE = 400;
public static int AI_PULSE_MOB_THRESHOLD = 200; 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_PATROL_DIVISOR = 15;
public static int AI_POWER_DIVISOR = 20; public static int AI_POWER_DIVISOR = 20;
public static float AI_MAX_ANGLE = 10f;
private MobileFSMManager() { private MobileFSMManager() {

39
src/engine/db/handlers/dbMobBaseHandler.java

@ -72,45 +72,6 @@ public class dbMobBaseHandler extends dbHandlerBase {
} }
return mobbaseList; return mobbaseList;
} }
public void SET_AI_DEFAULTS() {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_ai_defaults`")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
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);
}
}
public boolean UPDATE_AI_DEFAULTS() {
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, 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);
} catch (SQLException e) {
Logger.error(e);
}
return false;
}
public HashMap<Integer, Integer> LOAD_STATIC_POWERS(int mobBaseUUID) { public HashMap<Integer, Integer> LOAD_STATIC_POWERS(int mobBaseUUID) {
HashMap<Integer, Integer> powersList = new HashMap<>(); HashMap<Integer, Integer> powersList = new HashMap<>();

129
src/engine/devcmd/cmds/SetAICmd.java

@ -1,129 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.devcmd.cmds;
import engine.ai.MobileFSMManager;
import engine.devcmd.AbstractDevCmd;
import engine.gameManager.DbManager;
import engine.objects.AbstractGameObject;
import engine.objects.PlayerCharacter;
import engine.server.MBServerStatics;
/**
* @author Steve
*
*/
public class SetAICmd extends AbstractDevCmd {
public SetAICmd() {
super("setAI");
this.addCmdString("ai");
}
@Override
protected void _doCmd(PlayerCharacter pc, String[] words,
AbstractGameObject target) {
if (words.length < 2){
this.sendUsage(pc);
return;
}
int amount;
try{
amount = Integer.valueOf(words[1]);
}catch (NumberFormatException e) {
this.throwbackError(pc, "Failed to parse amount");
return;
}
switch(words[0]){
case "angle" :
float angle = Float.parseFloat(words[1]);
MobileFSMManager.AI_MAX_ANGLE = angle;
break;
case "aggrorange":
MobileFSMManager.AI_BASE_AGGRO_RANGE = amount;
DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS();
this.throwbackInfo(pc, "Aggro Range is now set to " + amount);
break;
case "dropaggrorange":
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":
MobileFSMManager.AI_PATROL_DIVISOR = amount;
DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS();
this.throwbackInfo(pc, "Patrol Chance is now set to " + amount);
break;
case "pulse":
if (amount < 500){
this.throwbackError(pc, "pulse amount must be greather than 500 to execute.");
return;
}
MobileFSMManager.AI_PULSE_MOB_THRESHOLD = amount;
this.throwbackInfo(pc, "Pulse is now set to " + amount);
break;
case "sleepthread":
if (amount < 500){
this.throwbackError(pc, "sleep amount must be greather than 500 to execute.");
return;
}
MobileFSMManager.AI_THREAD_SLEEP = amount;
this.throwbackInfo(pc, "Thread Sleep is now set to " + amount);
break;
case "recallrange":
MobileFSMManager.AI_RECALL_RANGE = amount;
DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS();
this.throwbackInfo(pc, "Recall Range is now set to " + amount);
break;
case "powerdivisor":
MobileFSMManager.AI_POWER_DIVISOR = amount;
DbManager.MobBaseQueries.UPDATE_AI_DEFAULTS();
this.throwbackInfo(pc, "Power Divisor is now set to " + amount);
break;
case "losehate":
MBServerStatics.PLAYER_HATE_DELIMITER = amount;
break;
case "hatemodcombat":
MBServerStatics.PLAYER_COMBAT_HATE_MODIFIER = amount;
default:
this.throwbackError(pc, words[0] + " is not a valid AI Command.");
break;
}
}
@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 " + 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;
return help;
}
@Override
protected String _getUsageString() {
String usage = "' /setai `command` `amount` `";
usage += '\n' + _getHelpString();
return usage;
}
}

1
src/engine/gameManager/DevCmdManager.java

@ -119,7 +119,6 @@ public enum DevCmdManager {
DevCmdManager.registerDevCmd(new PurgeObjectsCmd()); DevCmdManager.registerDevCmd(new PurgeObjectsCmd());
DevCmdManager.registerDevCmd(new SplatMobCmd()); DevCmdManager.registerDevCmd(new SplatMobCmd());
DevCmdManager.registerDevCmd(new SlotNpcCmd()); DevCmdManager.registerDevCmd(new SlotNpcCmd());
DevCmdManager.registerDevCmd(new SetAICmd());
DevCmdManager.registerDevCmd(new GateInfoCmd()); DevCmdManager.registerDevCmd(new GateInfoCmd());
DevCmdManager.registerDevCmd(new ShowOffsetCmd()); DevCmdManager.registerDevCmd(new ShowOffsetCmd());
DevCmdManager.registerDevCmd(new RealmInfoCmd()); DevCmdManager.registerDevCmd(new RealmInfoCmd());

2
src/engine/server/world/WorldServer.java

@ -358,8 +358,6 @@ public class WorldServer {
Logger.info("Starting InterestManager."); Logger.info("Starting InterestManager.");
WorldGrid.startLoadJob(); WorldGrid.startLoadJob();
DbManager.MobBaseQueries.SET_AI_DEFAULTS();
Logger.info("Loading blueprint data."); Logger.info("Loading blueprint data.");
StaticColliders.loadAllStaticColliders(); StaticColliders.loadAllStaticColliders();
BuildingRegions.loadAllStaticColliders(); BuildingRegions.loadAllStaticColliders();

Loading…
Cancel
Save