-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRegistrationExample.cs
More file actions
40 lines (33 loc) · 1.23 KB
/
RegistrationExample.cs
File metadata and controls
40 lines (33 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using SS.Core;
using SS.Core.ComponentInterfaces;
namespace Example.AdvisorExamples;
/// <summary>
/// This is an example on how to register and unregister a custom advisor.
/// </summary>
public sealed class RegistrationExample : IModule, IMyExampleAdvisor
{
private AdvisorRegistrationToken<IMyExampleAdvisor>? _iMyExampleAdvisorRegistrationToken;
bool IModule.Load(IComponentBroker broker)
{
// Register the module as an implementer
// of the IMyExampleAdvisor component advisor interface.
_iMyExampleAdvisorRegistrationToken = broker.RegisterAdvisor<IMyExampleAdvisor>(this);
return true;
}
bool IModule.Unload(IComponentBroker broker)
{
// Unregister
broker.UnregisterAdvisor(ref _iMyExampleAdvisorRegistrationToken);
return true;
}
// Notice that this is explicitly implemented,
// that's because we defined a default implementation
// and this is going to override the default.
bool IMyExampleAdvisor.IsAllowedToDoSomething(Player player)
{
// Whatever logic you decide.
// This has the advisor say it's allowed if the player
// is currently in a Warbird.
return player.Ship == ShipType.Warbird;
}
}