Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b70c79af7 | ||
|
|
ad5387d6eb | ||
|
|
11193f2472 | ||
|
|
fb96f17b55 | ||
|
|
db06cf19ad |
@@ -15,30 +15,48 @@ namespace MxValheim.EventSystem
|
||||
return (level * 100);
|
||||
}
|
||||
|
||||
public static void AddExperience(string playerid, int amount)
|
||||
public static float CalculateExpMultiplier(int level, Heightmap.Biome biome)
|
||||
{
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", playerid);
|
||||
int level = Profiles.playerLevel;
|
||||
int exp = Profiles.playerExperience;
|
||||
Dictionary<int, float> biomeBase = new Dictionary<int, float>()
|
||||
{
|
||||
{ 1, 1.0f },
|
||||
{ 2, 1.5f },
|
||||
{ 8, 2.0f },
|
||||
{ 4, 2.5f },
|
||||
{ 16, 3.0f },
|
||||
{ 256, 3.5f },
|
||||
{ 32, 4.0f },
|
||||
};
|
||||
|
||||
float rewardExpMulti = biomeBase[((int)biome)];
|
||||
|
||||
return rewardExpMulti;
|
||||
}
|
||||
|
||||
public static void AddExperience(int amount)
|
||||
{
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", "Event");
|
||||
int level = Profiles.serverLevel;
|
||||
int exp = Profiles.serverExperience;
|
||||
exp += amount;
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerSetUserExperience", playerid, exp);
|
||||
exp = Profiles.playerExperience;
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerSetExperience", exp);
|
||||
exp = Profiles.serverExperience;
|
||||
int maxexp = GetRequiredExpByLevel(level);
|
||||
UpdateProgressBar(playerid);
|
||||
UpdateProgressBar();
|
||||
if (exp >= maxexp)
|
||||
{
|
||||
exp -= maxexp;
|
||||
level++;
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerSetUserLevel", playerid, level);
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerSetUserExperience", playerid, exp);
|
||||
UpdateProgressBar(playerid);
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerSetLevel", level);
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerSetExperience", exp);
|
||||
UpdateProgressBar();
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateProgressBar(string playerid)
|
||||
public static void UpdateProgressBar()
|
||||
{
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", playerid);
|
||||
float expPercentage = ((float)Profiles.playerExperience / GetRequiredExpByLevel(Profiles.playerLevel));
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", "Event");
|
||||
float expPercentage = ((float)Profiles.serverExperience / GetRequiredExpByLevel(Profiles.serverLevel));
|
||||
|
||||
if (Clock.m_barFill != null)
|
||||
{
|
||||
|
||||
@@ -24,26 +24,19 @@ namespace MxValheim.EventSystem
|
||||
{
|
||||
static void Postfix(Player __instance)
|
||||
{
|
||||
// Only trigger for the actual human player, not NPCs/Dummies
|
||||
if (__instance == Player.m_localPlayer)
|
||||
{
|
||||
string pid = GetUserPlayerID(Player.m_localPlayer).ToString();
|
||||
ZLog.Log($"[ProfileSystem] Spawning finished. Requesting profile for {pid}");
|
||||
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(RandEventSystem), nameof(RandEventSystem.FixedUpdate))]
|
||||
[HarmonyPatch(typeof(RandEventSystem), nameof(RandEventSystem.StartRandomEvent))]
|
||||
public static class DebugRaidFrequency
|
||||
{
|
||||
static void Prefix(RandEventSystem __instance)
|
||||
{
|
||||
// Use a small timer check so we don't spam the logic every single frame
|
||||
// though for debugging, forcing these values is fine.
|
||||
__instance.m_eventIntervalMin = 10f;
|
||||
__instance.m_eventChance = 100f;
|
||||
if (ZRoutedRpc.instance != null)
|
||||
{
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "RPC_MxKillMsg", "", "", "", "", -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,52 +45,68 @@ namespace MxValheim.EventSystem
|
||||
{
|
||||
static void Prefix(RandEventSystem __instance)
|
||||
{
|
||||
//__instance.m_eventIntervalMin = 10f;
|
||||
//__instance.m_eventChance = 100f;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(RandEventSystem), nameof(RandEventSystem.RPC_SetEvent))]
|
||||
public static class RandEventEndPatch
|
||||
{
|
||||
private static readonly AccessTools.FieldRef<RandEventSystem, RandomEvent> ActiveEventField = AccessTools.FieldRefAccess<RandEventSystem, RandomEvent>("m_activeEvent");
|
||||
static void Prefix(RandEventSystem __instance, string eventName)
|
||||
{
|
||||
RandomEvent currentRaid = ActiveEventField(__instance);
|
||||
if (string.IsNullOrEmpty(eventName) && currentRaid != null)
|
||||
{
|
||||
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
||||
float distance = Vector3.Distance(playerPos, currentRaid.m_pos);
|
||||
|
||||
if (distance <= 96f)
|
||||
{
|
||||
Heightmap.Biome currentBiome = EnvMan.instance.GetCurrentBiome();
|
||||
Reward.GiveItemStatic("Coins", Reward.CalculateRewardCoin(Profiles.serverLevel, currentBiome));
|
||||
System.Random rand = new System.Random();
|
||||
Reward.GiveItemStatic("Feathers", rand.Next(5, 20));
|
||||
if (rand.Next(100) < 50)
|
||||
{
|
||||
Reward.GiveItemRandom(Reward.GetRewardPrefab(Profiles.serverLevel, "food"), 1);
|
||||
}
|
||||
if (rand.Next(100) < 25)
|
||||
{
|
||||
Reward.GiveItemRandom(Reward.GetRewardPrefab(Profiles.serverLevel, "heal"), 1);
|
||||
}
|
||||
if (rand.Next(100) < 10)
|
||||
{
|
||||
Reward.GiveItemRandom(Reward.GetRewardPrefab(Profiles.serverLevel, "metal"), rand.Next(5, 20));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(Hud), nameof(Hud.Update))]
|
||||
public static class Hud_MonitorPatch
|
||||
public static class Hud_Update_Patch
|
||||
{
|
||||
private static RandomEvent _lastKnownEvent = null;
|
||||
|
||||
static void Postfix()
|
||||
static void Postfix(Hud __instance)
|
||||
{
|
||||
// 1. Safety check: Ensure the system exists
|
||||
if (RandEventSystem.instance == null) return;
|
||||
if (Player.m_localPlayer == null || !Hud.instance) return;
|
||||
|
||||
if (RandEventSystem.instance != null)
|
||||
{
|
||||
RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
|
||||
|
||||
// 2. Logic: Detection
|
||||
if (activeEvent != null && _lastKnownEvent == null)
|
||||
if (activeEvent != null)
|
||||
{
|
||||
Debug.Log($"MxEvent: HUD Heartbeat detected Raid Start: {activeEvent.m_name}");
|
||||
_lastKnownEvent = activeEvent;
|
||||
eventName = Localization.instance.Localize(activeEvent.GetHudText());
|
||||
}
|
||||
}
|
||||
|
||||
// Force HUD Creation and Display
|
||||
//UpdateWave(true);
|
||||
}
|
||||
else if (activeEvent == null && _lastKnownEvent != null)
|
||||
// Hiding the yellow persistent text at the top center
|
||||
if (RandEventSystem.instance != null && RandEventSystem.instance.GetActiveEvent() != null)
|
||||
{
|
||||
Debug.Log("MxEvent: HUD Heartbeat detected Raid End.");
|
||||
string pid = GetUserPlayerID(Player.m_localPlayer).ToString();
|
||||
Heightmap.Biome currentBiome = EnvMan.instance.GetCurrentBiome();
|
||||
Reward.GiveItemStatic("Coins",Reward.CalculateRewardCoin(Profiles.playerLevel, currentBiome));
|
||||
System.Random rand = new System.Random();
|
||||
Reward.GiveItemStatic("Feathers", rand.Next(1,10));
|
||||
if (rand.Next(100) < 50)
|
||||
{
|
||||
Reward.GiveItemRandom(Reward.GetRewardPrefab(Profiles.playerLevel, "food"), 1);
|
||||
}
|
||||
if (rand.Next(100) < 25)
|
||||
{
|
||||
Reward.GiveItemRandom(Reward.GetRewardPrefab(Profiles.playerLevel, "heal"), 1);
|
||||
}
|
||||
if (rand.Next(100) < 10)
|
||||
{
|
||||
Reward.GiveItemRandom(Reward.GetRewardPrefab(Profiles.playerLevel, "metal"), 1);
|
||||
}
|
||||
_lastKnownEvent = null;
|
||||
// We set the text to an empty string so it doesn't render
|
||||
__instance.m_eventName.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,44 +127,57 @@ namespace MxValheim.EventSystem
|
||||
// 2. Check if a raid is active
|
||||
RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
|
||||
if (activeEvent == null) return;
|
||||
Debug.Log("MxEvent: Confirmed Active Event!");
|
||||
|
||||
Vector3 playerPos = Player.m_localPlayer.transform.position;
|
||||
string pid = GetUserPlayerID(Player.m_localPlayer).ToString();
|
||||
Debug.Log($"EventSystem:ApplyDamage User {pid}");
|
||||
float distance = Vector3.Distance(playerPos, activeEvent.m_pos);
|
||||
Debug.Log($"MxEvent: Distance: {distance}");
|
||||
|
||||
MonsterAI mai = __instance.GetComponent<MonsterAI>();
|
||||
bool isEventCreature = false;
|
||||
if (mai != null)
|
||||
{
|
||||
isEventCreature = Traverse.Create(mai).Field<bool>("m_eventCreature").Value;
|
||||
}
|
||||
Debug.Log($"EventSystem: Event Enemy {nview.GetZDO().GetBool(ZDOVars.s_eventCreature, isEventCreature)}");
|
||||
|
||||
if (distance <= 96f)
|
||||
{
|
||||
int level = __instance.GetLevel();
|
||||
int exp =
|
||||
(level == 1) ? 2:
|
||||
(level == 2) ? 3:
|
||||
(level == 3) ? 4:
|
||||
5;
|
||||
|
||||
Experience.AddExperience(pid, exp);
|
||||
|
||||
/* Send the update
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(
|
||||
ZRoutedRpc.Everybody,
|
||||
"RPC_UpdateRaidHUD",
|
||||
$"PHASE: {CurrentPhase}",
|
||||
KillsInCurrentPhase,
|
||||
GetTargetForPhase(CurrentPhase)
|
||||
);*/
|
||||
(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(Profiles.serverLevel, currentBiome));
|
||||
Experience.AddExperience(expFinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hide HUD when raid ends
|
||||
[HarmonyPatch(typeof(RandEventSystem), nameof(RandEventSystem.ResetRandomEvent))]
|
||||
[HarmonyPostfix]
|
||||
static void OnRaidEnd()
|
||||
[HarmonyPatch(typeof(Character), nameof(Character.ApplyDamage))]
|
||||
public static class DeathNotifierEvent
|
||||
{
|
||||
static void Postfix(Character __instance)
|
||||
{
|
||||
// Check if the character is dead or just died
|
||||
if (__instance.GetHealth() <= 0f)
|
||||
{
|
||||
ZNetView nview = __instance.GetComponent<ZNetView>();
|
||||
|
||||
// This check should now pass because ApplyDamage happens before the object is invalidated
|
||||
if (nview == null || !nview.IsValid() || !nview.IsOwner()) return;
|
||||
|
||||
MonsterAI mai = __instance.GetComponent<MonsterAI>();
|
||||
bool isEventCreature = false;
|
||||
if (mai != null)
|
||||
{
|
||||
isEventCreature = Traverse.Create(mai).Field<bool>("m_eventCreature").Value;
|
||||
}
|
||||
Debug.Log($"EventSystem: Event Enemy {nview.GetZDO().GetBool(ZDOVars.s_eventCreature, isEventCreature)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,13 @@ namespace MxValheim.EventSystem
|
||||
{
|
||||
public class ProfileRoot
|
||||
{
|
||||
public string playerid { get; set; }
|
||||
public string player_name { get; set; }
|
||||
public int level { get; set; }
|
||||
public int experience { get; set; }
|
||||
}
|
||||
|
||||
public static bool userExists = false;
|
||||
public static int playerLevel = 1;
|
||||
public static int playerExperience = 0;
|
||||
public static int serverLevel = 1;
|
||||
public static int serverExperience = 0;
|
||||
|
||||
|
||||
public static void ServerUserExists(string playerid)
|
||||
@@ -28,9 +26,8 @@ namespace MxValheim.EventSystem
|
||||
// Check to ensure this is actually the server running this
|
||||
ZNet zn = new ZNet();
|
||||
if (!zn.IsDedicated()) return;
|
||||
string profilePath = Path.Combine(MxValheimMod.internalDataEventSystemPath, $"{playerid}.json");
|
||||
|
||||
if (File.Exists(profilePath)) userExists = true;
|
||||
if (File.Exists(MxValheimMod.internalDataEventSystem)) userExists = true;
|
||||
}
|
||||
|
||||
public static void ServerReceiveCreateUser(long sender, string playerid, string playerName)
|
||||
@@ -39,129 +36,80 @@ namespace MxValheim.EventSystem
|
||||
ZNet zn = new ZNet();
|
||||
if (!zn.IsDedicated()) return;
|
||||
|
||||
string profilePath = Path.Combine(MxValheimMod.internalDataEventSystemPath, $"{playerid}.json");
|
||||
|
||||
ProfileRoot pr = new ProfileRoot
|
||||
{
|
||||
playerid = playerid,
|
||||
player_name = playerName,
|
||||
level = 1,
|
||||
experience = 0
|
||||
};
|
||||
|
||||
var raw = JsonConvert.SerializeObject(pr, Formatting.Indented);
|
||||
File.WriteAllText(profilePath, raw);
|
||||
File.WriteAllText(MxValheimMod.internalDataEventSystem, raw);
|
||||
}
|
||||
|
||||
public static void ServerHandleProfileRequest(long sender, string playerid)
|
||||
public static void ServerHandleProfileRequest(long sender, string required)
|
||||
{
|
||||
// Check to ensure this is actually the server running this
|
||||
ZNet zn = new ZNet();
|
||||
if (!zn.IsDedicated()) return;
|
||||
|
||||
ZNetPeer peer = ZNet.instance.GetPeer(sender);
|
||||
|
||||
string profilePath = Path.Combine(MxValheimMod.internalDataEventSystemPath, $"{playerid}.json");
|
||||
|
||||
if (File.Exists(profilePath))
|
||||
if (File.Exists(MxValheimMod.internalDataEventSystem))
|
||||
{
|
||||
string rawJson = File.ReadAllText(profilePath);
|
||||
// Send ONLY to the 'sender' who requested it
|
||||
string rawJson = File.ReadAllText(MxValheimMod.internalDataEventSystem);
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(sender, "RPC_ClientReceiveProfile", rawJson);
|
||||
}
|
||||
else
|
||||
{
|
||||
ProfileRoot pr = new ProfileRoot
|
||||
{
|
||||
playerid = playerid,
|
||||
player_name = peer.m_playerName,
|
||||
level = 1,
|
||||
experience = 0
|
||||
};
|
||||
|
||||
var raw = JsonConvert.SerializeObject(pr, Formatting.Indented);
|
||||
File.WriteAllText(profilePath, raw);
|
||||
File.WriteAllText(MxValheimMod.internalDataEventSystem, raw);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RequestCreateUser(string playerid, Player player)
|
||||
{
|
||||
string playerName = player.GetHoverName();
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerCreateUser", playerid, playerName);
|
||||
}
|
||||
|
||||
public static void ClientLoadProfile(long sender, string json)
|
||||
public static void LoadProfile(long sender, string json)
|
||||
{
|
||||
ProfileRoot loadedProfile = JsonConvert.DeserializeObject<ProfileRoot>(json);
|
||||
|
||||
playerLevel = loadedProfile.level;
|
||||
playerExperience = loadedProfile.experience;
|
||||
|
||||
//ZLog.Log($"[Client] Profile loaded! Level: {loadedProfile.level}");
|
||||
serverLevel = loadedProfile.level;
|
||||
serverExperience = loadedProfile.experience;
|
||||
}
|
||||
|
||||
public static void CreateUser(string playerid, Player player)
|
||||
{
|
||||
// We only send the raw data; we let the server handle the file I/O
|
||||
string playerName = player?.GetHoverName() ?? "Unknown";
|
||||
|
||||
// Invoke the RPC on the Server (0 is the server ID)
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerCreateUser", playerid, playerName);
|
||||
}
|
||||
|
||||
public static void ServerSetUserExperience(long sender, string playerid, int exp)
|
||||
public static void ServerSetExperience(long sender, int exp)
|
||||
{
|
||||
// Check to ensure this is actually the server running this
|
||||
ZNet zn = new ZNet();
|
||||
if (!zn.IsDedicated()) return;
|
||||
|
||||
string profilePath = Path.Combine(MxValheimMod.internalDataEventSystemPath, $"{playerid}.json");
|
||||
ProfileRoot pro = JsonConvert.DeserializeObject<ProfileRoot>(File.ReadAllText(profilePath));
|
||||
ProfileRoot pro = JsonConvert.DeserializeObject<ProfileRoot>(File.ReadAllText(MxValheimMod.internalDataEventSystem));
|
||||
ProfileRoot pr = new ProfileRoot
|
||||
{
|
||||
playerid = playerid,
|
||||
player_name = pro.player_name,
|
||||
level = pro.level,
|
||||
experience = exp
|
||||
};
|
||||
var raw = JsonConvert.SerializeObject(pr, Formatting.Indented);
|
||||
File.WriteAllText(profilePath, raw);
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", playerid);
|
||||
File.WriteAllText(MxValheimMod.internalDataEventSystem, raw);
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", "Event");
|
||||
}
|
||||
|
||||
public static void SetUserExperience(string playerid, int exp)
|
||||
{
|
||||
string profilePath = Path.Combine(MxValheimMod.internalDataEventSystemPath, $"{playerid}.json");
|
||||
ProfileRoot pro = JsonConvert.DeserializeObject<ProfileRoot>(File.ReadAllText(profilePath));
|
||||
ProfileRoot pr = new ProfileRoot
|
||||
{
|
||||
playerid = playerid,
|
||||
player_name = pro.player_name,
|
||||
level = pro.level,
|
||||
experience = exp
|
||||
};
|
||||
var raw = JsonConvert.SerializeObject(pr, Formatting.Indented);
|
||||
File.WriteAllText(profilePath, raw);
|
||||
}
|
||||
|
||||
public static void ServerSetUserLevel(long sender, string playerid, int level)
|
||||
public static void ServerSetLevel(long sender, int level)
|
||||
{
|
||||
// Check to ensure this is actually the server running this
|
||||
ZNet zn = new ZNet();
|
||||
if (!zn.IsDedicated()) return;
|
||||
|
||||
string profilePath = Path.Combine(MxValheimMod.internalDataEventSystemPath, $"{playerid}.json");
|
||||
ProfileRoot pro = JsonConvert.DeserializeObject<ProfileRoot>(File.ReadAllText(profilePath));
|
||||
ProfileRoot pro = JsonConvert.DeserializeObject<ProfileRoot>(File.ReadAllText(MxValheimMod.internalDataEventSystem));
|
||||
ProfileRoot pr = new ProfileRoot
|
||||
{
|
||||
playerid = playerid,
|
||||
player_name = pro.player_name,
|
||||
level = level,
|
||||
experience = pro.experience
|
||||
};
|
||||
var raw = JsonConvert.SerializeObject(pr, Formatting.Indented);
|
||||
File.WriteAllText(profilePath, raw);
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", playerid);
|
||||
File.WriteAllText(MxValheimMod.internalDataEventSystem, raw);
|
||||
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_RequestProfile", "Event");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ namespace MxValheim.EventSystem
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 20 },
|
||||
{ 4, 30 },
|
||||
{ 8, 40 },
|
||||
{ 8, 30 },
|
||||
{ 4, 40 },
|
||||
{ 16, 50 },
|
||||
{ 512, 60 },
|
||||
{ 64, 70 },
|
||||
{ 256, 60 },
|
||||
{ 32, 70 },
|
||||
};
|
||||
|
||||
int rewardCoin = biomeBase[((int)biome)] * level;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using HarmonyLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Threading;
|
||||
@@ -15,6 +16,38 @@ namespace MxValheim.KillFeed
|
||||
{
|
||||
public class KillFeed_Patch
|
||||
{
|
||||
public static Sprite LoadCustomSprite(string fileName)
|
||||
{
|
||||
string path = Path.Combine(BepInEx.Paths.PluginPath, "MxValheim", "Icons", fileName);
|
||||
if (!File.Exists(path)) return null;
|
||||
|
||||
try
|
||||
{
|
||||
byte[] fileData = File.ReadAllBytes(path);
|
||||
Texture2D tex = new Texture2D(2, 2);
|
||||
|
||||
// We use Reflection to find the LoadImage method inside the game's assemblies
|
||||
var imageConversion = System.Reflection.Assembly.Load("UnityEngine.ImageConversionModule")
|
||||
.GetType("UnityEngine.ImageConversion");
|
||||
|
||||
var loadImageMethod = imageConversion.GetMethod("LoadImage", new[] { typeof(Texture2D), typeof(byte[]) });
|
||||
|
||||
// Invoke the method: LoadImage(tex, fileData)
|
||||
bool success = (bool)loadImageMethod.Invoke(null, new object[] { tex, fileData });
|
||||
|
||||
if (success)
|
||||
{
|
||||
return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"[MxKillFeed] Reflection Load failed: {e.Message}");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void SendKillToAll(string attacker, string victim, string victimInternalName, string weaponPrefab, int encodedType)
|
||||
{
|
||||
if (ZRoutedRpc.instance != null)
|
||||
@@ -29,11 +62,32 @@ namespace MxValheim.KillFeed
|
||||
if (zn.IsDedicated()) return;
|
||||
if (attacker == "The World") return;
|
||||
|
||||
float distance = (encodedType / 1000) / 10.0f;
|
||||
int remainder = encodedType % 1000;
|
||||
bool isBoss = (remainder >= 100);
|
||||
int level = (remainder % 100) / 10;
|
||||
int type = remainder % 10;
|
||||
// --- DECODING START ---
|
||||
int biomeIndex = encodedType / 100000;
|
||||
int mainRemainder = encodedType % 100000;
|
||||
|
||||
float distance = (mainRemainder / 1000) / 10.0f;
|
||||
int subRemainder = mainRemainder % 1000;
|
||||
|
||||
bool isBoss = (subRemainder >= 100);
|
||||
int level = (subRemainder % 100) / 10;
|
||||
int type = subRemainder % 10;
|
||||
// --- DECODING END ---
|
||||
|
||||
// Inside OnReceiveKillMsg...
|
||||
Sprite biomeSprite = null;
|
||||
switch (biomeIndex)
|
||||
{
|
||||
case 1: biomeSprite = LoadCustomSprite("biome_meadows.png"); break;
|
||||
case 2: biomeSprite = LoadCustomSprite("biome_blackforest.png"); break;
|
||||
case 3: biomeSprite = LoadCustomSprite("biome_swamp.png"); break;
|
||||
case 4: biomeSprite = LoadCustomSprite("biome_mountain.png"); break;
|
||||
case 5: biomeSprite = LoadCustomSprite("biome_plains.png"); break;
|
||||
case 6: biomeSprite = LoadCustomSprite("biome_mistland.png"); break;
|
||||
case 7: biomeSprite = LoadCustomSprite("biome_deepnorth.png"); break;
|
||||
case 8: biomeSprite = LoadCustomSprite("biome_ashlands.png"); break;
|
||||
case 9: biomeSprite = LoadCustomSprite("biome_ocean.png"); break;
|
||||
}
|
||||
|
||||
Sprite victimIcon = GetCreatureIcon(victimInternalName);
|
||||
|
||||
@@ -48,6 +102,8 @@ namespace MxValheim.KillFeed
|
||||
// Message Format Variables
|
||||
string type1Separator = Localization.instance.Localize("$killfeed_format_type1");
|
||||
string type2Separator = Localization.instance.Localize("$killfeed_format_type2");
|
||||
string type3Separator = Localization.instance.Localize("$killfeed_format_type3");
|
||||
string eventFormat = $"<color=#00ff06>{victim}</color>";
|
||||
string finalMsg = "";
|
||||
string attackerFormat = "";
|
||||
string victimFormat = "";
|
||||
@@ -87,10 +143,16 @@ namespace MxValheim.KillFeed
|
||||
distanceFormat = $"{Localization.instance.Localize("$killfeed_format_distance_before")}<color=#9402f5>{distance:F1}m</color>{Localization.instance.Localize("$killfeed_format_distance_after")}";
|
||||
|
||||
finalMsg =
|
||||
(type == 1) ? $"{victimFormat}{type1Separator}{attackerFormat}{distanceFormat}": // Player Death
|
||||
(type == 2) ? $"{attackerFormat}{type2Separator}{victimFormat}{distanceFormat}": // Player Killed Something
|
||||
(type == 1) ? $"{victimFormat}{type1Separator}{attackerFormat}{distanceFormat}" : // Player Death
|
||||
(type == 2) ? $"{attackerFormat}{type2Separator}{victimFormat}{distanceFormat}" : // Player Killed Something
|
||||
$"{attackerFormat}{type2Separator}{victimFormat}{distanceFormat}"; // Failsafe
|
||||
|
||||
if (encodedType == -1)
|
||||
{
|
||||
attacker = Player.m_localPlayer?.GetHoverName();
|
||||
finalMsg = $"<color=#00ff06>{attacker.ToUpper()}</color><color=#ffd000>{type3Separator}</color>";
|
||||
}
|
||||
|
||||
Sprite weaponIcon = null;
|
||||
|
||||
if (ObjectDB.instance != null && !string.IsNullOrEmpty(weaponPrefab))
|
||||
@@ -124,17 +186,22 @@ namespace MxValheim.KillFeed
|
||||
{
|
||||
borderColor = new Color(0.141f, 0.141f, 0.153f);
|
||||
}
|
||||
if (encodedType == -1)
|
||||
{
|
||||
borderColor = new Color(0.0196f, 0.250f, 0.00750f);
|
||||
}
|
||||
|
||||
lock (_msgQueue)
|
||||
{
|
||||
_msgQueue.Enqueue(finalMsg);
|
||||
_biomeIconQueue.Enqueue(biomeSprite);
|
||||
_borderColQueue.Enqueue(borderColor);
|
||||
_iconQueue.Enqueue(weaponIcon);
|
||||
_victimIconQueue.Enqueue(victimIcon);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowNextMessage(string msg, Sprite weaponIcon, Sprite victimIcon, Color borderColor)
|
||||
public void ShowNextMessage(string msg, Sprite biome, Sprite weaponIcon, Sprite victimIcon, Color borderColor)
|
||||
{
|
||||
if (_hudRoot == null) CreateCustomHud();
|
||||
|
||||
@@ -154,6 +221,9 @@ namespace MxValheim.KillFeed
|
||||
_killText.text = msg;
|
||||
_border.effectColor = borderColor;
|
||||
_border.enabled = true;
|
||||
/////////////////////
|
||||
_biomeIconSlot.sprite = biome;
|
||||
_biomeIconSlot.gameObject.SetActive(biome != null);
|
||||
// Weapon icon (Left)
|
||||
_weaponIconSlot.sprite = weaponIcon;
|
||||
_weaponIconSlot.enabled = (weaponIcon != null);
|
||||
@@ -240,6 +310,9 @@ namespace MxValheim.KillFeed
|
||||
// This check should now pass because ApplyDamage happens before the object is invalidated
|
||||
if (nview == null || !nview.IsValid() || !nview.IsOwner()) return;
|
||||
|
||||
Heightmap.Biome currentBiome;
|
||||
int biomeIndex = 0;
|
||||
|
||||
float distance = 0f;
|
||||
Character attacker = hit.GetAttacker();
|
||||
if (attacker != null)
|
||||
@@ -272,14 +345,45 @@ namespace MxValheim.KillFeed
|
||||
string victimName = __instance.GetHoverName();
|
||||
|
||||
int type = 0;
|
||||
if (__instance.IsPlayer()) type = 1;
|
||||
else if (attackerName == Player.m_localPlayer?.GetHoverName()) type = 2;
|
||||
if (__instance.IsPlayer())
|
||||
{
|
||||
type = 1;
|
||||
currentBiome = Player.m_localPlayer.GetCurrentBiome();
|
||||
Debug.Log($"KillFeed: {currentBiome}");
|
||||
biomeIndex = 0;
|
||||
if (currentBiome == Heightmap.Biome.Meadows) biomeIndex = 1;
|
||||
else if (currentBiome == Heightmap.Biome.BlackForest) biomeIndex = 2;
|
||||
else if (currentBiome == Heightmap.Biome.Swamp) biomeIndex = 3;
|
||||
else if (currentBiome == Heightmap.Biome.Mountain) biomeIndex = 4;
|
||||
else if (currentBiome == Heightmap.Biome.Plains) biomeIndex = 5;
|
||||
else if (currentBiome == Heightmap.Biome.Mistlands) biomeIndex = 6;
|
||||
else if (currentBiome == Heightmap.Biome.DeepNorth) biomeIndex = 7;
|
||||
else if (currentBiome == Heightmap.Biome.AshLands) biomeIndex = 8;
|
||||
else if (currentBiome == Heightmap.Biome.Ocean) biomeIndex = 9;
|
||||
}
|
||||
|
||||
if (attackerName == Player.m_localPlayer?.GetHoverName())
|
||||
{
|
||||
type = 2;
|
||||
currentBiome = Player.m_localPlayer.GetCurrentBiome();
|
||||
Debug.Log($"KillFeed: {currentBiome}");
|
||||
biomeIndex = 0;
|
||||
if (currentBiome == Heightmap.Biome.Meadows) biomeIndex = 1;
|
||||
else if (currentBiome == Heightmap.Biome.BlackForest) biomeIndex = 2;
|
||||
else if (currentBiome == Heightmap.Biome.Swamp) biomeIndex = 3;
|
||||
else if (currentBiome == Heightmap.Biome.Mountain) biomeIndex = 4;
|
||||
else if (currentBiome == Heightmap.Biome.Plains) biomeIndex = 5;
|
||||
else if (currentBiome == Heightmap.Biome.Mistlands) biomeIndex = 6;
|
||||
else if (currentBiome == Heightmap.Biome.DeepNorth) biomeIndex = 7;
|
||||
else if (currentBiome == Heightmap.Biome.AshLands) biomeIndex = 8;
|
||||
else if (currentBiome == Heightmap.Biome.Ocean) biomeIndex = 9;
|
||||
}
|
||||
|
||||
int level = __instance.GetLevel();
|
||||
bool isBoss = __instance.IsBoss();
|
||||
|
||||
int distInt = (int)(Math.Min(distance, 999f) * 10);
|
||||
int encodedType = type + (level * 10) + (isBoss ? 100 : 0) + (distInt * 1000);
|
||||
int encodedType = type + (level * 10) + (isBoss ? 100 : 0) + (distInt * 1000) + (biomeIndex * 100000);
|
||||
|
||||
if (ZRoutedRpc.instance != null)
|
||||
{
|
||||
@@ -349,6 +453,14 @@ namespace MxValheim.KillFeed
|
||||
pRect.sizeDelta = new Vector2(400, 35); // Shorter and narrower
|
||||
pRect.localScale = Vector3.one;
|
||||
|
||||
GameObject biomeObj = new GameObject("BiomeIcon", typeof(RectTransform), typeof(Image));
|
||||
biomeObj.transform.SetParent(panel.transform, false); // Use 'false' for worldPositionStays
|
||||
_biomeIconSlot = biomeObj.GetComponent<Image>();
|
||||
_biomeIconSlot.preserveAspect = true;
|
||||
LayoutElement biomeLayout = biomeObj.AddComponent<LayoutElement>();
|
||||
biomeLayout.preferredWidth = 32;
|
||||
biomeLayout.preferredHeight = 32;
|
||||
|
||||
// 2. Compact Icon
|
||||
GameObject iconObj = new GameObject("Icon", typeof(RectTransform), typeof(Image));
|
||||
iconObj.transform.SetParent(panel.transform, false);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
|
||||
private const string ModGUID = "ovh.mxdev.mxvalheim";
|
||||
private const string ModName = "MxValheim";
|
||||
private const string ModVersion = "1.6.0";
|
||||
private const string ModVersion = "1.6.4";
|
||||
|
||||
public static ConfigEntry<bool> Config_Locked;
|
||||
public static ConfigEntry<int> Config_OreMultiplier;
|
||||
@@ -42,7 +42,7 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
public static string modPath = Path.Combine(Paths.PluginPath, "MxValheim");
|
||||
public static string internalConfigsPath = Path.Combine(modPath, "Configs");
|
||||
public static string internalDataPath = Path.Combine(modPath, "Data");
|
||||
public static string internalDataEventSystemPath = Path.Combine(internalDataPath, "EventSystem");
|
||||
public static string internalDataEventSystem = Path.Combine(internalDataPath, "EventSystem.json");
|
||||
public static string WeightConfigPath => Path.Combine(internalConfigsPath, "items_weight.json");
|
||||
public static string AutoDoorConfigPath => Path.Combine(internalConfigsPath, "auto_doors.json");
|
||||
public static DoorRoot CachedConfig;
|
||||
@@ -64,6 +64,7 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
public static Image _weaponIconSlot;
|
||||
public static Image _victimIconSlot;
|
||||
public static Image _panelImage;
|
||||
public static Image _biomeIconSlot;
|
||||
public static Outline _border;
|
||||
public static Color borderColor = Color.white;
|
||||
public static CanvasGroup _canvasGroup;
|
||||
@@ -74,6 +75,7 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
public static readonly Queue<Color> _borderColQueue = new Queue<Color>();
|
||||
public static readonly Queue<Sprite> _iconQueue = new Queue<Sprite>();
|
||||
public static readonly Queue<Sprite> _victimIconQueue = new Queue<Sprite>();
|
||||
public static readonly Queue<Sprite> _biomeIconQueue = new Queue<Sprite>();
|
||||
public static readonly Dictionary<Character, KillData> _activeTrackers = new Dictionary<Character, KillData>();
|
||||
|
||||
public static readonly Queue<ZNetView> _doorQueueNview = new Queue<ZNetView>();
|
||||
@@ -81,6 +83,8 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
public static readonly Queue<string> _doorQueueName = new Queue<string>();
|
||||
public static float _doorTimer;
|
||||
|
||||
public static string eventName;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
@@ -139,10 +143,9 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
|
||||
ZRoutedRpc.instance.Register<string, string>("RPC_ServerCreateUser", Profiles.ServerReceiveCreateUser);
|
||||
ZRoutedRpc.instance.Register<string>("RPC_RequestProfile", Profiles.ServerHandleProfileRequest);
|
||||
ZRoutedRpc.instance.Register<string>("RPC_ClientReceiveProfile", Profiles.ClientLoadProfile);
|
||||
ZRoutedRpc.instance.Register<string>("RPC_UpdateProgressBar", Profiles.ClientLoadProfile);
|
||||
ZRoutedRpc.instance.Register<string, int>("RPC_ServerSetUserExperience", Profiles.ServerSetUserExperience);
|
||||
ZRoutedRpc.instance.Register<string, int>("RPC_ServerSetUserLevel", Profiles.ServerSetUserLevel);
|
||||
ZRoutedRpc.instance.Register<string>("RPC_ClientReceiveProfile", Profiles.LoadProfile);
|
||||
ZRoutedRpc.instance.Register<int>("RPC_ServerSetExperience", Profiles.ServerSetExperience);
|
||||
ZRoutedRpc.instance.Register<int>("RPC_ServerSetLevel", Profiles.ServerSetLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +156,7 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
if (Player.m_localPlayer != null)
|
||||
{
|
||||
string pid = GetUserPlayerID(Player.m_localPlayer).ToString();
|
||||
Experience.UpdateProgressBar(pid);
|
||||
Experience.UpdateProgressBar();
|
||||
}
|
||||
|
||||
// Only run if we are actually in the game world
|
||||
@@ -177,7 +180,7 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
if (initExpBar)
|
||||
{
|
||||
string pid = GetUserPlayerID(Player.m_localPlayer).ToString();
|
||||
Experience.UpdateProgressBar(pid);
|
||||
Experience.UpdateProgressBar();
|
||||
initExpBar = false;
|
||||
}
|
||||
}
|
||||
@@ -188,7 +191,14 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
string timeString = clk.GetFormattedTime();
|
||||
int day = EnvMan.instance.GetDay();
|
||||
string pid = GetUserPlayerID(Player.m_localPlayer).ToString();
|
||||
Clock.m_textComponent.text = $"<color=#32a852>{Localization.instance.Localize("$clock_string_rank")} {Profiles.playerLevel}</color> <color=#677074>|</color> <color=#32a852>{Localization.instance.Localize("$clock_string_day")} {day}</color> <color=#677074>|</color> <color=#d1954a>{timeString}</color>";
|
||||
RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
|
||||
if ((activeEvent == null))
|
||||
{
|
||||
Clock.m_textComponent.text = $"<color=#32a852>{Localization.instance.Localize("$clock_string_rank")} {Profiles.serverLevel}</color> <color=#677074>|</color> <color=#32a852>{Localization.instance.Localize("$clock_string_day")} {day}</color> <color=#677074>|</color> <color=#d1954a>{timeString}</color>";
|
||||
} else
|
||||
{
|
||||
Clock.m_textComponent.text = $"<color=#ffd000>{eventName}</color> <color=#677074>|</color> <color=#32a852>{Localization.instance.Localize("$clock_string_rank")} {Profiles.serverLevel}</color> <color=#677074>|</color> <color=#32a852>{Localization.instance.Localize("$clock_string_day")} {day}</color> <color=#677074>|</color> <color=#d1954a>{timeString}</color>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +230,7 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
if (_msgQueue.Count > 0 && _displayTimer <= 0)
|
||||
{
|
||||
borderColor = new Color(0.141f, 0.141f, 0.153f);
|
||||
kfp.ShowNextMessage(_msgQueue.Dequeue(), _iconQueue.Dequeue(), _victimIconQueue.Dequeue(), _borderColQueue.Dequeue());
|
||||
kfp.ShowNextMessage(_msgQueue.Dequeue(), _biomeIconQueue.Dequeue(), _iconQueue.Dequeue(), _victimIconQueue.Dequeue(), _borderColQueue.Dequeue());
|
||||
}
|
||||
|
||||
if (_displayTimer > 0)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<LangVersion>12.0</LangVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -96,6 +97,14 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>E:\SteamLibrary\steamapps\common\Valheim\Valheim_Data\Managed\UnityEngine.UIModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UnityWebRequestModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>E:\SteamLibrary\steamapps\common\Valheim\Valheim_Data\Managed\UnityEngine.UnityWebRequestModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UnityWebRequestTextureModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>E:\SteamLibrary\steamapps\common\Valheim\Valheim_Data\Managed\UnityEngine.UnityWebRequestTextureModule.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EventSystem\Experience.cs" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using HarmonyLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -28,6 +29,31 @@ namespace MxValheim.Patch.HUD
|
||||
return $"{hours:00}:{minutes:00}";
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(MessageHud), nameof(MessageHud.ShowMessage))]
|
||||
public static class HideEventMessage_Patch
|
||||
{
|
||||
// We use a Prefix to check the message before it is displayed
|
||||
static bool Prefix(MessageHud.MessageType type, string text)
|
||||
{
|
||||
// Check if a raid is active
|
||||
if (RandEventSystem.instance != null)
|
||||
{
|
||||
RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
|
||||
if (activeEvent != null)
|
||||
{
|
||||
// If the message text matches the start or end message of the raid, block it
|
||||
if (text == activeEvent.GetHudText())
|
||||
{
|
||||
Debug.Log("Reached msg logic!!!");
|
||||
// Returning false tells Harmony to skip the original method (don't show text)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true; // Show all other messages (health, items, etc.) normally
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateOverlay()
|
||||
{
|
||||
m_canvasObject = new GameObject("ModdedCanvas");
|
||||
|
||||
Reference in New Issue
Block a user