Advertisement
Cryptextitannation

Untitled

Aug 3rd, 2023
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 156.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using Oxide.Core;
  6. using Oxide.Core.Configuration;
  7. using Oxide.Core.Libraries.Covalence;
  8. using Oxide.Core.Plugins;
  9. using Oxide.Game.Rust.Cui;
  10. using UnityEngine;
  11.  
  12. // ToDo: ZLevels integration (waiting for ZLevels api implementation)
  13. // ToDo: Add Cooldown option for Delivery
  14.  
  15. namespace Oxide.Plugins
  16. {
  17. [Info("Quests", "Gonzi", "2.4.3")]
  18. [Description("Creates quests for players to go on to earn rewards, complete with a GUI menu")]
  19. public class Quests : RustPlugin
  20. {
  21. #region Fields
  22. [PluginReference] Plugin HumanNPC;
  23. [PluginReference] Plugin ServerRewards;
  24. [PluginReference] Plugin Economics;
  25. [PluginReference] Plugin LustyMap;
  26. [PluginReference] Plugin EventManager;
  27. [PluginReference] Plugin HuntRPG;
  28. [PluginReference] Plugin PlayerChallenges;
  29. [PluginReference] Plugin BetterChat;
  30.  
  31. ConfigData configData;
  32.  
  33. QuestData questData;
  34. PlayerData playerData;
  35. NPCData vendors;
  36. ItemNames itemNames;
  37. private DynamicConfigFile Quest_Data;
  38. private DynamicConfigFile Player_Data;
  39. private DynamicConfigFile Quest_Vendors;
  40. private DynamicConfigFile Item_Names;
  41.  
  42. private Dictionary<ulong, PlayerQuestData> PlayerProgress;
  43. private Dictionary<QuestType, Dictionary<string, QuestEntry>> Quest;
  44.  
  45. private Dictionary<string, ItemDefinition> ItemDefs;
  46. private Dictionary<string, string> DisplayNames = new Dictionary<string, string>();
  47.  
  48. private Dictionary<ulong, QuestCreator> ActiveCreations = new Dictionary<ulong, QuestCreator>();
  49. private Dictionary<ulong, QuestCreator> ActiveEditors = new Dictionary<ulong, QuestCreator>();
  50.  
  51. private Dictionary<ulong, bool> AddVendor = new Dictionary<ulong, bool>();
  52.  
  53. private Dictionary<QuestType, List<string>> AllObjectives = new Dictionary<QuestType, List<string>>();
  54. private Dictionary<NetworkableId, Dictionary<ulong, int>> HeliAttackers = new Dictionary<NetworkableId, Dictionary<ulong, int>>();
  55.  
  56. private Dictionary<ulong, List<string>> OpenUI = new Dictionary<ulong, List<string>>();
  57. private Dictionary<ItemId, ulong> Looters = new Dictionary<ItemId, ulong>();
  58.  
  59. private List<ulong> StatsMenu = new List<ulong>();
  60. private List<ulong> OpenMenuBind = new List<ulong>();
  61.  
  62. static string UIMain = "UIMain";
  63. static string UIPanel = "UIPanel";
  64. static string UIEntry = "UIEntry";
  65.  
  66. static string permission_manage = "quests.manage";
  67. static string permission_use = "quests.use";
  68.  
  69. private string textPrimary;
  70. private string textSecondary;
  71. #endregion
  72.  
  73. #region Classes
  74.  
  75. class PlayerQuestData
  76. {
  77. public Dictionary<string, PlayerQuestInfo> Quests = new Dictionary<string, PlayerQuestInfo>();
  78. public List<QuestInfo> RequiredItems = new List<QuestInfo>();
  79. public ActiveDelivery CurrentDelivery = new ActiveDelivery();
  80. }
  81.  
  82. class PlayerQuestInfo
  83. {
  84. public QuestStatus Status;
  85. public QuestType Type;
  86. public int AmountCollected = 0;
  87. public bool RewardClaimed = false;
  88. public double ResetTime = 0;
  89. }
  90.  
  91. class QuestEntry
  92. {
  93. public string QuestName;
  94. public string Description;
  95. public string Objective;
  96. public string ObjectiveName;
  97. public int AmountRequired;
  98. public int Cooldown;
  99. public bool ItemDeduction;
  100. public List<RewardItem> Rewards;
  101. }
  102.  
  103. class NPCInfo
  104. {
  105. public float x;
  106. public float z;
  107. public string ID;
  108. public string Name;
  109. }
  110.  
  111. class DeliveryInfo
  112. {
  113. public string Description;
  114. public NPCInfo Info;
  115. public RewardItem Reward;
  116. public float Multiplier;
  117. }
  118.  
  119. class ActiveDelivery
  120. {
  121. public string VendorID;
  122. public string TargetID;
  123. public float Distance;
  124. }
  125.  
  126. class QuestInfo
  127. {
  128. public string ShortName;
  129. public QuestType Type;
  130. }
  131.  
  132. class RewardItem
  133. {
  134. public bool isRP = false;
  135. public bool isCoins = false;
  136. public bool isHuntXP = false;
  137. public string DisplayName;
  138. public string ShortName;
  139. public int ID;
  140. public float Amount;
  141. public bool BP;
  142. public ulong Skin;
  143. }
  144.  
  145. class QuestCreator
  146. {
  147. public QuestType type;
  148. public QuestEntry entry;
  149. public DeliveryInfo deliveryInfo;
  150. public RewardItem item;
  151. public string oldEntry;
  152. public int partNum;
  153. }
  154.  
  155. class ItemNames
  156. {
  157. public Dictionary<string, string> DisplayNames = new Dictionary<string, string>();
  158. }
  159.  
  160. enum QuestType
  161. {
  162. Kill,
  163. Craft,
  164. Gather,
  165. Loot,
  166. Delivery
  167. }
  168.  
  169. enum QuestStatus
  170. {
  171. Pending,
  172. Completed,
  173. Open
  174. }
  175.  
  176. #endregion
  177.  
  178. #region UI Creation
  179.  
  180. class QUI
  181. {
  182. public static bool disableFade;
  183.  
  184. static public CuiElementContainer CreateElementContainer(string panelName, string color, string aMin, string aMax, bool cursor = false)
  185. {
  186. var NewElement = new CuiElementContainer()
  187. {
  188. {
  189. new CuiPanel
  190. {
  191. Image = {Color = color},
  192. RectTransform = {AnchorMin = aMin, AnchorMax = aMax},
  193. CursorEnabled = cursor
  194. },
  195. new CuiElement().Parent = "Overlay",
  196. panelName
  197. }
  198. };
  199. return NewElement;
  200. }
  201.  
  202. static public void CreatePanel(ref CuiElementContainer container, string panel, string color, string aMin, string aMax, bool cursor = false)
  203. {
  204. container.Add(new CuiPanel
  205. {
  206. Image = { Color = color },
  207. RectTransform = { AnchorMin = aMin, AnchorMax = aMax },
  208. CursorEnabled = cursor
  209. },
  210. panel);
  211. }
  212.  
  213. static public void CreateLabel(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter, float fadein = 1.0f)
  214. {
  215. if (disableFade)
  216. fadein = 0;
  217. container.Add(new CuiLabel
  218. {
  219. Text = { Color = color, FontSize = size, Align = align, FadeIn = fadein, Text = text },
  220. RectTransform = { AnchorMin = aMin, AnchorMax = aMax }
  221. },
  222. panel);
  223. }
  224.  
  225. static public void CreateButton(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, string command, TextAnchor align = TextAnchor.MiddleCenter, float fadein = 1.0f)
  226. {
  227. if (disableFade)
  228. fadein = 0;
  229. container.Add(new CuiButton
  230. {
  231. Button = { Color = color, Command = command, FadeIn = fadein },
  232. RectTransform = { AnchorMin = aMin, AnchorMax = aMax },
  233. Text = { Text = text, FontSize = size, Align = align }
  234. },
  235. panel);
  236. }
  237.  
  238. static public void LoadImage(ref CuiElementContainer container, string panel, string png, string aMin, string aMax)
  239. {
  240. container.Add(new CuiElement
  241. {
  242. Parent = panel,
  243. Components =
  244. {
  245. new CuiRawImageComponent {Png = png},
  246. new CuiRectTransformComponent {AnchorMin = aMin, AnchorMax = aMax}
  247. }
  248. });
  249. }
  250.  
  251. static public void CreateTextOverlay(ref CuiElementContainer container, string panel, string text, string color, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter, float fadein = 1.0f)
  252. {
  253. if (disableFade)
  254. fadein = 0;
  255. container.Add(new CuiLabel
  256. {
  257. Text = { Color = color, FontSize = size, Align = align, FadeIn = fadein, Text = text },
  258. RectTransform = { AnchorMin = aMin, AnchorMax = aMax }
  259. },
  260. panel);
  261. }
  262.  
  263. static public string Color(string hexColor, float alpha)
  264. {
  265. if (hexColor.StartsWith("#"))
  266. hexColor = hexColor.TrimStart('#');
  267. int red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
  268. int green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
  269. int blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
  270. return $"{(double)red / 255} {(double)green / 255} {(double)blue / 255} {alpha}";
  271. }
  272. }
  273.  
  274. #endregion
  275.  
  276. #region Oxide Hooks
  277.  
  278. void Loaded()
  279. {
  280. permission.RegisterPermission(permission_use, this);
  281. permission.RegisterPermission(permission_manage, this);
  282. Quest_Data = Interface.Oxide.DataFileSystem.GetFile("Quests/quests_data");
  283. Player_Data = Interface.Oxide.DataFileSystem.GetFile("Quests/quests_players");
  284. Quest_Vendors = Interface.Oxide.DataFileSystem.GetFile("Quests/quests_vendors");
  285. Item_Names = Interface.Oxide.DataFileSystem.GetFile("Quests/quests_itemnames");
  286. lang.RegisterMessages(Localization, this);
  287. }
  288.  
  289. void OnServerInitialized()
  290. {
  291. LoadVariables();
  292. LoadData();
  293.  
  294. QUI.disableFade = configData.DisableUI_FadeIn;
  295. textPrimary = $"<color={configData.Colors.TextColor_Primary}>";
  296. textSecondary = $"<color={configData.Colors.TextColor_Secondary}>";
  297.  
  298. ItemDefs = ItemManager.itemList.ToDictionary(i => i.shortname);
  299. FillObjectiveList();
  300. AddMapIcons();
  301. timer.Once(900, () => SaveLoop());
  302. }
  303.  
  304. void Unload()
  305. {
  306. foreach (var player in BasePlayer.activePlayerList)
  307. DestroyUI(player);
  308. SavePlayerData();
  309. }
  310.  
  311. void OnPlayerConnected(BasePlayer player)
  312. {
  313. if (configData.KeybindOptions.Autoset_KeyBind)
  314. {
  315. if (!string.IsNullOrEmpty(configData.KeybindOptions.KeyBind_Key))
  316. {
  317. player.Command("bind " + configData.KeybindOptions.KeyBind_Key + " QUI_OpenQuestMenu");
  318. }
  319. }
  320. }
  321.  
  322. #region Objective Hooks
  323.  
  324. //Kill
  325. void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
  326. {
  327. try
  328. {
  329. if (entity == null || info == null) return;
  330. string entname = entity?.ShortPrefabName;
  331. if (entname == "testridablehorse")
  332. {
  333. entname = "horse";
  334. }
  335.  
  336. if ((entname.Contains("scientist")) && (!entname.Contains("corpse")))
  337. {
  338. entname = "scientist";
  339. }
  340.  
  341. BasePlayer player = null;
  342.  
  343. if (info.InitiatorPlayer != null)
  344. player = info.InitiatorPlayer;
  345. else if (entity.GetComponent<BaseHelicopter>() != null)
  346. player = BasePlayer.FindByID(GetLastAttacker(entity.net.ID));
  347.  
  348. if (player != null)
  349. {
  350. if (entity.ToPlayer() != null && entity.ToPlayer() == player) return;
  351. if (isPlaying(player)) return;
  352. if (hasQuests(player.userID) && isQuestItem(player.userID, entname, QuestType.Kill))
  353. ProcessProgress(player, QuestType.Kill, entname);
  354. }
  355. }
  356. catch (Exception ex)
  357. {
  358. PrintWarning("Error at hook OnEntityDeath:\n" + ex);
  359. }
  360. }
  361.  
  362. void OnEntityTakeDamage(BaseCombatEntity victim, HitInfo info)
  363. {
  364. if (victim.GetComponent<BaseHelicopter>() != null && info?.Initiator?.ToPlayer() != null)
  365. {
  366. var heli = victim.GetComponent<BaseHelicopter>();
  367. var player = info.Initiator.ToPlayer();
  368. if (isPlaying(player)) return;
  369. NextTick(() =>
  370. {
  371. if (heli == null) return;
  372. if (!HeliAttackers.ContainsKey(heli.net.ID))
  373. HeliAttackers.Add(heli.net.ID, new Dictionary<ulong, int>());
  374. if (!HeliAttackers[heli.net.ID].ContainsKey(player.userID))
  375. HeliAttackers[heli.net.ID].Add(player.userID, 0);
  376. HeliAttackers[heli.net.ID][player.userID]++;
  377. });
  378. }
  379. }
  380.  
  381. // Gather
  382. void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item)
  383. {
  384. BasePlayer player = entity?.ToPlayer();
  385. if (player != null)
  386. if (hasQuests(player.userID) && isQuestItem(player.userID, item.info.shortname, QuestType.Gather))
  387. ProcessProgress(player, QuestType.Gather, item.info.shortname, item.amount);
  388. }
  389.  
  390. void OnDispenserBonus(ResourceDispenser dispenser, BaseEntity entity, Item item) => OnDispenserGather(dispenser, entity, item);
  391.  
  392. void OnGrowableGather(GrowableEntity growable, Item item, BasePlayer player)
  393. {
  394. if (player != null)
  395. if (hasQuests(player.userID) && isQuestItem(player.userID, item.info.shortname, QuestType.Gather))
  396. ProcessProgress(player, QuestType.Gather, item.info.shortname, item.amount);
  397. }
  398.  
  399. void OnCollectiblePickup(CollectibleEntity collectible, BasePlayer player)
  400. {
  401. if (player != null)
  402. foreach (ItemAmount itemAmount in collectible.itemList)
  403. if (hasQuests(player.userID) && isQuestItem(player.userID, itemAmount.itemDef.shortname, QuestType.Gather))
  404. ProcessProgress(player, QuestType.Gather, itemAmount.itemDef.shortname, (int)itemAmount.amount);
  405. }
  406.  
  407. //Craft
  408. void OnItemCraftFinished(ItemCraftTask task, Item item, ItemCrafter itemCrafter)
  409. {
  410. var player = itemCrafter.owner;
  411. if (player != null)
  412. if (hasQuests(player.userID) && isQuestItem(player.userID, item.info.shortname, QuestType.Craft))
  413. ProcessProgress(player, QuestType.Craft, item.info.shortname, item.amount);
  414. }
  415.  
  416. //Loot
  417. void OnItemAddedToContainer(ItemContainer container, Item item)
  418. {
  419. if (Looters.ContainsKey(item.uid))
  420. {
  421. if (container.playerOwner != null)
  422. {
  423. if (Looters[item.uid] != container.playerOwner.userID)
  424. {
  425. if (hasQuests(container.playerOwner.userID) && isQuestItem(container.playerOwner.userID, item.info.shortname, QuestType.Loot))
  426. {
  427. ProcessProgress(container.playerOwner, QuestType.Loot, item.info.shortname, item.amount);
  428. Looters.Remove(item.uid);
  429. }
  430. }
  431. }
  432. }
  433. else if (container.playerOwner != null) Looters.Add(item.uid, container.playerOwner.userID);
  434. }
  435.  
  436. void OnItemRemovedFromContainer(ItemContainer container, Item item)
  437. {
  438. ulong id = 0U;
  439. if (container.entityOwner != null)
  440. id = container.entityOwner.OwnerID;
  441. else if (container.playerOwner != null)
  442. id = container.playerOwner.userID;
  443.  
  444. if (!Looters.ContainsKey(item.uid))
  445. Looters.Add(item.uid, id);
  446. }
  447.  
  448. // Delivery and Vendors
  449. void OnUseNPC(BasePlayer npc, BasePlayer player)
  450. {
  451. if (player == null || npc == null) return;
  452. CheckPlayerEntry(player);
  453. var npcID = npc.UserIDString;
  454. if (vendors.QuestVendors.ContainsKey(npcID) && configData.UseNPCVendors)
  455. {
  456. CreateMenu(player);
  457. return;
  458. }
  459.  
  460. if (vendors.DeliveryVendors.ContainsKey(npcID))
  461. {
  462. if (hasQuests(player.userID) && PlayerProgress[player.userID].CurrentDelivery.TargetID == npc.UserIDString)
  463. AcceptDelivery(player, npcID, 1);
  464.  
  465. if (hasQuests(player.userID) && string.IsNullOrEmpty(PlayerProgress[player.userID].CurrentDelivery.TargetID))
  466. AcceptDelivery(player, npcID);
  467. else SendMSG(player, LA("delInprog", player.UserIDString), LA("Quests", player.UserIDString));
  468. }
  469. }
  470.  
  471. #endregion
  472.  
  473. object OnPlayerChat(BasePlayer player, string message)
  474. {
  475. if (BetterChat) return null;
  476. if (player == null) return null;
  477.  
  478. if (ActiveEditors.ContainsKey(player.userID) || ActiveCreations.ContainsKey(player.userID) || AddVendor.ContainsKey(player.userID))
  479. {
  480. QuestChat(player, message.Split(' '));
  481. return false;
  482. }
  483.  
  484. return null;
  485. }
  486.  
  487. object OnBetterChat(Dictionary<string, object> dict)
  488. {
  489. var player = (dict["Player"] as IPlayer).Object as BasePlayer;
  490. if (player == null) return null;
  491. string message = dict["Message"].ToString();
  492. if (ActiveEditors.ContainsKey(player.userID) || ActiveCreations.ContainsKey(player.userID) || AddVendor.ContainsKey(player.userID))
  493. {
  494. QuestChat(player, message.Split(' '));
  495. dict["CancelOption"] = 2;
  496. return dict;
  497. }
  498.  
  499. return dict;
  500. }
  501.  
  502. void QuestChat(BasePlayer player, string[] arg)
  503. {
  504. bool isEditing = false;
  505. bool isCreating = false;
  506. QuestCreator Creator = new QuestCreator();
  507. QuestEntry Quest = new QuestEntry();
  508.  
  509. // remove all html codes from the message (needed for colored chat messages)
  510. System.Text.RegularExpressions.Regex rmHTML = new System.Text.RegularExpressions.Regex("<[^>]*>");
  511. var args = rmHTML.Replace(string.Join(" ", arg), "");
  512. var argsForNumbers = rmHTML.Replace(arg[0], "");
  513.  
  514. if (ActiveEditors.ContainsKey(player.userID))
  515. {
  516. isEditing = true;
  517. Creator = ActiveEditors[player.userID];
  518. Quest = Creator.entry;
  519. }
  520. else if (ActiveCreations.ContainsKey(player.userID))
  521. {
  522. isCreating = true;
  523. Creator = ActiveCreations[player.userID];
  524. Quest = Creator.entry;
  525. }
  526.  
  527. if (AddVendor.ContainsKey(player.userID) && string.Join(" ", arg).Contains("exit"))
  528. {
  529. ExitQuest(player, true);
  530. return;
  531. }
  532.  
  533. if (!isEditing && !isCreating)
  534. return;
  535.  
  536. if (args.Contains("exit"))
  537. {
  538. ExitQuest(player, isCreating);
  539. return;
  540. }
  541.  
  542. if (args.Contains("quest item"))
  543. {
  544. var item = GetItem(player);
  545. if (item != null)
  546. {
  547. if (Creator.type != QuestType.Delivery)
  548. {
  549. Quest.Rewards.Add(item);
  550. Creator.partNum++;
  551. if (isCreating)
  552. CreationHelp(player, 7);
  553. else if (isEditing)
  554. {
  555. SaveRewardsEdit(player);
  556. CreationHelp(player, 10);
  557. }
  558. }
  559. else
  560. {
  561. Creator.deliveryInfo.Reward = item;
  562. DeliveryHelp(player, 4);
  563. }
  564. }
  565. else SendMSG(player, $"{LA("noAItem", player.UserIDString)}'quest item'", LA("QC", player.UserIDString));
  566.  
  567. return;
  568. }
  569.  
  570. switch (Creator.partNum)
  571. {
  572. case 0:
  573. foreach (var type in questData.Quest)
  574. {
  575. if (type.Value.ContainsKey(args))
  576. {
  577. SendMSG(player, LA("nameExists", player.UserIDString), LA("QC", player.UserIDString));
  578. return;
  579. }
  580. }
  581.  
  582. Quest.QuestName = args;
  583. SendMSG(player, args, "Name:");
  584. Creator.partNum++;
  585. if (isCreating)
  586. CreationHelp(player, 1);
  587. else CreationHelp(player, 6);
  588. return;
  589. case 2:
  590. {
  591. int amount;
  592. if (!int.TryParse(argsForNumbers, out amount))
  593. {
  594. SendMSG(player, LA("objAmount", player.UserIDString), LA("QC", player.UserIDString));
  595. return;
  596. }
  597.  
  598. Quest.AmountRequired = amount;
  599. SendMSG(player, argsForNumbers, LA("OA", player.UserIDString));
  600. Creator.partNum++;
  601. if (isCreating)
  602. CreationHelp(player, 3);
  603. else CreationHelp(player, 6);
  604. }
  605. return;
  606. case 3:
  607. {
  608. if (Creator.type == QuestType.Delivery)
  609. {
  610. Creator.deliveryInfo.Description = args;
  611. SendMSG(player, args, LA("Desc", player.UserIDString));
  612. DeliveryHelp(player, 6);
  613. return;
  614. }
  615.  
  616. Quest.Description = args;
  617. SendMSG(player, args, LA("Desc", player.UserIDString));
  618. Creator.partNum++;
  619. if (isCreating)
  620. CreationHelp(player, 4);
  621. else CreationHelp(player, 6);
  622. }
  623. return;
  624. case 5:
  625. {
  626. if (Creator.type == QuestType.Delivery)
  627. {
  628. float amount;
  629. if (!float.TryParse(argsForNumbers, out amount))
  630. {
  631. SendMSG(player, LA("noRM", player.UserIDString), LA("QC", player.UserIDString));
  632. return;
  633. }
  634.  
  635. Creator.deliveryInfo.Multiplier = amount;
  636.  
  637. SendMSG(player, argsForNumbers, LA("RM", player.UserIDString));
  638. Creator.partNum++;
  639. DeliveryHelp(player, 5);
  640. }
  641. else
  642. {
  643. int amount;
  644. if (!int.TryParse(argsForNumbers, out amount))
  645. {
  646. SendMSG(player, LA("noRA", player.UserIDString), LA("QC", player.UserIDString));
  647. return;
  648. }
  649.  
  650. Creator.item.Amount = amount;
  651. Quest.Rewards.Add(Creator.item);
  652. Creator.item = new RewardItem();
  653. SendMSG(player, argsForNumbers, LA("RA", player.UserIDString));
  654. Creator.partNum++;
  655. if (isCreating)
  656. CreationHelp(player, 7);
  657. else if (isEditing)
  658. {
  659. SaveRewardsEdit(player);
  660. }
  661. }
  662.  
  663. return;
  664. }
  665. case 6:
  666. {
  667. int amount;
  668. if (!int.TryParse(argsForNumbers, out amount))
  669. {
  670. SendMSG(player, LA("noCD", player.UserIDString), LA("QC", player.UserIDString));
  671. return;
  672. }
  673.  
  674. Creator.entry.Cooldown = amount;
  675. SendMSG(player, argsForNumbers, LA("CD1", player.UserIDString));
  676. CreationHelp(player, 6);
  677. }
  678. return;
  679. default:
  680. break;
  681. }
  682. }
  683.  
  684. #endregion
  685.  
  686. #region External Calls
  687.  
  688. private bool isPlaying(BasePlayer player)
  689. {
  690. if (EventManager)
  691. {
  692. var inEvent = EventManager?.Call("isPlaying", player);
  693. if (inEvent is bool && (bool)inEvent)
  694. return true;
  695. }
  696.  
  697. return false;
  698. }
  699.  
  700. private void CloseMap(BasePlayer player)
  701. {
  702. if (LustyMap)
  703. {
  704. LustyMap.Call("DisableMaps", player);
  705. }
  706. }
  707.  
  708. private void OpenMap(BasePlayer player)
  709. {
  710. if (LustyMap)
  711. {
  712. LustyMap.Call("EnableMaps", player);
  713. }
  714. }
  715.  
  716. private void AddMapMarker(float x, float z, string name, string icon = "special", float r = 0)
  717. {
  718. if (LustyMap)
  719. LustyMap.Call("AddMarker", x, z, name, icon);
  720. }
  721.  
  722. private void RemoveMapMarker(string name)
  723. {
  724. if (LustyMap)
  725. LustyMap.Call("RemoveMarker", name);
  726. }
  727.  
  728. private object CanTeleport(BasePlayer player)
  729. {
  730. if (!PlayerProgress.ContainsKey(player.userID)) return null;
  731.  
  732. if (!string.IsNullOrEmpty(PlayerProgress[player.userID].CurrentDelivery.TargetID))
  733. {
  734. return LA("NoTP", player.UserIDString);
  735. }
  736. else
  737. return null;
  738. }
  739.  
  740. #endregion
  741.  
  742. #region Objective Lists
  743.  
  744. private void FillObjectiveList()
  745. {
  746. AllObjectives.Add(QuestType.Loot, new List<string>());
  747. AllObjectives.Add(QuestType.Craft, new List<string>());
  748. AllObjectives.Add(QuestType.Kill, new List<string>());
  749. AllObjectives.Add(QuestType.Gather, new List<string>());
  750. AllObjectives.Add(QuestType.Delivery, new List<string>());
  751. GetAllCraftables();
  752. GetAllItems();
  753. GetAllKillables();
  754. GetAllResources();
  755. foreach (var category in AllObjectives)
  756. category.Value.Sort();
  757.  
  758. if (itemNames.DisplayNames == null || itemNames.DisplayNames.Count < 1)
  759. {
  760. foreach (var item in ItemDefs)
  761. {
  762. if (!DisplayNames.ContainsKey(item.Key))
  763. DisplayNames.Add(item.Key, item.Value.displayName.translated);
  764. }
  765.  
  766. SaveDisplayNames();
  767. }
  768. else DisplayNames = itemNames.DisplayNames;
  769. }
  770.  
  771. private void GetAllItems()
  772. {
  773. foreach (var item in ItemManager.itemList)
  774. AllObjectives[QuestType.Loot].Add(item.shortname);
  775. }
  776.  
  777. private void GetAllCraftables()
  778. {
  779. foreach (var bp in ItemManager.bpList)
  780. if (bp.userCraftable)
  781. AllObjectives[QuestType.Craft].Add(bp.targetItem.shortname);
  782. }
  783.  
  784. private void GetAllResources()
  785. {
  786. AllObjectives[QuestType.Gather] = new List<string>
  787. {
  788. "wood",
  789. "stones",
  790. "metal.ore",
  791. "hq.metal.ore",
  792. "sulfur.ore",
  793. "cloth",
  794. "bone.fragments",
  795. "crude.oil",
  796. "fat.animal",
  797. "leather",
  798. "skull.wolf",
  799. "skull.human",
  800. "chicken.raw",
  801. "mushroom",
  802. "meat.boar",
  803. "bearmeat",
  804. "humanmeat.raw",
  805. "wolfmeat.raw"
  806. };
  807. }
  808.  
  809. private void GetAllKillables()
  810. {
  811. AllObjectives[QuestType.Kill] = new List<string>
  812. {
  813. "bear",
  814. "boar",
  815. "bradleyapc",
  816. "chicken",
  817. "horse",
  818. "stag",
  819. "wolf",
  820. "autoturret_deployed",
  821. "patrolhelicopter",
  822. "player",
  823. "scientist",
  824. "murderer",
  825. "tunneldweller",
  826. "underwaterdweller",
  827. "scarecrow",
  828. "simpleshark"
  829. };
  830. DisplayNames.Add("bear", "Bear");
  831. DisplayNames.Add("boar", "Boar");
  832. DisplayNames.Add("bradleyapc", "BradleyAPC");
  833. DisplayNames.Add("chicken", "Chicken");
  834. DisplayNames.Add("horse", "Horse");
  835. DisplayNames.Add("stag", "Stag");
  836. DisplayNames.Add("wolf", "Wolf");
  837. DisplayNames.Add("autoturret_deployed", "Auto-Turret");
  838. DisplayNames.Add("patrolhelicopter", "Helicopter");
  839. DisplayNames.Add("player", "Player");
  840. DisplayNames.Add("scientist", "Scientist");
  841. DisplayNames.Add("murderer", "Murderer");
  842. DisplayNames.Add("tunneldweller", "Tunneldweller");
  843. DisplayNames.Add("underwaterdweller", "Underwater Dweller");
  844. DisplayNames.Add("scarecrow", "Scarecrow");
  845. DisplayNames.Add("simpleshark", "Shark");
  846. }
  847.  
  848. #endregion
  849.  
  850. #region Functions
  851.  
  852. private bool isAdmin(BasePlayer player)
  853. {
  854. if (configData.UseOxidePermissions == true && permission.UserHasPermission(player.UserIDString, permission_manage) || player.IsAdmin && configData.UsePlayerIsAdmin == true) return true;
  855. else return false;
  856. }
  857.  
  858. void AddMapIcons()
  859. {
  860. int deliveryCount = 1;
  861. foreach (var vendor in vendors.DeliveryVendors)
  862. {
  863. AddMapMarker(vendor.Value.Info.x, vendor.Value.Info.z, vendor.Value.Info.Name, $"{configData.LustyMapIntegration.Icon_Delivery}_{deliveryCount}.png");
  864. ++deliveryCount;
  865. }
  866.  
  867. foreach (var vendor in vendors.QuestVendors)
  868. {
  869. AddMapMarker(vendor.Value.x, vendor.Value.z, vendor.Value.Name, $"{configData.LustyMapIntegration.Icon_Vendor}.png");
  870. }
  871. }
  872.  
  873. private void ProcessProgress(BasePlayer player, QuestType questType, string type, int amount = 0)
  874. {
  875. if (string.IsNullOrEmpty(type)) return;
  876. var data = PlayerProgress[player.userID];
  877. if (data.RequiredItems.Count > 0)
  878. {
  879. foreach (var entry in data.Quests.Where(x => x.Value.Status == QuestStatus.Pending))
  880. {
  881. var quest = GetQuest(entry.Key);
  882. if (quest != null)
  883. {
  884. if (type == quest.Objective)
  885. {
  886. if (amount > 0)
  887. {
  888. var amountRequired = quest.AmountRequired - entry.Value.AmountCollected;
  889. if (amount > amountRequired)
  890. amount = amountRequired;
  891. entry.Value.AmountCollected += amount;
  892.  
  893. if (quest.ItemDeduction)
  894. TakeQuestItem(player, type, amount);
  895. }
  896. else entry.Value.AmountCollected++;
  897.  
  898. if (entry.Value.AmountCollected >= quest.AmountRequired)
  899. CompleteQuest(player, entry.Key);
  900. return;
  901. }
  902. }
  903. }
  904. }
  905. }
  906.  
  907. private void TakeQuestItem(BasePlayer player, string item, int amount)
  908. {
  909. if (ItemDefs.ContainsKey(item))
  910. {
  911. var itemDef = ItemDefs[item];
  912. NextTick(() => player.inventory.Take(null, itemDef.itemid, amount));
  913. }
  914. else PrintWarning($"Unable to find definition for: {item}.");
  915. }
  916.  
  917. private void CompleteQuest(BasePlayer player, string questName)
  918. {
  919. var data = PlayerProgress[player.userID].Quests[questName];
  920. var items = PlayerProgress[player.userID].RequiredItems;
  921. var quest = GetQuest(questName);
  922. if (quest != null)
  923. {
  924. data.Status = QuestStatus.Completed;
  925. data.ResetTime = GrabCurrentTime() + (quest.Cooldown * 60);
  926.  
  927. for (int i = 0; i < items.Count; i++)
  928. {
  929. if (items[i].ShortName == quest.Objective && items[i].Type == data.Type)
  930. {
  931. items.Remove(items[i]);
  932. break;
  933. }
  934. }
  935.  
  936. SendMSG(player, "", $"{LA("qComple", player.UserIDString)} {questName}. {LA("claRew", player.UserIDString)}");
  937. PlayerChallenges?.Call("CompletedQuest", player);
  938. }
  939. }
  940.  
  941. private ItemDefinition FindItemDefinition(string shortname)
  942. {
  943. ItemDefinition itemDefinition;
  944. return ItemDefs.TryGetValue(shortname, out itemDefinition) ? itemDefinition : null;
  945. }
  946.  
  947. private string GetRewardString(List<RewardItem> entry)
  948. {
  949. var rewards = "";
  950. int i = 1;
  951. foreach (var item in entry)
  952. {
  953. rewards = rewards + $"{(int)item.Amount}x {item.DisplayName}";
  954. if (i < entry.Count)
  955. rewards = rewards + ", ";
  956. i++;
  957. }
  958.  
  959. return rewards;
  960. }
  961.  
  962. private bool GiveReward(BasePlayer player, List<RewardItem> rewards)
  963. {
  964. foreach (var reward in rewards)
  965. {
  966. if (reward.isCoins && Economics)
  967. {
  968. Economics.Call("Deposit", player.UserIDString, (double)reward.Amount);
  969. }
  970. else if (reward.isRP && ServerRewards)
  971. {
  972. ServerRewards.Call("AddPoints", player.userID, (int)reward.Amount);
  973. }
  974. else if (reward.isHuntXP)
  975. {
  976. HuntRPG?.Call("GiveEXP", player, (int)reward.Amount);
  977. }
  978. else
  979. {
  980. if (string.IsNullOrEmpty(reward.ShortName)) return true;
  981. var definition = FindItemDefinition(reward.ShortName);
  982. if (definition != null)
  983. {
  984. if (player.inventory.AllItems().Count() >= 30) return false;
  985. var item = ItemManager.Create(definition, (int)reward.Amount, reward.Skin);
  986. if (item != null)
  987. {
  988. player.inventory.GiveItem(item, player.inventory.containerMain);
  989. }
  990. }
  991. else PrintWarning($"Quests: Error building item {reward.ShortName} for {player.displayName}");
  992. }
  993. }
  994.  
  995. return true;
  996. }
  997.  
  998. private void ReturnItems(BasePlayer player, string itemname, int amount)
  999. {
  1000. if (amount > 0)
  1001. {
  1002. var definition = FindItemDefinition(itemname);
  1003. if (definition != null)
  1004. {
  1005. var item = ItemManager.Create(definition, amount);
  1006. if (item != null)
  1007. {
  1008. player.inventory.GiveItem(item);
  1009. PopupMessage(player, $"{LA("qCancel", player.UserIDString)} {item.amount}x {item.info.displayName.translated} {LA("rewRet", player.UserIDString)}");
  1010. }
  1011. }
  1012. }
  1013. }
  1014.  
  1015. private RewardItem GetItem(BasePlayer player)
  1016. {
  1017. Item item = player.GetActiveItem();
  1018. if (item == null) return null;
  1019. var newItem = new RewardItem
  1020. {
  1021. Amount = item.amount,
  1022. DisplayName = DisplayNames[item.info.shortname],
  1023. ID = item.info.itemid,
  1024. ShortName = item.info.shortname,
  1025. Skin = item.skin
  1026. };
  1027. return newItem;
  1028. }
  1029.  
  1030. private bool hasQuests(ulong player)
  1031. {
  1032. try
  1033. {
  1034. if (player.IsSteamId() && PlayerProgress.ContainsKey(player))
  1035. {
  1036. return true;
  1037. }
  1038.  
  1039. return false;
  1040. }
  1041. catch
  1042. {
  1043. Puts($"Error checking quests for {player}");
  1044. return false;
  1045. }
  1046. }
  1047.  
  1048. private bool isQuestItem(ulong player, string name, QuestType type)
  1049. {
  1050. var data = PlayerProgress[player].RequiredItems;
  1051. for (int i = 0; i < data.Count; i++)
  1052. {
  1053. if (data[i].ShortName == name && data[i].Type == type)
  1054. return true;
  1055. }
  1056.  
  1057. return false;
  1058. }
  1059.  
  1060. private void CheckPlayerEntry(BasePlayer player)
  1061. {
  1062. if (!PlayerProgress.ContainsKey(player.userID))
  1063. PlayerProgress.Add(player.userID, new PlayerQuestData());
  1064. }
  1065.  
  1066. private object GetQuestType(string name)
  1067. {
  1068. foreach (var entry in Quest)
  1069. if (entry.Value.ContainsKey(name))
  1070. return entry.Key;
  1071. return null;
  1072. }
  1073.  
  1074. private QuestEntry GetQuest(string name)
  1075. {
  1076. var type = GetQuestType(name);
  1077. if (type != null)
  1078. {
  1079. foreach (var entry in questData.Quest[(QuestType)type])
  1080. {
  1081. if (entry.Key == name)
  1082. return entry.Value;
  1083. }
  1084. }
  1085.  
  1086. PrintWarning($"Error retrieving quest info for: {name}");
  1087. return null;
  1088. }
  1089.  
  1090. private void SaveQuest(BasePlayer player, bool isCreating)
  1091. {
  1092. QuestCreator Creator;
  1093. QuestEntry Quest;
  1094.  
  1095. if (isCreating)
  1096. Creator = ActiveCreations[player.userID];
  1097. else Creator = ActiveEditors[player.userID];
  1098. Quest = Creator.entry;
  1099.  
  1100. if (isCreating)
  1101. {
  1102. if (Creator.type == QuestType.Delivery)
  1103. {
  1104. var npc = BasePlayer.FindByID(ulong.Parse(Creator.deliveryInfo.Info.ID));
  1105. if (npc != null)
  1106. {
  1107. npc.displayName = Creator.deliveryInfo.Info.Name;
  1108. npc.SendNetworkUpdateImmediate();
  1109. }
  1110.  
  1111. vendors.DeliveryVendors.Add(Creator.deliveryInfo.Info.ID, Creator.deliveryInfo);
  1112. AddMapMarker(Creator.deliveryInfo.Info.x, Creator.deliveryInfo.Info.z, Creator.deliveryInfo.Info.Name, $"{configData.LustyMapIntegration.Icon_Delivery}_{vendors.DeliveryVendors.Count}.png");
  1113. AddVendor.Remove(player.userID);
  1114. SaveVendorData();
  1115. DestroyUI(player);
  1116. if (vendors.DeliveryVendors.Count < 2)
  1117. PopupMessage(player, LA("minDV", player.UserIDString));
  1118. SendMSG(player, LA("DVSucc", player.UserIDString), LA("QC", player.UserIDString));
  1119. OpenMap(player);
  1120. return;
  1121. }
  1122. else questData.Quest[Creator.type].Add(Quest.QuestName, Quest);
  1123.  
  1124. ActiveCreations.Remove(player.userID);
  1125. }
  1126. else
  1127. {
  1128. questData.Quest[Creator.type].Remove(Creator.oldEntry);
  1129. questData.Quest[Creator.type].Add(Quest.QuestName, Quest);
  1130. ActiveEditors.Remove(player.userID);
  1131. }
  1132.  
  1133. DestroyUI(player);
  1134. SaveQuestData();
  1135. SendMSG(player, $"{LA("saveQ", player.UserIDString)} {Quest.QuestName}", LA("QC", player.UserIDString));
  1136. }
  1137.  
  1138. private void SaveRewardsEdit(BasePlayer player)
  1139. {
  1140. QuestCreator Creator = ActiveEditors[player.userID];
  1141. QuestEntry Quest = Creator.entry;
  1142. questData.Quest[Creator.type].Remove(Creator.entry.QuestName);
  1143. questData.Quest[Creator.type].Add(Quest.QuestName, Quest);
  1144.  
  1145. DestroyUI(player);
  1146. SaveQuestData();
  1147. CreationHelp(player, 10);
  1148. SendMSG(player, $"{LA("saveQ", player.UserIDString)} {Quest.QuestName}", LA("QC", player.UserIDString));
  1149. }
  1150.  
  1151. private void ExitQuest(BasePlayer player, bool isCreating)
  1152. {
  1153. if (isCreating)
  1154. ActiveCreations.Remove(player.userID);
  1155. else ActiveEditors.Remove(player.userID);
  1156.  
  1157. SendMSG(player, LA("QCCancel", player.UserIDString), LA("QC", player.UserIDString));
  1158. DestroyUI(player);
  1159. }
  1160.  
  1161. private void RemoveQuest(string questName)
  1162. {
  1163. var Quest = GetQuest(questName);
  1164. if (Quest == null) return;
  1165. var Type = (QuestType)GetQuestType(questName);
  1166. questData.Quest[Type].Remove(questName);
  1167.  
  1168. foreach (var player in PlayerProgress)
  1169. {
  1170. if (player.Value.Quests.ContainsKey(questName))
  1171. player.Value.Quests.Remove(questName);
  1172. }
  1173.  
  1174. if (vendors.DeliveryVendors.ContainsKey(Quest.Objective))
  1175. vendors.DeliveryVendors.Remove(Quest.Objective);
  1176. if (vendors.QuestVendors.ContainsKey(Quest.Objective))
  1177. vendors.QuestVendors.Remove(Quest.Objective);
  1178.  
  1179. SaveQuestData();
  1180. SaveVendorData();
  1181. }
  1182.  
  1183. private ulong GetLastAttacker(NetworkableId id)
  1184. {
  1185. int hits = 0;
  1186. ulong majorityPlayer = 0U;
  1187. if (HeliAttackers.ContainsKey(id))
  1188. {
  1189. foreach (var score in HeliAttackers[id])
  1190. {
  1191. if (score.Value > hits)
  1192. majorityPlayer = score.Key;
  1193. }
  1194. }
  1195.  
  1196. return majorityPlayer;
  1197. }
  1198.  
  1199. private string GetTypeDescription(QuestType type)
  1200. {
  1201. switch (type)
  1202. {
  1203. case QuestType.Kill:
  1204. return LA("KillOBJ");
  1205. case QuestType.Craft:
  1206. return LA("CraftOBJ");
  1207. case QuestType.Gather:
  1208. return LA("GatherOBJ");
  1209. case QuestType.Loot:
  1210. return LA("LootOBJ");
  1211. case QuestType.Delivery:
  1212. return LA("DelvOBJ");
  1213. }
  1214.  
  1215. return "";
  1216. }
  1217.  
  1218. private QuestType ConvertStringToType(string type)
  1219. {
  1220. switch (type)
  1221. {
  1222. case "gather":
  1223. case "Gather":
  1224. return QuestType.Gather;
  1225. case "loot":
  1226. case "Loot":
  1227. return QuestType.Loot;
  1228. case "craft":
  1229. case "Craft":
  1230. return QuestType.Craft;
  1231. case "delivery":
  1232. case "Delivery":
  1233. return QuestType.Delivery;
  1234. default:
  1235. return QuestType.Kill;
  1236. }
  1237. }
  1238.  
  1239. private string isNPCRegistered(string ID)
  1240. {
  1241. if (vendors.QuestVendors.ContainsKey(ID)) return LA("aQVReg");
  1242. if (vendors.DeliveryVendors.ContainsKey(ID)) return LA("aDVReg");
  1243. return null;
  1244. }
  1245.  
  1246. static double GrabCurrentTime() => DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
  1247.  
  1248. private BasePlayer FindEntity(BasePlayer player)
  1249. {
  1250. var currentRot = Quaternion.Euler(player.serverInput.current.aimAngles) * Vector3.forward;
  1251. var rayResult = Ray(player, currentRot);
  1252. if (rayResult is BasePlayer)
  1253. {
  1254. var ent = rayResult as BasePlayer;
  1255. return ent;
  1256. }
  1257.  
  1258. return null;
  1259. }
  1260.  
  1261. private object Ray(BasePlayer player, Vector3 Aim)
  1262. {
  1263. var hits = Physics.RaycastAll(player.transform.position + new Vector3(0f, 1.5f, 0f), Aim);
  1264. float distance = 50f;
  1265. object target = null;
  1266.  
  1267. foreach (var hit in hits)
  1268. {
  1269. if (hit.collider.GetComponentInParent<BaseEntity>() != null)
  1270. {
  1271. if (hit.distance < distance)
  1272. {
  1273. distance = hit.distance;
  1274. target = hit.collider.GetComponentInParent<BaseEntity>();
  1275. }
  1276. }
  1277. }
  1278.  
  1279. return target;
  1280. }
  1281.  
  1282. private void SetVendorName()
  1283. {
  1284. foreach (var npc in vendors.DeliveryVendors)
  1285. {
  1286. var player = BasePlayer.FindByID(ulong.Parse(npc.Key));
  1287. if (player != null)
  1288. {
  1289. player.displayName = npc.Value.Info.Name;
  1290. }
  1291. }
  1292.  
  1293. foreach (var npc in vendors.QuestVendors)
  1294. {
  1295. var player = BasePlayer.FindByID(ulong.Parse(npc.Key));
  1296. if (player != null)
  1297. {
  1298. player.displayName = npc.Value.Name;
  1299. }
  1300. }
  1301. }
  1302.  
  1303. private void RemoveVendor(BasePlayer player, string ID, bool isVendor)
  1304. {
  1305. if (isVendor)
  1306. {
  1307. RemoveMapMarker(vendors.QuestVendors[ID].Name);
  1308. vendors.QuestVendors.Remove(ID);
  1309.  
  1310. int i = 1;
  1311. foreach (var npc in vendors.QuestVendors)
  1312. {
  1313. RemoveMapMarker(npc.Value.Name);
  1314. AddMapMarker(npc.Value.x, npc.Value.z, npc.Value.Name, $"{configData.LustyMapIntegration.Icon_Vendor}.png");
  1315. i++;
  1316. }
  1317. }
  1318. else
  1319. {
  1320. RemoveMapMarker(vendors.DeliveryVendors[ID].Info.Name);
  1321. vendors.DeliveryVendors.Remove(ID);
  1322.  
  1323. int i = 1;
  1324. foreach (var npc in vendors.DeliveryVendors)
  1325. {
  1326. RemoveMapMarker(npc.Value.Info.Name);
  1327. AddMapMarker(npc.Value.Info.x, npc.Value.Info.z, npc.Value.Info.Name, $"{configData.LustyMapIntegration.Icon_Delivery}_{i}.png");
  1328. i++;
  1329. }
  1330.  
  1331. foreach (var user in PlayerProgress)
  1332. {
  1333. if (user.Value.Quests.ContainsKey(ID))
  1334. user.Value.Quests.Remove(ID);
  1335. }
  1336. }
  1337.  
  1338. DeleteNPCMenu(player);
  1339. PopupMessage(player, $"You have successfully removed the npc with ID: {ID}");
  1340. SaveVendorData();
  1341. }
  1342.  
  1343. private string GetRandomNPC(string ID)
  1344. {
  1345. List<string> npcIDs = vendors.DeliveryVendors.Keys.ToList();
  1346. List<string> withoutSelected = npcIDs;
  1347. if (withoutSelected.Contains(ID))
  1348. withoutSelected.Remove(ID);
  1349. var randNum = UnityEngine.Random.Range(0, withoutSelected.Count - 1);
  1350. return withoutSelected[randNum];
  1351. }
  1352.  
  1353. private string LA(string key, string userID = null) => lang.GetMessage(key, this, userID);
  1354.  
  1355. #endregion
  1356.  
  1357. #region UI
  1358.  
  1359. private void CreateMenu(BasePlayer player)
  1360. {
  1361. CloseMap(player);
  1362.  
  1363. var MenuElement = QUI.CreateElementContainer(UIMain, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0 0", "0.12 1");
  1364. QUI.CreatePanel(ref MenuElement, UIMain, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.05 0.01", "0.95 0.99", true);
  1365. QUI.CreateLabel(ref MenuElement, UIMain, "", $"{textPrimary}Quests</color>", 30, "0.05 0.9", "0.95 1");
  1366. int i = 0;
  1367. CreateMenuButton(ref MenuElement, UIMain, LA("Kill", player.UserIDString), "QUI_ChangeElement kill", i); i++;
  1368. CreateMenuButton(ref MenuElement, UIMain, LA("Gather", player.UserIDString), "QUI_ChangeElement gather", i); i++;
  1369. CreateMenuButton(ref MenuElement, UIMain, LA("Loot", player.UserIDString), "QUI_ChangeElement loot", i); i++;
  1370. CreateMenuButton(ref MenuElement, UIMain, LA("Craft", player.UserIDString), "QUI_ChangeElement craft", i); i++;
  1371. i++;
  1372. if (HumanNPC)
  1373. CreateMenuButton(ref MenuElement, UIMain, LA("Delivery", player.UserIDString), "QUI_ChangeElement delivery", i); i++;
  1374. CreateMenuButton(ref MenuElement, UIMain, LA("Your Quests", player.UserIDString), "QUI_ChangeElement personal", i); i++;
  1375.  
  1376. if (isAdmin(player)) QUI.CreateButton(ref MenuElement, UIMain, QUI.Color(configData.Colors.Button_Accept.Color, configData.Colors.Button_Accept.Alpha), LA("Create Quest", player.UserIDString), 18, "0.1 0.16", "0.9 0.215", "QUI_ChangeElement creation");
  1377.  
  1378. QUI.CreateButton(ref MenuElement, UIMain, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Close", player.UserIDString), 18, "0.1 0.03", "0.9 0.085", "QUI_DestroyAll");
  1379. CuiHelper.AddUi(player, MenuElement);
  1380. }
  1381.  
  1382. private void CreateEmptyMenu(BasePlayer player)
  1383. {
  1384. CloseMap(player);
  1385.  
  1386. var MenuElement = QUI.CreateElementContainer(UIMain, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0 0", "0.12 1");
  1387. QUI.CreatePanel(ref MenuElement, UIMain, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.05 0.01", "0.95 0.99", true);
  1388. QUI.CreateLabel(ref MenuElement, UIMain, "", $"{textPrimary}Quests</color>", 30, "0.05 0.9", "0.95 1");
  1389. CreateMenuButton(ref MenuElement, UIMain, LA("Your Quests", player.UserIDString), "QUI_ChangeElement personal", 4);
  1390.  
  1391. QUI.CreateButton(ref MenuElement, UIMain, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Close", player.UserIDString), 18, "0.1 0.03", "0.9 0.085", "QUI_DestroyAll");
  1392. CuiHelper.AddUi(player, MenuElement);
  1393. }
  1394.  
  1395. private void CreateMenuButton(ref CuiElementContainer container, string panelName, string buttonname, string command, int number)
  1396. {
  1397. Vector2 dimensions = new Vector2(0.8f, 0.055f);
  1398. Vector2 origin = new Vector2(0.1f, 0.75f);
  1399. Vector2 offset = new Vector2(0, (0.01f + dimensions.y) * number);
  1400.  
  1401. Vector2 posMin = origin - offset;
  1402. Vector2 posMax = posMin + dimensions;
  1403.  
  1404. QUI.CreateButton(ref container, panelName, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), buttonname, 18, $"{posMin.x} {posMin.y}", $"{posMax.x} {posMax.y}", command);
  1405. }
  1406.  
  1407. private void ListElement(BasePlayer player, QuestType type, int page = 0)
  1408. {
  1409. DestroyEntries(player);
  1410. var Main = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.12 0", "1 1");
  1411. QUI.CreatePanel(ref Main, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.01", "0.99 0.99", true);
  1412. QUI.CreateLabel(ref Main, UIPanel, "", GetTypeDescription(type), 16, "0.1 0.93", "0.9 0.99");
  1413. QUI.CreateLabel(ref Main, UIPanel, "1 1 1 0.015", type.ToString().ToUpper(), 200, "0.01 0.01", "0.99 0.99");
  1414. var quests = Quest[type];
  1415. if (quests.Count > 16)
  1416. {
  1417. var maxpages = (quests.Count - 1) / 16 + 1;
  1418. if (page < maxpages - 1)
  1419. QUI.CreateButton(ref Main, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Next", player.UserIDString), 16, "0.86 0.94", "0.97 0.98", $"QUI_ChangeElement listpage {type} {page + 1}");
  1420. if (page > 0)
  1421. QUI.CreateButton(ref Main, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Back", player.UserIDString), 16, "0.03 0.94", "0.14 0.98", $"QUI_ChangeElement listpage {type} {page - 1}");
  1422. }
  1423.  
  1424. int maxentries = (16 * (page + 1));
  1425. if (maxentries > quests.Count)
  1426. maxentries = quests.Count;
  1427. int rewardcount = 16 * page;
  1428. List<string> questNames = new List<string>();
  1429. foreach (var entry in Quest[type])
  1430. questNames.Add(entry.Key);
  1431.  
  1432. if (quests.Count == 0)
  1433. QUI.CreateLabel(ref Main, UIPanel, "", $"{textPrimary}{LA("noQ", player.UserIDString)} {type.ToString().ToLower()} {LA("quests", player.UserIDString)} </color>", 24, "0 0.82", "1 0.9");
  1434.  
  1435. CuiHelper.AddUi(player, Main);
  1436.  
  1437. int i = 0;
  1438. for (int n = rewardcount; n < maxentries; n++)
  1439. {
  1440. CreateQuestEntry(player, quests[questNames[n]], i);
  1441. i++;
  1442. }
  1443. }
  1444.  
  1445. private void CreateQuestEntry(BasePlayer player, QuestEntry entry, int num)
  1446. {
  1447. Vector2 posMin = CalcQuestPos(num);
  1448. Vector2 dimensions = new Vector2(0.21f, 0.22f);
  1449. Vector2 posMax = posMin + dimensions;
  1450.  
  1451. var panelName = UIEntry + num;
  1452. AddUIString(player, panelName);
  1453.  
  1454. var questEntry = QUI.CreateElementContainer(panelName, "0 0 0 0", $"{posMin.x} {posMin.y}", $"{posMax.x} {posMax.y}");
  1455. QUI.CreatePanel(ref questEntry, panelName, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), $"0 0", $"1 1");
  1456.  
  1457. string buttonCommand = "";
  1458. string buttonText = "";
  1459. string buttonColor = "";
  1460. QuestStatus status = QuestStatus.Open;
  1461. var prog = PlayerProgress[player.userID].Quests;
  1462. if (prog.ContainsKey(entry.QuestName))
  1463. {
  1464. status = prog[entry.QuestName].Status;
  1465. switch (prog[entry.QuestName].Status)
  1466. {
  1467. case QuestStatus.Pending:
  1468.  
  1469. buttonColor = QUI.Color(configData.Colors.Button_Pending.Color, configData.Colors.Button_Pending.Alpha);
  1470. buttonText = LA("Pending", player.UserIDString);
  1471. break;
  1472. case QuestStatus.Completed:
  1473. buttonColor = QUI.Color(configData.Colors.Button_Completed.Color, configData.Colors.Button_Completed.Alpha);
  1474. buttonText = LA("Completed", player.UserIDString);
  1475. break;
  1476. }
  1477. }
  1478. else
  1479. {
  1480. buttonColor = QUI.Color(configData.Colors.Button_Accept.Color, configData.Colors.Button_Accept.Alpha);
  1481. buttonText = LA("Accept Quest", player.UserIDString);
  1482. buttonCommand = $"QUI_AcceptQuest {entry.QuestName}";
  1483. }
  1484.  
  1485. if (configData.PlayerMaxQuests != 0 && !permission.UserHasPermission(player.UserIDString, "quests.bypassQuestsLimit") && playerData.PlayerProgress[player.userID].Quests.Count() >= configData.PlayerMaxQuests)
  1486. {
  1487. QUI.CreateButton(ref questEntry, panelName, QUI.Color(configData.Colors.Button_Cancel.Color, configData.Colors.Button_Cancel.Alpha), "Quests limit reached", 11, $"0.60 0.83", $"0.98 0.97", "");
  1488. }
  1489. else
  1490. {
  1491. QUI.CreateButton(ref questEntry, panelName, buttonColor, buttonText, 14, $"0.60 0.83", $"0.98 0.97", buttonCommand);
  1492. }
  1493.  
  1494.  
  1495. string rewards = GetRewardString(entry.Rewards);
  1496. string questInfo = $"{textPrimary}{LA("Status:", player.UserIDString)}</color> {status}";
  1497. questInfo = questInfo + $"\n{textPrimary}{LA("Desc", player.UserIDString)} </color>{textSecondary}{entry.Description}</color>";
  1498. questInfo = questInfo + $"\n{textPrimary}{LA("Objective:", player.UserIDString)} </color>{textSecondary}{entry.ObjectiveName}</color>";
  1499. questInfo = questInfo + $"\n{textPrimary}{LA("Amount Required:", player.UserIDString)} </color>{textSecondary}{entry.AmountRequired}</color>";
  1500. questInfo = questInfo + $"\n{textPrimary}{LA("Reward:", player.UserIDString)} </color>{textSecondary}{rewards}</color>";
  1501.  
  1502. QUI.CreateLabel(ref questEntry, panelName, "", $"{entry.QuestName}", 16, $"0.02 0.8", "0.72 0.95", TextAnchor.MiddleLeft);
  1503. QUI.CreateLabel(ref questEntry, panelName, buttonColor, questInfo, 14, $"0.02 0.01", "0.98 0.78", TextAnchor.UpperLeft);
  1504.  
  1505. if (isAdmin(player))
  1506. {
  1507. QUI.CreateButton(ref questEntry, panelName, QUI.Color(configData.Colors.Button_Completed.Color, configData.Colors.Button_Completed.Alpha), LA("Edit Quest", player.UserIDString), 10, "0.60 0.70", "0.77 0.80", $"QUI_EditQuest {entry.QuestName}");
  1508. QUI.CreateButton(ref questEntry, panelName, QUI.Color(configData.Colors.Button_Cancel.Color, configData.Colors.Button_Cancel.Alpha), LA("Delete Quest", player.UserIDString), 10, "0.78 0.70", "0.98 0.80", $"QUI_ConfirmDelete {entry.QuestName}");
  1509. }
  1510.  
  1511. CuiHelper.AddUi(player, questEntry);
  1512. }
  1513.  
  1514. private void PlayerStats(BasePlayer player, int page = 0)
  1515. {
  1516. DestroyEntries(player);
  1517. var Main = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.12 0", "1 1");
  1518. QUI.CreatePanel(ref Main, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.01", "0.99 0.99", true);
  1519. QUI.CreateLabel(ref Main, UIPanel, "", LA("yqDesc", player.UserIDString), 16, "0.1 0.93", "0.9 0.99");
  1520. QUI.CreateLabel(ref Main, UIPanel, "1 1 1 0.015", LA("STATS", player.UserIDString), 200, "0.01 0.01", "0.99 0.99");
  1521.  
  1522. var stats = PlayerProgress[player.userID];
  1523. if (stats.Quests.Count > 16)
  1524. {
  1525. var maxpages = (stats.Quests.Count - 1) / 16 + 1;
  1526. if (page < maxpages - 1)
  1527. QUI.CreateButton(ref Main, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Next", player.UserIDString), 16, "0.86 0.94", "0.97 0.98", $"QUI_ChangeElement statspage {page + 1}");
  1528. if (page > 0)
  1529. QUI.CreateButton(ref Main, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Back", player.UserIDString), 16, "0.03 0.94", "0.14 0.098", $"QUI_ChangeElement statspage {page - 1}");
  1530. }
  1531.  
  1532. int maxentries = (16 * (page + 1));
  1533. if (maxentries > stats.Quests.Count)
  1534. maxentries = stats.Quests.Count;
  1535. int rewardcount = 16 * page;
  1536. List<string> questNames = new List<string>();
  1537. foreach (var entry in stats.Quests)
  1538. questNames.Add(entry.Key);
  1539.  
  1540. if (stats.Quests.Count == 0)
  1541. QUI.CreateLabel(ref Main, UIPanel, "", $"{textPrimary}{LA("noQDSaved", player.UserIDString)}</color>", 24, "0 0.82", "1 0.9");
  1542.  
  1543. CuiHelper.AddUi(player, Main);
  1544.  
  1545. int i = 0;
  1546. for (int n = rewardcount; n < maxentries; n++)
  1547. {
  1548. var Quest = GetQuest(questNames[n]);
  1549. if (Quest == null) continue;
  1550. CreateStatEntry(player, Quest, i);
  1551. i++;
  1552. }
  1553. }
  1554.  
  1555. private void CreateStatEntry(BasePlayer player, QuestEntry entry, int num)
  1556. {
  1557. Vector2 posMin = CalcQuestPos(num);
  1558. Vector2 dimensions = new Vector2(0.21f, 0.22f);
  1559. Vector2 posMax = posMin + dimensions;
  1560.  
  1561. var panelName = UIEntry + num;
  1562. AddUIString(player, panelName);
  1563.  
  1564. var questEntry = QUI.CreateElementContainer(panelName, "0 0 0 0", $"{posMin.x} {posMin.y}", $"{posMax.x} {posMax.y}");
  1565. QUI.CreatePanel(ref questEntry, panelName, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), $"0 0", $"1 1");
  1566.  
  1567. string statusColor = "";
  1568. QuestStatus status = QuestStatus.Open;
  1569. var prog = PlayerProgress[player.userID].Quests;
  1570. if (prog.ContainsKey(entry.QuestName))
  1571. {
  1572. status = prog[entry.QuestName].Status;
  1573. switch (prog[entry.QuestName].Status)
  1574. {
  1575. case QuestStatus.Pending:
  1576. statusColor = QUI.Color(configData.Colors.Button_Pending.Color, configData.Colors.Button_Pending.Alpha);
  1577. break;
  1578. case QuestStatus.Completed:
  1579. statusColor = QUI.Color(configData.Colors.Button_Completed.Color, configData.Colors.Button_Completed.Alpha);
  1580. break;
  1581. }
  1582. }
  1583.  
  1584. if (status != QuestStatus.Completed)
  1585. QUI.CreateButton(ref questEntry, panelName, QUI.Color(configData.Colors.Button_Cancel.Color, configData.Colors.Button_Cancel.Alpha), LA("Cancel Quest", player.UserIDString), 16, $"0.63 0.83", $"0.97 0.97", $"QUI_CancelQuest {entry.QuestName}");
  1586. if (status == QuestStatus.Completed && !prog[entry.QuestName].RewardClaimed)
  1587. QUI.CreateButton(ref questEntry, panelName, statusColor, LA("Claim Reward", player.UserIDString), 16, $"0.62 0.83", $"0.97 0.97", $"QUI_ClaimReward {entry.QuestName}");
  1588. string questStatus = status.ToString();
  1589. if (status == QuestStatus.Completed && prog[entry.QuestName].RewardClaimed)
  1590. {
  1591. if (prog[entry.QuestName].ResetTime < GrabCurrentTime())
  1592. QUI.CreateButton(ref questEntry, panelName, statusColor, LA("Remove", player.UserIDString), 16, $"0.75 0.83", $"0.97 0.97", $"QUI_RemoveCompleted {entry.QuestName}");
  1593. else
  1594. {
  1595. TimeSpan dateDifference = TimeSpan.FromSeconds(prog[entry.QuestName].ResetTime - GrabCurrentTime());
  1596. var days = dateDifference.Days;
  1597. var hours = dateDifference.Hours;
  1598. hours += (days * 24);
  1599. var mins = dateDifference.Minutes;
  1600. string remaining = string.Format("{0:00}h :{1:00}m", hours, mins);
  1601. questStatus = $"{LA("Cooldown:", player.UserIDString)} {remaining}";
  1602. }
  1603. }
  1604.  
  1605. var rewards = GetRewardString(entry.Rewards);
  1606. var percent = Math.Round(Convert.ToDouble((float)prog[entry.QuestName].AmountCollected / (float)entry.AmountRequired), 4);
  1607. //Puts($"Collected: {prog[entry.QuestName].AmountCollected.ToString()}, Required: {entry.AmountRequired.ToString()}, Pct: {percent.ToString()}");
  1608. string stats = $"{textPrimary}{LA("Status:", player.UserIDString)}</color> {questStatus}";
  1609. stats += $"\n{textPrimary}{LA("Quest Type:", player.UserIDString)} </color> {textSecondary}{prog[entry.QuestName].Type}</color>";
  1610. stats += $"\n{textPrimary}{LA("Desc", player.UserIDString)} </color>{textSecondary}{entry.Description}</color>";
  1611. stats += $"\n{textPrimary}{LA("Objective:", player.UserIDString)} </color>{textSecondary}{entry.AmountRequired}x {entry.ObjectiveName}</color>";
  1612. stats += $"\n{textPrimary}{LA("Collected:", player.UserIDString)} </color>{textSecondary}{prog[entry.QuestName].AmountCollected}</color> {textPrimary}({percent * 100}%)</color>";
  1613. stats += $"\n{textPrimary}{LA("Reward:", player.UserIDString)} </color>{textSecondary}{rewards}</color>";
  1614.  
  1615. QUI.CreateLabel(ref questEntry, panelName, "", $"{entry.QuestName}", 18, $"0.02 0.8", "0.8 0.95", TextAnchor.UpperLeft);
  1616. QUI.CreateLabel(ref questEntry, panelName, "", stats, 14, $"0.02 0.01", "0.98 0.78", TextAnchor.UpperLeft);
  1617.  
  1618. CuiHelper.AddUi(player, questEntry);
  1619. }
  1620.  
  1621. private void PlayerDelivery(BasePlayer player)
  1622. {
  1623. DestroyEntries(player);
  1624. var Main = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.12 0", "1 1");
  1625. QUI.CreatePanel(ref Main, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.01", "0.99 0.99", true);
  1626. QUI.CreateLabel(ref Main, UIPanel, "", GetTypeDescription(QuestType.Delivery), 16, "0.1 0.93", "0.9 0.99");
  1627. QUI.CreateLabel(ref Main, UIPanel, "1 1 1 0.015", LA("DELIVERY", player.UserIDString), 200, "0.01 0.01", "0.99 0.99");
  1628.  
  1629. var npcid = PlayerProgress[player.userID].CurrentDelivery.VendorID;
  1630. var targetid = PlayerProgress[player.userID].CurrentDelivery.TargetID;
  1631. if (string.IsNullOrEmpty(npcid))
  1632. QUI.CreateLabel(ref Main, UIPanel, "", $"{textPrimary}{LA("noADM", player.UserIDString)}</color>", 24, "0 0.82", "1 0.9");
  1633. else
  1634. {
  1635. var quest = vendors.DeliveryVendors[npcid];
  1636. var target = vendors.DeliveryVendors[targetid];
  1637. if (quest != null && target != null)
  1638. {
  1639. var distance = Vector2.Distance(new Vector2(quest.Info.x, quest.Info.z), new Vector2(target.Info.x, target.Info.z));
  1640. var rewardAmount = distance * quest.Multiplier;
  1641. if (rewardAmount < 1) rewardAmount = 1;
  1642. var briefing = $"{textPrimary}{quest.Info.Name}\n\n</color>";
  1643. briefing = briefing + $"{textSecondary}{quest.Description}</color>\n\n";
  1644. briefing = briefing + $"{textPrimary}{LA("Destination:", player.UserIDString)} </color>{textSecondary}{target.Info.Name}\nX {target.Info.x}, Z {target.Info.z}</color>\n";
  1645. briefing = briefing + $"{textPrimary}{LA("Distance:", player.UserIDString)} </color>{textSecondary}{distance}M</color>\n";
  1646. briefing = briefing + $"{textPrimary}{LA("Reward:", player.UserIDString)} </color>{textSecondary}{(int)rewardAmount}x {quest.Reward.DisplayName}</color>";
  1647. QUI.CreateLabel(ref Main, UIPanel, "", briefing, 20, "0.15 0.2", "0.85 1", TextAnchor.MiddleLeft);
  1648.  
  1649. QUI.CreateButton(ref Main, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Cancel", player.UserIDString), 18, "0.2 0.05", "0.35 0.1", $"QUI_CancelDelivery");
  1650. }
  1651. }
  1652.  
  1653. CuiHelper.AddUi(player, Main);
  1654. }
  1655.  
  1656. private void CreationMenu(BasePlayer player)
  1657. {
  1658. DestroyEntries(player);
  1659. var Main = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.12 0", "1 1");
  1660. QUI.CreatePanel(ref Main, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.01", "0.99 0.99", true);
  1661.  
  1662. int i = 0;
  1663. QUI.CreateLabel(ref Main, UIPanel, "", $"{textPrimary}{LA("selCreat", player.UserIDString)}</color>", 20, "0.25 0.8", "0.75 0.9");
  1664. QUI.CreateLabel(ref Main, UIPanel, "1 1 1 0.025", LA("CREATOR", player.UserIDString), 200, "0.01 0.01", "0.99 0.99");
  1665. CreateNewQuestButton(ref Main, UIPanel, LA("Kill", player.UserIDString), "QUI_NewQuest kill", i); i++;
  1666. CreateNewQuestButton(ref Main, UIPanel, LA("Gather", player.UserIDString), "QUI_NewQuest gather", i); i++;
  1667. CreateNewQuestButton(ref Main, UIPanel, LA("Loot", player.UserIDString), "QUI_NewQuest loot", i); i++;
  1668. CreateNewQuestButton(ref Main, UIPanel, LA("Craft", player.UserIDString), "QUI_NewQuest craft", i); i++;
  1669. if (HumanNPC)
  1670. CreateNewQuestButton(ref Main, UIPanel, LA("Delivery", player.UserIDString), "QUI_NewQuest delivery", i); i++;
  1671.  
  1672. CuiHelper.AddUi(player, Main);
  1673. }
  1674.  
  1675. private void CreationHelp(BasePlayer player, int page = 0)
  1676. {
  1677. DestroyEntries(player);
  1678. QuestCreator quest = null;
  1679. if (ActiveCreations.ContainsKey(player.userID))
  1680. quest = ActiveCreations[player.userID];
  1681. else if (ActiveEditors.ContainsKey(player.userID))
  1682. quest = ActiveEditors[player.userID];
  1683. if (quest == null) return;
  1684.  
  1685. var HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9");
  1686. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1687.  
  1688. switch (page)
  1689. {
  1690. case 0:
  1691. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelMen", player.UserIDString)}.\n</color> {textSecondary}{LA("creHelFol", player.UserIDString)}.\n\n{LA("creHelExi", player.UserIDString)} </color>{textPrimary}'exit'\n\n\n\n{LA("creHelName", player.UserIDString)}</color>", 20, "0 0", "1 1");
  1692. break;
  1693. case 1:
  1694. var MenuMain = QUI.CreateElementContainer(UIMain, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0 0", "1 1", true);
  1695. QUI.CreatePanel(ref MenuMain, UIMain, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.01", "0.99 0.99");
  1696. QUI.CreateLabel(ref MenuMain, UIMain, "", $"{textPrimary}{LA("creHelObj", player.UserIDString)}</color>", 20, "0.25 0.85", "0.75 0.95");
  1697. CuiHelper.AddUi(player, MenuMain);
  1698. CreateObjectiveMenu(player);
  1699. return;
  1700. case 2:
  1701. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelRA", player.UserIDString)}</color>", 20, "0.25 0.4", "0.75 0.6");
  1702. break;
  1703. case 3:
  1704. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelQD", player.UserIDString)}</color>", 20, "0.25 0.4", "0.75 0.6");
  1705. break;
  1706. case 4:
  1707. {
  1708. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9");
  1709. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98", true);
  1710. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelRT", player.UserIDString)}</color>", 20, "0.25 0.8", "0.75 1");
  1711. int i = 0;
  1712. if (Economics) CreateRewardTypeButton(ref HelpMain, UIPanel, $"{LA("Coins", player.UserIDString)} (Economics)", "QUI_RewardType coins", i); i++;
  1713. if (ServerRewards) CreateRewardTypeButton(ref HelpMain, UIPanel, $"{LA("RP", player.UserIDString)} (ServerRewards)", "QUI_RewardType rp", i); i++;
  1714. CreateRewardTypeButton(ref HelpMain, UIPanel, LA("Item", player.UserIDString), "QUI_RewardType item", i); i++;
  1715. if (HuntRPG) CreateRewardTypeButton(ref HelpMain, UIPanel, $"{LA("HuntXP", player.UserIDString)} (HuntRPG)", "QUI_RewardType huntxp", i); i++;
  1716. }
  1717. break;
  1718. case 5:
  1719. if (quest.item.isCoins || quest.item.isRP || quest.item.isHuntXP)
  1720. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelRewA", player.UserIDString)}</color>", 20, "0.25 0.4", "0.75 0.6");
  1721. else
  1722. {
  1723. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.3 0.8", "0.7 0.97");
  1724. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1725. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelIH", player.UserIDString)} 'quest item'</color>", 20, "0.1 0", "0.9 1");
  1726. }
  1727.  
  1728. break;
  1729. case 7:
  1730. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9", true);
  1731. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1732. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelAR", player.UserIDString)}</color>", 20, "0.1 0", "0.9 1");
  1733. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Yes", player.UserIDString), 18, "0.6 0.05", "0.8 0.15", $"QUI_AddReward");
  1734. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("No", player.UserIDString), 18, "0.2 0.05", "0.4 0.15", $"QUI_RewardFinish");
  1735. break;
  1736. case 8:
  1737. if (quest.type != QuestType.Kill)
  1738. {
  1739. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9", true);
  1740. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1741. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelID", player.UserIDString)}</color>", 20, "0.1 0", "0.9 1");
  1742. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Yes", player.UserIDString), 18, "0.6 0.05", "0.8 0.15", $"QUI_ItemDeduction 1");
  1743. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("No", player.UserIDString), 18, "0.2 0.05", "0.4 0.15", $"QUI_ItemDeduction 0");
  1744. }
  1745. else
  1746. {
  1747. CreationHelp(player, 9);
  1748. return;
  1749. }
  1750.  
  1751. break;
  1752. case 9:
  1753. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.3 0.8", "0.7 0.97");
  1754. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1755. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelCD", player.UserIDString)}</color>", 20, "0.1 0", "0.9 1");
  1756. break;
  1757. case 10:
  1758. {
  1759. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9");
  1760. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98", true);
  1761. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelNewRew", player.UserIDString)}</color>", 20, "0.25 0.8", "0.75 1");
  1762. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("addNewRew", player.UserIDString), 18, "0.7 0.04", "0.95 0.12", $"QUI_AddReward");
  1763. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Back", player.UserIDString), 18, "0.05 0.04", "0.3 0.12", $"QUI_EndEditing");
  1764.  
  1765. int i = 0;
  1766. foreach (var entry in ActiveEditors[player.userID].entry.Rewards)
  1767. {
  1768. CreateDelEditButton(ref HelpMain, 0.1f, UIPanel, $"{entry.Amount}x {entry.DisplayName}", i, "", 0.35f);
  1769. CreateDelEditButton(ref HelpMain, 0.72f, UIPanel, LA("Remove", player.UserIDString), i, $"QUI_RemoveReward {entry.Amount} {entry.DisplayName}");
  1770. i++;
  1771. }
  1772. }
  1773. break;
  1774. default:
  1775. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9", true);
  1776. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1777. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelSQ", player.UserIDString)}</color>", 20, "0.1 0.8", "0.9 0.95");
  1778. string questDetails = $"{textPrimary}{LA("Quest Type:", player.UserIDString)}</color> {textSecondary}{quest.type}</color>";
  1779. questDetails = questDetails + $"\n{textPrimary}{LA("Name:", player.UserIDString)}</color> {textSecondary}{quest.entry.QuestName}</color>";
  1780. questDetails = questDetails + $"\n{textPrimary}{LA("Desc", player.UserIDString)}</color> {textSecondary}{quest.entry.Description}</color>";
  1781. questDetails = questDetails + $"\n{textPrimary}{LA("Objective:", player.UserIDString)}</color> {textSecondary}{quest.entry.ObjectiveName}</color>";
  1782. questDetails = questDetails + $"\n{textPrimary}{LA("Required Amount:", player.UserIDString)}</color> {textSecondary}{quest.entry.AmountRequired}</color>";
  1783. if (quest.type != QuestType.Kill) questDetails = questDetails + $"\n{textPrimary}{LA("Item Deduction:", player.UserIDString)}</color> {textSecondary}{quest.entry.ItemDeduction}</color>";
  1784. questDetails = questDetails + $"\n{textPrimary}{LA("CDMin", player.UserIDString)}</color> {textSecondary}{quest.entry.Cooldown}</color>";
  1785.  
  1786. var rewards = GetRewardString(quest.entry.Rewards);
  1787.  
  1788. questDetails = questDetails + $"\n{textPrimary}{LA("Reward:", player.UserIDString)}</color> {textSecondary}{rewards}</color>";
  1789.  
  1790. QUI.CreateLabel(ref HelpMain, UIPanel, "", questDetails, 20, "0.1 0.2", "0.9 0.75", TextAnchor.MiddleLeft);
  1791. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Save Quest", player.UserIDString), 18, "0.6 0.05", "0.8 0.15", $"QUI_SaveQuest");
  1792. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Cancel", player.UserIDString), 18, "0.2 0.05", "0.4 0.15", $"QUI_ExitQuest");
  1793. break;
  1794. }
  1795.  
  1796. CuiHelper.AddUi(player, HelpMain);
  1797. }
  1798.  
  1799. private void CreateObjectiveMenu(BasePlayer player, int page = 0)
  1800. {
  1801. DestroyEntries(player);
  1802. var HelpMain = QUI.CreateElementContainer(UIPanel, "0 0 0 0", "0 0", "1 1");
  1803. QuestType type;
  1804. if (ActiveCreations.ContainsKey(player.userID))
  1805. type = ActiveCreations[player.userID].type;
  1806. else type = ActiveEditors[player.userID].type;
  1807. var objCount = AllObjectives[type].Count;
  1808. if (objCount > 100)
  1809. {
  1810. var maxpages = (objCount - 1) / 96 + 1;
  1811. if (page < maxpages - 1)
  1812. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Next", player.UserIDString), 18, "0.84 0.05", "0.97 0.1", $"QUI_ChangeElement objpage {page + 1}");
  1813. if (page > 0)
  1814. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Back", player.UserIDString), 18, "0.03 0.05", "0.16 0.1", $"QUI_ChangeElement objpage {page - 1}");
  1815. }
  1816.  
  1817. int maxentries = (96 * (page + 1));
  1818. if (maxentries > objCount)
  1819. maxentries = objCount;
  1820. int rewardcount = 96 * page;
  1821.  
  1822. int i = 0;
  1823. for (int n = rewardcount; n < maxentries; n++)
  1824. {
  1825. CreateObjectiveEntry(ref HelpMain, UIPanel, AllObjectives[type][n], i);
  1826. i++;
  1827. }
  1828.  
  1829. CuiHelper.AddUi(player, HelpMain);
  1830. }
  1831.  
  1832. private void DeliveryHelp(BasePlayer player, int page = 0)
  1833. {
  1834. DestroyEntries(player);
  1835. switch (page)
  1836. {
  1837. case 0:
  1838. var HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.12 0.0", "1 1", true);
  1839. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.01", "0.99 0.99");
  1840. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("delHelMen", player.UserIDString)}\n\n</color> {textSecondary}{LA("delHelChoo", player.UserIDString)}.\n\n{LA("creHelExi", player.UserIDString)} </color>{textPrimary}'exit'</color>", 20, "0 0", "1 1");
  1841. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Quest Vendor", player.UserIDString), 18, "0.6 0.05", "0.8 0.15", $"QUI_AddVendor 1");
  1842. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Delivery Vendor", player.UserIDString), 18, "0.2 0.05", "0.4 0.15", $"QUI_AddVendor 2");
  1843. CuiHelper.AddUi(player, HelpMain);
  1844. return;
  1845. case 1:
  1846. var element = QUI.CreateElementContainer(UIMain, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.25 0.85", "0.75 0.95");
  1847. QUI.CreatePanel(ref element, UIMain, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), "0.005 0.04", "0.995 0.96");
  1848. QUI.CreateLabel(ref element, UIMain, "", $"{textPrimary}{LA("delHelNewNPC", player.UserIDString)} '/questnpc'</color>", 22, "0 0", "1 1");
  1849. CuiHelper.AddUi(player, element);
  1850. return;
  1851. case 2:
  1852. DestroyUI(player);
  1853. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9");
  1854. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98", true);
  1855. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textSecondary}{LA("delHelMult", player.UserIDString)}</color>\n{textPrimary}{LA("creHelRT", player.UserIDString)}</color>", 18, "0.05 0.82", "0.95 0.98");
  1856. int i = 0;
  1857. if (Economics) CreateRewardTypeButton(ref HelpMain, UIPanel, "Coins (Economics)", "QUI_RewardType coins", i); i++;
  1858. if (ServerRewards) CreateRewardTypeButton(ref HelpMain, UIPanel, "RP (ServerRewards)", "QUI_RewardType rp", i); i++;
  1859. CreateRewardTypeButton(ref HelpMain, UIPanel, LA("Item", player.UserIDString), "QUI_RewardType item", i); i++;
  1860. if (HuntRPG) CreateRewardTypeButton(ref HelpMain, UIPanel, "XP (HuntRPG)", "QUI_RewardType huntxp", i); i++;
  1861. CuiHelper.AddUi(player, HelpMain);
  1862. return;
  1863. case 3:
  1864. {
  1865. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9");
  1866. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1867. var quest = ActiveCreations[player.userID];
  1868. if (quest.deliveryInfo.Reward.isCoins || quest.deliveryInfo.Reward.isRP || quest.deliveryInfo.Reward.isHuntXP)
  1869. DeliveryHelp(player, 4);
  1870. else
  1871. {
  1872. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.3 0.8", "0.7 0.97");
  1873. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1874. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("creHelIH", player.UserIDString)} 'quest item'</color>", 20, "0.1 0", "0.9 1");
  1875. CuiHelper.AddUi(player, HelpMain);
  1876. }
  1877. }
  1878. return;
  1879. case 4:
  1880. ActiveCreations[player.userID].partNum = 5;
  1881. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9");
  1882. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1883. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("delHelRM", player.UserIDString)}</color> {textSecondary}\n\n{LA("delHelRM1", player.UserIDString)}</color>{textPrimary} 2000m</color>{textSecondary} {LA("delHelRM2", player.UserIDString)} </color>{textPrimary}0.25</color>{textSecondary}, {LA("delHelRM3", player.UserIDString)} </color>{textPrimary}500</color>", 20, "0.05 0.1", "0.95 0.9");
  1884. CuiHelper.AddUi(player, HelpMain);
  1885. return;
  1886. case 5:
  1887. ActiveCreations[player.userID].partNum = 3;
  1888. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9");
  1889. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1890. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("delHelDD", player.UserIDString)}</color>", 20, "0.05 0.1", "0.95 0.9");
  1891. CuiHelper.AddUi(player, HelpMain);
  1892. return;
  1893. case 6:
  1894. {
  1895. HelpMain = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9", true);
  1896. QUI.CreatePanel(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1897. QUI.CreateLabel(ref HelpMain, UIPanel, "", $"{textPrimary}{LA("delHelNewV", player.UserIDString)}</color>", 20, "0.1 0.8", "0.9 0.95");
  1898.  
  1899. var quest = ActiveCreations[player.userID];
  1900. string questDetails = $"{textPrimary}{LA("Quest Type:", player.UserIDString)}</color> {textSecondary}{quest.type}</color>";
  1901. questDetails = questDetails + $"\n{textPrimary}{LA("Name:", player.UserIDString)}</color> {textSecondary}{quest.deliveryInfo.Info.Name}</color>";
  1902. questDetails = questDetails + $"\n{textPrimary}{LA("Desc", player.UserIDString)}</color> {textSecondary}{quest.deliveryInfo.Description}</color>";
  1903. questDetails = questDetails + $"\n{textPrimary}{LA("Reward:", player.UserIDString)}</color> {textSecondary}{quest.deliveryInfo.Reward.DisplayName}</color>";
  1904. questDetails = questDetails + $"\n{textPrimary}{LA("Multiplier:", player.UserIDString)}</color> {textSecondary}{quest.deliveryInfo.Multiplier}</color>";
  1905.  
  1906. QUI.CreateLabel(ref HelpMain, UIPanel, "", questDetails, 20, "0.1 0.2", "0.9 0.75", TextAnchor.MiddleLeft);
  1907. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Save Quest", player.UserIDString), 18, "0.6 0.05", "0.8 0.15", $"QUI_SaveQuest");
  1908. QUI.CreateButton(ref HelpMain, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Cancel", player.UserIDString), 18, "0.2 0.05", "0.4 0.15", $"QUI_ExitQuest");
  1909. CuiHelper.AddUi(player, HelpMain);
  1910. }
  1911. return;
  1912. default:
  1913. return;
  1914. }
  1915. }
  1916.  
  1917. private void AcceptDelivery(BasePlayer player, string npcID, int page = 0)
  1918. {
  1919. var quest = vendors.DeliveryVendors[npcID];
  1920.  
  1921. switch (page)
  1922. {
  1923. case 0:
  1924. {
  1925. if (vendors.DeliveryVendors.Keys.ToList().Count == 1)
  1926. {
  1927. PopupMessage(player, LA("minDV", player.UserIDString));
  1928. return;
  1929. }
  1930.  
  1931. var target = vendors.DeliveryVendors[GetRandomNPC(npcID)];
  1932. if (quest != null && target != null)
  1933. {
  1934. var distance = Vector2.Distance(new Vector2(quest.Info.x, quest.Info.z), new Vector2(target.Info.x, target.Info.z));
  1935. var rewardAmount = distance * quest.Multiplier;
  1936. if (rewardAmount < 1) rewardAmount = 1;
  1937. var briefing = $"{textPrimary}{quest.Info.Name}\n\n</color>";
  1938. briefing = briefing + $"{textSecondary}{quest.Description}</color>\n\n";
  1939. briefing = briefing + $"{textPrimary}{LA("Destination:", player.UserIDString)} </color>{textSecondary}{target.Info.Name}\nX {target.Info.x}, Z {target.Info.z}</color>\n";
  1940. briefing = briefing + $"{textPrimary}{LA("Distance:", player.UserIDString)} </color>{textSecondary}{distance}M</color>\n";
  1941. briefing = briefing + $"{textPrimary}{LA("Reward:", player.UserIDString)} </color>{textSecondary}{(int)rewardAmount}x {quest.Reward.DisplayName}</color>";
  1942.  
  1943. var VendorUI = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9", true);
  1944. QUI.CreatePanel(ref VendorUI, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1945. QUI.CreateLabel(ref VendorUI, UIPanel, "", briefing, 20, "0.15 0.2", "0.85 1", TextAnchor.MiddleLeft);
  1946.  
  1947. QUI.CreateButton(ref VendorUI, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Accept", player.UserIDString), 18, "0.6 0.05", "0.8 0.15", $"QUI_AcceptDelivery {npcID} {target.Info.ID} {distance}");
  1948. QUI.CreateButton(ref VendorUI, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Decline", player.UserIDString), 18, "0.2 0.05", "0.4 0.15", $"QUI_DestroyAll");
  1949. CuiHelper.AddUi(player, VendorUI);
  1950. }
  1951. }
  1952. return;
  1953. case 1:
  1954. {
  1955. var VendorUI = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.4 0.3", "0.95 0.9", true);
  1956. QUI.CreatePanel(ref VendorUI, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  1957. QUI.CreateLabel(ref VendorUI, UIPanel, "", $"{textPrimary} {LA("delComplMSG", player.UserIDString)}</color>", 22, "0 0", "1 1");
  1958. QUI.CreateButton(ref VendorUI, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Claim", player.UserIDString), 18, "0.6 0.05", "0.8 0.15", $"QUI_FinishDelivery {npcID}");
  1959. QUI.CreateButton(ref VendorUI, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Cancel", player.UserIDString), 18, "0.2 0.05", "0.4 0.15", $"QUI_DestroyAll");
  1960. CuiHelper.AddUi(player, VendorUI);
  1961. }
  1962. return;
  1963. default:
  1964. return;
  1965. }
  1966. }
  1967.  
  1968. private void DeletionEditMenu(BasePlayer player, string page, string command)
  1969. {
  1970. DestroyEntries(player);
  1971. var Main = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.12 0", "1 1");
  1972. QUI.CreatePanel(ref Main, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.01", "0.99 0.99", true);
  1973. QUI.CreateLabel(ref Main, UIPanel, "1 1 1 0.025", page, 200, "0.01 0.01", "0.99 0.99");
  1974.  
  1975. QUI.CreateLabel(ref Main, UIPanel, "", $"{textPrimary}{LA("Kill", player.UserIDString)}</color>", 20, "0 0.87", "0.25 0.92");
  1976. QUI.CreateLabel(ref Main, UIPanel, "", $"{textPrimary}{LA("Gather", player.UserIDString)}</color>", 20, "0.25 0.87", "0.5 0.92");
  1977. QUI.CreateLabel(ref Main, UIPanel, "", $"{textPrimary}{LA("Loot", player.UserIDString)}</color>", 20, "0.5 0.87", "0.75 0.92");
  1978. QUI.CreateLabel(ref Main, UIPanel, "", $"{textPrimary}{LA("Craft", player.UserIDString)}</color>", 20, "0.75 0.87", "1 0.92");
  1979. if (command == "QUI_ConfirmDelete") QUI.CreateButton(ref Main, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), $"{textPrimary}{LA("Delete NPC", player.UserIDString)}</color>", 18, "0.8 0.94", "0.98 0.98", "QUI_DeleteNPCMenu");
  1980.  
  1981. int killNum = 0;
  1982. int gatherNum = 0;
  1983. int lootNum = 0;
  1984. int craftNum = 0;
  1985. foreach (var entry in questData.Quest[QuestType.Kill])
  1986. {
  1987. CreateDelEditButton(ref Main, 0.035f, UIPanel, entry.Key, killNum, command);
  1988. killNum++;
  1989. }
  1990.  
  1991. foreach (var entry in questData.Quest[QuestType.Gather])
  1992. {
  1993. CreateDelEditButton(ref Main, 0.285f, UIPanel, entry.Key, gatherNum, command);
  1994. gatherNum++;
  1995. }
  1996.  
  1997. foreach (var entry in questData.Quest[QuestType.Loot])
  1998. {
  1999. CreateDelEditButton(ref Main, 0.535f, UIPanel, entry.Key, lootNum, command);
  2000. lootNum++;
  2001. }
  2002.  
  2003. foreach (var entry in questData.Quest[QuestType.Craft])
  2004. {
  2005. CreateDelEditButton(ref Main, 0.785f, UIPanel, entry.Key, craftNum, command);
  2006. craftNum++;
  2007. }
  2008.  
  2009. CuiHelper.AddUi(player, Main);
  2010. }
  2011.  
  2012. private void DeleteNPCMenu(BasePlayer player)
  2013. {
  2014. DestroyEntries(player);
  2015. var Main = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.12 0", "1 1");
  2016. QUI.CreatePanel(ref Main, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.01", "0.99 0.99", true);
  2017. QUI.CreateLabel(ref Main, UIPanel, "1 1 1 0.025", LA("REMOVER", player.UserIDString), 200, "0.01 0.01", "0.99 0.99");
  2018.  
  2019. QUI.CreateLabel(ref Main, UIPanel, "", $"{textPrimary}{LA("Delivery Vendors", player.UserIDString)}</color>", 20, "0 0.87", "0.5 0.92");
  2020. QUI.CreateLabel(ref Main, UIPanel, "", $"{textPrimary}{LA("Quest Vendors", player.UserIDString)}</color>", 20, "0.5 0.87", "1 0.92");
  2021.  
  2022. int VendorNum = 0;
  2023. int DeliveryNum = 0;
  2024. foreach (var entry in vendors.QuestVendors)
  2025. {
  2026. CreateDelVendorButton(ref Main, 0.535f, UIPanel, entry.Value.Name, DeliveryNum, $"QUI_RemoveVendor {entry.Key}");
  2027. VendorNum++;
  2028. }
  2029.  
  2030. foreach (var entry in vendors.DeliveryVendors)
  2031. {
  2032. CreateDelVendorButton(ref Main, 0.035f, UIPanel, entry.Value.Info.Name, DeliveryNum, $"QUI_RemoveVendor {entry.Key}");
  2033. DeliveryNum++;
  2034. }
  2035.  
  2036. CuiHelper.AddUi(player, Main);
  2037. }
  2038.  
  2039. private void ConfirmDeletion(BasePlayer player, string questName)
  2040. {
  2041. var ConfirmDelete = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.2 0.4", "0.8 0.8", true);
  2042. QUI.CreatePanel(ref ConfirmDelete, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  2043. QUI.CreateLabel(ref ConfirmDelete, UIPanel, "", $"{textPrimary}{LA("confDel", player.UserIDString)} {questName}</color>", 20, "0.1 0.6", "0.9 0.9");
  2044. QUI.CreateButton(ref ConfirmDelete, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Yes", player.UserIDString), 18, "0.6 0.2", "0.8 0.3", $"QUI_DeleteQuest {questName}");
  2045. QUI.CreateButton(ref ConfirmDelete, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("No", player.UserIDString), 18, "0.2 0.2", "0.4 0.3", $"QUI_DeleteQuest reject");
  2046.  
  2047. CuiHelper.AddUi(player, ConfirmDelete);
  2048. }
  2049.  
  2050. private void ConfirmCancellation(BasePlayer player, string questName)
  2051. {
  2052. var ConfirmDelete = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.2 0.4", "0.8 0.8", true);
  2053. QUI.CreatePanel(ref ConfirmDelete, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.02", "0.99 0.98");
  2054. QUI.CreateLabel(ref ConfirmDelete, UIPanel, "", $"{textPrimary}{LA("confCan", player.UserIDString)} {questName}</color>\n{textSecondary}{LA("confCan2", player.UserIDString)}</color>", 20, "0.1 0.6", "0.9 0.9");
  2055. QUI.CreateButton(ref ConfirmDelete, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("Yes", player.UserIDString), 18, "0.6 0.2", "0.8 0.3", $"QUI_ConfirmCancel {questName}");
  2056. QUI.CreateButton(ref ConfirmDelete, UIPanel, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), LA("No", player.UserIDString), 18, "0.2 0.2", "0.4 0.3", $"QUI_ConfirmCancel reject");
  2057.  
  2058. CuiHelper.AddUi(player, ConfirmDelete);
  2059. }
  2060.  
  2061. private void QuestEditorMenu(BasePlayer player)
  2062. {
  2063. DestroyEntries(player);
  2064. var Main = QUI.CreateElementContainer(UIPanel, QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.12 0", "1 1");
  2065. QUI.CreatePanel(ref Main, UIPanel, QUI.Color(configData.Colors.Background_Light.Color, configData.Colors.Background_Light.Alpha), "0.01 0.01", "0.99 0.99", true);
  2066. QUI.CreateLabel(ref Main, UIPanel, "1 1 1 0.025", LA("EDITOR", player.UserIDString), 200, "0.01 0.01", "0.99 0.99");
  2067.  
  2068. int i = 0;
  2069. QUI.CreateLabel(ref Main, UIPanel, "", $"{textPrimary}{LA("chaEdi", player.UserIDString)}</color>", 20, "0.25 0.8", "0.75 0.9");
  2070. CreateNewQuestButton(ref Main, UIPanel, LA("Name", player.UserIDString), "QUI_EditQuestVar name", i); i++;
  2071. CreateNewQuestButton(ref Main, UIPanel, LA("Description", player.UserIDString), "QUI_EditQuestVar description", i); i++;
  2072. CreateNewQuestButton(ref Main, UIPanel, LA("Objective", player.UserIDString), "QUI_EditQuestVar objective", i); i++;
  2073. CreateNewQuestButton(ref Main, UIPanel, LA("Amount", player.UserIDString), "QUI_EditQuestVar amount", i); i++;
  2074. CreateNewQuestButton(ref Main, UIPanel, LA("Reward", player.UserIDString), "QUI_EditQuestVar reward", i); i++;
  2075.  
  2076. CuiHelper.AddUi(player, Main);
  2077. }
  2078.  
  2079. private void CreateObjectiveEntry(ref CuiElementContainer container, string panelName, string name, int number)
  2080. {
  2081. var pos = CalcEntryPos(number);
  2082. QUI.CreateButton(ref container, panelName, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), name, 10, $"{pos[0]} {pos[1]}", $"{pos[2]} {pos[3]}", $"QUI_SelectObj {name}");
  2083. }
  2084.  
  2085. private void CreateNewQuestButton(ref CuiElementContainer container, string panelName, string buttonname, string command, int number)
  2086. {
  2087. Vector2 dimensions = new Vector2(0.2f, 0.07f);
  2088. Vector2 origin = new Vector2(0.4f, 0.7f);
  2089. Vector2 offset = new Vector2(0, (0.01f + dimensions.y) * number);
  2090.  
  2091. Vector2 posMin = origin - offset;
  2092. Vector2 posMax = posMin + dimensions;
  2093.  
  2094. QUI.CreateButton(ref container, panelName, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), buttonname, 18, $"{posMin.x} {posMin.y}", $"{posMax.x} {posMax.y}", command);
  2095. }
  2096.  
  2097. private void CreateRewardTypeButton(ref CuiElementContainer container, string panelName, string buttonname, string command, int number)
  2098. {
  2099. Vector2 dimensions = new Vector2(0.36f, 0.1f);
  2100. Vector2 origin = new Vector2(0.32f, 0.7f);
  2101. Vector2 offset = new Vector2(0, (0.01f + dimensions.y) * number);
  2102.  
  2103. Vector2 posMin = origin - offset;
  2104. Vector2 posMax = posMin + dimensions;
  2105.  
  2106. QUI.CreateButton(ref container, panelName, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), buttonname, 18, $"{posMin.x} {posMin.y}", $"{posMax.x} {posMax.y}", command);
  2107. }
  2108.  
  2109. private void CreateDelEditButton(ref CuiElementContainer container, float xPos, string panelName, string buttonname, int number, string command, float width = 0.18f)
  2110. {
  2111. Vector2 dimensions = new Vector2(width, 0.05f);
  2112. Vector2 origin = new Vector2(xPos, 0.8f);
  2113. Vector2 offset = new Vector2(0, (-0.01f - dimensions.y) * number);
  2114.  
  2115. Vector2 posMin = origin + offset;
  2116. Vector2 posMax = posMin + dimensions;
  2117.  
  2118. QUI.CreateButton(ref container, panelName, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), buttonname, 14, $"{posMin.x} {posMin.y}", $"{posMax.x} {posMax.y}", $"{command} {buttonname}");
  2119. }
  2120.  
  2121. private void CreateDelVendorButton(ref CuiElementContainer container, float xPos, string panelName, string buttonname, int number, string command)
  2122. {
  2123. if (number > 15) xPos += 0.25f;
  2124. Vector2 dimensions = new Vector2(0.18f, 0.05f);
  2125. Vector2 origin = new Vector2(xPos, 0.8f);
  2126. Vector2 offset = new Vector2(0, (-0.01f - dimensions.y) * number);
  2127.  
  2128. Vector2 posMin = origin + offset;
  2129. Vector2 posMax = posMin + dimensions;
  2130.  
  2131. QUI.CreateButton(ref container, panelName, QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), buttonname, 14, $"{posMin.x} {posMin.y}", $"{posMax.x} {posMax.y}", command);
  2132. }
  2133.  
  2134. private void PopupMessage(BasePlayer player, string msg)
  2135. {
  2136. CuiHelper.DestroyUi(player, "PopupMsg");
  2137. var element = QUI.CreateElementContainer("PopupMsg", QUI.Color(configData.Colors.Background_Dark.Color, configData.Colors.Background_Dark.Alpha), "0.25 0.85", "0.75 0.95");
  2138. QUI.CreatePanel(ref element, "PopupMsg", QUI.Color(configData.Colors.Button_Standard.Color, configData.Colors.Button_Standard.Alpha), "0.005 0.04", "0.995 0.96");
  2139. QUI.CreateLabel(ref element, "PopupMsg", "", $"{textPrimary}{msg}</color>", 22, "0 0", "1 1");
  2140. CuiHelper.AddUi(player, element);
  2141. timer.Once(3, () => CuiHelper.DestroyUi(player, "PopupMsg"));
  2142. }
  2143.  
  2144. private Vector2 CalcQuestPos(int number)
  2145. {
  2146. Vector2 position = new Vector2(0.1325f, 0.71f);
  2147. Vector2 dimensions = new Vector2(0.21f, 0.22f);
  2148. float offsetY = 0f;
  2149. float offsetX = 0;
  2150. if (number >= 0 && number < 4)
  2151. {
  2152. offsetX = (0.005f + dimensions.x) * number;
  2153. }
  2154.  
  2155. if (number > 3 && number < 8)
  2156. {
  2157. offsetX = (0.005f + dimensions.x) * (number - 4);
  2158. offsetY = (-0.008f - dimensions.y) * 1;
  2159. }
  2160.  
  2161. if (number > 7 && number < 12)
  2162. {
  2163. offsetX = (0.005f + dimensions.x) * (number - 8);
  2164. offsetY = (-0.008f - dimensions.y) * 2;
  2165. }
  2166.  
  2167. if (number > 11 && number < 16)
  2168. {
  2169. offsetX = (0.005f + dimensions.x) * (number - 12);
  2170. offsetY = (-0.008f - dimensions.y) * 3;
  2171. }
  2172.  
  2173. return new Vector2(position.x + offsetX, position.y + offsetY);
  2174. }
  2175.  
  2176. private float[] CalcEntryPos(int number)
  2177. {
  2178. Vector2 position = new Vector2(0.014f, 0.8f);
  2179. Vector2 dimensions = new Vector2(0.12f, 0.055f);
  2180. float offsetY = 0;
  2181. float offsetX = 0;
  2182. if (number >= 0 && number < 8)
  2183. {
  2184. offsetX = (0.002f + dimensions.x) * number;
  2185. }
  2186.  
  2187. if (number > 7 && number < 16)
  2188. {
  2189. offsetX = (0.002f + dimensions.x) * (number - 8);
  2190. offsetY = (-0.0055f - dimensions.y) * 1;
  2191. }
  2192.  
  2193. if (number > 15 && number < 24)
  2194. {
  2195. offsetX = (0.002f + dimensions.x) * (number - 16);
  2196. offsetY = (-0.0055f - dimensions.y) * 2;
  2197. }
  2198.  
  2199. if (number > 23 && number < 32)
  2200. {
  2201. offsetX = (0.002f + dimensions.x) * (number - 24);
  2202. offsetY = (-0.0055f - dimensions.y) * 3;
  2203. }
  2204.  
  2205. if (number > 31 && number < 40)
  2206. {
  2207. offsetX = (0.002f + dimensions.x) * (number - 32);
  2208. offsetY = (-0.0055f - dimensions.y) * 4;
  2209. }
  2210.  
  2211. if (number > 39 && number < 48)
  2212. {
  2213. offsetX = (0.002f + dimensions.x) * (number - 40);
  2214. offsetY = (-0.0055f - dimensions.y) * 5;
  2215. }
  2216.  
  2217. if (number > 47 && number < 56)
  2218. {
  2219. offsetX = (0.002f + dimensions.x) * (number - 48);
  2220. offsetY = (-0.0055f - dimensions.y) * 6;
  2221. }
  2222.  
  2223. if (number > 55 && number < 64)
  2224. {
  2225. offsetX = (0.002f + dimensions.x) * (number - 56);
  2226. offsetY = (-0.0055f - dimensions.y) * 7;
  2227. }
  2228.  
  2229. if (number > 63 && number < 72)
  2230. {
  2231. offsetX = (0.002f + dimensions.x) * (number - 64);
  2232. offsetY = (-0.0055f - dimensions.y) * 8;
  2233. }
  2234.  
  2235. if (number > 71 && number < 80)
  2236. {
  2237. offsetX = (0.002f + dimensions.x) * (number - 72);
  2238. offsetY = (-0.0055f - dimensions.y) * 9;
  2239. }
  2240.  
  2241. if (number > 79 && number < 88)
  2242. {
  2243. offsetX = (0.002f + dimensions.x) * (number - 80);
  2244. offsetY = (-0.0055f - dimensions.y) * 10;
  2245. }
  2246.  
  2247. if (number > 87 && number < 96)
  2248. {
  2249. offsetX = (0.002f + dimensions.x) * (number - 88);
  2250. offsetY = (-0.0055f - dimensions.y) * 11;
  2251. }
  2252.  
  2253. Vector2 offset = new Vector2(offsetX, offsetY);
  2254. Vector2 posMin = position + offset;
  2255. Vector2 posMax = posMin + dimensions;
  2256. return new float[] { posMin.x, posMin.y, posMax.x, posMax.y };
  2257. }
  2258.  
  2259. private void AddUIString(BasePlayer player, string name)
  2260. {
  2261. if (!OpenUI.ContainsKey(player.userID))
  2262. OpenUI.Add(player.userID, new List<string>());
  2263. OpenUI[player.userID].Add(name);
  2264. }
  2265.  
  2266. private void DestroyUI(BasePlayer player)
  2267. {
  2268. CuiHelper.DestroyUi(player, UIMain);
  2269. DestroyEntries(player);
  2270. }
  2271.  
  2272. private void DestroyEntries(BasePlayer player)
  2273. {
  2274. CuiHelper.DestroyUi(player, UIPanel);
  2275. if (OpenUI.ContainsKey(player.userID))
  2276. {
  2277. foreach (var entry in OpenUI[player.userID])
  2278. CuiHelper.DestroyUi(player, entry);
  2279. OpenUI.Remove(player.userID);
  2280. }
  2281. }
  2282.  
  2283. #endregion
  2284.  
  2285. #region UI Commands
  2286.  
  2287. [ConsoleCommand("QUI_AcceptQuest")]
  2288. private void cmdAcceptQuest(ConsoleSystem.Arg arg)
  2289. {
  2290. var player = arg.Connection.player as BasePlayer;
  2291. if (player == null)
  2292. return;
  2293. var questName = string.Join(" ", arg.Args);
  2294. CheckPlayerEntry(player);
  2295. var data = PlayerProgress[player.userID].Quests;
  2296. if (!data.ContainsKey(questName))
  2297. {
  2298. var type = GetQuestType(questName);
  2299. if (type != null)
  2300. {
  2301. var quest = Quest[(QuestType)type][questName];
  2302. data.Add(questName, new PlayerQuestInfo { Status = QuestStatus.Pending, Type = (QuestType)type });
  2303. PlayerProgress[player.userID].RequiredItems.Add(new QuestInfo { ShortName = quest.Objective, Type = (QuestType)type });
  2304. DestroyEntries(player);
  2305. ListElement(player, (QuestType)type);
  2306. PopupMessage(player, $"{LA("qAccep", player.UserIDString)} {questName}");
  2307. return;
  2308. }
  2309. }
  2310. }
  2311.  
  2312. [ConsoleCommand("QUI_AcceptDelivery")]
  2313. private void cmdAcceptDelivery(ConsoleSystem.Arg arg)
  2314. {
  2315. var player = arg.Connection.player as BasePlayer;
  2316. if (player == null)
  2317. return;
  2318. var vendorID = arg.Args[0];
  2319. var targetID = arg.Args[1];
  2320. var distance = arg.Args[2];
  2321. PlayerProgress[player.userID].CurrentDelivery = new ActiveDelivery { VendorID = vendorID, TargetID = targetID, Distance = float.Parse(distance) };
  2322. PopupMessage(player, LA("dAccep", player.UserIDString));
  2323. DestroyUI(player);
  2324. }
  2325.  
  2326. [ConsoleCommand("QUI_CancelDelivery")]
  2327. private void cmdCancelDelivery(ConsoleSystem.Arg arg)
  2328. {
  2329. var player = arg.Connection.player as BasePlayer;
  2330. if (player == null)
  2331. return;
  2332. if (!string.IsNullOrEmpty(PlayerProgress[player.userID].CurrentDelivery.TargetID))
  2333. {
  2334. PlayerProgress[player.userID].CurrentDelivery = new ActiveDelivery();
  2335. DestroyUI(player);
  2336. PopupMessage(player, LA("canConf", player.UserIDString));
  2337. }
  2338. }
  2339.  
  2340. [ConsoleCommand("QUI_FinishDelivery")]
  2341. private void cmdFinishDelivery(ConsoleSystem.Arg arg)
  2342. {
  2343. var player = arg.Connection.player as BasePlayer;
  2344. if (player == null)
  2345. return;
  2346.  
  2347. if (PlayerProgress[player.userID].CurrentDelivery != null && PlayerProgress[player.userID].CurrentDelivery.TargetID == arg.GetString(0))
  2348. {
  2349. var npcID = PlayerProgress[player.userID].CurrentDelivery.VendorID;
  2350. var distance = PlayerProgress[player.userID].CurrentDelivery.Distance;
  2351. var quest = vendors.DeliveryVendors[npcID];
  2352. var rewardAmount = distance * quest.Multiplier;
  2353. if (rewardAmount < 1) rewardAmount = 1;
  2354.  
  2355. var reward = quest.Reward;
  2356. reward.Amount = rewardAmount;
  2357. if (GiveReward(player, new List<RewardItem> { reward }))
  2358. {
  2359. var rewards = GetRewardString(new List<RewardItem> { reward });
  2360. PopupMessage(player, $"{LA("rewRec", player.UserIDString)} {rewards}");
  2361. PlayerProgress[player.userID].CurrentDelivery = new ActiveDelivery();
  2362. }
  2363.  
  2364. DestroyUI(player);
  2365. }
  2366. }
  2367.  
  2368. [ConsoleCommand("QUI_ChangeElement")]
  2369. private void cmdChangeElement(ConsoleSystem.Arg arg)
  2370. {
  2371. var player = arg.Connection.player as BasePlayer;
  2372. if (player == null)
  2373. return;
  2374. CheckPlayerEntry(player);
  2375. var panelName = arg.GetString(0);
  2376. switch (panelName)
  2377. {
  2378. case "kill":
  2379. ListElement(player, QuestType.Kill);
  2380. return;
  2381. case "gather":
  2382. ListElement(player, QuestType.Gather);
  2383. return;
  2384. case "loot":
  2385. ListElement(player, QuestType.Loot);
  2386. return;
  2387. case "craft":
  2388. ListElement(player, QuestType.Craft);
  2389. return;
  2390. case "delivery":
  2391. PlayerDelivery(player);
  2392. return;
  2393. case "personal":
  2394. PlayerStats(player);
  2395. return;
  2396. case "editor":
  2397. if (isAdmin(player))
  2398. DeletionEditMenu(player, LA("EDITOR", player.UserIDString), "QUI_EditQuest");
  2399. return;
  2400. case "creation":
  2401. if (isAdmin(player))
  2402. {
  2403. if (ActiveCreations.ContainsKey(player.userID))
  2404. ActiveCreations.Remove(player.userID);
  2405. CreationMenu(player);
  2406. }
  2407. return;
  2408. case "objpage":
  2409. if (isAdmin(player))
  2410. {
  2411. var pageNumber = arg.GetString(1);
  2412. CreateObjectiveMenu(player, int.Parse(pageNumber));
  2413. }
  2414. return;
  2415. case "listpage":
  2416. {
  2417. var pageNumber = arg.GetString(2);
  2418. var type = ConvertStringToType(arg.GetString(1));
  2419. ListElement(player, type, int.Parse(pageNumber));
  2420. }
  2421. return;
  2422. case "statspage":
  2423. {
  2424. var pageNumber = arg.GetString(1);
  2425. PlayerStats(player, int.Parse(pageNumber));
  2426. }
  2427. return;
  2428. }
  2429. }
  2430.  
  2431. [ConsoleCommand("QUI_DestroyAll")]
  2432. private void cmdDestroyAll(ConsoleSystem.Arg arg)
  2433. {
  2434. var player = arg.Connection.player as BasePlayer;
  2435. if (player == null)
  2436. return;
  2437. if (StatsMenu.Contains(player.userID))
  2438. StatsMenu.Remove(player.userID);
  2439. if (ActiveCreations.ContainsKey(player.userID))
  2440. ActiveCreations.Remove(player.userID);
  2441. if (ActiveEditors.ContainsKey(player.userID))
  2442. ActiveEditors.Remove(player.userID);
  2443. if (OpenMenuBind.Contains(player.userID))
  2444. OpenMenuBind.Remove(player.userID);
  2445. DestroyUI(player);
  2446. OpenMap(player);
  2447. }
  2448.  
  2449. [ConsoleCommand("QUI_NewQuest")]
  2450. private void cmdNewQuest(ConsoleSystem.Arg arg)
  2451. {
  2452. var player = arg.Connection.player as BasePlayer;
  2453. if (player == null)
  2454. return;
  2455. if (isAdmin(player))
  2456. {
  2457. var questType = arg.GetString(0);
  2458. var Type = ConvertStringToType(questType);
  2459. if (Type == QuestType.Delivery)
  2460. {
  2461. DeliveryHelp(player);
  2462. return;
  2463. }
  2464.  
  2465. ActiveCreations.Add(player.userID, new QuestCreator { type = Type, entry = new QuestEntry { Rewards = new List<RewardItem>() }, item = new RewardItem() });
  2466. DestroyUI(player);
  2467. CreationHelp(player);
  2468. }
  2469. }
  2470.  
  2471. [ConsoleCommand("QUI_AddVendor")]
  2472. private void cmdAddVendor(ConsoleSystem.Arg arg)
  2473. {
  2474. var player = arg.Connection.player as BasePlayer;
  2475. if (player == null)
  2476. return;
  2477. if (isAdmin(player))
  2478. {
  2479. var vendorType = arg.GetString(0);
  2480. bool isVendor = false;
  2481. if (vendorType == "1")
  2482. isVendor = true;
  2483. if (!AddVendor.ContainsKey(player.userID))
  2484. AddVendor.Add(player.userID, isVendor);
  2485. DestroyUI(player);
  2486. DeliveryHelp(player, 1);
  2487. }
  2488. }
  2489.  
  2490. [ConsoleCommand("QUI_SelectObj")]
  2491. private void cmdSelectObj(ConsoleSystem.Arg arg)
  2492. {
  2493. var player = arg.Connection.player as BasePlayer;
  2494. if (player == null)
  2495. return;
  2496. if (isAdmin(player))
  2497. {
  2498. var questItem = string.Join(" ", arg.Args);
  2499. QuestCreator Creator;
  2500. if (ActiveCreations.ContainsKey(player.userID))
  2501. Creator = ActiveCreations[player.userID];
  2502. else Creator = ActiveEditors[player.userID];
  2503.  
  2504. Creator.entry.Objective = questItem;
  2505. if (DisplayNames.ContainsKey(questItem))
  2506. Creator.entry.ObjectiveName = DisplayNames[questItem];
  2507. else
  2508. Creator.entry.ObjectiveName = questItem;
  2509.  
  2510. Creator.partNum++;
  2511. DestroyUI(player);
  2512.  
  2513. CreationHelp(player, 2);
  2514. }
  2515. }
  2516.  
  2517. [ConsoleCommand("QUI_RewardType")]
  2518. private void cmdRewardType(ConsoleSystem.Arg arg)
  2519. {
  2520. var player = arg.Connection.player as BasePlayer;
  2521. if (player == null)
  2522. return;
  2523. if (isAdmin(player))
  2524. {
  2525. var rewardType = arg.GetString(0);
  2526. QuestCreator Creator;
  2527.  
  2528. if (ActiveCreations.ContainsKey(player.userID))
  2529. Creator = ActiveCreations[player.userID];
  2530. else Creator = ActiveEditors[player.userID];
  2531.  
  2532. bool isRP = false;
  2533. bool isCoins = false;
  2534. bool isHuntXP = false;
  2535. string name = "";
  2536.  
  2537. switch (rewardType)
  2538. {
  2539. case "rp":
  2540. isRP = true;
  2541. name = LA("RP", player.UserIDString);
  2542. break;
  2543. case "coins":
  2544. isCoins = true;
  2545. name = LA("Coins", player.UserIDString);
  2546. break;
  2547. case "huntxp":
  2548. isHuntXP = true;
  2549. name = LA("HuntXP", player.UserIDString);
  2550. break;
  2551. default:
  2552. break;
  2553. }
  2554.  
  2555. Creator.partNum = 5;
  2556. if (Creator.type != QuestType.Delivery)
  2557. {
  2558. Creator.item.isRP = isRP;
  2559. Creator.item.isCoins = isCoins;
  2560. Creator.item.isHuntXP = isHuntXP;
  2561. Creator.item.DisplayName = name;
  2562. CreationHelp(player, 5);
  2563. }
  2564. else
  2565. {
  2566. Creator.deliveryInfo.Reward.isRP = isRP;
  2567. Creator.deliveryInfo.Reward.isCoins = isCoins;
  2568. Creator.deliveryInfo.Reward.isHuntXP = isHuntXP;
  2569. Creator.deliveryInfo.Reward.DisplayName = name;
  2570. DeliveryHelp(player, 3);
  2571. }
  2572. }
  2573. }
  2574.  
  2575. [ConsoleCommand("QUI_ClaimReward")]
  2576. private void cmdClaimReward(ConsoleSystem.Arg arg)
  2577. {
  2578. var player = arg.Connection.player as BasePlayer;
  2579. if (player == null)
  2580. return;
  2581.  
  2582. var questName = string.Join(" ", arg.Args);
  2583. var quest = GetQuest(questName);
  2584. if (quest == null) return;
  2585.  
  2586. if (IsQuestCompleted(player.userID, questName))
  2587. {
  2588. if (GiveReward(player, quest.Rewards))
  2589. {
  2590. var rewards = GetRewardString(quest.Rewards);
  2591. PopupMessage(player, $"{LA("rewRec", player.UserIDString)} {rewards}");
  2592. SendMSG(player, $"{LA("rewRec", player.UserIDString)} {rewards}");
  2593. PlayerProgress[player.userID].Quests[questName].RewardClaimed = true;
  2594. }
  2595. else
  2596. {
  2597. PopupMessage(player, LA("rewError", player.UserIDString));
  2598. SendMSG(player, LA("rewError", player.UserIDString));
  2599. }
  2600. }
  2601.  
  2602. PlayerStats(player);
  2603. }
  2604.  
  2605. bool IsQuestCompleted(ulong playerId, string questName = "") => !string.IsNullOrEmpty(questName) && PlayerProgress[playerId].Quests[questName].Status == QuestStatus.Completed;
  2606.  
  2607. [ConsoleCommand("QUI_CancelQuest")]
  2608. private void cmdCancelQuest(ConsoleSystem.Arg arg)
  2609. {
  2610. var player = arg.Connection.player as BasePlayer;
  2611. if (player == null)
  2612. return;
  2613. var questName = string.Join(" ", arg.Args);
  2614. DestroyUI(player);
  2615. ConfirmCancellation(player, questName);
  2616. }
  2617.  
  2618. [ConsoleCommand("QUI_ItemDeduction")]
  2619. private void cmdItemDeduction(ConsoleSystem.Arg arg)
  2620. {
  2621. var player = arg.Connection.player as BasePlayer;
  2622. if (player == null)
  2623. return;
  2624. if (isAdmin(player))
  2625. {
  2626. QuestCreator Creator;
  2627. if (ActiveCreations.ContainsKey(player.userID))
  2628. Creator = ActiveCreations[player.userID];
  2629. else Creator = ActiveEditors[player.userID];
  2630. switch (arg.Args[0])
  2631. {
  2632. case "0":
  2633. Creator.entry.ItemDeduction = false;
  2634. break;
  2635. default:
  2636. Creator.entry.ItemDeduction = true;
  2637. break;
  2638. }
  2639.  
  2640. CreationHelp(player, 9);
  2641. }
  2642. }
  2643.  
  2644. [ConsoleCommand("QUI_ConfirmCancel")]
  2645. private void cmdConfirmCancel(ConsoleSystem.Arg arg)
  2646. {
  2647. var player = arg.Connection.player as BasePlayer;
  2648. if (player == null)
  2649. return;
  2650. var questName = string.Join(" ", arg.Args);
  2651. if (questName.Contains("reject"))
  2652. {
  2653. DestroyUI(player);
  2654. if (StatsMenu.Contains(player.userID))
  2655. CreateEmptyMenu(player);
  2656. else CreateMenu(player);
  2657. PlayerStats(player);
  2658. return;
  2659. }
  2660.  
  2661. var quest = GetQuest(questName);
  2662. if (quest == null) return;
  2663. var info = PlayerProgress[player.userID];
  2664. var items = info.RequiredItems;
  2665. for (int i = 0; i < items.Count; i++)
  2666. {
  2667. if (items[i].ShortName == questName && items[i].Type == info.Quests[questName].Type)
  2668. {
  2669. items.Remove(items[i]);
  2670. break;
  2671. }
  2672. }
  2673.  
  2674. var type = (QuestType)GetQuestType(questName);
  2675. if (type != QuestType.Delivery && type != QuestType.Kill)
  2676. {
  2677. string questitem = quest.Objective;
  2678. int amount = info.Quests[questName].AmountCollected;
  2679. if (quest.ItemDeduction)
  2680. ReturnItems(player, questitem, amount);
  2681. }
  2682.  
  2683. PlayerProgress[player.userID].Quests.Remove(questName);
  2684.  
  2685. if (StatsMenu.Contains(player.userID))
  2686. CreateEmptyMenu(player);
  2687. else CreateMenu(player);
  2688.  
  2689. PlayerStats(player);
  2690. }
  2691.  
  2692. [ConsoleCommand("QUI_RemoveCompleted")]
  2693. private void cmdRemoveCompleted(ConsoleSystem.Arg arg)
  2694. {
  2695. var player = arg.Connection.player as BasePlayer;
  2696. if (player == null)
  2697. return;
  2698. var questName = string.Join(" ", arg.Args);
  2699. var quest = GetQuest(questName);
  2700. if (quest == null) return;
  2701. var info = PlayerProgress[player.userID];
  2702. var items = info.RequiredItems;
  2703. for (int i = 0; i < items.Count; i++)
  2704. {
  2705. if (items[i].ShortName == questName && items[i].Type == info.Quests[questName].Type)
  2706. {
  2707. items.Remove(items[i]);
  2708. break;
  2709. }
  2710. }
  2711.  
  2712. PlayerProgress[player.userID].Quests.Remove(questName);
  2713. PlayerStats(player);
  2714. }
  2715.  
  2716. [ConsoleCommand("QUI_DeleteQuest")]
  2717. private void cmdDeleteQuest(ConsoleSystem.Arg arg)
  2718. {
  2719. var player = arg.Connection.player as BasePlayer;
  2720. if (player == null)
  2721. return;
  2722. if (isAdmin(player))
  2723. {
  2724. if (arg.Args == null || arg.Args.Length == 0) return;
  2725.  
  2726. if (arg.Args.Length == 1 && arg.Args[0] == "reject")
  2727. {
  2728. DestroyUI(player);
  2729. CreateMenu(player);
  2730. return;
  2731. }
  2732.  
  2733. var questName = string.Join(" ", arg.Args);
  2734. RemoveQuest(questName);
  2735. DestroyUI(player);
  2736. CreateMenu(player);
  2737. }
  2738. }
  2739.  
  2740. [ConsoleCommand("QUI_DeleteNPCMenu")]
  2741. private void cmdDeleteNPCMenu(ConsoleSystem.Arg arg)
  2742. {
  2743. var player = arg.Connection.player as BasePlayer;
  2744. if (player == null)
  2745. return;
  2746. if (isAdmin(player))
  2747. {
  2748. DeleteNPCMenu(player);
  2749. }
  2750. }
  2751.  
  2752. [ConsoleCommand("QUI_RemoveVendor")]
  2753. private void cmdRemoveVendor(ConsoleSystem.Arg arg)
  2754. {
  2755. var player = arg.Connection.player as BasePlayer;
  2756. if (player == null)
  2757. return;
  2758. if (isAdmin(player))
  2759. {
  2760. var ID = arg.Args[0];
  2761. foreach (var npc in vendors.QuestVendors)
  2762. {
  2763. if (npc.Key == ID)
  2764. {
  2765. RemoveVendor(player, ID, true);
  2766. return;
  2767. }
  2768. }
  2769.  
  2770. foreach (var npc in vendors.DeliveryVendors)
  2771. {
  2772. if (npc.Key == ID)
  2773. {
  2774. RemoveVendor(player, ID, false);
  2775. return;
  2776. }
  2777. }
  2778. }
  2779. }
  2780.  
  2781. [ConsoleCommand("QUI_ConfirmDelete")]
  2782. private void cmdConfirmDelete(ConsoleSystem.Arg arg)
  2783. {
  2784. var player = arg.Connection.player as BasePlayer;
  2785. if (player == null)
  2786. return;
  2787. if (isAdmin(player))
  2788. {
  2789. var questName = string.Join(" ", arg.Args);
  2790. DestroyUI(player);
  2791. ConfirmDeletion(player, questName);
  2792. }
  2793. }
  2794.  
  2795. [ConsoleCommand("QUI_EditQuest")]
  2796. private void cmdEditQuest(ConsoleSystem.Arg arg)
  2797. {
  2798. var player = arg.Connection.player as BasePlayer;
  2799. if (player == null)
  2800. return;
  2801. if (isAdmin(player))
  2802. {
  2803. if (ActiveEditors.ContainsKey(player.userID))
  2804. ActiveEditors.Remove(player.userID);
  2805. ActiveEditors.Add(player.userID, new QuestCreator());
  2806.  
  2807. var questName = string.Join(" ", arg.Args);
  2808. var Quest = GetQuest(questName);
  2809. if (Quest == null) return;
  2810. ActiveEditors[player.userID].entry = Quest;
  2811. ActiveEditors[player.userID].oldEntry = Quest.QuestName;
  2812. ActiveEditors[player.userID].type = (QuestType)GetQuestType(questName);
  2813. ActiveEditors[player.userID].item = new RewardItem();
  2814. QuestEditorMenu(player);
  2815. }
  2816. }
  2817.  
  2818. [ConsoleCommand("QUI_EditQuestVar")]
  2819. private void cmdEditQuestVar(ConsoleSystem.Arg arg)
  2820. {
  2821. var player = arg.Connection.player as BasePlayer;
  2822. if (player == null)
  2823. return;
  2824. if (isAdmin(player))
  2825. {
  2826. if (ActiveEditors.ContainsKey(player.userID))
  2827. {
  2828. var Creator = ActiveEditors[player.userID];
  2829.  
  2830. DestroyUI(player);
  2831. switch (arg.Args[0].ToLower())
  2832. {
  2833. case "name":
  2834. CreationHelp(player, 0);
  2835. break;
  2836. case "description":
  2837. Creator.partNum = 3;
  2838. CreationHelp(player, 3);
  2839. break;
  2840. case "objective":
  2841. Creator.partNum = 1;
  2842. CreationHelp(player, 1);
  2843. break;
  2844. case "amount":
  2845. Creator.partNum = 2;
  2846. CreationHelp(player, 2);
  2847. break;
  2848. case "reward":
  2849. Creator.partNum = 4;
  2850. CreationHelp(player, 10);
  2851. break;
  2852. default:
  2853. return;
  2854. }
  2855. }
  2856. }
  2857. }
  2858.  
  2859. [ConsoleCommand("QUI_RemoveReward")]
  2860. private void cmdEditReward(ConsoleSystem.Arg arg)
  2861. {
  2862. var player = arg.Connection.player as BasePlayer;
  2863. if (player == null)
  2864. return;
  2865. if (isAdmin(player))
  2866. {
  2867. QuestCreator Creator = ActiveEditors[player.userID];
  2868. var amount = arg.Args[0];
  2869. var dispName = arg.Args[1];
  2870. foreach (var entry in Creator.entry.Rewards)
  2871. {
  2872. if (entry.Amount == float.Parse(amount) && entry.DisplayName == dispName)
  2873. {
  2874. Creator.entry.Rewards.Remove(entry);
  2875. break;
  2876. }
  2877. }
  2878.  
  2879. SaveRewardsEdit(player);
  2880. }
  2881. }
  2882.  
  2883. [ConsoleCommand("QUI_EndEditing")]
  2884. private void cmdEndEditing(ConsoleSystem.Arg arg)
  2885. {
  2886. var player = arg.Connection.player as BasePlayer;
  2887. if (player == null)
  2888. return;
  2889. if (isAdmin(player))
  2890. {
  2891. CreateMenu(player);
  2892. DeletionEditMenu(player, LA("EDITOR", player.UserIDString), "QUI_EditQuest");
  2893. }
  2894. }
  2895.  
  2896. [ConsoleCommand("QUI_SaveQuest")]
  2897. private void cmdSaveQuest(ConsoleSystem.Arg arg)
  2898. {
  2899. var player = arg.Connection.player as BasePlayer;
  2900. if (player == null)
  2901. return;
  2902. if (isAdmin(player))
  2903. {
  2904. bool creating = false;
  2905. if (ActiveCreations.ContainsKey(player.userID))
  2906. creating = true;
  2907. SaveQuest(player, creating);
  2908. }
  2909. }
  2910.  
  2911. [ConsoleCommand("QUI_ExitQuest")]
  2912. private void cmdExitQuest(ConsoleSystem.Arg arg)
  2913. {
  2914. var player = arg.Connection.player as BasePlayer;
  2915. if (player == null)
  2916. return;
  2917. if (isAdmin(player))
  2918. {
  2919. bool creating = false;
  2920. if (ActiveCreations.ContainsKey(player.userID))
  2921. creating = true;
  2922. ExitQuest(player, creating);
  2923. }
  2924. }
  2925.  
  2926. [ConsoleCommand("QUI_AddReward")]
  2927. private void cmdAddReward(ConsoleSystem.Arg arg)
  2928. {
  2929. var player = arg.Connection.player as BasePlayer;
  2930. if (player == null)
  2931. return;
  2932. if (isAdmin(player))
  2933. {
  2934. QuestCreator Creator;
  2935. if (ActiveCreations.ContainsKey(player.userID))
  2936. Creator = ActiveCreations[player.userID];
  2937. else Creator = ActiveEditors[player.userID];
  2938. Creator.partNum = 4;
  2939. CreationHelp(player, 4);
  2940. }
  2941. }
  2942.  
  2943. [ConsoleCommand("QUI_RewardFinish")]
  2944. private void cmdFinishReward(ConsoleSystem.Arg arg)
  2945. {
  2946. var player = arg.Connection.player as BasePlayer;
  2947. if (player == null)
  2948. return;
  2949. if (isAdmin(player))
  2950. {
  2951. CreationHelp(player, 8);
  2952. }
  2953. }
  2954.  
  2955. [ConsoleCommand("QUI_OpenQuestMenu")]
  2956. private void cmdOpenQuestMenu(ConsoleSystem.Arg arg)
  2957. {
  2958. var player = arg.Connection.player as BasePlayer;
  2959. if (player == null)
  2960. return;
  2961. if (!OpenMenuBind.Contains(player.userID))
  2962. {
  2963. cmdOpenMenu(player, "q", new string[0]);
  2964. OpenMenuBind.Add(player.userID);
  2965. }
  2966. }
  2967.  
  2968. #endregion
  2969.  
  2970. #region Chat Commands
  2971.  
  2972. [ChatCommand("q")]
  2973. void cmdOpenMenu(BasePlayer player, string command, string[] args)
  2974. {
  2975. if (AddVendor.ContainsKey(player.userID)) return;
  2976. if ((configData.UseNPCVendors && isAdmin(player)) || !configData.UseNPCVendors)
  2977. {
  2978. CheckPlayerEntry(player);
  2979. CreateMenu(player);
  2980. return;
  2981. }
  2982.  
  2983. if (configData.UseNPCVendors)
  2984. {
  2985. CheckPlayerEntry(player);
  2986. if (!StatsMenu.Contains(player.userID))
  2987. StatsMenu.Add(player.userID);
  2988.  
  2989. CreateEmptyMenu(player);
  2990. PlayerStats(player);
  2991. PopupMessage(player, LA("noVendor", player.UserIDString));
  2992. }
  2993. }
  2994.  
  2995. [ChatCommand("wipePlayerProgress")]
  2996. void wipePlayerProgress(BasePlayer player, string command, string[] args)
  2997. {
  2998. if (!isAdmin(player)) return;
  2999. playerData.PlayerProgress = null;
  3000. Player_Data.WriteObject(Player_Data);
  3001. PopupMessage(player, LA("progressWiped", player.UserIDString));
  3002. LoadData();
  3003. }
  3004.  
  3005. [ChatCommand("questnpc")]
  3006. void cmdQuestNPC(BasePlayer player, string command, string[] args)
  3007. {
  3008. if (!isAdmin(player)) return;
  3009. var NPC = FindEntity(player);
  3010. if (NPC != null)
  3011. {
  3012. var isRegistered = isNPCRegistered(NPC.UserIDString);
  3013. if (!string.IsNullOrEmpty(isRegistered))
  3014. {
  3015. SendMSG(player, isRegistered, LA("Quest NPCs:", player.UserIDString));
  3016. return;
  3017. }
  3018.  
  3019. string name = "";
  3020. if (args.Length >= 1)
  3021. name = string.Join(" ", args);
  3022.  
  3023. if (AddVendor.ContainsKey(player.userID))
  3024. {
  3025. var pos = new NPCInfo { x = NPC.transform.position.x, z = NPC.transform.position.z, ID = NPC.UserIDString };
  3026. if (AddVendor[player.userID])
  3027. {
  3028. pos.Name = $"QuestVendor_{vendors.QuestVendors.Count + 1}";
  3029. vendors.QuestVendors.Add(NPC.UserIDString, pos);
  3030. SendMSG(player, LA("newVSucc", player.UserIDString), LA("Quest NPCs:", player.UserIDString));
  3031. if (NPC != null)
  3032. {
  3033. NPC.displayName = pos.Name;
  3034. NPC.UpdateNetworkGroup();
  3035. }
  3036.  
  3037. AddMapMarker(pos.x, pos.z, pos.Name, configData.LustyMapIntegration.Icon_Vendor + ".png");
  3038. AddVendor.Remove(player.userID);
  3039. SaveVendorData();
  3040. DestroyUI(player);
  3041. OpenMap(player);
  3042. return;
  3043. }
  3044. else
  3045. {
  3046. if (string.IsNullOrEmpty(name))
  3047. name = $"Delivery_{ vendors.DeliveryVendors.Count + 1}";
  3048.  
  3049. if (ActiveCreations.ContainsKey(player.userID))
  3050. ActiveCreations.Remove(player.userID);
  3051. pos.Name = name;
  3052.  
  3053. ActiveCreations.Add(player.userID, new QuestCreator
  3054. {
  3055. deliveryInfo = new DeliveryInfo
  3056. {
  3057. Info = pos,
  3058. Reward = new RewardItem()
  3059. },
  3060. partNum = 4,
  3061. type = QuestType.Delivery
  3062. });
  3063. DeliveryHelp(player, 2);
  3064. }
  3065. }
  3066. }
  3067. else SendMSG(player, LA("noNPC", player.UserIDString));
  3068. }
  3069.  
  3070. #endregion
  3071.  
  3072. #region Data Management
  3073.  
  3074. void SaveQuestData()
  3075. {
  3076. questData.Quest = Quest;
  3077. Quest_Data.WriteObject(questData);
  3078. }
  3079.  
  3080. void SaveVendorData()
  3081. {
  3082. Quest_Vendors.WriteObject(vendors);
  3083. }
  3084.  
  3085. void SavePlayerData()
  3086. {
  3087. playerData.PlayerProgress = PlayerProgress;
  3088. Player_Data.WriteObject(playerData);
  3089. }
  3090.  
  3091. void SaveDisplayNames()
  3092. {
  3093. itemNames.DisplayNames = DisplayNames;
  3094. Item_Names.WriteObject(itemNames);
  3095. }
  3096.  
  3097. private void SaveLoop()
  3098. {
  3099. SavePlayerData();
  3100. timer.Once(900, () => SaveLoop());
  3101. }
  3102.  
  3103. void LoadData()
  3104. {
  3105. try
  3106. {
  3107. questData = Quest_Data.ReadObject<QuestData>();
  3108. Quest = questData.Quest;
  3109. }
  3110. catch
  3111. {
  3112. Puts("Couldn't load quest data, creating new datafile");
  3113. questData = new QuestData();
  3114. }
  3115.  
  3116. try
  3117. {
  3118. vendors = Quest_Vendors.ReadObject<NPCData>();
  3119. }
  3120. catch
  3121. {
  3122. Puts("Couldn't load quest vendor data, creating new datafile");
  3123. vendors = new NPCData();
  3124. }
  3125.  
  3126. try
  3127. {
  3128. playerData = Player_Data.ReadObject<PlayerData>();
  3129. PlayerProgress = playerData.PlayerProgress;
  3130. }
  3131. catch
  3132. {
  3133. Puts("Couldn't load player data, creating new datafile");
  3134. playerData = new PlayerData();
  3135. PlayerProgress = new Dictionary<ulong, PlayerQuestData>();
  3136. }
  3137.  
  3138. try
  3139. {
  3140. itemNames = Item_Names.ReadObject<ItemNames>();
  3141. }
  3142. catch
  3143. {
  3144. Puts("Couldn't load item display name data, creating new datafile");
  3145. itemNames = new ItemNames();
  3146. }
  3147. }
  3148.  
  3149. #endregion
  3150.  
  3151. #region Data Storage
  3152.  
  3153. class QuestData
  3154. {
  3155. public Dictionary<QuestType, Dictionary<string, QuestEntry>> Quest = new Dictionary<QuestType, Dictionary<string, QuestEntry>>
  3156. {
  3157. {QuestType.Craft, new Dictionary<string, QuestEntry>()},
  3158. {QuestType.Delivery, new Dictionary<string, QuestEntry>()},
  3159. {QuestType.Gather, new Dictionary<string, QuestEntry>()},
  3160. {QuestType.Kill, new Dictionary<string, QuestEntry>()},
  3161. {QuestType.Loot, new Dictionary<string, QuestEntry>()}
  3162. };
  3163. }
  3164.  
  3165. class PlayerData
  3166. {
  3167. public Dictionary<ulong, PlayerQuestData> PlayerProgress = new Dictionary<ulong, PlayerQuestData>();
  3168. }
  3169.  
  3170. class NPCData
  3171. {
  3172. public Dictionary<string, NPCInfo> QuestVendors = new Dictionary<string, NPCInfo>();
  3173. public Dictionary<string, DeliveryInfo> DeliveryVendors = new Dictionary<string, DeliveryInfo>();
  3174. }
  3175.  
  3176. #endregion
  3177.  
  3178. #region Config
  3179.  
  3180. class UIColor
  3181. {
  3182. public string Color { get; set; }
  3183. public float Alpha { get; set; }
  3184. }
  3185.  
  3186. class Colors
  3187. {
  3188. public string TextColor_Primary { get; set; }
  3189. public string TextColor_Secondary { get; set; }
  3190. public UIColor Background_Dark { get; set; }
  3191. public UIColor Background_Light { get; set; }
  3192. public UIColor Button_Standard { get; set; }
  3193. public UIColor Button_Accept { get; set; }
  3194. public UIColor Button_Completed { get; set; }
  3195. public UIColor Button_Cancel { get; set; }
  3196. public UIColor Button_Pending { get; set; }
  3197. }
  3198.  
  3199. class Keybinds
  3200. {
  3201. public bool Autoset_KeyBind { get; set; }
  3202. public string KeyBind_Key { get; set; }
  3203. }
  3204.  
  3205. class LMIcons
  3206. {
  3207. public string Icon_Vendor { get; set; }
  3208. public string Icon_Delivery { get; set; }
  3209. }
  3210.  
  3211. class ConfigData
  3212. {
  3213. public Colors Colors { get; set; }
  3214. public Keybinds KeybindOptions { get; set; }
  3215. public LMIcons LustyMapIntegration { get; set; }
  3216. public bool DisableUI_FadeIn { get; set; }
  3217. public bool UseNPCVendors { get; set; }
  3218. public bool UseOxidePermissions { get; set; }
  3219. public bool UsePlayerIsAdmin { get; set; }
  3220. public int PlayerMaxQuests { get; set; }
  3221. }
  3222.  
  3223. private void LoadVariables()
  3224. {
  3225. LoadConfigVariables();
  3226. SaveConfig();
  3227. }
  3228.  
  3229. private void LoadConfigVariables()
  3230. {
  3231. configData = Config.ReadObject<ConfigData>();
  3232. }
  3233.  
  3234. protected override void LoadDefaultConfig()
  3235. {
  3236. Puts("Creating a new config file");
  3237. ConfigData config = new ConfigData
  3238. {
  3239. DisableUI_FadeIn = false,
  3240.  
  3241. UseNPCVendors = false,
  3242. UseOxidePermissions = false,
  3243. UsePlayerIsAdmin = true,
  3244. PlayerMaxQuests = 0,
  3245. Colors = new Colors
  3246. {
  3247. Background_Dark = new UIColor { Color = "#2a2a2a", Alpha = 0.98f },
  3248. Background_Light = new UIColor { Color = "#696969", Alpha = 0.3f },
  3249. Button_Accept = new UIColor { Color = "#00cd00", Alpha = 0.9f },
  3250. Button_Cancel = new UIColor { Color = "#8c1919", Alpha = 0.9f },
  3251. Button_Completed = new UIColor { Color = "#829db4", Alpha = 0.9f },
  3252. Button_Pending = new UIColor { Color = "#a8a8a8", Alpha = 0.9f },
  3253. Button_Standard = new UIColor { Color = "#2a2a2a", Alpha = 0.9f },
  3254. TextColor_Primary = "#ce422b",
  3255. TextColor_Secondary = "#939393"
  3256. },
  3257. LustyMapIntegration = new LMIcons
  3258. {
  3259. Icon_Delivery = "deliveryicon",
  3260. Icon_Vendor = "vendoricon"
  3261. },
  3262. KeybindOptions = new Keybinds
  3263. {
  3264. Autoset_KeyBind = false,
  3265. KeyBind_Key = "k"
  3266. }
  3267. };
  3268. SaveConfig(config);
  3269. }
  3270.  
  3271. void SaveConfig(ConfigData config)
  3272. {
  3273. Config.WriteObject(config, true);
  3274. }
  3275.  
  3276. #endregion
  3277.  
  3278. #region Messaging
  3279.  
  3280. void SendMSG(BasePlayer player, string message, string keyword = "")
  3281. {
  3282. message = $"{textSecondary}{message}</color>";
  3283. if (!string.IsNullOrEmpty(keyword))
  3284. message = $"{textPrimary}{keyword}</color> {message}";
  3285. SendReply(player, message);
  3286. }
  3287.  
  3288. Dictionary<string, string> Localization = new Dictionary<string, string>
  3289. {
  3290. {"Quests", "Quests:"},
  3291. {"delInprog", "You already have a delivery mission in progress."},
  3292. {"QC", "Quest Creator:"},
  3293. {"noAItem", "Unable to find a active item. Place the item in your hands then type "},
  3294. {"nameExists", "A quest with this name already exists"},
  3295. {"objAmount", "You need to enter a objective amount"},
  3296. {"OA", "Objective Amount:"},
  3297. {"Desc", "Description:"},
  3298. {"noRM", "You need to enter a reward multiplier"},
  3299. {"RM", "Reward Multiplier:"},
  3300. {"noRA", "You need to enter a reward amount"},
  3301. {"RA", "Reward Amount:"},
  3302. {"noCD", "You need to enter a cooldown amount"},
  3303. {"CD1", "Cooldown Timer (minutes):"},
  3304. {"qComple", "You have completed the quest"},
  3305. {"claRew", "You can claim your reward from the quest menu."},
  3306. {"qCancel", "You have cancelled this quest."},
  3307. {"rewRet", "has been returned to you"},
  3308. {"minDV","Delivery missions require atleast 2 vendors. Add some more vendors to activate delivery missions"},
  3309. {"DVSucc", "You have successfully added a new delivery vendor"},
  3310. {"saveQ", "You have successfully saved the quest:"},
  3311. {"QCCancel", "You have cancelled quest creation"},
  3312. {"KillOBJ", "Kill quests require you to kill 'X' amount of the target objective"},
  3313. {"CraftOBJ", "Crafting quests require you to craft 'X' amount of the objective item"},
  3314. {"GatherOBJ", "Gather quests require you to gather 'X' amount of the objective from resources"},
  3315. {"LootOBJ", "Loot quests require you to collect 'X' amount of the objective item from containers"},
  3316. {"DelvOBJ", "Delivery quests require you to deliver a package from one vendor to another"},
  3317. {"aQVReg", "This NPC is already a registered Quest vendor"},
  3318. {"aDVReg", "This NPC is already a registed Delivery vendor"},
  3319. {"Kill", "Kill"},
  3320. {"Gather", "Gather"},
  3321. {"Craft", "Craft"},
  3322. {"Loot", "Loot"},
  3323. {"Delivery", "Delivery"},
  3324. {"Your Quests", "Your Quests"},
  3325. {"Create Quest", "Create Quest"},
  3326. {"Edit Quest", "Edit Quest"},
  3327. {"Delete Quest", "Delete Quest"},
  3328. {"Close", "Close"},
  3329. {"Next", "Next"},
  3330. {"Back", "Back"},
  3331. {"noQ", "The are currently no"},
  3332. {"quests", "quests"},
  3333. {"Pending", "Pending"},
  3334. {"Completed", "Completed"},
  3335. {"Accept Quest", "Accept Quest"},
  3336. {"Status:", "Status:"},
  3337. {"Amount Required:", "Amount Required:"},
  3338. {"Reward:", "Reward:"},
  3339. {"yqDesc", "Check your current progress for each quest"},
  3340. {"STATS", "STATS"},
  3341. {"noQDSaved", "You don't have any quest data saved"},
  3342. {"Cancel Quest", "Cancel Quest"},
  3343. {"Claim Reward", "Claim Reward"},
  3344. {"Remove", "Remove"},
  3345. {"Cooldown", "Cooldown"},
  3346. {"Collected:", "Collected:"},
  3347. {"Reward Claimed:", "Reward Claimed:"},
  3348. {"DELIVERY", "DELIVERY"},
  3349. {"noADM", "You do not have a active delivery mission"},
  3350. {"Destination:", "Destination:"},
  3351. {"Distance:", "Distance:"},
  3352. {"Cancel", "Cancel"},
  3353. {"selCreat", "Select a quest type to begin creation"},
  3354. {"CREATOR", "CREATOR"},
  3355. {"creHelMen", "This is the quest creation help menu"},
  3356. {"creHelFol", "Follow the instructions given by typing in chat"},
  3357. {"creHelExi", "You can exit quest creation at any time by typing"},
  3358. {"creHelName", "To proceed enter the name of your new quest!"},
  3359. {"creHelObj", "Choose a quest objective from the list"},
  3360. {"creHelRA", "Enter a required amount"},
  3361. {"creHelQD", "Enter a quest description"},
  3362. {"creHelRT", "Choose a reward type"},
  3363. {"creHelNewRew", "Select a reward to remove, or add a new one"},
  3364. {"Coins", "Coins"},
  3365. {"RP", "RP"},
  3366. {"HuntXP", "XP"},
  3367. {"Item", "Item"},
  3368. {"creHelRewA", "Enter a reward amount"},
  3369. {"creHelIH", "Place the item you want to issue as a reward in your hands and type"},
  3370. {"creHelAR", "Would you like to add additional rewards?"},
  3371. {"Yes", "Yes"},
  3372. {"No", "No"},
  3373. {"creHelID", "Would you like to enable item deduction (take items from player when collected)?"},
  3374. {"creHelCD", "Enter a cooldown time (in minutes)"},
  3375. {"creHelSQ", "You have successfully created a new quest. To confirm click 'Save Quest'"},
  3376. {"Save Quest", "Save Quest"},
  3377. {"Name:", "Name:"},
  3378. {"Objective:", "Objective:"},
  3379. {"CDMin", "Cooldown (minutes):"},
  3380. {"Quest Type:", "Quest Type:"},
  3381. {"Required Amount:", "Required Amount:"},
  3382. {"Item Deduction:", "Item Deduction:"},
  3383. {"delHelMen", "Here you can add delivery missions and Quest vendors."},
  3384. {"delHelChoo", "Choose either a Delivery vendor (delivery mission) or a Quest vendor (npc based quest menu)"},
  3385. {"Quest Vendor", "Quest Vendor"},
  3386. {"Delivery Vendor", "Delivery Vendor"},
  3387. {"delHelNewNPC", "Stand infront of the NPC you wish to add and type"},
  3388. {"delHelMult", "Delivery mission rewards are based on distance X a multiplier. Keep this in mind when selecting a reward."},
  3389. {"delHelRM", "Enter a reward multiplier (per unit)."},
  3390. {"delHelRM1", "For example, if a delivery is"},
  3391. {"delHelRM2", "away, and the multiplier is"},
  3392. {"delHelRM3", "the total reward amount would be"},
  3393. {"delHelDD", "Enter a delivery description."},
  3394. {"delHelNewV", "You have successfully added a new delivery vendor. To confirm click 'Save Quest'"},
  3395. {"Accept", "Accept"},
  3396. {"Decline", "Decline"},
  3397. {"Claim", "Claim"},
  3398. {"delComplMSG", "Thanks for making the delivery"},
  3399. {"Delete NPC", "Delete NPC"},
  3400. {"REMOVER", "REMOVER"},
  3401. {"Delivery Vendors", "Delivery Vendors"},
  3402. {"Quest Vendors", "Quest Vendors"},
  3403. {"confDel", "Are you sure you want to delete:"},
  3404. {"confCan", "Are you sure you want to cancel:"},
  3405. {"confCan2", "Any progress you have made will be lost!"},
  3406. {"EDITOR", "EDITOR"},
  3407. {"chaEdi", "Select a value to change"},
  3408. {"Name", "Name"},
  3409. {"Description", "Description"},
  3410. {"Objective", "Objective"},
  3411. {"Amount", "Amount"},
  3412. {"Reward", "Reward"},
  3413. {"qAccep", "You have accepted the quest"},
  3414. {"dAccep", "You have accepted the delivery mission"},
  3415. {"canConf", "You have cancelled the delivery mission"},
  3416. {"rewRec", "You have recieved"},
  3417. {"rewError", "Unable to issue your reward. Please contact an administrator / check if your inventory is full"},
  3418. {"Quest NPCs:", "Quest NPCs:"},
  3419. {"newVSucc", "You have successfully added a new Quest vendor"},
  3420. {"noNPC", "Unable to find a valid NPC"},
  3421. {"addNewRew", "Add Reward"},
  3422. {"NoTP", "You cannot teleport while you are on a delivery mission"},
  3423. {"noVendor", "To accept new Quests you must find a Quest Vendor"},
  3424. {"progressWiped", "You wiped all player progresses!"},
  3425. };
  3426.  
  3427. #endregion
  3428.  
  3429. #region API
  3430.  
  3431. private bool API_GetNotChatOutput(BasePlayer player)
  3432. {
  3433. if (player == null) return false;
  3434. if (ActiveEditors.ContainsKey(player.userID) || ActiveCreations.ContainsKey(player.userID) || AddVendor.ContainsKey(player.userID)) return true;
  3435. else return false;
  3436. }
  3437.  
  3438. #endregion
  3439. }
  3440. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement