-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from FroggerHH/dev
Pull from dev
- Loading branch information
Showing
51 changed files
with
1,338 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.