Add hooks for Region creation/deletion. Add hooks for Region Enter/Leave. Add member to TSPlayer displaying current region. Set private setters in AccountHooks.
This commit is contained in:
parent
803aa643c2
commit
406abce30c
6 changed files with 156 additions and 4 deletions
|
|
@ -115,6 +115,18 @@ namespace TShockAPI.DB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a region to the database.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tx">TileX of the top left corner.</param>
|
||||||
|
/// <param name="ty">TileY of the top left corner.</param>
|
||||||
|
/// <param name="width">Width of the region in tiles.</param>
|
||||||
|
/// <param name="height">Height of the region in tiles.</param>
|
||||||
|
/// <param name="regionname">The name of the region.</param>
|
||||||
|
/// <param name="owner">The User Account Name of the person who created this region.</param>
|
||||||
|
/// <param name="worldid">The world id that this region is in.</param>
|
||||||
|
/// <param name="z">The Z index of the region.</param>
|
||||||
|
/// <returns>Whether the region was created and added successfully.</returns>
|
||||||
public bool AddRegion(int tx, int ty, int width, int height, string regionname, string owner, string worldid, int z = 0)
|
public bool AddRegion(int tx, int ty, int width, int height, string regionname, string owner, string worldid, int z = 0)
|
||||||
{
|
{
|
||||||
if (GetRegionByName(regionname) != null)
|
if (GetRegionByName(regionname) != null)
|
||||||
|
|
@ -126,7 +138,9 @@ namespace TShockAPI.DB
|
||||||
database.Query(
|
database.Query(
|
||||||
"INSERT INTO Regions (X1, Y1, width, height, RegionName, WorldID, UserIds, Protected, Groups, Owner, Z) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10);",
|
"INSERT INTO Regions (X1, Y1, width, height, RegionName, WorldID, UserIds, Protected, Groups, Owner, Z) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10);",
|
||||||
tx, ty, width, height, regionname, worldid, "", 1, "", owner, z);
|
tx, ty, width, height, regionname, worldid, "", 1, "", owner, z);
|
||||||
Regions.Add(new Region(new Rectangle(tx, ty, width, height), regionname, owner, true, worldid, z));
|
var region = new Region(new Rectangle(tx, ty, width, height), regionname, owner, true, worldid, z);
|
||||||
|
Regions.Add(region);
|
||||||
|
Hooks.RegionHooks.OnRegionCreated(region);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -136,13 +150,20 @@ namespace TShockAPI.DB
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the region from this world with a given name.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name of the region to delete.</param>
|
||||||
|
/// <returns>Whether the region was successfully deleted.</returns>
|
||||||
public bool DeleteRegion(string name)
|
public bool DeleteRegion(string name)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
database.Query("DELETE FROM Regions WHERE RegionName=@0 AND WorldID=@1", name, Main.worldID.ToString());
|
database.Query("DELETE FROM Regions WHERE RegionName=@0 AND WorldID=@1", name, Main.worldID.ToString());
|
||||||
var worldid = Main.worldID.ToString();
|
var worldid = Main.worldID.ToString();
|
||||||
|
var region = Regions.FirstOrDefault(r => r.Name == name && r.WorldID == worldid);
|
||||||
Regions.RemoveAll(r => r.Name == name && r.WorldID == worldid);
|
Regions.RemoveAll(r => r.Name == name && r.WorldID == worldid);
|
||||||
|
Hooks.RegionHooks.OnRegionDeleted(region);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace TShockAPI.Hooks
|
||||||
{
|
{
|
||||||
public class AccountDeleteEventArgs
|
public class AccountDeleteEventArgs
|
||||||
{
|
{
|
||||||
public User User { get; set; }
|
public User User { get; private set; }
|
||||||
|
|
||||||
public AccountDeleteEventArgs(User user)
|
public AccountDeleteEventArgs(User user)
|
||||||
{
|
{
|
||||||
|
|
@ -31,7 +31,7 @@ namespace TShockAPI.Hooks
|
||||||
|
|
||||||
public class AccountCreateEventArgs
|
public class AccountCreateEventArgs
|
||||||
{
|
{
|
||||||
public User User { get; set; }
|
public User User { get; private set; }
|
||||||
|
|
||||||
public AccountCreateEventArgs(User user)
|
public AccountCreateEventArgs(User user)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
109
TShockAPI/Hooks/RegionHooks.cs
Normal file
109
TShockAPI/Hooks/RegionHooks.cs
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
TShock, a server mod for Terraria
|
||||||
|
Copyright (C) 2011-2015 Nyx Studios (fka. The TShock Team)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using TShockAPI.DB;
|
||||||
|
|
||||||
|
namespace TShockAPI.Hooks
|
||||||
|
{
|
||||||
|
class RegionHooks
|
||||||
|
{
|
||||||
|
internal class RegionEnteredEventArgs
|
||||||
|
{
|
||||||
|
public TSPlayer Player { get; private set; }
|
||||||
|
|
||||||
|
public RegionEnteredEventArgs(TSPlayer ply)
|
||||||
|
{
|
||||||
|
Player = ply;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void RegionEnteredD(RegionEnteredEventArgs args);
|
||||||
|
public static event RegionEnteredD RegionEntered;
|
||||||
|
public static void OnRegionEntered(TSPlayer player)
|
||||||
|
{
|
||||||
|
if (RegionEntered == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RegionEntered(new RegionEnteredEventArgs(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class RegionLeftEventArgs
|
||||||
|
{
|
||||||
|
public TSPlayer Player { get; private set; }
|
||||||
|
|
||||||
|
public RegionLeftEventArgs(TSPlayer ply)
|
||||||
|
{
|
||||||
|
Player = ply;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void RegionLeftD(RegionLeftEventArgs args);
|
||||||
|
public static event RegionLeftD RegionLeft;
|
||||||
|
public static void OnRegionLeft(TSPlayer player)
|
||||||
|
{
|
||||||
|
if (RegionLeft == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RegionLeft(new RegionLeftEventArgs(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class RegionCreatedEventArgs
|
||||||
|
{
|
||||||
|
public Region Region { get; private set; }
|
||||||
|
|
||||||
|
public RegionCreatedEventArgs(Region region)
|
||||||
|
{
|
||||||
|
Region = region;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void RegionCreatedD(RegionCreatedEventArgs args);
|
||||||
|
public static event RegionCreatedD RegionCreated;
|
||||||
|
public static void OnRegionCreated(Region region)
|
||||||
|
{
|
||||||
|
if (RegionCreated == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
RegionCreated(new RegionCreatedEventArgs(region));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class RegionDeletedEventArgs
|
||||||
|
{
|
||||||
|
public Region Region { get; private set; }
|
||||||
|
|
||||||
|
public RegionDeletedEventArgs(Region region)
|
||||||
|
{
|
||||||
|
Region = region;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void RegionDeletedD(RegionDeletedEventArgs args);
|
||||||
|
public static event RegionDeletedD RegionDeleted;
|
||||||
|
public static void OnRegionDeleted(Region region)
|
||||||
|
{
|
||||||
|
if (RegionDeleted == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
RegionDeleted(new RegionDeletedEventArgs(region));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -304,6 +304,11 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int LastKilledProjectile = 0;
|
public int LastKilledProjectile = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The current region this player is in, or null if none.
|
||||||
|
/// </summary>
|
||||||
|
public Region CurrentRegion = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the player is a real, human, player on the server.
|
/// Whether the player is a real, human, player on the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -818,6 +818,22 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
player.SetBuff(23, 120); //Cursed
|
player.SetBuff(23, 120); //Cursed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var oldRegion = player.CurrentRegion;
|
||||||
|
player.CurrentRegion = Regions.GetTopRegion(Regions.InAreaRegion(player.TileX, player.TileY));
|
||||||
|
|
||||||
|
if (oldRegion != player.CurrentRegion)
|
||||||
|
{
|
||||||
|
if (oldRegion != null)
|
||||||
|
{
|
||||||
|
Hooks.RegionHooks.OnRegionLeft(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.CurrentRegion != null)
|
||||||
|
{
|
||||||
|
Hooks.RegionHooks.OnRegionEntered(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetConsoleTitle(false);
|
SetConsoleTitle(false);
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@
|
||||||
<Compile Include="Hooks\AccountHooks.cs" />
|
<Compile Include="Hooks\AccountHooks.cs" />
|
||||||
<Compile Include="Hooks\GeneralHooks.cs" />
|
<Compile Include="Hooks\GeneralHooks.cs" />
|
||||||
<Compile Include="Hooks\PlayerHooks.cs" />
|
<Compile Include="Hooks\PlayerHooks.cs" />
|
||||||
|
<Compile Include="Hooks\RegionHooks.cs" />
|
||||||
<Compile Include="ILog.cs" />
|
<Compile Include="ILog.cs" />
|
||||||
<Compile Include="Log.cs" />
|
<Compile Include="Log.cs" />
|
||||||
<Compile Include="SqlLog.cs" />
|
<Compile Include="SqlLog.cs" />
|
||||||
|
|
@ -185,7 +186,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
<VisualStudio>
|
<VisualStudio>
|
||||||
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" />
|
<UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
|
||||||
</VisualStudio>
|
</VisualStudio>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue