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 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"); 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.DecodeBitsByte(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) { Log.Error(ex.ToString()); } return(playerData); }
public static RelevantInfo GetRelevance(QueryResult reader) { bool[] hiddens = new bool[20]; RelevantInfo relevantPlr = new RelevantInfo(); Color eyeColor = (Color)TShock.Utils.DecodeColor(reader.Get <Int32>("eyecolor")); Color hairColor = (Color)TShock.Utils.DecodeColor(reader.Get <Int32>("haircolor")); Color pantsColor = (Color)TShock.Utils.DecodeColor(reader.Get <Int32>("pantscolor")); Color shirtColor = (Color)TShock.Utils.DecodeColor(reader.Get <Int32>("shirtcolor")); Color shoeColor = (Color)TShock.Utils.DecodeColor(reader.Get <Int32>("shoecolor")); Color skinColor = (Color)TShock.Utils.DecodeColor(reader.Get <Int32>("skincolor")); Color underShirtColor = (Color)TShock.Utils.DecodeColor(reader.Get <Int32>("undershirtcolor")); relevantPlr.EyeColor = new int[] { eyeColor.R, eyeColor.G, eyeColor.B }; relevantPlr.HairColor = new int[] { hairColor.R, hairColor.G, hairColor.B }; relevantPlr.PantsColor = new int[] { pantsColor.R, pantsColor.G, pantsColor.B }; relevantPlr.ShirtColor = new int[] { shirtColor.R, shirtColor.G, shirtColor.B }; relevantPlr.ShoeColor = new int[] { shoeColor.R, shoeColor.G, shoeColor.B }; relevantPlr.SkinColor = new int[] { skinColor.R, skinColor.G, skinColor.B }; relevantPlr.UnderShirtColor = new int[] { underShirtColor.R, underShirtColor.G, underShirtColor.B }; relevantPlr.SkinVariant = reader.Get <Int32>("skinvariant"); relevantPlr.Hair = reader.Get <Int32>("hair"); bool extraSlot = reader.Get <Boolean>("extraSlot"); for (int i = 0; i < 20; i++) { if (i < 10) { hiddens[i] = (reader.Get <Int32>("hideVisuals") & 1 << i) != 0; } else { hiddens[i] = false; } } string[] inventory_entries = reader.Get <String>("inventory").Split('~'); NetItem parsed; Item item; // Because vanity items are stored after regular, if one is wearing vanity it will replace the former int not_weird = 0; for (int i = 59; i < 79; i++) { not_weird = i - 59; parsed = NetItem.Parse(inventory_entries[i]); if (parsed.NetId < 1) { continue; } if (extraSlot && (not_weird == 8 || not_weird == 18)) // lets skip the extra slots { continue; } item = new Item(); item.SetDefaults(parsed.NetId); // Head if ((i == 59 || i == 69) && item.headSlot >= 0) { relevantPlr.HeadSlot = (item.headSlot == 0) ? (int?)null : item.headSlot; } // Body else if ((i == 60 || i == 70) && item.bodySlot >= 0) { relevantPlr.BodySlot = (item.bodySlot == 0) ? (int?)null : item.bodySlot; } // Legs else if ((i == 61 || i == 71) && item.legSlot >= 0) { relevantPlr.LegsSlot = (item.legSlot == 0) ? (int?)null : item.legSlot; } // Accessories else if (((i >= 62 && i <= 67) && !hiddens[not_weird]) || i >= 72 && i <= 77) { if (item.handOnSlot >= 0) { relevantPlr.HandsOnSlot = item.handOnSlot; } if (item.handOffSlot >= 0) { relevantPlr.HandsOffSlot = item.handOffSlot; } if (item.backSlot >= 0) { relevantPlr.BackSlot = item.backSlot; relevantPlr.FrontSlot = null; } if (item.frontSlot > 0) { relevantPlr.FrontSlot = item.frontSlot; } if (item.shoeSlot > 0) { relevantPlr.ShoeSlot = item.shoeSlot; } if (item.waistSlot > 0) { relevantPlr.WaistSlot = item.waistSlot; } if (item.wingSlot > 0) { relevantPlr.WingSlot = item.wingSlot; } if (item.shieldSlot > 0) { relevantPlr.ShieldSlot = item.shieldSlot; } if (item.neckSlot > 0) { relevantPlr.NeckSlot = item.neckSlot; } if (item.faceSlot > 0) { relevantPlr.FaceSlot = item.faceSlot; } if (item.balloonSlot > 0) { relevantPlr.BalloonSlot = item.balloonSlot; } } } // Robes and set pieces that stretch bool wearsRobe = false; int news = Player.SetMatch(1, relevantPlr.BodySlot.HasValue ? relevantPlr.BodySlot.Value : 0, Terraria.ID.PlayerVariantID.Sets.Male[relevantPlr.SkinVariant], ref wearsRobe); if (news != -1) { relevantPlr.LegsSlot = news; } news = Player.SetMatch(2, relevantPlr.LegsSlot.HasValue ? relevantPlr.LegsSlot.Value : 0, Terraria.ID.PlayerVariantID.Sets.Male[relevantPlr.SkinVariant], ref wearsRobe); if (news != -1) { relevantPlr.LegsSlot = news; } news = Player.SetMatch(0, relevantPlr.HeadSlot.HasValue ? relevantPlr.HeadSlot.Value : 0, Terraria.ID.PlayerVariantID.Sets.Male[relevantPlr.SkinVariant], ref wearsRobe); if (news != -1) { relevantPlr.HeadSlot = news; } // Conditionals if (relevantPlr.WingSlot.HasValue) { relevantPlr.BackSlot = null; relevantPlr.FrontSlot = null; } if (relevantPlr.HeadSlot.HasValue && relevantPlr.HeadSlot != 0) { relevantPlr.FaceSlot = relevantPlr.FaceSlot.HasValue ? ((relevantPlr.FaceSlot == 7) ? 7 : (int?)null) : (int?)null; } return(relevantPlr); }