-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRoom.cs
180 lines (150 loc) · 6.53 KB
/
Room.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using ItemChanger;
using ItemChanger.Placements;
using ItemChanger.Tags;
using ItemChanger.UIDefs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace HKSecondQuest
{
/// <summary>
/// Handles changes to rooms or areas of the game
/// </summary>
public abstract class Room
{
/// <summary>
/// The scene name of the room to be modified (if none is provided, OnBeforeLoad and OnLoad never trigger)
/// </summary>
public string RoomName;
/// <summary>
/// Should the room be flipped?
/// </summary>
public bool IsFlipped = false;
/// <summary>
/// What's the minimum amount of damage any hit should deal?
/// </summary>
public int MinDamage = 0;
public int MaxDamage = 100;
public int Revision = 1; //World init gets called if save from older Revision is loaded
/// <param name="roomName">The scene name of this room (or a placeholder if there is none)</param>
protected Room(string roomName)
{
RoomName = roomName;
}
/// <summary>
/// Called on initialization of the mod
/// </summary>
public virtual void OnInit() {}
/// <summary>
/// Called on creation of a new save file
/// </summary>
public virtual void OnWorldInit() {}
/// <summary>
/// Called before any "Start" functions are executed in this room
/// </summary>
public virtual void OnBeforeLoad() {}
/// <summary>
/// Called after the "Start" functions of the room have executed
/// </summary>
public virtual void OnLoad() {}
/// <summary>
/// Changes an item location using ItemChanger (Call in OnWorldInit)
/// </summary>
/// <param name="location">The item location to change</param>
/// <param name="item">The item it should be changed to</param>
/// <param name="merge">Should the item be merged with other items place here (used for shops,grubfather and seer)?</param>
/// <param name="alternateName">Alternate name to be displayed in shops</param>
/// <param name="alternateDesc">Alternate description to be displayed in shops</param>
/// <param name="destroySeerRewards">Should the normal rewards of Seer be removed? (only applicable at that location)</param>
public void SetItem(string location, string item, bool merge = false, int geoCost = 0, int essenceCost = 0, int grubCost = 0, string alternateName=null, string alternateDesc=null, bool destroySeerRewards=false, bool nonIncremental=false)
{
//find item and location
AbstractPlacement placement = Finder.GetLocation(location).Wrap();
AbstractItem aitem = Finder.GetItem(item);
if (nonIncremental)
{
aitem.RemoveTags<IItemModifierTag>();
}
//set cost tags if necessary
if (geoCost > 0)
{
if (placement is ISingleCostPlacement)
{
((ISingleCostPlacement)placement).Cost = new GeoCost(geoCost);
}
else
{
aitem.AddTag<CostTag>().Cost = new GeoCost(geoCost);
}
}
if (essenceCost > 0)
{
aitem.AddTag<CostTag>().Cost = new PDIntCost(essenceCost, nameof(PlayerData.dreamOrbs), essenceCost+" Essence");
}
if (grubCost > 0)
{
aitem.AddTag<CostTag>().Cost = new PDIntCost(grubCost, nameof(PlayerData.grubsCollected), grubCost+" Grubs");
}
//change UIDef names if necessary
if (alternateName != null) ((MsgUIDef)aitem.UIDef).name = new BoxedString(alternateName);
if (alternateDesc != null) ((MsgUIDef)aitem.UIDef).shopDesc = new BoxedString(alternateDesc);
placement.Add(aitem);
//add DestroySeerRewardTag if necessary
if (destroySeerRewards)
{
placement.AddTag<DestroySeerRewardTag>().destroyRewards = SeerRewards.All;
}
//choose conflict reolution methos
PlacementConflictResolution resolution = merge ? PlacementConflictResolution.MergeKeepingNew : PlacementConflictResolution.Replace;
//add placement
ItemChangerMod.AddPlacements(new AbstractPlacement[] { placement }, resolution);
}
/// <summary>
/// Changes a transition using ItemChanger
/// </summary>
/// <param name="oneWay">If true, no transition from target to source will be set</param>
public void SetTransition(string sourceScene, string sourceGate, string targetScene, string targetGate, bool oneWay = false)
{
Transition t1 = new Transition(sourceScene, sourceGate);
Transition t2 = new Transition(targetScene, targetGate);
ItemChangerMod.AddTransitionOverride(t1, t2);
if (!oneWay) ItemChangerMod.AddTransitionOverride(t2, t1);
}
/// <summary>
/// Places a prefab (Call in OnBeforeLoad or OnLoad)
/// </summary>
public GameObject PlaceGO(GameObject prefab, float x, float y, Quaternion? rotation = null)
{
GameObject go = GameObject.Instantiate(prefab, new Vector3(x, y, 0), rotation.GetValueOrDefault(Quaternion.identity));
go.SetActive(true);
return go;
}
/// <summary>
/// Destroys the named GameObject (Call in OnBeforeLoad or OnLoad)
/// </summary>
public void DestroyGO(string name)
{
GameObject.Destroy(GameObject.Find(name));
}
/// <summary>
/// Adds a text replacement to the TextChanger (Call in OnInit)
/// </summary>
public void ReplaceText(string key, string text, string sheetKey = "")
{
HKSecondQuest.Instance.TextChanger.AddReplacement(key, text, sheetKey);
}
/// <summary>
/// Changes whether the room should be dark without lantern (Call in OnBeforeLoad)
/// </summary>
public void SetDarkness(bool dark)
{
foreach (GameObject go in Resources.FindObjectsOfTypeAll(typeof(GameObject)).Where(go => go.name == "_SceneManager"))
{
go.GetComponent<SceneManager>().darknessLevel = dark ? 2 : 0;
}
}
}
}