Split generateRewardItem()
into two functions
This commit is contained in:
parent
e176b0ae45
commit
32e8557723
@ -100,7 +100,7 @@ export class RepeatableQuestRewardGenerator
|
|||||||
rewardIndex++;
|
rewardIndex++;
|
||||||
|
|
||||||
// Add GP coin reward
|
// Add GP coin reward
|
||||||
rewards.Success.push(this.generateRewardItem(
|
rewards.Success.push(this.generateItemReward(
|
||||||
Money.GP,
|
Money.GP,
|
||||||
rewardParams.gpCoinRewardCount,
|
rewardParams.gpCoinRewardCount,
|
||||||
rewardIndex,
|
rewardIndex,
|
||||||
@ -142,7 +142,7 @@ export class RepeatableQuestRewardGenerator
|
|||||||
// Add item rewards
|
// Add item rewards
|
||||||
for (const itemReward of itemsToReward)
|
for (const itemReward of itemsToReward)
|
||||||
{
|
{
|
||||||
rewards.Success.push(this.generateRewardItem(itemReward.item._id, itemReward.stackSize, rewardIndex));
|
rewards.Success.push(this.generateItemReward(itemReward.item._id, itemReward.stackSize, rewardIndex));
|
||||||
rewardIndex++;
|
rewardIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,7 +358,7 @@ export class RepeatableQuestRewardGenerator
|
|||||||
const chosenPreset = this.cloner.clone(randomPreset);
|
const chosenPreset = this.cloner.clone(randomPreset);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
weapon: this.generateRewardItem(chosenPreset._encyclopedia, 1, rewardIndex, chosenPreset._items),
|
weapon: this.generatePresetReward(chosenPreset._encyclopedia, 1, rewardIndex, chosenPreset._items),
|
||||||
price: presetPrice };
|
price: presetPrice };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -505,23 +505,46 @@ export class RepeatableQuestRewardGenerator
|
|||||||
* Helper to create a reward item structured as required by the client
|
* Helper to create a reward item structured as required by the client
|
||||||
*
|
*
|
||||||
* @param {string} tpl ItemId of the rewarded item
|
* @param {string} tpl ItemId of the rewarded item
|
||||||
* @param {integer} value Amount of items to give
|
* @param {integer} count Amount of items to give
|
||||||
* @param {integer} index All rewards will be appended to a list, for unknown reasons the client wants the index
|
* @param {integer} index All rewards will be appended to a list, for unknown reasons the client wants the index
|
||||||
* @param preset Optional array of preset items
|
* @param preset Optional array of preset items
|
||||||
* @returns {object} Object of "Reward"-item-type
|
* @returns {object} Object of "Reward"-item-type
|
||||||
*/
|
*/
|
||||||
protected generateRewardItem(tpl: string, value: number, index: number, preset?: Item[]): IQuestReward
|
protected generateItemReward(tpl: string, count: number, index: number): IQuestReward
|
||||||
{
|
{
|
||||||
const id = this.objectId.generate();
|
const id = this.objectId.generate();
|
||||||
const questRewardItem: IQuestReward = {
|
const questRewardItem: IQuestReward = {
|
||||||
target: id,
|
target: id,
|
||||||
value: value,
|
value: count,
|
||||||
type: QuestRewardType.ITEM,
|
type: QuestRewardType.ITEM,
|
||||||
index: index,
|
index: index,
|
||||||
items: [] };
|
items: [] };
|
||||||
|
|
||||||
if (preset)
|
const rootItem = { _id: id, _tpl: tpl, upd: { StackObjectsCount: count, SpawnedInSession: true } };
|
||||||
|
questRewardItem.items = [rootItem];
|
||||||
|
|
||||||
|
return questRewardItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to create a reward item structured as required by the client
|
||||||
|
*
|
||||||
|
* @param {string} tpl ItemId of the rewarded item
|
||||||
|
* @param {integer} count Amount of items to give
|
||||||
|
* @param {integer} index All rewards will be appended to a list, for unknown reasons the client wants the index
|
||||||
|
* @param preset Optional array of preset items
|
||||||
|
* @returns {object} Object of "Reward"-item-type
|
||||||
|
*/
|
||||||
|
protected generatePresetReward(tpl: string, count: number, index: number, preset?: Item[]): IQuestReward
|
||||||
{
|
{
|
||||||
|
const id = this.objectId.generate();
|
||||||
|
const questRewardItem: IQuestReward = {
|
||||||
|
target: id,
|
||||||
|
value: count,
|
||||||
|
type: QuestRewardType.ITEM,
|
||||||
|
index: index,
|
||||||
|
items: [] };
|
||||||
|
|
||||||
// Get presets root item
|
// Get presets root item
|
||||||
const rootItem = preset.find((item) => item._tpl === tpl);
|
const rootItem = preset.find((item) => item._tpl === tpl);
|
||||||
if (!rootItem)
|
if (!rootItem)
|
||||||
@ -531,12 +554,6 @@ export class RepeatableQuestRewardGenerator
|
|||||||
|
|
||||||
questRewardItem.items = this.itemHelper.reparentItemAndChildren(rootItem, preset);
|
questRewardItem.items = this.itemHelper.reparentItemAndChildren(rootItem, preset);
|
||||||
questRewardItem.target = rootItem._id; // Target property and root items id must match
|
questRewardItem.target = rootItem._id; // Target property and root items id must match
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const rootItem = { _id: id, _tpl: tpl, upd: { StackObjectsCount: value, SpawnedInSession: true } };
|
|
||||||
questRewardItem.items = [rootItem];
|
|
||||||
}
|
|
||||||
|
|
||||||
return questRewardItem;
|
return questRewardItem;
|
||||||
}
|
}
|
||||||
@ -653,6 +670,6 @@ export class RepeatableQuestRewardGenerator
|
|||||||
: rewardRoubles;
|
: rewardRoubles;
|
||||||
|
|
||||||
// Get chosen currency + amount and return
|
// Get chosen currency + amount and return
|
||||||
return this.generateRewardItem(currency, rewardAmountToGivePlayer, rewardIndex);
|
return this.generateItemReward(currency, rewardAmountToGivePlayer, rewardIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user