Rework how repeatable quests are replaced
This commit is contained in:
parent
57b1fe0733
commit
d97beda4b7
@ -336,63 +336,49 @@ export class RepeatableQuestController
|
|||||||
{
|
{
|
||||||
let repeatableToChange: IPmcDataRepeatableQuest;
|
let repeatableToChange: IPmcDataRepeatableQuest;
|
||||||
let changeRequirement: IChangeRequirement;
|
let changeRequirement: IChangeRequirement;
|
||||||
let existingQuestTraderId: string;
|
|
||||||
|
|
||||||
// Daily or weekly
|
// Trader existing quest is linked to
|
||||||
for (const currentRepeatable of pmcData.RepeatableQuests)
|
let replacedQuestTraderId: string;
|
||||||
|
|
||||||
|
// Daily,weekly or scav daily
|
||||||
|
for (const currentRepeatablePool of pmcData.RepeatableQuests)
|
||||||
{
|
{
|
||||||
// Check for existing quest in (daily/weekly arrays)
|
// Check for existing quest in (daily/weekly/scav arrays)
|
||||||
const existingQuest = currentRepeatable.activeQuests.find(x => x._id === changeRequest.qid);
|
const questToReplace = currentRepeatablePool.activeQuests.find(x => x._id === changeRequest.qid);
|
||||||
if (existingQuest)
|
if (!questToReplace)
|
||||||
{
|
{
|
||||||
existingQuestTraderId = existingQuest.traderId;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const numQuests = currentRepeatable.activeQuests.length;
|
replacedQuestTraderId = questToReplace.traderId;
|
||||||
currentRepeatable.activeQuests = currentRepeatable.activeQuests.filter(x => x._id !== changeRequest.qid);
|
|
||||||
if (numQuests > currentRepeatable.activeQuests.length)
|
// Update active quests to exclude the quest we're replacing
|
||||||
{
|
currentRepeatablePool.activeQuests = currentRepeatablePool.activeQuests.filter(x => x._id !== changeRequest.qid);
|
||||||
|
|
||||||
// Get saved costs to replace existing quest
|
// Get saved costs to replace existing quest
|
||||||
changeRequirement = this.jsonUtil.clone(currentRepeatable.changeRequirement[changeRequest.qid]);
|
changeRequirement = this.jsonUtil.clone(currentRepeatablePool.changeRequirement[changeRequest.qid]);
|
||||||
delete currentRepeatable.changeRequirement[changeRequest.qid];
|
delete currentRepeatablePool.changeRequirement[changeRequest.qid];
|
||||||
const repeatableConfig = this.questConfig.repeatableQuests.find(x => x.name === currentRepeatable.name);
|
const repeatableConfig = this.questConfig.repeatableQuests.find(x => x.name === currentRepeatablePool.name);
|
||||||
const questTypePool = this.generateQuestPool(repeatableConfig, pmcData.Info.Level);
|
const questTypePool = this.generateQuestPool(repeatableConfig, pmcData.Info.Level);
|
||||||
// TODO: somehow we need to reduce the questPool by the currently active quests (for all repeatables)
|
// TODO: somehow we need to reduce the questPool by the currently active quests (for all repeatables)
|
||||||
let newRepeatableQuest: IRepeatableQuest = null;
|
|
||||||
let attemptsToGenerateQuest = 0;
|
|
||||||
while (!newRepeatableQuest && questTypePool.types.length > 0)
|
|
||||||
{
|
|
||||||
newRepeatableQuest = this.repeatableQuestGenerator.generateRepeatableQuest(
|
|
||||||
pmcData.Info.Level,
|
|
||||||
pmcData.TradersInfo,
|
|
||||||
questTypePool,
|
|
||||||
repeatableConfig
|
|
||||||
);
|
|
||||||
attemptsToGenerateQuest++;
|
|
||||||
if (attemptsToGenerateQuest > 10)
|
|
||||||
{
|
|
||||||
this.logger.debug("We were stuck in repeatable quest generation. This should never happen. Please report");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const newRepeatableQuest = this.attemptToGenerateRepeatableQuest(pmcData, questTypePool, repeatableConfig);
|
||||||
if (newRepeatableQuest)
|
if (newRepeatableQuest)
|
||||||
{
|
{
|
||||||
// Add newly generated quest to daily/weekly array
|
// Add newly generated quest to daily/weekly array
|
||||||
newRepeatableQuest.side = repeatableConfig.side;
|
newRepeatableQuest.side = repeatableConfig.side;
|
||||||
currentRepeatable.activeQuests.push(newRepeatableQuest);
|
currentRepeatablePool.activeQuests.push(newRepeatableQuest);
|
||||||
currentRepeatable.changeRequirement[newRepeatableQuest._id] = {
|
currentRepeatablePool.changeRequirement[newRepeatableQuest._id] = {
|
||||||
changeCost: newRepeatableQuest.changeCost,
|
changeCost: newRepeatableQuest.changeCost,
|
||||||
changeStandingCost: newRepeatableQuest.changeStandingCost
|
changeStandingCost: newRepeatableQuest.changeStandingCost
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Found and replaced the quest in current repeatable
|
// Found and replaced the quest in current repeatable
|
||||||
repeatableToChange = this.jsonUtil.clone(currentRepeatable);
|
repeatableToChange = this.jsonUtil.clone(currentRepeatablePool);
|
||||||
delete repeatableToChange.inactiveQuests;
|
delete repeatableToChange.inactiveQuests;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let output = this.eventOutputHolder.getOutput(sessionID);
|
let output = this.eventOutputHolder.getOutput(sessionID);
|
||||||
if (!repeatableToChange)
|
if (!repeatableToChange)
|
||||||
@ -413,7 +399,7 @@ export class RepeatableQuestController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reduce standing with trader for not doing their quest
|
// Reduce standing with trader for not doing their quest
|
||||||
const droppedQuestTrader = pmcData.TradersInfo[existingQuestTraderId];
|
const droppedQuestTrader = pmcData.TradersInfo[replacedQuestTraderId];
|
||||||
droppedQuestTrader.standing -= changeRequirement.changeStandingCost;
|
droppedQuestTrader.standing -= changeRequirement.changeStandingCost;
|
||||||
|
|
||||||
// Update client output with new repeatable
|
// Update client output with new repeatable
|
||||||
@ -421,4 +407,27 @@ export class RepeatableQuestController
|
|||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected attemptToGenerateRepeatableQuest(pmcData: IPmcData, questTypePool: IQuestTypePool, repeatableConfig: IRepeatableQuestConfig): IRepeatableQuest
|
||||||
|
{
|
||||||
|
let newRepeatableQuest: IRepeatableQuest = null;
|
||||||
|
let attemptsToGenerateQuest = 0;
|
||||||
|
while (!newRepeatableQuest && questTypePool.types.length > 0)
|
||||||
|
{
|
||||||
|
newRepeatableQuest = this.repeatableQuestGenerator.generateRepeatableQuest(
|
||||||
|
pmcData.Info.Level,
|
||||||
|
pmcData.TradersInfo,
|
||||||
|
questTypePool,
|
||||||
|
repeatableConfig
|
||||||
|
);
|
||||||
|
attemptsToGenerateQuest++;
|
||||||
|
if (attemptsToGenerateQuest > 10)
|
||||||
|
{
|
||||||
|
this.logger.debug("We were stuck in repeatable quest generation. This should never happen. Please report");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newRepeatableQuest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user