public PlayerData GetPlayerData(TSPlayer player, int acctid) { PlayerData playerData = new PlayerData(player); try { using (var reader = database.QueryReader("SELECT * FROM tsCharacter WHERE Account=@0", acctid)) { if (reader.Read()) { playerData.exists = true; playerData.health = reader.Get<int>("Health"); playerData.maxHealth = reader.Get<int>("MaxHealth"); playerData.mana = reader.Get<int>("Mana"); playerData.maxMana = reader.Get<int>("MaxMana"); playerData.inventory = NetItem.Parse(reader.Get<string>("Inventory")); playerData.spawnX = reader.Get<int>("spawnX"); playerData.spawnY = reader.Get<int>("spawnY"); return playerData; } } } catch (Exception ex) { Log.Error(ex.ToString()); } return playerData; }
public bool InsertPlayerData(TSPlayer player, int acctid) { PlayerData playerData = player.PlayerData; if (!GetPlayerData(player, acctid).exists) { try { database.Query("INSERT INTO Inventory (Account, MaxHealth, MaxMana, Inventory) VALUES (@0, @1, @2, @3);", acctid, playerData.maxHealth, playerData.maxMana, NetItem.ToString(playerData.inventory)); return true; } catch (Exception ex) { Log.Error(ex.ToString()); } } else { try { database.Query("UPDATE Inventory SET MaxHealth = @0, MaxMana = @1, Inventory = @2 WHERE Account = @3;", playerData.maxHealth, playerData.maxMana, NetItem.ToString(playerData.inventory), acctid); return true; } catch (Exception ex) { Log.Error(ex.ToString()); } } return false; }
public static void OnReloadEvent(TSPlayer ply) { if(ReloadEvent == null) return; ReloadEvent(new ReloadEventArgs(ply)); }
public bool InsertPlayerData(TSPlayer player) { PlayerData playerData = player.PlayerData; if (!player.IsLoggedIn) return false; if (!GetPlayerData(player, player.UserID).exists) { try { database.Query("INSERT INTO Inventory (Account, MaxHealth, Inventory) VALUES (@0, @1, @2);", player.UserID, playerData.maxHealth, NetItem.ToString(playerData.inventory)); return true; } catch (Exception ex) { Log.Error(ex.ToString()); } } else { try { database.Query("UPDATE Inventory SET MaxHealth = @0, Inventory = @1 WHERE Account = @2;", playerData.maxHealth, NetItem.ToString(playerData.inventory), player.UserID); return true; } catch (Exception ex) { Log.Error(ex.ToString()); } } return false; }
public static void OnRegionLeft(TSPlayer player, Region region) { if (RegionLeft == null) { return; } RegionLeft(new RegionLeftEventArgs(player, region)); }
public static void OnRegionEntered(TSPlayer player, Region region) { if (RegionEntered == null) { return; } RegionEntered(new RegionEnteredEventArgs(player, region)); }
public static void OnPlayerLogin(TSPlayer ply) { if(PlayerLogin == null) { return; } PlayerLoginEventArgs args = new PlayerLoginEventArgs(ply); PlayerLogin(args); }
public PlayerData GetPlayerData(TSPlayer player, int acctid) { PlayerData playerData = new PlayerData(player); try { using (var reader = database.QueryReader("SELECT * FROM tsCharacter WHERE Account=@0", acctid)) { if (reader.Read()) { playerData.exists = true; playerData.health = reader.Get<int>("Health"); playerData.maxHealth = reader.Get<int>("MaxHealth"); playerData.mana = reader.Get<int>("Mana"); playerData.maxMana = reader.Get<int>("MaxMana"); List<NetItem> inventory = reader.Get<string>("Inventory").Split('~').Select(NetItem.Parse).ToList(); if (inventory.Count < NetItem.MaxInventory) { //TODO: unhardcode this - stop using magic numbers and use NetItem numbers //Set new armour slots empty inventory.InsertRange(67, new NetItem[2]); //Set new vanity slots empty inventory.InsertRange(77, new NetItem[2]); //Set new dye slots empty inventory.InsertRange(87, new NetItem[2]); //Set the rest of the new slots empty inventory.AddRange(new NetItem[NetItem.MaxInventory - inventory.Count]); } playerData.inventory = inventory.ToArray(); playerData.extraSlot = reader.Get<int>("extraSlot"); playerData.spawnX = reader.Get<int>("spawnX"); playerData.spawnY = reader.Get<int>("spawnY"); playerData.skinVariant = reader.Get<int>("skinVariant"); playerData.hair = reader.Get<int?>("hair"); playerData.hairDye = (byte)reader.Get<int>("hairDye"); playerData.hairColor = TShock.Utils.DecodeColor(reader.Get<int?>("hairColor")); playerData.pantsColor = TShock.Utils.DecodeColor(reader.Get<int?>("pantsColor")); playerData.shirtColor = TShock.Utils.DecodeColor(reader.Get<int?>("shirtColor")); playerData.underShirtColor = TShock.Utils.DecodeColor(reader.Get<int?>("underShirtColor")); playerData.shoeColor = TShock.Utils.DecodeColor(reader.Get<int?>("shoeColor")); playerData.hideVisuals = TShock.Utils.DecodeBoolArray(reader.Get<int?>("hideVisuals")); playerData.skinColor = TShock.Utils.DecodeColor(reader.Get<int?>("skinColor")); playerData.eyeColor = TShock.Utils.DecodeColor(reader.Get<int?>("eyeColor")); playerData.questsCompleted = reader.Get<int>("questsCompleted"); return playerData; } } } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } return playerData; }
public static bool OnPlayerCommand(TSPlayer player, string cmdName, string cmdText, List<string> args) { if (PlayerCommand == null) { return false; } PlayerCommandEventArgs playerCommandEventArgs = new PlayerCommandEventArgs() { Player = player, CommandName = cmdName, CommandText = cmdText, Parameters = args }; PlayerCommand(playerCommandEventArgs); return playerCommandEventArgs.Handled; }
public bool CanBuild(int x, int y, TSPlayer ply) { if (!ply.Group.HasPermission(Permissions.canbuild)) { return false; } Region top = null; for (int i = 0; i < Regions.Count; i++) { if (Regions[i].InArea(x,y) ) { if (top == null) top = Regions[i]; else { if (Regions[i].Z > top.Z) top = Regions[i]; } } } return top == null || top.HasPermissionToBuildInRegion(ply); }
//End commands ecexute voids //Presure Plate trigger void void OnPlayerTriggerPressurePlate(TriggerPressurePlateEventArgs <Player> args) { if (!pressureTriggerEnable) { return; } else if (!TShock.Players[args.Object.whoAmI].HasPermission("terrajump.usepad")) { return; } //TShock.Log.ConsoleInfo("[PlTPP]Starting procedure"); bool pds = false; TSPlayer ow = TShock.Players[args.Object.whoAmI]; Tile pressurePlate = Main.tile[args.TileX, args.TileY]; Tile underBlock = Main.tile[args.TileX, args.TileY + 1]; Tile upBlock = Main.tile[args.TileX, args.TileY - 1]; if (underBlock.type == Terraria.ID.TileID.SlimeBlock) { //TShock.Log.ConsoleInfo("[PlTPP]O on 'Under' this slime block are!"); bool ulb = false; bool urb = false; Tile underLeftBlock = Main.tile[args.TileX - 1, args.TileY + 1]; Tile underRightBlock = Main.tile[args.TileX + 1, args.TileY + 1]; if (underLeftBlock.type == Terraria.ID.TileID.SlimeBlock) { //TShock.Log.ConsoleInfo("[PlTPP]Ok on left!"); ulb = true; } if (underRightBlock.type == Terraria.ID.TileID.SlimeBlock) { //TShock.Log.ConsoleInfo("[PlTPP]Ok on right!"); urb = true; } if (ulb && urb) { pds = true; } } else if (upBlock.type == Terraria.ID.TileID.SlimeBlock) { //TShock.Log.ConsoleInfo("[PlTPP]O on 'Up' this slime block are!"); bool ulb = false; bool urb = false; Tile upLeftBlock = Main.tile[args.TileX - 1, args.TileY - 1]; Tile upRightBlock = Main.tile[args.TileX + 1, args.TileY - 1]; if (upLeftBlock.type == Terraria.ID.TileID.SlimeBlock) { //TShock.Log.ConsoleInfo("[PlTPP]Ok on left!"); ulb = true; } if (upRightBlock.type == Terraria.ID.TileID.SlimeBlock) { //TShock.Log.ConsoleInfo("[PlTPP]Ok on right!"); urb = true; } if (ulb && urb) { pds = true; } } else { //TShock.Log.ConsoleInfo("[PlTPP]Can't find any SlimeBlocks! Stoping"); return; } if (pds) { ow.TPlayer.velocity.Y = ow.TPlayer.velocity.Y - height; TSPlayer.All.SendData(PacketTypes.PlayerUpdate, "", ow.Index); //TShock.Log.ConsoleInfo("[PlTPP]Wooh! Procedure succesfull finish!"); ow.SendInfoMessage("Jump!"); } }
/// <summary> /// Show the top of players /// </summary> /// <param name="player">Tsplayer player</param> public void Top(TSPlayer player, bool rc = true) { string playername = string.Empty; int playingtime = 0; int count = 0; double rcoins = 0; var user = TShock.Users.GetUserByName(player.Name); try { if (rc == true) { using (var reader = database.QueryReader("SELECT * FROM Users ORDER BY RCoins DESC LIMIT 3")) while (reader.Read()) { count++; playername = reader.Get<string>("Username"); playingtime = reader.Get<int>("PlayingTime"); rcoins = reader.Get<double>("RCoins"); if (count == 1) player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightPink); if (count == 2) player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightGreen); if (count == 3) player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightBlue); } } else { using (var reader = database.QueryReader("SELECT * FROM Users ORDER BY PlayingTime DESC LIMIT 3")) while (reader.Read()) { count++; playername = reader.Get<string>("Username"); playingtime = reader.Get<int>("PlayingTime"); rcoins = reader.Get<double>("RCoins"); if (count == 1) player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightPink); if (count == 2) player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightGreen); if (count == 3) player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightBlue); } } } catch (Exception ex) { throw new UserManagerException("Top SQL returned an error", ex); } player.SendMessage("You have " + Math.Round(user.RCoins, 2) + " Rcoins. Total played time is " + user.PlayingTime + " minutes", Color.Yellow); }
public bool InsertPlayerData(TSPlayer player) { PlayerData playerData = player.PlayerData; if (!player.IsLoggedIn) return false; if (!GetPlayerData(player, player.UserID).exists) { try { database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY) VALUES (@0, @1, @2, @3, @4, @5, @6, @7);", player.UserID, playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.TPlayer.SpawnX, player.TPlayer.SpawnY); return true; } catch (Exception ex) { Log.Error(ex.ToString()); } } else { try { database.Query("UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7 WHERE Account = @5;", playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.UserID, player.TPlayer.SpawnX, player.TPlayer.SpawnY); return true; } catch (Exception ex) { Log.Error(ex.ToString()); } } return false; }
private static void ApplyInventory(TSPlayer player, IReadOnlyList <NetItem> inventory) { int index; var ssc = Main.ServerSideCharacter; if (!ssc) { Main.ServerSideCharacter = true; NetMessage.SendData((int)PacketTypes.WorldInfo, player.Index, -1, NetworkText.Empty); } for (var i = 0; i < NetItem.MaxInventory; i++) { if (i < NetItem.InventoryIndex.Item2) { player.TPlayer.inventory[i].netDefaults(inventory[i].NetId); if (player.TPlayer.inventory[i].netID != 0) { player.TPlayer.inventory[i].prefix = inventory[i].PrefixId; player.TPlayer.inventory[i].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.inventory[i].Name), player.Index, i, player.TPlayer.inventory[i].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.inventory[i].Name), player.Index, i, player.TPlayer.inventory[i].prefix); } else if (i < NetItem.ArmorIndex.Item2) { index = i - NetItem.ArmorIndex.Item1; player.TPlayer.armor[index].netDefaults(inventory[i].NetId); if (player.TPlayer.armor[index].netID != 0) { player.TPlayer.armor[index].prefix = inventory[i].PrefixId; player.TPlayer.armor[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.armor[index].Name), player.Index, i, player.TPlayer.armor[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.armor[index].Name), player.Index, i, player.TPlayer.armor[index].prefix); } else if (i < NetItem.DyeIndex.Item2) { index = i - NetItem.DyeIndex.Item1; player.TPlayer.dye[index].netDefaults(inventory[i].NetId); if (player.TPlayer.dye[index].netID != 0) { player.TPlayer.dye[index].prefix = inventory[i].PrefixId; player.TPlayer.dye[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.dye[index].Name), player.Index, i, player.TPlayer.dye[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.dye[index].Name), player.Index, i, player.TPlayer.dye[index].prefix); } else if (i < NetItem.MiscEquipIndex.Item2) { index = i - NetItem.MiscEquipIndex.Item1; player.TPlayer.miscEquips[index].netDefaults(inventory[i].NetId); if (player.TPlayer.miscEquips[index].netID != 0) { player.TPlayer.miscEquips[index].prefix = inventory[i].PrefixId; player.TPlayer.miscEquips[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.miscEquips[index].Name), player.Index, i, player.TPlayer.miscEquips[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.miscEquips[index].Name), player.Index, i, player.TPlayer.miscEquips[index].prefix); } else if (i < NetItem.MiscDyeIndex.Item2) { index = i - NetItem.MiscDyeIndex.Item1; player.TPlayer.miscDyes[index].netDefaults(inventory[i].NetId); if (player.TPlayer.miscDyes[index].netID != 0) { player.TPlayer.miscDyes[index].prefix = inventory[i].PrefixId; player.TPlayer.miscDyes[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.miscDyes[index].Name), player.Index, i, player.TPlayer.miscDyes[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.miscDyes[index].Name), player.Index, i, player.TPlayer.miscDyes[index].prefix); } else if (i < NetItem.PiggyIndex.Item2) { index = i - NetItem.PiggyIndex.Item1; player.TPlayer.bank.item[index].netDefaults(inventory[i].NetId); if (player.TPlayer.bank.item[index].netID != 0) { player.TPlayer.bank.item[index].prefix = inventory[i].PrefixId; player.TPlayer.bank.item[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.bank.item[index].Name), player.Index, i, player.TPlayer.bank.item[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.bank.item[index].Name), player.Index, i, player.TPlayer.bank.item[index].prefix); } else if (i < NetItem.SafeIndex.Item2) { index = i - NetItem.SafeIndex.Item1; player.TPlayer.bank2.item[index].netDefaults(inventory[i].NetId); if (player.TPlayer.bank2.item[index].netID != 0) { player.TPlayer.bank2.item[index].prefix = inventory[i].PrefixId; player.TPlayer.bank2.item[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.bank2.item[index].Name), player.Index, i, player.TPlayer.bank2.item[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.bank2.item[index].Name), player.Index, i, player.TPlayer.bank2.item[index].prefix); } else if (i < NetItem.TrashIndex.Item2) { player.TPlayer.trashItem.netDefaults(inventory[i].NetId); if (player.TPlayer.trashItem.netID != 0) { player.TPlayer.trashItem.prefix = inventory[i].PrefixId; player.TPlayer.trashItem.stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.trashItem.Name), player.Index, i, player.TPlayer.trashItem.prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.trashItem.Name), player.Index, i, player.TPlayer.trashItem.prefix); } else if (i < NetItem.ForgeIndex.Item2) { index = i - NetItem.ForgeIndex.Item1; player.TPlayer.bank3.item[index].netDefaults(inventory[i].NetId); if (player.TPlayer.bank3.item[index].netID != 0) { player.TPlayer.bank3.item[index].prefix = inventory[i].PrefixId; player.TPlayer.bank3.item[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.bank3.item[index].Name), player.Index, i, player.TPlayer.bank3.item[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.bank3.item[index].Name), player.Index, i, player.TPlayer.bank3.item[index].prefix); } } if (!ssc) { Main.ServerSideCharacter = false; NetMessage.SendData((int)PacketTypes.WorldInfo, player.Index, -1, NetworkText.Empty); } }
public RegionLeftEventArgs(TSPlayer ply, Region region) { Player = ply; Region = region; }
public static DPoint ToLocation(this TSPlayer player) { return(new DPoint((int)player.X, (int)player.Y)); }
/// <summary> /// Inserts player data to the tsCharacter database table /// </summary> /// <param name="player">player to take data from</param> /// <returns>true if inserted successfully</returns> public bool InsertPlayerData(TSPlayer player) { PlayerData playerData = player.PlayerData; if (!player.IsLoggedIn) return false; if (!GetPlayerData(player, player.User.ID).exists) { try { database.Query( "INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY, hair, hairDye, hairColor, pantsColor, shirtColor, underShirtColor, shoeColor, hideVisuals, skinColor, eyeColor, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18);", player.User.ID, playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, String.Join("~", playerData.inventory), player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor),TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBoolArray(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor),TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished); return true; } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } } else { try { database.Query( "UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7, hair = @8, hairDye = @9, hairColor = @10, pantsColor = @11, shirtColor = @12, underShirtColor = @13, shoeColor = @14, hideVisuals = @15, skinColor = @16, eyeColor = @17, questsCompleted = @18 WHERE Account = @5;", playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, String.Join("~", playerData.inventory), player.User.ID, player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor), TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBoolArray(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor), TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished); return true; } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } } return false; }
/// <summary> /// Uses x, y as the top left origin and size as width, height. /// </summary> public static void SendTileSquareEx(this TSPlayer player, int x, int y, int size = 10) { player.SendData(PacketTypes.TileSendSquare, string.Empty, size, x, y); }
/// <summary> /// Uses x, y as the top left origin and size as width, height. /// </summary> public static void SendTileSquareEx(this TSPlayer player, DPoint location, int size = 10) { TShockEx.SendTileSquareEx(player, location.X, location.Y, size); }
public static void SendTileSquare(this TSPlayer player, DPoint location, int size = 10) { player.SendTileSquare(location.X, location.Y, size); }
public static bool MatchUserAccountNameByPlayerName(string playerName, out string exactName, TSPlayer messagesReceiver = null) { exactName = null; TShockAPI.DB.User tsUser = TShock.Users.GetUserByName(playerName); if (tsUser == null) { TSPlayer player; if (!TShockEx.MatchPlayerByName(playerName, out player, messagesReceiver)) { return(false); } exactName = player.User.Name; } else { exactName = tsUser.Name; } return(true); }
async void BankTransferCompleted(object sender, BankTransferEventArgs e) { // Null check the instance - Thanks Wolfje if (SEconomyPlugin.Instance == null) { return; } // The world account does not have a rank if (e.ReceiverAccount == null || !e.ReceiverAccount.IsAccountEnabled || e.ReceiverAccount.IsSystemAccount || SEconomyPlugin.Instance.WorldAccount == null) { return; } // Stop chain transfers if (e.TransactionMessage.StartsWith("AutoRank")) { return; } TSPlayer ply = TShock.Players.FirstOrDefault(p => p != null && p.Active && p.IsLoggedIn && p.User.Name == e.ReceiverAccount.UserAccountName); if (ply == null) { return; } var rank = ply.GetRank(); if (rank != null) { var ranks = rank.FindNextRanks(e.ReceiverAccount.Balance); if (ranks != null && ranks.Count > 0) { //Money cost = 0L; //foreach (Rank rk in ranks) //{ // cost += rk.Cost(); //} //Money balance = e.ReceiverAccount.Balance; //var task = await e.ReceiverAccount.TransferToAsync(SEconomyPlugin.Instance.WorldAccount, cost, // BankAccountTransferOptions.SuppressDefaultAnnounceMessages, "", // String.Format("{0} paid {1} to rank up with AutoRank.", ply.Name, cost.ToString())); //if (!task.TransferSucceeded) //{ // if (task.Exception != null) // { // Log.ConsoleError("SEconomy Exception: {0}\nCheck logs for details.", task.Exception.Message); // Log.Error(task.Exception.ToString()); // } // // Returning the money; This transaction may fail, but I see no other way. // await SEconomyPlugin.Instance.WorldAccount.TransferToAsync(e.ReceiverAccount, // balance - e.ReceiverAccount.Balance, BankAccountTransferOptions.SuppressDefaultAnnounceMessages, // "", ""); // ply.SendErrorMessage( // "Your transaction could not be completed. Start a new transaction to retry."); //} //else await ply.RankUpAsync(ranks); //Task.Factory.StartNew(await args.ReceiverAccount.TransferToAsync(SEconomyPlugin.Instance.WorldAccount, cost, // BankAccountTransferOptions.None, String.Empty, // String.Format("{0} paid {1} to rank up with AutoRank.", ply.Name, // cost.ToString())) }); .ContinueWith((task) => // { // if (!task.Result.TransferSucceeded) // { // ply.SendErrorMessage( // "Your transaction could not be completed. Start a new transaction to retry."); // return; // } // ply.RankUpAsync(ranks); // }); } } }
public bool NewPlayer(TSPlayer player) { string[] inv, bank1, bank2, armor; inv = new string[49]; bank1 = new string[21]; bank2 = new string[21]; armor = new string[12]; for (int i = 0; i < 48; i++) { inv[i] = player.TPlayer.inventory[i].name + ":" + player.TPlayer.inventory[i].stack; } for (int k = 0; k < 20; k++) { bank1[k] = player.TPlayer.bank[k].name + ":" + player.TPlayer.bank[k].stack; bank2[k] = player.TPlayer.bank2[k].name + ":" + player.TPlayer.bank2[k].stack; } if ("Copper Shortsword:1" == inv[0] && "Copper Pickaxe:1" == inv[1] && "Copper Axe:1" == inv[2]) { } else { return false; } if ("Carrot:1" == inv[3]) { for (int i = 4; i < 48; i++) { if (":0" != inv[i]) { return false; } } } else { for (int i = 3; i < 48; i++) { if (":0" != inv[i]) { return false; } } } for (int i = 0; i < 20; i++) { bank1[i] = player.TPlayer.bank[i].name + ":" + player.TPlayer.bank[i].stack; bank2[i] = player.TPlayer.bank2[i].name + ":" + player.TPlayer.bank2[i].stack; if (":0" != bank1[i] || ":0" != bank2[i]) { return false; } } for (int i = 0; i < 11; i++) { armor[i] = player.TPlayer.armor[i].name; if ("" != armor[i]) { return false; } } return true; }
public static DPoint ToTileLocation(this TSPlayer player) { return(new DPoint(player.TileX, player.TileY)); }
public bool UserExist(TSPlayer player) { try { QueryResult result; result = database.QueryReader("SELECT * FROM Inventory WHERE LOWER (Username) = @0", player.Name.ToLower()); using (var reader = result) { if (reader.Read()) { return true; } } return false; } catch { return false; } }
public static bool MatchUserByPlayerName(string playerName, out TShockAPI.DB.User user, TSPlayer messagesReceiver = null) { user = null; TShockAPI.DB.User tsUser = TShock.Users.GetUserByName(playerName); if (tsUser == null) { TSPlayer player; if (!TShockEx.MatchPlayerByName(playerName, out player, messagesReceiver)) { return(false); } user = TShock.Users.GetUserByID(player.User.ID); } else { user = tsUser; } return(true); }
/// <summary> /// Inserts player data to the tsCharacter database table /// </summary> /// <param name="player">player to take data from</param> /// <returns>true if inserted successfully</returns> public bool InsertPlayerData(TSPlayer player) { PlayerData playerData = player.PlayerData; if (!player.IsLoggedIn) return false; if ((player.tempGroup != null && player.tempGroup.HasPermission(Permissions.bypassssc)) || player.Group.HasPermission(Permissions.bypassssc)) { TShock.Log.ConsoleInfo("Skipping SSC Backup for " + player.User.Name); // Debug code return true; } if (!GetPlayerData(player, player.User.ID).exists) { try { database.Query( "INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, extraSlot, spawnX, spawnY, skinVariant, hair, hairDye, hairColor, pantsColor, shirtColor, underShirtColor, shoeColor, hideVisuals, skinColor, eyeColor, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20);", player.User.ID, playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, String.Join("~", playerData.inventory), playerData.extraSlot, player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.skinVariant, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor),TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBoolArray(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor),TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished); return true; } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } } else { try { database.Query( "UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7, hair = @8, hairDye = @9, hairColor = @10, pantsColor = @11, shirtColor = @12, underShirtColor = @13, shoeColor = @14, hideVisuals = @15, skinColor = @16, eyeColor = @17, questsCompleted = @18, skinVariant = @19, extraSlot = @20 WHERE Account = @5;", playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, String.Join("~", playerData.inventory), player.User.ID, player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor), TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBoolArray(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor), TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished, player.TPlayer.skinVariant, player.TPlayer.extraAccessory ? 1 : 0); return true; } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } } return false; }
private void KeyChange(CommandArgs args) { TSPlayer ply = args.Player; // SSC check to alert users if (!Main.ServerSideCharacter) { ply.SendWarningMessage("[Warning] This plugin will not work properly with ServerSideCharacters disabled."); } if (args.Parameters.Count < 1) { // Plugin Info var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; ply.SendMessage(string.Format("KeyChanger (v{0}) by Enerdy", version), Color.SkyBlue); ply.SendMessage("Description: Changes special chest keys into their specific items", Color.SkyBlue); ply.SendMessage("Syntax: /key <list/mode/change/reload> [type]", Color.SkyBlue); ply.SendMessage("Type /help key for more info", Color.SkyBlue); } else if (args.Parameters[0].ToLower() == "change" && args.Parameters.Count == 1) { ply.SendErrorMessage("Invalid syntax! Proper syntax: /key change <type>"); } else if (args.Parameters.Count > 0) { string cmd = args.Parameters[0].ToLower(); switch (cmd) { case "change": if (!ply.Group.HasPermission("key.change")) { ply.SendErrorMessage("You do not have access to this command."); break; } // Prevents cast from the server console if (ply == TSPlayer.Server) { ply.SendErrorMessage("You must use this command in-game."); return; } Key key; string str = args.Parameters[1].ToLower(); if (str == Key.Temple.Name) { key = Key.Temple; } else if (str == Key.Jungle.Name) { key = Key.Jungle; } else if (str == Key.Corruption.Name) { key = Key.Corruption; } else if (str == Key.Crimson.Name) { key = Key.Crimson; } else if (str == Key.Hallowed.Name) { key = Key.Hallowed; } else if (str == Key.Frozen.Name) { key = Key.Frozen; } else { ply.SendErrorMessage("Invalid key type! Available types: " + string.Join(", ", Key.Temple.Enabled ? Key.Temple.Name : null, Key.Jungle.Enabled ? Key.Jungle.Name : null, Key.Corruption.Enabled ? Key.Corruption.Name : null, Key.Crimson.Enabled ? Key.Crimson.Name : null, Key.Hallowed.Enabled ? Key.Hallowed.Name : null, Key.Frozen.Enabled ? Key.Frozen.Name : null)); return; } // Verifies whether the key has been enabled if (!key.Enabled) { ply.SendInfoMessage("The selected key is disabled."); return; } // Checks if the player carries the necessary key var lookup = ply.TPlayer.inventory.FirstOrDefault(i => i.netID == (int)key.Type); if (lookup == null) { ply.SendErrorMessage("Make sure you carry the selected key in your inventory."); return; } if (Config.contents.EnableRegionExchanges) { Region region; if (Config.contents.MarketMode) { region = TShock.Regions.GetRegionByName(Config.contents.MarketRegion); } else { region = key.Region; } // Checks if the required region is set to null if (region == null) { ply.SendInfoMessage("No valid region was set for this key."); return; } // Checks if the player is inside the region if (!region.Area.Contains(ply.TileX, ply.TileY)) { ply.SendErrorMessage("You are not in a valid region to make this exchange."); return; } } Item item; for (int i = 0; i < 50; i++) { item = ply.TPlayer.inventory[i]; // Loops through the player's inventory if (item.netID == (int)key.Type) { // Found the item, checking for available slots if (item.stack == 1 || ply.InventorySlotAvailable) { ply.TPlayer.inventory[i].stack--; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, string.Empty, ply.Index, i); Random rand = new Random(); Item give = key.Items[rand.Next(0, key.Items.Count)]; ply.GiveItem(give.netID, give.name, give.width, give.height, 1); Item take = TShock.Utils.GetItemById((int)key.Type); ply.SendSuccessMessage("Exchanged a {0} for 1 {1}!", take.name, give.name); return; } // Sent if neither of the above conditions were fulfilled. ply.SendErrorMessage("Make sure you have at least one available inventory slot."); return; } } break; case "reload": { if (!ply.Group.HasPermission("key.reload")) { ply.SendErrorMessage("You do not have access to this command."); break; } if (Config.ReadConfig()) { Utils.InitKeys(); ply.SendMessage("KeyChangerConfig.json reloaded successfully.", Color.Green); break; } else { ply.SendErrorMessage("Failed to read KeyChangerConfig.json. Consider deleting the file so that it may be recreated."); break; } } case "list": { ply.SendMessage("Temple Key - " + string.Join(", ", Key.Temple.Items.Select(i => i.name)), Color.Goldenrod); ply.SendMessage("Jungle Key - " + string.Join(", ", Key.Jungle.Items.Select(i => i.name)), Color.Goldenrod); ply.SendMessage("Corruption Key - " + string.Join(", ", Key.Corruption.Items.Select(i => i.name)), Color.Goldenrod); ply.SendMessage("Crimson Key - " + string.Join(", ", Key.Crimson.Items.Select(i => i.name)), Color.Goldenrod); ply.SendMessage("Hallowed Key - " + string.Join(", ", Key.Hallowed.Items.Select(i => i.name)), Color.Goldenrod); ply.SendMessage("Frozen Key - " + string.Join(", ", Key.Frozen.Items.Select(i => i.name)), Color.Goldenrod); break; } case "mode": { if (!ply.Group.HasPermission("key.mode")) { ply.SendErrorMessage("You do not have access to this command."); break; } if (args.Parameters.Count < 2) { ply.SendErrorMessage("Invalid syntax! Proper syntax: /key mode <normal/region/market>"); break; } string query = args.Parameters[1].ToLower(); if (query == "normal") { Config.contents.EnableRegionExchanges = false; ply.SendSuccessMessage("Exchange mode set to normal (exchange everywhere)."); } else if (query == "region") { Config.contents.EnableRegionExchanges = true; Config.contents.MarketMode = false; ply.SendSuccessMessage("Exchange mode set to region (a region for each type)."); } else if (query == "market") { Config.contents.EnableRegionExchanges = true; Config.contents.MarketMode = true; ply.SendSuccessMessage("Exchange mode set to market (one region for every type)."); } else { ply.SendErrorMessage("Invalid syntax! Proper syntax: /key mode <normal/region/market>"); return; } Config.UpdateConfig(); break; } default: { ply.SendErrorMessage(Utils.ErrorMessage(ply)); break; } } } else { ply.SendErrorMessage(Utils.ErrorMessage(ply)); } }
/// <summary> /// Checks if a given player can build in a region at the given (x, y) coordinate /// </summary> /// <param name="x">X coordinate</param> /// <param name="y">Y coordinate</param> /// <param name="ply">Player to check permissions with</param> /// <returns>Whether the player can build at the given (x, y) coordinate</returns> public bool CanBuild(int x, int y, TSPlayer ply) { if (!ply.HasPermission(Permissions.canbuild)) { return false; } Region top = null; foreach (Region region in Regions.ToList()) { if (region.InArea(x, y)) { if (top == null || region.Z > top.Z) top = region; } } return top == null || top.HasPermissionToBuildInRegion(ply); }
public RegionEnteredEventArgs(TSPlayer ply, Region region) { Player = ply; Region = region; }
private static void DoOres(CommandArgs args) { if (WorldGen.genRand == null) { WorldGen.genRand = new Random(); } TSPlayer ply = args.Player; ushort oreType; float oreAmts = 100f; //Sigh why did I bother checking what this does...gets completely overwritten //Mod altarcount divide 3 - gives number between: 0 to 2 //int num = WorldGen.altarCount % 3; //Altarcount divide 3 + 1 - gives number between: 1 to infinity //int num2 = WorldGen.altarCount / 3 + 1; //4200 = small world size //6400 = medium world size //8400 = large world size //returns value: - 0 , 1.523809523809524, 2 //float num3 = (float)(Main.maxTilesX / 4200); //Gives number between: -1 to 1 //int num4 = 1 - num; //num3 * 310f - returns value: 0, 472.3809523809524, 620 //(float)(85 * num) - gives number between 0 to 170 //Returns value: -170, 302.3809523809524, 450 //num3 = num3 * 310f - (float)(85 * num); //Returns Value: -144.5, 257.0238095238095, 382.5 //num3 *= 0.85f; //gives number between: -144.5 to 382.5 //num3 /= (float)num2; if (args.Parameters.Count < 1) { ply.SendInfoMessage("Usage: /genores (type) (amount)"); return; } else if (args.Parameters[0].ToLowerInvariant() == "cobalt") { oreType = Terraria.ID.TileID.Cobalt; } else if (args.Parameters[0].ToLowerInvariant() == "mythril") { oreType = Terraria.ID.TileID.Mythril; } else if (args.Parameters[0].ToLowerInvariant() == "copper") { oreType = Terraria.ID.TileID.Copper; } else if (args.Parameters[0].ToLowerInvariant() == "iron") { oreType = Terraria.ID.TileID.Iron; } else if (args.Parameters[0].ToLowerInvariant() == "silver") { oreType = Terraria.ID.TileID.Silver; } else if (args.Parameters[0].ToLowerInvariant() == "gold") { oreType = Terraria.ID.TileID.Gold; } else if (args.Parameters[0].ToLowerInvariant() == "demonite") { oreType = Terraria.ID.TileID.Demonite; } else if (args.Parameters[0].ToLowerInvariant() == "sapphire") { oreType = Terraria.ID.TileID.Sapphire; } else if (args.Parameters[0].ToLowerInvariant() == "ruby") { oreType = Terraria.ID.TileID.Ruby; } else if (args.Parameters[0].ToLowerInvariant() == "emerald") { oreType = Terraria.ID.TileID.Emerald; } else if (args.Parameters[0].ToLowerInvariant() == "topaz") { oreType = Terraria.ID.TileID.Topaz; } else if (args.Parameters[0].ToLowerInvariant() == "amethyst") { oreType = Terraria.ID.TileID.Amethyst; } else if (args.Parameters[0].ToLowerInvariant() == "diamond") { oreType = Terraria.ID.TileID.Diamond; } else if (args.Parameters[0].ToLowerInvariant() == "adamantite") { oreType = Terraria.ID.TileID.Adamantite; } else if (args.Parameters[0].ToLowerInvariant() == "hellstone") { oreType = Terraria.ID.TileID.Hellstone; } else if (args.Parameters[0].ToLowerInvariant() == "meteorite") { oreType = Terraria.ID.TileID.Meteorite; } // New Ores else if (args.Parameters[0].ToLowerInvariant() == "tin") { oreType = Terraria.ID.TileID.Tin; } else if (args.Parameters[0].ToLowerInvariant() == "lead") { oreType = Terraria.ID.TileID.Lead; } else if (args.Parameters[0].ToLowerInvariant() == "tungsten") { oreType = Terraria.ID.TileID.Tungsten; } else if (args.Parameters[0].ToLowerInvariant() == "platinum") { oreType = Terraria.ID.TileID.Platinum; } else if (args.Parameters[0].ToLowerInvariant() == "crimtane") { oreType = Terraria.ID.TileID.Crimtane; } // 1.2 Hardmode Ores else if (args.Parameters[0].ToLowerInvariant() == "palladium") { oreType = Terraria.ID.TileID.Palladium; } else if (args.Parameters[0].ToLowerInvariant() == "orichalcum") { oreType = Terraria.ID.TileID.Orichalcum; } else if (args.Parameters[0].ToLowerInvariant() == "titanium") { oreType = Terraria.ID.TileID.Titanium; } else if (args.Parameters[0].ToLowerInvariant() == "chlorophyte") { oreType = Terraria.ID.TileID.Chlorophyte; } // Others else if (args.Parameters[0].ToLowerInvariant() == "dirt") { oreType = Terraria.ID.TileID.Dirt; } else if (args.Parameters[0].ToLowerInvariant() == "stone") { oreType = Terraria.ID.TileID.Stone; } else if (args.Parameters[0].ToLowerInvariant() == "sand") { oreType = Terraria.ID.TileID.Sand; } else if (args.Parameters[0].ToLowerInvariant() == "silt") { oreType = Terraria.ID.TileID.Silt; } else { ply.SendErrorMessage("Warning! Typo in Tile name or Tile does not exist"); return; } //If user specifies how many ores to generate (make sure not over 10000) if (args.Parameters.Count > 1) { float.TryParse(args.Parameters[1], out oreAmts); oreAmts = Math.Min(oreAmts, 10000f); } //oreGened = track amount of ores generated already int oreGened = 0; int minFrequency; int maxFrequency; int minSpread; int maxSpread; while ((float)oreGened < oreAmts) { //Get random number from 100 tiles each side int i2 = WorldGen.genRand.Next(100, Main.maxTilesX - 100); double worldY = Main.worldSurface; //Rare Ores - Adamantite (Titanium), Demonite, Diamond, Chlorophyte if ((oreType == Terraria.ID.TileID.Adamantite) || (oreType == Terraria.ID.TileID.Demonite) || (oreType == Terraria.ID.TileID.Crimtane) || (oreType == Terraria.ID.TileID.Chlorophyte) || (oreType == Terraria.ID.TileID.Titanium) || ((oreType >= Terraria.ID.TileID.Sapphire) && (oreType <= Terraria.ID.TileID.Diamond))) { //Some formula created by k0rd for getting somewhere between hell and roughly half way after rock worldY = (Main.rockLayer + Main.rockLayer + (double)Main.maxTilesY) / 3.0; minFrequency = 2; minSpread = 2; maxFrequency = 3; maxSpread = 3; } //Hellstone Only else if (oreType == Terraria.ID.TileID.Hellstone) { //roughly where hell is worldY = Main.maxTilesY - 200; minFrequency = 4; minSpread = 4; maxFrequency = 9; maxSpread = 9; } else { worldY = Main.rockLayer; minFrequency = 5; minSpread = 9; maxFrequency = 5; maxSpread = 9; } //Gets random number based on minimum spawn point to maximum depth of map int j2 = WorldGen.genRand.Next((int)worldY, Main.maxTilesY - 150); WorldGen.OreRunner(i2, j2, (double)WorldGen.genRand.Next(minSpread, maxSpread), WorldGen.genRand.Next(minFrequency, maxFrequency), oreType); oreGened++; } ply.SendSuccessMessage("Spawned {0} tiles of {1}", Math.Floor(oreAmts), args.Parameters[0].ToLowerInvariant()); InformPlayers(); }
public void onElapsed(object sender, ElapsedEventArgs args) { List <InfChest> nearbyChests = DB.getNearbyChests(location); List <Item[]> original = new List <Item[]>(); foreach (InfChest chest in nearbyChests) { original.Add((Item[])chest.items.Clone()); } TSPlayer player = TShock.Players[index]; Dictionary <int, Item> slotInfo = new Dictionary <int, Item>(); slotQueue.Sort(); foreach (int slot in slotQueue) { slotInfo.Add(slot, new Item()); slotInfo[slot] = player.TPlayer.inventory[slot]; } //foreach item in player's inventory for (int l = 0; l < slotInfo.Count; l++) { Item item = slotInfo.ElementAt(l).Value; //foreach chest nearby for (int i = 0; i < nearbyChests.Count; i++) { bool emptySlots = false; bool stacking = false; //if player has access to chest if ((nearbyChests[i].userid == player.User.ID || nearbyChests[i].userid == -1 || nearbyChests[i].isPublic || player.HasPermission("ic.edit")) && !InfChests.playerData.Values.Any(p => p.dbid == nearbyChests[i].id) && nearbyChests[i].refillTime == -1) { //foreach slot in chest for (int j = 0; j < nearbyChests[i].items.Length; j++) { //if slot is empty if (nearbyChests[i].items[j].type <= 0 || nearbyChests[i].items[j].stack <= 0) { emptySlots = true; } //else if slot has equivalent item else if (item.IsTheSameAs(nearbyChests[i].items[j])) { //stacks items into the chest stacking = true; int num = nearbyChests[i].items[j].maxStack - nearbyChests[i].items[j].stack; if (num > 0) { if (num > item.stack) { num = item.stack; } item.stack -= num; nearbyChests[i].items[j].stack += num; if (item.stack <= 0) { item.SetDefaults(0, false); } } } } //if item was partially stacked into a slot, and chest still has open slots remaining if (stacking && emptySlots && item.stack > 0) { //places items into empty slots in the chest for (int k = 0; k < nearbyChests[i].items.Length; k++) { if (nearbyChests[i].items[k].type == 0 || nearbyChests[i].items[k].stack == 0) { nearbyChests[i].items[k] = item.Clone(); item.SetDefaults(0, false); } } } } } } //update players foreach (KeyValuePair <int, Item> kvp in slotInfo) { NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, index, kvp.Key, kvp.Value.prefix, kvp.Value.stack, kvp.Value.type); } //update database for (int i = 0; i < nearbyChests.Count; i++) { for (int j = 0; j < 40; j++) { if (nearbyChests[i].items[j] == original[i][j]) { continue; } else { DB.setItem(nearbyChests[i].id, nearbyChests[i].items[j], j); } } } //restore defaults slotQueue.Clear(); location = new Point(); }
public Drain(int x, int y, int x2, int y2, TSPlayer plr) : base(x, y, x2, y2, plr) { }
public RegionEnteredEventArgs(TSPlayer ply) { Player = ply; }
private void OnGetData(GetDataEventArgs args) { if ((int)args.MsgID == (int)PacketTypes.ItemDrop) { TSPlayer tSPlayer = TShock.Players[args.Msg.whoAmI]; using (MemoryStream memoryStream = new MemoryStream(args.Msg.readBuffer, args.Index, args.Length)) { using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8, true)) { int num = (int)binaryReader.ReadInt16(); float num2 = binaryReader.ReadSingle(); float num3 = binaryReader.ReadSingle(); binaryReader.ReadSingle(); binaryReader.ReadSingle(); int num4 = (int)binaryReader.ReadInt16(); int num5 = (int)binaryReader.ReadByte(); binaryReader.ReadBoolean(); int num6 = (int)binaryReader.ReadInt16(); if (num == 400) { Item itemById = TShock.Utils.GetItemById(num6); string name = tSPlayer.Name; string sourceIP = tSPlayer.IP.Split(new char[] { ':' })[0]; lock (this._pendingLocker) { float dropX = num2 / 16f; float dropY = num3 / 16f; this._playerDropsPending.Add(new ItemDrop(name, itemById.netID, num4, num5, dropX, dropY)); if (this.CheckItem(itemById)) { ItemDropLogger.CreateItemEntry(new ItemDropLogInfo("PlayerDrop", name, string.Empty, itemById.netID, num4, num5, dropX, dropY) { SourceIP = sourceIP }); } } } if (num < 400 && num6 == 0) { Item item = Main.item[num]; if (item.netID != 0) { string name2 = tSPlayer.Name; string targetIP = tSPlayer.IP.Split(new char[] { ':' })[0]; lock (this._dropLocker) { ItemDrop itemDrop = this._drops[num]; if (this._drops[num] != null && this._drops[num].NetworkId != 0) { if (this.CheckItem(item)) { ItemDropLogger.UpdateItemEntry(new ItemDropLogInfo("Pickup", itemDrop.SourceName, name2, itemDrop.NetworkId, itemDrop.Stack, (int)itemDrop.Prefix) { TargetIP = targetIP }); } this._drops[num] = null; } } } } } } } }
public ReloadEventArgs(TSPlayer ply) { Player = ply; }
/// <summary> /// Inserts a specific PlayerData into the SSC table for a player. /// </summary> /// <param name="player">The player to store the data for.</param> /// <param name="data">The player data to store.</param> /// <returns>If the command succeeds.</returns> public bool InsertSpecificPlayerData(TSPlayer player, PlayerData data) { PlayerData playerData = data; if (!player.IsLoggedIn) { return(false); } if (player.HasPermission(Permissions.bypassssc)) { TShock.Log.ConsoleInfo("Skipping SSC Backup for " + player.Account.Name); // Debug code return(true); } if (!GetPlayerData(player, player.Account.ID).exists) { try { database.Query( "INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, extraSlot, spawnX, spawnY, skinVariant, hair, hairDye, hairColor, pantsColor, shirtColor, underShirtColor, shoeColor, hideVisuals, skinColor, eyeColor, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20);", player.Account.ID, playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, String.Join("~", playerData.inventory), playerData.extraSlot, playerData.spawnX, playerData.spawnX, playerData.skinVariant, playerData.hair, playerData.hairDye, TShock.Utils.EncodeColor(playerData.hairColor), TShock.Utils.EncodeColor(playerData.pantsColor), TShock.Utils.EncodeColor(playerData.shirtColor), TShock.Utils.EncodeColor(playerData.underShirtColor), TShock.Utils.EncodeColor(playerData.shoeColor), TShock.Utils.EncodeBoolArray(playerData.hideVisuals), TShock.Utils.EncodeColor(playerData.skinColor), TShock.Utils.EncodeColor(playerData.eyeColor), playerData.questsCompleted); return(true); } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } } else { try { database.Query( "UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7, hair = @8, hairDye = @9, hairColor = @10, pantsColor = @11, shirtColor = @12, underShirtColor = @13, shoeColor = @14, hideVisuals = @15, skinColor = @16, eyeColor = @17, questsCompleted = @18, skinVariant = @19, extraSlot = @20 WHERE Account = @5;", playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, String.Join("~", playerData.inventory), player.Account.ID, playerData.spawnX, playerData.spawnX, playerData.skinVariant, playerData.hair, playerData.hairDye, TShock.Utils.EncodeColor(playerData.hairColor), TShock.Utils.EncodeColor(playerData.pantsColor), TShock.Utils.EncodeColor(playerData.shirtColor), TShock.Utils.EncodeColor(playerData.underShirtColor), TShock.Utils.EncodeColor(playerData.shoeColor), TShock.Utils.EncodeBoolArray(playerData.hideVisuals), TShock.Utils.EncodeColor(playerData.skinColor), TShock.Utils.EncodeColor(playerData.eyeColor), playerData.questsCompleted, playerData.extraSlot ?? 0); return(true); } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } } return(false); }
public void NewInventory(TSPlayer player) { string[] inv; inv = new string[41]; for (int i = 0; i < 40; i++) { inv[i] = player.TPlayer.inventory[i].name + ":" + player.TPlayer.inventory[i].stack; } try { database.Query("INSERT INTO Inventory (Username, Slot0, Slot1, Slot2, Slot3, Slot4, " + "Slot5, Slot6, Slot7, Slot8, Slot9, "+ "Slot10, Slot11, Slot12, Slot13, Slot14, " + "Slot15, Slot16, Slot17, Slot18, Slot19, "+ "Slot20, Slot21, Slot22, Slot23, Slot24, " + "Slot25, Slot26, Slot27, Slot28, Slot29, "+ "Slot30, Slot31, Slot32, Slot33, Slot34, " + "Slot35, Slot36, Slot37, Slot38, Slot39"+ ") VALUES (@40, @0, @1, @2, @3, @4, @5, "+ "@6, @7, @8, @9, @10, @11, @12, @13, "+ "@14, @15, @16, @17, @18, @19, @20, "+ "@21, @22, @23, @24, @25, @26, @27, "+ "@28, @29, @30, @31, @32, @33, @34, @35, @36, "+ "@37, @38, @39);", inv[0], inv[1], inv[2], inv[3], inv[4], inv[5], inv[6], inv[7], inv[8], inv[9], inv[10], inv[11], inv[12], inv[13], inv[14], inv[15], inv[16], inv[17], inv[18], inv[19], inv[20], inv[21], inv[22], inv[23], inv[24], inv[25], inv[26], inv[27], inv[28], inv[29], inv[30], inv[31], inv[32], inv[33], inv[34], inv[35], inv[36], inv[37], inv[38], inv[39], player.Name); } catch (Exception ex) { Log.Error(ex.ToString()); } }
public void SetTeam(object player, int team) { TSPlayer p = GetPlayer(player); p.SetTeam(team); }
public void UpdateInventory(TSPlayer player) { string[] inv; inv = new string[41]; for (int i = 0; i < 40; i++) { inv[i] = player.TPlayer.inventory[i].name + ":" + player.TPlayer.inventory[i].stack; } try { database.Query("UPDATE Inventory SET Slot0 = @0, Slot1 = @1, Slot2 = @2, Slot3 = @3, Slot4 = @4, " + "Slot5 = @5, Slot6 = @6, Slot7 = @7, Slot8 = @8, Slot9 = @9, " + "Slot10 = @10, Slot11 = @11, Slot12 = @12, Slot13 = @13, Slot14 = @14, " + "Slot15 = @15, Slot16 = @16, Slot17 = @17, Slot18 = @18, Slot19 = @19, " + "Slot20 = @20, Slot21 = @21, Slot22 = @22, Slot23 = @23, Slot24 = @24, " + "Slot25 = @25, Slot26 = @26, Slot27 = @27, Slot28 = @28, Slot29 = @29, " + "Slot30 = @30, Slot31 = @31, Slot32 = @32, Slot33 = @33, Slot34 = @34, " + "Slot35 = @35, Slot36 = @36, Slot37 = @37, Slot38 = @38, Slot39 = @39 " + "WHERE LOWER (Username) = @40;", inv[0], inv[1], inv[2], inv[3], inv[4], inv[5], inv[6], inv[7], inv[8], inv[9], inv[10], inv[11], inv[12], inv[13], inv[14], inv[15], inv[16], inv[17], inv[18], inv[19], inv[20], inv[21], inv[22], inv[23], inv[24], inv[25], inv[26], inv[27], inv[28], inv[29], inv[30], inv[31], inv[32], inv[33], inv[34], inv[35], inv[36], inv[37], inv[38], inv[39], player.Name.ToLower()); return; } catch (Exception ex) { Log.Error(ex.ToString()); } }
public void WarpPlayer(object player, float x, float y) { TSPlayer p = GetPlayer(player); p.Teleport(x, y); }
public bool CheckInventory(TSPlayer player) { string[] inv; inv = new string[41]; QueryResult result; for (int i = 0; i < 40; i++) { inv[i] = player.TPlayer.inventory[i].name + ":" + player.TPlayer.inventory[i].stack; } try { result = database.QueryReader("SELECT * FROM Inventory WHERE LOWER (Username) = @0", player.Name.ToLower()); using (var reader = result) { if (reader.Read()) { string slot0 = reader.Get<string>("Slot0"); string slot1 = reader.Get<string>("Slot1"); string slot2 = reader.Get<string>("Slot2"); string slot3 = reader.Get<string>("Slot3"); string slot4 = reader.Get<string>("Slot4"); string slot5 = reader.Get<string>("Slot5"); string slot6 = reader.Get<string>("Slot6"); string slot7 = reader.Get<string>("Slot7"); string slot8 = reader.Get<string>("Slot8"); string slot9 = reader.Get<string>("Slot9"); string slot10 = reader.Get<string>("Slot10"); string slot11 = reader.Get<string>("Slot11"); string slot12 = reader.Get<string>("Slot12"); string slot13 = reader.Get<string>("Slot13"); string slot14 = reader.Get<string>("Slot14"); string slot15 = reader.Get<string>("Slot15"); string slot16 = reader.Get<string>("Slot16"); string slot17 = reader.Get<string>("Slot17"); string slot18 = reader.Get<string>("Slot18"); string slot19 = reader.Get<string>("Slot19"); string slot20 = reader.Get<string>("Slot20"); string slot21 = reader.Get<string>("Slot21"); string slot22 = reader.Get<string>("Slot22"); string slot23 = reader.Get<string>("Slot23"); string slot24 = reader.Get<string>("Slot24"); string slot25 = reader.Get<string>("Slot25"); string slot26 = reader.Get<string>("Slot26"); string slot27 = reader.Get<string>("Slot27"); string slot28 = reader.Get<string>("Slot28"); string slot29 = reader.Get<string>("Slot29"); string slot30 = reader.Get<string>("Slot30"); string slot31 = reader.Get<string>("Slot31"); string slot32 = reader.Get<string>("Slot32"); string slot33 = reader.Get<string>("Slot33"); string slot34 = reader.Get<string>("Slot34"); string slot35 = reader.Get<string>("Slot35"); string slot36 = reader.Get<string>("Slot36"); string slot37 = reader.Get<string>("Slot37"); string slot38 = reader.Get<string>("Slot38"); string slot39 = reader.Get<string>("Slot39"); if (slot0 == inv[0] && slot1 == inv[1] && slot2 == inv[2] && slot3 == inv[3] && slot4 == inv[4] && slot5 == inv[5] && slot6 == inv[6] && slot7 == inv[7] && slot8 == inv[8] && slot9 == inv[9] && slot10 == inv[10] && slot11 == inv[11] && slot12 == inv[12] && slot13 == inv[13] && slot14 == inv[14] && slot15 == inv[15] && slot16 == inv[16] && slot17 == inv[17] && slot18 == inv[18] && slot19 == inv[19] && slot20 == inv[20] && slot21 == inv[21] && slot22 == inv[22] && slot23 == inv[23] && slot24 == inv[24] && slot25 == inv[25] && slot26 == inv[26] && slot27 == inv[27] && slot28 == inv[28] && slot29 == inv[29] && slot30 == inv[30] && slot31 == inv[31] && slot32 == inv[32] && slot33 == inv[33] && slot34 == inv[34] && slot35 == inv[35] && slot36 == inv[36] && slot37 == inv[37] && slot38 == inv[38] && slot39 == inv[39]) { return true; } else { return false; } } } } catch (Exception ex) { Log.Error(ex.ToString()); } return false; }
protected override bool Broke(TSPlayer Player) => (Player.TPlayer.hostile != Value);
public bool HasPermissionToBuildInRegion(TSPlayer ply, out string CoOwner) { CoOwner = string.Empty; if (!ply.IsLoggedIn) { ply.SendMessage("You must be logged in to take advantage of protected regions.", Color.Red); return false; } if (!DisableBuild) { return true; } try { for (int i = 0; i < AllowedIDs.Count; i++) { CoOwner = string.Format("{0} {1}", CoOwner, TShock.Users.GetNameForID((int)AllowedIDs[i])); } CoOwner = CoOwner.Remove(0, 1); } catch { CoOwner = ""; return false; } for (int i = 0; i < AllowedIDs.Count; i++) { if (AllowedIDs[i] == ply.UserID) { return true; } } return false; }
public bool HasPermissionToBuildInRegion(TSPlayer ply) { if (!ply.IsLoggedIn) { if (!ply.HasBeenNaggedAboutLoggingIn) { ply.SendMessage("You must be logged in to take advantage of protected regions.", Color.Red); ply.HasBeenNaggedAboutLoggingIn = true; } return false; } if (!DisableBuild) { return true; } for (int i = 0; i < AllowedIDs.Count; i++) { if (AllowedIDs[i] == ply.UserID) { return true; } } return false; }
private static NetItem[] CreateInventory(TSPlayer player) { int index; var playerInventory = new NetItem[NetItem.MaxInventory]; var inventory = player.TPlayer.inventory; var armor = player.TPlayer.armor; var dye = player.TPlayer.dye; var miscEquips = player.TPlayer.miscEquips; var miscDyes = player.TPlayer.miscDyes; var piggy = player.TPlayer.bank.item; var safe = player.TPlayer.bank2.item; var trash = player.TPlayer.trashItem; var forge = player.TPlayer.bank3.item; for (var i = 0; i < NetItem.MaxInventory; i++) { if (i < NetItem.InventoryIndex.Item2) { playerInventory[i] = (NetItem)inventory[i]; } else if (i < NetItem.ArmorIndex.Item2) { index = i - NetItem.ArmorIndex.Item1; playerInventory[i] = (NetItem)armor[index]; } else if (i < NetItem.DyeIndex.Item2) { index = i - NetItem.DyeIndex.Item1; playerInventory[i] = (NetItem)dye[index]; } else if (i < NetItem.MiscEquipIndex.Item2) { index = i - NetItem.MiscEquipIndex.Item1; playerInventory[i] = (NetItem)miscEquips[index]; } else if (i < NetItem.MiscDyeIndex.Item2) { index = i - NetItem.MiscDyeIndex.Item1; playerInventory[i] = (NetItem)miscDyes[index]; } else if (i < NetItem.PiggyIndex.Item2) { index = i - NetItem.PiggyIndex.Item1; playerInventory[i] = (NetItem)piggy[index]; } else if (i < NetItem.SafeIndex.Item2) { index = i - NetItem.SafeIndex.Item1; playerInventory[i] = (NetItem)safe[index]; } else if (i < NetItem.TrashIndex.Item2) { playerInventory[i] = (NetItem)trash; } else if (i < NetItem.ForgeIndex.Item2) { index = i - NetItem.ForgeIndex.Item1; playerInventory[i] = (NetItem)forge[index]; } } return(playerInventory); }
public PlayerPostLoginEventArgs(TSPlayer ply) { Player = ply; }
/// <summary> /// Checks if a given player has permission to build in the region /// </summary> /// <param name="ply">Player to check permissions with</param> /// <returns>Whether the player has permission</returns> public bool HasPermissionToBuildInRegion(TSPlayer ply) { if (!DisableBuild) { return true; } if (!ply.IsLoggedIn) { if (!ply.HasBeenNaggedAboutLoggingIn) { ply.SendMessage("You must be logged in to take advantage of protected regions.", Color.Red); ply.HasBeenNaggedAboutLoggingIn = true; } return false; } return ply.HasPermission(Permissions.editregion) || AllowedIDs.Contains(ply.User.ID) || AllowedGroups.Contains(ply.Group.Name) || Owner == ply.User.Name; }
/* * private static string GetImpersonatedString(User user, string text) * { * var group = TShock.Groups.GetGroupByName(user.Group); * * return string.Format(TShock.Config.ChatFormat, group.Name, group.Prefix, user.Name, group.Suffix, text); * } */ /* * private static IEnumerable<TSPlayer> GetTargetsByRegion(Region region) * => TShock.Players.Where(p => p?.CurrentRegion == region); */ /* * private static TSPlayer GetTSPlayerFromUser(User user) => * TShock.Players.FirstOrDefault(p => p?.Name.Equals(user.Name, StringComparison.InvariantCultureIgnoreCase) ?? false); */ private static string GetImpersonatedString(TSPlayer p, string text) => string.Format(TShock.Config.ChatFormat, p.Group.Name, p.Group.Prefix, p.Name, p.Group.Suffix, text);
/// <summary> /// Initializes a new instance of the <see cref="BalanceSheet" /> class for the specified player. /// </summary> /// <param name="player">The player, which must not be <c>null</c>.</param> public BalanceSheet([NotNull] TSPlayer player) { Debug.Assert(player != null, "Player must not be null."); _player = player; }
public void WarpPlayer(object player, Warp warp) { TSPlayer p = GetPlayer(player); p.Teleport(warp.Position.X * 16, warp.Position.Y * 16); }
public PlayerSpawnEventArgs(TSPlayer player, DPoint spawnTileLocation) : base(player) { this.SpawnTileLocation = spawnTileLocation; }
public bool CanBuild(int x, int y, TSPlayer ply) { if (!ply.Group.HasPermission(Permissions.canbuild)) { return false; } for (int i = 0; i < Regions.Count; i++) { if (Regions[i].InArea(new Rectangle(x, y, 0, 0)) && !Regions[i].HasPermissionToBuildInRegion(ply)) { return false; } } return true; }
private void OnChat(ServerChatEventArgs args) { if (args.Handled) { //Do nothing if the event is already handled return; } if (args.Text.StartsWith(TShock.Config.CommandSilentSpecifier) || args.Text.StartsWith(TShock.Config.CommandSpecifier)) { //Do nothing if the text is a command return; } //Grab the player who sent the text TSPlayer p = TShock.Players[args.Who]; if (p == null) { //Do nothing if the player doesn't actually exist return; } //Do a regex match to see if the text contains any chat tags Match match = TagRegex.Match(args.Text); //Declare a new string to be our altered text string text; //This is the colour the pop-up text and chat will be sent in. Default is the player's group text colour Color msgColor = new Color(p.Group.R, p.Group.G, p.Group.B); string tag = match.Groups["tag"].Value; if (tag != "c" && tag != "color") { //replace achievements and colours for pop-ups text = TagRegex.Replace(args.Text, ""); } else { //Remove the tag (but leave any text contained in the tag) text = TagRegex.Replace(args.Text, match.Groups["text"].Value ?? ""); //Attempt to parse a colour out of the tag string options = match.Groups["options"].Value; int num; if (int.TryParse(options, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out num)) { msgColor = new Color(num >> 16 & 255, num >> 8 & 255, num & 255); } } //Send pop-up text of the chat message NetMessage.SendData((int)PacketTypes.CreateCombatText, -1, -1, text, (int)msgColor.PackedValue, p.TPlayer.position.X, p.TPlayer.position.Y + 32); if (config.RadiusInFeet == -1) { //-1 means everyone should receive a chat message, so return return; } //Re-format the text for normal chat text = String.Format(TShock.Config.ChatFormat, p.Group.Name, p.Group.Prefix, p.Name, p.Group.Suffix, args.Text); if (config.RadiusInFeet == 0) { //0 means no one should receive a chat message, so handle the event and return args.Handled = true; return; } //Get an enumerable object of all players in the config-defined chat range IEnumerable <TSPlayer> plrList = TShock.Players.Where( plr => plr != null && plr != p && plr.Active && Vector2.Distance(plr.TPlayer.position, p.TPlayer.position) <= (config.RadiusInFeet * 8)); //Send the message to the player who sent the message //Sounds silly, but it's necessary p.SendMessage(text, msgColor); //Send the message to the server (console) TSPlayer.Server.SendMessage(text, msgColor); foreach (TSPlayer plr in plrList) { //Send the message to every player who was inside the config-defined chat range plr.SendMessage(text, msgColor); } //Mark the event as handled, so that (hopefully) no other plugins will mess with the chat args.Handled = true; }
public static bool OnPlayerPreLogin(TSPlayer ply, string name, string pass) { if (PlayerPreLogin == null) return false; var args = new PlayerPreLoginEventArgs {Player = ply, LoginName = name, Password = pass}; PlayerPreLogin(args); return args.Handled; }
public DataType this[TSPlayer tsPlayer] { get { return(this[tsPlayer.Index]); } set { this[tsPlayer.Index] = value; } }
public FixSlopes(int x, int y, int x2, int y2, TSPlayer plr) : base(x, y, x2, y2, plr) { }