source: binary-improvements/MapRendering/Web/API/GetHostileLocation.cs@ 323

Last change on this file since 323 was 313, checked in by alloc, 7 years ago

Common func: Rebased Animals and Hostiles to common base

File size: 1.5 KB
RevLine 
[251]1using AllocsFixes.JSON;
2using AllocsFixes.LiveData;
3using System;
4using System.Collections.Generic;
5using System.Net;
6
7namespace AllocsFixes.NetConnections.Servers.Web.API
8{
9 class GetHostileLocation : WebAPI
10 {
[306]11 private List<EntityEnemy> enemies = new List<EntityEnemy> ();
12
[251]13 public override void HandleRequest(HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel)
14 {
15 JSONArray hostilesJsResult = new JSONArray();
16
[313]17 Hostiles.Instance.Get (enemies);
[306]18 for (int i = 0; i < enemies.Count; i++)
[251]19 {
[306]20 EntityEnemy entity = enemies [i];
[251]21 Vector3i position = new Vector3i(entity.GetPosition());
22
23 JSONObject jsonPOS = new JSONObject();
24 jsonPOS.Add("x", new JSONNumber(position.x));
25 jsonPOS.Add("y", new JSONNumber(position.y));
26 jsonPOS.Add("z", new JSONNumber(position.z));
27
28 JSONObject pJson = new JSONObject();
29 pJson.Add("id", new JSONNumber(entity.entityId));
30
31 if (!string.IsNullOrEmpty(entity.EntityName))
32 pJson.Add("name", new JSONString(entity.EntityName));
33 else
34 pJson.Add("name", new JSONString("enemy class #" + entity.entityClass.ToString()));
35
36 pJson.Add("position", jsonPOS);
37
38 hostilesJsResult.Add(pJson);
39 }
40
41 WriteJSON(resp, hostilesJsResult);
42 }
43 }
44}
Note: See TracBrowser for help on using the repository browser.