Added world specific regions and warps. Added logging. reagions and warps will require redoing
This commit is contained in:
parent
25472ea497
commit
db1edd3f98
3 changed files with 62 additions and 27 deletions
|
|
@ -764,7 +764,7 @@ namespace TShockAPI
|
||||||
private static void SetWarp(CommandArgs args)
|
private static void SetWarp(CommandArgs args)
|
||||||
{
|
{
|
||||||
if (args.Parameters.Count > 0)
|
if (args.Parameters.Count > 0)
|
||||||
if (WarpsManager.AddWarp(args.Player.TileX, args.Player.TileY, args.Parameters[0]))
|
if (WarpsManager.AddWarp(args.Player.TileX, args.Player.TileY, args.Parameters[0], Main.worldName))
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Set warp " + args.Parameters[0], Color.Yellow);
|
args.Player.SendMessage("Set warp " + args.Parameters[0], Color.Yellow);
|
||||||
WarpsManager.WriteSettings();
|
WarpsManager.WriteSettings();
|
||||||
|
|
@ -1039,7 +1039,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (!args.Player.TempArea.IsEmpty)
|
if (!args.Player.TempArea.IsEmpty)
|
||||||
{
|
{
|
||||||
if (RegionManager.AddRegion(args.Player.TempArea.X, args.Player.TempArea.Y, args.Player.TempArea.Width, args.Player.TempArea.Height, args.Parameters[1], true))
|
if (RegionManager.AddRegion(args.Player.TempArea.X, args.Player.TempArea.Y, args.Player.TempArea.Width, args.Player.TempArea.Height, args.Parameters[1], Main.worldName))
|
||||||
{
|
{
|
||||||
RegionManager.WriteSettings();
|
RegionManager.WriteSettings();
|
||||||
args.Player.TempArea = Rectangle.Empty;
|
args.Player.TempArea = Rectangle.Empty;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
using Terraria;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
|
|
@ -11,7 +12,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
public static List<Region> Regions = new List<Region>();
|
public static List<Region> Regions = new List<Region>();
|
||||||
|
|
||||||
public static bool AddRegion(int tx, int ty, int width, int height, string name, bool state)
|
public static bool AddRegion(int tx, int ty, int width, int height, string name, string worldname)
|
||||||
{
|
{
|
||||||
foreach (Region nametest in Regions)
|
foreach (Region nametest in Regions)
|
||||||
{
|
{
|
||||||
|
|
@ -20,7 +21,7 @@ namespace TShockAPI
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Regions.Add(new Region(new Rectangle(tx, ty, width, height), name, true));
|
Regions.Add(new Region(new Rectangle(tx, ty, width, height), name, true, worldname));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,7 +29,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
foreach (Region nametest in Regions)
|
foreach (Region nametest in Regions)
|
||||||
{
|
{
|
||||||
if (name.ToLower() == nametest.RegionName.ToLower())
|
if (name.ToLower() == nametest.RegionName.ToLower() && nametest.WorldRegionName == Main.worldName)
|
||||||
{
|
{
|
||||||
Regions.Remove(nametest);
|
Regions.Remove(nametest);
|
||||||
WriteSettings();
|
WriteSettings();
|
||||||
|
|
@ -56,7 +57,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
foreach(Region region in Regions)
|
foreach(Region region in Regions)
|
||||||
{
|
{
|
||||||
if (X >= region.RegionArea.Left && X <= region.RegionArea.Right && Y >= region.RegionArea.Top && Y <= region.RegionArea.Bottom && region.DisableBuild)
|
if (X >= region.RegionArea.Left && X <= region.RegionArea.Right && Y >= region.RegionArea.Top && Y <= region.RegionArea.Bottom && region.DisableBuild && Main.worldName == region.WorldRegionName)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -86,6 +87,7 @@ namespace TShockAPI
|
||||||
settingsw.WriteElementString("Point2X", region.RegionArea.Width.ToString());
|
settingsw.WriteElementString("Point2X", region.RegionArea.Width.ToString());
|
||||||
settingsw.WriteElementString("Point2Y", region.RegionArea.Height.ToString());
|
settingsw.WriteElementString("Point2Y", region.RegionArea.Height.ToString());
|
||||||
settingsw.WriteElementString("Protected", region.DisableBuild.ToString());
|
settingsw.WriteElementString("Protected", region.DisableBuild.ToString());
|
||||||
|
settingsw.WriteElementString("WorldName", region.WorldRegionName);
|
||||||
settingsw.WriteEndElement();
|
settingsw.WriteEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,7 +98,7 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Log.Info("Could not write Regions");
|
Log.Warn("Could not write Regions");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,15 +125,20 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (settingr.Read())
|
if (settingr.Read())
|
||||||
{
|
{
|
||||||
string name;
|
string name = null;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
bool state = true;
|
bool state = true;
|
||||||
|
string worldname = null;
|
||||||
|
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
name = settingr.Value;
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
|
name = settingr.Value;
|
||||||
|
else
|
||||||
|
Log.Warn("Region name is empty");
|
||||||
|
|
||||||
|
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
|
|
@ -139,7 +146,7 @@ namespace TShockAPI
|
||||||
if (settingr.Value != "" || settingr.Value != null)
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
Int32.TryParse(settingr.Value, out x);
|
Int32.TryParse(settingr.Value, out x);
|
||||||
else
|
else
|
||||||
Console.WriteLine("Could not parse x");
|
Log.Warn("x for region " + name + " is empty");
|
||||||
|
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
|
|
@ -147,7 +154,7 @@ namespace TShockAPI
|
||||||
if (settingr.Value != "" || settingr.Value != null)
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
Int32.TryParse(settingr.Value, out y);
|
Int32.TryParse(settingr.Value, out y);
|
||||||
else
|
else
|
||||||
Console.WriteLine("Could not parse y");
|
Log.Warn("y for region " + name + " is empty");
|
||||||
|
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
|
|
@ -155,7 +162,7 @@ namespace TShockAPI
|
||||||
if (settingr.Value != "" || settingr.Value != null)
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
Int32.TryParse(settingr.Value, out width);
|
Int32.TryParse(settingr.Value, out width);
|
||||||
else
|
else
|
||||||
Console.WriteLine("Could not parse width");
|
Log.Warn("Width for region " + name + " is empty");
|
||||||
|
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
|
|
@ -163,7 +170,7 @@ namespace TShockAPI
|
||||||
if (settingr.Value != "" || settingr.Value != null)
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
Int32.TryParse(settingr.Value, out height);
|
Int32.TryParse(settingr.Value, out height);
|
||||||
else
|
else
|
||||||
Console.WriteLine("Could not parse height");
|
Log.Warn("Height for region " + name + " is empty");
|
||||||
|
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
|
|
@ -171,9 +178,17 @@ namespace TShockAPI
|
||||||
if (settingr.Value != "" || settingr.Value != null)
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
bool.TryParse(settingr.Value, out state);
|
bool.TryParse(settingr.Value, out state);
|
||||||
else
|
else
|
||||||
Console.WriteLine("Could not parse state");
|
Log.Warn("State for region " + name + " is empty");
|
||||||
|
|
||||||
AddRegion(x, y, width, height, name, state);
|
settingr.Read();
|
||||||
|
settingr.Read();
|
||||||
|
settingr.Read();
|
||||||
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
|
worldname = settingr.Value;
|
||||||
|
else
|
||||||
|
Log.Warn("Worldname for region " + name + " is empty");
|
||||||
|
|
||||||
|
AddRegion(x, y, width, height, name, worldname);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -185,7 +200,7 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Log.Info("Could not read Regions");
|
Log.Warn("Could not read Regions");
|
||||||
WriteSettings();
|
WriteSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -196,12 +211,14 @@ namespace TShockAPI
|
||||||
public Rectangle RegionArea { get; set; }
|
public Rectangle RegionArea { get; set; }
|
||||||
public string RegionName { get; set; }
|
public string RegionName { get; set; }
|
||||||
public bool DisableBuild { get; set; }
|
public bool DisableBuild { get; set; }
|
||||||
|
public string WorldRegionName { get; set; }
|
||||||
|
|
||||||
public Region(Rectangle region, string name, bool disablebuild)
|
public Region(Rectangle region, string name, bool disablebuild, string worldname)
|
||||||
{
|
{
|
||||||
RegionArea = region;
|
RegionArea = region;
|
||||||
RegionName = name;
|
RegionName = name;
|
||||||
DisableBuild = disablebuild;
|
DisableBuild = disablebuild;
|
||||||
|
WorldRegionName = worldname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Region()
|
public Region()
|
||||||
|
|
@ -209,6 +226,7 @@ namespace TShockAPI
|
||||||
RegionArea = Rectangle.Empty;
|
RegionArea = Rectangle.Empty;
|
||||||
RegionName = string.Empty;
|
RegionName = string.Empty;
|
||||||
DisableBuild = true;
|
DisableBuild = true;
|
||||||
|
WorldRegionName = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using Terraria;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
|
|
@ -11,7 +12,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
public static List<Warp> Warps = new List<Warp>();
|
public static List<Warp> Warps = new List<Warp>();
|
||||||
|
|
||||||
public static bool AddWarp(int x, int y, string name)
|
public static bool AddWarp(int x, int y, string name, string worldname)
|
||||||
{
|
{
|
||||||
foreach (Warp nametest in Warps)
|
foreach (Warp nametest in Warps)
|
||||||
{
|
{
|
||||||
|
|
@ -20,7 +21,7 @@ namespace TShockAPI
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Warps.Add(new Warp(new Vector2(x, y), name));
|
Warps.Add(new Warp(new Vector2(x, y), name, worldname));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,7 +29,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
foreach (Warp nametest in Warps)
|
foreach (Warp nametest in Warps)
|
||||||
{
|
{
|
||||||
if (name.ToLower() == nametest.WarpName.ToLower())
|
if (name.ToLower() == nametest.WarpName.ToLower() && nametest.WorldWarpName == Main.worldName)
|
||||||
{
|
{
|
||||||
Warps.Remove(nametest);
|
Warps.Remove(nametest);
|
||||||
WriteSettings();
|
WriteSettings();
|
||||||
|
|
@ -42,7 +43,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
foreach (Warp nametest in Warps)
|
foreach (Warp nametest in Warps)
|
||||||
{
|
{
|
||||||
if (name.ToLower() == nametest.WarpName.ToLower())
|
if (name.ToLower() == nametest.WarpName.ToLower() && nametest.WorldWarpName == Main.worldName)
|
||||||
{
|
{
|
||||||
return nametest.WarpPos;
|
return nametest.WarpPos;
|
||||||
}
|
}
|
||||||
|
|
@ -69,6 +70,7 @@ namespace TShockAPI
|
||||||
settingsw.WriteElementString("WarpName", warp.WarpName);
|
settingsw.WriteElementString("WarpName", warp.WarpName);
|
||||||
settingsw.WriteElementString("X", warp.WarpPos.X.ToString());
|
settingsw.WriteElementString("X", warp.WarpPos.X.ToString());
|
||||||
settingsw.WriteElementString("Y", warp.WarpPos.Y.ToString());
|
settingsw.WriteElementString("Y", warp.WarpPos.Y.ToString());
|
||||||
|
settingsw.WriteElementString("WorldName", warp.WorldWarpName);
|
||||||
settingsw.WriteEndElement();
|
settingsw.WriteEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,12 +108,16 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (settingr.Read())
|
if (settingr.Read())
|
||||||
{
|
{
|
||||||
string name;
|
string name = string.Empty;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
string worldname = string.Empty;
|
||||||
|
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
name = settingr.Value;
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
|
name = settingr.Value;
|
||||||
|
else
|
||||||
|
Log.Warn("Warp name is empty, This warp will not work");
|
||||||
|
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
|
|
@ -119,7 +125,7 @@ namespace TShockAPI
|
||||||
if (settingr.Value != "" || settingr.Value != null)
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
Int32.TryParse(settingr.Value, out x);
|
Int32.TryParse(settingr.Value, out x);
|
||||||
else
|
else
|
||||||
Console.WriteLine("Could not parse x");
|
Log.Warn("x for warp " + name + " is empty");
|
||||||
|
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
settingr.Read();
|
settingr.Read();
|
||||||
|
|
@ -127,9 +133,17 @@ namespace TShockAPI
|
||||||
if (settingr.Value != "" || settingr.Value != null)
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
Int32.TryParse(settingr.Value, out y);
|
Int32.TryParse(settingr.Value, out y);
|
||||||
else
|
else
|
||||||
Console.WriteLine("Could not parse y");
|
Log.Warn("y for warp " + name + " is empty");
|
||||||
|
|
||||||
AddWarp(x, y, name);
|
settingr.Read();
|
||||||
|
settingr.Read();
|
||||||
|
settingr.Read();
|
||||||
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
|
worldname = settingr.Value;
|
||||||
|
else
|
||||||
|
Log.Warn("Worldname for warp " + name + " is empty");
|
||||||
|
|
||||||
|
AddWarp(x, y, name, worldname);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -151,17 +165,20 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
public Vector2 WarpPos { get; set; }
|
public Vector2 WarpPos { get; set; }
|
||||||
public string WarpName { get; set; }
|
public string WarpName { get; set; }
|
||||||
|
public string WorldWarpName { get; set; }
|
||||||
|
|
||||||
public Warp(Vector2 warppos, string name)
|
public Warp(Vector2 warppos, string name, string worldname)
|
||||||
{
|
{
|
||||||
WarpPos = warppos;
|
WarpPos = warppos;
|
||||||
WarpName = name;
|
WarpName = name;
|
||||||
|
WorldWarpName = worldname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Warp()
|
public Warp()
|
||||||
{
|
{
|
||||||
WarpPos = Vector2.Zero;
|
WarpPos = Vector2.Zero;
|
||||||
WarpName = null;
|
WarpName = null;
|
||||||
|
WorldWarpName = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue