-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added Roslyn to the project. - Added an example of parsing game logic settings from a .csx file. - Converted extended NPC facilities into scripting .csx files for each NPC.
- Loading branch information
1 parent
4ae8eed
commit 81551e3
Showing
24 changed files
with
569 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Arrowgene.Ddon.GameServer.Scripting | ||
{ | ||
public class DdonLibrary | ||
{ | ||
public DdonLibrary() | ||
{ | ||
} | ||
|
||
public static uint GetValue() | ||
{ | ||
return 1; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Arrowgene.Ddon.GameServer/Scripting/INpcExtendedFacility.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Arrowgene.Ddon.GameServer; | ||
using Arrowgene.Ddon.Shared.Entity.PacketStructure; | ||
using Arrowgene.Ddon.Shared.Model; | ||
|
||
namespace Arrowgene.Ddon.GameServer.Scripting | ||
{ | ||
public abstract class INpcExtendedFacility | ||
{ | ||
/// <summary> | ||
/// NPC ID associated with the extended options. | ||
/// </summary> | ||
public NpcId NpcId { get; protected set; } | ||
|
||
/// <summary> | ||
/// Gets extended menu options for the NPC. | ||
/// </summary> | ||
/// <param name="server"></param> | ||
/// <param name="client"></param> | ||
/// <param name="result">The result object for the extended NPC options</param> | ||
public abstract void GetExtendedOptions(DdonGameServer server, GameClient client, S2CNpcGetNpcExtendedFacilityRes result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Arrowgene.Ddon.Server; | ||
using Arrowgene.Ddon.Shared; | ||
using Arrowgene.Ddon.Shared.Model; | ||
using Arrowgene.Logging; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Scripting; | ||
using Microsoft.CodeAnalysis.Scripting; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace Arrowgene.Ddon.GameServer.Scripting | ||
{ | ||
public class ScriptManager | ||
{ | ||
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(ScriptManager)); | ||
public class Globals | ||
{ | ||
public Globals(DdonGameServer server) | ||
{ | ||
Server = server; | ||
} | ||
|
||
public DdonGameServer Server { get; } | ||
}; | ||
|
||
|
||
public ScriptManager(DdonGameServer server) | ||
{ | ||
Server = server; | ||
ScriptsRoot = $"{server.AssetRepository.AssetsPath}\\scripts"; | ||
NpcExtendedFacilities = new Dictionary<NpcId, INpcExtendedFacility>(); | ||
} | ||
|
||
private DdonGameServer Server { get; } | ||
private string ScriptsRoot { get; set; } | ||
public Dictionary<NpcId, INpcExtendedFacility> NpcExtendedFacilities { get; private set; } | ||
|
||
public void CompileScripts() | ||
{ | ||
var ExtendedFacilitiesPath = $"{ScriptsRoot}\\extended_facilities"; | ||
|
||
var options = ScriptOptions.Default | ||
.AddReferences(MetadataReference.CreateFromFile(typeof(DdonGameServer).Assembly.Location)) | ||
.AddReferences(MetadataReference.CreateFromFile(typeof(AssetRepository).Assembly.Location)) | ||
.AddImports("System", "System.Collections", "System.Collections.Generic") | ||
.AddImports("Arrowgene.Ddon.Shared") | ||
.AddImports("Arrowgene.Ddon.Shared.Model") | ||
.AddImports("Arrowgene.Ddon.GameServer") | ||
.AddImports("Arrowgene.Ddon.GameServer.Characters") | ||
.AddImports("Arrowgene.Ddon.GameServer.Scripting") | ||
.AddImports("Arrowgene.Ddon.Shared.Entity.PacketStructure") | ||
.AddImports("Arrowgene.Ddon.Shared.Entity.Structure") | ||
.AddImports("Arrowgene.Ddon.Shared.Model.Quest"); | ||
|
||
|
||
var globals = new Globals(Server); | ||
|
||
Logger.Info($"Compiling NPC extended facility scripts from {ExtendedFacilitiesPath}"); | ||
foreach (var file in Directory.EnumerateFiles(ExtendedFacilitiesPath)) | ||
{ | ||
Logger.Info($"{file}"); | ||
|
||
var script = CSharpScript.Create( | ||
code: File.ReadAllText(file), | ||
options: options, | ||
globalsType: typeof(Globals) | ||
); | ||
|
||
var result = script.RunAsync(globals).Result; | ||
if (result == null) | ||
{ | ||
Logger.Error($"Failed to execute '{file}' successfully. Skipping."); | ||
continue; | ||
} | ||
|
||
INpcExtendedFacility extendedFacility = (INpcExtendedFacility)result.ReturnValue; | ||
NpcExtendedFacilities[extendedFacility.NpcId] = extendedFacility; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.