[325] | 1 | using System.Collections.Generic;
|
---|
| 2 | using AllocsFixes.JSON;
|
---|
[251] | 3 | using AllocsFixes.LiveData;
|
---|
[454] | 4 | using Webserver;
|
---|
| 5 | using Webserver.WebAPI;
|
---|
[251] | 6 |
|
---|
[454] | 7 | namespace AllocsFixes.WebAPIs {
|
---|
| 8 | internal class GetHostileLocation : AbsWebAPI {
|
---|
[325] | 9 | private readonly List<EntityEnemy> enemies = new List<EntityEnemy> ();
|
---|
[306] | 10 |
|
---|
[454] | 11 | public override void HandleRequest (RequestContext _context) {
|
---|
[325] | 12 | JSONArray hostilesJsResult = new JSONArray ();
|
---|
[251] | 13 |
|
---|
[313] | 14 | Hostiles.Instance.Get (enemies);
|
---|
[325] | 15 | for (int i = 0; i < enemies.Count; i++) {
|
---|
[306] | 16 | EntityEnemy entity = enemies [i];
|
---|
[325] | 17 | Vector3i position = new Vector3i (entity.GetPosition ());
|
---|
[251] | 18 |
|
---|
[325] | 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));
|
---|
[251] | 23 |
|
---|
[325] | 24 | JSONObject pJson = new JSONObject ();
|
---|
| 25 | pJson.Add ("id", new JSONNumber (entity.entityId));
|
---|
[251] | 26 |
|
---|
[325] | 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 | }
|
---|
[251] | 32 |
|
---|
[325] | 33 | pJson.Add ("position", jsonPOS);
|
---|
[251] | 34 |
|
---|
[325] | 35 | hostilesJsResult.Add (pJson);
|
---|
| 36 | }
|
---|
[251] | 37 |
|
---|
[454] | 38 | LegacyApiHelper.WriteJSON (_context.Response, hostilesJsResult);
|
---|
[325] | 39 | }
|
---|
| 40 | }
|
---|
| 41 | }
|
---|