Browse Source

slotnpc dev command now supports both mobs and npc's.

master
MagicBot 2 years ago
parent
commit
5d6e43313b
  1. 104
      src/engine/devcmd/cmds/SlotNpcCmd.java

104
src/engine/devcmd/cmds/SlotNpcCmd.java

@ -7,17 +7,13 @@
// www.magicbane.com // www.magicbane.com
package engine.devcmd.cmds; package engine.devcmd.cmds;
import engine.Enum.BuildingGroup; import engine.Enum.BuildingGroup;
import engine.Enum.GameObjectType;
import engine.devcmd.AbstractDevCmd; import engine.devcmd.AbstractDevCmd;
import engine.gameManager.ChatManager; import engine.gameManager.ChatManager;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.objects.AbstractGameObject; import engine.objects.*;
import engine.objects.Contract;
import engine.objects.PlayerCharacter;
import engine.util.StringUtils; import engine.util.StringUtils;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -35,29 +31,68 @@ public class SlotNpcCmd extends AbstractDevCmd {
// AbstractDevCmd Overridden methods // AbstractDevCmd Overridden methods
private static boolean validateUserInput(String[] userInput) {
int stringIndex;
BuildingGroup testGroup;
testGroup = BuildingGroup.FORGE;
String commandSet = "onoff";
// incorrect number of arguments test
if (userInput.length > 2)
return false;
// Test of toggle argument
stringIndex = commandSet.indexOf(userInput[1].toLowerCase());
if (stringIndex == -1)
return false;
// Validate we have a corrent building group name
for (BuildingGroup group : BuildingGroup.values()) {
if (group.name().equals(userInput[0].toUpperCase()))
return true;
}
return false;
}
@Override @Override
protected void _doCmd(PlayerCharacter pc, String[] args, protected void _doCmd(PlayerCharacter pc, String[] args,
AbstractGameObject target) { AbstractGameObject target) {
Contract contractObject; Contract contract;
BuildingGroup buildingGroup; BuildingGroup buildingGroup;
NPC npc;
Mob mob;
long slotBitvalue;
String outString; String outString;
if (target.getObjectType() != GameObjectType.NPC) { switch (target.getObjectType()) {
case NPC:
npc = (NPC) target;
contract = npc.getContract();
break;
case Mob:
mob = (Mob) target;
contract = mob.getContract();
break;
default:
throwbackInfo(pc, "NpcSlot: target must be an NPC"); throwbackInfo(pc, "NpcSlot: target must be an NPC");
return; return;
} }
// Get the contract from the npc
contractObject = getTargetAsNPC(pc).getContract();
// User requests list of current groups. // User requests list of current groups.
if (args[0].toUpperCase().equals("LIST")) { if (args[0].equalsIgnoreCase("LIST")) {
outString = "Current: " + contractObject.getAllowedBuildings(); outString = "Current: " + contract.getAllowedBuildings();
throwbackInfo(pc, outString); throwbackInfo(pc, outString);
return; return;
@ -75,9 +110,9 @@ public class SlotNpcCmd extends AbstractDevCmd {
switch (args[1].toUpperCase()) { switch (args[1].toUpperCase()) {
case "ON": case "ON":
contractObject.getAllowedBuildings().add(buildingGroup); contract.getAllowedBuildings().add(buildingGroup);
if (!DbManager.ContractQueries.updateAllowedBuildings(contractObject, contractObject.getAllowedBuildings().toLong())){ if (!DbManager.ContractQueries.updateAllowedBuildings(contract, contract.getAllowedBuildings().toLong())) {
Logger.error("Failed to update Database for Contract Allowed buildings"); Logger.error("Failed to update Database for Contract Allowed buildings");
ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. " + ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. " +
"Contact A CCR, oh wait, you are a CCR. You're Fubared."); "Contact A CCR, oh wait, you are a CCR. You're Fubared.");
@ -87,8 +122,8 @@ public class SlotNpcCmd extends AbstractDevCmd {
throwbackInfo(pc, "SlotNpc " + buildingGroup.name() + " added to npc"); throwbackInfo(pc, "SlotNpc " + buildingGroup.name() + " added to npc");
break; break;
case "OFF": case "OFF":
contractObject.getAllowedBuildings().remove(buildingGroup); contract.getAllowedBuildings().remove(buildingGroup);
if (!DbManager.ContractQueries.updateAllowedBuildings(contractObject, contractObject.getAllowedBuildings().toLong())){ if (!DbManager.ContractQueries.updateAllowedBuildings(contract, contract.getAllowedBuildings().toLong())) {
Logger.error("Failed to update Database for Contract Allowed buildings"); Logger.error("Failed to update Database for Contract Allowed buildings");
ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. " + ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. " +
"Contact A CCR, oh wait, you are a CCR. You're Fubared."); "Contact A CCR, oh wait, you are a CCR. You're Fubared.");
@ -106,6 +141,8 @@ public class SlotNpcCmd extends AbstractDevCmd {
return "Sets a building slot on a targeted npc"; return "Sets a building slot on a targeted npc";
} }
// Class methods
@Override @Override
protected String _getUsageString() { protected String _getUsageString() {
String usage = "/npcslot [BuildingType] on-off \n"; String usage = "/npcslot [BuildingType] on-off \n";
@ -119,37 +156,4 @@ public class SlotNpcCmd extends AbstractDevCmd {
return usage; return usage;
} }
// Class methods
private static boolean validateUserInput(String[] userInput) {
int stringIndex;
BuildingGroup testGroup;
testGroup = BuildingGroup.FORGE;
String commandSet = "onoff";
// incorrect number of arguments test
if (userInput.length > 2)
return false;
// Test of toggle argument
stringIndex = commandSet.indexOf(userInput[1].toLowerCase());
if (stringIndex == -1)
return false;
// Validate we have a corrent building group name
for (BuildingGroup group:BuildingGroup.values()) {
if (group.name().equals(userInput[0].toUpperCase()))
return true;
}
return false;
}
} }

Loading…
Cancel
Save