196 lines
7.7 KiB
C#
196 lines
7.7 KiB
C#
using BepInEx.Bootstrap;
|
|
using EpicLoot;
|
|
using HarmonyLib;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Controls;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using static MxValheimMod;
|
|
using Canvas = UnityEngine.Canvas;
|
|
using Image = UnityEngine.UI.Image;
|
|
|
|
namespace MxValheim.EventSystem
|
|
{
|
|
internal class EventSystem_Patch
|
|
{
|
|
// --- 3. HARMONY PATCHES ---
|
|
|
|
[HarmonyPatch(typeof(Player), nameof(Player.Awake))]
|
|
public static class PlayerAwakePatch
|
|
{
|
|
static void Postfix(Player __instance)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(RandEventSystem), nameof(RandEventSystem.Awake))]
|
|
public static class EventRadiusPatch
|
|
{
|
|
static void Postfix(RandEventSystem __instance)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(RandEventSystem), nameof(RandEventSystem.StartRandomEvent))]
|
|
public static class DebugRaidFrequency
|
|
{
|
|
static void Prefix(RandEventSystem __instance)
|
|
{
|
|
if (ZRoutedRpc.instance != null)
|
|
{
|
|
ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "RPC_MxKillMsg", "", "", "", "", -1);
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(RandEventSystem), nameof(RandEventSystem.FixedUpdate))]
|
|
public static class TimerFreezePatch
|
|
{
|
|
static void Prefix(RandEventSystem __instance)
|
|
{
|
|
if (MxValheimMod.Config_DebugRandomEventInterval.Value)
|
|
{
|
|
__instance.m_eventIntervalMin = 10f;
|
|
__instance.m_eventChance = 100f;
|
|
}
|
|
RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
|
|
if (activeEvent != null)
|
|
{
|
|
activeEvent.m_eventRange = 200f;
|
|
activeEvent.m_duration = 10f;
|
|
}
|
|
}
|
|
}
|
|
|
|
[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)
|
|
{
|
|
int kill = 0;
|
|
ZPackage pkg = new ZPackage();
|
|
pkg.Write(currentRaid.m_name);
|
|
pkg.Write($"{currentRaid.m_pos}");
|
|
kill = Watcher.eventKill;
|
|
ZRoutedRpc.instance.InvokeRoutedRPC(0, "RPC_ServerRemoveEvent", pkg);
|
|
|
|
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, kill));
|
|
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));
|
|
}
|
|
if (Chainloader.PluginInfos.ContainsKey("randyknapp.mods.epicloot"))
|
|
{
|
|
Reward.GiveEpicLootLowMats();
|
|
Reward.GiveEpicLootEssence();
|
|
Reward.GiveEpicLootRune();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Hud), nameof(Hud.Update))]
|
|
public static class Hud_Update_Patch
|
|
{
|
|
static void Postfix(Hud __instance)
|
|
{
|
|
if (Player.m_localPlayer == null || !Hud.instance) return;
|
|
|
|
if (RandEventSystem.instance != null)
|
|
{
|
|
RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
|
|
|
|
if (activeEvent != null)
|
|
{
|
|
eventName = Localization.instance.Localize(activeEvent.GetHudText());
|
|
}
|
|
}
|
|
|
|
if (RandEventSystem.instance != null && RandEventSystem.instance.GetActiveEvent() != null)
|
|
{
|
|
__instance.m_eventName.text = "";
|
|
}
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(Character), nameof(Character.ApplyDamage))]
|
|
public static class DeathNotifier
|
|
{
|
|
static void Postfix(Character __instance)
|
|
{
|
|
if (__instance.GetHealth() <= 0f)
|
|
{
|
|
ZNetView nview = __instance.GetComponent<ZNetView>();
|
|
|
|
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;
|
|
}
|
|
|
|
if (!isEventCreature) return;
|
|
|
|
RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
|
|
if (activeEvent != null)
|
|
{
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|