-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAPI.cs
More file actions
46 lines (39 loc) · 1.32 KB
/
API.cs
File metadata and controls
46 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using ItemDrawers;
using UnityEngine;
namespace API;
//class to copy
public static class ItemDrawers_API
{
private static readonly bool _IsInstalled;
private static readonly MethodInfo MI_GetAllDrawers;
public class Drawer(ZNetView znv)
{
public string Prefab = znv.m_zdo.GetString("Prefab");
public int Amount = znv.m_zdo.GetInt("Amount");
public void Remove(int amount) { znv.ClaimOwnership(); znv.InvokeRPC("ForceRemove", amount); }
public void Withdraw(int amount) => znv.InvokeRPC("WithdrawItem_Request", amount);
}
public static List<Drawer> AllDrawers => _IsInstalled ?
((List<ZNetView>)MI_GetAllDrawers.Invoke(null, null)).Select(znv => new Drawer(znv)).ToList()
: new();
static ItemDrawers_API()
{
if (Type.GetType("API.ClientSide, ItemDrawers") is not { } drawersAPI)
{
_IsInstalled = false;
return;
}
_IsInstalled = true;
MI_GetAllDrawers = drawersAPI.GetMethod("AllDrawers", BindingFlags.Public | BindingFlags.Static);
}
}
//do not copy
public static class ClientSide
{
public static List<ZNetView> AllDrawers() => DrawerComponent.AllDrawers.Select(d => d._znv).ToList();
}