summaryrefslogtreecommitdiff
path: root/Valheim_r202102_v0.141.2/Valheim/assembly_valheim/OfferingBowl.cs
blob: 8f361b3fabaebe1c61f9ad7e9aefc47b9a5fa7ac (plain)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using System.Collections.Generic;
using UnityEngine;

public class OfferingBowl : MonoBehaviour, Hoverable, Interactable
{
	public string m_name = "Ancient bowl";

	public string m_useItemText = "Burn item";

	public ItemDrop m_bossItem;

	public int m_bossItems = 1;

	public GameObject m_bossPrefab;

	public ItemDrop m_itemPrefab;

	public Transform m_itemSpawnPoint;

	public string m_setGlobalKey = "";

	[Header("Boss")]
	public float m_spawnBossDelay = 5f;

	public float m_spawnBossMaxDistance = 40f;

	public float m_spawnBossMaxYDistance = 9999f;

	public float m_spawnOffset = 1f;

	[Header("Use itemstands")]
	public bool m_useItemStands;

	public string m_itemStandPrefix = "";

	public float m_itemstandMaxRange = 20f;

	[Header("Effects")]
	public EffectList m_fuelAddedEffects = new EffectList();

	public EffectList m_spawnBossStartEffects = new EffectList();

	public EffectList m_spawnBossDoneffects = new EffectList();

	private Vector3 m_bossSpawnPoint;

	private void Awake()
	{
	}

	public string GetHoverText()
	{
		if (m_useItemStands)
		{
			return Localization.instance.Localize(m_name + "\n[<color=yellow><b>$KEY_Use</b></color>] ") + Localization.instance.Localize(m_useItemText);
		}
		return Localization.instance.Localize(m_name + "\n[<color=yellow><b>1-8</b></color>] " + m_useItemText);
	}

	public string GetHoverName()
	{
		return m_name;
	}

	public bool Interact(Humanoid user, bool hold)
	{
		if (hold)
		{
			return false;
		}
		if (IsBossSpawnQueued())
		{
			return false;
		}
		if (m_useItemStands)
		{
			List<ItemStand> list = FindItemStands();
			foreach (ItemStand item in list)
			{
				if (!item.HaveAttachment())
				{
					user.Message(MessageHud.MessageType.Center, "$msg_incompleteoffering");
					return false;
				}
			}
			if (SpawnBoss(base.transform.position))
			{
				user.Message(MessageHud.MessageType.Center, "$msg_offerdone");
				foreach (ItemStand item2 in list)
				{
					item2.DestroyAttachment();
				}
				if ((bool)m_itemSpawnPoint)
				{
					m_fuelAddedEffects.Create(m_itemSpawnPoint.position, base.transform.rotation);
				}
			}
			return true;
		}
		return false;
	}

	public bool UseItem(Humanoid user, ItemDrop.ItemData item)
	{
		if (m_useItemStands)
		{
			return false;
		}
		if (IsBossSpawnQueued())
		{
			return true;
		}
		if (m_bossItem != null)
		{
			if (item.m_shared.m_name == m_bossItem.m_itemData.m_shared.m_name)
			{
				int num = user.GetInventory().CountItems(m_bossItem.m_itemData.m_shared.m_name);
				if (num < m_bossItems)
				{
					user.Message(MessageHud.MessageType.Center, "$msg_incompleteoffering: " + m_bossItem.m_itemData.m_shared.m_name + " " + num + " / " + m_bossItems);
					return true;
				}
				if (m_bossPrefab != null)
				{
					if (SpawnBoss(base.transform.position))
					{
						user.GetInventory().RemoveItem(item.m_shared.m_name, m_bossItems);
						user.ShowRemovedMessage(m_bossItem.m_itemData, m_bossItems);
						user.Message(MessageHud.MessageType.Center, "$msg_offerdone");
						if ((bool)m_itemSpawnPoint)
						{
							m_fuelAddedEffects.Create(m_itemSpawnPoint.position, base.transform.rotation);
						}
					}
				}
				else if (m_itemPrefab != null && SpawnItem(m_itemPrefab, user as Player))
				{
					user.GetInventory().RemoveItem(item.m_shared.m_name, m_bossItems);
					user.ShowRemovedMessage(m_bossItem.m_itemData, m_bossItems);
					user.Message(MessageHud.MessageType.Center, "$msg_offerdone");
					m_fuelAddedEffects.Create(m_itemSpawnPoint.position, base.transform.rotation);
				}
				if (!string.IsNullOrEmpty(m_setGlobalKey))
				{
					ZoneSystem.instance.SetGlobalKey(m_setGlobalKey);
				}
				return true;
			}
			user.Message(MessageHud.MessageType.Center, "$msg_offerwrong");
			return true;
		}
		return false;
	}

	private bool SpawnItem(ItemDrop item, Player player)
	{
		if (item.m_itemData.m_shared.m_questItem && player.HaveUniqueKey(item.m_itemData.m_shared.m_name))
		{
			player.Message(MessageHud.MessageType.Center, "$msg_cantoffer");
			return false;
		}
		Object.Instantiate(item, m_itemSpawnPoint.position, Quaternion.identity);
		return true;
	}

	private bool SpawnBoss(Vector3 point)
	{
		for (int i = 0; i < 100; i++)
		{
			Vector2 vector = Random.insideUnitCircle * m_spawnBossMaxDistance;
			Vector3 vector2 = point + new Vector3(vector.x, 0f, vector.y);
			float solidHeight = ZoneSystem.instance.GetSolidHeight(vector2);
			if (!(solidHeight < 0f) && !(Mathf.Abs(solidHeight - base.transform.position.y) > m_spawnBossMaxYDistance))
			{
				vector2.y = solidHeight + m_spawnOffset;
				m_spawnBossStartEffects.Create(vector2, Quaternion.identity);
				m_bossSpawnPoint = vector2;
				Invoke("DelayedSpawnBoss", m_spawnBossDelay);
				return true;
			}
		}
		return false;
	}

	private bool IsBossSpawnQueued()
	{
		return IsInvoking("DelayedSpawnBoss");
	}

	private void DelayedSpawnBoss()
	{
		BaseAI component = Object.Instantiate(m_bossPrefab, m_bossSpawnPoint, Quaternion.identity).GetComponent<BaseAI>();
		if (component != null)
		{
			component.SetPatrolPoint();
		}
		m_spawnBossDoneffects.Create(m_bossSpawnPoint, Quaternion.identity);
	}

	private List<ItemStand> FindItemStands()
	{
		List<ItemStand> list = new List<ItemStand>();
		ItemStand[] array = Object.FindObjectsOfType<ItemStand>();
		foreach (ItemStand itemStand in array)
		{
			if (!(Vector3.Distance(base.transform.position, itemStand.transform.position) > m_itemstandMaxRange) && itemStand.gameObject.name.StartsWith(m_itemStandPrefix))
			{
				list.Add(itemStand);
			}
		}
		return list;
	}
}