-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFlaggedRegionManager.cs
96 lines (84 loc) · 2.62 KB
/
FlaggedRegionManager.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TShockAPI;
using TShockAPI.DB;
namespace RegionFlags
{
class FlaggedRegionManager
{
private Dictionary<string, FlaggedRegion> regions;
public FlaggedRegionManager()
{
regions = new Dictionary<string, FlaggedRegion>();
}
public void ImportRegion( string name, int flags, int d, int h, List<string> items, Group tempGroup )
{
var reg = TShock.Regions.GetRegionByName(name);
if( reg == null )
{
Console.WriteLine( "{0} was not found in tshocks region list.", name);
return;
}
FlaggedRegion f = new FlaggedRegion(reg, flags);
f.setDPS( d );
f.setHPS(h);
f.setBannedItems(items);
f.setTempGroup(tempGroup);
regions.Add( name, f );
}
public bool AddRegion( string name, int flags )
{
if( regions.ContainsKey( name ) )
{
return false;
}
var reg = TShock.Regions.GetRegionByName(name);
FlaggedRegion f = new FlaggedRegion(reg, flags);
f.setDPS(0);
//todo:save to db
RegionFlags.db.Query(
"INSERT INTO Regions (Name, Flags, Damage) VALUES (@0, @1, @2);",
name, flags, 0);
regions.Add(name, f);
return true;
}
public bool UpdateRegion( string name )
{
if( !regions.ContainsKey(name))
{
return false;
}
FlaggedRegion f = regions[name];
RegionFlags.db.Query(
"UPDATE Regions SET Flags=@0, Damage=@1, Heal=@2, TempGroup=@3 WHERE Name=@4", f.getIntFlags(), f.getDPS(), f.getHPS(), f.getTempGroup(), name);
return true;
}
public FlaggedRegion getRegion( string region )
{
if( regions.ContainsKey(region))
{
return regions[region];
}
return null;
}
public List<FlaggedRegion> InRegions( int x, int y )
{
List<FlaggedRegion> ret = new List<FlaggedRegion>();
foreach( FlaggedRegion reg in regions.Values )
{
if (reg.getRegion() != null)
{
if (reg.getRegion().InArea(x, y))
ret.Add(reg);
}
}
return ret;
}
public void Clear()
{
regions.Clear();
}
}
}