Skip to content

Commit a40c1b1

Browse files
committed
[Loot] Fix bug in loot
1 parent 69c7b41 commit a40c1b1

File tree

15 files changed

+344
-23
lines changed

15 files changed

+344
-23
lines changed

Modules/WDE.HttpDatabase/Models/MySqlLootEntry.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace WDE.HttpDatabase.Models;
66
public class JsonLootEntry : ILootEntry
77
{
88
public LootSourceType SourceType { get; set; }
9+
public LootType LootType { get; set; }
910
public uint Entry { get; set; }
1011
public int ItemOrCurrencyId { get; set; }
1112
public uint Reference { get; set; }

Modules/WDE.LootEditor/Editor/Standalone/StandaloneLootEditorToolBar.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<CompletionComboBox
2323
IsEnabled="{CompiledBinding CanChangeLootType}"
2424
SelectedItem="{CompiledBinding LootType, Mode=TwoWay}"
25-
controls:Extensions.EnumType="{x:Type database:LootSourceType}" />
25+
Items="{CompiledBinding SupportedLootTypes}" />
2626

2727
<Border Width="20" />
2828

Modules/WDE.LootEditor/Editor/Standalone/StandaloneLootEditorViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public LootSourceType LootType
5858
}
5959
}
6060

61+
public IReadOnlyList<LootSourceType> SupportedLootTypes { get; }
62+
6163
[Notify] private bool canChangeLootType = true;
6264
[Notify] private bool canChangeEntry = true;
6365
[Notify] private uint solutionEntry;
@@ -192,6 +194,7 @@ public StandaloneLootEditorViewModel(
192194
ITextDocumentService textDocumentService,
193195
IParameterFactory parameterFactory,
194196
ICurrentCoreVersion currentCoreVersion,
197+
ILootEditorFeatures lootEditorFeatures,
195198
PerDatabaseTableLootSolutionItem? solutionItem = null
196199
)
197200
{
@@ -202,6 +205,7 @@ public StandaloneLootEditorViewModel(
202205
this.parameterPickerService = parameterPickerService;
203206
this.messageBoxService = messageBoxService;
204207
this.currentCoreVersion = currentCoreVersion;
208+
SupportedLootTypes = lootEditorFeatures.SupportedTypes;
205209
legacyDifficulties[0] = DifficultyViewModel.Legacy(0, "default");
206210
legacyDifficulties[1] = DifficultyViewModel.Legacy(1, "heroic dung/25 raid");
207211
legacyDifficulties[2] = DifficultyViewModel.Legacy(2, "10 heroic raid");

Modules/WDE.LootEditor/Editor/ViewModels/LootEditorViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ private async Task UnloadLoot(LootSourceType type, LootEntry menu)
10861086

10871087
private IReadOnlyList<LootEntry> Roots =>
10881088
(LootEditingMode == LootEditingMode.PerDatabaseTable) ? PerDatabaseSolutionItems :
1089-
Loots.Where(x => x.LootSourceType != LootSourceType.Reference || (uint)x.LootEntry == perEntitySolutionItem!.Entry)
1089+
Loots.Where(x => x.LootSourceType != LootSourceType.Reference || perEntitySolutionItem!.Type == LootSourceType.Reference && (uint)x.LootEntry == perEntitySolutionItem!.Entry)
10901090
.Select(x => x.LootEntry)
10911091
.ToList();
10921092

@@ -1128,7 +1128,7 @@ private bool VerifyDuplicateKeys()
11281128
{
11291129
var loot = lootGroup.LootItems[lootIndex];
11301130
loot.IsDuplicate = false;
1131-
var item = loot.ItemOrCurrencyId.Value;
1131+
var item = loot.IsReference ? loot.ReferenceEntry : loot.ItemOrCurrencyId.Value;
11321132
var minPatch = loot.MinPatch.Value;
11331133
if (!keys.Add((item, minPatch)))
11341134
{

Modules/WDE.LootEditor/Editor/ViewModels/LootItemViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ public LootModel ToModel()
249249
SourceType = Parent.LootSourceType,
250250
Entry = (uint)Parent.LootEntry,
251251
ItemOrCurrencyId = (int)ItemOrCurrencyId.Value,
252+
LootType = IsReference ? LootType.Reference : LootType.Item,
252253
Chance = Math.Abs(Chance.Value),
253254
QuestRequired = Chance.Value < 0,
254255
LootMode = (uint)LootMode.Value,

Modules/WDE.LootEditor/QueryGenerator/CmangosLootQueryGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public IQuery GenerateQuery(IReadOnlyList<LootGroupModel> models)
6464
.BulkInsert(group.Items.Select(x => new
6565
{
6666
entry = x.Loot.Entry,
67-
item = x.Loot.ItemOrCurrencyId,
67+
item = x.Loot.IsReference() && x.Loot.ItemOrCurrencyId == 0 ? (long)x.Loot.Reference : x.Loot.ItemOrCurrencyId,
6868
ChanceOrQuestChance = (x.Loot.QuestRequired ? -1 : 1) * x.Loot.Chance,
6969
groupid = x.Loot.GroupId,
7070
mincountOrRef = x.Loot.IsReference() ? -(int)x.Loot.Reference : x.Loot.MinCount,

Modules/WDE.LootEditor/QueryGenerator/TrinityLootQueryGenerator.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public IQuery GenerateUpdateLootIds(LootSourceType sourceType, uint solutionEntr
129129
}
130130
}
131131

132-
[RequiresCore("TrinityMaster", "TrinityWrath", "Azeroth")]
132+
[RequiresCore("TrinityWrath", "Azeroth")]
133133
[AutoRegister]
134134
[SingleInstance]
135135
public class TrinityLootQueryGenerator : BaseTrinityLootQueryGenerator
@@ -143,7 +143,7 @@ protected override object CreateDatabaseObjectRow(LootModel x)
143143
return new
144144
{
145145
Entry = x.Loot.Entry,
146-
Item = x.Loot.ItemOrCurrencyId,
146+
Item = x.Loot.IsReference() && x.Loot.ItemOrCurrencyId == 0 ? (long)x.Loot.Reference : x.Loot.ItemOrCurrencyId,
147147
Reference = x.Loot.Reference,
148148
Chance = x.Loot.Chance,
149149
QuestRequired = x.Loot.QuestRequired,
@@ -156,6 +156,33 @@ protected override object CreateDatabaseObjectRow(LootModel x)
156156
}
157157
}
158158

159+
[RequiresCore("TrinityMaster")]
160+
[AutoRegister]
161+
[SingleInstance]
162+
public class TrinityMasterLootQueryGenerator : BaseTrinityLootQueryGenerator
163+
{
164+
public TrinityMasterLootQueryGenerator(IConditionQueryGenerator conditionQueryGenerator, ICurrentCoreVersion currentCoreVersion, ILootEditorFeatures editorFeatures) : base(conditionQueryGenerator, currentCoreVersion, editorFeatures)
165+
{
166+
}
167+
168+
protected override object CreateDatabaseObjectRow(LootModel x)
169+
{
170+
return new
171+
{
172+
Entry = x.Loot.Entry,
173+
Item = x.Loot.LootType == LootType.Reference ? x.Loot.Reference : (long)x.Loot.ItemOrCurrencyId,
174+
ItemType = (int)x.Loot.LootType,
175+
Chance = x.Loot.Chance,
176+
QuestRequired = x.Loot.QuestRequired,
177+
LootMode = x.Loot.LootMode,
178+
GroupId = x.Loot.GroupId,
179+
MinCount = x.Loot.MinCount,
180+
MaxCount = x.Loot.MaxCount,
181+
Comment = x.Loot.Comment
182+
};
183+
}
184+
}
185+
159186
[RequiresCore("TrinityCata")]
160187
[AutoRegister]
161188
[SingleInstance]
@@ -170,7 +197,7 @@ protected override object CreateDatabaseObjectRow(LootModel x)
170197
return new
171198
{
172199
Entry = x.Loot.Entry,
173-
Item = Math.Abs(x.Loot.ItemOrCurrencyId),
200+
Item = x.Loot.IsReference() && x.Loot.ItemOrCurrencyId == 0 ? (long)x.Loot.Reference : Math.Abs(x.Loot.ItemOrCurrencyId),
174201
IsCurrency = x.Loot.ItemOrCurrencyId < 0,
175202
Reference = x.Loot.Reference,
176203
Chance = x.Loot.Chance,

WoWDatabaseEditor.Common/WDE.CMMySqlDatabase/Models/Loot.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ namespace WDE.CMMySqlDatabase.Models;
66
public abstract class BaseLootTemplate : ILootEntry
77
{
88
public abstract LootSourceType SourceType { get; }
9-
9+
10+
public LootType LootType => Reference != 0 ? LootType.Reference : LootType.Item;
11+
1012
[PrimaryKey]
1113
[Column(Name = "entry")]
1214
public uint Entry { get; set; }

WoWDatabaseEditor.Common/WDE.Common/Database/ILoot.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
namespace WDE.Common.Database;
44

5+
public enum LootType
6+
{
7+
Item = 0,
8+
Reference = 1,
9+
}
10+
511
public interface ILootEntry
612
{
713
LootSourceType SourceType { get; }
14+
LootType LootType { get; }
815
uint Entry { get; }
916
int ItemOrCurrencyId { get; }
1017
uint Reference { get; }
@@ -27,6 +34,7 @@ public interface ITreasureLootEntry { }
2734
public struct AbstractLootEntry : ILootEntry
2835
{
2936
public LootSourceType SourceType { get; set; }
37+
public LootType LootType { get; set; }
3038
public uint Entry { get; set; }
3139
public int ItemOrCurrencyId { get; set; }
3240
public uint Reference { get; set; }
@@ -46,6 +54,7 @@ public struct AbstractLootEntry : ILootEntry
4654
public AbstractLootEntry(ILootEntry x)
4755
{
4856
SourceType = x.SourceType;
57+
LootType = x.LootType;
4958
Entry = x.Entry;
5059
ItemOrCurrencyId = x.ItemOrCurrencyId;
5160
Reference = x.Reference;
@@ -82,13 +91,13 @@ public struct AbstractLootTemplateName : ILootTemplateName
8291
public static class LootExtensions
8392
{
8493
public static bool IsReference(this ILootEntry entry)
85-
=> entry.Reference > 0;
94+
=> entry.LootType == LootType.Reference;
8695

8796
public static bool IsCurrency(this ILootEntry entry)
88-
=> entry.ItemOrCurrencyId < 0;
89-
97+
=> entry.LootType == LootType.Item && entry.ItemOrCurrencyId < 0;
98+
9099
public static bool IsItem(this ILootEntry entry)
91-
=> !entry.IsCurrency();
100+
=> entry.LootType == LootType.Item && entry.ItemOrCurrencyId >= 0;
92101
}
93102

94103
public enum LootSourceType

WoWDatabaseEditor.Common/WDE.Common/Database/LootType.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

WoWDatabaseEditor.Common/WDE.Common/Utils/AsyncAutoCommand.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Prism.Commands;
88
using WDE.Common.Annotations;
99
using WDE.Common.Exceptions;
10+
using WDE.Common.Services;
1011
using WDE.Common.Services.MessageBox;
1112
using WDE.Common.Tasks;
1213

@@ -46,7 +47,14 @@ public AsyncAutoCommand(Func<Task> execute,
4647
{
4748
LOG.LogError(e, "Error in {0} at {1}:{2}", caller, callerFile, callerLineNumber);
4849
}
49-
onException?.Invoke(e);
50+
if (onException == null)
51+
{
52+
var service = DI.Resolve<IMessageBoxService>();
53+
if (service != null)
54+
GlobalApplication.MainThread.Dispatch(() => CommandExtensions.ShowError(service, e, null));
55+
}
56+
else
57+
onException?.Invoke(e);
5058
},
5159
continueOnCapturedContext);
5260
}
@@ -116,7 +124,14 @@ public AsyncAutoCommand([NotNull]
116124
e =>
117125
{
118126
IsBusy = false;
119-
onException?.Invoke(e);
127+
if (onException == null)
128+
{
129+
var service = DI.Resolve<IMessageBoxService>();
130+
if (service != null)
131+
GlobalApplication.MainThread.Dispatch(() => CommandExtensions.ShowError(service, e, null));
132+
}
133+
else
134+
onException?.Invoke(e);
120135
},
121136
continueOnCapturedContext);
122137
}
@@ -290,7 +305,7 @@ public static IAsyncCommand<R> WrapMessageBox<T, R>(this IAsyncCommand<R> cmd, I
290305
});
291306
}
292307

293-
private static async Task ShowError(IMessageBoxService messageBoxService, Exception e, string? header,
308+
internal static async Task ShowError(IMessageBoxService messageBoxService, Exception e, string? header,
294309
[CallerMemberName] string? caller = null,
295310
[CallerFilePath] string? callerFile = null,
296311
[CallerLineNumber] int? callerLineNumber = null)

0 commit comments

Comments
 (0)