From 0777e5529fdc82fa2b2a4df7cb274a2b44c6674c Mon Sep 17 00:00:00 2001 From: P0nk Date: Thu, 9 Sep 2021 23:05:32 +0200 Subject: [PATCH] Rename and clean up MapleQuestAction --- src/main/java/server/quest/Quest.java | 28 ++-- .../quest/actions/AbstractQuestAction.java | 131 +++++++++++++++++ .../java/server/quest/actions/BuffAction.java | 2 +- .../java/server/quest/actions/ExpAction.java | 2 +- .../java/server/quest/actions/FameAction.java | 2 +- .../java/server/quest/actions/InfoAction.java | 2 +- .../java/server/quest/actions/ItemAction.java | 2 +- .../quest/actions/MapleQuestAction.java | 132 ------------------ .../java/server/quest/actions/MesoAction.java | 2 +- .../server/quest/actions/NextQuestAction.java | 2 +- .../server/quest/actions/PetSkillAction.java | 2 +- .../server/quest/actions/PetSpeedAction.java | 2 +- .../quest/actions/PetTamenessAction.java | 2 +- .../server/quest/actions/QuestAction.java | 2 +- .../server/quest/actions/SkillAction.java | 2 +- 15 files changed, 157 insertions(+), 158 deletions(-) create mode 100644 src/main/java/server/quest/actions/AbstractQuestAction.java delete mode 100644 src/main/java/server/quest/actions/MapleQuestAction.java diff --git a/src/main/java/server/quest/Quest.java b/src/main/java/server/quest/Quest.java index 3e39778669..12722f9ad6 100644 --- a/src/main/java/server/quest/Quest.java +++ b/src/main/java/server/quest/Quest.java @@ -60,8 +60,8 @@ public class Quest { protected int timeLimit, timeLimit2; protected Map startReqs = new EnumMap<>(QuestRequirementType.class); protected Map completeReqs = new EnumMap<>(QuestRequirementType.class); - protected Map startActs = new EnumMap<>(QuestActionType.class); - protected Map completeActs = new EnumMap<>(QuestActionType.class); + protected Map startActs = new EnumMap<>(QuestActionType.class); + protected Map completeActs = new EnumMap<>(QuestActionType.class); protected List relevantMobs = new LinkedList<>(); private boolean autoStart; private boolean autoPreComplete, autoComplete; @@ -148,7 +148,7 @@ public class Quest { if (startActData != null) { for (Data startAct : startActData.getChildren()) { QuestActionType questActionType = QuestActionType.getByWZName(startAct.getName()); - MapleQuestAction act = this.getAction(questActionType, startAct); + AbstractQuestAction act = this.getAction(questActionType, startAct); if (act == null) { continue; @@ -161,7 +161,7 @@ public class Quest { if (completeActData != null) { for (Data completeAct : completeActData.getChildren()) { QuestActionType questActionType = QuestActionType.getByWZName(completeAct.getName()); - MapleQuestAction act = this.getAction(questActionType, completeAct); + AbstractQuestAction act = this.getAction(questActionType, completeAct); if (act == null) { continue; @@ -267,13 +267,13 @@ public class Quest { public void start(Character chr, int npc) { if (autoStart || canStart(chr, npc)) { - Collection acts = startActs.values(); - for (MapleQuestAction a : acts) { + Collection acts = startActs.values(); + for (AbstractQuestAction a : acts) { if (!a.check(chr, null)) { // would null be good ? return; } } - for (MapleQuestAction a : acts) { + for (AbstractQuestAction a : acts) { a.run(chr, null); } forceStart(chr, npc); @@ -286,14 +286,14 @@ public class Quest { public void complete(Character chr, int npc, Integer selection) { if (autoPreComplete || canComplete(chr, npc)) { - Collection acts = completeActs.values(); - for (MapleQuestAction a : acts) { + Collection acts = completeActs.values(); + for (AbstractQuestAction a : acts) { if (!a.check(chr, selection)) { return; } } forceComplete(chr, npc); - for (MapleQuestAction a : acts) { + for (AbstractQuestAction a : acts) { a.run(chr, selection); } if (!this.hasNextQuestAction()) { @@ -534,8 +534,8 @@ public class Quest { return ret; } - private MapleQuestAction getAction(QuestActionType type, Data data) { - MapleQuestAction ret = null; + private AbstractQuestAction getAction(QuestActionType type, Data data) { + AbstractQuestAction ret = null; switch (type) { case BUFF: ret = new BuffAction(this, data); @@ -618,8 +618,8 @@ public class Quest { } public boolean hasNextQuestAction() { - Map acts = completeActs; - MapleQuestAction mqa = acts.get(QuestActionType.NEXTQUEST); + Map acts = completeActs; + AbstractQuestAction mqa = acts.get(QuestActionType.NEXTQUEST); return mqa != null; } diff --git a/src/main/java/server/quest/actions/AbstractQuestAction.java b/src/main/java/server/quest/actions/AbstractQuestAction.java new file mode 100644 index 0000000000..e438020d80 --- /dev/null +++ b/src/main/java/server/quest/actions/AbstractQuestAction.java @@ -0,0 +1,131 @@ +/* + This file is part of the MapleSolaxia Maple Story Server + + This program 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 version 3 as published by + the Free Software Foundation. You may not use, modify or distribute + this program under any other version of the GNU Affero General Public + License. + + This program 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 this program. If not, see . +*/ +package server.quest.actions; + +import client.Character; +import provider.Data; +import server.quest.Quest; +import server.quest.QuestActionType; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Tyler (Twdtwd) + */ +public abstract class AbstractQuestAction { + private final QuestActionType type; + protected int questID; + + public AbstractQuestAction(QuestActionType action, Quest quest) { + this.type = action; + this.questID = quest.getId(); + } + + public abstract void run(Character chr, Integer extSelection); + public abstract void processData(Data data); + + public boolean check(Character chr, Integer extSelection) { + return true; + } + + public QuestActionType getType() { + return type; + } + + public static List getJobBy5ByteEncoding(int encoded) { + List ret = new ArrayList<>(); + if ((encoded & 0x1) != 0) { + ret.add(0); + } + if ((encoded & 0x2) != 0) { + ret.add(100); + } + if ((encoded & 0x4) != 0) { + ret.add(200); + } + if ((encoded & 0x8) != 0) { + ret.add(300); + } + if ((encoded & 0x10) != 0) { + ret.add(400); + } + if ((encoded & 0x20) != 0) { + ret.add(500); + } + if ((encoded & 0x400) != 0) { + ret.add(1000); + } + if ((encoded & 0x800) != 0) { + ret.add(1100); + } + if ((encoded & 0x1000) != 0) { + ret.add(1200); + } + if ((encoded & 0x2000) != 0) { + ret.add(1300); + } + if ((encoded & 0x4000) != 0) { + ret.add(1400); + } + if ((encoded & 0x8000) != 0) { + ret.add(1500); + } + if ((encoded & 0x20000) != 0) { + ret.add(2001); //im not sure of this one + ret.add(2200); + } + if ((encoded & 0x100000) != 0) { + ret.add(2000); + ret.add(2001); //? + } + if ((encoded & 0x200000) != 0) { + ret.add(2100); + } + if ((encoded & 0x400000) != 0) { + ret.add(2001); //? + ret.add(2200); + } + + if ((encoded & 0x40000000) != 0) { //i haven't seen any higher than this o.o + ret.add(3000); + ret.add(3200); + ret.add(3300); + ret.add(3500); + } + return ret; + } + + public static List getJobBySimpleEncoding(int encoded) { + List ret = new ArrayList<>(); + if ((encoded & 0x1) != 0) { + ret.add(200); + } + if ((encoded & 0x2) != 0) { + ret.add(300); + } + if ((encoded & 0x4) != 0) { + ret.add(400); + } + if ((encoded & 0x8) != 0) { + ret.add(500); + } + return ret; + } +} diff --git a/src/main/java/server/quest/actions/BuffAction.java b/src/main/java/server/quest/actions/BuffAction.java index d403d91d5b..3f45ec59d0 100644 --- a/src/main/java/server/quest/actions/BuffAction.java +++ b/src/main/java/server/quest/actions/BuffAction.java @@ -32,7 +32,7 @@ import server.quest.QuestActionType; * * @author Tyler (Twdtwd) */ -public class BuffAction extends MapleQuestAction { +public class BuffAction extends AbstractQuestAction { int itemEffect; public BuffAction(Quest quest, Data data) { diff --git a/src/main/java/server/quest/actions/ExpAction.java b/src/main/java/server/quest/actions/ExpAction.java index 1dc07757b0..2a9dbb61a6 100644 --- a/src/main/java/server/quest/actions/ExpAction.java +++ b/src/main/java/server/quest/actions/ExpAction.java @@ -32,7 +32,7 @@ import server.quest.QuestActionType; * * @author Tyler (Twdtwd) */ -public class ExpAction extends MapleQuestAction { +public class ExpAction extends AbstractQuestAction { int exp; public ExpAction(Quest quest, Data data) { diff --git a/src/main/java/server/quest/actions/FameAction.java b/src/main/java/server/quest/actions/FameAction.java index 642192be71..3af4763d14 100644 --- a/src/main/java/server/quest/actions/FameAction.java +++ b/src/main/java/server/quest/actions/FameAction.java @@ -31,7 +31,7 @@ import server.quest.QuestActionType; * * @author Tyler (Twdtwd) */ -public class FameAction extends MapleQuestAction { +public class FameAction extends AbstractQuestAction { int fame; public FameAction(Quest quest, Data data) { diff --git a/src/main/java/server/quest/actions/InfoAction.java b/src/main/java/server/quest/actions/InfoAction.java index 92714bcadb..7a8fbe50c2 100644 --- a/src/main/java/server/quest/actions/InfoAction.java +++ b/src/main/java/server/quest/actions/InfoAction.java @@ -29,7 +29,7 @@ import server.quest.QuestActionType; * * @author Ronan */ -public class InfoAction extends MapleQuestAction { +public class InfoAction extends AbstractQuestAction { private String info; private int questID; diff --git a/src/main/java/server/quest/actions/ItemAction.java b/src/main/java/server/quest/actions/ItemAction.java index 1af280c9db..0ac27b85fd 100644 --- a/src/main/java/server/quest/actions/ItemAction.java +++ b/src/main/java/server/quest/actions/ItemAction.java @@ -47,7 +47,7 @@ import java.util.List; * @author Tyler (Twdtwd) * @author Ronan */ -public class ItemAction extends MapleQuestAction { +public class ItemAction extends AbstractQuestAction { List items = new ArrayList<>(); public ItemAction(Quest quest, Data data) { diff --git a/src/main/java/server/quest/actions/MapleQuestAction.java b/src/main/java/server/quest/actions/MapleQuestAction.java deleted file mode 100644 index 824237d9d7..0000000000 --- a/src/main/java/server/quest/actions/MapleQuestAction.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - This file is part of the MapleSolaxia Maple Story Server - - This program 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 version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program 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 this program. If not, see . -*/ -package server.quest.actions; - -import client.Character; -import provider.Data; -import server.quest.Quest; -import server.quest.QuestActionType; - -import java.util.ArrayList; -import java.util.List; - -/** - * - * @author Tyler (Twdtwd) - */ -public abstract class MapleQuestAction { - private final QuestActionType type; - protected int questID; - - public MapleQuestAction(QuestActionType action, Quest quest) { - this.type = action; - this.questID = quest.getId(); - } - - public abstract void run(Character chr, Integer extSelection); - public abstract void processData(Data data); - - public boolean check(Character chr, Integer extSelection) { - return true; - } - - public QuestActionType getType() { - return type; - } - - public static List getJobBy5ByteEncoding(int encoded) { - List ret = new ArrayList<>(); - if ((encoded & 0x1) != 0) { - ret.add(0); - } - if ((encoded & 0x2) != 0) { - ret.add(100); - } - if ((encoded & 0x4) != 0) { - ret.add(200); - } - if ((encoded & 0x8) != 0) { - ret.add(300); - } - if ((encoded & 0x10) != 0) { - ret.add(400); - } - if ((encoded & 0x20) != 0) { - ret.add(500); - } - if ((encoded & 0x400) != 0) { - ret.add(1000); - } - if ((encoded & 0x800) != 0) { - ret.add(1100); - } - if ((encoded & 0x1000) != 0) { - ret.add(1200); - } - if ((encoded & 0x2000) != 0) { - ret.add(1300); - } - if ((encoded & 0x4000) != 0) { - ret.add(1400); - } - if ((encoded & 0x8000) != 0) { - ret.add(1500); - } - if ((encoded & 0x20000) != 0) { - ret.add(2001); //im not sure of this one - ret.add(2200); - } - if ((encoded & 0x100000) != 0) { - ret.add(2000); - ret.add(2001); //? - } - if ((encoded & 0x200000) != 0) { - ret.add(2100); - } - if ((encoded & 0x400000) != 0) { - ret.add(2001); //? - ret.add(2200); - } - - if ((encoded & 0x40000000) != 0) { //i haven't seen any higher than this o.o - ret.add(3000); - ret.add(3200); - ret.add(3300); - ret.add(3500); - } - return ret; - } - - public static List getJobBySimpleEncoding(int encoded) { - List ret = new ArrayList<>(); - if ((encoded & 0x1) != 0) { - ret.add(200); - } - if ((encoded & 0x2) != 0) { - ret.add(300); - } - if ((encoded & 0x4) != 0) { - ret.add(400); - } - if ((encoded & 0x8) != 0) { - ret.add(500); - } - return ret; - } -} diff --git a/src/main/java/server/quest/actions/MesoAction.java b/src/main/java/server/quest/actions/MesoAction.java index eb78077278..459930bb12 100644 --- a/src/main/java/server/quest/actions/MesoAction.java +++ b/src/main/java/server/quest/actions/MesoAction.java @@ -32,7 +32,7 @@ import server.quest.QuestActionType; * * @author Tyler (Twdtwd) */ -public class MesoAction extends MapleQuestAction { +public class MesoAction extends AbstractQuestAction { int mesos; public MesoAction(Quest quest, Data data) { diff --git a/src/main/java/server/quest/actions/NextQuestAction.java b/src/main/java/server/quest/actions/NextQuestAction.java index 3bbb649a99..9ac7c83464 100644 --- a/src/main/java/server/quest/actions/NextQuestAction.java +++ b/src/main/java/server/quest/actions/NextQuestAction.java @@ -33,7 +33,7 @@ import tools.PacketCreator; * * @author Tyler (Twdtwd) */ -public class NextQuestAction extends MapleQuestAction { +public class NextQuestAction extends AbstractQuestAction { int nextQuest; public NextQuestAction(Quest quest, Data data) { diff --git a/src/main/java/server/quest/actions/PetSkillAction.java b/src/main/java/server/quest/actions/PetSkillAction.java index 533ad60d66..f310d59ee5 100644 --- a/src/main/java/server/quest/actions/PetSkillAction.java +++ b/src/main/java/server/quest/actions/PetSkillAction.java @@ -33,7 +33,7 @@ import server.quest.QuestActionType; * * @author Tyler (Twdtwd) */ -public class PetSkillAction extends MapleQuestAction { +public class PetSkillAction extends AbstractQuestAction { int flag; public PetSkillAction(Quest quest, Data data) { diff --git a/src/main/java/server/quest/actions/PetSpeedAction.java b/src/main/java/server/quest/actions/PetSpeedAction.java index 5abb71a7ff..cd1b997707 100644 --- a/src/main/java/server/quest/actions/PetSpeedAction.java +++ b/src/main/java/server/quest/actions/PetSpeedAction.java @@ -30,7 +30,7 @@ import server.quest.QuestActionType; * * @author Ronan */ -public class PetSpeedAction extends MapleQuestAction { +public class PetSpeedAction extends AbstractQuestAction { public PetSpeedAction(Quest quest, Data data) { super(QuestActionType.PETTAMENESS, quest); diff --git a/src/main/java/server/quest/actions/PetTamenessAction.java b/src/main/java/server/quest/actions/PetTamenessAction.java index 79aef49efc..fa32db7829 100644 --- a/src/main/java/server/quest/actions/PetTamenessAction.java +++ b/src/main/java/server/quest/actions/PetTamenessAction.java @@ -31,7 +31,7 @@ import server.quest.QuestActionType; * * @author Ronan */ -public class PetTamenessAction extends MapleQuestAction { +public class PetTamenessAction extends AbstractQuestAction { int tameness; public PetTamenessAction(Quest quest, Data data) { diff --git a/src/main/java/server/quest/actions/QuestAction.java b/src/main/java/server/quest/actions/QuestAction.java index e72bb7d105..8f26c74f10 100644 --- a/src/main/java/server/quest/actions/QuestAction.java +++ b/src/main/java/server/quest/actions/QuestAction.java @@ -35,7 +35,7 @@ import java.util.Map; * * @author Tyler (Twdtwd) */ -public class QuestAction extends MapleQuestAction { +public class QuestAction extends AbstractQuestAction { int mesos; Map quests = new HashMap<>(); diff --git a/src/main/java/server/quest/actions/SkillAction.java b/src/main/java/server/quest/actions/SkillAction.java index 2c83c944c6..c825246d13 100644 --- a/src/main/java/server/quest/actions/SkillAction.java +++ b/src/main/java/server/quest/actions/SkillAction.java @@ -39,7 +39,7 @@ import java.util.Map; * * @author Tyler (Twdtwd) */ -public class SkillAction extends MapleQuestAction { +public class SkillAction extends AbstractQuestAction { int itemEffect; Map skillData = new HashMap<>();