-
Notifications
You must be signed in to change notification settings - Fork 0
/
ForcePractice.cs
115 lines (91 loc) · 3.19 KB
/
ForcePractice.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
using System;
using System.Reflection;
using Kitchen;
using KitchenMods;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using Unity.Entities;
using Kitchen.Modules;
namespace PlateUp_ForceConsent
{
public class ForceStartPracticeMode : GenericSystemBase, IModSystem
{
EntityQuery PopupQuery;
protected override void Initialise() {
base.Initialise();
//RequireSingletonForUpdate<SKitchenMarker>();
RequireSingletonForUpdate<SIsNightTime>();
Helper.LogInfo("ForcePractice Initialise()");
this.PopupQuery = base.GetEntityQuery(new ComponentType[]
{
typeof(StartPracticePopup.CRequest)
});
}
protected override void OnUpdate()
{
bool hasMatches = !this.PopupQuery.IsEmpty;
if (!hasMatches)
{
return;
}
Helper.LogInfo("FORCE: StartPracticeMode");
ConsentElement[] consentElements = GameObject.FindObjectsOfType<ConsentElement>();
if (consentElements.Length < 2)
{
//Debug.Log("consentElements.Length < 2");
//Helper.LogInfo("consentElements.Length < 2");
return;
}
//int counter = 0;
//foreach(var consentElement in consentElements)
//{
// //consentElement.ClearConsents();
// //Helper.LogInfo("foreach"+counter+" "+consentElement.Mode);
// //counter++;
//}
ConsentElement elem = consentElements[1];
//elem.SetAllConsents(true);
ConsentElement elemTwo = consentElements[2];
elemTwo.Mode = ConsentElement.ConsentMode.AnyRequired;
//elemTwo.ClearConsents();
elemTwo.SetAllConsents(true);
}
}
public class ForceLeavePracticeMode : LeavePracticeMode, IModSystem
{
protected override void Initialise()
{
base.Initialise();
Helper.LogInfo("ForceLeavePractice Initialise()");
}
protected override void OnUpdate()
{
if (!base.Has<SPracticeMode>())
{
return;
}
EndPracticeView view = GameObject.FindObjectOfType<EndPracticeView>();
if (!view)
{
return;
}
int[] consents = GetConsentArray(view);
if (consents.Length > 0)
{
Helper.LogInfo("FORCE: LeavePracticeMode");
var leave = GetOrDefault<SLeavePracticeView>();
leave.Ready = true;
Set(leave);
}
}
private int[] GetConsentArray(EndPracticeView view)
{
Type type = typeof(EndPracticeView);
FieldInfo field = type.GetField("Consents", BindingFlags.NonPublic | BindingFlags.Instance);
HashSet<int> consents = (HashSet<int>)field.GetValue(view);
int[] consentsArrray = consents.ToArray();
return consentsArrray;
}
}
}