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 @@ @@ -7,149 +7,153 @@
// www.magicbane.com
package engine.devcmd.cmds;
import engine.Enum.BuildingGroup;
import engine.Enum.GameObjectType;
import engine.devcmd.AbstractDevCmd;
import engine.gameManager.ChatManager;
import engine.gameManager.DbManager;
import engine.objects.AbstractGameObject;
import engine.objects.Contract;
import engine.objects.PlayerCharacter;
import engine.objects.*;
import engine.util.StringUtils;
import org.pmw.tinylog.Logger;
/**
* 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 SlotNpcCmd() {
public SlotNpcCmd() {
super("slotnpc");
}
// AbstractDevCmd Overridden methods
@Override
protected void _doCmd(PlayerCharacter pc, String[] args,
AbstractGameObject target) {
// AbstractDevCmd Overridden methods
Contract contractObject;
BuildingGroup buildingGroup;
private static boolean validateUserInput(String[] userInput) {
long slotBitvalue;
String outString;
int stringIndex;
BuildingGroup testGroup;
if (target.getObjectType() != GameObjectType.NPC) {
throwbackInfo(pc, "NpcSlot: target must be an NPC");
return;
}
testGroup = BuildingGroup.FORGE;
// Get the contract from the npc
contractObject = getTargetAsNPC(pc).getContract();
String commandSet = "onoff";
// 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);
return;
}
// Test of toggle argument
if(validateUserInput(args) == false) {
this.sendUsage(pc);
return;
}
stringIndex = commandSet.indexOf(userInput[1].toLowerCase());
// 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":
contractObject.getAllowedBuildings().add(buildingGroup);
@Override
protected void _doCmd(PlayerCharacter pc, String[] args,
AbstractGameObject target) {
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;
}
Contract contract;
BuildingGroup buildingGroup;
NPC npc;
Mob mob;
throwbackInfo(pc, "SlotNpc " + buildingGroup.name() + " added to npc");
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;
}
String outString;
throwbackInfo(pc, "SlotNpc " + buildingGroup.name() + " removed from npc");
break;
}
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");
return;
}
@Override
protected String _getHelpString() {
return "Sets a building slot on a targeted npc";
}
@Override
protected String _getUsageString() {
String usage = "/npcslot [BuildingType] on-off \n";
// User requests list of current groups.
for (BuildingGroup group:BuildingGroup.values()) {
usage += group.name() + ' ';
}
if (args[0].equalsIgnoreCase("LIST")) {
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 testGroup;
buildingGroup = BuildingGroup.valueOf(args[0].toUpperCase());
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)
return false;
throwbackInfo(pc, "SlotNpc " + buildingGroup.name() + " added to npc");
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)
return false;
// Class methods
// Validate we have a corrent building group name
@Override
protected String _getUsageString() {
String usage = "/npcslot [BuildingType] on-off \n";
for (BuildingGroup group:BuildingGroup.values()) {
if (group.name().equals(userInput[0].toUpperCase()))
return true;
}
return false;
for (BuildingGroup group : BuildingGroup.values()) {
usage += group.name() + ' ';
}
usage = StringUtils.wordWrap(usage, 30);
return usage;
}
}

Loading…
Cancel
Save