@rpg-engine/long-bow 0.6.74 → 0.6.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.6.74",
3
+ "version": "0.6.76",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -92,43 +92,65 @@ export const QuestList: React.FC<IQuestListProps> = ({ quests }) => {
92
92
  const formatObjectives = (
93
93
  objectives: (IQuestObjectiveKill | IQuestObjectiveInteraction)[]
94
94
  ) => {
95
- return objectives
96
- .map(objective => {
97
- if ('killCountTarget' in objective) {
98
- // This is an IQuestObjectiveKill
99
- const killObjective = objective as IQuestObjectiveKill;
100
- return `Kill ${formatText(killObjective.creatureKeys.join(', '))}: ${
101
- killObjective.killCount
102
- }/${killObjective.killCountTarget}`;
103
- } else if ('targetNPCkey' in objective) {
104
- // This is an IQuestObjectiveInteraction
105
- const interactionObjective = objective as IQuestObjectiveInteraction;
106
- return `Interact with NPC: ${formatText(
107
- interactionObjective.targetNPCkey ?? 'Unknown'
108
- )}`;
109
- } else {
110
- return 'Unknown objective';
111
- }
112
- })
113
- .join('; ');
95
+ try {
96
+ if (!objectives || !Array.isArray(objectives)) return 'No objectives';
97
+ return objectives
98
+ .map(objective => {
99
+ if ('killCountTarget' in objective) {
100
+ const killObjective = objective as IQuestObjectiveKill;
101
+ return `Kill ${formatText(
102
+ killObjective.creatureKeys?.join(', ') ?? 'Unknown'
103
+ )}: ${killObjective.killCount ?? 0}/${killObjective.killCountTarget ??
104
+ 0}`;
105
+ } else if ('targetNPCkey' in objective) {
106
+ const interactionObjective = objective as IQuestObjectiveInteraction;
107
+ return `Interact with NPC: ${formatText(
108
+ interactionObjective.targetNPCkey ?? 'Unknown'
109
+ )}`;
110
+ } else {
111
+ return 'Unknown objective';
112
+ }
113
+ })
114
+ .join('; ');
115
+ } catch (error) {
116
+ console.error('Error formatting objectives:', error);
117
+ return 'Error formatting objectives';
118
+ }
114
119
  };
115
120
 
116
121
  // Updated helper function to format rewards
117
122
  const formatRewards = (rewards: IQuest['rewards']) => {
118
123
  try {
119
124
  if (!rewards || !Array.isArray(rewards)) return 'No rewards';
125
+
120
126
  return rewards
121
127
  .map(reward => {
122
- return `${formatText(
123
- reward?.itemKeys
124
- ?.map(itemKey => itemKey + ' x' + reward?.qty)
125
- .join(', ')
126
- )}${
127
- reward?.spellKeys
128
- ? `, Spells: ${formatText(reward.spellKeys.join(', '))}`
129
- : ''
130
- }`;
128
+ const itemKeysFormatted = reward?.itemKeys
129
+ ?.map(itemKey =>
130
+ itemKey && reward?.qty !== undefined
131
+ ? `${itemKey} x${reward.qty}`
132
+ : ''
133
+ )
134
+ .filter(Boolean)
135
+ .join(', ');
136
+
137
+ const spellKeysFormatted = reward?.spellKeys
138
+ ?.filter(Boolean)
139
+ .join(', ');
140
+
141
+ const formattedReward = itemKeysFormatted
142
+ ? `${formatText(itemKeysFormatted)}`
143
+ : '';
144
+
145
+ if (spellKeysFormatted) {
146
+ return formattedReward
147
+ ? `${formattedReward}, Spells: ${formatText(spellKeysFormatted)}`
148
+ : `Spells: ${formatText(spellKeysFormatted)}`;
149
+ }
150
+
151
+ return formattedReward || 'No rewards';
131
152
  })
153
+ .filter(Boolean)
132
154
  .join('; ');
133
155
  } catch (error) {
134
156
  console.error(
@@ -138,6 +160,7 @@ const formatRewards = (rewards: IQuest['rewards']) => {
138
160
  return 'Error on rewards';
139
161
  }
140
162
  };
163
+
141
164
  const formatText = (text: string) => {
142
165
  return text
143
166
  .split('-')