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 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 RunQuest(object RunQuestOb) { Lua lua = new Lua(); QFunctions functions = new QFunctions(); //Updated In 1.1 lua.RegisterFunction("AtXY", functions, functions.GetType().GetMethod("AtXY")); //int x, int y, QPlayer Player lua.RegisterFunction("TileEdit", functions, functions.GetType().GetMethod("TileEdit")); //int x, int y, string tile lua.RegisterFunction("WallEdit", functions, functions.GetType().GetMethod("WallEdit")); //int x, int y, string wall lua.RegisterFunction("DeleteBoth", functions, functions.GetType().GetMethod("DeleteBoth")); //int x, int y lua.RegisterFunction("DeleteWall", functions, functions.GetType().GetMethod("DeleteWall")); //int x, int y lua.RegisterFunction("DeleteTile", functions, functions.GetType().GetMethod("DeleteTile")); //int x, int y lua.RegisterFunction("Sleep", functions, functions.GetType().GetMethod("Sleep")); //int time lua.RegisterFunction("Teleport", functions, functions.GetType().GetMethod("Teleport")); //int x, int y, QPlayer Player lua.RegisterFunction("ClearKillList", functions, functions.GetType().GetMethod("ClearKillList")); //QPlayer Player lua.RegisterFunction("GoCollectItem", functions, functions.GetType().GetMethod("GoCollectItem")); //string itemname, int amount, QPlayer Player lua.RegisterFunction("TakeItem", functions, functions.GetType().GetMethod("TakeItem")); //string qname, string iname, int amt, QPlayer Player lua.RegisterFunction("GetRegionTilePercentage", functions, functions.GetType().GetMethod("GetRegionTilePercentage")); //string tiletype, string regionname lua.RegisterFunction("GetXYTilePercentage", functions, functions.GetType().GetMethod("GetXYTilePercentage")); //string tiletype, int X, int Y, int Width, int Height lua.RegisterFunction("GetRegionWallPercentage", functions, functions.GetType().GetMethod("GetRegionWallPercentage")); //string walltype, string regionname lua.RegisterFunction("GetXYWallPercentage", functions, functions.GetType().GetMethod("GetXYWallPercentage")); //string walltype, int X, int Y, int Width, int Height //Updated In 1.2 lua.RegisterFunction("Give", functions, functions.GetType().GetMethod("Give")); //string name, QPlayer Player lua.RegisterFunction("Kill", functions, functions.GetType().GetMethod("Kill")); //string name, QPlayer Player, int amount = 1 lua.RegisterFunction("KillNpc", functions, functions.GetType().GetMethod("KillNpc")); //int id lua.RegisterFunction("StartQuest", functions, functions.GetType().GetMethod("StartQuest")); //string qname, QPlayer Player lua.RegisterFunction("ReadNextChatLine", functions, functions.GetType().GetMethod("ReadNextChatLine")); //QPlayer Player, bool hide = false lua.RegisterFunction("SetNPCHealth", functions, functions.GetType().GetMethod("SetNPCHealth")); //int id, int health lua.RegisterFunction("Private", functions, functions.GetType().GetMethod("Private")); //string message, QPlayer Player, Color color lua.RegisterFunction("Broadcast", functions, functions.GetType().GetMethod("Broadcast")); //string message, Color color lua.RegisterFunction("SpawnMob", functions, functions.GetType().GetMethod("SpawnMob")); //string name, int x, int y, int amount = 1 var parameters = (RunQuestParameters)RunQuestOb; QuestPlayerData qdata = null; if ((qdata = GetPlayerQuestData(parameters.Quest.Name, parameters.Player)) != null) { qdata.Attempts++; } else { qdata = new QuestPlayerData(parameters.Quest.Name, false, 0); parameters.Player.MyDBPlayer.QuestPlayerData.Add(qdata); qdata.Attempts++; } parameters.Player.RunningQuests.Add(parameters.Quest.Name); object[] returnvalues = new object[1]; try { lua["Player"] = parameters.Player; lua["Name"] = parameters.Player.TSPlayer.Name; lua["QName"] = parameters.Quest.Name; lua["Color"] = new Color(); returnvalues = lua.DoFile(parameters.Quest.FilePath); if (returnvalues == null || returnvalues[0] == null || (bool)returnvalues[0]) { qdata.Complete = true; } UpdateStoredPlayersInDB(); parameters.Player.RunningQuests.Remove(parameters.Quest.Name); parameters.Player.RunningQuestThreads.Remove(parameters); } catch (LuaException e) { Log.Error(e.Message); parameters.Player.RunningQuests.Remove(parameters.Quest.Name); parameters.Player.RunningQuestThreads.Remove(parameters); UpdateStoredPlayersInDB(); } catch { parameters.Player.RunningQuests.Remove(parameters.Quest.Name); parameters.Player.RunningQuestThreads.Remove(parameters); UpdateStoredPlayersInDB(); } }
public static void RunQuest(object RunQuestOb) { Lua lua = new Lua(); QFunctions functions = new QFunctions(); //Updated In 1.1 lua.RegisterFunction("AtXY", functions, functions.GetType().GetMethod("AtXY")); //int x, int y, QPlayer Player lua.RegisterFunction("TileEdit", functions, functions.GetType().GetMethod("TileEdit")); //int x, int y, string tile lua.RegisterFunction("WallEdit", functions, functions.GetType().GetMethod("WallEdit")); //int x, int y, string wall lua.RegisterFunction("DeleteBoth", functions, functions.GetType().GetMethod("DeleteBoth")); //int x, int y lua.RegisterFunction("DeleteWall", functions, functions.GetType().GetMethod("DeleteWall")); //int x, int y lua.RegisterFunction("DeleteTile", functions, functions.GetType().GetMethod("DeleteTile")); //int x, int y lua.RegisterFunction("Sleep", functions, functions.GetType().GetMethod("Sleep")); //int time lua.RegisterFunction("Teleport", functions, functions.GetType().GetMethod("Teleport")); //int x, int y, QPlayer Player lua.RegisterFunction("ClearKillList", functions, functions.GetType().GetMethod("ClearKillList")); //QPlayer Player lua.RegisterFunction("GoCollectItem", functions, functions.GetType().GetMethod("GoCollectItem")); //string itemname, int amount, QPlayer Player lua.RegisterFunction("TakeItem", functions, functions.GetType().GetMethod("TakeItem")); //string qname, string iname, int amt, QPlayer Player lua.RegisterFunction("GetRegionTilePercentage", functions, functions.GetType().GetMethod("GetRegionTilePercentage")); //string tiletype, string regionname lua.RegisterFunction("GetXYTilePercentage", functions, functions.GetType().GetMethod("GetXYTilePercentage")); //string tiletype, int X, int Y, int Width, int Height lua.RegisterFunction("GetRegionWallPercentage", functions, functions.GetType().GetMethod("GetRegionWallPercentage")); //string walltype, string regionname lua.RegisterFunction("GetXYWallPercentage", functions, functions.GetType().GetMethod("GetXYWallPercentage"));//string walltype, int X, int Y, int Width, int Height //Updated In 1.2 lua.RegisterFunction("Give", functions, functions.GetType().GetMethod("Give")); //string name, QPlayer Player lua.RegisterFunction("Kill", functions, functions.GetType().GetMethod("Kill")); //string name, QPlayer Player, int amount = 1 lua.RegisterFunction("KillNpc", functions, functions.GetType().GetMethod("KillNpc")); //int id lua.RegisterFunction("StartQuest", functions, functions.GetType().GetMethod("StartQuest")); //string qname, QPlayer Player lua.RegisterFunction("ReadNextChatLine", functions, functions.GetType().GetMethod("ReadNextChatLine")); //QPlayer Player, bool hide = false lua.RegisterFunction("SetNPCHealth", functions, functions.GetType().GetMethod("SetNPCHealth")); //int id, int health lua.RegisterFunction("Private", functions, functions.GetType().GetMethod("Private")); //string message, QPlayer Player, Color color lua.RegisterFunction("Broadcast", functions, functions.GetType().GetMethod("Broadcast")); //string message, Color color lua.RegisterFunction("SpawnMob", functions, functions.GetType().GetMethod("SpawnMob")); //string name, int x, int y, int amount = 1 var parameters = (RunQuestParameters)RunQuestOb; QuestPlayerData qdata = null; if ((qdata = GetPlayerQuestData(parameters.Quest.Name, parameters.Player)) != null) qdata.Attempts++; else { qdata = new QuestPlayerData(parameters.Quest.Name, false, 0); parameters.Player.MyDBPlayer.QuestPlayerData.Add(qdata); qdata.Attempts++; } parameters.Player.RunningQuests.Add(parameters.Quest.Name); object[] returnvalues = new object[1]; try { lua["Player"] = parameters.Player; lua["Name"] = parameters.Player.TSPlayer.Name; lua["QName"] = parameters.Quest.Name; lua["Color"] = new Color(); returnvalues = lua.DoFile(parameters.Quest.FilePath); if (returnvalues == null || returnvalues[0] == null || (bool)returnvalues[0]) qdata.Complete = true; UpdateStoredPlayersInDB(); parameters.Player.RunningQuests.Remove(parameters.Quest.Name); parameters.Player.RunningQuestThreads.Remove(parameters); } catch (LuaException e) { Log.Error(e.Message); parameters.Player.RunningQuests.Remove(parameters.Quest.Name); parameters.Player.RunningQuestThreads.Remove(parameters); UpdateStoredPlayersInDB(); } catch { parameters.Player.RunningQuests.Remove(parameters.Quest.Name); parameters.Player.RunningQuestThreads.Remove(parameters); UpdateStoredPlayersInDB(); } }