Rename and clean up MapleQuestAction

This commit is contained in:
P0nk
2021-09-09 23:05:32 +02:00
parent 62d2e87d25
commit 0777e5529f
15 changed files with 157 additions and 158 deletions

View File

@@ -60,8 +60,8 @@ public class Quest {
protected int timeLimit, timeLimit2;
protected Map<QuestRequirementType, MapleQuestRequirement> startReqs = new EnumMap<>(QuestRequirementType.class);
protected Map<QuestRequirementType, MapleQuestRequirement> completeReqs = new EnumMap<>(QuestRequirementType.class);
protected Map<QuestActionType, MapleQuestAction> startActs = new EnumMap<>(QuestActionType.class);
protected Map<QuestActionType, MapleQuestAction> completeActs = new EnumMap<>(QuestActionType.class);
protected Map<QuestActionType, AbstractQuestAction> startActs = new EnumMap<>(QuestActionType.class);
protected Map<QuestActionType, AbstractQuestAction> completeActs = new EnumMap<>(QuestActionType.class);
protected List<Integer> 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<MapleQuestAction> acts = startActs.values();
for (MapleQuestAction a : acts) {
Collection<AbstractQuestAction> 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<MapleQuestAction> acts = completeActs.values();
for (MapleQuestAction a : acts) {
Collection<AbstractQuestAction> 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<QuestActionType, MapleQuestAction> acts = completeActs;
MapleQuestAction mqa = acts.get(QuestActionType.NEXTQUEST);
Map<QuestActionType, AbstractQuestAction> acts = completeActs;
AbstractQuestAction mqa = acts.get(QuestActionType.NEXTQUEST);
return mqa != null;
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<Integer> getJobBy5ByteEncoding(int encoded) {
List<Integer> 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<Integer> getJobBySimpleEncoding(int encoded) {
List<Integer> 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;
}
}

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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;

View File

@@ -47,7 +47,7 @@ import java.util.List;
* @author Tyler (Twdtwd)
* @author Ronan
*/
public class ItemAction extends MapleQuestAction {
public class ItemAction extends AbstractQuestAction {
List<ItemData> items = new ArrayList<>();
public ItemAction(Quest quest, Data data) {

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<Integer> getJobBy5ByteEncoding(int encoded) {
List<Integer> 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<Integer> getJobBySimpleEncoding(int encoded) {
List<Integer> 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;
}
}

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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) {

View File

@@ -35,7 +35,7 @@ import java.util.Map;
*
* @author Tyler (Twdtwd)
*/
public class QuestAction extends MapleQuestAction {
public class QuestAction extends AbstractQuestAction {
int mesos;
Map<Integer, Integer> quests = new HashMap<>();

View File

@@ -39,7 +39,7 @@ import java.util.Map;
*
* @author Tyler (Twdtwd)
*/
public class SkillAction extends MapleQuestAction {
public class SkillAction extends AbstractQuestAction {
int itemEffect;
Map<Integer, SkillData> skillData = new HashMap<>();