-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUseAdvisorExample.cs
More file actions
57 lines (49 loc) · 1.55 KB
/
UseAdvisorExample.cs
File metadata and controls
57 lines (49 loc) · 1.55 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using SS.Core;
using SS.Core.ComponentInterfaces;
namespace Example.AdvisorExamples;
/// <summary>
/// An example on how to use an advisor.
/// </summary>
/// <param name="broker">The global (zone-wide) broker.</param>
public sealed class UseAdvisorExample(IComponentBroker broker) : IModule
{
private readonly IComponentBroker _broker = broker ?? throw new ArgumentNullException(nameof(broker));
bool IModule.Load(IComponentBroker broker)
{
return true;
}
bool IModule.Unload(IComponentBroker broker)
{
return true;
}
// Make believe this was used at some point
// in the operation of your module.
public void DoSomething(Player player)
{
bool allow = true;
// Get the advisors collection.
var advisors = _broker.GetAdvisors<IMyExampleAdvisor>();
// Ask each advisor for advice.
// How you decide to use advice from an advisor is up to you.
// Here we'll consider something to be allowed, only if
// every advisor says it's allowed.
foreach (var advisor in advisors)
{
if (!advisor.IsAllowedToDoSomething(player))
{
// One advisor said it's not allowed, so we're done.
// There's no reason to ask other advisors.
allow = false;
break;
}
}
if (allow)
{
// Do the 'something' that is player is allowed to do.
}
else
{
// Otherwise, do something else.
}
}
}