-
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 a mixin module which is used to collect various scripts which implement common functionality shared across the server and other scripts.
- Loading branch information
1 parent
f832406
commit f5d44c8
Showing
7 changed files
with
120 additions
and
1 deletion.
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
9 changes: 9 additions & 0 deletions
9
Arrowgene.Ddon.GameServer/Scripting/Interfaces/IExpCurveMixin.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,9 @@ | ||
using Arrowgene.Ddon.Shared.Model; | ||
|
||
namespace Arrowgene.Ddon.GameServer.Scripting.Interfaces | ||
{ | ||
public abstract class IExpCurveMixin | ||
{ | ||
public abstract uint GetExpValue(InstancedEnemy enemy); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
Arrowgene.Ddon.GameServer/Scripting/Modules/MixinModule.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,69 @@ | ||
using Arrowgene.Ddon.Shared; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Scripting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Dynamic; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Arrowgene.Ddon.GameServer.Scripting | ||
{ | ||
public class MixinModule : ScriptModule | ||
{ | ||
public override string ModuleRoot => "mixins"; | ||
public override string Filter => "*.csx"; | ||
public override bool ScanSubdirectories => true; | ||
public override bool EnableHotLoad => true; | ||
|
||
private Dictionary<string, object> Mixins { get; set; } | ||
|
||
public MixinModule() | ||
{ | ||
Mixins = new Dictionary<string, object>(); | ||
} | ||
|
||
public T Get<T>(string scriptName) | ||
{ | ||
if (!Mixins.ContainsKey(scriptName)) | ||
{ | ||
throw new Exception($"A mixin with the name '{scriptName}' doesn't exist"); | ||
} | ||
|
||
return (T) Mixins[scriptName]; | ||
} | ||
|
||
public override ScriptOptions Options() | ||
{ | ||
return ScriptOptions.Default | ||
.AddReferences(MetadataReference.CreateFromFile(typeof(DdonGameServer).Assembly.Location)) | ||
.AddReferences(MetadataReference.CreateFromFile(typeof(AssetRepository).Assembly.Location)) | ||
.AddReferences(MetadataReference.CreateFromFile(typeof(DynamicAttribute).Assembly.Location)) | ||
.AddImports("System", "System.Collections", "System.Collections.Generic") | ||
.AddImports("System.Runtime.CompilerServices") | ||
.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.GameServer.Scripting.Interfaces") | ||
.AddImports("Arrowgene.Ddon.Shared.Entity.PacketStructure") | ||
.AddImports("Arrowgene.Ddon.Shared.Entity.Structure") | ||
.AddImports("Arrowgene.Ddon.Shared.Model.Quest"); | ||
} | ||
|
||
public override bool EvaluateResult(string path, ScriptState<object> result) | ||
{ | ||
if (result == null) | ||
{ | ||
return false; | ||
} | ||
|
||
// Mixins are c# Func<> with arbitary return and params based on the functionality | ||
string mixinName = Path.GetFileNameWithoutExtension(path); | ||
Mixins[mixinName] = result.ReturnValue; | ||
|
||
return true; | ||
} | ||
} | ||
} |
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,3 @@ | ||
# Mixins | ||
|
||
Mixins are a collection of configurable functionality which can be shared across various server components and scripts, but is not tied to a particular feature. |
17 changes: 17 additions & 0 deletions
17
Arrowgene.Ddon.Shared/Files/Assets/scripts/mixins/exp_curve.csx
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,17 @@ | ||
/** | ||
* @breif This mixin is used to calculate the exp amount for a given | ||
* enemy based on observations from realworld exp data. It should be | ||
* possible to call this script directly from the server code or from | ||
* other scripts. | ||
*/ | ||
|
||
public class Mixin : IExpCurveMixin | ||
{ | ||
public override uint GetExpValue(InstancedEnemy enemy) | ||
{ | ||
// TODO: Implement algorithm to calculate exp amount | ||
return enemy.GetDroppedExperience(); | ||
} | ||
} | ||
|
||
return new Mixin(); |
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