-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRegion.cs
More file actions
85 lines (84 loc) · 2.74 KB
/
Region.cs
File metadata and controls
85 lines (84 loc) · 2.74 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TShockAPI;
namespace Factions
{
public class Region
{
public int ID;
public int X;
public int Y;
public int Width;
public int Height;
public byte Flags;
public int Owner;
public int Faction;
public Region(int id, int x, int y) : this(id, x, y, 0, 0, 0) { }
public Region(int id, int x, int y, int owner) : this(id, x, y, owner, 0, 0) { }
public Region(int id, int x, int y, int owner, int faction) : this(id, x, y, owner, faction, 0) { }
public Region(int id, int x, int y, int owner, int faction, byte flags)
{
this.ID = id;
this.X = x;
this.Y = y;
this.Width = 20;
this.Height = 20;
this.Flags = flags;
this.Owner = owner;
this.Faction = faction;
}
public bool InArea(Point point)
{
return InArea(point.X, point.Y);
}
public bool InArea(int x, int y)
{
if (x >= this.X && x < (this.X + this.Width) && y >= this.Y && y < (this.Y + this.Height))
return true;
return false;
}
public static Region GetRegionByID(int id)
{
foreach (Region reg in Factions.Regions)
{
if (reg.ID == id)
return reg;
}
return new Region(-1, 0, 0);
}
public static List<Region> GetRegionsByUserID(int userid)
{
List<Region> ReturnList = new List<Region>();
foreach (Region reg in Factions.Regions)
{
if (reg.Owner != -1 && reg.Owner == userid)
ReturnList.Add(reg);
}
return ReturnList;
}
public static Region GetRegionFromLocation(int x, int y)
{
foreach (Region reg in Factions.Regions)
{
if (reg.InArea(x, y))
return reg;
}
var newregion = new Region(-1, x, y);
newregion.X = (int)(newregion.X / newregion.Width) * newregion.Width;
newregion.Y = (int)(newregion.Y / newregion.Height) * newregion.Height;
return newregion;
}
public static List<TShockAPI.DB.Region> GetTSRegionsFromLocation(int x, int y)
{
List<TShockAPI.DB.Region> returnList = new List<TShockAPI.DB.Region>();
foreach (TShockAPI.DB.Region region in TShock.Regions.Regions)
{
if (region.InArea(x, y))
returnList.Add(region);
}
return returnList;
}
}
}