-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRecipes.cs
141 lines (116 loc) · 4.33 KB
/
Recipes.cs
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using ModAPI;
using ModAPI.Attributes;
using TheForest.Items;
using TheForest.Items.Craft;
using TheForest.Utils;
using UnityEngine;
using Input = ModAPI.Input;
namespace Blueprints
{
internal class Recipes : MonoBehaviour
{
public static bool BOpened;
public static float FStamina;
public static float FEnergy;
protected Dictionary<int, Receipe> DicItemIdToReceipe;
protected string SInput = "Search for recipe...";
[ExecuteOnGameStart]
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private static void Init()
{
var go = new GameObject("__RECIPES__");
go.AddComponent<Recipes>();
Log.Write("Recipes added to Scene.");
}
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private void Start()
{
try
{
DicItemIdToReceipe = new Dictionary<int, Receipe>();
foreach (var recipe in ReceipeDatabase.Receipes)
{
if (DicItemIdToReceipe.ContainsKey(recipe._productItemID))
continue;
DicItemIdToReceipe.Add(recipe._productItemID, recipe);
}
Log.Write("Dictionary initialized.");
}
catch (Exception e)
{
Log.Write(e.Message);
}
}
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private void OnGUI()
{
if (!BOpened) return;
//TheForest.Utils.LocalPlayer.Inventory.Block();
//TheForest.Utils.LocalPlayer.Inventory.CancelNextChargedAttack = true;
//TheForest.Utils.LocalPlayer.Inventory.StashEquipedWeapon(false);
var cY = 30f;
GUI.skin = Gui.Skin;
var bkpMatrix = GUI.matrix;
SInput = GUI.TextField(new Rect(110, 110, 900, 30), SInput);
foreach (var item in ItemDatabase.Items)
if (item._name.ToUpper().Contains(SInput.ToUpper()))
{
if (SInput.Equals(string.Empty)) continue;
var bfound = false;
var sRecipe = GetRecipeString(item._id, ref bfound);
//ModAPI.Log.Write(string.Format("Recipe found for Item: {0} => {1}", item._name, bfound));
if (!bfound) continue;
GUI.TextField(new Rect(110f, 120f + cY, 800, 30f), sRecipe);
cY += 30f;
}
GUI.matrix = bkpMatrix;
}
private string GetRecipeString(int id, ref bool bNoEntry)
{
try
{
if (!DicItemIdToReceipe.ContainsKey(id))
{
bNoEntry = true;
return string.Empty;
}
var sRecipe = DicItemIdToReceipe[id]._name;
bNoEntry = true;
//foreach (var ingredient in dicItemIdToReceipe[id]._ingredients)
//{
// sRecipe += string.Format(", [Item: {0} - Amount: {1}]", TheForest.Items.ItemDatabase.ItemById(ingredient._itemID)._name, ingredient._amount);
//}
return sRecipe;
}
catch (Exception e)
{
Log.Write(e.Message);
return string.Empty;
}
}
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private void Update()
{
if (!Input.GetButtonDown("Recipes", "Blueprints")) return;
//TheForest.Utils.LocalPlayer.Inventory.Block();
//TheForest.Utils.LocalPlayer.Inventory.CancelNextChargedAttack = true;
if (BOpened)
{
LocalPlayer.FpCharacter.UnLockView();
//TheForest.Utils.LocalPlayer.Inventory.UnBlock();
LocalPlayer.Inventory.EquipPreviousWeaponDelayed();
}
else
{
LocalPlayer.FpCharacter.LockView();
FStamina = LocalPlayer.Stats.Stamina;
FEnergy = LocalPlayer.Stats.Energy;
LocalPlayer.Inventory.StashEquipedWeapon(false);
}
BOpened = !BOpened;
}
}
}