New "AlwayaPvp" system. Client controls its own pvp status completely and will refuse all damage attempts by players outside of pvp and if it's not set to pvp. Solution? Block all actions and wait for user to manually enable pvp.

This commit is contained in:
Zidonuke 2011-12-20 04:20:18 -05:00
parent 82fb69f9d4
commit 37692d0365
3 changed files with 104 additions and 28 deletions

View file

@ -253,6 +253,12 @@ namespace TShockAPI
return true;
}
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
var tiles = new NetTile[size, size];
for (int x = 0; x < size; x++)
@ -463,6 +469,12 @@ namespace TShockAPI
}
}
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (TShock.CheckTilePermission(args.Player, tileX, tileY))
{
args.Player.SendTileSquare(tileX, tileY);
@ -491,17 +503,24 @@ namespace TShockAPI
int id = args.Data.ReadByte();
bool pvp = args.Data.ReadBoolean();
long seconds = (long)(DateTime.UtcNow - args.Player.LastPvpChange).TotalSeconds;
if (TShock.Config.PvpThrottle > 0 && seconds < TShock.Config.PvpThrottle)
if (id != args.Player.Index)
{
args.Player.SendMessage(string.Format("You cannot change pvp status for {0} seconds", TShock.Config.PvpThrottle - seconds), 255, 0, 0);
args.Player.SetPvP(id != args.Player.Index || TShock.Config.AlwaysPvP ? true : args.TPlayer.hostile);
return true;
}
else
if (args.TPlayer.hostile != pvp)
{
args.Player.SetPvP(id != args.Player.Index || TShock.Config.AlwaysPvP ? true : pvp);
long seconds = (long)(DateTime.UtcNow - args.Player.LastPvpChange).TotalSeconds;
if (TShock.Config.PvpThrottle > 0 && seconds < TShock.Config.PvpThrottle)
{
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;
NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", args.Player.Index);
return true;
}
@ -528,14 +547,25 @@ namespace TShockAPI
}
}
if (TShock.CheckPlayerCollision((int)(pos.X / 16f), (int)(pos.Y / 16f))) //NoClipping or possible errors
if (!pos.Equals(args.Player.LastNetPosition))
{
args.Player.SendMessage("You got stuck in a solid object! Sent you to the spawn point.", Color.Red);
args.Player.SendTileSquare((int)(pos.X / 16f), (int)(pos.X / 16f));
args.Player.Spawn();
return true;
float distance = Vector2.Distance(new Vector2((pos.X / 16f), (pos.Y / 16f)), new Vector2(Main.spawnTileX, Main.spawnTileY));
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile && distance > 6f)
{
args.Player.SendMessage("PvP is forced! Enable PvP else you can't do anything!", Color.Red);
args.Player.Spawn();
return true;
}
if (TShock.CheckPlayerCollision((int)(pos.X / 16f), (int)(pos.Y / 16f))) //NoClipping or possible errors
{
args.Player.SendMessage("You got stuck in a solid object! Sent you to the spawn point.", Color.Red);
args.Player.SendTileSquare((int)(pos.X / 16f), (int)(pos.X / 16f));
args.Player.Spawn();
return true;
}
}
args.Player.LastNetPosition = pos;
return false;
}
@ -568,6 +598,12 @@ namespace TShockAPI
return true;
}
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.ProjectileNew, "", index);
return true;
}
if (TShock.CheckProjectilePermission(args.Player, index, type))
{
args.Player.LastThreat = DateTime.UtcNow;
@ -603,6 +639,12 @@ namespace TShockAPI
return true;
}
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.ProjectileNew, "", index);
return true;
}
if (TShock.CheckProjectilePermission(args.Player, index, type))
{
args.Player.LastThreat = DateTime.UtcNow;
@ -653,6 +695,12 @@ namespace TShockAPI
if (tileX < 0 || tileX >= Main.maxTilesX || tileY < 0 || tileY >= Main.maxTilesY)
return false;
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
{
args.Player.SendTileSquare(tileX, tileY);
@ -702,6 +750,12 @@ namespace TShockAPI
if (tileX < 0 || tileX >= Main.maxTilesX || tileY < 0 || tileY >= Main.maxTilesY)
return false;
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (Main.tile[tileX, tileY].type != 0x15 && (!TShock.Utils.MaxChests() && Main.tile[tileX, tileY].type != 0)) //Chest
{
args.Player.SendTileSquare(tileX, tileY);
@ -753,6 +807,11 @@ namespace TShockAPI
var x = args.Data.ReadInt32();
var y = args.Data.ReadInt32();
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
return true;
}
if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - x) > 32) || (Math.Abs(args.Player.TileY - y) > 32)))
{
return true;
@ -773,6 +832,12 @@ namespace TShockAPI
return false;
}
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.ChestItem, "", id, slot);
return true;
}
Item item = new Item();
item.netDefaults(type);
if (stacks > item.maxStack || TShock.Itembans.ItemIsBanned(item.name))
@ -841,6 +906,11 @@ namespace TShockAPI
var type = args.Data.ReadInt8();
var time = args.Data.ReadInt16();
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
return true;
}
if (!TShock.Players[id].TPlayer.hostile)
{
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
@ -892,6 +962,13 @@ namespace TShockAPI
args.Player.SendData(PacketTypes.ItemDrop, "", id);
return true;
}
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.ItemDrop, "", id);
return true;
}
return false;
}
@ -931,6 +1008,13 @@ namespace TShockAPI
return true;
}
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.PlayerHp, "", id);
args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
return true;
}
if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - TShock.Players[id].TileX) > 128) || (Math.Abs(args.Player.TileY - TShock.Players[id].TileY) > 128)))
{
args.Player.SendData(PacketTypes.PlayerHp, "", id);
@ -965,6 +1049,12 @@ namespace TShockAPI
return true;
}
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
return true;
}
if (Main.npc[id].townNPC && !args.Player.Group.HasPermission(Permissions.movenpc))
{
args.Player.SendData(PacketTypes.NpcUpdate, "", id);

View file

@ -37,7 +37,7 @@ namespace TShockAPI
public Group Group { get; set; }
public bool ReceivedInfo { get; set; }
public int Index { get; protected set; }
public DateTime LastPvpChange { get; protected set; }
public DateTime LastPvpChange;
public Point[] TempPoints = new Point[2];
public int AwaitingTempPoint { get; set; }
public bool AwaitingName { get; set; }
@ -49,6 +49,7 @@ namespace TShockAPI
public TSPlayer LastWhisper;
public int LoginAttempts { get; set; }
public Vector2 TeleportCoords = new Vector2(-1, -1);
public Vector2 LastNetPosition = Vector2.Zero;
public string UserAccountName { get; set; }
public bool HasBeenSpammedWithBuildMessage;
public bool IsLoggedIn;
@ -307,18 +308,6 @@ namespace TShockAPI
NetMessage.SendData((int)PacketTypes.PlayerDamage, -1, -1, "", Index, ((new Random()).Next(-1, 1)), damage, (float)0);
}
public virtual void SetPvP(bool pvp)
{
if (TPlayer.hostile != pvp)
{
LastPvpChange = DateTime.UtcNow;
TPlayer.hostile = pvp;
All.SendMessage(string.Format("{0} has {1} PvP!", Name, pvp ? "enabled" : "disabled"), Main.teamColor[Team]);
}
//Broadcast anyways to keep players synced
NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", Index);
}
public virtual void SetTeam(int team)
{
Main.player[Index].team = team;

View file

@ -725,10 +725,7 @@ namespace TShockAPI
if (Config.AlwaysPvP)
{
player.SetPvP(true);
player.SendMessage(
"PvP is forced! Enable PvP else you can't deal damage to other people. (People can kill you)",
Color.Red);
player.SendMessage("PvP is forced! Enable PvP else you can't move or do anything!", Color.Red);
}
if (player.Group.HasPermission(Permissions.causeevents) && Config.InfiniteInvasion)
{