1 | using System.Collections.Generic;
|
---|
2 | using AllocsFixes.JSON;
|
---|
3 | using AllocsFixes.LiveData;
|
---|
4 | using JetBrains.Annotations;
|
---|
5 |
|
---|
6 | namespace Webserver.WebAPI {
|
---|
7 | [UsedImplicitly]
|
---|
8 | internal class GetHostileLocation : AbsWebAPI {
|
---|
9 | private readonly List<EntityEnemy> enemies = new List<EntityEnemy> ();
|
---|
10 |
|
---|
11 | public override void HandleRequest (RequestContext _context) {
|
---|
12 | JsonArray hostilesJsResult = new JsonArray ();
|
---|
13 |
|
---|
14 | Hostiles.Instance.Get (enemies);
|
---|
15 | for (int i = 0; i < enemies.Count; i++) {
|
---|
16 | EntityEnemy entity = enemies [i];
|
---|
17 | Vector3i position = new Vector3i (entity.GetPosition ());
|
---|
18 |
|
---|
19 | JsonObject jsonPOS = new JsonObject ();
|
---|
20 | jsonPOS.Add ("x", new JsonNumber (position.x));
|
---|
21 | jsonPOS.Add ("y", new JsonNumber (position.y));
|
---|
22 | jsonPOS.Add ("z", new JsonNumber (position.z));
|
---|
23 |
|
---|
24 | JsonObject pJson = new JsonObject ();
|
---|
25 | pJson.Add ("id", new JsonNumber (entity.entityId));
|
---|
26 |
|
---|
27 | if (!string.IsNullOrEmpty (entity.EntityName)) {
|
---|
28 | pJson.Add ("name", new JsonString (entity.EntityName));
|
---|
29 | } else {
|
---|
30 | pJson.Add ("name", new JsonString ("enemy class #" + entity.entityClass));
|
---|
31 | }
|
---|
32 |
|
---|
33 | pJson.Add ("position", jsonPOS);
|
---|
34 |
|
---|
35 | hostilesJsResult.Add (pJson);
|
---|
36 | }
|
---|
37 |
|
---|
38 | WebUtils.WriteJson (_context.Response, hostilesJsResult);
|
---|
39 | }
|
---|
40 | }
|
---|
41 | }
|
---|