mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-28 22:15:54 -04:00
121 lines
4.6 KiB
Plaintext
121 lines
4.6 KiB
Plaintext
include library.quests;
|
|
include library.utils;
|
|
|
|
trigger OnContainerChildGainItem(obj_id item, obj_id source, obj_id transferer)
|
|
{
|
|
// was a quest item received?
|
|
LOG("newquests", "received item(" + item + ", " + getTemplateName(item) + ") source(" + source + ", " + getTemplateName(source) + ") transferer(" + transferer + ", " + getTemplateName(transferer) + ")");
|
|
|
|
// There may be multiple retrieve_item tasks active simultaneously,
|
|
// either because they were granted at the same time, or because
|
|
// the player has accepted multiple quests. Which task, if any
|
|
// might be interested in this item?
|
|
LOG("newquests", "checking active retrieve_item tasks for a match!");
|
|
String[] activeTasks = quests.getActiveQuestsWithScript("quest.task.retrieve_item", self);
|
|
int i;
|
|
for(i = 0; i < activeTasks.length; ++i)
|
|
{
|
|
LOG("newquests", "checking " + activeTasks[i]);
|
|
// is the active task complete?
|
|
boolean taskComplete = false;
|
|
|
|
int count = 0;
|
|
|
|
if(hasObjVar(self, "quest." + activeTasks[i] + ".current_count"))
|
|
count = getIntObjVar(self, "quest." + activeTasks[i] + ".current_count");
|
|
|
|
int targetCount = 1;
|
|
|
|
// does this task require retrieving multiple items of the targetObjectTemplate type?
|
|
if(hasObjVar(self, "quest." + activeTasks[i] + ".parameter"))
|
|
{
|
|
|
|
// the count was overridden by a script, use that
|
|
targetCount = getIntObjVar(self, "quest." + activeTasks[i] + ".parameter");
|
|
LOG("newquests", "task objvar parameter overriding data table. parameter = " + targetCount);
|
|
}
|
|
else
|
|
{
|
|
// count was not overridden, fallback to the quest data table entry
|
|
// does the data table entry specify how may items?
|
|
String countString = quests.getDataEntry(activeTasks[i], "PARAMETER");
|
|
if(countString != null && countString.length() > 0)
|
|
{
|
|
int t = utils.stringToInt(countString);
|
|
if(t > -1)
|
|
{
|
|
targetCount = t;
|
|
LOG("newquests", "target count is set in the PARAMETER column to " + t);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if(hasObjVar(self, "quest." + activeTasks[i] + ".target_id"))
|
|
{
|
|
LOG("newquests", "a target_id is overriding the TARGET column");
|
|
// a specific object much be retrieved, overridden by a script
|
|
obj_id targetId = getObjIdObjVar(self, activeTasks[i] + ".target_id");
|
|
if(targetId == item)
|
|
{
|
|
LOG("newquests", "this item (" + getTemplateName(item) + ") is part of this retrieve_item task");
|
|
count++;
|
|
}
|
|
else
|
|
{
|
|
LOG("newquests", "this item(" + getTemplateName(item) + ") is not part of the retrieve_item task");
|
|
}
|
|
}
|
|
else if(hasObjVar(self, "quest." + activeTasks[i] + ".target_object_template"))
|
|
{
|
|
// the object type was overridden in script
|
|
String targetObjectTemplate = getStringObjVar(self, "quest." + activeTasks[i] + ".target_object_template");
|
|
String wantItem = getTemplateName(item);
|
|
LOG("newquests", "the TARGET column is overidden by target_object_template(" + targetObjectTemplate + ")");
|
|
if(wantItem == targetObjectTemplate)
|
|
{
|
|
LOG("newquests", "this item(" + wantItem + ") is part of this retrieve_item task");
|
|
count++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// if there was no override, use the datatable entry
|
|
String questItem = quests.getDataEntry(activeTasks[i], "TARGET");
|
|
String wantItem = getTemplateName(item);
|
|
LOG("newquests", "the data table for " + activeTasks[i] + " specifies an object of type \"" + questItem + "\" to complete this task. The player has received \"" + wantItem + "\"");
|
|
if(wantItem == questItem)
|
|
{
|
|
LOG("newquests", "increasing the item count for this task");
|
|
count++;
|
|
}
|
|
}
|
|
|
|
LOG("newquests", "checking for objvar quest." + activeTasks[i] + ".quest_item_target");
|
|
if(hasObjVar(item, "quest." + activeTasks[i] + ".quest_item_target"))
|
|
{
|
|
obj_id itemTarget = getObjIdObjVar(item, "quest." + activeTasks[i] + ".quest_item_target");
|
|
LOG("newquests", "the item has a quest_item_target objvar, it might be part of this retrieve_item task");
|
|
if(itemTarget == self)
|
|
{
|
|
LOG("newquests", "the item has a quest_item_target objvar identifying this player. It is part of this retrieve_item task");
|
|
count++;
|
|
}
|
|
}
|
|
// if the task is complete, stop iterating through the active tasks
|
|
// and complete this task
|
|
if(count >= targetCount)
|
|
{
|
|
LOG("newquests", "This retrieve_item task wanted " + targetCount + " items and the player has retrieved " + count + " items. Completing the task");
|
|
quests.complete(activeTasks[i], self, true);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
LOG("newquests", "This retrieve_item task wanted " + targetCount + " items and the player has retrieved " + count + " items. Continuing the task");
|
|
setObjVar(self, "quest." + activeTasks[i] + ".current_count", count);
|
|
}
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|