private void OnNpcDamaged(GetDataHandlerArgs args) { var npcid = args.Data.ReadInt16(); var damage = args.Data.ReadInt16(); args.Data.ReadSingle(); args.Data.ReadInt8(); var crit = args.Data.ReadBoolean(); manager.InvokeHandler(new NpcDamageEvent() { Crit = crit, Damage = damage, PlayerIndex = args.Player.Index, NpcIndex = npcid }, EventType.NpcTakesDamage); int damageDone = damage - (int)Math.Ceiling(Main.npc[npcid].defense * .5f); damageDone = (crit ? damageDone * 2 : damageDone); if (damageDone >= Main.npc[npcid].life) { manager.InvokeHandler(new NpcKilledEvent() { Crit = crit, Damage = damage, PlayerIndex = args.Player.Index, NpcIndex = npcid }, EventType.NpcIsKilled); } }
private static bool HandleTileKill(GetDataHandlerArgs args) { int x = args.Data.ReadInt32(); int y = args.Data.ReadInt32(); var player = QTools.GetPlayerByID(args.Player.Index); if (player.AwaitingQRName) { player.AwaitingQRName = false; if (QTools.InQuestRegion(x, y) == null) { args.Player.SendMessage("Tile is not in any Quest Region", Color.Yellow); } else { args.Player.SendMessage("Quest Region Name: " + QTools.InQuestRegion(x, y), Color.Yellow); } } if (player.AwaitingHitCoords) { player.TSPlayer.SendMessage("X:" + x + ", Y:" + y); args.Player.SendTileSquare(x, y); player.AwaitingHitCoords = false; return(true); } return(false); }
private static bool HandleNpcEvent(GetDataHandlerArgs args) { if (args.Player == null) return false; var index = args.Player.Index; var npcId = (byte) args.Data.ReadByte(); args.Data.ReadByte(); var damage = args.Data.ReadInt16(); var crit = args.Data.ReadBoolean(); var player = TShock.Players.First(p => p != null && p.IsLoggedIn && p.Index == index); if (player == null) return false; if (Main.npc[npcId].target < 255) { var critical = 1; if (crit) critical = 2; var hitDamage = (damage - Main.npc[npcId].defense/2)*critical; if (hitDamage > Main.npc[npcId].life && Main.npc[npcId].active && Main.npc[npcId].life > 0) { //not a boss kill if (!Main.npc[npcId].boss && !Main.npc[npcId].friendly) { Statistics.database.UpdateKills(player.UserID, KillType.Mob); Statistics.SentDamageCache[player.Index][KillType.Mob] += Main.npc[npcId].life; //Push damage to database on kill Statistics.database.UpdateMobDamageGiven(player.UserID, player.Index); } //a boss kill else { Statistics.database.UpdateKills(player.UserID, KillType.Boss); Statistics.SentDamageCache[player.Index][KillType.Boss] += Main.npc[npcId].life; Statistics.database.UpdateBossDamageGiven(player.UserID, player.Index); } //Push player damage dealt and damage received as well Statistics.database.UpdatePlayerDamageGiven(player.UserID, player.Index); Statistics.database.UpdateDamageReceived(player.UserID, player.Index); Statistics.database.UpdateHighScores(player.UserID); } else { if (!Main.npc[npcId].boss) Statistics.SentDamageCache[player.Index][KillType.Mob] += hitDamage; else Statistics.SentDamageCache[player.Index][KillType.Boss] += hitDamage; } } else return true; return false; }
private static bool HandleLiquidSet(GetDataHandlerArgs args) { int tileX = args.Data.ReadInt16(); int tileY = args.Data.ReadInt16(); if (PlotMarker.BlockModify(args.Player, tileX, tileY)) { args.Player.SendTileSquare(tileX, tileY, 4); return(true); } return(false); }
private static bool HandleLiquidSet(GetDataHandlerArgs args) { int x = args.Data.ReadInt32(); int y = args.Data.ReadInt32(); var player = QTools.GetPlayerByID(args.Player.Index); if (player.AwaitingHitCoords) { player.TSPlayer.SendMessage("X:" + x + ", Y:" + y); args.Player.SendTileSquare(x, y); player.AwaitingHitCoords = false; return(true); } return(false); }
private static bool OnNpcStrike(GetDataHandlerArgs args) { short npcid = args.Data.ReadInt16(); int damage = args.Data.ReadByte(); NPC npc = Main.npc[(int)npcid]; if (npc.life - damage <= 0) { var player = QTools.GetPlayerByID(args.Player.Index); if (player.AwaitingKill && !player.KillNames.Contains(npc.name)) { player.KillNames.Add(npc.name); } } return(false); }
private static bool HandleTile(GetDataHandlerArgs args) { var info = PlayerInfo.GetInfo(args.Player); using (var reader = new BinaryReader(args.Data)) { reader.ReadByte(); int x = reader.ReadInt16(); int y = reader.ReadInt16(); if (info.Status != PlayerInfo.PointStatus.None) { if (x >= 0 && y >= 0 && x < Main.maxTilesX && y < Main.maxTilesY) { switch (info.Status) { case PlayerInfo.PointStatus.Point1: info.X = x; info.Y = y; args.Player.SendInfoMessage("设定点 1 完毕."); break; case PlayerInfo.PointStatus.Point2: info.X2 = x; info.Y2 = y; args.Player.SendInfoMessage("设定点 2 完毕."); break; case PlayerInfo.PointStatus.Delegate: info.OnGetPoint?.Invoke(x, y, args.Player); break; } info.Status = PlayerInfo.PointStatus.None; args.Player.SendTileSquare(x, y, 3); return(true); } } if (PlotMarker.BlockModify(args.Player, x, y)) { args.Player.SendTileSquare(x, y, 3); return(true); } } return(false); }
private static bool HandlePaintWall(GetDataHandlerArgs args) { var x = args.Data.ReadInt16(); var y = args.Data.ReadInt16(); var t = args.Data.ReadInt8(); if (x < 0 || y < 0 || x >= Main.maxTilesX || y >= Main.maxTilesY || t > Main.numTileColors) { return(true); } if (PlotMarker.BlockModify(args.Player, x, y)) { args.Player.SendData(PacketTypes.PaintWall, "", x, y, Main.tile[x, y].wallColor()); return(true); } return(false); }
private static bool HandleSendTileSquare(GetDataHandlerArgs args) { var player = args.Player; var size = args.Data.ReadInt16(); var tileX = args.Data.ReadInt16(); var tileY = args.Data.ReadInt16(); var tiles = new NetTile[size, size]; for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { tiles[x, y] = new NetTile(args.Data); } } for (int x = 0; x < size; x++) { int realx = tileX + x; if (realx < 0 || realx >= Main.maxTilesX) { continue; } for (int y = 0; y < size; y++) { int realy = tileY + y; if (realy < 0 || realy >= Main.maxTilesY) { continue; } if (tiles[x, y].Type == Terraria.ID.TileID.LogicSensor && PlotMarker.BlockModify(args.Player, realx, realy)) { args.Player.SendTileSquare(realx, realy, 1); return(true); } } } return(false); }
private void OnPlayerDamage(GetDataHandlerArgs args) { var id = args.Data.ReadInt8(); args.Data.ReadInt8(); var dmg = args.Data.ReadInt16(); var pvp = args.Data.ReadBoolean(); var crit = args.Data.ReadBoolean(); manager.InvokeHandler(new PlayerDamageEvent() { Crit = crit, Damage = dmg, HurtPlayerIndex = args.Player.Index, DamagingEntityIndex = id, PVP = pvp }, EventType.PlayerTakesDamage); if (pvp) { manager.InvokeHandler(new PlayerDamageEvent() { Crit = crit, Damage = dmg, HurtPlayerIndex = args.Player.Index, DamagingEntityIndex = id, PVP = pvp }, EventType.PlayerDoesDamage); } }
private static bool HandlePlaceObject(GetDataHandlerArgs args) { var x = args.Data.ReadInt16(); var y = args.Data.ReadInt16(); var type = args.Data.ReadInt16(); var style = args.Data.ReadInt16(); if (type < 0 || type >= Main.maxTileSets) { return(true); } if (x < 0 || x >= Main.maxTilesX) { return(true); } if (y < 0 || y >= Main.maxTilesY) { return(true); } var tileData = TileObjectData.GetTileData(type, style); for (int i = x; i < x + tileData.Width; i++) { for (int j = y; j < y + tileData.Height; j++) { if (PlotMarker.BlockModify(args.Player, x, y)) { args.Player.SendTileSquare(i, j, 4); return(true); } } } return(false); }
private static bool HandlePlaceTileEntity(GetDataHandlerArgs args) { var x = args.Data.ReadInt16(); var y = args.Data.ReadInt16(); var type = args.Data.ReadByte(); if (x < 0 || x >= Main.maxTilesX) { return(true); } if (y < 0 || y >= Main.maxTilesY) { return(true); } if (PlotMarker.BlockModify(args.Player, x, y)) { args.Player.SendTileSquare(x, y, 3); return(true); } return(false); }
private static bool HandlePlayerKillMe(GetDataHandlerArgs args) { int index = args.Player.Index; byte PlayerID = (byte)args.Data.ReadByte(); byte hitDirection = (byte)args.Data.ReadByte(); Int16 Damage = (Int16)args.Data.ReadInt16(); bool PVP = args.Data.ReadBoolean(); GunPlayer player = GunTools.GetGunPlayerByID(PlayerID); GunPlayer attacker = player.KillingPlayer; if (player != null && attacker != null) { if (player.CurrentGame != null && player.CurrentGame.Running && player.KillingPlayer != null) { lock (player.CurrentGame.Players) { if (player.CurrentGame.Players.Contains(attacker)) { if (attacker.TSPlayer.TPlayer.inventory[attacker.TSPlayer.TPlayer.selectedItem].name == "Light's Bane") { TShock.Utils.Broadcast(String.Format("{0} stole a level from {1}!", attacker.TSPlayer.Name, player.TSPlayer.Name), Color.Aqua); player.DecreaseLevel(); attacker.IncreaseLevel(); player.TSPlayer.TPlayer.dead = true; } else { attacker.IncreaseLevel(); player.TSPlayer.TPlayer.dead = true; GunTools.SpawnAndGiveItems(player); } } } } else { player.TSPlayer.TPlayer.dead = true; GunTools.SpawnAndGiveItems(player); } } player.KillingPlayer = null; return false; }
private static bool HandlePaintWall(GetDataHandlerArgs args) { var Start = DateTime.Now; var X = args.Data.ReadInt16(); var Y = args.Data.ReadInt16(); var T = args.Data.ReadInt8(); if (!args.Player.Group.HasPermission(EditHouse)) { lock (HousingDistricts.HPlayers) { return House.HandlerAction((house) => { if (HousingDistricts.Timeout(Start)) return false; if (house != null && house.HouseArea.Intersects(new Rectangle(X, Y, 1, 1)) && !HouseTools.WorldMismatch(house)) if (!HTools.OwnsHouse(args.Player.User, house.Name)) { args.Player.SendData(PacketTypes.PaintWall, "", X, Y, Main.tile[X, Y].wallColor()); return true; } return false; }); } } return false; }
//handle BANITEM private static bool HandlePlayerUpdate(GetDataHandlerArgs args) { if (args.Player == null) return false; int index = args.Player.Index; var info = args.Player.GetPlayerInfo(); byte plr = args.Data.ReadInt8(); BitsByte control = args.Data.ReadInt8(); BitsByte pulley = args.Data.ReadInt8(); byte item = args.Data.ReadInt8(); string itemName = args.Player.TPlayer.inventory[item].name; if (control[5] && info.regionStorage.flags.Contains("BANITEM") && info.regionStorage.bannedItems.Contains(itemName)) { if (info.inEventRegion) { control[5] = false; info.Disable(args.Player,"Using a banned item ({0}) in region \"{1}\"".SFormat(itemName, info.regionStorage.region.Name)); args.Player.SendErrorMessage("You cannot use {0} in this region. Your actions are being ignored.", itemName); NetMessage.SendData((int)PacketTypes.PlayerUpdate, -1, args.Player.Index, "", args.Player.Index); return true; } } return false; }
//handle PORTAL, NOPORTAL, BANPROJ private static bool HandleProjectile(GetDataHandlerArgs args) { if (args.Player == null) return false; int index = args.Player.Index; var info = args.Player.GetPlayerInfo(); short ident = args.Data.ReadInt16(); var pos = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); var vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); float knockback = args.Data.ReadSingle(); short dmg = args.Data.ReadInt16(); byte owner = args.Data.ReadInt8(); short type = args.Data.ReadInt16(); BitsByte bits = args.Data.ReadInt8(); bool bypassFlag = info.BypassFlag(args.Player); if (info.regionStorage.flags.Contains("BANPROJ") && info.regionStorage.bannedProjectiles.Contains(type) && !bypassFlag) { args.Player.RemoveProjectile(ident, owner); args.Player.Disable(); args.Player.SendErrorMessage("No permission to use this projectile in this region!"); return true; } if (info.regionStorage.flags.Contains("NOPORTAL") && !bypassFlag) { if (type == ProjectileID.PortalGunGate) { args.Player.RemoveProjectile(ident, owner); return true; } } return false; }
private static bool HandlePlayerKillMe(GetDataHandlerArgs args) { if (args.Player == null) return false; var index = args.Player.Index; args.Data.ReadByte(); args.Data.ReadByte(); args.Data.ReadInt16(); var pvp = args.Data.ReadBoolean(); var player = TShock.Players.First(p => p != null && p.IsLoggedIn && p.Index == index); if (player == null) return false; if (Statistics.PlayerKilling[player] != null) { //Only update killer if the killer is logged in if (Statistics.PlayerKilling[player].IsLoggedIn && pvp) { Statistics.database.UpdateKills(Statistics.PlayerKilling[player].UserID, KillType.Player); Statistics.database.UpdateHighScores(Statistics.PlayerKilling[player].UserID); Statistics.database.UpdatePlayerDamageGiven(Statistics.PlayerKilling[player].UserID, Statistics.PlayerKilling[player].Index); Statistics.database.UpdateDamageReceived(Statistics.PlayerKilling[player].UserID, Statistics.PlayerKilling[player].Index); } Statistics.PlayerKilling[player] = null; } Statistics.database.UpdateDeaths(player.UserID); Statistics.database.UpdatePlayerDamageGiven(player.UserID, player.Index); //update all received damage on death Statistics.database.UpdateDamageReceived(player.UserID, player.Index); Statistics.database.UpdateHighScores(player.UserID); return false; }
private static bool HandlePlayerUpdate(GetDataHandlerArgs args) { // int Index = (int)args.Data.ReadByte(); //TShock player = TShock.Players[args.Player.Index]; var player = TShock.Players[args.Player.Index]; VKPlayer vkplyr = new VKPlayer(player.Index); //args.Player.SendMessage("Hello from HandlePlayerUpdate: " + vkplyr.X, Color.Yellow); if ( vkplyr.X < Votekick.config.WestPosition ) { vkplyr.Connect(Votekick.config.WestServer); } //args.Player.SendMessage("Hello from HandlePlayerUpdate: ", Color.Yellow); return false; }
private static bool HandleSendTileSquare(GetDataHandlerArgs args) { Console.WriteLine("HandleSendTileSquare"); var Start = DateTime.Now; short size = args.Data.ReadInt16(); int tilex = args.Data.ReadInt16(); int tiley = args.Data.ReadInt16(); //args.Player.SendMessage("Hello from HandleSendTileSquare: " + tilex, Color.Yellow); return false; }
private static bool HandleTileKill(GetDataHandlerArgs args) { int x = args.Data.ReadInt32(); int y = args.Data.ReadInt32(); int tilex = Math.Abs(x); int tiley = Math.Abs(y); if (args.Player.AwaitingTemp1) { args.Player.TempArea.X = tilex; args.Player.TempArea.Y = tiley; args.Player.SendMessage("Set Temp Point 1", Color.Yellow); args.Player.SendTileSquare(tilex, tiley); args.Player.AwaitingTemp1 = false; return true; } if (args.Player.AwaitingTemp2) { if (tilex > args.Player.TempArea.X && tiley > args.Player.TempArea.Y) { args.Player.TempArea.Width = tilex - args.Player.TempArea.X; args.Player.TempArea.Height = tiley - args.Player.TempArea.Y; args.Player.SendMessage("Set Temp Point 2", Color.Yellow); args.Player.SendTileSquare(tilex, tiley); args.Player.AwaitingTemp2 = false; } else { args.Player.SendMessage("Point 2 must be below and right of Point 1", Color.Yellow); args.Player.SendMessage("Use /region clear to start again", Color.Yellow); args.Player.SendTileSquare(tilex, tiley); args.Player.AwaitingTemp2 = false; } return true; } if (!args.Player.Group.HasPermission("edithouse")) { lock (HousingDistricts.HPlayers) { foreach (House house in HousingDistricts.Houses) { if (house.HouseArea.Intersects(new Rectangle(tilex, tiley, 1, 1)) && house.WorldID == Main.worldID.ToString()) { if (!HTools.OwnsHouse(args.Player.UserID.ToString(), house.Name)) { args.Player.SendTileSquare(tilex, tiley); return true; } } } } } return false; }
private static bool HandleChest(GetDataHandlerArgs args) { var Start = DateTime.Now; int action = args.Data.ReadByte(); int x = args.Data.ReadInt16(); int y = args.Data.ReadInt16(); int tilex = Math.Abs(x); int tiley = Math.Abs(y); var player = HTools.GetPlayerByID(args.Player.Index); if (player.AwaitingHouseName) { if (HTools.InAreaHouseName(x, y) == null) args.Player.SendMessage("Tile is not in any House", Color.Yellow); else args.Player.SendMessage("House Name: " + HTools.InAreaHouseName(x, y), Color.Yellow); args.Player.SendTileSquare(x, y); player.AwaitingHouseName = false; return true; } if (args.Player.AwaitingTempPoint > 0) { args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].X = x; args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].Y = y; if (args.Player.AwaitingTempPoint == 1) args.Player.SendMessage("Top-left corner of protection area has been set!", Color.Yellow); if (args.Player.AwaitingTempPoint == 2) args.Player.SendMessage("Bottom-right corner of protection area has been set!", Color.Yellow); args.Player.SendTileSquare(x, y); args.Player.AwaitingTempPoint = 0; return true; } if (!args.Player.Group.HasPermission(EditHouse)) { lock (HousingDistricts.HPlayers) { return House.HandlerAction((house) => { if (HousingDistricts.Timeout(Start)) return false; if (HTools.InAreaHouseName(x, y) == null) { if (action == 0 || action == 2) { args.Player.SendErrorMessage("You must place this in your house."); args.Player.SendTileSquare(tilex, tiley, 3); return true; } } if (house != null && house.HouseArea.Intersects(new Rectangle(tilex, tiley, 1, 1)) && !HouseTools.WorldMismatch(house)) { if (!HTools.OwnsHouse(args.Player.User, house.Name)) { args.Player.SendTileSquare(tilex, tiley); return true; } if (HTools.OwnsHouse(args.Player.User, house.Name)) { if (action == 0 || action == 2) { int maxChests = 1000; int iCount = 0; for (int iChest = 0; iChest < maxChests; iChest++) { if (Main.chest[iChest] != null && house.HouseArea.Intersects(new Rectangle(Main.chest[iChest].x, Main.chest[iChest].y, 1, 1))) { iCount++; if (iCount >= HousingDistricts.HConfig.MaxChests) { args.Player.SendErrorMessage("Houses must contain {0} or less.", HousingDistricts.HConfig.MaxChests); args.Player.SendTileSquare(x, y, 3); return true; } } } } } } return false; }); } } return false; }
private static bool HandleTile(GetDataHandlerArgs args) { var Start = DateTime.Now; byte type = args.Data.ReadInt8(); int x = args.Data.ReadInt16(); int y = args.Data.ReadInt16(); //short tiletype = args.Data.ReadInt16(); var player = HTools.GetPlayerByID(args.Player.Index); int tilex = Math.Abs(x); int tiley = Math.Abs(y); if (player.AwaitingHouseName) { if (HTools.InAreaHouseName(x, y) == null) args.Player.SendMessage("Tile is not in any House", Color.Yellow); else args.Player.SendMessage("House Name: " + HTools.InAreaHouseName(x, y), Color.Yellow); args.Player.SendTileSquare(x, y); player.AwaitingHouseName = false; return true; } if (args.Player.AwaitingTempPoint > 0) { args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].X = x; args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].Y = y; if (args.Player.AwaitingTempPoint == 1) args.Player.SendMessage("Top-left corner of protection area has been set!", Color.Yellow); if (args.Player.AwaitingTempPoint == 2) args.Player.SendMessage("Bottom-right corner of protection area has been set!", Color.Yellow); args.Player.SendTileSquare(x, y); args.Player.AwaitingTempPoint = 0; return true; } if (!args.Player.Group.HasPermission(EditHouse)) { lock (HousingDistricts.HPlayers) { return House.HandlerAction((house) => { if (HousingDistricts.Timeout(Start)) return false; if (house != null && house.HouseArea.Intersects(new Rectangle(tilex, tiley, 1, 1)) && !HouseTools.WorldMismatch(house)) if (!HTools.OwnsHouse(args.Player.User, house.Name)) // Changing to User.ID will result in having to check for User != null { args.Player.SendTileSquare(tilex, tiley); return true; } return false; }); } } return false; }
private static bool HandleTeleport(GetDataHandlerArgs args) { if (HousingDistricts.HConfig.AllowRod || args.Player.Group.HasPermission(TPHouse)) return false; var Start = DateTime.Now; var Flags = args.Data.ReadInt8(); var ID = args.Data.ReadInt16(); var X = args.Data.ReadSingle(); var Y = args.Data.ReadSingle(); if ((Flags & 2) != 2 && (Flags & 1) != 1 && !args.Player.Group.HasPermission(TPHouse)) { lock (HousingDistricts.HPlayers) { return House.HandlerAction((house) => { if (HousingDistricts.Timeout(Start)) return false; if (house != null && house.HouseArea.Intersects(new Rectangle((int)(X / 16), (int)(Y / 16), 1, 1)) && !HouseTools.WorldMismatch(house)) if (!HTools.CanVisitHouse(args.Player.User, house)) { args.Player.SendErrorMessage(string.Format("You do not have permission to teleport into house '{0}'.", house.Name)); args.Player.Teleport(args.TPlayer.position.X, args.TPlayer.position.Y); return true; } return false; }); } } return false; }
private static bool HandleSign(GetDataHandlerArgs args) { var Start = DateTime.Now; //byte type = args.Data.ReadInt8(); int x = args.Data.ReadInt16(); int y = args.Data.ReadInt16(); //byte tiletype = args.Data.ReadInt8(); //var player = HTools.GetPlayerByID(args.Player.Index); int tilex = Math.Abs(x); int tiley = Math.Abs(y); if (!args.Player.Group.HasPermission(EditHouse)) { if (HousingDistricts.HConfig.ProtectContents) { lock (HousingDistricts.HPlayers) { var I = HousingDistricts.Houses.Count; for (int i = 0; i < I; i++) { if (HousingDistricts.Timeout(Start)) return false; var house = HousingDistricts.Houses[i]; if (house != null && house.HouseArea.Intersects(new Rectangle(tilex, tiley, 1, 1)) && !HouseTools.WorldMismatch(house)) { if (!HTools.OwnsHouse(args.Player.User, house.Name)) { args.Player.SendErrorMessage("This sign is protected"); return true; } } } } } } return false; }
private static bool HandleSendTileSquare(GetDataHandlerArgs args) { var Start = DateTime.Now; short size = args.Data.ReadInt16(); int tilex = args.Data.ReadInt16(); int tiley = args.Data.ReadInt16(); if (!args.Player.Group.HasPermission(EditHouse)) { lock (HousingDistricts.HPlayers) { return House.HandlerAction((house) => { if (HousingDistricts.Timeout(Start)) return false; if (house != null && house.HouseArea.Intersects(new Rectangle(tilex, tiley, 1, 1)) && !HouseTools.WorldMismatch(house)) if (!HTools.OwnsHouse(args.Player.User, house.Name)) { args.Player.SendTileSquare(tilex, tiley); return true; } return false; }); } } return false; }
private static bool HandleItemDrop(GetDataHandlerArgs args) { int index = args.Player.Index; var id = args.Data.ReadInt16(); var posx = args.Data.ReadSingle(); var posy = args.Data.ReadSingle(); var velx = args.Data.ReadSingle(); var vely = args.Data.ReadSingle(); var stack = args.Data.ReadByte(); var prefix = args.Data.ReadByte(); var type = args.Data.ReadInt16(); GunPlayer ply = GunTools.GetGunPlayerByID(index); if (ply.CurrentGame != null && ply.CurrentGame.Running) { //Console.WriteLine(TShock.Utils.GetItemById(type).name); foreach (string[] arr in ply.CurrentGame.GameLevels.Levels) { foreach (string item in arr) { if (TShock.Utils.GetItemById(type).name == item || ply.CurrentGame.GameLevels.Knife == TShock.Utils.GetItemById(type).name) return true; } } } return false; }
private static bool HandleDropItems(GetDataHandlerArgs args) { var traderPlayer = args.Player; var id = args.Data.ReadInt16(); var pos = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); var vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); var stacks = args.Data.ReadInt16(); var prefix = args.Data.ReadInt8(); var noDelay = args.Data.ReadInt8() == 1; var type = args.Data.ReadInt16(); // player is attempting to crash clients if (type < -48 || type >= Main.maxItemTypes) { args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } if (type == 0) //Item removed, let client do this to prevent item duplication client side (but only if it passed the range check) { if (TShock.CheckRangePermission(args.Player, (int)(Main.item[id].position.X / 16f), (int)(Main.item[id].position.Y / 16f))) { args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } return false; } if (TShock.CheckRangePermission(args.Player, (int)(pos.X / 16f), (int)(pos.Y / 16f))) { args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } if (Main.item[id].active && Main.item[id].netID != type) //stop the client from changing the item type of a drop but only if the client isn't picking up the item { args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } if(( vel.X >= -12 && vel.X <= 12) && vel.Y == -2) { TradePlayer trader = TradeRequest.TradeActive[args.Player.Index]; TradePlayer target = TradeRequest.TradeActive[trader.target]; if (trader.active && !trader.confirm) { TSPlayer targetPlayer = TShock.Players[trader.target]; Item item = new Item(); item.netDefaults(type); item.stack = stacks; item.prefix = prefix; int targetSlots = 0; for (int i = 0; i < 49; i++) { if (targetPlayer.TPlayer.inventory[i].name == "") targetSlots++; } for (int i = 0; i < 8; i++) { if (trader.tItems.ContainsKey(i)) continue; else { trader.time = DateTime.UtcNow; trader.confirmlock = DateTime.UtcNow; trader.tItems.Add(i, item); args.Player.SendInfoMessage("Your item [i/s{0}:{1}] was stored in the Queue.", item.stack, item.type); if (item.stack > 1) targetPlayer.SendInfoMessage("{0} added to Queue [i/s{1}:{2}].", args.Player.Name, item.stack, item.type); else targetPlayer.SendInfoMessage("{0} added to Queue [i/p{1}:{2}].", args.Player.Name, item.prefix, item.type); args.Player.SendData(PacketTypes.ItemDrop, "", id); if (targetSlots < trader.tItems.Count) { target.failure = true; trader.time = DateTime.UtcNow.AddSeconds(-30); target.time = DateTime.UtcNow.AddSeconds(-30); } return true; } } } } return false; }
private static bool HandleMassWireOperation(GetDataHandlerArgs args) { var startX = args.Data.ReadInt16(); var startY = args.Data.ReadInt16(); var endX = args.Data.ReadInt16(); var endY = args.Data.ReadInt16(); args.Data.ReadByte(); // Ignore toolmode var data = PlayerInfo.GetInfo(args.Player); if (data.Status != PlayerInfo.PointStatus.None) { if (startX >= 0 && startY >= 0 && endX >= 0 && endY >= 0 && startX < Main.maxTilesX && startY < Main.maxTilesY && endX < Main.maxTilesX && endY < Main.maxTilesY) { if (startX == endX && startY == endY) { switch (data.Status) { case PlayerInfo.PointStatus.Point1: data.X = startX; data.Y = startY; args.Player.SendInfoMessage("设定点 1 完毕."); break; case PlayerInfo.PointStatus.Point2: data.X2 = startX; data.Y2 = startY; args.Player.SendInfoMessage("设定点 2 完毕."); break; case PlayerInfo.PointStatus.Delegate: data.OnGetPoint?.Invoke(startX, startY, args.Player); break; } } else { switch (data.Status) { case PlayerInfo.PointStatus.Point1: case PlayerInfo.PointStatus.Point2: data.X = startX; data.Y = startY; data.X2 = endX; data.Y2 = endY; args.Player.SendInfoMessage("设定区域完毕."); break; case PlayerInfo.PointStatus.Delegate: data.OnGetPoint?.Invoke(startX, startY, args.Player); break; } } data.Status = PlayerInfo.PointStatus.None; return(true); } } var points = TShock.Utils.GetMassWireOperationRange( new Point(startX, startY), new Point(endX, endY), args.Player.TPlayer.direction == 1 ); return(points.Any(p => PlotMarker.BlockModify(args.Player, p.X, p.Y))); }
private static bool HandleTile(GetDataHandlerArgs args) { Console.WriteLine("HandleTile"); var Start = DateTime.Now; byte type = args.Data.ReadInt8(); int x = args.Data.ReadInt16(); int y = args.Data.ReadInt16(); ushort tiletype = args.Data.ReadUInt16(); int tilex = Math.Abs(x); //Not Used yet int tiley = Math.Abs(y); //Not Used yet //args.Player.SendMessage("Hello from HandleTile: " + x, Color.Yellow); //args.Player.SendTileSquare(x, y); //We might want to send this everytime we return true.... NO That makes the world not editable return false; }
private static bool HandlePlayerKillMe(GetDataHandlerArgs args) { int index = args.Player.Index; //Attacking Player byte PlayerID = (byte)args.Data.ReadByte(); byte hitDirection = (byte)args.Data.ReadByte(); Int16 Damage = (Int16)args.Data.ReadInt16(); bool PVP = args.Data.ReadBoolean(); var player = C3Tools.GetC3PlayerByIndex(PlayerID); if (player.SpawnProtectionEnabled) { NetMessage.SendData(4, -1, PlayerID, player.PlayerName, PlayerID, 0f, 0f, 0f, 0); return true; } if (player.GameType == "ffa") { player.KillingPlayer.FFAScore++; C3Tools.BroadcastMessageToGametype("ffa", player.KillingPlayer.PlayerName + " - Score : " + player.KillingPlayer.FFAScore + " -- kills -- " + player.PlayerName + " - Score : " + player.FFAScore, Color.Black); player.Dead = true; player.TSPlayer.TPlayer.dead = true; } if (player.KillingPlayer != null) { C3Events.Death(player.KillingPlayer, player, player.GameType, PVP); player.KillingPlayer = null; } return false; }
private static bool HandlePlayerDamage(GetDataHandlerArgs args) { if (args.Player == null) return false; var index = args.Player.Index; var playerId = (byte) args.Data.ReadByte(); args.Data.ReadByte(); var damage = args.Data.ReadInt16(); //player being attacked var player = TShock.Players.First(p => p != null && p.IsLoggedIn && p.Index == index); if (player == null) return false; var crit = args.Data.ReadBoolean(); args.Data.ReadByte(); //Attacking player Statistics.PlayerKilling[player] = index != playerId ? args.Player : null; damage = (short) Main.CalculateDamage(damage, player.TPlayer.statDefense); if (Statistics.PlayerKilling[player] != null) { Statistics.SentDamageCache[args.Player.Index][KillType.Player] += damage; Statistics.RecvDamageCache[player.Index] += damage; } else Statistics.RecvDamageCache[player.Index] += (damage*(crit ? 2 : 1)); return false; }
private static bool HandleTile(GetDataHandlerArgs args) { byte type = args.Data.ReadInt8(); int x = args.Data.ReadInt32(); int y = args.Data.ReadInt32(); byte tiletype = args.Data.ReadInt8(); var player = HTools.GetPlayerByID(args.Player.Index); int tilex = Math.Abs(x); int tiley = Math.Abs(y); if (player.AwaitingHouseName) { if (HTools.InAreaHouseName(x, y) == null) { args.Player.SendMessage("Tile is not in any House", Color.Yellow); } else { args.Player.SendMessage("House Name: " + HTools.InAreaHouseName(x, y), Color.Yellow); } args.Player.SendTileSquare(x, y); player.AwaitingHouseName = false; return true; } if (args.Player.AwaitingTempPoint > 0) { args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].X = x; args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].Y = y; if (args.Player.AwaitingTempPoint == 1) { args.Player.SendMessage("Top-left corner of protection area has been set!", Color.Yellow); } if (args.Player.AwaitingTempPoint == 2) { args.Player.SendMessage("Bottom-right corner of protection area has been set!", Color.Yellow); } //if (!args.Player.TempPoints.Any(p => p == Point.Zero)) //{ // args.Player.SendMessage("Top-left and bottom-right points are both set", Color.Yellow); //} args.Player.SendTileSquare(x, y); args.Player.AwaitingTempPoint = 0; return true; } if (!args.Player.Group.HasPermission("edithouse")) { lock (HousingDistricts.HPlayers) { foreach (House house in HousingDistricts.Houses) { if (house.HouseArea.Intersects(new Rectangle(tilex, tiley, 1, 1)) && house.WorldID == Main.worldID.ToString()) { if (!HTools.OwnsHouse(args.Player.UserID.ToString(), house.Name)) { args.Player.SendTileSquare(tilex, tiley); return true; } } } } } return false; }
private static bool HandlePlayerDamage(GetDataHandlerArgs args) { int index = args.Player.Index; byte PlayerID = (byte)args.Data.ReadByte(); byte hitDirection = (byte)args.Data.ReadByte(); Int16 Damage = (Int16)args.Data.ReadInt16(); var player = sTools.GetPlayer(PlayerID); bool PVP = args.Data.ReadBoolean(); byte Crit = (byte)args.Data.ReadByte(); if (index != PlayerID) { player.KillingPlayer = sTools.GetPlayer(index); } else { player.KillingPlayer = null; } return false; }
private static bool HandleNPCEvent(GetDataHandlerArgs args) { int index = args.Player.Index; byte npcID = (byte)args.Data.ReadByte(); byte hitDirection = (byte)args.Data.ReadByte(); Int16 Damage = (Int16)args.Data.ReadInt16(); bool Crit = args.Data.ReadBoolean(); var player = sTools.GetPlayer(index); if (Main.npc[npcID].target < 255) { int critical = 1; if (Crit) critical = 2; int hitDamage = (Damage - Main.npc[npcID].defense / 2) * critical; if (hitDamage > Main.npc[npcID].life && Main.npc[npcID].active && Main.npc[npcID].life > 0) { if (!Main.npc[npcID].boss) player.mobkills++; else player.bosskills++; } } else { return true; } return false; }
//handle BANTILE private static bool HandleTile(GetDataHandlerArgs args) { if (args.Player == null) return false; int index = args.Player.Index; var info = args.Player.GetPlayerInfo(); TShockAPI.GetDataHandlers.EditAction action = (TShockAPI.GetDataHandlers.EditAction)args.Data.ReadInt8(); var tileX = args.Data.ReadInt16(); var tileY = args.Data.ReadInt16(); var editData = args.Data.ReadInt16(); if (info.regionStorage.flags.Contains("BANTILE") && !info.BypassFlag(args.Player)) { if (action == GetDataHandlers.EditAction.PlaceTile && info.regionStorage.bannedTiles.Contains(editData)) { args.Player.SendTileSquare(tileX, tileY, 1); args.Player.SendErrorMessage("You do not have permission to place this tile in this region."); return true; } } return false; }
private static bool HandlePlayerDamage(GetDataHandlerArgs args) { int index = args.Player.Index; //Attacking Player byte PlayerID = (byte)args.Data.ReadByte(); //Damaged Player byte hitDirection = (byte)args.Data.ReadByte(); Int16 Damage = (Int16)args.Data.ReadInt16(); var player = GunTools.GetGunPlayerByID(PlayerID); bool PVP = args.Data.ReadBoolean(); byte Crit = (byte)args.Data.ReadByte(); if (player != null && GunTools.GetGunPlayerByID(index) != null) { if (index != PlayerID) { player.KillingPlayer = GunTools.GetGunPlayerByID(index); } else player.KillingPlayer = null; } return false; }
private static bool HandlePlayerKillMe(GetDataHandlerArgs args) { int index = args.Player.Index; byte PlayerID = (byte)args.Data.ReadByte(); byte hitDirection = (byte)args.Data.ReadByte(); Int16 Damage = (Int16)args.Data.ReadInt16(); bool PVP = args.Data.ReadBoolean(); var player = sTools.GetPlayer(PlayerID); if (player.KillingPlayer != null) { if (PVP == true) { player.KillingPlayer.kills++; player.deaths++; } player.KillingPlayer = null; } else { player.deaths++; } return false; }
private static bool HandleMassWireOperation(GetDataHandlerArgs args) { var Start = DateTime.Now; int x1 = args.Data.ReadInt16(); int y1 = args.Data.ReadInt16(); int x2 = args.Data.ReadInt16(); int y2 = args.Data.ReadInt16(); var player = HTools.GetPlayerByID(args.Player.Index); ; if (args.Player.AwaitingTempPoint > 0) { args.Player.TempPoints[0].X = x1; args.Player.TempPoints[0].Y = y1; args.Player.TempPoints[1].X = x2; args.Player.TempPoints[1].Y = y2; args.Player.SendMessage("Protection corners have been set!", Color.Yellow); args.Player.AwaitingTempPoint = 0; return true; } if (!args.Player.Group.HasPermission(EditHouse)) { Rectangle A = new Rectangle(Math.Min(x1, x2), args.TPlayer.direction != 1 ? y1 : y2, Math.Abs(x2 - x1) + 1, 1); Rectangle B = new Rectangle(args.TPlayer.direction != 1 ? x2 : x1, Math.Min(y1, y2), 1, Math.Abs(y2 - y1) + 1); lock (HousingDistricts.HPlayers) { return House.HandlerAction((house) => { if (HousingDistricts.Timeout(Start)) return false; if (house != null && (house.HouseArea.Intersects(A) || house.HouseArea.Intersects(B)) && !HouseTools.WorldMismatch(house)) if (!HTools.OwnsHouse(args.Player.User, house)) return true; return false; }); } } return false; }
private static bool HandlePlayerDamage(GetDataHandlerArgs args) { int index = args.Player.Index; //Attacking Player byte PlayerID = (byte)args.Data.ReadByte(); //Damaged Player byte hitDirection = (byte)args.Data.ReadByte(); Int16 Damage = (Int16)args.Data.ReadInt16(); var player = C3Tools.GetC3PlayerByIndex(PlayerID); bool PVP = args.Data.ReadBoolean(); bool Crit = args.Data.ReadBoolean(); if (player.SpawnProtectionEnabled) { C3Tools.GetC3PlayerByIndex(index).TSPlayer.SendData(PacketTypes.PlayerUpdate, "", PlayerID); return true; } if (index != PlayerID) { player.KillingPlayer = C3Tools.GetC3PlayerByIndex(index); } else player.KillingPlayer = null; return false; }
private static bool HandleDropItem(GetDataHandlerArgs args) { var player = QTools.GetPlayerByID(args.Player.Index); var reader = new BinaryReader(args.Data); var id = reader.ReadInt16(); var posx = reader.ReadSingle(); var posy = reader.ReadSingle(); var velx = reader.ReadSingle(); var vely = reader.ReadSingle(); var stack = reader.ReadByte(); var itemnamebytes = new byte[args.Data.Length]; reader.Read(itemnamebytes, 0, (int)(args.Data.Length)); reader.Close(); List <byte> finalbytelist = new List <byte>(); foreach (byte by in itemnamebytes) { if (by != 0) { finalbytelist.Add(by); } } var itemname = System.Text.Encoding.ASCII.GetString(finalbytelist.ToArray()); var item = new Item(); item.SetDefaults(itemname); foreach (AwaitingItem aitem in player.AwaitingItems) { if (aitem.AwaitingItemName == itemname) { aitem.AwaitingAmount -= stack; if (aitem.AwaitingAmount < 0) { if (Math.Abs(aitem.AwaitingAmount) > 1) { player.TSPlayer.SendMessage(string.Format("Returning {0} {1}'s", Math.Abs(aitem.AwaitingAmount), itemname)); } else { player.TSPlayer.SendMessage(string.Format("Returning {0} {1}", Math.Abs(aitem.AwaitingAmount), itemname)); } player.TSPlayer.GiveItem(item.type, item.name, item.width, item.width, Math.Abs(aitem.AwaitingAmount)); player.AwaitingItems.Remove(aitem); return(true); } else if (aitem.AwaitingAmount > 0) { if (Math.Abs(aitem.AwaitingAmount) > 1) { player.TSPlayer.SendMessage(string.Format("Drop another {0} {1}'s, to continue", Math.Abs(aitem.AwaitingAmount), itemname)); } else { player.TSPlayer.SendMessage(string.Format("Drop {0} {1}, to continue", Math.Abs(aitem.AwaitingAmount), itemname)); } return(true); } else { if (stack > 1) { player.TSPlayer.SendMessage(string.Format("You dropped {0} {1}'s", stack, itemname)); } else { player.TSPlayer.SendMessage(string.Format("You dropped {0} {1}", stack, itemname)); } player.AwaitingItems.Remove(aitem); return(true); } } } return(false); }
private static bool HandleSendTileSquare(GetDataHandlerArgs args) { short size = args.Data.ReadInt16(); int tilex = args.Data.ReadInt32(); int tiley = args.Data.ReadInt32(); if (!args.Player.Group.HasPermission("edithouse")) { lock (HousingDistricts.HPlayers) { foreach (House house in HousingDistricts.Houses) { if (house.HouseArea.Intersects(new Rectangle(tilex, tiley, 1, 1)) && house.WorldID == Main.worldID.ToString()) { if (!HTools.OwnsHouse(args.Player.UserID.ToString(), house.Name)) { args.Player.SendTileSquare(tilex, tiley); return true; } } } } } return false; }
private static bool OnKillMe(GetDataHandlerArgs args) { return(false); }
private static bool HandleTileKill(GetDataHandlerArgs args) { int x = args.Data.ReadInt32(); int y = args.Data.ReadInt32(); int tilex = Math.Abs(x); int tiley = Math.Abs(y); var player = HTools.GetPlayerByID(args.Player.Index); if (player.AwaitingHouseName) { if (HTools.InAreaHouseName(x, y) == null) { args.Player.SendMessage("Tile is not in any House", Color.Yellow); } else { args.Player.SendMessage("House Name: " + HTools.InAreaHouseName(x, y), Color.Yellow); } args.Player.SendTileSquare(x, y); player.AwaitingHouseName = false; return true; } if (args.Player.AwaitingTempPoint > 0) { args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].X = x; args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].Y = y; args.Player.SendMessage("Set Temp Vector2 " + args.Player.AwaitingTempPoint, Color.Yellow); args.Player.SendTileSquare(x, y); args.Player.AwaitingTempPoint = 0; return true; } if (!args.Player.Group.HasPermission("edithouse")) { lock (HousingDistricts.HPlayers) { foreach (House house in HousingDistricts.Houses) { if (house.HouseArea.Intersects(new Rectangle(tilex, tiley, 1, 1)) && house.WorldID == Main.worldID.ToString()) { if (!HTools.OwnsHouse(args.Player.UserID.ToString(), house.Name)) { args.Player.SendTileSquare(tilex, tiley); return true; } } } } } return false; }
private static bool HandlePlayerKillMe(GetDataHandlerArgs args) { byte id = args.Data.ReadInt8(); if (id != args.Player.Index) { return Tools.HandleGriefer(args.Player, TShock.Config.KillMeAbuseReason); } else { } return false; }