Made other efficiency changes to getting droid commands for a player

This commit is contained in:
CekisSWG
2018-06-06 20:50:03 +01:00
parent d5cd1a00db
commit e5a33f2d2b
3 changed files with 20 additions and 32 deletions

View File

@@ -2,6 +2,8 @@ package script.library;
import script.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
public class space_combat extends script.base_script
@@ -1947,33 +1949,25 @@ public class space_combat extends script.base_script
{
return null;
}
obj_id[] objContents = utils.getContents(objDataPad);
Vector strCommands = new Vector();
strCommands.setSize(0);
for (obj_id objContent : objContents) {
if (hasObjVar(objContent, "strDroidCommand")) {
String strTest = getStringObjVar(objContent, "strDroidCommand");
strCommands = utils.addElement(strCommands, strTest);
obj_id[] dataPadItems = utils.getContents(objDataPad);
List<String> droidCommands = new ArrayList<>();
for (obj_id dataPadItem : dataPadItems) {
if (hasObjVar(dataPadItem, "strDroidCommand")) {
droidCommands.add(getStringObjVar(dataPadItem, "strDroidCommand"));
}
}
if(strCommands.size() > 0)
return (String[]) strCommands.toArray(new String[0]);
return null;
return droidCommands.toArray(new String[0]);
}
public static String[] getDroidCommands(obj_id objPlayer) throws InterruptedException
{
String[] strRawCommands = getCommandListingForPlayer(objPlayer);
Vector strDroidCommands = new Vector();
strDroidCommands.setSize(0);
for (String strRawCommand : strRawCommands) {
int intIndex = strRawCommand.indexOf("droidcommand");
if (intIndex > -1) {
strDroidCommands = utils.addElement(strDroidCommands, strRawCommand);
String[] playerCommands = getCommandListingForPlayer(objPlayer);
List<String> droidCommands = new ArrayList<>();
for (String playerCommand : playerCommands) {
if (playerCommand.contains("droidcommand")) {
droidCommands.add(playerCommand);
}
}
if (strDroidCommands.size() > 0)
return (String[]) strDroidCommands.toArray();
return null;
return droidCommands.toArray(new String[0]);
}
public static void grantCapitalShipSequenceRewardsAndCreditForKills(obj_id objDefender) throws InterruptedException
{

View File

@@ -1,12 +1,8 @@
package script.library;
import script.*;
import script.base_class.*;
import script.combat_engine.*;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Vector;
import script.base_script;
public class space_transition extends script.base_script
{
@@ -870,9 +866,8 @@ public class space_transition extends script.base_script
String[] strDroidCommands = space_combat.getProgrammedDroidCommands(objPlayer);
if (strDroidCommands != null && strDroidCommands.length > 0)
{
for (int intI = 0; intI < strDroidCommands.length; intI++)
{
grantCommand(objPlayer, "droid+" + strDroidCommands[intI]);
for (String strDroidCommand : strDroidCommands) {
grantCommand(objPlayer, "droid+" + strDroidCommand);
}
}
}
@@ -881,9 +876,8 @@ public class space_transition extends script.base_script
String[] strDroidCommands = space_combat.getProgrammedDroidCommands(objPlayer);
if (strDroidCommands != null && strDroidCommands.length > 0)
{
for (int intI = 0; intI < strDroidCommands.length; intI++)
{
revokeCommand(objPlayer, "droid+" + strDroidCommands[intI]);
for (String strDroidCommand : strDroidCommands) {
revokeCommand(objPlayer, "droid+" + strDroidCommand);
}
}
}

View File

@@ -46,7 +46,7 @@ public class droid_memory_module extends script.base_script
if (item == menu_info_types.MEMORY_CHIP_PROGRAM)
{
String[] strDroidCommands = space_combat.getDroidCommands(objPlayer);
if (strDroidCommands == null)
if (strDroidCommands.length == 0)
{
string_id strSpam = new string_id("space/space_interaction", "no_droid_commands");
sendSystemMessage(objPlayer, strSpam);