Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions LethalProgression/Extensions/ExtensionsMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using UnityEngine;

namespace LethalProgression.Extensions
{
internal static class ExtensionsMethods
{
public static T GetOrAddComponent<T>(this GameObject go) where T : Component
{
T component = go.GetComponent<T>();
if (component == null)
{
component = go.AddComponent<T>();
}
return component;
}
public static T GetOrAddComponentInChildren<T>(this GameObject go) where T : Component
{
T component = go.GetComponentInChildren<T>();
if (component == null)
{
component = go.AddComponent<T>();
}
return component;
}
public static T GetOrAddComponentInParent<T>(this GameObject go) where T : Component
{
T component = go.GetComponentInParent<T>();
if (component == null)
{
component = go.AddComponent<T>();
}
return component;
}
}
}
90 changes: 90 additions & 0 deletions LethalProgression/GUIUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using HarmonyLib;
using LethalProgression.Config;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;

namespace LethalProgression.GUI
{
[HarmonyPatch]
internal class GUIUpdate
{
public static bool isMenuOpen = false;
public static SkillsGUI guiInstance;

[HarmonyPostfix]
[HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.Update))]
private static void SkillMenuUpdate(QuickMenuManager __instance)
{
if (guiInstance == null || !guiInstance.mainPanel)
{
return;
}

// If the menu is open, activate mainPanel.
if (!isMenuOpen)
{
guiInstance.mainPanel.SetActive(false);
return;
}

if (bool.Parse(SkillConfig.hostConfig["Unspec in Ship Only"]) && !bool.Parse(SkillConfig.hostConfig["Disable Unspec"]))
{
// Check if you are in the ship right now
guiInstance.SetUnspec(GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom);
}

if (bool.Parse(SkillConfig.hostConfig["Unspec in Orbit Only"]))
{
// Check if you are in orbit right now

guiInstance.SetUnspec(StartOfRound.Instance.inShipPhase);
}

if (bool.Parse(SkillConfig.hostConfig["Disable Unspec"]))
{
guiInstance.SetUnspec(false);
}
GameObject pointsPanel = guiInstance.mainPanel.transform.GetChild(2).gameObject;
GameObject toolTip = pointsPanel.transform.GetChild(2).gameObject;
// If the mouse is on the points panel, show the tooltip.
toolTip.SetActive(IsHovering());

guiInstance.mainPanel.SetActive(true);
GameObject mainButtons = GameObject.Find("Systems/UI/Canvas/QuickMenu/MainButtons");
mainButtons.SetActive(false);

GameObject playerList = GameObject.Find("Systems/UI/Canvas/QuickMenu/PlayerList");
playerList.SetActive(false);

RealTimeUpdateInfo();
}
public static bool IsHovering()
{
Vector2 mousePos = Mouse.current.position.ReadValue();
// If the mouse is currently on the PointsPanel
GameObject pointsPanel = guiInstance.mainPanel.transform.GetChild(2).gameObject;
float xLeast = pointsPanel.transform.position.x - pointsPanel.GetComponent<RectTransform>().rect.width;
float xMost = pointsPanel.transform.position.x + pointsPanel.GetComponent<RectTransform>().rect.width;
float yLeast = pointsPanel.transform.position.y - pointsPanel.GetComponent<RectTransform>().rect.height;
float yMost = pointsPanel.transform.position.y + pointsPanel.GetComponent<RectTransform>().rect.height;

return mousePos.x >= xLeast && mousePos.x <= xMost && mousePos.y >= yLeast && mousePos.y <= yMost;
}

[HarmonyPostfix]
[HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.CloseQuickMenu))]
private static void SkillMenuClose(QuickMenuManager __instance)
{
isMenuOpen = false;
}
private static void RealTimeUpdateInfo()
{
GameObject tempObj = guiInstance.mainPanel.transform.GetChild(2).gameObject;
tempObj = tempObj.transform.GetChild(1).gameObject;

TextMeshProUGUI points = tempObj.GetComponent<TextMeshProUGUI>();
points.text = LP_NetworkManager.xpInstance.GetSkillPoints().ToString();
}
}
}
61 changes: 24 additions & 37 deletions LethalProgression/XP.cs → LethalProgression/LC_XP.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
using HarmonyLib;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using Unity.Netcode;
using Unity.Networking;
using UnityEngine;
using System.IO;
using UnityEngine.SceneManagement;
using System.Collections;
using System.Linq;
using GameNetcodeStuff;
using LethalProgression.Config;
using LethalProgression.Skills;
using LethalProgression.GUI;
using LethalProgression.Patches;
using LethalProgression.Saving;
using LethalProgression.Skills;
using Newtonsoft.Json;
using Steamworks;
using System.Linq;
using Unity.Netcode;
using UnityEngine;

namespace LethalProgression
{
Expand All @@ -41,7 +33,7 @@ public void Start()
LethalPlugin.Log.LogInfo("XP Network Behavior Made!");
PlayerConnect_ServerRpc();
}
public void LoadSharedData()
public void LoadSharedSaveData()
{
SaveSharedData sharedData = SaveManager.LoadShared();

Expand Down Expand Up @@ -77,18 +69,6 @@ public void LoadLocalData(string data)
skillCheck += skill.Value;
}
LethalPlugin.Log.LogInfo(GetXPRequirement().ToString());

