diff --git a/MxValheim/EventSystem/Patch.cs b/MxValheim/EventSystem/Patch.cs index bed96b8..c252bee 100644 --- a/MxValheim/EventSystem/Patch.cs +++ b/MxValheim/EventSystem/Patch.cs @@ -102,17 +102,18 @@ namespace MxValheim.EventSystem Reward.GiveItemStatic("Coins", Reward.CalculateRewardCoin(Profiles.serverLevel, currentBiome, kill)); System.Random rand = new System.Random(); Reward.GiveItemStatic("Feathers", rand.Next(5, 20)); - if (rand.Next(100) < 50) + float dayPercent = ((float)EnvMan.instance.GetDay() / 10); + if (rand.Next(100) < (50+dayPercent)) { Reward.GiveItemRandom(Reward.GetRewardPrefab(Profiles.serverLevel, "food"), 1); } - if (rand.Next(100) < 25) + if (rand.Next(100) < (25+dayPercent)) { Reward.GiveItemRandom(Reward.GetRewardPrefab(Profiles.serverLevel, "heal"), 1); } - if (rand.Next(100) < 10) + if (rand.Next(100) < (10+dayPercent)) { - Reward.GiveItemRandom(Reward.GetRewardPrefab(Profiles.serverLevel, "metal"), rand.Next(5, 20)); + Reward.GiveItemRandom(Reward.GetRewardPrefab(Profiles.serverLevel, "metal"), rand.Next(5, (20+Profiles.serverLevel))); } if (Chainloader.PluginInfos.ContainsKey("randyknapp.mods.epicloot")) { @@ -168,35 +169,48 @@ namespace MxValheim.EventSystem isEventCreature = Traverse.Create(mai).Field("m_eventCreature").Value; } - if (!isEventCreature) return; - - RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent(); - if (activeEvent != null) + if (isEventCreature) { - ZPackage pkg = new ZPackage(); - pkg.Write(activeEvent.m_name); - pkg.Write($"{activeEvent.m_pos}"); - ActiveEventData entry = MxValheimMod.ActiveEvents.Find(e => e.Position == activeEvent.m_pos.ToString()); - if (entry == null) - { - ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerRegisterEvent", pkg); - } else + RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent(); + if (activeEvent != null) { - ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerSetEventKill", pkg); + ZPackage pkg = new ZPackage(); + pkg.Write(activeEvent.m_name); + pkg.Write($"{activeEvent.m_pos}"); + ActiveEventData entry = MxValheimMod.ActiveEvents.Find(e => e.Position == activeEvent.m_pos.ToString()); + if (entry == null) + { + ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerRegisterEvent", pkg); + } + else + { + ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerSetEventKill", pkg); + } + ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerGetEventKill", pkg); } - ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerGetEventKill", pkg); - } - int level = __instance.GetLevel(); - int exp = - (level == 1) ? 2 : - (level == 2) ? 4 : - (level == 3) ? 6 : - 6; - ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", "Event"); - Heightmap.Biome currentBiome = EnvMan.instance.GetCurrentBiome(); - int expFinal = ((int)(exp * Experience.CalculateExpMultiplier(currentBiome))) + Profiles.serverLevel; - Experience.AddExperience(expFinal); + int level = __instance.GetLevel(); + int exp = + (level == 1) ? 4 : + (level == 2) ? 6 : + (level == 3) ? 8 : + 8; + ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", "Event"); + Heightmap.Biome currentBiome = EnvMan.instance.GetCurrentBiome(); + int expFinal = ((int)(exp * Experience.CalculateExpMultiplier(currentBiome))) + Profiles.serverLevel; + Experience.AddExperience(expFinal); + } else + { + int level = __instance.GetLevel(); + int exp = + (level == 1) ? 2 : + (level == 2) ? 4 : + (level == 3) ? 6 : + 6; + Heightmap.Biome currentBiome = EnvMan.instance.GetCurrentBiome(); + int expFinal = ((int)(exp * Experience.CalculateExpMultiplier(currentBiome))) + Profiles.serverLevel; + Experience.AddExperience(expFinal); + } } } } diff --git a/MxValheim/EventSystem/Reward.cs b/MxValheim/EventSystem/Reward.cs index 0cd9999..dc62b0a 100644 --- a/MxValheim/EventSystem/Reward.cs +++ b/MxValheim/EventSystem/Reward.cs @@ -1,10 +1,12 @@ using EpicLoot; +using HarmonyLib; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using System.Windows.Navigation; using UnityEngine; namespace MxValheim.EventSystem @@ -52,7 +54,7 @@ namespace MxValheim.EventSystem int qty = rand.Next(1, Profiles.serverLevel); - string[] rarity = { "Rare", "Epic", "Legendary", "Mythic" }; + string[] rarity = GetRarityList(Watcher.eventKill); string itemName = $"Dust{rarity[rand.Next(0, rarity.Length - 1)]}"; @@ -62,7 +64,7 @@ namespace MxValheim.EventSystem GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); if (prefab != null) { - player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); + GiveItemInWorld(itemName, player, qty); } else { @@ -76,7 +78,7 @@ namespace MxValheim.EventSystem int qty = rand.Next(1, Profiles.serverLevel); - string[] rarity = { "Rare", "Epic", "Legendary", "Mythic" }; + string[] rarity = GetRarityList(Watcher.eventKill); string itemName = $"Shard{rarity[rand.Next(0, rarity.Length - 1)]}"; @@ -86,7 +88,7 @@ namespace MxValheim.EventSystem GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); if (prefab != null) { - player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); + GiveItemInWorld(itemName, player, qty); } else { @@ -100,7 +102,7 @@ namespace MxValheim.EventSystem int qty = rand.Next(1, Profiles.serverLevel); - string[] rarity = { "Rare", "Epic", "Legendary", "Mythic" }; + string[] rarity = GetRarityList(Watcher.eventKill); string itemName = $"Essence{rarity[rand.Next(0, rarity.Length - 1)]}"; @@ -110,7 +112,7 @@ namespace MxValheim.EventSystem GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); if (prefab != null) { - player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); + GiveItemInWorld(itemName, player, qty); } else { @@ -124,7 +126,7 @@ namespace MxValheim.EventSystem int qty = rand.Next(1, 2); - string[] rarity = { "Rare", "Epic", "Legendary", "Mythic" }; + string[] rarity = GetRarityList(Watcher.eventKill); string itemName = $"Runestone{rarity[rand.Next(0, rarity.Length - 1)]}"; @@ -134,7 +136,7 @@ namespace MxValheim.EventSystem GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); if (prefab != null) { - player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); + GiveItemInWorld(itemName, player, qty); SendRewardMessage(player, prefab, itemName, qty); } else @@ -153,7 +155,7 @@ namespace MxValheim.EventSystem GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); if (prefab != null) { - player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); + GiveItemInWorld(itemName, player, qty); } else { @@ -169,7 +171,7 @@ namespace MxValheim.EventSystem GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); if (prefab != null) { - player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); + GiveItemInWorld(itemName, player, qty); if (itemName == "Coins") { SendRewardMessage(player, prefab, itemName, qty); @@ -181,6 +183,37 @@ namespace MxValheim.EventSystem } } + public static void GiveItemInWorld(string itemName, Player player, int qty) + { + GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); + Vector3 spawnPos = player.transform.position + player.transform.forward + Vector3.up; + + GameObject go = UnityEngine.Object.Instantiate(prefab, spawnPos, Quaternion.identity); + + ItemDrop itemDrop = go.GetComponent(); + if (itemDrop != null) + { + itemDrop.m_itemData.m_stack = qty; + ZNetView nview = go.GetComponent(); + if (nview != null && nview.IsValid()) + { + nview.GetZDO().Set("stack", qty); + } + + GameObject vfxPrefab = ZNetScene.instance.GetPrefab("vfx_item_spawn"); + if (vfxPrefab != null) + { + UnityEngine.Object.Instantiate(vfxPrefab, spawnPos, Quaternion.identity); + } + + GameObject sfxPrefab = ZNetScene.instance.GetPrefab("sfx_item_spawn"); + if (sfxPrefab != null) + { + UnityEngine.Object.Instantiate(sfxPrefab, spawnPos, Quaternion.identity); + } + } + } + public static void SendRewardMessage(Player player, GameObject prefab, string itemName, int qty) { if (ZRoutedRpc.instance != null) @@ -190,5 +223,29 @@ namespace MxValheim.EventSystem ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "RPC_MxKillMsg", Player.m_localPlayer.GetHoverName(), qty.ToString(), Localization.instance.Localize(nameToken), itemName, -2); } } + + public static string[] GetRarityList(int victim) + { + string[] rarity = { }; + switch (victim) + { + case <= 1: + rarity = ["Magic"]; + break; + case > 1 and < 5: + rarity = ["Rare"]; + break; + case >= 5 and <= 10: + rarity = ["Rare", "Epic"]; + break; + case >= 11 and <= 20: + rarity = ["Rare", "Epic", "Legendary"]; + break; + case >= 21: + rarity = ["Rare", "Epic", "Legendary", "Mythic"]; + break; + } + return rarity; + } } } diff --git a/MxValheim/KillFeed/Patch.cs b/MxValheim/KillFeed/Patch.cs index b616985..a945cdc 100644 --- a/MxValheim/KillFeed/Patch.cs +++ b/MxValheim/KillFeed/Patch.cs @@ -209,6 +209,7 @@ namespace MxValheim.KillFeed itemIcon = item?.m_itemData?.m_shared?.m_icons[0]; } biomeSprite = itemIcon; + weaponIcon = null; } lastVictimName = victim; diff --git a/MxValheim/MxValheim.cs b/MxValheim/MxValheim.cs index 904c983..75271ab 100644 --- a/MxValheim/MxValheim.cs +++ b/MxValheim/MxValheim.cs @@ -33,7 +33,7 @@ public class MxValheimMod : BaseUnityPlugin private const string ModGUID = "ovh.mxdev.mxvalheim"; private const string ModName = "MxValheim"; - private const string ModVersion = "1.6.8"; + private const string ModVersion = "1.6.9"; public static ConfigEntry Config_DebugRandomEventInterval; public static ConfigEntry Config_bowDrawSpeedBonusPerLevel;