source: binary-improvements/7dtd-server-fixes/src/LiveData/Animals.cs@ 306

Last change on this file since 306 was 306, checked in by alloc, 8 years ago

Fixes update A16.2

File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace AllocsFixes.LiveData
5{
6 public class Animals
7 {
8 public static void Get (List<EntityAnimal> _list) {
9 _list.Clear ();
10 try {
11 List<Entity> entities = GameManager.Instance.World.Entities.list;
12 for (int i = 0; i < entities.Count; i++) {
13 Entity entity = entities [i];
14
15 // Kind of hack-ish, but the game is legitimately setting the base type of animals ('entityType') to enum 0 ('EntityType.Unknown').
16 if ((entity.entityType == EntityType.Animal) || (entity is EntityAnimal)) {
17 EntityAnimal ea = (EntityAnimal)entity;
18
19 if (ea.IsAlive ())
20 _list.Add (ea);
21 }
22 }
23 }
24 catch (Exception e) {
25 Log.Exception (e);
26 }
27 }
28
29 public static int GetCount () {
30 int count = 0;
31 try {
32 List<Entity> entities = GameManager.Instance.World.Entities.list;
33 for (int i = 0; i < entities.Count; i++) {
34 Entity entity = entities [i];
35
36 // Kind of hack-ish, but the game is legitimately setting the base type of animals ('entityType') to enum 0 ('EntityType.Unknown').
37 if ((entity.entityType == EntityType.Animal) || (entity is EntityAnimal)) {
38 EntityAnimal ea = (EntityAnimal)entity;
39
40 if (ea.IsAlive ())
41 count++;
42 }
43 }
44 }
45 catch (Exception e) {
46 Log.Exception (e);
47 }
48 return count;
49 }
50
51 }
52}
53
Note: See TracBrowser for help on using the repository browser.