Skip to content

Commit

Permalink
Merge pull request #2 from FroggerHH/dev
Browse files Browse the repository at this point in the history
Pull from dev
  • Loading branch information
FroggerHH authored May 14, 2024
2 parents 617af18 + 75f6252 commit fbecd4e
Show file tree
Hide file tree
Showing 51 changed files with 1,338 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/documentation_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def update_readme():
f.write(entry + '\n')


directory = os.getcwd() + "/mod/Web/Controllers"
directory = os.getcwd() + "/mod/core/Web/Controllers"
readme_path = "DOCUMENTATION.md"
controllers = []
readme_entries = []
Expand Down
8 changes: 7 additions & 1 deletion mod/ValheimWebLink.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ValheimWebLink", "ValheimWebLink.csproj", "{02CE308D-1155-4B96-AD14-80AA60C2D79D}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ValheimWebLink", "core/ValheimWebLink.csproj", "{02CE308D-1155-4B96-AD14-80AA60C2D79D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VWL_WorldObjectsData", "WorldObjectsData\VWL_WorldObjectsData.csproj", "{1ED47FF7-4B37-46DF-9595-8F7C133A76DD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -11,5 +13,9 @@ Global
{02CE308D-1155-4B96-AD14-80AA60C2D79D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02CE308D-1155-4B96-AD14-80AA60C2D79D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02CE308D-1155-4B96-AD14-80AA60C2D79D}.Release|Any CPU.Build.0 = Release|Any CPU
{1ED47FF7-4B37-46DF-9595-8F7C133A76DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1ED47FF7-4B37-46DF-9595-8F7C133A76DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1ED47FF7-4B37-46DF-9595-8F7C133A76DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1ED47FF7-4B37-46DF-9595-8F7C133A76DD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
21 changes: 0 additions & 21 deletions mod/Web/Controllers/FindObjects/RecordPrefabNames.cs

This file was deleted.

36 changes: 0 additions & 36 deletions mod/Web/Controllers/PlayerData/GetPlayerData.cs

This file was deleted.

83 changes: 0 additions & 83 deletions mod/Web/Controllers/PlayerData/PlayerData.cs

This file was deleted.

41 changes: 0 additions & 41 deletions mod/Web/Controllers/PlayerData/SetPlayerData.cs

This file was deleted.

16 changes: 0 additions & 16 deletions mod/Web/QueryParamInfo.cs

This file was deleted.

25 changes: 25 additions & 0 deletions mod/WorldObjectsData/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ReSharper disable RedundantUsingDirective.Global
// Global using directives

global using System;
global using System.Collections.Generic;
global using System.Collections;
global using System.IO;
global using System.Linq;
global using System.Net;
global using System.Text;
global using System.Threading;
global using System.Threading.Tasks;
global using fastJSON;
global using JetBrains.Annotations;
global using JFUtils;
global using TMPro;
global using UnityEngine;
global using static System.Net.HttpStatusCode;
global using Object = UnityEngine.Object;
global using static JFUtils.ModBase;
global using static Player;
global using static VWL_WorldObjectsData.WorldObjectsData;
global using static UnityEngine.Mathf;
global using static UnityEngine.Object;
global using Random = UnityEngine.Random;
27 changes: 27 additions & 0 deletions mod/WorldObjectsData/HandlerSendPlayerInventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace VWL_WorldObjectsData;

public static class HandlerSendPlayerInventory
{
public static void SendInventoryToServer(long _, string name)
{
Debug($"Server asking me for inventory of {name}");
var pl = m_localPlayer;
if (!pl || !pl.GetPlayerName().Equals(name)) return;
var result = new InventoryData();
foreach (var itemData in pl.GetInventory().m_inventory)
{
result.items.Add(new()
{
prefabName = itemData.m_dropPrefab.name,
durability = itemData.m_durability,
quality = itemData.m_quality,
stack = itemData.m_stack,
crafterName = itemData.m_crafterName,
variant = itemData.m_variant,
gridPos = itemData.m_gridPos,
});
}

ZRoutedRpc.instance.InvokeRoutedRPC("VWL_GotInventory_Server", name, JSON.ToJSON(result));
}
}
75 changes: 75 additions & 0 deletions mod/WorldObjectsData/HandlerSetPlayerData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
namespace VWL_WorldObjectsData;

internal static class HandlerSetPlayerData
{
private static Transform? spawnHolder;

private static void ChangeInventory(Player pl, InventoryData inventoryData)
{
if (spawnHolder == null)
{
spawnHolder = new GameObject("VWL_SpawnHolder").transform;
spawnHolder.gameObject.SetActive(false);
}

var plInv = pl.GetInventory().m_inventory;
foreach (var item in inventoryData.items)
{
var itemData = plInv.Find(x => x.m_gridPos.ToVector2() == item.gridPos);
if (itemData == null)
{
var itemDrop = ObjectDB.instance.GetItem(item.prefabName);
if (!itemDrop) continue;
itemDrop = Instantiate(itemDrop, parent: spawnHolder);
if (item.gridPos.HasValue) itemDrop.m_itemData.m_gridPos = item.gridPos.Value;
if (item.stack.HasValue) itemDrop.m_itemData.m_stack = item.stack.Value;
if (item.durability.HasValue) itemDrop.m_itemData.m_durability = item.durability.Value;
if (item.quality.HasValue) itemDrop.m_itemData.m_quality = item.quality.Value;
if (item.variant.HasValue) itemDrop.m_itemData.m_variant = item.variant.Value;
if (item.crafterName != null) itemDrop.m_itemData.m_crafterName = item.crafterName;
if (item.stack.HasValue) plInv.Add(itemDrop.m_itemData);
Destroy(itemDrop.gameObject);
continue;
}

if (item.stack.HasValue) itemData.m_stack = item.stack.Value;
if (item.durability.HasValue) itemData.m_durability = item.durability.Value;
if (item.quality.HasValue) itemData.m_quality = item.quality.Value;
if (item.variant.HasValue) itemData.m_variant = item.variant.Value;
if (item.crafterName != null) itemData.m_crafterName = item.crafterName;
}
}

public static void SetPlayerData(long _, string name, string dataJson)
{
PlayerData data;
try
{
data = JSON.ToObject<PlayerData>(dataJson);
}
catch (Exception e)
{
DebugError($"HandlerSetPlayerData: Failed to parse PlayerData from JSON: {e}");
return;
}

var pl = m_localPlayer;
if (!pl || name != pl.GetPlayerName()) return;
Debug($"Got HandlerSetPlayerData for self\n{data.GetObjectString()}");

if (data.inDebugFly.HasValue) pl.m_debugFly = data.inDebugFly.Value;
if (data.maxHealth.HasValue) pl.SetMaxHealth(data.maxHealth.Value);
if (data.health.HasValue) pl.SetHealth(data.health.Value);
if (data.eitr.HasValue) pl.m_eitr = data.eitr.Value;
if (data.eitr.HasValue) pl.m_maxEitr = Max(pl.m_eitr, data.eitr.Value);
if (data.stamina.HasValue) pl.m_stamina = data.stamina.Value;
if (data.stamina.HasValue) pl.m_maxStamina = Max(pl.m_stamina, data.stamina.Value);
if (data.pvp.HasValue) pl.SetPVP(data.pvp.Value);
if (data.inBed.HasValue) pl.SetSleeping(data.inBed.Value);
if (data.noise.HasValue) pl.m_noiseRange = data.noise.Value;
if (data.noise.HasValue) pl.m_nview.GetZDO().Set(ZDOVars.s_noise, data.noise.Value);
if (data.position.HasValue) pl.TeleportTo(data.position.Value, Quaternion.identity, false);
if (data.publicPosition.HasValue) ZNet.instance.SetPublicReferencePosition(data.publicPosition.Value);
if (data.inventory.HasValue) ChangeInventory(pl, data.inventory.Value);
}
}
File renamed without changes.
21 changes: 21 additions & 0 deletions mod/WorldObjectsData/InventoryData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace VWL_WorldObjectsData;

#nullable enable

[Serializable]
public struct InventoryData()
{
public List<ItemInfo> items = [];
}

[Serializable]
public struct ItemInfo
{
public string? prefabName;
public int? stack;
public float? durability;
public int? quality;
public int? variant;
public string? crafterName;
public SimpleVector2? gridPos;
}
Loading

0 comments on commit fbecd4e

Please sign in to comment.