Files
Server/src/engine/devcmd/cmds/SlotNpcCmd.java
T

158 lines
4.7 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.devcmd.cmds;
import engine.mbEnums.BuildingGroup;
2022-04-30 09:41:17 -04:00
import engine.devcmd.AbstractDevCmd;
import engine.gameManager.ChatManager;
import engine.gameManager.DbManager;
import engine.objects.*;
2022-04-30 09:41:17 -04:00
import engine.util.StringUtils;
import org.pmw.tinylog.Logger;
/**
* Summary: Game designer utility command to add or
* remove building slot access for contracts
2022-04-30 09:41:17 -04:00
*/
2022-04-30 09:41:17 -04:00
public class SlotNpcCmd extends AbstractDevCmd {
public SlotNpcCmd() {
2022-04-30 09:41:17 -04:00
super("slotnpc");
}
// AbstractDevCmd Overridden methods
2022-04-30 09:41:17 -04:00
private static boolean validateUserInput(String[] userInput) {
2022-04-30 09:41:17 -04:00
int stringIndex;
BuildingGroup testGroup;
2022-04-30 09:41:17 -04:00
testGroup = BuildingGroup.FORGE;
2022-04-30 09:41:17 -04:00
String commandSet = "onoff";
2022-04-30 09:41:17 -04:00
// incorrect number of arguments test
2022-04-30 09:41:17 -04:00
if (userInput.length > 2)
return false;
2022-04-30 09:41:17 -04:00
// Test of toggle argument
2022-04-30 09:41:17 -04:00
stringIndex = commandSet.indexOf(userInput[1].toLowerCase());
2022-04-30 09:41:17 -04:00
if (stringIndex == -1)
return false;
2024-02-09 14:10:28 -05:00
// Validate we have a correct building group name
for (BuildingGroup group : BuildingGroup.values()) {
2022-04-30 09:41:17 -04:00
if (group.name().equals(userInput[0].toUpperCase()))
return true;
}
2022-04-30 09:41:17 -04:00
return false;
}
@Override
protected void _doCmd(PlayerCharacter pc, String[] args,
AbstractGameObject target) {
Contract contract;
BuildingGroup buildingGroup;
NPC npc;
Mob mob;
String outString;
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;
2022-04-30 09:41:17 -04:00
}
// User requests list of current groups.
if (args[0].equalsIgnoreCase("LIST")) {
outString = "Current: " + contract.getAllowedBuildings();
throwbackInfo(pc, outString);
return;
}
if (validateUserInput(args) == false) {
this.sendUsage(pc);
return;
}
// Extract the building group flag from user input
buildingGroup = BuildingGroup.valueOf(args[0].toUpperCase());
switch (args[1].toUpperCase()) {
case "ON":
contract.getAllowedBuildings().add(buildingGroup);
if (!DbManager.ContractQueries.updateAllowedBuildings(contract, contract.getAllowedBuildings().toLong())) {
Logger.error("Failed to update Database for Contract Allowed buildings");
2024-02-09 14:10:28 -05:00
ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. ");
return;
}
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");
2024-02-09 14:10:28 -05:00
ChatManager.chatSystemError(pc, "Failed to update Database for Contract Allowed buildings. ");
return;
}
throwbackInfo(pc, "SlotNpc " + buildingGroup.name() + " removed from npc");
break;
}
}
@Override
protected String _getHelpString() {
2024-02-09 14:10:28 -05:00
return "Toggles a building group on a targeted npc";
}
// Class methods
@Override
protected String _getUsageString() {
2024-02-09 14:10:28 -05:00
String usage = "/npcslot [BuildingGroup] on-off \n";
for (BuildingGroup group : BuildingGroup.values()) {
usage += group.name() + ' ';
}
usage = StringUtils.wordWrap(usage, 30);
return usage;
}
2022-04-30 09:41:17 -04:00
}