Repository navigation
Expand file tree
/
Copy pathModDynamicInterestPoint.cs
More file actions
145 lines (143 loc) · 4.4 KB
/
Copy pathModDynamicInterestPoint.cs
File metadata and controls
145 lines (143 loc) · 4.4 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using Orleans;
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Reflection;
using Backend;
using Backend.Business;
using Backend.Database;
using NQutils.Config;
using Backend.Construct;
using Backend.Storage;
using Backend.Scenegraph;
using NQ;
using NQ.RDMS;
using NQ.Interfaces;
using NQ.Visibility;
using NQ.Grains.Core;
using NQutils;
using NQutils.Exceptions;
using NQutils.Net;
using NQutils.Serialization;
using NQutils.Sql;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using MathNet.Spatial.Euclidean;
using MathNet.Numerics;
public class MyDuMod : IMod
{
private IServiceProvider isp;
private ILogger logger;
private IPub pub;
private IClusterClient orleans;
private readonly Dictionary<ulong, ulong> playerPlanetCat = new();
public string GetName()
{
return "DynamicInterestPoint";
}
public Task Initialize(IServiceProvider isp)
{
this.isp = isp;
this.logger = isp.GetRequiredService<ILogger<MyDuMod>>();
this.pub = isp.GetRequiredService<IPub>();
this.orleans = isp.GetRequiredService<IClusterClient>();
return Task.CompletedTask;
}
public Task<ModInfo> GetModInfoFor(ulong playerId, bool admin)
{
return Task.FromResult<ModInfo>(new ModInfo
{
name = GetName(),
actions = new List<ModActionDefinition>
{
new ModActionDefinition
{
id = 1000,
label = "My cat is here!",
context = ModActionContext.Global,
},
new ModActionDefinition
{
id = 1001,
label = "My cat is stealth!",
context = ModActionContext.Global,
},
}
});
}
public async Task TriggerAction(ulong playerId, ModAction action)
{
if (action.actionId == 1001)
{
if (!playerPlanetCat.ContainsKey(playerId))
return;
var dip = new DynamicInterestPoint
{
planetId = playerPlanetCat[playerId],
markType = 1000,
uniqueId = 1000000,
location = new DetailedLocation
{
absolute = new(),
relative = new(),
}
};
var dips = JsonConvert.SerializeObject(dip);
logger.LogInformation("GO FOR REMOVE {mark}", dips);
var s = new VoxelEdit
{
flags = 10,
hashContext = dips,
};
await pub.NotifyTopic(Topics.PlayerNotifications(playerId),
new NQutils.Messages.VoxelCsgApplied(s));
return;
}
if (action.actionId == 1000)
{
var (rloc, aloc) = await isp.GetRequiredService<IScenegraph>().GetPlayerWorldPosition(playerId);
ulong planetId = 0;
if (rloc.constructId != 0)
{
var ctree = await isp.GetRequiredService<IScenegraph>().GetTree(rloc.constructId);
foreach (var crd in ctree)
{
if (crd.constructId < 10000)
{
planetId = crd.constructId;
break;
}
}
}
playerPlanetCat[playerId] = planetId;
var dip = new DynamicInterestPoint
{
planetId = planetId,
markType = 1000,
uniqueId = 1000000,
location = new DetailedLocation
{
absolute = aloc,
relative = rloc,
},
name = "My CAT",
description = "He's so cute and fluffy!",
};
var dips = JsonConvert.SerializeObject(dip);
logger.LogInformation("GO FOR {mark}", dips);
var s = new VoxelEdit
{
flags = 9,
hashContext = dips,
};
await pub.NotifyTopic(Topics.PlayerNotifications(playerId),
new NQutils.Messages.VoxelCsgApplied(s));
}
}
}