From 60b88435637d3efbe213ae7506692f0117f1ea34 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 4 May 2024 21:38:06 -0500 Subject: [PATCH] Added ./setrace command --- src/engine/db/handlers/dbNPCHandler.java | 14 +++++++ src/engine/devcmd/cmds/SetRaceCmd.java | 51 +++++++++++++++++++++++ src/engine/gameManager/DevCmdManager.java | 1 + src/engine/objects/NPC.java | 2 +- 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/engine/devcmd/cmds/SetRaceCmd.java diff --git a/src/engine/db/handlers/dbNPCHandler.java b/src/engine/db/handlers/dbNPCHandler.java index 38ec0fee..f9c39dcd 100644 --- a/src/engine/db/handlers/dbNPCHandler.java +++ b/src/engine/db/handlers/dbNPCHandler.java @@ -309,7 +309,21 @@ public class dbNPCHandler extends dbHandlerBase { return false; } } + public boolean UPDATE_RACE(NPC npc, int value) { + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `npc_raceID`=? WHERE `UID`=?")) { + + preparedStatement.setInt(1, value); + preparedStatement.setLong(2, npc.getObjectUUID()); + + return (preparedStatement.executeUpdate() > 0); + + } catch (SQLException e) { + Logger.error(e); + return false; + } + } public void LOAD_PIRATE_NAMES() { String pirateName; diff --git a/src/engine/devcmd/cmds/SetRaceCmd.java b/src/engine/devcmd/cmds/SetRaceCmd.java new file mode 100644 index 00000000..f9816aed --- /dev/null +++ b/src/engine/devcmd/cmds/SetRaceCmd.java @@ -0,0 +1,51 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + + +package engine.devcmd.cmds; + +import engine.InterestManagement.WorldGrid; +import engine.devcmd.AbstractDevCmd; +import engine.gameManager.BuildingManager; +import engine.gameManager.ChatManager; +import engine.gameManager.DbManager; +import engine.mbEnums; +import engine.objects.*; + +public class SetRaceCmd extends AbstractDevCmd { + + public SetRaceCmd() { + super("setRace"); + } + + @Override + protected void _doCmd(PlayerCharacter player, String[] words, + AbstractGameObject target) { + + int newRace = Integer.parseInt(words[0]); + + if(target.getObjectType().equals(mbEnums.GameObjectType.NPC) == false){ + throwbackError(player, "You Must Target An NPC"); + } + + NPC npc = (NPC)target; + npc.loadID = newRace; + DbManager.NPCQueries.UPDATE_RACE(npc,newRace); + } + + @Override + protected String _getHelpString() { + return "Sets NPC race"; + } + + @Override + protected String _getUsageString() { + return "' /setrace ID'"; + } + +} diff --git a/src/engine/gameManager/DevCmdManager.java b/src/engine/gameManager/DevCmdManager.java index dd0e25a6..ee1e8fbb 100644 --- a/src/engine/gameManager/DevCmdManager.java +++ b/src/engine/gameManager/DevCmdManager.java @@ -76,6 +76,7 @@ public enum DevCmdManager { DevCmdManager.registerDevCmd(new SetLevelCmd()); DevCmdManager.registerDevCmd(new SetBaseClassCmd()); DevCmdManager.registerDevCmd(new SetPromotionClassCmd()); + DevCmdManager.registerDevCmd(new SetRaceCmd()); DevCmdManager.registerDevCmd(new SetRuneCmd()); DevCmdManager.registerDevCmd(new GetOffsetCmd()); DevCmdManager.registerDevCmd(new AddGoldCmd()); diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index ddb12851..94180f65 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -50,7 +50,7 @@ public class NPC extends AbstractCharacter { public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock(); public int runeSetID = 0; public int extraRune2 = 0; - protected int loadID; + public int loadID; protected MobBase mobBase; protected String name; protected int dbID;