Merge branch 'general-devel' of https://github.com/Pryaxis/TShock into general-devel

This commit is contained in:
Chris 2020-05-18 15:47:40 +09:30
commit ea53fdf04a
3 changed files with 55 additions and 72 deletions

View file

@ -104,6 +104,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Multiple fields got slightly renamed. * Multiple fields got slightly renamed.
* Modifying ToggleExpert command. Main.expertMode is no longer settable. Using a Main.GameMode int property comparsion. * Modifying ToggleExpert command. Main.expertMode is no longer settable. Using a Main.GameMode int property comparsion.
* GameCulture no longer has static fields to get local language. Using methods to return/compare language. * GameCulture no longer has static fields to get local language. Using methods to return/compare language.
* Added permission "tshock.npc.spawnpets" which restricts pet spawns. This can cause high network load, so it's restricted. (@hakusaro)
* Updated OnTeleport to support new args per protocol changes. (@hakusaro)
## TShock 4.3.26 ## TShock 4.3.26
* Removed the stat tracking system. (@hakusaro) * Removed the stat tracking system. (@hakusaro)

View file

@ -1431,8 +1431,8 @@ namespace TShockAPI
/// Flag is a bit field /// Flag is a bit field
/// if the first bit is set -> 0 = player, 1 = NPC /// if the first bit is set -> 0 = player, 1 = NPC
/// if the second bit is set, ignore this packet /// if the second bit is set, ignore this packet
/// if the third bit is set, style +1 /// if the third bit is set, "get extra info from target" is true
/// if the fourth bit is set, style +1 /// if the fourth bit is set, extra information is valid to read
/// </summary> /// </summary>
public byte Flag { get; set; } public byte Flag { get; set; }
/// <summary> /// <summary>
@ -1443,12 +1443,20 @@ namespace TShockAPI
/// Y Location /// Y Location
/// </summary> /// </summary>
public float Y { get; set; } public float Y { get; set; }
/// <summary>
/// Style
/// </summary>
public byte Style { get; set; }
/// <summary>
/// "Extra info"
/// </summary>
public int ExtraInfo { get; set; }
} }
/// <summary> /// <summary>
/// NPCStrike - Called when an NPC is attacked /// NPCStrike - Called when an NPC is attacked
/// </summary> /// </summary>
public static HandlerList<TeleportEventArgs> Teleport = new HandlerList<TeleportEventArgs>(); public static HandlerList<TeleportEventArgs> Teleport = new HandlerList<TeleportEventArgs>();
private static bool OnTeleport(TSPlayer player, MemoryStream data, Int16 id, byte f, float x, float y) private static bool OnTeleport(TSPlayer player, MemoryStream data, Int16 id, byte f, float x, float y, byte style, int extraInfo)
{ {
if (Teleport == null) if (Teleport == null)
return false; return false;
@ -1460,7 +1468,9 @@ namespace TShockAPI
ID = id, ID = id,
Flag = f, Flag = f,
X = x, X = x,
Y = y Y = y,
Style = style,
ExtraInfo = extraInfo
}; };
Teleport.Invoke(null, args); Teleport.Invoke(null, args);
return args.Handled; return args.Handled;
@ -2821,6 +2831,9 @@ namespace TShockAPI
return false; return false;
} }
private static readonly int[] invasions = { -1, -2, -3, -4, -5, -6, -7, -8, -10, -11 };
private static readonly int[] pets = { -12, -13, -14 };
private static readonly int[] bosses = { 4, 13, 50, 125, 126, 134, 127, 128, 131, 129, 130, 222, 245, 266, 370, 657 };
private static bool HandleSpawnBoss(GetDataHandlerArgs args) private static bool HandleSpawnBoss(GetDataHandlerArgs args)
{ {
if (args.Player.IsBouncerThrottled()) if (args.Player.IsBouncerThrottled())
@ -2828,104 +2841,67 @@ namespace TShockAPI
return true; return true;
} }
var spawnboss = false;
var invasion = false;
var plr = args.Data.ReadInt16(); var plr = args.Data.ReadInt16();
var Type = args.Data.ReadInt16(); var thingType = args.Data.ReadInt16();
NPC npc = new NPC(); NPC npc = new NPC();
npc.SetDefaults(Type); npc.SetDefaults(thingType);
spawnboss = npc.boss;
if (!spawnboss) if (bosses.Contains(thingType) && !args.Player.HasPermission(Permissions.summonboss))
{
switch (Type)
{
case -1:
case -2:
case -3:
case -4:
case -5:
case -6:
case -7:
case -8:
invasion = true;
break;
case 4:
case 13:
case 50:
case 75:
case 125:
case 126:
case 127:
case 128:
case 129:
case 130:
case 131:
case 134:
case 222:
case 245:
case 266:
case 370:
case 398:
case 422:
case 439:
case 493:
case 507:
case 517:
spawnboss = true;
break;
}
}
if (spawnboss && !args.Player.HasPermission(Permissions.summonboss))
{ {
args.Player.SendErrorMessage("You don't have permission to summon a boss."); args.Player.SendErrorMessage("You don't have permission to summon a boss.");
return true; return true;
} }
if (invasion && !args.Player.HasPermission(Permissions.startinvasion))
if (invasions.Contains(thingType) && !args.Player.HasPermission(Permissions.startinvasion))
{ {
args.Player.SendErrorMessage("You don't have permission to start an invasion."); args.Player.SendErrorMessage("You don't have permission to start an invasion.");
return true; return true;
} }
if (!spawnboss && !invasion)
if (pets.Contains(thingType) && !args.Player.HasPermission(Permissions.spawnpets))
{
args.Player.SendErrorMessage("You don't have permission to spawn pets.");
return true; return true;
}
if (plr != args.Player.Index) if (plr != args.Player.Index)
return true; return true;
string boss; string thing;
switch (Type) switch (thingType)
{ {
case -8: case -8:
boss = "a Moon Lord"; thing = "a Moon Lord";
break; break;
case -7: case -7:
boss = "a Martian invasion"; thing = "a Martian invasion";
break; break;
case -6: case -6:
boss = "an eclipse"; thing = "an eclipse";
break; break;
case -5: case -5:
boss = "a frost moon"; thing = "a frost moon";
break; break;
case -4: case -4:
boss = "a pumpkin moon"; thing = "a pumpkin moon";
break; break;
case -3: case -3:
boss = "the Pirates"; thing = "the Pirates";
break; break;
case -2: case -2:
boss = "the Snow Legion"; thing = "the Snow Legion";
break; break;
case -1: case -1:
boss = "a Goblin Invasion"; thing = "a Goblin Invasion";
break; break;
default: default:
boss = String.Format("the {0}", npc.FullName); thing = String.Format("the {0}", npc.FullName);
break; break;
} }
if (TShock.Config.AnonymousBossInvasions) if (TShock.Config.AnonymousBossInvasions)
TShock.Utils.SendLogs(string.Format("{0} summoned {1}!", args.Player.Name, boss), Color.PaleVioletRed, args.Player); TShock.Utils.SendLogs(string.Format("{0} summoned {1}!", args.Player.Name, thing), Color.PaleVioletRed, args.Player);
else else
TShock.Utils.Broadcast(String.Format("{0} summoned {1}!", args.Player.Name, boss), 175, 75, 255); TShock.Utils.Broadcast(String.Format("{0} summoned {1}!", args.Player.Name, thing), 175, 75, 255);
return false; return false;
} }
@ -3023,13 +2999,12 @@ namespace TShockAPI
short id = args.Data.ReadInt16(); short id = args.Data.ReadInt16();
var x = args.Data.ReadSingle(); var x = args.Data.ReadSingle();
var y = args.Data.ReadSingle(); var y = args.Data.ReadSingle();
byte style = args.Data.ReadInt8();
if (OnTeleport(args.Player, args.Data, id, flag, x, y))
return true;
int type = 0; int type = 0;
byte style = 0;
bool isNPC = type == 1; bool isNPC = type == 1;
int extraInfo = -1;
bool getPositionFromTarget = false;
if (flag[0]) if (flag[0])
{ {
@ -3041,13 +3016,16 @@ namespace TShockAPI
} }
if (flag[2]) if (flag[2])
{ {
style++; getPositionFromTarget = true;
} }
if (flag[3]) if (flag[3])
{ {
style += 2; extraInfo = args.Data.ReadInt32();
} }
if (OnTeleport(args.Player, args.Data, id, flag, x, y, style, extraInfo))
return true;
//Rod of Discord teleport (usually (may be used by modded clients to teleport)) //Rod of Discord teleport (usually (may be used by modded clients to teleport))
if (type == 0 && !args.Player.HasPermission(Permissions.rod)) if (type == 0 && !args.Player.HasPermission(Permissions.rod))
{ {

View file

@ -189,7 +189,7 @@ namespace TShockAPI
[Description("User can edit the spawnrate.")] [Description("User can edit the spawnrate.")]
public static readonly string spawnrate = "tshock.npc.spawnrate"; public static readonly string spawnrate = "tshock.npc.spawnrate";
[Description("User can start an invasion.")] [Description("User can start an invasion. Warning: high network use. Easy to abuse.")]
public static readonly string invade = "tshock.npc.invade"; public static readonly string invade = "tshock.npc.invade";
[Description("User can hurt town NPCs.")] [Description("User can hurt town NPCs.")]
@ -198,6 +198,9 @@ namespace TShockAPI
[Description("User can spawn bosses.")] [Description("User can spawn bosses.")]
public static readonly string spawnboss = "tshock.npc.spawnboss"; public static readonly string spawnboss = "tshock.npc.spawnboss";
[Description("User can spawn pets. Warning: high network use. Easy to abuse.")]
public static readonly string spawnpets = "tshock.npc.spawnpets";
[Description("User can rename NPCs.")] [Description("User can rename NPCs.")]
public static readonly string renamenpc = "tshock.npc.rename"; public static readonly string renamenpc = "tshock.npc.rename";