(1.6.9) Major EventSystem Update (see release)

This commit is contained in:
mikx
2026-03-01 00:36:07 -05:00
parent 8b504d02e0
commit 19a6a2f62d
4 changed files with 112 additions and 40 deletions

View File

@@ -102,17 +102,18 @@ namespace MxValheim.EventSystem
Reward.GiveItemStatic("Coins", Reward.CalculateRewardCoin(Profiles.serverLevel, currentBiome, kill)); Reward.GiveItemStatic("Coins", Reward.CalculateRewardCoin(Profiles.serverLevel, currentBiome, kill));
System.Random rand = new System.Random(); System.Random rand = new System.Random();
Reward.GiveItemStatic("Feathers", rand.Next(5, 20)); 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); 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); 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")) if (Chainloader.PluginInfos.ContainsKey("randyknapp.mods.epicloot"))
{ {
@@ -168,35 +169,48 @@ namespace MxValheim.EventSystem
isEventCreature = Traverse.Create(mai).Field<bool>("m_eventCreature").Value; isEventCreature = Traverse.Create(mai).Field<bool>("m_eventCreature").Value;
} }
if (!isEventCreature) return; if (isEventCreature)
RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
if (activeEvent != null)
{ {
ZPackage pkg = new ZPackage(); RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
pkg.Write(activeEvent.m_name); if (activeEvent != null)
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); 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 level = __instance.GetLevel();
int exp = int exp =
(level == 1) ? 2 : (level == 1) ? 4 :
(level == 2) ? 4 : (level == 2) ? 6 :
(level == 3) ? 6 : (level == 3) ? 8 :
6; 8;
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", "Event"); ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", "Event");
Heightmap.Biome currentBiome = EnvMan.instance.GetCurrentBiome(); Heightmap.Biome currentBiome = EnvMan.instance.GetCurrentBiome();
int expFinal = ((int)(exp * Experience.CalculateExpMultiplier(currentBiome))) + Profiles.serverLevel; int expFinal = ((int)(exp * Experience.CalculateExpMultiplier(currentBiome))) + Profiles.serverLevel;
Experience.AddExperience(expFinal); 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);
}
} }
} }
} }

View File

@@ -1,10 +1,12 @@
using EpicLoot; using EpicLoot;
using HarmonyLib;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Navigation;
using UnityEngine; using UnityEngine;
namespace MxValheim.EventSystem namespace MxValheim.EventSystem
@@ -52,7 +54,7 @@ namespace MxValheim.EventSystem
int qty = rand.Next(1, Profiles.serverLevel); 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)]}"; string itemName = $"Dust{rarity[rand.Next(0, rarity.Length - 1)]}";
@@ -62,7 +64,7 @@ namespace MxValheim.EventSystem
GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName);
if (prefab != null) if (prefab != null)
{ {
player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); GiveItemInWorld(itemName, player, qty);
} }
else else
{ {
@@ -76,7 +78,7 @@ namespace MxValheim.EventSystem
int qty = rand.Next(1, Profiles.serverLevel); 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)]}"; string itemName = $"Shard{rarity[rand.Next(0, rarity.Length - 1)]}";
@@ -86,7 +88,7 @@ namespace MxValheim.EventSystem
GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName);
if (prefab != null) if (prefab != null)
{ {
player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); GiveItemInWorld(itemName, player, qty);
} }
else else
{ {
@@ -100,7 +102,7 @@ namespace MxValheim.EventSystem
int qty = rand.Next(1, Profiles.serverLevel); 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)]}"; string itemName = $"Essence{rarity[rand.Next(0, rarity.Length - 1)]}";
@@ -110,7 +112,7 @@ namespace MxValheim.EventSystem
GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName);
if (prefab != null) if (prefab != null)
{ {
player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); GiveItemInWorld(itemName, player, qty);
} }
else else
{ {
@@ -124,7 +126,7 @@ namespace MxValheim.EventSystem
int qty = rand.Next(1, 2); 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)]}"; string itemName = $"Runestone{rarity[rand.Next(0, rarity.Length - 1)]}";
@@ -134,7 +136,7 @@ namespace MxValheim.EventSystem
GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName);
if (prefab != null) if (prefab != null)
{ {
player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); GiveItemInWorld(itemName, player, qty);
SendRewardMessage(player, prefab, itemName, qty); SendRewardMessage(player, prefab, itemName, qty);
} }
else else
@@ -153,7 +155,7 @@ namespace MxValheim.EventSystem
GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName);
if (prefab != null) if (prefab != null)
{ {
player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); GiveItemInWorld(itemName, player, qty);
} }
else else
{ {
@@ -169,7 +171,7 @@ namespace MxValheim.EventSystem
GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName); GameObject prefab = ObjectDB.instance.GetItemPrefab(itemName);
if (prefab != null) if (prefab != null)
{ {
player.GetInventory().AddItem(itemName, qty, 1, 0, 0, ""); GiveItemInWorld(itemName, player, qty);
if (itemName == "Coins") if (itemName == "Coins")
{ {
SendRewardMessage(player, prefab, itemName, qty); 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<ItemDrop>();
if (itemDrop != null)
{
itemDrop.m_itemData.m_stack = qty;
ZNetView nview = go.GetComponent<ZNetView>();
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) public static void SendRewardMessage(Player player, GameObject prefab, string itemName, int qty)
{ {
if (ZRoutedRpc.instance != null) 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); 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;
}
} }
} }

View File

@@ -209,6 +209,7 @@ namespace MxValheim.KillFeed
itemIcon = item?.m_itemData?.m_shared?.m_icons[0]; itemIcon = item?.m_itemData?.m_shared?.m_icons[0];
} }
biomeSprite = itemIcon; biomeSprite = itemIcon;
weaponIcon = null;
} }
lastVictimName = victim; lastVictimName = victim;

View File

@@ -33,7 +33,7 @@ public class MxValheimMod : BaseUnityPlugin
private const string ModGUID = "ovh.mxdev.mxvalheim"; private const string ModGUID = "ovh.mxdev.mxvalheim";
private const string ModName = "MxValheim"; private const string ModName = "MxValheim";
private const string ModVersion = "1.6.8"; private const string ModVersion = "1.6.9";
public static ConfigEntry<bool> Config_DebugRandomEventInterval; public static ConfigEntry<bool> Config_DebugRandomEventInterval;
public static ConfigEntry<float> Config_bowDrawSpeedBonusPerLevel; public static ConfigEntry<float> Config_bowDrawSpeedBonusPerLevel;