forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL2WorldRegion.cs
More file actions
218 lines (174 loc) · 6.21 KB
/
Copy pathL2WorldRegion.cs
File metadata and controls
218 lines (174 loc) · 6.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System.Collections.Generic;
using System.Linq;
using L2dotNET.Models;
using L2dotNET.Models.Player;
using L2dotNET.Models.Zones;
using NLog;
namespace L2dotNET.World
{
public class L2WorldRegion
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
private readonly Dictionary<int, L2Object> _objects = new Dictionary<int, L2Object>();
private readonly List<L2WorldRegion> _surroundingRegions = new List<L2WorldRegion>();
private readonly List<L2ZoneType> _zones = new List<L2ZoneType>();
private readonly int _tileX;
private readonly int _tileY;
private bool _active;
private int _playersCount;
public L2WorldRegion(int x, int y)
{
_tileX = x;
_tileY = y;
}
public string GetName()
{
return $"WorldRegion:{_tileX}_{_tileY}";
}
public List<L2Object> GetObjects()
{
return _objects.Values.ToList();
}
public void AddSurroundingRegion(L2WorldRegion region)
{
_surroundingRegions.Add(region);
}
public List<L2WorldRegion> GetSurroundingRegions()
{
return _surroundingRegions;
}
public List<L2ZoneType> GetZones()
{
return _zones;
}
public void AddZone(L2ZoneType zone)
{
_zones.Add(zone);
}
public void RemoveZone(L2ZoneType zone)
{
_zones.Remove(zone);
}
public void RevalidateZones(L2Character character)
{
//if (character.isTeleporting())
// return;
_zones.ForEach(zone => zone.RevalidateInZone(character));
}
public void RemoveFromZones(L2Character character)
{
_zones.ForEach(zone => zone.RemoveCharacter(character));
}
public bool ContainsZone(int zoneId)
{
return _zones.Any(z => z.Id == zoneId);
}
// public bool checkEffectRangeInsidePeaceZone(L2Skill skill, final int x, final int y, final int z)
// {
// int range = skill.getEffectRange();
// int up = y + range;
// int down = y - range;
// int left = x + range;
// int right = x - range;
// foreach (L2ZoneType e in _zones)
// {
//// if ((e is L2TownZone && ((L2TownZone)e).isPeaceZone()) || e instanceof L2DerbyTrackZone || e instanceof L2PeaceZone)
////{
// //if (e.isInsideZone(x, up, z))
// // return false;
// //if (e.isInsideZone(x, down, z))
// // return false;
// //if (e.isInsideZone(left, y, z))
// // return false;
// //if (e.isInsideZone(right, y, z))
// // return false;
// //if (e.isInsideZone(x, y, z))
// // return false;
// //}
// }
// return true;
// }
//public void onDeath(L2Character character)
//{
// _zones.stream().filter(z->z.isCharacterInZone(character)).forEach(z->z.onDieInside(character));
//}
//public void onRevive(L2Character character)
//{
// _zones.stream().filter(z->z.isCharacterInZone(character)).forEach(z->z.onReviveInside(character));
//}
public bool IsActive()
{
return _active;
}
public int GetPlayersCount()
{
return _playersCount;
}
/**
* Check if neighbors (including self) aren't inhabited.
* @return true if the above condition is met.
*/
public bool IsEmptyNeighborhood()
{
return _surroundingRegions.All(neighbor => neighbor.GetPlayersCount() == 0);
}
/**
* This function turns this region's AI on or off.
* @param value : if true, activate hp/mp regen and random animation. If false, clean aggro/attack list, set objects on IDLE and drop their AI tasks.
*/
public void SetActive(bool value)
{
_active = value;
//if (!value)
//{
// foreach (L2Object o in _objects.Values)
// {
// if (o is L2Attackable)
// {
// L2Attackable mob = (L2Attackable)o;
// // Set target to null and cancel Attack or Cast
// mob.setTarget(null);
// // Stop movement
// mob.stopMove(null);
// // Stop all active skills effects in progress on the L2Character
// mob.stopAllEffects();
// mob.getAggroList().clear();
// mob.getAttackByList().clear();
// // stop the ai tasks
// if (mob.hasAI())
// {
// mob.getAI().setIntention(CtrlIntention.IDLE);
// mob.getAI().stopAITask();
// }
// }
// }
//else
//{
// for (L2Object o : _objects.values())
// {
// if (o instanceof L2Attackable)
// ((L2Attackable)o).getStatus().startHpMpRegeneration();
// else if (o instanceof L2Npc)
// ((L2Npc)o).startRandomAnimationTimer();
// }
//}
}
public void AddVisibleObject(L2Object obj)
{
if (obj == null)
return;
if (!_objects.ContainsKey(obj.ObjectId))
_objects.Add(obj.ObjectId, obj);
if (obj is L2Player)
_playersCount += 1;
}
public void RemoveVisibleObject(L2Object obj)
{
if (obj == null)
return;
_objects.Remove(obj.ObjectId);
if (obj is L2Player)
_playersCount -= 1;
}
}
}