Elin Decompiled Documentation EA 23.201 Nightly
Loading...
Searching...
No Matches
ZoneEventManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using Newtonsoft.Json;
4using UnityEngine;
5
6public class ZoneEventManager : EClass
7{
8 public Zone zone;
9
10 [JsonProperty]
11 public List<ZoneEvent> list = new List<ZoneEvent>();
12
13 [JsonProperty]
14 public List<ZonePreEnterEvent> listPreEnter = new List<ZonePreEnterEvent>();
15
16 public void OnLoad(Zone _zone)
17 {
18 zone = _zone;
19 foreach (ZoneEvent item in list)
20 {
21 item.zone = zone;
22 item.OnLoad();
23 }
24 }
25
26 public void Add<T>(bool allowDuplicate = false) where T : ZoneEvent
27 {
28 Add(Activator.CreateInstance<T>(), allowDuplicate);
29 }
30
31 public void Add(ZoneEvent e, bool allowDuplicate = false)
32 {
34 {
35 return;
36 }
37 if (!allowDuplicate)
38 {
39 foreach (ZoneEvent item in list)
40 {
41 if (e.GetType() == item.GetType())
42 {
43 return;
44 }
45 }
46 }
47 list.Add(e);
48 e.zone = zone;
49 e.Init();
50 Debug.Log("#game zone event " + e.GetType()?.ToString() + " added.");
51 }
52
53 public void AddPreEnter(ZonePreEnterEvent e, bool executeIfActiveZone = true)
54 {
55 if (zone.IsActiveZone && executeIfActiveZone)
56 {
57 e.Execute();
58 }
59 else
60 {
61 listPreEnter.Add(e);
62 }
63 }
64
65 public T GetEvent<T>() where T : ZoneEvent
66 {
67 foreach (ZoneEvent item in list)
68 {
69 if (item is T)
70 {
71 return item as T;
72 }
73 }
74 return null;
75 }
76
77 public void Remove<T>() where T : ZoneEvent
78 {
79 for (int num = list.Count - 1; num >= 0; num--)
80 {
81 if (list[num] is T)
82 {
83 list[num].Kill();
84 }
85 }
86 }
87
88 public void Remove(ZoneEvent e)
89 {
90 list.Remove(e);
91 }
92
93 public void Clear()
94 {
95 list.Clear();
96 }
97
98 public void Tick(float delta)
99 {
100 list.ForeachReverse(delegate(ZoneEvent e)
101 {
102 e.Tick(delta);
103 });
104 }
105
106 public void OnVisit()
107 {
108 foreach (ZoneEvent item in list)
109 {
110 item.OnVisit();
111 }
112 }
113
114 public void OnLeaveZone()
115 {
116 foreach (ZoneEvent item in list)
117 {
118 item.OnLeaveZone();
119 }
120 }
121
122 public void OnCharaDie(Chara c)
123 {
124 list.ForeachReverse(delegate(ZoneEvent e)
125 {
126 e.OnCharaDie(c);
127 });
128 }
129
130 public void OnSimulateHour()
131 {
132 if (list.Count == 0)
133 {
134 return;
135 }
136 foreach (ZoneEvent item in list.Copy())
137 {
138 item.OnSimulateHour();
139 }
140 }
141}
Definition: Chara.cs:10
bool skipEvent
Definition: CoreDebug.cs:162
Definition: EClass.cs:5
static Zone _zone
Definition: EClass.cs:20
static CoreDebug debug
Definition: EClass.cs:48
List< ZoneEvent > list
void Add< T >(bool allowDuplicate=false)
List< ZonePreEnterEvent > listPreEnter
void Add(ZoneEvent e, bool allowDuplicate=false)
void OnLoad(Zone _zone)
void Tick(float delta)
void OnCharaDie(Chara c)
void AddPreEnter(ZonePreEnterEvent e, bool executeIfActiveZone=true)
void Remove(ZoneEvent e)
void Tick(float delta)
Definition: ZoneEvent.cs:48
virtual bool debugSkip
Definition: ZoneEvent.cs:31
virtual void OnCharaDie(Chara c)
Definition: ZoneEvent.cs:102
void Init()
Definition: ZoneEvent.cs:64
virtual void Execute()
Definition: Zone.cs:12
bool IsActiveZone
Definition: Zone.cs:490