Addition of generic getRandomEntry method.

This commit is contained in:
MobiusDevelopment
2019-10-29 13:52:24 +00:00
parent 60b7afe5e3
commit dde3a7274f
542 changed files with 1650 additions and 1309 deletions

View File

@@ -51,7 +51,7 @@ public class Toma extends AbstractNpcAI
{
if (event.equals("RESPAWN_TOMA"))
{
addSpawn(TOMA, LOCATIONS[getRandom(LOCATIONS.length)], false, TELEPORT_DELAY);
addSpawn(TOMA, getRandomEntry(LOCATIONS), false, TELEPORT_DELAY);
}
return null;
}

View File

@@ -59,7 +59,7 @@ public class TimakOrcTroopLeader extends AbstractNpcAI
{
addMinion((MonsterInstance) npc, is.getId());
}
npc.broadcastSay(ChatType.NPC_GENERAL, ON_ATTACK_MSG[getRandom(ON_ATTACK_MSG.length)]);
npc.broadcastSay(ChatType.NPC_GENERAL, getRandomEntry(ON_ATTACK_MSG));
}
}
}

View File

@@ -116,7 +116,7 @@ public class FactionSystem extends AbstractNpcAI
{
if (npc != null)
{
npc.broadcastSay(ChatType.NPC_GENERAL, TEXTS[getRandom(TEXTS.length)], 1500);
npc.broadcastSay(ChatType.NPC_GENERAL, getRandomEntry(TEXTS), 1500);
}
break;
}

View File

@@ -95,8 +95,7 @@ public class Elpies extends Event
EVENT_ACTIVE = true;
final EventLocation[] locations = EventLocation.values();
final EventLocation randomLoc = locations[getRandom(locations.length)];
final EventLocation randomLoc = getRandomEntry(EventLocation.values());
CURRENT_ELPY_COUNT = 0;
final long despawnDelay = EVENT_DURATION_MINUTES * 60000;

View File

@@ -3005,22 +3005,43 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
/**
* Get a random entry.<br>
* @param entry array with values.
* @return random one value from array entry.
* @param <T>
* @param array of values.
* @return one value from array.
*/
public static String getRandomEntry(String... entry)
@SuppressWarnings("unchecked")
public static <T> T getRandomEntry(T... array)
{
return entry[getRandom(entry.length)];
if (array.length == 0)
{
return null;
}
return array[getRandom(array.length)];
}
/**
* Get a random entry.<br>
* @param entry array with values.
* @return random one value from array entry.
* @param <T>
* @param list of values.
* @return one value from list.
*/
public static int getRandomEntry(int... entry)
public static <T> T getRandomEntry(List<T> list)
{
return entry[getRandom(entry.length)];
if (list.isEmpty())
{
return null;
}
return list.get(getRandom(list.size()));
}
/**
* Get a random entry.<br>
* @param array of Integers.
* @return one Integer from array.
*/
public static int getRandomEntry(int... array)
{
return array[getRandom(array.length)];
}
/**