Skip to content

Commit

Permalink
[SmartScript] Add support for AreaTriggers SAI
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed Feb 6, 2021
1 parent ba1c5ea commit 85f36c3
Show file tree
Hide file tree
Showing 28 changed files with 370 additions and 39 deletions.
16 changes: 15 additions & 1 deletion QuestChainTest/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using WDE.Common.CoreVersion;
using WDE.Common.Database;
using WDE.Common.Tasks;
using WDE.QuestChainEditor.Editor.ViewModels;
using WDE.QuestChainEditor.Exporter;
Expand Down Expand Up @@ -28,7 +31,7 @@ public MainWindow()

new TrinityMySqlDatabaseModule().OnInitialized(null);

TrinityMySqlDatabaseProvider db = new(new ConnectionSettingsProvider(), new DatabaseLogger(), new MockTaskRunner());
TrinityMySqlDatabaseProvider db = new(new ConnectionSettingsProvider(), new DatabaseLogger(), new MockCoreVersion());

ExampleQuestsProvider exampleQuestProvider = new();

Expand All @@ -46,6 +49,17 @@ public MainWindow()
q.RequiredQuests.CollectionChanged += (sender, e) => { Update(); };
}

public class MockCoreVersion : ICurrentCoreVersion, ICoreVersion, IDatabaseFeatures,ISmartScriptFeatures
{
public ICoreVersion Current => this;
public string Tag => "mock";
public string FriendlyName => "mock";
public IDatabaseFeatures DatabaseFeatures => this;
public ISmartScriptFeatures SmartScriptFeatures => this;
public ISet<Type> UnsupportedTables => new HashSet<Type>();
public ISet<SmartScriptType> SupportedTypes => null;
}

private void Update()
{
Text.Text = new QuestChainExporter().GenerateSQL(quests);
Expand Down
18 changes: 16 additions & 2 deletions WDE.AzerothCore/AzerothCoreVersion.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
using WDE.Common.CoreVersion;
using System;
using System.Collections.Generic;
using WDE.Common.CoreVersion;
using WDE.Common.Database;
using WDE.Module.Attributes;

namespace WDE.AzerothCore
{
[AutoRegister]
[SingleInstance]
public class AzerothCoreVersion : ICoreVersion
public class AzerothCoreVersion : ICoreVersion, IDatabaseFeatures, ISmartScriptFeatures
{
public string Tag => "Azeroth";
public string FriendlyName => "AzerothCore Wrath of the Lich King";
public ISmartScriptFeatures SmartScriptFeatures => this;
public IDatabaseFeatures DatabaseFeatures => this;

public ISet<Type> UnsupportedTables { get; } = new HashSet<Type>{typeof(IAreaTriggerTemplate)};
public ISet<SmartScriptType> SupportedTypes { get; } = new HashSet<SmartScriptType>
{
SmartScriptType.Creature,
SmartScriptType.GameObject,
SmartScriptType.AreaTrigger,
SmartScriptType.TimedActionList,
};
}
}
3 changes: 3 additions & 0 deletions WDE.Blueprints/Providers/BlueprintItemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using WDE.Common;
using WDE.Common.CoreVersion;
using WDE.Module.Attributes;

namespace WDE.Blueprints.Providers
{
//[AutoRegister]
public class BlueprintItemProvider : ISolutionItemProvider
{
public bool IsCompatibleWithCore(ICoreVersion core) => false;

public ISolutionItem CreateSolutionItem()
{
return new BlueprintSolutionItem();
Expand Down
6 changes: 6 additions & 0 deletions WDE.SmartScriptEditor/Exporter/SmartScriptExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ private void BuildUpdate()
sql.AppendLine("DELETE FROM areatrigger_scripts WHERE entry = @ENTRY;");
sql.AppendLine("INSERT INTO areatrigger_scripts(entry, ScriptName) VALUES(@ENTRY, \"SmartTrigger\");");
break;
case SmartScriptType.AreaTriggerEntityServerSide:
sql.AppendLine("UPDATE areatrigger_template SET ScriptName = \"SmartAreaTriggerAI\" WHERE Id = @ENTRY AND IsServerSide = 1;");
break;
case SmartScriptType.AreaTriggerEntity:
sql.AppendLine("UPDATE areatrigger_template SET ScriptName = \"SmartAreaTriggerAI\" WHERE Id = @ENTRY AND IsServerSide = 0;");
break;
}
}

Expand Down
8 changes: 5 additions & 3 deletions WDE.SmartScriptEditor/Providers/SmartScriptNameProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public string GetName(SmartScriptSolutionItem item)
IGameObjectTemplate g = database.GetGameObjectTemplate((uint) entry);
return g == null || g.Name == null ? "GameObject " + entry : g.Name;
case SmartScriptType.AreaTrigger:
return "Areatrigger " + entry;
return "Clientside area trigger " + entry;
case SmartScriptType.Quest:
IQuestTemplate q = database.GetQuestTemplate((uint) entry);
return q == null || q.Name == null ? "Quest " + entry : q.Name;
Expand All @@ -43,8 +43,10 @@ public string GetName(SmartScriptSolutionItem item)
return (item.SmartType == SmartScriptType.Aura ? "Aura " : "Spell ") + entry;
case SmartScriptType.TimedActionList:
return "Timed list " + entry;
case SmartScriptType.Cinematic:
return "Cinematic " + entry;
case SmartScriptType.AreaTriggerEntity:
return "Area trigger entity " + entry;
case SmartScriptType.AreaTriggerEntityServerSide:
return "Serverside area trigger entity " + entry;
}
}

