using Oxide.Core.Plugins; using Oxide.Core.Libraries.Covalence; using System.Collections.Generic; using Oxide.Game.Rust.Cui; using UnityEngine; namespace Oxide.Plugins { [Info("ResourceLeveling", "Wolfsketch", "1.2.0")] [Description("Een plugin die een levelsysteem implementeert voor het verzamelen van resources.")] public class ResourceLeveling : CovalencePlugin { private const int MaxLevel = 10; private const float BaseMultiplier = 1.0f; private const float LevelMultiplierIncrease = 0.2f; private bool pluginEnabled = true; // Zet dit handmatig op true private int xpPerMining; private int xpPerWoodcutting; private int xpPerGathering; private int xpPerHuntingHit; private int xpPerHuntingKill; private int xpPerHuntingGather; private int xpPerLooting; private int xpPerBarrelHit; private Dictionary playerLevels = new Dictionary(); private Dictionary playerXP = new Dictionary(); private Dictionary> resourceXP = new Dictionary>(); private Dictionary> resourceLevels = new Dictionary>(); private Dictionary> openedContainers = new Dictionary>(); private HashSet hudEnabledPlayers = new HashSet(); protected override void LoadDefaultConfig() { Puts("[ResourceLeveling] Loading default config..."); pluginEnabled = GetConfig("Plugin Enabled", true); xpPerMining = GetConfig("XP Per Mining", 100); xpPerWoodcutting = GetConfig("XP Per Woodcutting", 100); xpPerGathering = GetConfig("XP Per Gathering", 50); xpPerHuntingHit = GetConfig("XP Per Hunting Hit", 25); xpPerHuntingKill = GetConfig("XP Per Hunting Kill", 50); xpPerHuntingGather = GetConfig("XP Per Hunting Gather", 10); xpPerLooting = GetConfig("XP Per Looting", 50); xpPerBarrelHit = GetConfig("XP Per Barrel Hit", 10); // Debugging: Controleer de geladen configuratiewaarden Puts($"[ResourceLeveling] Plugin Enabled: {pluginEnabled}"); Puts($"[ResourceLeveling] XP Per Mining: {xpPerMining}"); Puts($"[ResourceLeveling] XP Per Woodcutting: {xpPerWoodcutting}"); Puts($"[ResourceLeveling] XP Per Gathering: {xpPerGathering}"); Puts($"[ResourceLeveling] XP Per Hunting Hit: {xpPerHuntingHit}"); Puts($"[ResourceLeveling] XP Per Hunting Kill: {xpPerHuntingKill}"); Puts($"[ResourceLeveling] XP Per Hunting Gather: {xpPerHuntingGather}"); Puts($"[ResourceLeveling] XP Per Looting: {xpPerLooting}"); Puts($"[ResourceLeveling] XP Per Barrel Hit: {xpPerBarrelHit}"); SaveConfig(); // Ensure the configuration is saved Puts("[ResourceLeveling] Config loaded successfully."); } private void OnServerInitialized() { Puts("[ResourceLeveling] Server Initialized, loading configuration..."); LoadDefaultConfig(); Puts("[ResourceLeveling] Configuration loaded successfully."); } private T GetConfig(string name, T defaultValue) { Puts($"[ResourceLeveling] Getting config for {name}, default: {defaultValue}"); return Config[name] is T ? (T)Config[name] : defaultValue; } private void OnPlayerInit(BasePlayer player) { Puts($"[ResourceLeveling] Initializing player {player.UserIDString}"); if (!pluginEnabled) { Puts("[ResourceLeveling] Plugin is disabled. Exiting OnPlayerInit."); return; } InitializePlayer(player); } private void InitializePlayer(BasePlayer player) { if (!playerLevels.ContainsKey(player)) { Puts($"[ResourceLeveling] Initializing player data for {player.UserIDString}"); playerLevels[player] = 1; playerXP[player] = 0; if (!resourceXP.ContainsKey(player)) resourceXP[player] = new Dictionary(); if (!resourceLevels.ContainsKey(player)) resourceLevels[player] = new Dictionary(); if (!openedContainers.ContainsKey(player)) openedContainers[player] = new HashSet(); InitializeResource(player, "Mining"); InitializeResource(player, "Woodcutting"); InitializeResource(player, "Gathering"); InitializeResource(player, "Hunting"); InitializeResource(player, "Looting"); Puts($"[ResourceLeveling] Player {player.UserIDString} initialized."); } else { Puts($"[ResourceLeveling] Player {player.UserIDString} is already initialized."); } } private void InitializeResource(BasePlayer player, string resourceType) { Puts($"[ResourceLeveling] Initializing resource {resourceType} for player {player.UserIDString}"); if (!resourceXP[player].ContainsKey(resourceType)) resourceXP[player][resourceType] = 0; if (!resourceLevels[player].ContainsKey(resourceType)) resourceLevels[player][resourceType] = 1; } private void OnLootEntity(BasePlayer player, BaseEntity entity) { Puts($"[ResourceLeveling] OnLootEntity called for player {player.UserIDString}"); if (!pluginEnabled) { Puts("[ResourceLeveling] Plugin is disabled. Exiting OnLootEntity."); return; } InitializePlayer(player); if (entity is StorageContainer) { uint containerId = (uint)entity.net.ID.Value; Puts($"[ResourceLeveling] Player {player.UserIDString} looting container {containerId}"); if (!openedContainers[player].Contains(containerId)) { AddResourceXP(player, "Looting", xpPerLooting); openedContainers[player].Add(containerId); Puts($"[ResourceLeveling] Player {player.UserIDString} gains {xpPerLooting} Looting XP."); } else { Puts($"[ResourceLeveling] Player {player.UserIDString} attempted to loot an already opened container. No XP granted."); } } } private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { if (!pluginEnabled) { Puts("[ResourceLeveling] Plugin is disabled. Exiting OnEntityTakeDamage."); return; } if (info?.Initiator is BasePlayer player) { Puts($"[ResourceLeveling] Damage initiated by player {player.UserIDString}"); InitializePlayer(player); if (entity is BaseNpc) { AddResourceXP(player, "Hunting", xpPerHuntingHit); Puts($"[ResourceLeveling] Player {player.UserIDString} hit a NPC and gains {xpPerHuntingHit} Hunting XP."); } else if (entity.ShortPrefabName.Contains("barrel")) { AddResourceXP(player, "Looting", xpPerBarrelHit); Puts($"[ResourceLeveling] Player {player.UserIDString} hit a barrel and gains {xpPerBarrelHit} Looting XP."); } } } private void OnDispenserGather(ResourceDispenser dispenser, BasePlayer player, Item item) { if (!pluginEnabled) return; Puts($"[ResourceLeveling] OnDispenserGather called for player {player.UserIDString}"); InitializePlayer(player); if (dispenser.gatherType == ResourceDispenser.GatherType.Flesh) { int level = resourceLevels[player]["Hunting"]; int resourceMultiplier = level; item.amount = item.amount * resourceMultiplier; Puts($"[ResourceLeveling] Player {player.UserIDString} gathers {item.amount} {item.info.shortname} with a multiplier of {resourceMultiplier}x."); AddResourceXP(player, "Hunting", xpPerHuntingGather); } else { string resourceType = ""; if (item.info.shortname == "wood") { resourceType = "Woodcutting"; int xpToAdd = xpPerWoodcutting; // Zorg dat deze waarde correct wordt doorgegeven Puts($"[ResourceLeveling] Adding {xpToAdd} XP to Woodcutting for player {player.UserIDString}"); // Debugging output Puts($"[ResourceLeveling] XP per Woodcutting (xpPerWoodcutting): {xpPerWoodcutting}"); // Debugging output AddResourceXP(player, resourceType, xpToAdd); } else if (item.info.shortname == "stones" || item.info.shortname == "metal.ore" || item.info.shortname == "sulfur.ore") { resourceType = "Mining"; int xpToAdd = xpPerMining; Puts($"[ResourceLeveling] Adding {xpToAdd} XP to Mining for player {player.UserIDString}"); // Debugging output Puts($"[ResourceLeveling] XP per Mining (xpPerMining): {xpPerMining}"); // Debugging output AddResourceXP(player, resourceType, xpToAdd); } else { return; } int level = resourceLevels[player][resourceType]; float multiplier = BaseMultiplier + ((level - 1) * LevelMultiplierIncrease); Puts($"[ResourceLeveling] Player {player.UserIDString} gathers {resourceType} at level {level} with a multiplier of {multiplier}."); item.amount = (int)(item.amount * multiplier); Puts($"[ResourceLeveling] Player {player.UserIDString} gathered {item.amount} items after applying the multiplier."); } } private void AddResourceXP(BasePlayer player, string resourceType, int xp) { Puts($"[ResourceLeveling] Attempting to add {xp} XP for {resourceType} to player {player.UserIDString}"); if (!pluginEnabled) { Puts("[ResourceLeveling] Plugin is disabled. Exiting AddResourceXP."); return; } if (!resourceXP.ContainsKey(player)) { Puts("[ResourceLeveling] resourceXP not initialized for player. Exiting AddResourceXP."); return; } // Debugging: Controleer de huidige XP en level voordat we XP toevoegen int currentXP = resourceXP[player][resourceType]; int currentLevel = resourceLevels[player][resourceType]; Puts($"[ResourceLeveling] Current {resourceType} XP for player {player.UserIDString}: {currentXP}"); Puts($"[ResourceLeveling] Current {resourceType} level for player {player.UserIDString}: {currentLevel}"); resourceXP[player][resourceType] += xp; // Debugging: Controleer de nieuwe XP en level na het toevoegen int newXP = resourceXP[player][resourceType]; Puts($"[ResourceLeveling] New {resourceType} XP for player {player.UserIDString}: {newXP}"); player.ChatMessage($"You gain: +{xp} {resourceType} XP"); if (currentLevel < MaxLevel && newXP >= XPNeededForNextLevel(currentLevel)) { LevelUpResource(player, resourceType); } UpdateResourceHUD(player, resourceType, currentLevel, newXP, XPNeededForNextLevel(currentLevel)); } private void LevelUpResource(BasePlayer player, string resourceType) { resourceLevels[player][resourceType]++; resourceXP[player][resourceType] = 0; player.ChatMessage($"Gefeliciteerd! Je bent nu level {resourceLevels[player][resourceType]} in {resourceType}."); Puts($"[ResourceLeveling] Player {player.UserIDString} leveled up {resourceType} to level {resourceLevels[player][resourceType]}."); } private int XPNeededForNextLevel(int level) { int requiredXP = level * 1000; Puts($"[ResourceLeveling] XP needed for next level: {requiredXP}"); return requiredXP; } private void UpdateResourceHUD(BasePlayer player, string resourceType, int level, int xp, int nextLevelXP) { Puts($"[ResourceLeveling] Updating HUD for player {player.UserIDString} and resource {resourceType}"); string hudName = $"ResourceHUD_{resourceType}"; CuiHelper.DestroyUi(player, hudName); var elements = new CuiElementContainer(); string anchorMin; string anchorMax; switch (resourceType) { case "Mining": anchorMin = "0.80 0.96"; anchorMax = "0.95 0.99"; break; case "Woodcutting": anchorMin = "0.80 0.92"; anchorMax = "0.95 0.95"; break; case "Gathering": anchorMin = "0.80 0.88"; anchorMax = "0.95 0.91"; break; case "Hunting": anchorMin = "0.80 0.84"; anchorMax = "0.95 0.87"; break; case "Looting": anchorMin = "0.80 0.80"; anchorMax = "0.95 0.83"; break; default: anchorMin = "0.80 0.84"; anchorMax = "0.95 0.87"; break; } string panelName = elements.Add(new CuiPanel { Image = { Color = "0.761 0.761 0.761 0.4" }, RectTransform = { AnchorMin = anchorMin, AnchorMax = anchorMax }, CursorEnabled = false }, "Overlay", hudName); elements.Add(new CuiLabel { Text = { Text = $"{resourceType} XP (level {level}): {xp} / {nextLevelXP}", FontSize = 13, Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = "0.0 0.0", AnchorMax = "1.0 1.0" } }, panelName); CuiHelper.AddUi(player, elements); } [Command("showhud")] private void ShowHudCommand(IPlayer player, string command, string[] args) { Puts($"[ResourceLeveling] showhud command called by player {player.Name}"); if (!pluginEnabled) { player.Reply("ResourceLeveling is currently disabled."); return; } var basePlayer = player.Object as BasePlayer; if (basePlayer == null) { player.Reply("Er is iets misgegaan. Kan de speler niet vinden."); return; } InitializePlayer(basePlayer); if (!resourceLevels.ContainsKey(basePlayer) || !resourceXP.ContainsKey(basePlayer)) { player.Reply("Er is een probleem opgetreden bij het initialiseren van je gegevens. Probeer opnieuw in te loggen."); return; } if (hudEnabledPlayers.Contains(basePlayer)) { CuiHelper.DestroyUi(basePlayer, "ResourceHUD_Mining"); CuiHelper.DestroyUi(basePlayer, "ResourceHUD_Woodcutting"); CuiHelper.DestroyUi(basePlayer, "ResourceHUD_Gathering"); CuiHelper.DestroyUi(basePlayer, "ResourceHUD_Hunting"); CuiHelper.DestroyUi(basePlayer, "ResourceHUD_Looting"); hudEnabledPlayers.Remove(basePlayer); player.Reply("Resource HUD is uitgeschakeld."); } else { hudEnabledPlayers.Add(basePlayer); if (resourceLevels[basePlayer].ContainsKey("Mining") && resourceXP[basePlayer].ContainsKey("Mining")) { UpdateResourceHUD(basePlayer, "Mining", resourceLevels[basePlayer]["Mining"], resourceXP[basePlayer]["Mining"], XPNeededForNextLevel(resourceLevels[basePlayer]["Mining"])); } if (resourceLevels[basePlayer].ContainsKey("Woodcutting") && resourceXP[basePlayer].ContainsKey("Woodcutting")) { UpdateResourceHUD(basePlayer, "Woodcutting", resourceLevels[basePlayer]["Woodcutting"], resourceXP[basePlayer]["Woodcutting"], XPNeededForNextLevel(resourceLevels[basePlayer]["Woodcutting"])); } if (resourceLevels[basePlayer].ContainsKey("Gathering") && resourceXP[basePlayer].ContainsKey("Gathering")) { UpdateResourceHUD(basePlayer, "Gathering", resourceLevels[basePlayer]["Gathering"], resourceXP[basePlayer]["Gathering"], XPNeededForNextLevel(resourceLevels[basePlayer]["Gathering"])); } if (resourceLevels[basePlayer].ContainsKey("Hunting") && resourceXP[basePlayer].ContainsKey("Hunting")) { UpdateResourceHUD(basePlayer, "Hunting", resourceLevels[basePlayer]["Hunting"], resourceXP[basePlayer]["Hunting"], XPNeededForNextLevel(resourceLevels[basePlayer]["Hunting"])); } if (resourceLevels[basePlayer].ContainsKey("Looting") && resourceXP[basePlayer].ContainsKey("Looting")) { UpdateResourceHUD(basePlayer, "Looting", resourceLevels[basePlayer]["Looting"], resourceXP[basePlayer]["Looting"], XPNeededForNextLevel(resourceLevels[basePlayer]["Looting"])); } player.Reply("Resource HUD is ingeschakeld."); } } [Command("ResourceLeveling")] private void ResourceLevelingCommand(IPlayer player, string command, string[] args) { Puts($"[ResourceLeveling] ResourceLeveling command called by player {player.Name}"); if (args.Length == 0) { player.Reply("Please specify 'enable' or 'disable'."); return; } if (args[0].ToLower() == "disable") { pluginEnabled = false; Config["Plugin Enabled"] = pluginEnabled; SaveConfig(); player.Reply("ResourceLeveling is now disabled."); Puts($"[ResourceLeveling] Plugin is disabled by {player.Name}"); } else if (args[0].ToLower() == "enable") { pluginEnabled = true; Config["Plugin Enabled"] = pluginEnabled; SaveConfig(); player.Reply("ResourceLeveling is now enabled."); Puts($"[ResourceLeveling] Plugin is enabled by {player.Name}"); } else { player.Reply("Invalid argument. Please specify 'enable' or 'disable'."); } } private void OnPlayerDisconnected(BasePlayer player) { Puts($"[ResourceLeveling] Player {player.UserIDString} disconnected."); if (hudEnabledPlayers.Contains(player)) { CuiHelper.DestroyUi(player, "ResourceHUD_Mining"); CuiHelper.DestroyUi(player, "ResourceHUD_Woodcutting"); CuiHelper.DestroyUi(player, "ResourceHUD_Gathering"); CuiHelper.DestroyUi(player, "ResourceHUD_Hunting"); CuiHelper.DestroyUi(player, "ResourceHUD_Looting"); hudEnabledPlayers.Remove(player); Puts($"[ResourceLeveling] HUD destroyed for player {player.UserIDString}"); } } } }