From 752d497142fef0e1aa44e9fc1d4e40b23cdf523b Mon Sep 17 00:00:00 2001 From: Waverunner Date: Thu, 20 Aug 2015 13:05:27 -0400 Subject: [PATCH] Added foundation for /qatool command for easy QA features such as generating an item from a template --- .../commands/callbacks/QaToolCmdCallback.java | 148 ++++++++++++++++++ src/services/commands/CommandService.java | 1 + 2 files changed, 149 insertions(+) create mode 100644 src/resources/commands/callbacks/QaToolCmdCallback.java diff --git a/src/resources/commands/callbacks/QaToolCmdCallback.java b/src/resources/commands/callbacks/QaToolCmdCallback.java new file mode 100644 index 000000000..f42290a6b --- /dev/null +++ b/src/resources/commands/callbacks/QaToolCmdCallback.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2015 /// Project SWG /// www.projectswg.com + * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. + * Our goal is to create an emulator which will provide a server for players to + * continue playing a game similar to the one they used to play. We are basing + * it on the final publish of the game prior to end-game events. + * + * This file is part of Holocore. + * + * -------------------------------------------------------------------------------- + * + * Holocore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Holocore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Holocore. If not, see + ******************************************************************************/ + +package resources.commands.callbacks; + +import intents.chat.ChatBroadcastIntent; +import resources.commands.ICmdCallback; +import resources.objects.SWGObject; +import resources.player.Player; +import resources.server_info.Log; +import resources.sui.ISuiCallback; +import resources.sui.SuiButtons; +import resources.sui.SuiEvent; +import resources.sui.SuiInputBox; +import resources.sui.SuiListBox; +import resources.sui.SuiMessageBox; +import services.galaxy.GalacticManager; + +import java.util.Map; + +/** + * Created by Waverunner on 8/19/2015 + */ +public class QaToolCmdCallback implements ICmdCallback { + private static final String TITLE = "QA Tool"; + private static final String PROMPT = "Select the action that you would like to do"; + + private GalacticManager galacticManager; + + @Override + public void execute(GalacticManager galacticManager, Player player, SWGObject target, String args) { + if (this.galacticManager == null) + this.galacticManager = galacticManager; + + if (args != null && !args.isEmpty()) { + String[] command = args.split(" "); + + switch(command[0]) { + case "item": + if (command.length > 1) handleCreateItem(player, command[1]); + else displayItemCreator(player); + break; + case "help": displayHelp(player); break; + default: displayMainWindow(player); break; + } + } else { + displayMainWindow(player); + } + Log.i("QA", "%s has accessed the QA Tool", player.getUsername()); + } + + /* Windows */ + + private void displayMainWindow(Player player) { + SuiListBox window = new SuiListBox(SuiButtons.OK_CANCEL, TITLE, PROMPT); + window.addListItem("Item Creator"); + + window.addCallback("handleQaTool", new QaListBoxSuiCallback()); + window.display(player); + } + + private void displayItemCreator(Player creator) { + SuiInputBox inputBox = new SuiInputBox(SuiButtons.OK_CANCEL, "Item Creator", "Enter the template of the item you wish to create"); + inputBox.addOkButtonCallback("handleCreateItem", (player, actor, event, parameters) -> handleCreateItem(player, SuiInputBox.getEnteredText(parameters))); + inputBox.addCancelButtonCallback("displayMainWindow", (player, actor, event, parameters) -> displayMainWindow(player)); + inputBox.display(creator); + } + + /* Handlers */ + + private void handleCreateItem(Player player, String template) { + SWGObject object = galacticManager.getObjectManager().createObject(template); + if (object == null) { + sendSystemMessage(player, "Failed to create object with template \'" + template + "\'"); + return; + } + + SWGObject creature = player.getCreatureObject(); + if (creature == null) + return; + + SWGObject inventory = creature.getSlottedObject("inventory"); + if (inventory == null) + return; + + inventory.addObject(object); + sendSystemMessage(player, "Object has been created and placed in your inventory"); + Log.i("QA", "%s created item from template %s", player, template); + } + + private void displayHelp(Player player) { + String prompt = "The following are acceptable arguments that can be used as shortcuts to the various QA tools:\n" + + "item