Browse Source

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

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

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

@ -7,149 +7,153 @@
// 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;
/** /**
* Summary: Game designer utility command to add or * Summary: Game designer utility command to add or
* remove building slot access for contracts * remove building slot access for contracts
*/ */
public class SlotNpcCmd extends AbstractDevCmd { public class SlotNpcCmd extends AbstractDevCmd {
public SlotNpcCmd() { public SlotNpcCmd() {
super("slotnpc"); super("slotnpc");
} }
// AbstractDevCmd Overridden methods // AbstractDevCmd Overridden methods
@Override
protected void _doCmd(PlayerCharacter pc, String[] args,
AbstractGameObject target) {
Contract contractObject; private static boolean validateUserInput(String[] userInput) {
BuildingGroup buildingGroup;
long slotBitvalue; int stringIndex;
String outString; BuildingGroup testGroup;
if (target.getObjectType() != GameObjectType.NPC) { testGroup = BuildingGroup.FORGE;
throwbackInfo(pc, "NpcSlot: target must be an NPC");
return;
}
// Get the contract from the npc String commandSet = "onoff";
contractObject = getTargetAsNPC(pc).getContract();
// User requests list of current groups. // incorrect number of arguments test
if (args[0].toUpperCase().equals("LIST")) { if (userInput.length > 2)
return false;
outString = "Current: " + contractObject.getAllowedBuildings();
throwbackInfo(pc, outString); // Test of toggle argument
return;
}
if(validateUserInput(args) == false) { stringIndex = commandSet.indexOf(userInput[1].toLowerCase());
this.sendUsage(pc);
return;
}
// Extract the building group flag from user input if (stringIndex == -1)
return false;
buildingGroup = BuildingGroup.valueOf(args[0].toUpperCase()); // Validate we have a corrent building group name
switch (args[1].toUpperCase()) { for (BuildingGroup group : BuildingGroup.values()) {
if (group.name().equals(userInput[0].toUpperCase()))
return true;
}
return false;
}
case "ON": @Override
contractObject.getAllowedBuildings().add(buildingGroup); protected void _doCmd(PlayerCharacter pc, String[] args,
AbstractGameObject target) {
if (!DbManager.ContractQueries.updateAllowedBuildings(contractObject, contractObject.getAllowedBuildings().toLong())){ Contract contract;
Logger.error( "Failed to update Database for Contract Allowed buildings"); BuildingGroup buildingGroup;
ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. " + NPC npc;
"Contact A CCR, oh wait, you are a CCR. You're Fubared."); Mob mob;
return;
}
throwbackInfo(pc, "SlotNpc " + buildingGroup.name() + " added to npc"); String outString;
break;
case "OFF":
contractObject.getAllowedBuildings().remove(buildingGroup);
if (!DbManager.ContractQueries.updateAllowedBuildings(contractObject, contractObject.getAllowedBuildings().toLong())){
Logger.error( "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.");
return;
}
throwbackInfo(pc, "SlotNpc " + buildingGroup.name() + " removed from npc"); switch (target.getObjectType()) {
break;
}
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");
return;
} }
@Override // User requests list of current groups.
protected String _getHelpString() {
return "Sets a building slot on a targeted npc";
}
@Override
protected String _getUsageString() {
String usage = "/npcslot [BuildingType] on-off \n";
for (BuildingGroup group:BuildingGroup.values()) { if (args[0].equalsIgnoreCase("LIST")) {
usage += group.name() + ' ';
}
usage = StringUtils.wordWrap(usage, 30); outString = "Current: " + contract.getAllowedBuildings();
return usage; throwbackInfo(pc, outString);
} return;
}
// Class methods if (validateUserInput(args) == false) {
this.sendUsage(pc);
return;
}
private static boolean validateUserInput(String[] userInput) { // Extract the building group flag from user input
int stringIndex; buildingGroup = BuildingGroup.valueOf(args[0].toUpperCase());
BuildingGroup testGroup;
testGroup = BuildingGroup.FORGE; switch (args[1].toUpperCase()) {
String commandSet = "onoff"; case "ON":
contract.getAllowedBuildings().add(buildingGroup);
// incorrect number of arguments test if (!DbManager.ContractQueries.updateAllowedBuildings(contract, contract.getAllowedBuildings().toLong())) {
Logger.error("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.");
return;
}
if (userInput.length > 2) throwbackInfo(pc, "SlotNpc " + buildingGroup.name() + " added to npc");
return false; break;
case "OFF":
contract.getAllowedBuildings().remove(buildingGroup);
if (!DbManager.ContractQueries.updateAllowedBuildings(contract, contract.getAllowedBuildings().toLong())) {
Logger.error("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.");
return;
}
throwbackInfo(pc, "SlotNpc " + buildingGroup.name() + " removed from npc");
break;
}
// Test of toggle argument }
stringIndex = commandSet.indexOf(userInput[1].toLowerCase()); @Override
protected String _getHelpString() {
return "Sets a building slot on a targeted npc";
}
if (stringIndex == -1) // Class methods
return false;
// Validate we have a corrent building group name @Override
protected String _getUsageString() {
String usage = "/npcslot [BuildingType] on-off \n";
for (BuildingGroup group:BuildingGroup.values()) { for (BuildingGroup group : BuildingGroup.values()) {
if (group.name().equals(userInput[0].toUpperCase())) usage += group.name() + ' ';
return true;
}
return false;
} }
usage = StringUtils.wordWrap(usage, 30);
return usage;
}
} }

Loading…
Cancel
Save