// Sanity check: If skillCheck goes over amount of skill points, reset all skills.
//if (skillCheck > skillPoints)
//{
// LethalPlugin.Log.LogInfo("Skill check is greater than skill points, resetting skills.");
// foreach (KeyValuePair<UpgradeType, Skill> skill in skillList.skills)
// {
// skill.Value.Reset();
// }
//}

// if the skill check is less than the current level plus five, add the difference
if ((skillCheck + skillPoints) < xpLevel.Value + 5)
{
LethalPlugin.Log.LogInfo($"Skill check is less than current level, adding {((xpLevel.Value + 5) - (skillCheck + skillPoints))} skill points.");
Expand Down Expand Up @@ -220,7 +200,7 @@ public void Givepoint_ClientRPC()
/////////////////////////////////////////////////
/// Team Loot Upgrade Sync
/////////////////////////////////////////////////
public void TeamLootValueUpdate(float update, int newValue)
public void TeamLootValueUpdate(float update)
{
TeamLootValueUpdate_ServerRpc(update);
}
Expand All @@ -229,8 +209,13 @@ public void TeamLootValueUpdate(float update, int newValue)
public void TeamLootValueUpdate_ServerRpc(float updatedValue)
{
float mult = LP_NetworkManager.xpInstance.skillList.skills[UpgradeType.Value].GetMultiplier();
float newvalue = updatedValue * mult;
teamLootValue.Value += newvalue;
float value = updatedValue * mult;

teamLootValue.Value += value;
if (value == 0)
{
teamLootValue.Value = value;
}
LethalPlugin.Log.LogInfo($"Changed team loot value by {updatedValue * mult} turning into {teamLootValue.Value}.");
}

Expand Down Expand Up @@ -307,10 +292,7 @@ public void SetHandSlot(ulong playerID, int newSlots)
[ServerRpc(RequireOwnership = false)]
public void GetEveryoneHandSlots_ServerRpc()
{
if (LethalPlugin.ReservedSlots)
return;

if (!LP_NetworkManager.xpInstance.skillList.IsSkillValid(UpgradeType.HandSlot))
if (LethalPlugin.ReservedSlots || !LP_NetworkManager.xpInstance.skillList.IsSkillValid(UpgradeType.HandSlot))
{
return;
}
Expand Down Expand Up @@ -361,7 +343,7 @@ public void SendEveryoneConfigs_ClientRpc(string serializedConfig)

if (GameNetworkManager.Instance.isHostingGame)
{
LoadSharedData();
LoadSharedSaveData();
}

guiObj = new SkillsGUI();
Expand All @@ -376,16 +358,21 @@ public void SendEveryoneConfigs_ClientRpc(string serializedConfig)
}

// Saving
[ServerRpc (RequireOwnership = false)]
public void SaveData_ServerRpc(ulong steamID, string saveData)
[ServerRpc(RequireOwnership = false)]
public void SaveData_ServerRpc(ulong steamID, string saveData, SaveType type = SaveType.PlayerPrefs)
{
if (type == SaveType.Json)
{
SaveMigrator.MigrateSaves();
return;
}
SaveManager.Save(steamID, saveData);
SaveManager.SaveShared(xpPoints.Value, xpLevel.Value, profit.Value);
}

// Loading
[ServerRpc(RequireOwnership = false)]
public void RequestSavedData_ServerRpc(ulong steamID)
public void RequestSavedData_ServerRpc(ulong? steamID)
{
string saveData = SaveManager.Load(steamID);
SendSavedData_ClientRpc(saveData);
Expand Down
24 changes: 12 additions & 12 deletions LethalProgression/LP_NetworkManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Text;
using Unity.Netcode;
using UnityEngine;
using Object = UnityEngine.Object;
Expand All @@ -11,12 +8,16 @@ namespace LethalProgression
[HarmonyPatch]
internal class LP_NetworkManager
{
public static LC_XP xpInstance;

[HarmonyPostfix]
[HarmonyPatch(typeof(GameNetworkManager), "Start")]
[HarmonyPatch(typeof(GameNetworkManager), nameof(GameNetworkManager.Start))]
public static void Init()
{
if (xpNetworkObject != null)
{
return;
}

xpNetworkObject = (GameObject)LethalPlugin.skillBundle.LoadAsset("LP_XPHandler");
xpNetworkObject.AddComponent<LC_XP>();
Expand All @@ -26,18 +27,17 @@ public static void Init()
public static GameObject xpNetworkObject;

[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "Awake")]
[HarmonyPatch(typeof(StartOfRound), nameof(StartOfRound.Awake))]
static void SpawnNetworkHandler()
{
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
{
var networkHandlerHost = Object.Instantiate(xpNetworkObject, Vector3.zero, Quaternion.identity);
networkHandlerHost.GetComponent<NetworkObject>().Spawn();
xpInstance = networkHandlerHost.GetComponent<LC_XP>();
LethalPlugin.Log.LogInfo("XPHandler Initialized.");
return;
}
var networkHandlerHost = Object.Instantiate(xpNetworkObject, Vector3.zero, Quaternion.identity);
networkHandlerHost.GetComponent<NetworkObject>().Spawn();
xpInstance = networkHandlerHost.GetComponent<LC_XP>();
LethalPlugin.Log.LogInfo("XPHandler Initialized.");
}

public static LC_XP xpInstance;
}
}
Loading