public static void DeleteTile(int x, int y) { Main.tile[x, y].active = false; Main.tile[x, y].skipLiquid = true; Main.tile[x, y].liquid = 0; QTools.UpdateTile(x, y); }
public static int GetXYWallPercentage(string walltype, int X, int Y, int Width, int Height) { double amountofmatchedwalls = 0; double totalwallcount = 0; byte type; if (QTools.GetWallTypeFromName(walltype, out type)) { for (int i = X; i < (X + Width); i++) { for (int j = Y; j < (Y + Height); j++) { if (Main.tile[i, j].active && Main.tile[i, j].type == type) { amountofmatchedwalls++; } totalwallcount++; } } } if (totalwallcount != 0) { return((int)((amountofmatchedwalls / totalwallcount) * 100)); } return(0); }
public static int GetRegionWallPercentage(string walltype, string regionname) { double amountofmatchedwalls = 0; double totalwallcount = 0; TShockAPI.DB.Region r; byte type; if (QTools.GetWallTypeFromName(walltype, out type)) { if ((r = TShock.Regions.ZacksGetRegionByName(regionname)) != null) { for (int i = r.Area.X; i < (r.Area.X + r.Area.Width); i++) { for (int j = r.Area.Y; j < (r.Area.Y + r.Area.Height); j++) { if (Main.tile[i, j].active && Main.tile[i, j].wall == type) { amountofmatchedwalls++; } totalwallcount++; } } } } if (totalwallcount != 0) { return((int)((amountofmatchedwalls / totalwallcount) * 100)); } return(0); }
public static void HitCoords(CommandArgs args) { var player = QTools.GetPlayerByID(args.Player.Index); player.AwaitingHitCoords = true; args.Player.SendMessage("Hit a Tile/Wall to get its Coords", Color.Magenta); }
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); }
public void OnUpdate() { lock (Players) { foreach (QPlayer player in Players) { if (!player.IsLoggedIn && player.TSPlayer.IsLoggedIn) { player.MyDBPlayer = QTools.GetStoredPlayerByIdentification(player); if (player.MyDBPlayer == null) { StoredQPlayer splayer = new StoredQPlayer(player.TSPlayer.UserAccountName, new List <QuestPlayerData>()); StoredPlayers.Add(splayer); player.MyDBPlayer = splayer; QTools.UpdateStoredPlayersInDB(); } player.IsLoggedIn = true; } if (player.LastTilePos != new Vector2(player.TSPlayer.TileX, player.TSPlayer.TileY)) { bool inhouse = false; foreach (QuestRegion qr in QuestRegions) { if (qr.Area.Intersects(new Rectangle(player.TSPlayer.TileX, player.TSPlayer.TileY, 1, 1))) { if (player.CurQuestRegion != qr.Name) { player.CurQuestRegion = qr.Name; player.InHouse = true; if (qr.MessageOnEntry != "") { player.TSPlayer.SendMessage(qr.MessageOnEntry, Color.Magenta); } } inhouse = true; } if (!inhouse && player.InHouse) { if (qr.MessageOnExit != "") { player.TSPlayer.SendMessage(qr.MessageOnExit, Color.Magenta); } player.CurQuestRegion = ""; player.InHouse = false; } player.LastTilePos = new Vector2(player.TSPlayer.TileX, player.TSPlayer.TileY); } } } } }
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); }
public static void StopQuest(CommandArgs args) { if (args.Parameters.Count > 1) { var runpara = QTools.GetRunningQuestByName(args.Parameters[0], args.Parameters[1]); if (runpara != null) { runpara.QThread.Abort(); } else { args.Player.SendMessage("Invalid Arguments or Player is not running Quest", Color.Red); } } }
public static void StartQuest(CommandArgs args) { QPlayer Player = QTools.GetPlayerByID(args.Player.Index); if (Player.IsLoggedIn) { Rectangle ply = new Rectangle((int)args.Player.X / 16, (int)args.Player.Y / 16, 1, 1); bool questfound = false; foreach (QuestRegion qr in QMain.QuestRegions) { if (ply.Intersects(qr.Area)) { foreach (Quest q in qr.Quests) { QuestPlayerData data = QTools.GetPlayerQuestData(q.Name, Player); if (QTools.AbleToRunQuest(q) && (q.MinQuestsNeeded == 0 || q.MinQuestsNeeded <= QTools.GetQuestsCompleted(Player.MyDBPlayer.QuestPlayerData)) && q.Name.ToLower() == args.Parameters[0].ToLower() && (q.MaxAttemps == 0 || data == null || QTools.GetPlayerQuestData(q.Name, Player).Attempts < q.MaxAttemps)) { questfound = true; break; } } } if (questfound) { break; } } if (questfound) { if (!Player.NewQuest(QTools.GetQuestByName(args.Parameters[0]))) { Player.TSPlayer.SendMessage("Quest already running.", Color.Red); } } else { Player.TSPlayer.SendMessage("Quest not found.", Color.Red); } } else { Player.TSPlayer.SendMessage("You are not Logged in", Color.Red); } }
public static void WallEdit(int x, int y, string wall) { byte type; if (QTools.GetTileTypeFromName(wall, out type)) { if (type < 255) { Main.tile[x, y].wall = (byte)type; } QTools.UpdateTile(x, y); } else { throw new Exception("Invalid Wall Name"); } }
public void OnInitialize() { Main.ignoreErrors = true; Main.rand = new Random(); SQLEditor = new SqlTableEditor(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder) new SqliteQueryCreator() : new MysqlQueryCreator()); SQLWriter = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder) new SqliteQueryCreator() : new MysqlQueryCreator()); Commands.ChatCommands.Add(new Command(QCommands.GetCoords, "getcoords")); Commands.ChatCommands.Add(new Command(QCommands.HitCoords, "hitcoords")); Commands.ChatCommands.Add(new Command("usequest", QCommands.ListQuest, "listquests")); Commands.ChatCommands.Add(new Command("usequest", QCommands.StartQuest, "startquest")); Commands.ChatCommands.Add(new Command("questregion", QCommands.QuestRegion, "questr")); Commands.ChatCommands.Add(new Command("reloadqdata", QCommands.LoadQuestData, "reloadquestdata")); Commands.ChatCommands.Add(new Command("giveq", QCommands.GiveQuest, "giveq")); Commands.ChatCommands.Add(new Command("stopquest", QCommands.StopQuest, "stopquest")); var table = new SqlTable("QuestPlayers", new SqlColumn("LogInName", MySqlDbType.Text) { Unique = true }, new SqlColumn("QuestPlayerData", MySqlDbType.Text) ); SQLWriter.EnsureExists(table); table = new SqlTable("QuestRegions", new SqlColumn("RegionName", MySqlDbType.Text) { Unique = true }, new SqlColumn("X1", MySqlDbType.Int32), new SqlColumn("Y1", MySqlDbType.Int32), new SqlColumn("X2", MySqlDbType.Int32), new SqlColumn("Y2", MySqlDbType.Int32), new SqlColumn("Quests", MySqlDbType.Text), new SqlColumn("EntryMessage", MySqlDbType.Text), new SqlColumn("ExitMessage", MySqlDbType.Text) ); SQLWriter.EnsureExists(table); QTools.LoadQuestData(); }
public static void TileEdit(int x, int y, string tile) { byte type; if (QTools.GetTileTypeFromName(tile, out type)) { if (type < 253) { Main.tile[x, y].type = (byte)type; Main.tile[x, y].active = true; Main.tile[x, y].liquid = 0; Main.tile[x, y].skipLiquid = true; Main.tile[x, y].frameNumber = 0; Main.tile[x, y].frameX = -1; Main.tile[x, y].frameY = -1; } else if (type == 253) { Main.tile[x, y].active = false; Main.tile[x, y].skipLiquid = false; Main.tile[x, y].lava = false; Main.tile[x, y].liquid = 255; Main.tile[x, y].checkingLiquid = false; } else if (type == 254) { Main.tile[x, y].active = false; Main.tile[x, y].skipLiquid = false; Main.tile[x, y].lava = true; Main.tile[x, y].liquid = 255; Main.tile[x, y].checkingLiquid = false; } if ((Main.tile[x, y].type == 53) || (Main.tile[x, y].type == 253) || (Main.tile[x, y].type == 254)) { WorldGen.SquareTileFrame(x, y, false); } QTools.UpdateTile(x, y); } else { throw new Exception("Invalid Tile Name"); } }
public void OnChat(messageBuffer msg, int ply, string text, HandledEventArgs e) { if (e.Handled) { return; } var player = QTools.GetPlayerByID(ply); if (player.AwaitingChat) { player.LastChatMessage = text; player.AwaitingChat = false; if (player.HideChat) { e.Handled = true; } } }
public static void ListQuest(CommandArgs args) { QPlayer Player = QTools.GetPlayerByID(args.Player.Index); if (Player.IsLoggedIn) { Rectangle ply = new Rectangle((int)args.Player.X / 16, (int)args.Player.Y / 16, 1, 1); string availquests = "Available Quests: "; foreach (QuestRegion qr in QMain.QuestRegions) { if (ply.Intersects(qr.Area)) { foreach (Quest q in qr.Quests) { QuestPlayerData data = QTools.GetPlayerQuestData(q.Name, Player); if (QTools.AbleToRunQuest(q) && (q.MinQuestsNeeded == 0 || q.MinQuestsNeeded <= QTools.GetQuestsCompleted(Player.MyDBPlayer.QuestPlayerData)) && (q.MaxAttemps == 0 || data == null || QTools.GetPlayerQuestData(q.Name, Player).Attempts < q.MaxAttemps)) { availquests = availquests + q.Name + ", "; } } } } if (availquests != "Available Quests: ") { availquests = availquests.Substring(0, availquests.Length - 2); Player.TSPlayer.SendMessage(availquests, Color.Magenta); Player.TSPlayer.SendMessage("Use /startquest [Quest Name], to begin that quest", Color.Magenta); } else { Player.TSPlayer.SendMessage("No Available Quests", Color.Red); } } else { Player.TSPlayer.SendMessage("You are not Logged in", Color.Red); } }
public static void GiveQuest(CommandArgs args) { if (args.Parameters.Count > 1) { QPlayer ply; if ((ply = QTools.GetPlayerByName(args.Parameters[0])) != null) { Quest q; if ((q = QTools.GetQuestByName(args.Parameters[1])) != null) { ply.NewQuest(q); } else { args.Player.SendMessage("Quest does not exist!", Color.Red); } } else { args.Player.SendMessage("Player does not exist!", Color.Red); } } }
public static void LoadQuestData() { QMain.QuestPool = new List <Quest>(); QMain.QuestRegions = new List <QuestRegion>(); QMain.StoredPlayers = new List <StoredQPlayer>(); if (!Directory.Exists("Quests")) { Directory.CreateDirectory("Quests"); } string[] filePaths = Directory.GetFiles("Quests", "*.lua"); foreach (string path in filePaths) { try { string[] configfile = File.ReadAllLines(path.Split('.')[0] + ".cfg"); string Name = ""; int MaxAttempts = 0; int MinQuestsNeeded = 0; int AmountOfPlayersAtATime = 0; bool endondeath = false; foreach (string line in configfile) { if (line.Trim().StartsWith("Name")) { Name = line.Trim().Split(':')[1]; } if (line.Trim().StartsWith("MaxAttempts")) { MaxAttempts = Int32.Parse(line.Trim().Split(':')[1]); } if (line.Trim().StartsWith("MinQuestsNeeded")) { MinQuestsNeeded = Int32.Parse(line.Trim().Split(':')[1]); } if (line.Trim().StartsWith("AmountOfPlayersAtATime")) { AmountOfPlayersAtATime = Int32.Parse(line.Trim().Split(':')[1]); } if (line.Trim().StartsWith("EndOnDeath")) { endondeath = bool.Parse(line.Trim().Split(':')[1]); } } QMain.QuestPool.Add(new Quest(Name, path, MinQuestsNeeded, MaxAttempts, AmountOfPlayersAtATime, endondeath)); } catch { } } for (int i = 0; i < QMain.SQLEditor.ReadColumn("QuestPlayers", "LogInName", new List <SqlValue>()).Count; i++) { string qname = QMain.SQLEditor.ReadColumn("QuestPlayers", "LogInName", new List <SqlValue>())[i].ToString(); string questdata = QMain.SQLEditor.ReadColumn("QuestPlayers", "QuestPlayerData", new List <SqlValue>())[i].ToString(); List <QuestPlayerData> playerdata = new List <QuestPlayerData>(); foreach (string data in questdata.Split(':')) { try { if (data != "") { string name = data.Split(',')[0]; bool complete = bool.Parse(data.Split(',')[1]); int attempts = int.Parse(data.Split(',')[2]); playerdata.Add(new QuestPlayerData(name, complete, attempts)); } } catch { } } QMain.StoredPlayers.Add(new StoredQPlayer(qname, playerdata)); } for (int i = 0; i < QMain.SQLEditor.ReadColumn("QuestRegions", "RegionName", new List <SqlValue>()).Count; i++) { try { string name = QMain.SQLEditor.ReadColumn("QuestRegions", "RegionName", new List <SqlValue>())[i].ToString(); int X1 = int.Parse(QMain.SQLEditor.ReadColumn("QuestRegions", "X1", new List <SqlValue>())[i].ToString()); int Y1 = int.Parse(QMain.SQLEditor.ReadColumn("QuestRegions", "Y1", new List <SqlValue>())[i].ToString()); int X2 = int.Parse(QMain.SQLEditor.ReadColumn("QuestRegions", "X2", new List <SqlValue>())[i].ToString()); int Y2 = int.Parse(QMain.SQLEditor.ReadColumn("QuestRegions", "Y2", new List <SqlValue>())[i].ToString()); string Quests = QMain.SQLEditor.ReadColumn("QuestRegions", "Quests", new List <SqlValue>())[i].ToString(); string Entry = QMain.SQLEditor.ReadColumn("QuestRegions", "EntryMessage", new List <SqlValue>())[i].ToString(); string Exit = QMain.SQLEditor.ReadColumn("QuestRegions", "ExitMessage", new List <SqlValue>())[i].ToString(); List <Quest> quests = new List <Quest>(); foreach (string quest in Quests.Split(',')) { Quest q = QTools.GetQuestByName(quest); if (q != null) { quests.Add(q); } } QMain.QuestRegions.Add(new QuestRegion(name, quests, X1, Y1, X2, Y2, Entry, Exit)); } catch { } } }
} //In Wiki public static void StartQuest(string qname, QPlayer Player) { Player.NewQuest(QTools.GetQuestByName(qname), true); }
public static void DeleteWall(int x, int y) { Main.tile[x, y].wall = 0; QTools.UpdateTile(x, y); }
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); }
public static void LoadQuestData(CommandArgs args) { QTools.LoadQuestData(); args.Player.SendMessage("Successfully Loaded Quest Data!"); }
public static void QuestRegion(CommandArgs args) { if (args.Parameters.Count > 0) { switch (args.Parameters[0].ToLower()) { case "name": { var player = QTools.GetPlayerByID(args.Player.Index); args.Player.SendMessage("Hit a block to get the name of the Quest Region", Color.Yellow); player.AwaitingQRName = true; break; } case "define": { if (args.Parameters.Count > 1) { if (!args.Player.TempPoints.Any(p => p == Point.Zero)) { string qregionName = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1)); var x = Math.Min(args.Player.TempPoints[0].X, args.Player.TempPoints[1].X); var y = Math.Min(args.Player.TempPoints[0].Y, args.Player.TempPoints[1].Y); var width = Math.Abs(args.Player.TempPoints[0].X - args.Player.TempPoints[1].X); var height = Math.Abs(args.Player.TempPoints[0].Y - args.Player.TempPoints[1].Y); QMain.QuestRegions.Add(new QuestRegion(qregionName, new List <Quest>(), x, y, width + x, height + y, "Entered Quest Region: " + qregionName, "Left Quest Region: " + qregionName)); args.Player.SendMessage(string.Format("Added new Quest Region: \"{0}\"", qregionName), Color.Yellow); QTools.UpdateRegionsInDB(); } else { args.Player.SendMessage("Points not set up yet", Color.Red); } } else { args.Player.SendMessage("Invalid syntax! Proper syntax: /questr define [name]", Color.Red); } break; } case "add": { if (args.Parameters.Count > 2) { string rName = args.Parameters[1]; string qName = args.Parameters[2]; Quest q = QTools.GetQuestByName(qName); QuestRegion r = QTools.GetRegionByName(rName); if (r != null && q != null) { args.Player.SendMessage(string.Format("Added Quest: \"{0}\" to the Quest Region: \"{1}\"", q.Name, r.Name), Color.Yellow); r.Quests.Add(q); QTools.UpdateRegionsInDB(); } else if (r == null) { args.Player.SendMessage("Invalid Quest Region Name", Color.Red); } else if (q == null) { args.Player.SendMessage("Invalid Quest Name", Color.Red); } } else { args.Player.SendMessage("Invalid syntax! Proper syntax: /questr add [RegionName] [QuestName]", Color.Red); } break; } case "delete": { if (args.Parameters.Count > 1) { string questregionName = string.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1)); foreach (QuestRegion qr in QMain.QuestRegions) { if (qr.Name == questregionName) { QMain.QuestRegions.Remove(qr); break; } } QTools.UpdateRegionsInDB(); args.Player.SendMessage("Quest Region: " + questregionName + " deleted", Color.Yellow); } else { args.Player.SendMessage("Invalid syntax! Proper syntax: /questr delete [region]", Color.Red); } break; } case "list": { const int pagelimit = 15; const int perline = 5; int page = 0; if (args.Parameters.Count > 1) { if (!int.TryParse(args.Parameters[1], out page) || page < 1) { args.Player.SendMessage(string.Format("Invalid page number ({0})", page), Color.Red); return; } page--; } if (QMain.QuestRegions.Count == 0) { args.Player.SendMessage("There are currently no Quest Regions defined.", Color.Red); return; } int pagecount = QMain.QuestRegions.Count / pagelimit; if (page > pagecount) { args.Player.SendMessage(string.Format("Page number exceeds pages ({0}/{1})", page + 1, pagecount + 1), Color.Red); return; } args.Player.SendMessage(string.Format("Current Quest Regions ({0}/{1}):", page + 1, pagecount + 1), Color.Green); var nameslist = new List <string>(); for (int i = (page * pagelimit); (i < ((page * pagelimit) + pagelimit)) && i < QMain.QuestRegions.Count; i++) { nameslist.Add(QMain.QuestRegions[i].Name); } var names = nameslist.ToArray(); for (int i = 0; i < names.Length; i += perline) { args.Player.SendMessage(string.Join(", ", names, i, Math.Min(names.Length - i, perline)), Color.Yellow); } if (page < pagecount) { args.Player.SendMessage(string.Format("Type /questr list {0} for more Quest Regions.", (page + 2)), Color.Yellow); } break; } } } }