mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-10-04 19:12:50 -04:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -122,14 +122,6 @@ def handleOptionsSeven(core, actor, npc, selection):
|
||||
print ('selection 7: ' + str(selection))
|
||||
if (selection == 0): # Ok, I'll do what he says.
|
||||
quest = actor.getPlayerObject().getQuest('tatooine_eisley_legacy')
|
||||
|
||||
if (actor.getLevel() >= 10):
|
||||
core.questService.activateQuest(actor, 'quest/tatooine_eisley_gotoniko')
|
||||
return
|
||||
else:
|
||||
core.questService.activateQuest(actor, 'quest/tatooine_eisley_gotomayor')
|
||||
return
|
||||
|
||||
core.questService.handleActivateSignal(actor, npc, quest, 2)
|
||||
core.conversationService.sendStopConversation(actor, npc, '@conversation/c_newbie_secondchance', 's_136')
|
||||
return
|
||||
|
||||
@@ -5,5 +5,10 @@ def wait(core, actor):
|
||||
return
|
||||
|
||||
def activate(core, actor, quest):
|
||||
core.questService.completeActiveTask(actor, quest)
|
||||
core.questService.completeQuest(actor.getPlayerObject(), quest)
|
||||
|
||||
if (actor.getLevel() >= 10):
|
||||
core.questService.sendQuestAcceptWindow(actor, 'tatooine_eisley_gotoniko')
|
||||
else:
|
||||
core.questService.sendQuestAcceptWindow(actor, 'tatooine_eisley_gotomayor')
|
||||
return
|
||||
@@ -26,16 +26,17 @@ import java.nio.ByteOrder;
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
|
||||
import protocol.swg.ObjControllerMessage;
|
||||
import resources.quest.Quest;
|
||||
|
||||
public class QuestTaskCounterMessage extends ObjControllerObject {
|
||||
|
||||
private long objectId;
|
||||
private String questName;
|
||||
private Quest quest;
|
||||
private String stf;
|
||||
|
||||
public QuestTaskCounterMessage(long objectId, String questName, String stf) {
|
||||
public QuestTaskCounterMessage(long objectId, Quest quest, String stf) {
|
||||
this.objectId = objectId;
|
||||
this.questName = questName;
|
||||
this.quest = quest;
|
||||
this.stf = stf;
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ public class QuestTaskCounterMessage extends ObjControllerObject {
|
||||
@Override
|
||||
public IoBuffer serialize() {
|
||||
|
||||
byte[] questNameBytes = getAsciiString(questName);
|
||||
byte[] questNameBytes = getAsciiString(quest.getCrcName());
|
||||
byte[] stfBytes = getUnicodeString(stf);
|
||||
|
||||
IoBuffer buffer = IoBuffer.allocate(38 + questNameBytes.length + stfBytes.length).order(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -57,10 +58,10 @@ public class QuestTaskCounterMessage extends ObjControllerObject {
|
||||
buffer.putInt(0);
|
||||
|
||||
buffer.put(questNameBytes);
|
||||
buffer.putInt(1); // ??
|
||||
buffer.putInt(quest.getCounterMax()); // Max count
|
||||
buffer.put(stfBytes);
|
||||
buffer.putInt(0); // ??
|
||||
buffer.putInt(1); // ??
|
||||
buffer.putInt(0); // spacer?
|
||||
buffer.putInt(quest.getCounterValue()); // Current count
|
||||
|
||||
return buffer.flip();
|
||||
}
|
||||
|
||||
@@ -24,16 +24,17 @@ package protocol.swg.objectControllerObjects;
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
|
||||
import protocol.swg.ObjControllerMessage;
|
||||
import engine.resources.common.CRC;
|
||||
import engine.resources.objects.Baseline;
|
||||
|
||||
public class ShowQuestAcceptWindow extends ObjControllerObject {
|
||||
|
||||
private long objectId;
|
||||
private int questCrc;
|
||||
private String questName;
|
||||
|
||||
public ShowQuestAcceptWindow(long objectId, int questCrc) {
|
||||
public ShowQuestAcceptWindow(long objectId, String questName) {
|
||||
this.objectId = objectId;
|
||||
this.questCrc = questCrc;
|
||||
this.questName = questName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,11 +45,11 @@ public class ShowQuestAcceptWindow extends ObjControllerObject {
|
||||
public IoBuffer serialize() {
|
||||
IoBuffer buffer = Baseline.createBuffer(20);
|
||||
|
||||
buffer.putInt(ObjControllerMessage.SHOW_QUEST_COMPLETION_WINDOW);
|
||||
buffer.putInt(ObjControllerMessage.SHOW_QUEST_ACCEPT_WINDOW);
|
||||
buffer.putLong(objectId);
|
||||
buffer.putInt(0);
|
||||
|
||||
buffer.putInt(questCrc);
|
||||
buffer.putInt(CRC.StringtoCRC(questName));
|
||||
|
||||
return buffer.flip();
|
||||
}
|
||||
|
||||
@@ -24,16 +24,17 @@ package protocol.swg.objectControllerObjects;
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
|
||||
import protocol.swg.ObjControllerMessage;
|
||||
import engine.resources.common.CRC;
|
||||
import engine.resources.objects.Baseline;
|
||||
|
||||
public class ShowQuestCompletionWindow extends ObjControllerObject {
|
||||
|
||||
private long objectId;
|
||||
private int questCrc;
|
||||
private String questName;
|
||||
|
||||
public ShowQuestCompletionWindow(long objectId, int questCrc) {
|
||||
public ShowQuestCompletionWindow(long objectId, String questName) {
|
||||
this.objectId = objectId;
|
||||
this.questCrc = questCrc;
|
||||
this.questName = questName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,7 +49,7 @@ public class ShowQuestCompletionWindow extends ObjControllerObject {
|
||||
buffer.putLong(objectId);
|
||||
buffer.putInt(0);
|
||||
|
||||
buffer.putInt(questCrc);
|
||||
buffer.putInt(CRC.StringtoCRC(questName));
|
||||
|
||||
return buffer.flip();
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ public class Quest extends Delta implements Serializable {
|
||||
private ScheduledFuture<?> timer;
|
||||
private long waypointId;
|
||||
|
||||
private int counterMax;
|
||||
private int counterCurrent;
|
||||
|
||||
public Quest() {}
|
||||
|
||||
public Quest(String name, long ownerId) {
|
||||
@@ -145,6 +148,30 @@ public class Quest extends Delta implements Serializable {
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
public int getCounterMax() {
|
||||
return counterMax;
|
||||
}
|
||||
|
||||
public void setCounterMax(int counterMax) {
|
||||
this.counterMax = counterMax;
|
||||
}
|
||||
|
||||
public void incrementCounter() {
|
||||
counterCurrent++;
|
||||
}
|
||||
|
||||
public void decrementCounter() {
|
||||
counterCurrent--;
|
||||
}
|
||||
|
||||
public int getCounterValue() {
|
||||
return counterCurrent;
|
||||
}
|
||||
|
||||
public void setCounterValue(int value) {
|
||||
this.counterCurrent = value;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
byte[] activeStepBytes = activeStepBitmask.toByteArray();
|
||||
byte[] completedStepBytes = completedStepBitmask.toByteArray();
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.nio.file.Paths;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -57,7 +58,6 @@ import resources.common.OutOfBand;
|
||||
import resources.common.ProsePackage;
|
||||
import resources.common.collidables.QuestCollidable;
|
||||
import resources.datatables.DisplayType;
|
||||
import resources.objects.SWGMap;
|
||||
import resources.objects.creature.CreatureObject;
|
||||
import resources.objects.player.PlayerObject;
|
||||
import resources.objects.tangible.TangibleObject;
|
||||
@@ -79,9 +79,21 @@ public class QuestService implements INetworkDispatch {
|
||||
private NGECore core;
|
||||
private Map<String, QuestData> questMap = new ConcurrentHashMap<String, QuestData>();
|
||||
private Map<String, QuestList> questRewardMap = new ConcurrentHashMap<String, QuestList>();
|
||||
|
||||
private List<String> forceAcceptQuests = new ArrayList<String>();
|
||||
|
||||
public QuestService(NGECore core) {
|
||||
this.core = core;
|
||||
|
||||
try {
|
||||
DatatableVisitor forceQuestVisitor = ClientFileManager.loadFile("datatables/quest/force_accept_quests.iff", DatatableVisitor.class);
|
||||
|
||||
for (int r = 0; r > forceQuestVisitor.getRowCount(); r++) {
|
||||
forceAcceptQuests.add((String) forceQuestVisitor.getObject(r, 0));
|
||||
}
|
||||
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,49 +107,6 @@ public class QuestService implements INetworkDispatch {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public boolean doesPlayerHaveQuest(CreatureObject creo, String questName) {
|
||||
PlayerObject ghost = creo.getPlayerObject();
|
||||
|
||||
if (ghost == null) {
|
||||
try { throw new Exception("Ghost is null! Cannot determine if player has quest or not."); }
|
||||
catch (Exception e) {e.printStackTrace();}
|
||||
}
|
||||
|
||||
SWGMap<Integer, Quest> questJournal = ghost.getQuestJournal();
|
||||
|
||||
if (questJournal.size() == 0)
|
||||
return false;
|
||||
|
||||
return questJournal.containsKey(CRC.StringtoCRC("quest/" + questName));
|
||||
}
|
||||
|
||||
public boolean isQuestCompleted(CreatureObject creo, String questName) {
|
||||
PlayerObject ghost = creo.getPlayerObject();
|
||||
|
||||
if (ghost == null) {
|
||||
try { throw new Exception("Ghost is null! Cannot determine if player completed quest or not."); }
|
||||
catch (Exception e) {e.printStackTrace();}
|
||||
}
|
||||
|
||||
SWGMap<Integer, Quest> questJournal = ghost.getQuestJournal();
|
||||
|
||||
if (questJournal.size() == 0)
|
||||
return false;
|
||||
|
||||
if (!questJournal.containsKey(CRC.StringtoCRC("quest/" + questName)))
|
||||
return false;
|
||||
else
|
||||
return questJournal.get(CRC.StringtoCRC("quest/") + questName).isCompleted();
|
||||
}
|
||||
|
||||
public void sendQuestWindow(CreatureObject reciever, String questName) {
|
||||
if (reciever == null || reciever.getClient() == null || reciever.getClient().getSession() == null)
|
||||
return;
|
||||
|
||||
ObjControllerMessage objMsg = new ObjControllerMessage(11, new ForceActivateQuest(reciever.getObjectID(), CRC.StringtoCRC("quest/" + questName)));
|
||||
reciever.getClient().getSession().write(objMsg.serialize());
|
||||
}
|
||||
|
||||
public void activateNextTask(CreatureObject quester, String questName) {
|
||||
|
||||
@@ -164,7 +133,6 @@ public class QuestService implements INetworkDispatch {
|
||||
|
||||
QuestTask task = qData.getTasks().get(activeStep);
|
||||
|
||||
|
||||
switch (task.getType()) {
|
||||
|
||||
// quest.task.ground.go_to_location
|
||||
@@ -184,10 +152,14 @@ public class QuestService implements INetworkDispatch {
|
||||
|
||||
// quest.task.ground.retrieve_item
|
||||
case "retrieve_item":
|
||||
if (quest.getCounterMax() != task.getNumRequired()) {
|
||||
quest.setCounterMax(task.getNumRequired());
|
||||
quest.setCounterValue(0);
|
||||
}
|
||||
|
||||
player.getQuestRetrieveItemTemplates().put(task.getServerTemplate(), new QuestItem(quest.getName(), activeStep));
|
||||
|
||||
// TODO: add item count
|
||||
ObjControllerMessage itemCount = new ObjControllerMessage(11, new QuestTaskCounterMessage(quester.getObjectID(), quest.getCrcName(), "@quest/groundquests:retrieve_item_counter"));
|
||||
ObjControllerMessage itemCount = new ObjControllerMessage(11, new QuestTaskCounterMessage(quester.getObjectID(), quest, "@quest/groundquests:retrieve_item_counter"));
|
||||
quester.getClient().getSession().write(itemCount.serialize());
|
||||
|
||||
WaypointObject wpRetrieve = createWaypoint(task.getWaypointName(), new Point3D(task.getLocationX(), task.getLocationY(), task.getLocationZ()), task.getPlanet());
|
||||
@@ -232,9 +204,17 @@ public class QuestService implements INetworkDispatch {
|
||||
break;
|
||||
|
||||
case "complete_quest":
|
||||
completeQuest(player, quest);
|
||||
break;
|
||||
if (quest.getWaypointId() != 0) {
|
||||
player.getWaypoints().remove(quest.getWaypointId());
|
||||
core.objectService.destroyObject(quest.getWaypointId());
|
||||
}
|
||||
|
||||
if (quest.getTimer() != null)
|
||||
quest.getTimer().cancel(true);
|
||||
|
||||
completeQuest(player, quest);
|
||||
return;
|
||||
|
||||
case "reward":
|
||||
// TODO: System message? - Also check possibility of "Item" column being used for reward as well
|
||||
TangibleObject reward = (TangibleObject) core.objectService.createObject(getQuestRewardTemplate(task.getLootName()), core.terrainService.getPlanetByName(task.getPlanet()));
|
||||
@@ -278,7 +258,7 @@ public class QuestService implements INetworkDispatch {
|
||||
player.getWaypoints().remove(quest.getWaypointId());
|
||||
core.objectService.destroyObject(quest.getWaypointId());
|
||||
}
|
||||
|
||||
|
||||
if (quest.getTimer() != null)
|
||||
quest.getTimer().cancel(true);
|
||||
|
||||
@@ -287,20 +267,17 @@ public class QuestService implements INetworkDispatch {
|
||||
|
||||
quest.setCompleted(true);
|
||||
|
||||
if (!task.isGrantQuestOnCompleteShowSystemMessage()) {
|
||||
completeQuest(player, quest); // Force complete packet sent if the quest isn't auto completed (window shows up, typical for exclusive reward items)
|
||||
player.getContainer().getClient().getSession().write(player.getBaseline(8).createDelta(7));
|
||||
} else
|
||||
sendQuestCompleteWindow(quester, quest.getCrc());
|
||||
|
||||
if (task.getGrantQuestOnComplete() != null && !task.getGrantQuestOnComplete().equals(""))
|
||||
activateQuest(quester, task.getGrantQuestOnComplete());
|
||||
|
||||
// TODO: Unable to determine if this is calculated in "Complete Quest" window should pop up or just finish automatically, but it's the best for now
|
||||
if (task.isVisible())
|
||||
sendQuestCompleteWindow(quester, quest.getCrcName());
|
||||
else
|
||||
completeQuest(player, quest);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (task.getGrantQuestOnComplete() != null && !task.getGrantQuestOnComplete().equals(""))
|
||||
activateQuest(quester, task.getGrantQuestOnComplete());
|
||||
sendQuestAcceptWindow(quester, task.getGrantQuestOnComplete());
|
||||
|
||||
quest.incrementQuestStep();
|
||||
|
||||
@@ -310,7 +287,7 @@ public class QuestService implements INetworkDispatch {
|
||||
|
||||
}
|
||||
|
||||
public void activateQuest(CreatureObject quester, String questString) {
|
||||
public void immediatlyActivateQuest(CreatureObject quester, String questString) {
|
||||
Quest quest = new Quest(questString, quester.getObjectID());
|
||||
|
||||
PlayerObject player = quester.getPlayerObject();
|
||||
@@ -346,6 +323,7 @@ public class QuestService implements INetworkDispatch {
|
||||
quest.setCompleted(true);
|
||||
|
||||
QuestList info = getQuestList(quest.getName());
|
||||
QuestTask task = getQuestData(quest.getName()).getTasks().get(quest.getActiveTask());
|
||||
|
||||
ArrayList<Long> recievedItems = new ArrayList<Long>();
|
||||
TangibleObject inventory = (TangibleObject) creo.getSlottedObject("inventory");
|
||||
@@ -416,18 +394,25 @@ public class QuestService implements INetworkDispatch {
|
||||
core.playerService.giveExperience(creo, info.getRewardExperienceAmount());
|
||||
}
|
||||
|
||||
if (task.getGrantQuestOnComplete() != null && !task.getGrantQuestOnComplete().equals(""))
|
||||
sendQuestAcceptWindow(creo, task.getGrantQuestOnComplete());
|
||||
|
||||
// Update quest & client
|
||||
quest.setRecievedAward(true);
|
||||
creo.getClient().getSession().write(player.getBaseline(8).createDelta(7));
|
||||
}
|
||||
|
||||
public void sendQuestAcceptWindow(CreatureObject reciever, int questCrc) {
|
||||
ObjControllerMessage objController = new ObjControllerMessage(0x0B, new ShowQuestAcceptWindow(reciever.getObjectID(), questCrc));
|
||||
public void sendQuestWindow(CreatureObject reciever, String questName) {
|
||||
ObjControllerMessage objMsg = new ObjControllerMessage(0x0B, new ForceActivateQuest(reciever.getObjectID(), CRC.StringtoCRC("quest/" + questName)));
|
||||
reciever.getClient().getSession().write(objMsg.serialize());
|
||||
}
|
||||
public void sendQuestAcceptWindow(CreatureObject reciever, String questName) {
|
||||
ObjControllerMessage objController = new ObjControllerMessage(0x0B, new ShowQuestAcceptWindow(reciever.getObjectID(), questName));
|
||||
reciever.getClient().getSession().write(objController.serialize());
|
||||
}
|
||||
|
||||
public void sendQuestCompleteWindow(CreatureObject reciever, int questCrc) {
|
||||
ObjControllerMessage objController = new ObjControllerMessage(0x0B, new ShowQuestCompletionWindow(reciever.getObjectID(), questCrc));
|
||||
public void sendQuestCompleteWindow(CreatureObject reciever, String questName) {
|
||||
ObjControllerMessage objController = new ObjControllerMessage(0x0B, new ShowQuestCompletionWindow(reciever.getObjectID(), questName));
|
||||
reciever.getClient().getSession().write(objController.serialize());
|
||||
}
|
||||
|
||||
@@ -477,8 +462,6 @@ public class QuestService implements INetworkDispatch {
|
||||
core.scriptService.callScript("scripts/quests/events/signals/", task.getSignalName(), "activate", core, actor, quest);
|
||||
return;
|
||||
}
|
||||
|
||||
completeActiveTask(actor, quest);
|
||||
}
|
||||
|
||||
public void handleAddConversationScript(TangibleObject object, String script) {
|
||||
@@ -564,7 +547,7 @@ public class QuestService implements INetworkDispatch {
|
||||
if (questData == null)
|
||||
return false;
|
||||
|
||||
activateQuest(creo, questName);
|
||||
immediatlyActivateQuest(creo, questName);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -639,7 +622,7 @@ public class QuestService implements INetworkDispatch {
|
||||
|
||||
//if (visitor.getObjectByColumnNameAndIndex("", r))
|
||||
|
||||
if (task.getType().equals("quest.task.ground.go_to_location")) {
|
||||
if (task.getType().equals("go_to_location")) {
|
||||
QuestCollidable collision = new QuestCollidable(new Point3D(task.getLocationX(), task.getLocationY(), task.getLocationZ()), task.getRadius(), core.terrainService.getPlanetByName(task.getPlanet()), quest, r);
|
||||
collision.setCallback(core.scriptService.getMethod("scripts/quests/events/", "go_to_location", "run"));
|
||||
core.simulationService.addCollidable(collision, task.getLocationX(), task.getLocationZ());
|
||||
|
||||
Reference in New Issue
Block a user