From ad7c86e809f2ce9a20b228d37245c398db0c35ca Mon Sep 17 00:00:00 2001 From: MobiusDev <8391001+MobiusDevelopment@users.noreply.github.com> Date: Sat, 28 Apr 2018 01:19:32 +0000 Subject: [PATCH] Added instance world support for StatsSet parameters. --- .../HallOfErosionAttack.java | 12 +- .../HallOfErosionDefence.java | 9 +- .../HallOfSufferingAttack.java | 90 ++++----- .../HallOfSufferingDefence.java | 90 ++++----- .../HeartInfinityAttack.java | 12 +- ...Q00694_BreakThroughTheHallOfSuffering.java | 23 ++- .../Q00695_DefendTheHallOfSuffering.java | 23 ++- .../l2jmobius/gameserver/model/StatsSet.java | 189 ++++++++++++++++-- .../model/instancezone/InstanceWorld.java | 62 +++++- .../model/variables/AbstractVariables.java | 1 + .../com/l2jmobius/gameserver/util/Util.java | 85 ++++++++ 11 files changed, 432 insertions(+), 164 deletions(-) diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfErosionAttack/HallOfErosionAttack.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfErosionAttack/HallOfErosionAttack.java index 6f05da80bc..439cc2d22b 100644 --- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfErosionAttack/HallOfErosionAttack.java +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfErosionAttack/HallOfErosionAttack.java @@ -64,14 +64,8 @@ public class HallOfErosionAttack extends AbstractNpcAI tumorCount += value; } - public synchronized void addTag(int value) - { - tag += value; - } - public HEAWorld() { - tag = -1; } } @@ -538,7 +532,8 @@ public class HallOfErosionAttack extends AbstractNpcAI if (npc.getId() == TUMOR_DEAD) { - world.addTag(1); + final int tag = world.getParameters().getInt("tag", -1); + world.getParameters().set("tag", tag + 1); } } return super.onSpawn(npc); @@ -659,7 +654,8 @@ public class HallOfErosionAttack extends AbstractNpcAI final L2Npc tumor = addSpawn(TUMOR_ALIVE, _deadTumor.getLocation(), _world.getInstanceId()); _world.npcList.add(tumor); _deadTumor.deleteMe(); - _world.addTag(-1); + final int tag = _world.getParameters().getInt("tag", -1); + _world.getParameters().set("tag", tag - 1); } } diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfErosionDefence/HallOfErosionDefence.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfErosionDefence/HallOfErosionDefence.java index e281bb1e65..8eb01f5f6f 100644 --- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfErosionDefence/HallOfErosionDefence.java +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfErosionDefence/HallOfErosionDefence.java @@ -58,14 +58,8 @@ public class HallOfErosionDefence extends AbstractNpcAI public long startTime = 0; public ScheduledFuture finishTask = null; - public synchronized void addTag(int value) - { - tag += value; - } - public HEDWorld() { - tag = -1; } } @@ -521,7 +515,8 @@ public class HallOfErosionDefence extends AbstractNpcAI final HEDWorld world = (HEDWorld) tmpworld; if (npc.getId() == TUMOR_DEAD) { - world.addTag(1); + final int tag = world.getParameters().getInt("tag", -1); + world.getParameters().set("tag", tag + 1); } } return super.onSpawn(npc); diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfSufferingAttack/HallOfSufferingAttack.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfSufferingAttack/HallOfSufferingAttack.java index f71bbbf8cc..d7f5977924 100644 --- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfSufferingAttack/HallOfSufferingAttack.java +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfSufferingAttack/HallOfSufferingAttack.java @@ -60,52 +60,6 @@ public class HallOfSufferingAttack extends AbstractNpcAI public HSAWorld() { - tag = -1; - } - - protected void calcRewardItemId() - { - final Long finishDiff = storeTime[1] - storeTime[0]; - if (finishDiff < 1260000) - { - tag = 13777; - } - else if (finishDiff < 1380000) - { - tag = 13778; - } - else if (finishDiff < 1500000) - { - tag = 13779; - } - else if (finishDiff < 1620000) - { - tag = 13780; - } - else if (finishDiff < 1740000) - { - tag = 13781; - } - else if (finishDiff < 1860000) - { - tag = 13782; - } - else if (finishDiff < 1980000) - { - tag = 13783; - } - else if (finishDiff < 2100000) - { - tag = 13784; - } - else if (finishDiff < 2220000) - { - tag = 13785; - } - else - { - tag = 13786; - } } } @@ -565,7 +519,49 @@ public class HallOfSufferingAttack extends AbstractNpcAI { world.incStatus(); world.storeTime[1] = System.currentTimeMillis(); - world.calcRewardItemId(); + + final Long finishDiff = world.storeTime[1] - world.storeTime[0]; + if (finishDiff < 1260000) + { + world.getParameters().set("tag", 13777); + } + else if (finishDiff < 1380000) + { + world.getParameters().set("tag", 13778); + } + else if (finishDiff < 1500000) + { + world.getParameters().set("tag", 13779); + } + else if (finishDiff < 1620000) + { + world.getParameters().set("tag", 13780); + } + else if (finishDiff < 1740000) + { + world.getParameters().set("tag", 13781); + } + else if (finishDiff < 1860000) + { + world.getParameters().set("tag", 13782); + } + else if (finishDiff < 1980000) + { + world.getParameters().set("tag", 13783); + } + else if (finishDiff < 2100000) + { + world.getParameters().set("tag", 13784); + } + else if (finishDiff < 2220000) + { + world.getParameters().set("tag", 13785); + } + else + { + world.getParameters().set("tag", 13786); + } + world.klanikus = null; world.klodekus = null; cancelQuestTimers("ressurectTwin"); diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfSufferingDefence/HallOfSufferingDefence.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfSufferingDefence/HallOfSufferingDefence.java index becdfd5f9b..9bf57a1286 100644 --- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfSufferingDefence/HallOfSufferingDefence.java +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HallOfSufferingDefence/HallOfSufferingDefence.java @@ -60,52 +60,6 @@ public class HallOfSufferingDefence extends AbstractNpcAI public HSDWorld() { - tag = -1; - } - - protected void calcRewardItemId() - { - final Long finishDiff = storeTime[1] - storeTime[0]; - if (finishDiff < 1260000) - { - tag = 13777; - } - else if (finishDiff < 1380000) - { - tag = 13778; - } - else if (finishDiff < 1500000) - { - tag = 13779; - } - else if (finishDiff < 1620000) - { - tag = 13780; - } - else if (finishDiff < 1740000) - { - tag = 13781; - } - else if (finishDiff < 1860000) - { - tag = 13782; - } - else if (finishDiff < 1980000) - { - tag = 13783; - } - else if (finishDiff < 2100000) - { - tag = 13784; - } - else if (finishDiff < 2220000) - { - tag = 13785; - } - else - { - tag = 13786; - } } } @@ -565,7 +519,49 @@ public class HallOfSufferingDefence extends AbstractNpcAI { world.incStatus(); world.storeTime[1] = System.currentTimeMillis(); - world.calcRewardItemId(); + + final Long finishDiff = world.storeTime[1] - world.storeTime[0]; + if (finishDiff < 1260000) + { + world.getParameters().set("tag", 13777); + } + else if (finishDiff < 1380000) + { + world.getParameters().set("tag", 13778); + } + else if (finishDiff < 1500000) + { + world.getParameters().set("tag", 13779); + } + else if (finishDiff < 1620000) + { + world.getParameters().set("tag", 13780); + } + else if (finishDiff < 1740000) + { + world.getParameters().set("tag", 13781); + } + else if (finishDiff < 1860000) + { + world.getParameters().set("tag", 13782); + } + else if (finishDiff < 1980000) + { + world.getParameters().set("tag", 13783); + } + else if (finishDiff < 2100000) + { + world.getParameters().set("tag", 13784); + } + else if (finishDiff < 2220000) + { + world.getParameters().set("tag", 13785); + } + else + { + world.getParameters().set("tag", 13786); + } + world.klanikus = null; world.klodekus = null; cancelQuestTimers("ressurectTwin"); diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HeartInfinityAttack/HeartInfinityAttack.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HeartInfinityAttack/HeartInfinityAttack.java index 5ec3467f58..65b5b97006 100644 --- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HeartInfinityAttack/HeartInfinityAttack.java +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/areas/Gracia/instances/HeartInfinityAttack/HeartInfinityAttack.java @@ -69,14 +69,8 @@ public class HeartInfinityAttack extends AbstractNpcAI tumorCount += value; } - public synchronized void addTag(int value) - { - tag += value; - } - public HIAWorld() { - tag = -1; } } @@ -585,7 +579,8 @@ public class HeartInfinityAttack extends AbstractNpcAI if (npc.getId() == DEADTUMOR) { - world.addTag(1); + final int tag = world.getParameters().getInt("tag", -1); + world.getParameters().set("tag", tag + 1); } } return super.onSpawn(npc); @@ -661,7 +656,8 @@ public class HeartInfinityAttack extends AbstractNpcAI notifyTumorRevival(_world); _world.npcList.add(alivetumor); _deadTumor.deleteMe(); - _world.addTag(-1); + final int tag = _world.getParameters().getInt("tag", -1); + _world.getParameters().set("tag", tag - 1); } } diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/quests/Q00694_BreakThroughTheHallOfSuffering/Q00694_BreakThroughTheHallOfSuffering.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/quests/Q00694_BreakThroughTheHallOfSuffering/Q00694_BreakThroughTheHallOfSuffering.java index dcb15f66d0..111004dc93 100644 --- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/quests/Q00694_BreakThroughTheHallOfSuffering/Q00694_BreakThroughTheHallOfSuffering.java +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/quests/Q00694_BreakThroughTheHallOfSuffering/Q00694_BreakThroughTheHallOfSuffering.java @@ -99,7 +99,8 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest final InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player); if ((world != null) && (world.getTemplateId() == 115)) { - if (world.tag == -1) + final int tag = world.getParameters().getInt("tag", -1); + if (tag == -1) { htmltext = "32530-11.html"; } @@ -110,7 +111,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest final QuestState qs1 = member.getQuestState(getName()); if (qs1 != null) { - if (world.tag == 13777) + if (tag == 13777) { if (getQuestItemsCount(member, MARK) == 0) { @@ -124,7 +125,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest htmltext = "32530-00.html"; finishInstance(player); } - else if (world.tag == 13778) + else if (tag == 13778) { if (getQuestItemsCount(member, MARK) == 0) { @@ -138,7 +139,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest htmltext = "32530-01.html"; finishInstance(player); } - else if (world.tag == 13779) + else if (tag == 13779) { if (getQuestItemsCount(member, MARK) == 0) { @@ -152,7 +153,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest htmltext = "32530-02.html"; finishInstance(player); } - else if (world.tag == 13780) + else if (tag == 13780) { if (getQuestItemsCount(member, MARK) == 0) { @@ -166,7 +167,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest htmltext = "32530-03.html"; finishInstance(player); } - else if (world.tag == 13781) + else if (tag == 13781) { if (getQuestItemsCount(member, MARK) == 0) { @@ -180,7 +181,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest htmltext = "32530-04.html"; finishInstance(player); } - else if (world.tag == 13782) + else if (tag == 13782) { if (getQuestItemsCount(member, MARK) == 0) { @@ -194,7 +195,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest htmltext = "32530-05.html"; finishInstance(player); } - else if (world.tag == 13783) + else if (tag == 13783) { if (getQuestItemsCount(member, MARK) == 0) { @@ -208,7 +209,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest htmltext = "32530-06.html"; finishInstance(player); } - else if (world.tag == 13784) + else if (tag == 13784) { if (getQuestItemsCount(member, MARK) == 0) { @@ -222,7 +223,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest htmltext = "32530-07.html"; finishInstance(player); } - else if (world.tag == 13785) + else if (tag == 13785) { if (getQuestItemsCount(member, MARK) == 0) { @@ -236,7 +237,7 @@ public final class Q00694_BreakThroughTheHallOfSuffering extends Quest htmltext = "32530-08.html"; finishInstance(player); } - else if (world.tag == 13786) + else if (tag == 13786) { if (getQuestItemsCount(member, MARK) == 0) { diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/quests/Q00695_DefendTheHallOfSuffering/Q00695_DefendTheHallOfSuffering.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/quests/Q00695_DefendTheHallOfSuffering/Q00695_DefendTheHallOfSuffering.java index ba10e59d2f..2e33de699c 100644 --- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/quests/Q00695_DefendTheHallOfSuffering/Q00695_DefendTheHallOfSuffering.java +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/quests/Q00695_DefendTheHallOfSuffering/Q00695_DefendTheHallOfSuffering.java @@ -108,7 +108,8 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest if ((world != null) && (world.getTemplateId() == 116)) { - if (world.tag == -1) + final int tag = world.getParameters().getInt("tag", -1); + if (tag == -1) { htmltext = "32530-11.html"; } @@ -119,7 +120,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest final QuestState qs1 = member.getQuestState(getName()); if (qs1 != null) { - if (world.tag == 13777) + if (tag == 13777) { giveItems(member, 13777, 1); giveItems(member, SOE, 1); @@ -129,7 +130,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest htmltext = "32530-00.html"; finishInstance(player); } - else if (world.tag == 13778) + else if (tag == 13778) { giveItems(member, 13778, 1); giveItems(member, SOE, 1); @@ -139,7 +140,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest htmltext = "32530-01.html"; finishInstance(player); } - else if (world.tag == 13779) + else if (tag == 13779) { giveItems(member, 13779, 1); giveItems(member, SOE, 1); @@ -149,7 +150,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest htmltext = "32530-02.html"; finishInstance(player); } - else if (world.tag == 13780) + else if (tag == 13780) { giveItems(member, 13780, 1); giveItems(member, SOE, 1); @@ -159,7 +160,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest htmltext = "32530-03.html"; finishInstance(player); } - else if (world.tag == 13781) + else if (tag == 13781) { giveItems(member, 13781, 1); giveItems(member, SOE, 1); @@ -169,7 +170,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest htmltext = "32530-04.html"; finishInstance(player); } - else if (world.tag == 13782) + else if (tag == 13782) { giveItems(member, 13782, 1); giveItems(member, SOE, 1); @@ -179,7 +180,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest htmltext = "32530-05.html"; finishInstance(player); } - else if (world.tag == 13783) + else if (tag == 13783) { giveItems(member, 13783, 1); giveItems(member, SOE, 1); @@ -189,7 +190,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest htmltext = "32530-06.html"; finishInstance(player); } - else if (world.tag == 13784) + else if (tag == 13784) { giveItems(member, 13784, 1); giveItems(member, SOE, 1); @@ -199,7 +200,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest htmltext = "32530-07.html"; finishInstance(player); } - else if (world.tag == 13785) + else if (tag == 13785) { giveItems(member, 13785, 1); giveItems(member, SOE, 1); @@ -209,7 +210,7 @@ public final class Q00695_DefendTheHallOfSuffering extends Quest htmltext = "32530-08.html"; finishInstance(player); } - else if (world.tag == 13786) + else if (tag == 13786) { giveItems(member, 13786, 1); giveItems(member, SOE, 1); diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/StatsSet.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/StatsSet.java index a2c373a808..b95711eb52 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/StatsSet.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/StatsSet.java @@ -23,10 +23,12 @@ import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; import com.l2jmobius.gameserver.model.holders.MinionHolder; import com.l2jmobius.gameserver.model.holders.SkillHolder; import com.l2jmobius.gameserver.model.interfaces.IParserAdvUtils; +import com.l2jmobius.gameserver.util.Util; /** * This class is meant to hold a set of (key,value) pairs.
@@ -187,11 +189,10 @@ public class StatsSet implements IParserAdvUtils } if (val instanceof Number) { - final byte[] result = + return new byte[] { ((Number) val).byteValue() }; - return result; } int c = 0; final String[] vals = ((String) val).split(splitOn); @@ -319,11 +320,10 @@ public class StatsSet implements IParserAdvUtils } if (val instanceof Number) { - final int[] result = + return new int[] { ((Number) val).intValue() }; - return result; } int c = 0; final String[] vals = ((String) val).split(splitOn); @@ -499,7 +499,11 @@ public class StatsSet implements IParserAdvUtils public String getString(String key, String defaultValue) { final Object val = _set.get(key); - return val == null ? defaultValue : String.valueOf(val); + if (val == null) + { + return defaultValue; + } + return String.valueOf(val); } @Override @@ -552,20 +556,168 @@ public class StatsSet implements IParserAdvUtils public final A getObject(String name, Class type) { final Object obj = _set.get(name); - return (obj == null) || !type.isAssignableFrom(obj.getClass()) ? null : (A) obj; + if ((obj == null) || !type.isAssignableFrom(obj.getClass())) + { + return null; + } + + return (A) obj; + } + + @SuppressWarnings("unchecked") + public final A getObject(String name, Class type, A defaultValue) + { + final Object obj = _set.get(name); + if ((obj == null) || !type.isAssignableFrom(obj.getClass())) + { + return defaultValue; + } + + return (A) obj; } public SkillHolder getSkillHolder(String key) { final Object obj = _set.get(key); - return (obj == null) || !(obj instanceof SkillHolder) ? null : (SkillHolder) obj; + if ((obj == null) || !(obj instanceof SkillHolder)) + { + return null; + } + + return (SkillHolder) obj; + } + + public Location getLocation(String key) + { + final Object obj = _set.get(key); + if ((obj == null) || !(obj instanceof Location)) + { + return null; + } + return (Location) obj; } @SuppressWarnings("unchecked") public List getMinionList(String key) { final Object obj = _set.get(key); - return (obj == null) || !(obj instanceof List) ? Collections.emptyList() : (List) obj; + if ((obj == null) || !(obj instanceof List)) + { + return Collections.emptyList(); + } + + return (List) obj; + } + + @SuppressWarnings("unchecked") + public List getList(String key, Class clazz) + { + final Object obj = _set.get(key); + if ((obj == null) || !(obj instanceof List)) + { + return null; + } + + final List originalList = (List) obj; + if (!originalList.isEmpty() && !originalList.stream().allMatch(clazz::isInstance)) + { + if (clazz.getSuperclass() == Enum.class) + { + throw new IllegalAccessError("Please use getEnumList if you want to get list of Enums!"); + } + + // Attempt to convert the list + final List convertedList = convertList(originalList, clazz); + if (convertedList == null) + { + LOGGER.log(Level.WARNING, "getList(\"" + key + "\", " + clazz.getSimpleName() + ") requested with wrong generic type: " + obj.getClass().getGenericInterfaces()[0] + "!", new ClassNotFoundException()); + return null; + } + + // Overwrite the existing list with proper generic type + _set.put(key, convertedList); + return convertedList; + } + return (List) obj; + } + + public List getList(String key, Class clazz, List defaultValue) + { + final List list = getList(key, clazz); + return list == null ? defaultValue : list; + } + + @SuppressWarnings("unchecked") + public > List getEnumList(String key, Class clazz) + { + final Object obj = _set.get(key); + if ((obj == null) || !(obj instanceof List)) + { + return null; + } + + final List originalList = (List) obj; + if (!originalList.isEmpty() && (obj.getClass().getGenericInterfaces()[0] != clazz) && originalList.stream().allMatch(name -> Util.isEnum(name.toString(), clazz))) + { + final List convertedList = originalList.stream().map(Object::toString).map(name -> Enum.valueOf(clazz, name)).map(clazz::cast).collect(Collectors.toList()); + + // Overwrite the existing list with proper generic type + _set.put(key, convertedList); + return convertedList; + } + return (List) obj; + } + + /** + * @param + * @param originalList + * @param clazz + * @return + */ + private List convertList(List originalList, Class clazz) + { + if (clazz == Integer.class) + { + if (originalList.stream().map(Object::toString).allMatch(Util::isInteger)) + { + return originalList.stream().map(Object::toString).map(Integer::valueOf).map(clazz::cast).collect(Collectors.toList()); + } + } + else if (clazz == Float.class) + { + if (originalList.stream().map(Object::toString).allMatch(Util::isFloat)) + { + return originalList.stream().map(Object::toString).map(Float::valueOf).map(clazz::cast).collect(Collectors.toList()); + } + } + else if (clazz == Double.class) + { + if (originalList.stream().map(Object::toString).allMatch(Util::isDouble)) + { + return originalList.stream().map(Object::toString).map(Double::valueOf).map(clazz::cast).collect(Collectors.toList()); + } + } + return null; + } + + @SuppressWarnings("unchecked") + public Map getMap(String key, Class keyClass, Class valueClass) + { + final Object obj = _set.get(key); + if ((obj == null) || !(obj instanceof Map)) + { + return null; + } + + final Map originalList = (Map) obj; + if (!originalList.isEmpty()) + { + if ((!originalList.keySet().stream().allMatch(keyClass::isInstance)) || (!originalList.values().stream().allMatch(valueClass::isInstance))) + { + LOGGER.log(Level.WARNING, "getMap(\"" + key + "\", " + keyClass.getSimpleName() + ", " + valueClass.getSimpleName() + ") requested with wrong generic type: " + obj.getClass().getGenericInterfaces()[0] + "!", new ClassNotFoundException()); + } + } + return (Map) obj; } public void set(String name, Object value) @@ -618,14 +770,19 @@ public class StatsSet implements IParserAdvUtils _set.put(key, value); } - public void safeSet(String key, int value, int min, int max, String reference) + public void remove(String key) { - assert ((min > max) || ((value >= min) && (value < max))); - if ((min <= max) && ((value < min) || (value >= max))) - { - LOGGER.log(Level.SEVERE, "Incorrect value: " + value + "for: " + key + "Ref: " + reference); - } - - set(key, value); + _set.remove(key); + } + + public boolean contains(String name) + { + return _set.containsKey(name); + } + + @Override + public String toString() + { + return "StatsSet{_set=" + _set + '}'; } } diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/instancezone/InstanceWorld.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/instancezone/InstanceWorld.java index b19d9879b0..d804711555 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/instancezone/InstanceWorld.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/instancezone/InstanceWorld.java @@ -18,9 +18,9 @@ package com.l2jmobius.gameserver.model.instancezone; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicInteger; import com.l2jmobius.gameserver.instancemanager.InstanceManager; +import com.l2jmobius.gameserver.model.StatsSet; import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.network.SystemMessageId; import com.l2jmobius.gameserver.network.serverpackets.SystemMessage; @@ -34,8 +34,7 @@ public class InstanceWorld private int _instanceId; private int _templateId = -1; private final List _allowed = new CopyOnWriteArrayList<>(); - private final AtomicInteger _status = new AtomicInteger(); - public int tag = -1; + private final StatsSet _parameters = new StatsSet(); public List getAllowed() { @@ -93,24 +92,69 @@ public class InstanceWorld _templateId = templateId; } + /** + * Set instance world parameter. + * @param key parameter name + * @param val parameter value + */ + public void setParameter(String key, Object val) + { + if (val == null) + { + _parameters.remove(key); + } + else + { + _parameters.set(key, val); + } + } + + /** + * Get instance world parameters. + * @return instance parameters + */ + public StatsSet getParameters() + { + return _parameters; + } + + /** + * Get status of instance world. + * @return instance status, otherwise 0 + */ public int getStatus() { - return _status.get(); + return _parameters.getInt("INSTANCE_STATUS", 0); } + /** + * Check if instance status is equal to {@code status}. + * @param status number used for status comparison + * @return {@code true} when instance status and {@code status} are equal, otherwise {@code false} + */ public boolean isStatus(int status) { - return _status.get() == status; + return getStatus() == status; } - public void setStatus(int status) + /** + * Set status of instance world. + * @param value new world status + */ + public void setStatus(int value) { - _status.set(status); + _parameters.set("INSTANCE_STATUS", value); } - public void incStatus() + /** + * Increment instance world status + * @return new world status + */ + public int incStatus() { - _status.incrementAndGet(); + final int status = getStatus() + 1; + setStatus(status); + return status; } /** diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/variables/AbstractVariables.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/variables/AbstractVariables.java index 3903aabaad..e24d5a8cbe 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/variables/AbstractVariables.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/variables/AbstractVariables.java @@ -108,6 +108,7 @@ public abstract class AbstractVariables extends StatsSet implements IRestorable, * Removes variable * @param name */ + @Override public final void remove(String name) { _hasChanges.compareAndSet(false, true); diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/util/Util.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/util/Util.java index 8d8874c3ee..7820c2a63b 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/util/Util.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/util/Util.java @@ -359,6 +359,91 @@ public final class Util return true; } + /** + * @param text - the text to check + * @return {@code true} if {@code text} is integer, {@code false} otherwise + */ + public static boolean isInteger(String text) + { + if ((text == null) || text.isEmpty()) + { + return false; + } + try + { + Integer.parseInt(text); + return true; + } + catch (Exception e) + { + return false; + } + } + + /** + * @param text - the text to check + * @return {@code true} if {@code text} is float, {@code false} otherwise + */ + public static boolean isFloat(String text) + { + if ((text == null) || text.isEmpty()) + { + return false; + } + try + { + Float.parseFloat(text); + return true; + } + catch (Exception e) + { + return false; + } + } + + /** + * @param text - the text to check + * @return {@code true} if {@code text} is double, {@code false} otherwise + */ + public static boolean isDouble(String text) + { + if ((text == null) || text.isEmpty()) + { + return false; + } + try + { + Double.parseDouble(text); + return true; + } + catch (Exception e) + { + return false; + } + } + + /** + * @param + * @param name - the text to check + * @param enumType + * @return {@code true} if {@code text} is enum, {@code false} otherwise + */ + public static > boolean isEnum(String name, Class enumType) + { + if ((name == null) || name.isEmpty()) + { + return false; + } + try + { + return Enum.valueOf(enumType, name) != null; + } + catch (Exception e) + { + return false; + } + } + /** * @param text - the text to check * @return {@code true} if {@code text} contains only letters and/or numbers, {@code false} otherwise