Browse Source

Refactored aggro system to use Monstertype.

master
MagicBot 2 years ago
parent
commit
beff5c3e06
  1. 84
      src/engine/Enum.java
  2. 2
      src/engine/ai/MobileFSM.java
  3. 22
      src/engine/db/handlers/dbMobBaseHandler.java
  4. 84
      src/engine/devcmd/cmds/CopyMobCmd.java
  5. 1
      src/engine/gameManager/DevCmdManager.java
  6. 9
      src/engine/objects/MobBase.java

84
src/engine/Enum.java

@ -88,28 +88,6 @@ public class Enum {
} }
public enum AggroType implements EnumBitSetHelper<AggroType> {
// Used for MobBase NoAggro types
// *** WARNING: ENUM IS FRAGILE AS
// ORDINALS STORED IN DB.
AELF,
ARACOIX,
CENTAUR,
DWARF,
ELF,
HALFGIANT,
HUMAN,
IREKEI,
MINO,
NEPH,
SHADE,
VAMP,
ARCHON;
}
public enum CharacterSex { public enum CharacterSex {
MALE, MALE,
FEMALE, FEMALE,
@ -121,45 +99,45 @@ public class Enum {
// RaceRuneID / AggroType, isFemale // RaceRuneID / AggroType, isFemale
AELFMALE(2000, AggroType.AELF, RunSpeed.STANDARD, CharacterSex.MALE,1.05f), AELFMALE(2000, MonsterType.Aelfborn, RunSpeed.STANDARD, CharacterSex.MALE,1.05f),
AELFFEMALE(2001, AggroType.AELF, RunSpeed.STANDARD, CharacterSex.FEMALE,1.05f), AELFFEMALE(2001, MonsterType.Aelfborn, RunSpeed.STANDARD, CharacterSex.FEMALE,1.05f),
ARACOIXMALE(2002, AggroType.ARACOIX, RunSpeed.STANDARD, CharacterSex.MALE,1), ARACOIXMALE(2002, MonsterType.Aracoix, RunSpeed.STANDARD, CharacterSex.MALE,1),
ARACOIXFEMALE(2003, AggroType.ARACOIX, RunSpeed.STANDARD, CharacterSex.FEMALE,1), ARACOIXFEMALE(2003, MonsterType.Aracoix, RunSpeed.STANDARD, CharacterSex.FEMALE,1),
CENTAURMALE(2004, AggroType.CENTAUR, RunSpeed.CENTAUR, CharacterSex.MALE,1.2f), CENTAURMALE(2004, MonsterType.Centaur, RunSpeed.CENTAUR, CharacterSex.MALE,1.2f),
CENTAURFEMALE(2005, AggroType.CENTAUR, RunSpeed.CENTAUR, CharacterSex.FEMALE, 1.2f), CENTAURFEMALE(2005, MonsterType.Centaur, RunSpeed.CENTAUR, CharacterSex.FEMALE, 1.2f),
DWARFMALE(2006, AggroType.DWARF, RunSpeed.STANDARD, CharacterSex.MALE,0.80000001f), DWARFMALE(2006, MonsterType.Dwarf, RunSpeed.STANDARD, CharacterSex.MALE,0.80000001f),
ELFMALE(2008, AggroType.ELF, RunSpeed.STANDARD, CharacterSex.MALE, 1.4f), ELFMALE(2008, MonsterType.Elf, RunSpeed.STANDARD, CharacterSex.MALE, 1.4f),
ELFFEMALE(2009, AggroType.ELF, RunSpeed.STANDARD, CharacterSex.FEMALE,1.1f), ELFFEMALE(2009, MonsterType.Elf, RunSpeed.STANDARD, CharacterSex.FEMALE,1.1f),
HALFGIANTMALE(2010, AggroType.HALFGIANT, RunSpeed.STANDARD, CharacterSex.MALE, 1.15f), HALFGIANTMALE(2010, MonsterType.HalfGiant, RunSpeed.STANDARD, CharacterSex.MALE, 1.15f),
HUMANMALE(2011, AggroType.HUMAN, RunSpeed.STANDARD, CharacterSex.MALE,1), HUMANMALE(2011, MonsterType.Human, RunSpeed.STANDARD, CharacterSex.MALE,1),
HUMANFEMALE(2012, AggroType.HUMAN, RunSpeed.STANDARD, CharacterSex.FEMALE,1), HUMANFEMALE(2012, MonsterType.Human, RunSpeed.STANDARD, CharacterSex.FEMALE,1),
IREKEIMALE(2013, AggroType.IREKEI, RunSpeed.STANDARD, CharacterSex.MALE,1.1f), IREKEIMALE(2013, MonsterType.Irekei, RunSpeed.STANDARD, CharacterSex.MALE,1.1f),
IREKEIFEMALE(2014, AggroType.IREKEI, RunSpeed.STANDARD, CharacterSex.FEMALE,1.1f), IREKEIFEMALE(2014, MonsterType.Irekei, RunSpeed.STANDARD, CharacterSex.FEMALE,1.1f),
SHADEMALE(2015, AggroType.SHADE, RunSpeed.STANDARD, CharacterSex.MALE,1), SHADEMALE(2015, MonsterType.Shade, RunSpeed.STANDARD, CharacterSex.MALE,1),
SHADEFEMALE(2016, AggroType.SHADE, RunSpeed.STANDARD, CharacterSex.FEMALE,1), SHADEFEMALE(2016, MonsterType.Shade, RunSpeed.STANDARD, CharacterSex.FEMALE,1),
MINOMALE(2017, AggroType.MINO, RunSpeed.MINOTAUR, CharacterSex.MALE,1.3f), MINOMALE(2017, MonsterType.Minotaur, RunSpeed.MINOTAUR, CharacterSex.MALE,1.3f),
ARCHONMALE(2018, AggroType.ARCHON, RunSpeed.STANDARD, CharacterSex.MALE,1), ARCHONMALE(2018, MonsterType.Celestial, RunSpeed.STANDARD, CharacterSex.MALE,1),
HALEGIANTOLDMALE(2019, AggroType.HALFGIANT, RunSpeed.STANDARD, CharacterSex.MALE,1.15f), HALEGIANTOLDMALE(2019, MonsterType.HalfGiant, RunSpeed.STANDARD, CharacterSex.MALE,1.15f),
CSRFEMALE(2020, AggroType.ARCHON, RunSpeed.STANDARD, CharacterSex.FEMALE,0.66000003f), CSRFEMALE(2020, MonsterType.CSR, RunSpeed.STANDARD, CharacterSex.FEMALE,0.66000003f),
CSRMALE(2021, AggroType.ARCHON, RunSpeed.STANDARD, CharacterSex.MALE,1), CSRMALE(2021, MonsterType.CSR, RunSpeed.STANDARD, CharacterSex.MALE,1),
NEPHMALE(2025, AggroType.NEPH, RunSpeed.STANDARD, CharacterSex.MALE,1.1f), NEPHMALE(2025, MonsterType.Nephilim, RunSpeed.STANDARD, CharacterSex.MALE,1.1f),
NEPHFEMALE(2026, AggroType.NEPH, RunSpeed.STANDARD, CharacterSex.FEMALE,1.1f), NEPHFEMALE(2026, MonsterType.Nephilim, RunSpeed.STANDARD, CharacterSex.FEMALE,1.1f),
HALFGIANTFEMALE(2027, AggroType.HALFGIANT, RunSpeed.STANDARD, CharacterSex.FEMALE,1.15f), HALFGIANTFEMALE(2027, MonsterType.HalfGiant, RunSpeed.STANDARD, CharacterSex.FEMALE,1.15f),
VAMPMALE(2028, AggroType.VAMP, RunSpeed.STANDARD, CharacterSex.MALE, 1), VAMPMALE(2028, MonsterType.Vampire, RunSpeed.STANDARD, CharacterSex.MALE, 1),
VAMPFEMALE(2029, AggroType.VAMP, RunSpeed.STANDARD, CharacterSex.FEMALE,1); VAMPFEMALE(2029, MonsterType.Vampire, RunSpeed.STANDARD, CharacterSex.FEMALE,1);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static HashMap<Integer, RaceType> _raceTypeByID = new HashMap<>(); private static HashMap<Integer, RaceType> _raceTypeByID = new HashMap<>();
int runeID; int runeID;
private AggroType aggroType; private MonsterType monsterType;
private CharacterSex characterSex; private CharacterSex characterSex;
private RunSpeed runSpeed; private RunSpeed runSpeed;
private float scaleHeight; private float scaleHeight;
RaceType(int runeID, AggroType aggroType, RunSpeed runspeed, CharacterSex characterSex, float scaleHeight) { RaceType(int runeID, MonsterType aggroType, RunSpeed runspeed, CharacterSex characterSex, float scaleHeight) {
this.runeID = runeID; this.runeID = runeID;
this.aggroType = aggroType; this.monsterType = aggroType;
this.runSpeed = runspeed; this.runSpeed = runspeed;
this.characterSex = characterSex; this.characterSex = characterSex;
this.scaleHeight = scaleHeight; this.scaleHeight = scaleHeight;
@ -184,8 +162,8 @@ public class Enum {
} }
} }
public AggroType getAggroType() { public MonsterType getMonsterType() {
return aggroType; return monsterType;
} }
public RunSpeed getRunSpeed() { public RunSpeed getRunSpeed() {

2
src/engine/ai/MobileFSM.java

@ -251,7 +251,7 @@ public class MobileFSM {
} }
// No aggro for this race type // No aggro for this race type
if (loadedPlayer.getRace().getRaceType().getAggroType().elementOf(aiAgent.getMobBase().getNoAggro())) if (loadedPlayer.getRace().getRaceType().getMonsterType().elementOf(aiAgent.notEnemy))
continue; continue;

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

@ -189,28 +189,6 @@ public class dbMobBaseHandler extends dbHandlerBase {
return (executeUpdate() > 0); return (executeUpdate() > 0);
} }
public MobBase COPY_MOBBASE(MobBase toAdd, String name) {
prepareCallable("INSERT INTO `static_npc_mobbase` (`loadID`, `lootTableID`, `name`, `level`, `health`, `atr`, `defense`, `minDmg`,`maxDmg`, `goldMod`, `seeInvis`, `flags`, `noaggro`, `spawntime`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
setInt(1, toAdd.getLoadID());
setInt(2, toAdd.getLootTable());
setString(3, (name.length() > 0) ? name : toAdd.getFirstName());
setInt(4, toAdd.getLevel());
setFloat(5, toAdd.getHealthMax());
setInt(5, toAdd.getAtr());
setInt(6, toAdd.getDefense());
setFloat(7, toAdd.getMinDmg());
setFloat(8, toAdd.getMaxDmg());
setInt(9, toAdd.getGoldMod());
setInt(10, toAdd.getSeeInvis());
setLong(11, toAdd.getFlags().toLong());
setLong(12, toAdd.getNoAggro().toLong());
setInt(13, toAdd.getSpawnTime());
int objectUUID = insertGetUUID();
if (objectUUID > 0)
return GET_MOBBASE(objectUUID, true);
return null;
}
public boolean RENAME_MOBBASE(int ID, String newName) { public boolean RENAME_MOBBASE(int ID, String newName) {
prepareCallable("UPDATE `static_npc_mobbase` SET `name`=? WHERE `ID`=?;"); prepareCallable("UPDATE `static_npc_mobbase` SET `name`=? WHERE `ID`=?;");
setString(1, newName); setString(1, newName);

84
src/engine/devcmd/cmds/CopyMobCmd.java

@ -1,84 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.devcmd.cmds;
import engine.devcmd.AbstractDevCmd;
import engine.gameManager.ChatManager;
import engine.objects.AbstractGameObject;
import engine.objects.MobBase;
import engine.objects.PlayerCharacter;
/**
* @author Eighty
*
*/
public class CopyMobCmd extends AbstractDevCmd {
public CopyMobCmd() {
super("copymob");
}
@Override
protected void _doCmd(PlayerCharacter pc, String[] words,
AbstractGameObject target) {
if (words.length < 1) {
this.sendUsage(pc);
return;
}
int loadID = 0;
String name = "";
try {
loadID = Integer.parseInt(words[0]);
if (words.length > 1) {
name = words[1];
for (int i=2; i<words.length;i++)
name += ' ' + words[i];
}
} catch (NumberFormatException e) {
throwbackError(pc, "Supplied type " + words[0]
+ " failed to parse to an Integer");
return;
} catch (Exception e) {
throwbackError(pc,
"Invalid copyMob Command. Need mob ID specified.");
return; // NaN
}
MobBase mob = MobBase.getMobBase(loadID);
if (mob == null) {
throwbackError(pc,
"Invalid copyMob Command. Mob ID specified is not valid.");
return;
}
MobBase mb = null;
try {
mb = MobBase.copyMobBase(mob, name);
} catch (Exception e) {}
if (mb == null) {
throwbackError(pc, "copyMob SQL Error. Failed to create new mob.");
return;
}
ChatManager.chatSayInfo(
pc,
"MobBase created with ID " + mb.getObjectUUID() + " using name "
+ mb.getFirstName());
}
@Override
protected String _getHelpString() {
return "Copies a Mob of type 'mobID' with optional new name";
}
@Override
protected String _getUsageString() {
return "' /mob mobID [name]'";
}
}

1
src/engine/gameManager/DevCmdManager.java

@ -85,7 +85,6 @@ public enum DevCmdManager {
DevCmdManager.registerDevCmd(new AddBuildingCmd()); DevCmdManager.registerDevCmd(new AddBuildingCmd());
DevCmdManager.registerDevCmd(new AddNPCCmd()); DevCmdManager.registerDevCmd(new AddNPCCmd());
DevCmdManager.registerDevCmd(new AddMobCmd()); DevCmdManager.registerDevCmd(new AddMobCmd());
DevCmdManager.registerDevCmd(new CopyMobCmd());
DevCmdManager.registerDevCmd(new RemoveObjectCmd()); DevCmdManager.registerDevCmd(new RemoveObjectCmd());
DevCmdManager.registerDevCmd(new RotateCmd()); DevCmdManager.registerDevCmd(new RotateCmd());
DevCmdManager.registerDevCmd(new FlashMsgCmd()); DevCmdManager.registerDevCmd(new FlashMsgCmd());

9
src/engine/objects/MobBase.java

@ -38,7 +38,6 @@ public class MobBase extends AbstractGameObject {
private int maxGold; private int maxGold;
private EnumBitSet<Enum.MobFlagType> flags; private EnumBitSet<Enum.MobFlagType> flags;
private EnumBitSet<Enum.AggroType> noAggro;
private int mask; private int mask;
private int goldMod; private int goldMod;
@ -110,7 +109,6 @@ public class MobBase extends AbstractGameObject {
} }
this.flags = EnumBitSet.asEnumBitSet(rs.getLong("flags"), Enum.MobFlagType.class); this.flags = EnumBitSet.asEnumBitSet(rs.getLong("flags"), Enum.MobFlagType.class);
this.noAggro = EnumBitSet.asEnumBitSet(rs.getLong("noaggro"), Enum.AggroType.class);
this.notEnemy = EnumBitSet.asEnumBitSet(rs.getLong("notEnemy"), Enum.MonsterType.class); this.notEnemy = EnumBitSet.asEnumBitSet(rs.getLong("notEnemy"), Enum.MonsterType.class);
this.enemy = EnumBitSet.asEnumBitSet(rs.getLong("enemy"), Enum.MonsterType.class); this.enemy = EnumBitSet.asEnumBitSet(rs.getLong("enemy"), Enum.MonsterType.class);
@ -247,10 +245,6 @@ public class MobBase extends AbstractGameObject {
return this.flags; return this.flags;
} }
public EnumBitSet getNoAggro() {
return this.noAggro;
}
public int getGoldMod() { public int getGoldMod() {
return this.goldMod; return this.goldMod;
} }
@ -284,9 +278,6 @@ public class MobBase extends AbstractGameObject {
return DbManager.MobBaseQueries.GET_MOBBASE(id, forceDB); return DbManager.MobBaseQueries.GET_MOBBASE(id, forceDB);
} }
public static MobBase copyMobBase(MobBase mobbase, String name) {
return DbManager.MobBaseQueries.COPY_MOBBASE(mobbase, name);
}
public static boolean renameMobBase(int ID, String newName) { public static boolean renameMobBase(int ID, String newName) {
return DbManager.MobBaseQueries.RENAME_MOBBASE(ID, newName); return DbManager.MobBaseQueries.RENAME_MOBBASE(ID, newName);

Loading…
Cancel
Save