Expand Down
4 changes: 3 additions & 1 deletion WDE.SmartScriptEditor/SmartData/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,9 @@
{
"id": 46,
"valid_types": [
"AreaTrigger"
"AreaTrigger",
"AreaTriggerEntity",
"AreaTriggerEntityServerSide"
],
"name": "SMART_EVENT_AREATRIGGER_ONTRIGGER",
"parameters": [
Expand Down
105 changes: 105 additions & 0 deletions WDE.SmartScriptEditor/SmartScriptSolutionItemProvider.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using System;
using System.Linq;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using WDE.Common;
using WDE.Common.CoreVersion;
using WDE.Common.Database;
using WDE.Common.DBC;
using WDE.Common.Parameters;
using WDE.Common.Providers;
using WDE.Module.Attributes;

namespace WDE.SmartScriptEditor
Expand Down Expand Up @@ -36,6 +41,9 @@ public string GetDescription()
{
return desc;
}

public bool IsCompatibleWithCore(ICoreVersion core) =>
core.SmartScriptFeatures.SupportedTypes.Contains(type);

public abstract ISolutionItem CreateSolutionItem();
}
Expand Down Expand Up @@ -172,4 +180,101 @@ public override ISolutionItem CreateSolutionItem()
return new SmartScriptSolutionItem((int) entry.Value, SmartScriptType.TimedActionList);
}
}

[AutoRegister]
public class SmartScriptClientAreaTriggerEntityListProvider : SmartScriptSolutionItemProvider
{
private readonly Lazy<IItemFromListProvider> itemFromListProvider;
private readonly Lazy<IDbcStore> dbcStore;

public SmartScriptClientAreaTriggerEntityListProvider(
Lazy<IItemFromListProvider> itemFromListProvider,
Lazy<IDbcStore> dbcStore
) : base("Client Area Trigger",
"The script from AreaTrigger from client database (DBC)",
"SmartScriptGeneric",
SmartScriptType.AreaTrigger)
{
this.itemFromListProvider = itemFromListProvider;
this.dbcStore = dbcStore;
}

public override ISolutionItem CreateSolutionItem()
{
var areaTriggers =
dbcStore.Value.AreaTriggerStore.ToDictionary(at => at.Key, at => new SelectOption($"Client areatrigger {at.Key}"));
int? entry = itemFromListProvider.Value.GetItemFromList(areaTriggers, false);
if (!entry.HasValue)
return null;
return new SmartScriptSolutionItem(entry.Value, SmartScriptType.AreaTrigger);
}
}

public abstract class SmartScriptAreaTriggerEntityListProviderBase : SmartScriptSolutionItemProvider
{
private readonly Lazy<IItemFromListProvider> itemFromListProvider;
private readonly Lazy<IDatabaseProvider> database;
private readonly SmartScriptType type;
private readonly bool serverSide;

public SmartScriptAreaTriggerEntityListProviderBase(
Lazy<IItemFromListProvider> itemFromListProvider,
Lazy<IDatabaseProvider> database,
string name,
string desc,
string icon,
SmartScriptType type,
bool serverSide
) : base(name, desc, icon, type)
{
this.itemFromListProvider = itemFromListProvider;
this.database = database;
this.type = type;
this.serverSide = serverSide;
}

public override ISolutionItem CreateSolutionItem()
{
var areaTriggers = database.Value.GetAreaTriggerTemplates()
.Where(trigger => trigger.IsServerSide == serverSide)
.ToDictionary(at => (int)at.Id, at => new SelectOption($"Area trigger {at.Id}"));

int? entry = itemFromListProvider.Value.GetItemFromList(areaTriggers, false);
if (!entry.HasValue)
return null;
return new SmartScriptSolutionItem(entry.Value, type);
}
}

[AutoRegister]
public class SmartScriptAreaTriggerEntityListProvider : SmartScriptAreaTriggerEntityListProviderBase
{
public SmartScriptAreaTriggerEntityListProvider(
Lazy<IItemFromListProvider> itemFromListProvider,
Lazy<IDatabaseProvider> database
) : base(
itemFromListProvider,
database,
"Area Trigger Entity",
"The script from AreaTrigger defined in areatrigger_template",
"SmartScriptGeneric",
SmartScriptType.AreaTriggerEntity,
false) {}
}

