Change the way that forced PvP works

This commit is contained in:
MarioE 2013-11-28 17:23:12 -05:00
parent 8b7e8772da
commit 02820c0172
3 changed files with 30 additions and 50 deletions

View file

@ -2134,37 +2134,17 @@ namespace TShockAPI
return true;
if (id != args.Player.Index)
return true;
string pvpMode = TShock.Config.PvPMode.ToLowerInvariant();
if (pvpMode == "disabled" || pvpMode == "always" || (DateTime.UtcNow - args.Player.LastPvPTeamChange).TotalSeconds < 5)
{
args.Player.SendData(PacketTypes.TogglePvp, "", id);
return true;
}
if (TShock.Config.PvPMode == "disabled")
{
return true;
}
if (args.TPlayer.hostile != pvp)
{
long seconds = (long) (DateTime.UtcNow - args.Player.LastPvpChange).TotalSeconds;
if (seconds > 5)
{
TSPlayer.All.SendMessage(string.Format("{0} has {1} PvP!", args.Player.Name, pvp ? "enabled" : "disabled"),
Main.teamColor[args.Player.Team]);
}
args.Player.LastPvpChange = DateTime.UtcNow;
}
args.TPlayer.hostile = pvp;
if (TShock.Config.PvPMode == "always")
{
if (!pvp)
args.Player.Spawn();
}
NetMessage.SendData((int) PacketTypes.TogglePvp, -1, -1, "", args.Player.Index);
return true;
args.Player.LastPvPTeamChange = DateTime.UtcNow;
return false;
}
private static bool HandlePlayerTeam(GetDataHandlerArgs args)
@ -2175,15 +2155,16 @@ namespace TShockAPI
return true;
if (id != args.Player.Index)
return true;
if ((DateTime.UtcNow - args.Player.LastPvPTeamChange).TotalSeconds < 5)
{
args.Player.SendData(PacketTypes.PlayerTeam, "", id);
return true;
}
args.TPlayer.team = team;
NetMessage.SendData((int)PacketTypes.PlayerTeam, -1, -1, "", args.Player.Index);
return true;
args.Player.LastPvPTeamChange = DateTime.UtcNow;
return false;
}
private static bool HandlePlayerUpdate(GetDataHandlerArgs args)
@ -2244,11 +2225,6 @@ namespace TShockAPI
{
args.Player.SendMessage("You need to rejoin to ensure your trash can is cleared!", Color.Red);
}
else if (TShock.Config.PvPMode == "always" && !args.TPlayer.hostile)
{
args.Player.SendMessage("PvP is forced! Enable PvP or else you can't do anything!",
Color.Red);
}
var lastTileX = args.Player.LastNetPosition.X;
var lastTileY = args.Player.LastNetPosition.Y - 48;
if (!args.Player.Teleport(lastTileX, lastTileY))

View file

@ -130,7 +130,7 @@ namespace TShockAPI
/// <summary>
/// The last time the player changed their team or pvp status.
/// </summary>
public DateTime LastPvpChange;
public DateTime LastPvPTeamChange;
/// <summary>
/// Temp points for use in regions and other plugins.

View file

@ -1183,13 +1183,17 @@ namespace TShockAPI
args.Handled = true;
return;
}
player.LoginMS = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
Utils.ShowFileToUser(player, "motd.txt");
if (Config.PvPMode == "always" && !player.TPlayer.hostile)
string pvpMode = Config.PvPMode.ToLowerInvariant();
if (pvpMode == "always")
{
player.SendMessage("PvP is forced! Enable PvP else you can't do anything!", Color.Red);
player.TPlayer.hostile = true;
player.SendData(PacketTypes.TogglePvp, "", player.Index);
TSPlayer.All.SendData(PacketTypes.TogglePvp, "", player.Index);
}
if (!player.IsLoggedIn)
@ -1739,7 +1743,7 @@ namespace TShockAPI
public static bool CheckIgnores(TSPlayer player)
{
return Config.PvPMode == "always" && !player.TPlayer.hostile || player.IgnoreActionsForInventory != "none" || player.IgnoreActionsForCheating != "none" || player.IgnoreActionsForDisabledArmor != "none" || player.IgnoreActionsForClearingTrashCan || !player.IsLoggedIn && Config.RequireLogin;;
return player.IgnoreActionsForInventory != "none" || player.IgnoreActionsForCheating != "none" || player.IgnoreActionsForDisabledArmor != "none" || player.IgnoreActionsForClearingTrashCan || !player.IsLoggedIn && Config.RequireLogin;;
}
public void OnConfigRead(ConfigFile file)