Skip to content

Commit

Permalink
[Loot] Fix bug in loot
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed Aug 30, 2024
1 parent 69c7b41 commit a40c1b1
Show file tree
Hide file tree
Showing 15 changed files with 344 additions and 23 deletions.
1 change: 1 addition & 0 deletions Modules/WDE.HttpDatabase/Models/MySqlLootEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace WDE.HttpDatabase.Models;
public class JsonLootEntry : ILootEntry
{
public LootSourceType SourceType { get; set; }
public LootType LootType { get; set; }
public uint Entry { get; set; }
public int ItemOrCurrencyId { get; set; }
public uint Reference { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<CompletionComboBox
IsEnabled="{CompiledBinding CanChangeLootType}"
SelectedItem="{CompiledBinding LootType, Mode=TwoWay}"
controls:Extensions.EnumType="{x:Type database:LootSourceType}" />
Items="{CompiledBinding SupportedLootTypes}" />

<Border Width="20" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public LootSourceType LootType
}
}

public IReadOnlyList<LootSourceType> SupportedLootTypes { get; }

[Notify] private bool canChangeLootType = true;
[Notify] private bool canChangeEntry = true;
[Notify] private uint solutionEntry;
Expand Down Expand Up @@ -192,6 +194,7 @@ public StandaloneLootEditorViewModel(
ITextDocumentService textDocumentService,
IParameterFactory parameterFactory,
ICurrentCoreVersion currentCoreVersion,
ILootEditorFeatures lootEditorFeatures,
PerDatabaseTableLootSolutionItem? solutionItem = null
)
{
Expand All @@ -202,6 +205,7 @@ public StandaloneLootEditorViewModel(
this.parameterPickerService = parameterPickerService;
this.messageBoxService = messageBoxService;
this.currentCoreVersion = currentCoreVersion;
SupportedLootTypes = lootEditorFeatures.SupportedTypes;
legacyDifficulties[0] = DifficultyViewModel.Legacy(0, "default");
legacyDifficulties[1] = DifficultyViewModel.Legacy(1, "heroic dung/25 raid");
legacyDifficulties[2] = DifficultyViewModel.Legacy(2, "10 heroic raid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ private async Task UnloadLoot(LootSourceType type, LootEntry menu)

private IReadOnlyList<LootEntry> Roots =>
(LootEditingMode == LootEditingMode.PerDatabaseTable) ? PerDatabaseSolutionItems :
Loots.Where(x => x.LootSourceType != LootSourceType.Reference || (uint)x.LootEntry == perEntitySolutionItem!.Entry)
Loots.Where(x => x.LootSourceType != LootSourceType.Reference || perEntitySolutionItem!.Type == LootSourceType.Reference && (uint)x.LootEntry == perEntitySolutionItem!.Entry)
.Select(x => x.LootEntry)
.ToList();

Expand Down Expand Up @@ -1128,7 +1128,7 @@ private bool VerifyDuplicateKeys()
{
var loot = lootGroup.LootItems[lootIndex];
loot.IsDuplicate = false;
var item = loot.ItemOrCurrencyId.Value;
var item = loot.IsReference ? loot.ReferenceEntry : loot.ItemOrCurrencyId.Value;
var minPatch = loot.MinPatch.Value;
if (!keys.Add((item, minPatch)))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public LootModel ToModel()
SourceType = Parent.LootSourceType,
Entry = (uint)Parent.LootEntry,
ItemOrCurrencyId = (int)ItemOrCurrencyId.Value,
LootType = IsReference ? LootType.Reference : LootType.Item,
Chance = Math.Abs(Chance.Value),
QuestRequired = Chance.Value < 0,
LootMode = (uint)LootMode.Value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public IQuery GenerateQuery(IReadOnlyList<LootGroupModel> models)
.BulkInsert(group.Items.Select(x => new
{
entry = x.Loot.Entry,
item = x.Loot.ItemOrCurrencyId,
item = x.Loot.IsReference() && x.Loot.ItemOrCurrencyId == 0 ? (long)x.Loot.Reference : x.Loot.ItemOrCurrencyId,
ChanceOrQuestChance = (x.Loot.QuestRequired ? -1 : 1) * x.Loot.Chance,
groupid = x.Loot.GroupId,
mincountOrRef = x.Loot.IsReference() ? -(int)x.Loot.Reference : x.Loot.MinCount,
Expand Down
33 changes: 30 additions & 3 deletions Modules/WDE.LootEditor/QueryGenerator/TrinityLootQueryGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public IQuery GenerateUpdateLootIds(LootSourceType sourceType, uint solutionEntr
}
}

[RequiresCore("TrinityMaster", "TrinityWrath", "Azeroth")]
[RequiresCore("TrinityWrath", "Azeroth")]
[AutoRegister]
[SingleInstance]
public class TrinityLootQueryGenerator : BaseTrinityLootQueryGenerator
Expand All @@ -143,7 +143,7 @@ protected override object CreateDatabaseObjectRow(LootModel x)
return new
{
Entry = x.Loot.Entry,
Item = x.Loot.ItemOrCurrencyId,
Item = x.Loot.IsReference() && x.Loot.ItemOrCurrencyId == 0 ? (long)x.Loot.Reference : x.Loot.ItemOrCurrencyId,
Reference = x.Loot.Reference,
Chance = x.Loot.Chance,
QuestRequired = x.Loot.QuestRequired,
Expand All @@ -156,6 +156,33 @@ protected override object CreateDatabaseObjectRow(LootModel x)
}
}

[RequiresCore("TrinityMaster")]
[AutoRegister]
[SingleInstance]
public class TrinityMasterLootQueryGenerator : BaseTrinityLootQueryGenerator
{
public TrinityMasterLootQueryGenerator(IConditionQueryGenerator conditionQueryGenerator, ICurrentCoreVersion currentCoreVersion, ILootEditorFeatures editorFeatures) : base(conditionQueryGenerator, currentCoreVersion, editorFeatures)
{
}

protected override object CreateDatabaseObjectRow(LootModel x)
{
return new
{
Entry = x.Loot.Entry,
Item = x.Loot.LootType == LootType.Reference ? x.Loot.Reference : (long)x.Loot.ItemOrCurrencyId,
ItemType = (int)x.Loot.LootType,
Chance = x.Loot.Chance,
QuestRequired = x.Loot.QuestRequired,
LootMode = x.Loot.LootMode,
GroupId = x.Loot.GroupId,
MinCount = x.Loot.MinCount,
MaxCount = x.Loot.MaxCount,
Comment = x.Loot.Comment
};
}
}

[RequiresCore("TrinityCata")]
[AutoRegister]
[SingleInstance]
Expand All @@ -170,7 +197,7 @@ protected override object CreateDatabaseObjectRow(LootModel x)
return new
{
Entry = x.Loot.Entry,
Item = Math.Abs(x.Loot.ItemOrCurrencyId),
Item = x.Loot.IsReference() && x.Loot.ItemOrCurrencyId == 0 ? (long)x.Loot.Reference : Math.Abs(x.Loot.ItemOrCurrencyId),
IsCurrency = x.Loot.ItemOrCurrencyId < 0,
Reference = x.Loot.Reference,
Chance = x.Loot.Chance,
Expand Down
4 changes: 3 additions & 1 deletion WoWDatabaseEditor.Common/WDE.CMMySqlDatabase/Models/Loot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace WDE.CMMySqlDatabase.Models;
public abstract class BaseLootTemplate : ILootEntry
{
public abstract LootSourceType SourceType { get; }


public LootType LootType => Reference != 0 ? LootType.Reference : LootType.Item;

[PrimaryKey]
[Column(Name = "entry")]
public uint Entry { get; set; }
Expand Down
17 changes: 13 additions & 4 deletions WoWDatabaseEditor.Common/WDE.Common/Database/ILoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

namespace WDE.Common.Database;

public enum LootType
{
Item = 0,
Reference = 1,
}

public interface ILootEntry
{
LootSourceType SourceType { get; }
LootType LootType { get; }
uint Entry { get; }
int ItemOrCurrencyId { get; }
uint Reference { get; }
Expand All @@ -27,6 +34,7 @@ public interface ITreasureLootEntry { }
public struct AbstractLootEntry : ILootEntry
{
public LootSourceType SourceType { get; set; }
public LootType LootType { get; set; }
public uint Entry { get; set; }
public int ItemOrCurrencyId { get; set; }
public uint Reference { get; set; }
Expand All @@ -46,6 +54,7 @@ public struct AbstractLootEntry : ILootEntry
public AbstractLootEntry(ILootEntry x)
{
SourceType = x.SourceType;
LootType = x.LootType;
Entry = x.Entry;
ItemOrCurrencyId = x.ItemOrCurrencyId;
Reference = x.Reference;
Expand Down Expand Up @@ -82,13 +91,13 @@ public struct AbstractLootTemplateName : ILootTemplateName
public static class LootExtensions
{
public static bool IsReference(this ILootEntry entry)
=> entry.Reference > 0;
=> entry.LootType == LootType.Reference;

public static bool IsCurrency(this ILootEntry entry)
=> entry.ItemOrCurrencyId < 0;
=> entry.LootType == LootType.Item && entry.ItemOrCurrencyId < 0;

public static bool IsItem(this ILootEntry entry)
=> !entry.IsCurrency();
=> entry.LootType == LootType.Item && entry.ItemOrCurrencyId >= 0;
}

public enum LootSourceType
Expand Down
6 changes: 0 additions & 6 deletions WoWDatabaseEditor.Common/WDE.Common/Database/LootType.cs

This file was deleted.

21 changes: 18 additions & 3 deletions WoWDatabaseEditor.Common/WDE.Common/Utils/AsyncAutoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Prism.Commands;
using WDE.Common.Annotations;
using WDE.Common.Exceptions;
using WDE.Common.Services;
using WDE.Common.Services.MessageBox;
using WDE.Common.Tasks;

Expand Down Expand Up @@ -46,7 +47,14 @@ public AsyncAutoCommand(Func<Task> execute,
{
LOG.LogError(e, "Error in {0} at {1}:{2}", caller, callerFile, callerLineNumber);
}
onException?.Invoke(e);
if (onException == null)
{
var service = DI.Resolve<IMessageBoxService>();
if (service != null)
GlobalApplication.MainThread.Dispatch(() => CommandExtensions.ShowError(service, e, null));
}
else
onException?.Invoke(e);
},
continueOnCapturedContext);
}
Expand Down Expand Up @@ -116,7 +124,14 @@ public AsyncAutoCommand([NotNull]
e =>
{
IsBusy = false;
onException?.Invoke(e);
if (onException == null)
{
var service = DI.Resolve<IMessageBoxService>();
if (service != null)
GlobalApplication.MainThread.Dispatch(() => CommandExtensions.ShowError(service, e, null));
}
else
onException?.Invoke(e);
},
continueOnCapturedContext);
}
Expand Down Expand Up @@ -290,7 +305,7 @@ public static IAsyncCommand<R> WrapMessageBox<T, R>(this IAsyncCommand<R> cmd, I
});
}

private static async Task ShowError(IMessageBoxService messageBoxService, Exception e, string? header,
internal static async Task ShowError(IMessageBoxService messageBoxService, Exception e, string? header,
[CallerMemberName] string? caller = null,
[CallerFilePath] string? callerFile = null,
[CallerLineNumber] int? callerLineNumber = null)
Expand Down
Loading

0 comments on commit a40c1b1

Please sign in to comment.