[AutoRegister]
public class SmartScriptServerSideAreaTriggerEntityListProvider : SmartScriptAreaTriggerEntityListProviderBase
{
public SmartScriptServerSideAreaTriggerEntityListProvider(
Lazy<IItemFromListProvider> itemFromListProvider,
Lazy<IDatabaseProvider> database
) : base(
itemFromListProvider,
database,
"Area Trigger Server-side Entity",
"The script from server side AreaTrigger defined in areatrigger_template",
"SmartScriptGeneric",
SmartScriptType.AreaTriggerEntityServerSide,
true) {}
}
}
3 changes: 3 additions & 0 deletions WDE.Solutions/SolutionFolderItemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
using System.Windows.Media.Imaging;
using Microsoft.VisualBasic;
using WDE.Common;
using WDE.Common.CoreVersion;
using WDE.Module.Attributes;

namespace WDE.Solutions
{
[AutoRegister]
public class SolutionFolderItemProvider : ISolutionItemProvider
{
public bool IsCompatibleWithCore(ICoreVersion core) => true;

public string GetName()
{
return "Folder";
Expand Down
19 changes: 17 additions & 2 deletions WDE.Trinity/TrinityCataclysmVersion.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
using WDE.Common.CoreVersion;
using System;
using System.Collections.Generic;
using WDE.Common.CoreVersion;
using WDE.Common.Database;
using WDE.Module.Attributes;

namespace WDE.Trinity
{
[AutoRegister]
[SingleInstance]
public class TrinityCataclysmVersion : ICoreVersion
public class TrinityCataclysmVersion : ICoreVersion, IDatabaseFeatures, ISmartScriptFeatures
{
public string Tag => "TrinityCata";
public string FriendlyName => "The Cataclysm Preservation Project";

public IDatabaseFeatures DatabaseFeatures => this;
public ISmartScriptFeatures SmartScriptFeatures => this;

public ISet<Type> UnsupportedTables { get; } = new HashSet<Type>{typeof(IAreaTriggerTemplate)};
public ISet<SmartScriptType> SupportedTypes { get; } = new HashSet<SmartScriptType>
{
SmartScriptType.Creature,
SmartScriptType.GameObject,
SmartScriptType.AreaTrigger,
SmartScriptType.TimedActionList,
};
}
}
22 changes: 19 additions & 3 deletions WDE.Trinity/TrinityMasterVersion.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
using WDE.Common.CoreVersion;
using WDE.Common.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using WDE.Common.CoreVersion;
using WDE.Common.Database;
using WDE.Module.Attributes;

namespace WDE.Trinity
{
[AutoRegister]
[SingleInstance]
public class TrinityMasterVersion : ICoreVersion
public class TrinityMasterVersion : ICoreVersion, IDatabaseFeatures, ISmartScriptFeatures
{
public string Tag => "TrinityMaster";
public string FriendlyName => "TrinityCore Shadowlands";
public ISmartScriptFeatures SmartScriptFeatures => this;
public IDatabaseFeatures DatabaseFeatures => this;

public ISet<Type> UnsupportedTables { get; } = new HashSet<Type>();
public ISet<SmartScriptType> SupportedTypes { get; } = new HashSet<SmartScriptType>
{
SmartScriptType.Creature,
SmartScriptType.GameObject,
SmartScriptType.AreaTrigger,
SmartScriptType.TimedActionList,
SmartScriptType.AreaTriggerEntity,
SmartScriptType.AreaTriggerEntityServerSide
};
}
}
18 changes: 16 additions & 2 deletions WDE.Trinity/TrinityWrathVersion.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
using WDE.Common.CoreVersion;
using System;
using System.Collections.Generic;
using WDE.Common.CoreVersion;
using WDE.Common.Database;
using WDE.Module.Attributes;

namespace WDE.Trinity
{
[AutoRegister]
[SingleInstance]
public class TrinityWrathVersion : ICoreVersion
public class TrinityWrathVersion : ICoreVersion, IDatabaseFeatures, ISmartScriptFeatures
{
public string Tag => "TrinityWrath";
public string FriendlyName => "TrinityCore Wrath of the Lich King";
public ISmartScriptFeatures SmartScriptFeatures => this;
public IDatabaseFeatures DatabaseFeatures => this;

public ISet<Type> UnsupportedTables { get; } = new HashSet<Type>{typeof(IAreaTriggerTemplate)};
public ISet<SmartScriptType> SupportedTypes { get; } = new HashSet<SmartScriptType>
{
SmartScriptType.Creature,
SmartScriptType.GameObject,
SmartScriptType.AreaTrigger,
SmartScriptType.TimedActionList,
};
}
}
Loading

0 comments on commit 85f36c3

Please sign in to comment.