From aa3cdb4d13ac0211325e1341d742a84b13c6ea72 Mon Sep 17 00:00:00 2001 From: mbedda Date: Thu, 4 Apr 2024 14:21:49 +0200 Subject: [PATCH 1/2] Calculate travel quests distance on timer --- x_UnpolishedPlugins/ZNQuests.cs | 169 ++++++++++++++++++++++---------- 1 file changed, 119 insertions(+), 50 deletions(-) diff --git a/x_UnpolishedPlugins/ZNQuests.cs b/x_UnpolishedPlugins/ZNQuests.cs index 82949ca..d21e4dd 100644 --- a/x_UnpolishedPlugins/ZNQuests.cs +++ b/x_UnpolishedPlugins/ZNQuests.cs @@ -34,7 +34,7 @@ namespace Oxide.Plugins { - [Info("ZNQuests", "DocValerian", "1.2.5")] + [Info("ZNQuests", "DocValerian", "1.2.6")] class ZNQuests : RustPlugin { static ZNQuests Plugin; @@ -132,7 +132,11 @@ void Unload() { OnPlayerDisconnected(player); killUI(player); + } + foreach (var monitor in playersTravelMonitor) + { + monitor.Value.KillTimer(); } _gm.SaveData(); } @@ -191,16 +195,16 @@ private static void SaveData(T data, string filename = null) => // catch quests difficulty = "easy", new ZQuest{ type = "catch", item = "fish", difficulty = "easy", amountGoal = 5, desc = "Catch a number of (any) Fish" }, // travel quests difficulty = "easy", - new ZQuest{ type = "travel", item = "saddletest", difficulty = "easy", amountGoal = 500, desc = "Ride a Horse for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "miniheliseat", difficulty = "easy", amountGoal = 1000, desc = "Pilot a Minicopter for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "transporthelicopilot", difficulty = "easy", amountGoal = 1000, desc = "Co-Pilot a Scrapheli for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "smallboatdriver", difficulty = "easy", amountGoal = 1000, desc = "Captain a Boat for total distance (mount to unmount point)" }, + new ZQuest{ type = "travel", item = "saddletest", difficulty = "easy", amountGoal = 500, desc = "Ride a Horse for total distance" }, + new ZQuest{ type = "travel", item = "miniheliseat", difficulty = "easy", amountGoal = 1000, desc = "Pilot a Minicopter for total distance" }, + new ZQuest{ type = "travel", item = "transporthelicopilot", difficulty = "easy", amountGoal = 1000, desc = "Co-Pilot a Scrapheli for total distance" }, + new ZQuest{ type = "travel", item = "smallboatdriver", difficulty = "easy", amountGoal = 1000, desc = "Captain a Boat for total distance" }, - new ZQuest{ type = "travel", item = "snowmobiledriverseat", difficulty = "easy", amountGoal = 1000, desc = "Drive a SnowMobile for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "submarinesolodriverstanding", difficulty = "easy", amountGoal = 1000, desc = "Captain a Solo Submarine for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "submarineduodriverseat", difficulty = "easy", amountGoal = 1000, desc = "Captain a Duo Submarine for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "modularcardriverseat", difficulty = "easy", amountGoal = 1000, desc = "Drive a Modular Car for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "itemCarPassenger", difficulty = "easy", amountGoal = 1000, desc = "Be a Modular Car passenger for total distance (mount to unmount point)" }, + new ZQuest{ type = "travel", item = "snowmobiledriverseat", difficulty = "easy", amountGoal = 1000, desc = "Drive a SnowMobile for total distance" }, + new ZQuest{ type = "travel", item = "submarinesolodriverstanding", difficulty = "easy", amountGoal = 1000, desc = "Captain a Solo Submarine for total distance" }, + new ZQuest{ type = "travel", item = "submarineduodriverseat", difficulty = "easy", amountGoal = 1000, desc = "Captain a Duo Submarine for total distance" }, + new ZQuest{ type = "travel", item = "modularcardriverseat", difficulty = "easy", amountGoal = 1000, desc = "Drive a Modular Car for total distance" }, + new ZQuest{ type = "travel", item = "itemCarPassenger", difficulty = "easy", amountGoal = 1000, desc = "Be a Modular Car passenger for total distance" }, //modularcardriverseat submarineduodriverseat ...(15:55:02) | [ZNQuests] DEBUG: dismount submarineduopassengerseat ... }; @@ -234,21 +238,21 @@ private static void SaveData(T data, string filename = null) => // catch quests difficulty = "normal", new ZQuest{ type = "catch", item = "fish", difficulty = "normal", amountGoal = 15, desc = "Catch a number of (any) Fish" }, // travel quests difficulty = "normal", - new ZQuest{ type = "travel", item = "saddletest", difficulty = "normal", amountGoal = 1500, desc = "Ride a Horse for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "miniheliseat", difficulty = "normal", amountGoal = 5000, desc = "Pilot a Minicopter for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "minihelipassenger", difficulty = "normal", amountGoal = 4000, desc = "Be passenger in a Minicopter for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "transporthelipilot", difficulty = "normal", amountGoal = 5000, desc = "Pilot a Scrapheli for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "transporthelicopilot", difficulty = "normal", amountGoal = 4000, desc = "Co-Pilot a Scrapheli for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "smallboatdriver", difficulty = "normal", amountGoal = 2000, desc = "Captain a Boat for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "smallboatpassenger", difficulty = "normal", amountGoal = 2000, desc = "Be a Boat/RHIB passenger for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "standingdriver", difficulty = "normal", amountGoal = 2000, desc = "Captain a RHIB for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "snowmobiledriverseat", difficulty = "normal", amountGoal = 3500, desc = "Drive a SnowMobile for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "snowmobilepassengerseat tomaha", difficulty = "normal", amountGoal = 3500, desc = "Be a SnowMobile passenger for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "submarinesolodriverstanding", difficulty = "normal", amountGoal = 2500, desc = "Captain a Solo Submarine for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "submarineduodriverseat", difficulty = "normal", amountGoal = 2500, desc = "Captain a Duo Submarine for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "submarineduopassengerseat", difficulty = "normal", amountGoal = 2500, desc = "Be a Duo Submarine passenger for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "modularcardriverseat", difficulty = "normal", amountGoal = 3500, desc = "Drive a Modular Car for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "itemCarPassenger", difficulty = "normal", amountGoal = 3500, desc = "Be a Modular Car passenger for total distance (mount to unmount point)" }, + new ZQuest{ type = "travel", item = "saddletest", difficulty = "normal", amountGoal = 1500, desc = "Ride a Horse for total distance" }, + new ZQuest{ type = "travel", item = "miniheliseat", difficulty = "normal", amountGoal = 5000, desc = "Pilot a Minicopter for total distance" }, + new ZQuest{ type = "travel", item = "minihelipassenger", difficulty = "normal", amountGoal = 4000, desc = "Be passenger in a Minicopter for total distance" }, + new ZQuest{ type = "travel", item = "transporthelipilot", difficulty = "normal", amountGoal = 5000, desc = "Pilot a Scrapheli for total distance" }, + new ZQuest{ type = "travel", item = "transporthelicopilot", difficulty = "normal", amountGoal = 4000, desc = "Co-Pilot a Scrapheli for total distance" }, + new ZQuest{ type = "travel", item = "smallboatdriver", difficulty = "normal", amountGoal = 2000, desc = "Captain a Boat for total distance" }, + new ZQuest{ type = "travel", item = "smallboatpassenger", difficulty = "normal", amountGoal = 2000, desc = "Be a Boat/RHIB passenger for total distance" }, + new ZQuest{ type = "travel", item = "standingdriver", difficulty = "normal", amountGoal = 2000, desc = "Captain a RHIB for total distance" }, + new ZQuest{ type = "travel", item = "snowmobiledriverseat", difficulty = "normal", amountGoal = 3500, desc = "Drive a SnowMobile for total distance" }, + new ZQuest{ type = "travel", item = "snowmobilepassengerseat tomaha", difficulty = "normal", amountGoal = 3500, desc = "Be a SnowMobile passenger for total distance" }, + new ZQuest{ type = "travel", item = "submarinesolodriverstanding", difficulty = "normal", amountGoal = 2500, desc = "Captain a Solo Submarine for total distance" }, + new ZQuest{ type = "travel", item = "submarineduodriverseat", difficulty = "normal", amountGoal = 2500, desc = "Captain a Duo Submarine for total distance" }, + new ZQuest{ type = "travel", item = "submarineduopassengerseat", difficulty = "normal", amountGoal = 2500, desc = "Be a Duo Submarine passenger for total distance" }, + new ZQuest{ type = "travel", item = "modularcardriverseat", difficulty = "normal", amountGoal = 3500, desc = "Drive a Modular Car for total distance" }, + new ZQuest{ type = "travel", item = "itemCarPassenger", difficulty = "normal", amountGoal = 3500, desc = "Be a Modular Car passenger for total distance" }, }; private static List AvailableHardQuests = new List @@ -283,26 +287,26 @@ private static void SaveData(T data, string filename = null) => // catch quests new ZQuest{ type = "catch", item = "fish", difficulty = "hard", amountGoal = 30, desc = "Catch a number of (any) Fish" }, // travel quests - new ZQuest{ type = "travel", item = "saddletest", difficulty = "hard", amountGoal = 5000, desc = "Ride a Horse for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "miniheliseat", difficulty = "hard", amountGoal = 10000, desc = "Pilot a Minicopter for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "minihelipassenger", difficulty = "hard", amountGoal = 10000, desc = "Be passenger in a Minicopter for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "transporthelipilot", difficulty = "hard", amountGoal = 10000, desc = "Pilot a Scrapheli for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "transporthelicopilot", difficulty = "hard", amountGoal = 10000, desc = "Co-Pilot a Scrapheli for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "smallboatdriver", difficulty = "hard", amountGoal = 10000, desc = "Captain a Boat for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "smallboatpassenger", difficulty = "hard", amountGoal = 10000, desc = "Be a Boat/RHIB passenger for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "standingdriver", difficulty = "hard", amountGoal = 10000, desc = "Captain a RHIB for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "snowmobiledriverseat", difficulty = "hard", amountGoal = 10000, desc = "Drive a SnowMobile for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "snowmobilepassengerseat tomaha", difficulty = "hard", amountGoal = 10000, desc = "Be a SnowMobile passenger for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "submarinesolodriverstanding", difficulty = "hard", amountGoal = 10000, desc = "Captain a Solo Submarine for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "submarineduodriverseat", difficulty = "hard", amountGoal = 10000, desc = "Captain a Duo Submarine for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "submarineduopassengerseat", difficulty = "hard", amountGoal = 10000, desc = "Be a Duo Submarine passenger for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "modularcardriverseat", difficulty = "hard", amountGoal = 10000, desc = "Drive a Modular Car for total distance (mount to unmount point)" }, - new ZQuest{ type = "travel", item = "itemCarPassenger", difficulty = "hard", amountGoal = 10000, desc = "Be a Modular Car passenger for total distance (mount to unmount point)" }, + new ZQuest{ type = "travel", item = "saddletest", difficulty = "hard", amountGoal = 5000, desc = "Ride a Horse for total distance" }, + new ZQuest{ type = "travel", item = "miniheliseat", difficulty = "hard", amountGoal = 10000, desc = "Pilot a Minicopter for total distance" }, + new ZQuest{ type = "travel", item = "minihelipassenger", difficulty = "hard", amountGoal = 10000, desc = "Be passenger in a Minicopter for total distance" }, + new ZQuest{ type = "travel", item = "transporthelipilot", difficulty = "hard", amountGoal = 10000, desc = "Pilot a Scrapheli for total distance" }, + new ZQuest{ type = "travel", item = "transporthelicopilot", difficulty = "hard", amountGoal = 10000, desc = "Co-Pilot a Scrapheli for total distance" }, + new ZQuest{ type = "travel", item = "smallboatdriver", difficulty = "hard", amountGoal = 10000, desc = "Captain a Boat for total distance" }, + new ZQuest{ type = "travel", item = "smallboatpassenger", difficulty = "hard", amountGoal = 10000, desc = "Be a Boat/RHIB passenger for total distance" }, + new ZQuest{ type = "travel", item = "standingdriver", difficulty = "hard", amountGoal = 10000, desc = "Captain a RHIB for total distance" }, + new ZQuest{ type = "travel", item = "snowmobiledriverseat", difficulty = "hard", amountGoal = 10000, desc = "Drive a SnowMobile for total distance" }, + new ZQuest{ type = "travel", item = "snowmobilepassengerseat tomaha", difficulty = "hard", amountGoal = 10000, desc = "Be a SnowMobile passenger for total distance" }, + new ZQuest{ type = "travel", item = "submarinesolodriverstanding", difficulty = "hard", amountGoal = 10000, desc = "Captain a Solo Submarine for total distance" }, + new ZQuest{ type = "travel", item = "submarineduodriverseat", difficulty = "hard", amountGoal = 10000, desc = "Captain a Duo Submarine for total distance" }, + new ZQuest{ type = "travel", item = "submarineduopassengerseat", difficulty = "hard", amountGoal = 10000, desc = "Be a Duo Submarine passenger for total distance" }, + new ZQuest{ type = "travel", item = "modularcardriverseat", difficulty = "hard", amountGoal = 10000, desc = "Drive a Modular Car for total distance" }, + new ZQuest{ type = "travel", item = "itemCarPassenger", difficulty = "hard", amountGoal = 10000, desc = "Be a Modular Car passenger for total distance" }, }; private List> rewardList = new List>(); - public Dictionary playerMountPoints = new Dictionary(); + // public Dictionary playerMountPoints = new Dictionary(); // multi type items to kill public Dictionary itemList = new Dictionary() { @@ -861,23 +865,62 @@ object OnCollectiblePickup(CollectibleEntity collectible, BasePlayer player) void OnEntityMounted(BaseMountable entity, BasePlayer player) { - if (playerMountPoints.ContainsKey(player.userID)) + if (!playerGotQuest(player, "travel", entity.ShortPrefabName)) return; + + if (playersTravelMonitor.ContainsKey(player.userID)) { - playerMountPoints[player.userID] = entity.transform.position; + playersTravelMonitor[player.userID].lastLocation = entity.transform.position; } else { - playerMountPoints.Add(player.userID, entity.transform.position); + playersTravelMonitor.Add(player.userID, new TravelMonitor(){ lastLocation = entity.transform.position }); } + + playersTravelMonitor[player.userID].KillTimer(); + playersTravelMonitor[player.userID].timer = Plugin.timer.Repeat( + 5f, + 0, + () => + { + if (player.GetMountedVehicle() == null) + { + if (playersTravelMonitor.ContainsKey(player.userID)) + { + playersTravelMonitor[player.userID].KillTimer(); + playersTravelMonitor.Remove(player.userID); + } + return; + } + + int distance = (int)Math.Floor(Vector3Ex.Distance2D(entity.transform.position, playersTravelMonitor[player.userID].lastLocation)); + playersTravelMonitor[player.userID].lastLocation = entity.transform.position; + + if(distance > 500) + { + PrintWarning($"Suspicious {entity.ShortPrefabName} travel distance of {distance} - {player.displayName}"); + return; + } + + questProgress(player, "travel", entity.ShortPrefabName, distance); + + if (!playerGotQuest(player, "travel", entity.ShortPrefabName)) playersTravelMonitor[player.userID].KillTimer(); + } + ); } void OnEntityDismounted(BaseMountable entity, BasePlayer player) { - if (playerMountPoints.ContainsKey(player.userID)) + if (playersTravelMonitor.ContainsKey(player.userID)) { - int distance = (int)Math.Floor(Vector3Ex.Distance2D(entity.transform.position, playerMountPoints[player.userID])); - playerMountPoints.Remove(player.userID); - questProgress(player, "travel", entity.ShortPrefabName, distance); - //Puts("DEBUG: dismount " + entity.ShortPrefabName + " ..."); + int distance = (int)Math.Floor(Vector3Ex.Distance2D(entity.transform.position, playersTravelMonitor[player.userID].lastLocation)); + + if(distance > 500) + PrintWarning($"Suspicious {entity.ShortPrefabName} travel distance of {distance} - {player.displayName}"); + else + questProgress(player, "travel", entity.ShortPrefabName, distance); + + playersTravelMonitor[player.userID].KillTimer(); + playersTravelMonitor.Remove(player.userID); + // Puts("DEBUG: dismount " + entity.ShortPrefabName + " ..."); } } #endregion @@ -1126,6 +1169,15 @@ private void questProgress(BasePlayer player, string type, string itemName, int } + private bool playerGotQuest(BasePlayer player, string type, string itemName) + { + if (!_qm.ContainsKey(player.userID)) return false; + + if (itemList.ContainsKey(itemName)) itemName = itemList[itemName]; + + return _qm[player.userID].HasActiveQuest(type, itemName); + } + private void showInfoText(BasePlayer player) { string infoText = "=== ZN Trade (v" + Plugin.Version + " ALPHA) ==="; @@ -2016,7 +2068,6 @@ private void GUIInfoElement(BasePlayer player, string elUiId) +"\n- You can Claim rewards in Blood OR XP" +"\n- Claiming rewards has a price (trade RP for XP or bleach for RP)" +"\n- With each claimed quest the reward & price rises!" - +"\n- 'travel' quests only count distance between start and end (don't drive circles!)" +"\n\nGLOBAL BONUS:\n- After "+Cfg.globalQuestClaimThreshold+" claims you can get a Bonus" +"\n- The more players globally contribute, the more XP bonus everyone gets" +"\n- The more quests you claim the higher your Global Bonus share" @@ -2388,5 +2439,23 @@ private string numberCandy(int number) { return Convert.ToDecimal(number).ToString("N", nfi); } + + #region TravelMonitor + + public Dictionary playersTravelMonitor = new Dictionary(); + + public class TravelMonitor + { + public Timer timer; + public Vector3 lastLocation { get; set; } + + public void KillTimer() + { + if (timer != null) + timer.Destroy(); + } + } + + #endregion } } \ No newline at end of file From 157b9ed021c29d5d00d75a0183714c4c1d219a68 Mon Sep 17 00:00:00 2001 From: mbedda Date: Thu, 4 Apr 2024 14:28:50 +0200 Subject: [PATCH 2/2] fix: change RHIB captain quest from "standingdriver" to "rhibdriver" --- x_UnpolishedPlugins/ZNQuests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x_UnpolishedPlugins/ZNQuests.cs b/x_UnpolishedPlugins/ZNQuests.cs index d21e4dd..e15e597 100644 --- a/x_UnpolishedPlugins/ZNQuests.cs +++ b/x_UnpolishedPlugins/ZNQuests.cs @@ -245,7 +245,7 @@ private static void SaveData(T data, string filename = null) => new ZQuest{ type = "travel", item = "transporthelicopilot", difficulty = "normal", amountGoal = 4000, desc = "Co-Pilot a Scrapheli for total distance" }, new ZQuest{ type = "travel", item = "smallboatdriver", difficulty = "normal", amountGoal = 2000, desc = "Captain a Boat for total distance" }, new ZQuest{ type = "travel", item = "smallboatpassenger", difficulty = "normal", amountGoal = 2000, desc = "Be a Boat/RHIB passenger for total distance" }, - new ZQuest{ type = "travel", item = "standingdriver", difficulty = "normal", amountGoal = 2000, desc = "Captain a RHIB for total distance" }, + new ZQuest{ type = "travel", item = "rhibdriver", difficulty = "normal", amountGoal = 2000, desc = "Captain a RHIB for total distance" }, new ZQuest{ type = "travel", item = "snowmobiledriverseat", difficulty = "normal", amountGoal = 3500, desc = "Drive a SnowMobile for total distance" }, new ZQuest{ type = "travel", item = "snowmobilepassengerseat tomaha", difficulty = "normal", amountGoal = 3500, desc = "Be a SnowMobile passenger for total distance" }, new ZQuest{ type = "travel", item = "submarinesolodriverstanding", difficulty = "normal", amountGoal = 2500, desc = "Captain a Solo Submarine for total distance" },