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