using System;
using System.Collections;
using System.Collections.Generic;
using DarkTonic.MasterAudio;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

// Token: 0x020000D9 RID: 217
public class SkillButton : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler
{
	// Token: 0x06001449 RID: 5193 RVA: 0x00188E12 File Offset: 0x00187012
	private void Awake()
	{
		this.clickedDown = false;
		this.button = base.gameObject.GetComponent<Button>();
		this.componentID = -1;
		if (this.deleteButton)
		{
			this.delete = this.deleteButton.GetComponent<Button>();
		}
	}

	// Token: 0x0600144A RID: 5194 RVA: 0x00188E51 File Offset: 0x00187051
	public void StartSheen()
	{
		this.character.portrait.skillBag.PlayFX(base.gameObject, this.isSpell);
	}

	// Token: 0x0600144B RID: 5195 RVA: 0x00188E74 File Offset: 0x00187074
	private void OnEnable()
	{
		if (this.abilityName != "" && this.character && this.updateDescOnEnable)
		{
			this.UpdateSpellDescription();
		}
	}

	// Token: 0x0600144C RID: 5196 RVA: 0x00188EA4 File Offset: 0x001870A4
	public void Setup(bool activeTrigger, bool useable)
	{
		this.iconBG.enabled = true;
		base.gameObject.SetActive(true);
		this.abilityRow = Links.x.library.GetAbilityRow(this.abilityName);
		this.effectRow = null;
		this.isInstrument = false;
		if (this.inWindow)
		{
			this.rt = base.gameObject.GetComponent<RectTransform>();
		}
		if (this.iconBG && this.inWindow)
		{
			this.iconBG.raycastTarget = true;
			this.button.interactable = true;
		}
		if (this.difficulty)
		{
			this.difficulty.gameObject.SetActive(false);
		}
		if (this.spirit)
		{
			this.spirit.gameObject.SetActive(false);
		}
		if (this.abilityRow._IsSpell)
		{
			this.isInstrument = false;
			this.paganRow = Links.x.library.GetPaganRow(this.abilityName);
			Sprite sprite;
			if (!this.forSale)
			{
				sprite = Links.x.archives.AddRune(this.uniqueName, string.Concat(new string[]
				{
					Application.persistentDataPath,
					"/AutoSave/",
					this.uniqueName,
					"_",
					this.character.stats.partyID.ToString(),
					".png"
				}), this.character.stats.GetName(), this.abilityName);
			}
			else
			{
				sprite = Resources.Load<Sprite>("Sprites/" + this.abilityName);
			}
			this.iconBG.sprite = sprite;
			if (sprite == null)
			{
				sprite = this.songBack;
			}
			this.iconBG.gameObject.SetActive(true);
			this.iconBG.sprite = sprite;
			this.isSpell = true;
			if (this.spellMaterial != null)
			{
				this.iconBG.material = this.spellMaterial;
			}
			this.iconBG.color = this.spellColor;
		}
		else
		{
			this.abilityRow = Links.x.library.GetAbilityRow(this.abilityName);
			if (this.songMaterial != null)
			{
				this.iconBG.material = this.songMaterial;
			}
			if (this.button)
			{
				this.button.interactable = true;
				this.button.enabled = true;
			}
			if (this.abilityRow._IsSong)
			{
				this.isInstrument = true;
				this.iconBG.gameObject.SetActive(true);
				this.iconBG.color = this.songColor;
				Sprite abilitySprite = Links.x.archives.GetAbilitySprite(this.abilityRow._Sprite);
				this.iconBG.sprite = abilitySprite;
				if (abilitySprite == null)
				{
					this.iconBG.sprite = this.songBack;
				}
			}
			else
			{
				Library.Inventory invRow = this.character.invRow1;
				Sprite abilitySprite2 = Links.x.archives.GetAbilitySprite(this.abilityRow._Sprite);
				this.iconBG.sprite = abilitySprite2;
				this.iconBG.gameObject.SetActive(true);
				this.iconBG.sprite = abilitySprite2;
			}
			this.isSpell = false;
		}
		if (!this.inWindow)
		{
			if (this.spellMat1)
			{
				if (this.isSpell)
				{
					int num = Random.Range(0, 4);
					if (num == 0)
					{
						this.iconBG.material = this.spellMat1;
					}
					else if (num == 1)
					{
						this.iconBG.material = this.spellMat2;
					}
					else if (num == 2)
					{
						this.iconBG.material = this.spellMat3;
					}
					else if (num == 3)
					{
						this.iconBG.material = this.spellMat4;
					}
				}
				else
				{
					this.iconBG.material = this.songMat;
				}
			}
			if (this.delete)
			{
				this.delete.interactable = Links.x.mk;
			}
		}
		this.canUse = true;
		if (this.inWindow && this.deleteButton)
		{
			this.deleteButton.SetActive(false);
		}
		else if (!this.inWindow && this.deleteButton)
		{
			if (this.abilityRow._IsSpell)
			{
				this.deleteButton.SetActive(true);
			}
			else
			{
				this.deleteButton.SetActive(false);
			}
		}
		if (this.isSpell && this.deleteButton && !this.rt)
		{
			this.rt = base.gameObject.GetComponent<RectTransform>();
		}
		if (!this.isSpell)
		{
			this.str.Clear();
			if (this.componentID == -1)
			{
				this.str.Append("<size=1.4em><font=Bold>");
				this.str.Append(this.abilityRow._DisplayName);
				if (this.abilityRow._WeaponReq == "Flute")
				{
					this.str.Append(" (Flute)");
				}
				if (this.abilityRow._WeaponReq == "Pipe")
				{
					this.str.Append(" (Shepard Pipes)");
				}
				if (this.abilityRow._WeaponReq == "Horn")
				{
					this.str.Append(" (Horn)");
				}
				this.str.Append("</font></size>\n");
				if (!this.isInstrument)
				{
					this.effectRow = Links.x.library.GetEffectRow(this.abilityName);
					if (this.effectRow == null)
					{
						this.effectRow = Links.x.library.GetEffectRow(this.abilityName + "Word");
					}
				}
				else
				{
					this.effectRow = Links.x.library.GetEffectRow(this.abilityName);
					if (this.effectRow == null)
					{
						Debug.Log(this.abilityName);
					}
				}
				float num2;
				if (this.abilityRow._WeaponReq == "Flute")
				{
					num2 = this.character.stats.GetSkill(26);
				}
				else if (this.abilityRow._WeaponReq == "Horn")
				{
					num2 = this.character.stats.GetSkill(27);
				}
				else
				{
					num2 = this.character.stats.GetSkill(29);
				}
				string effectDescription = Links.x.manual.GetEffectDescription(this.effectRow, Records.x.SongSkillMultiplier(num2), 0);
				this.str.Append(effectDescription);
				if (!this.isEquipped)
				{
					int num3;
					if (this.forSale)
					{
						num3 = this.abilityRow._X;
					}
					else
					{
						num3 = this.character.stats.GetAbilityTriggerGoal(this.index);
					}
					if (num3 > 1)
					{
						string text;
						if (!this.forSale)
						{
							text = this.character.stats.GetAbilityTrigger(this.index, true);
						}
						else
						{
							text = this.character.stats.TriggerName(this.abilityRow._Trigger, true);
						}
						this.str.Append(". Triggers every ");
						this.str.Append(num3);
						this.str.Append(" ");
						if (text == "X")
						{
							this.str.Append("attacks");
						}
						else
						{
							this.str.Append(text);
						}
						this.str.Append(".");
					}
					else
					{
						string text2;
						if (!this.forSale)
						{
							text2 = this.character.stats.GetAbilityTrigger(this.index, false);
						}
						else
						{
							text2 = this.character.stats.TriggerName(this.abilityRow._Trigger, false);
						}
						this.str.Append(". Triggers on ");
						if (text2 == "X")
						{
							this.str.Append("attack");
						}
						else
						{
							this.str.Append(text2);
						}
						this.str.Append(".");
					}
				}
				if (!this.inWindow)
				{
					this.str.Append("\n<font=Bold>Points:</font> ");
					this.str.Append(this.abilityRow._SongCost);
				}
				this.fullText = this.str.ToString();
				this.spellDesc = this.str.ToString();
				if (this.nameText)
				{
					this.nameText.text = this.fullText;
					this.nameText.enabled = true;
				}
				this.halfText = this.abilityRow._DisplayName;
			}
		}
		else
		{
			this.UpdateSpellDescription();
		}
		if (this.triggerBackground)
		{
			this.ShowTrigger();
		}
		this.UpdateUseState(useable);
		if (this.nameText)
		{
			float num4 = 65f;
			float preferredHeight = this.nameText.preferredHeight;
			if (preferredHeight > num4)
			{
			}
			this.nameTextRT.sizeDelta = new Vector2(this.nameTextRT.sizeDelta.x, preferredHeight);
		}
		if (this.button && !this.isSpell)
		{
			if (this.inWindow || this.forSale)
			{
				this.button.transition = Selectable.Transition.ColorTint;
				return;
			}
			this.button.transition = Selectable.Transition.None;
		}
	}

	// Token: 0x0600144D RID: 5197 RVA: 0x00189808 File Offset: 0x00187A08
	public void UpdateSpellDescription()
	{
		this.effectRow = Links.x.library.GetEffectRow(this.abilityName);
		this.str.Clear();
		if (!this.inWindow)
		{
			this.str.Append("<size=1.5em><font=Bold>");
			this.str.Append(this.uniqueName);
			this.str.Append("</font></size>\n");
		}
		this.SetDescription(this.spellStats.x, this.spellStats.y, this.spellStats.z, this.spellStats.w);
		this.fullText = this.str.ToString();
		this.spellDesc = this.str.ToString();
		if (this.nameText)
		{
			this.nameText.text = this.fullText;
			this.nameText.enabled = true;
		}
		this.str.Clear();
		this.str.Append("Cast ");
		this.str.Append(this.uniqueName);
		this.str.Append(" (");
		this.str.Append(Mathf.RoundToInt(this.abilityCost));
		this.str.Append(" Spirit)");
		this.halfText = this.str.ToString();
		this.header = "Cast " + this.uniqueName;
		float num = Records.x.SpellDifficulty(this.paganRow, this.spellStats.x, this.spellStats.y, this.spellStats.z);
		if (this.paganRow._Slider1.Contains("Summon"))
		{
			this.updateDescOnEnable = true;
			num += this.character.stats.SummonModSpells();
		}
		else
		{
			this.updateDescOnEnable = false;
		}
		float num2 = this.character.stats.PaganHitChance(true, this.paganRow._School);
		if (num > num2 && this.difficulty)
		{
			this.difficulty.gameObject.SetActive(true);
			return;
		}
		if (this.difficulty)
		{
			this.difficulty.gameObject.SetActive(false);
		}
	}

	// Token: 0x0600144E RID: 5198 RVA: 0x00189A50 File Offset: 0x00187C50
	public void SetResizeDrag()
	{
		bool flag = true;
		if (Records.x.movingWindows)
		{
			flag = false;
		}
		if (flag && !this.button.interactable)
		{
			return;
		}
		this.iconBG.raycastTarget = flag;
	}

	// Token: 0x0600144F RID: 5199 RVA: 0x00189A8A File Offset: 0x00187C8A
	public void ForSaleInteractable(bool state)
	{
		this.button.enabled = true;
		if (Links.x.joy)
		{
			this.button.interactable = true;
		}
		else
		{
			this.button.interactable = state;
		}
		this.iconBG.raycastTarget = state;
	}

	// Token: 0x06001450 RID: 5200 RVA: 0x00189ACC File Offset: 0x00187CCC
	public void End()
	{
		this.index = -1;
		this.componentID = -1;
		this.abilityName = "";
		this.SetState(false);
		this.iconBG.enabled = false;
		if (this.triggerBackground)
		{
			this.triggerBackground.enabled = false;
			this.triggerReadyText.enabled = false;
		}
	}

	// Token: 0x06001451 RID: 5201 RVA: 0x00189B2C File Offset: 0x00187D2C
	public void ShowTrigger()
	{
		if (this.abilityName != "" && this.inWindow)
		{
			if (!this.character.stats.GetAbilityReadyState(this.index))
			{
				this.triggerBackground.enabled = true;
				this.triggerReadyText.enabled = true;
				this.triggerBackground.color = this.triggerNotReady;
				this.triggerReadyText.text = "!";
				return;
			}
			this.triggerBackground.color = Color.white;
			int abilityTriggerGoal = this.character.stats.GetAbilityTriggerGoal(this.index);
			if (abilityTriggerGoal > 1)
			{
				this.triggerBackground.enabled = true;
				this.triggerReadyText.enabled = true;
				this.triggerReadyText.text = (abilityTriggerGoal - this.character.stats.GetAbilityTriggerCount(this.index)).ToString();
				return;
			}
			this.triggerBackground.enabled = false;
			this.triggerReadyText.enabled = false;
		}
	}

	// Token: 0x06001452 RID: 5202 RVA: 0x00189C34 File Offset: 0x00187E34
	public void UpdateUseState(bool useable)
	{
		if (this.index == -1)
		{
			return;
		}
		if (!this.character)
		{
			return;
		}
		if (!this.inWindow)
		{
			return;
		}
		if (this.isEquipped)
		{
			return;
		}
		if (this.inSpellMenu)
		{
			this.canUse = true;
		}
		else if (this.abilityRow._IsSpell)
		{
			this.canUse = useable;
		}
		else
		{
			if (!Records.x.InCombat(false) && this.abilityRow._WeaponReq == "Pipe")
			{
				useable = false;
			}
			this.canUse = useable;
		}
		if (this.character.attackTime < 1f)
		{
			this.canUse = false;
		}
		if (!this.character.CanAttack())
		{
			this.canUse = false;
		}
		if (this.spirit)
		{
			if (this.canUse)
			{
				this.spirit.gameObject.SetActive(false);
			}
			else
			{
				this.spirit.gameObject.SetActive(true);
			}
			if (useable || Records.x.partySailing)
			{
				this.spirit.enabled = false;
			}
			else
			{
				this.spirit.enabled = true;
			}
		}
		if (!this.canUse && this.isSpell)
		{
			ColorBlock colors = this.button.colors;
			Color disabledColor = colors.disabledColor;
			colors.normalColor = disabledColor;
			colors.highlightedColor = disabledColor;
			colors.selectedColor = disabledColor;
			colors.pressedColor = disabledColor;
			this.button.colors = colors;
			this.button.interactable = true;
			this.iconBG.raycastTarget = true;
			return;
		}
		float num = 0.6039216f;
		Color color = new Color(num, num, num, 1f);
		ColorBlock colors2 = this.button.colors;
		colors2.normalColor = color;
		colors2.highlightedColor = Color.white;
		colors2.selectedColor = Color.white;
		colors2.pressedColor = Color.white;
		this.button.colors = colors2;
		this.button.interactable = true;
		this.iconBG.raycastTarget = true;
	}

	// Token: 0x06001453 RID: 5203 RVA: 0x00189E2B File Offset: 0x0018802B
	public void RemoveOutline()
	{
		if (!this.character)
		{
			return;
		}
		if (this.slowedTime)
		{
			Links.x.combat.EndSlowTime();
		}
		this.character.portrait.skillBag.EndFX();
	}

	// Token: 0x06001454 RID: 5204 RVA: 0x00189E68 File Offset: 0x00188068
	public void SetState(bool state)
	{
		if (!this.inWindow)
		{
			return;
		}
		if (this.index > -1)
		{
			if (!state)
			{
				this.button.interactable = false;
				this.RemoveOutline();
				return;
			}
			if (this.character.stats.GetAbilityStatus(this.index))
			{
				this.button.interactable = true;
				return;
			}
			this.button.interactable = true;
		}
	}

	// Token: 0x06001455 RID: 5205 RVA: 0x00189ECE File Offset: 0x001880CE
	public void ToggleStateSkillMenu(bool state)
	{
		if (!state)
		{
			this.RemoveOutline();
			this.iconBG.enabled = false;
			return;
		}
		this.iconBG.enabled = true;
	}

	// Token: 0x06001456 RID: 5206 RVA: 0x00189EF4 File Offset: 0x001880F4
	public void OnPointerEnter(PointerEventData eventData)
	{
		if (Input.GetMouseButton(0))
		{
			return;
		}
		if (this.inSpellMenu && (Links.x.characterSheet.open || Links.x.spellcrafting.open))
		{
			return;
		}
		if (!this.inWindow)
		{
			return;
		}
		Links.x.currentSkillHover = this;
		Links.x.gameplay.uiCanClick = true;
		if (this.isSpell)
		{
			this.character.portrait.skillBag.TooltipOn(this, base.gameObject, this.halfText, false);
			return;
		}
		this.character.portrait.skillBag.TooltipOn(this, base.gameObject, this.halfText, false);
	}

	// Token: 0x06001457 RID: 5207 RVA: 0x00189FA8 File Offset: 0x001881A8
	public string GetHoverSpell()
	{
		string text = "Cast " + this.abilityRow._DisplayName;
		if (this.canUse)
		{
			text += "\n-Ready-";
		}
		return text;
	}

	// Token: 0x06001458 RID: 5208 RVA: 0x00189FE0 File Offset: 0x001881E0
	public void OnPointerExit(PointerEventData eventData)
	{
		if (Input.GetMouseButton(0))
		{
			return;
		}
		if (!this.inWindow)
		{
			return;
		}
		if (Links.x.currentSkillHover == this)
		{
			Links.x.currentSkillHover = null;
		}
		if (this.inSpellMenu)
		{
			return;
		}
		Links.x.gameplay.uiCanClick = false;
		this.character.portrait.skillBag.TooltipOff();
	}

	// Token: 0x06001459 RID: 5209 RVA: 0x0018A04C File Offset: 0x0018824C
	private void SetDescription(float slider1, float slider2, float slider3, float tether)
	{
		this.str.Append(this.paganRow._DynamicDescriptionStart);
		string text = Records.x.PaganDescription(this.paganRow, slider1, slider2, slider3);
		if (this.inWindow)
		{
			this.str.Append(text);
			this.str.Append(".");
			this.str.Append("\nSpell Challenge: ");
			float num = Records.x.SpellDifficulty(this.paganRow, slider1, slider2, slider3);
			this.str.Append(num);
			if (this.paganRow._Slider1.Contains("Summon"))
			{
				float num2 = this.character.stats.SummonModSpells();
				if (num2 > 0f)
				{
					this.str.Append(" + ");
					this.str.Append(num2);
					this.str.Append(" [Party Size Penalty]");
				}
			}
			this.str.Append(" (vs. ");
			this.str.Append(this.character.stats.GetName());
			this.str.Append("'s ");
			this.str.Append(this.character.stats.PaganHitChance(true, this.paganRow._School));
			this.str.Append(")");
			if (this.abilityRow._UseOnBoat)
			{
				this.str.Append("\nCan use on boat");
				return;
			}
		}
		else
		{
			this.str.Append("\n<font=Bold>Spirit Cost: </font>");
			this.str.Append(Mathf.RoundToInt(this.abilityCost));
			this.str.Append(" spirit");
			this.str.Append("\n<font=Bold>Spell Challenge: </font>");
			this.str.Append(Records.x.SpellDifficulty(this.paganRow, slider1, slider2, slider3));
			this.str.Append(" (vs. ");
			this.str.Append(this.character.stats.GetName());
			this.str.Append("'s ");
			this.str.Append(this.character.stats.PaganHitChance(true, this.paganRow._School));
			this.str.Append(")");
			if (this.paganRow._NeedsTether)
			{
				this.str.Append("\n<font=Bold>Overpower Strength: </font>");
				this.str.Append(this.R2(tether));
			}
			if (this.abilityRow._UseOnBoat)
			{
				this.str.Append("\nCan use on boat");
			}
			this.str.Append(text);
			this.str.Append(".");
		}
	}

	// Token: 0x0600145A RID: 5210 RVA: 0x0018A325 File Offset: 0x00188525
	private float R2(float x)
	{
		return Mathf.Round(x * 10f) / 10f;
	}

	// Token: 0x0600145B RID: 5211 RVA: 0x0018A33C File Offset: 0x0018853C
	public void OnPointerDown(PointerEventData eventData)
	{
		if (!this.inWindow)
		{
			if (this.forSale)
			{
				if (!this.isSpell && this.canBuy)
				{
					this.BuySong();
					return;
				}
			}
			else
			{
				if (!this.isSpell && !this.isEquipped)
				{
					this.SelectSong();
					return;
				}
				if (this.isSpell && !this.inWindow && !this.isEquipped)
				{
					if (Links.x.joy)
					{
						this.OpenDeleteConfirm();
						return;
					}
					if (Links.x.characterSheet.booksMenu.open)
					{
						Links.x.characterSheet.booksMenu.AddFavoriteSpell(this);
						return;
					}
				}
				else
				{
					bool flag = this.isEquipped;
				}
			}
			return;
		}
		Links.x.gameplay.StoneSoundQuieter();
		if (this.inSpellMenu && Links.x.spellcrafting.open)
		{
			return;
		}
		if ((Input.GetMouseButton(1) && Links.x.mk) || Links.x.joy)
		{
			if (this.isInstrument)
			{
				this.desc = this.fullText;
				int abilityTriggerGoal = this.character.stats.GetAbilityTriggerGoal(this.index);
				int num = abilityTriggerGoal - this.character.stats.GetAbilityTriggerCount(this.index);
				if (abilityTriggerGoal > 0)
				{
					this.desc += " (";
					this.desc += num.ToString();
					this.desc += " needed until song plays.)";
				}
			}
			else
			{
				this.str.Clear();
				this.str.Append(this.abilityRow._DisplayName);
				if (this.abilityRow._MainSkill == "Bindings")
				{
					this.str.Append(" (Bindings)");
				}
				if (this.abilityRow._MainSkill == "Fauna")
				{
					this.str.Append(" (Fauna)");
				}
				if (this.abilityRow._MainSkill == "Vines")
				{
					this.str.Append(" (Vines)");
				}
				if (this.abilityRow._MainSkill == "Spores")
				{
					this.str.Append(" (Spores)");
				}
				this.header = this.str.ToString();
				this.str.Clear();
				this.str.Append(this.spellDesc);
				float num2 = 0f;
				Vector4 abilityLevel = this.character.stats.GetAbilityLevel(this.index);
				for (int i = 0; i < 3; i++)
				{
					string text = "";
					float num3 = 0f;
					if (i == 0)
					{
						text = this.paganRow._Slider1;
						num3 = abilityLevel.x;
					}
					if (i == 1)
					{
						text = this.paganRow._Slider2;
						num3 = abilityLevel.y;
					}
					if (i == 2)
					{
						text = this.paganRow._Slider3;
						num3 = abilityLevel.z;
					}
					if (text.Contains("Damage") || text.Contains("Deterioration") || text.Contains("Effects") || text.Contains("Power"))
					{
						num2 = num3;
					}
				}
				string effectDescription = Links.x.manual.GetEffectDescription(this.effectRow, num2, 0);
				if (effectDescription != "")
				{
					this.str.Append("\nSpell effects: ");
					this.str.Append(effectDescription);
					this.str.Append("\n");
				}
				else
				{
					this.str.Append("\n\n");
				}
				this.desc = this.str.ToString();
			}
			this.character.portrait.skillBag.OpenDescription(this, base.gameObject, this.header, this.desc);
			return;
		}
		if (this.character.attackTime < 1f || this.character.inAction || this.character.inQueuedAbility || !this.character.IsSentient())
		{
			return;
		}
		this.clickedDown = true;
	}

	// Token: 0x0600145C RID: 5212 RVA: 0x0018A76C File Offset: 0x0018896C
	private void SelectSong()
	{
		if (this.isInstrument)
		{
			Links.x.characterSheet.character.stats.UpdateEquippedSongList(this.uniqueName);
		}
		Links.x.characterSheet.booksMenu.UpdateSelected();
		this.character.portrait.skillBag.SetSongGrid();
	}

	// Token: 0x0600145D RID: 5213 RVA: 0x0018A7CC File Offset: 0x001889CC
	private void BuySong()
	{
		int num = (int)Links.x.characterSheet.character.stats.SongCost(this.abilityRow);
		if (Links.x.inventory.emeralds >= num)
		{
			Links.x.characterSheet.character.stats.AddSong(this.abilityName, this.abilityName, new Vector3(1f, 1f, 1f));
			Links.x.inventory.emeralds -= num;
			MasterAudio.PlaySoundAndForget("Inventory", Random.Range(0.3f, 0.45f), new float?(1f), 0f, "Coins", null);
			Links.x.inventory.UpdateMisc();
			Links.x.characterSheet.UpdateSongShop();
			Links.x.characterSheet.booksMenu.SetGrid("Songs", Links.x.characterSheet.character, false);
			return;
		}
		string merchantText = Links.x.merchant.GetMerchantText("Not Enough");
		Links.x.characterSheet.StartQuip(merchantText, FaceAnimations.AnimationNames.Frown);
	}

	// Token: 0x0600145E RID: 5214 RVA: 0x0018A908 File Offset: 0x00188B08
	public void PointerUpJoystick()
	{
		if (this.inWindow && !this.isEquipped)
		{
			if (Links.x.joy)
			{
				this.clickedDown = true;
				this.OnPointerUp(null);
				return;
			}
		}
		else if (this.forSale && Links.x.joy)
		{
			if (!this.isSpell && this.canBuy)
			{
				this.BuySong();
				return;
			}
		}
		else
		{
			if (Links.x.joy && this.isInstrument && Links.x.characterSheet.open && !this.inWindow)
			{
				this.SelectSong();
				return;
			}
			if (Links.x.joy && this.isSpell && !this.inWindow && !this.isEquipped && Links.x.characterSheet.open)
			{
				Links.x.characterSheet.booksMenu.AddFavoriteSpell(this);
			}
		}
	}

	// Token: 0x0600145F RID: 5215 RVA: 0x0018A9F4 File Offset: 0x00188BF4
	public void OnPointerUp(PointerEventData eventData)
	{
		if (Links.x.mk)
		{
			EventSystem.current.SetSelectedGameObject(null);
		}
		if (this.inWindow && !this.isEquipped)
		{
			if (!this.clickedDown)
			{
				return;
			}
			if (this.inSpellMenu && Links.x.spellcrafting.open)
			{
				return;
			}
			if (Input.GetMouseButton(1) || Input.GetMouseButtonUp(1))
			{
				return;
			}
			if (!this.character.IsSentient())
			{
				return;
			}
			if (this.character.IsSentient())
			{
				this.ChooseSkill();
			}
		}
	}

	// Token: 0x06001460 RID: 5216 RVA: 0x0018AA80 File Offset: 0x00188C80
	public void StartSkill()
	{
		if (!this.inWindow)
		{
			return;
		}
		if (this.character.actions)
		{
			if (this.character.actions.cannotInterrupt)
			{
				this.character.actions.TryingToInterruptInventoryWait();
				return;
			}
			if (this.character.actions.instrumentCoroutine != null)
			{
				this.str.Clear();
				this.str.Append(Links.x.gameFeed.GetPartyColorText(this.character));
				this.str.Append(this.character.stats.GetName());
				this.str.Append("</color>");
				this.str.Append(" is still playing song");
				Links.x.gameFeed.AddFeed(this.str.ToString());
				return;
			}
		}
		if (!this.abilityRow._IsSpell)
		{
			return;
		}
		if (this.difficulty.gameObject.activeSelf)
		{
			return;
		}
		if (!this.character.CanAttack())
		{
			return;
		}
		if (!this.character.actions && this.canUse)
		{
			Links.x.combat.GivePartyActions(this.character, false);
			Links.x.gameplay.combatStartedWithSkill = true;
		}
		if (this.isInstrument)
		{
			if (!Records.x.InCombat(false) && this.abilityRow._WeaponReq == "Pipe")
			{
				Links.x.gameFeed.ShowNotice("Cannot summon outside of combat");
				return;
			}
			this.character.actions.StartSong(this.abilityRow, false);
			Links.x.pocketWheel.Close(true);
			return;
		}
		else
		{
			if (!this.canUse)
			{
				return;
			}
			this.character.portrait.skillBag.RemoveSelectedButton();
			if (Links.x.gameplay.spellTargetingGround || Links.x.gameplay.charming)
			{
				Links.x.gameplay.RemoveAbilityInfo();
			}
			this.character.portrait.skillBag.selectedSkillButton = this;
			this.selected = true;
			if (!Records.x.pocketPause && this.character.mainSelected)
			{
				Links.x.gameplay.PocketPause(true);
			}
			Links.x.gameplay.actionCharacter = this.character;
			Links.x.gameplay.currentAbility = this.abilityRow._Name;
			this.character.actions.spellIndex = this.index;
			this.character.actions.paganRow = this.paganRow;
			Links.x.gameplay.spellPaganRow = this.paganRow;
			Links.x.gameplay.spellcasting = true;
			Links.x.gameplay.throwingElixir = false;
			if (this.abilityRow._RadiusCenter == "Mouse")
			{
				Links.x.gameplay.RemoveSpellTargets();
				Links.x.gameplay.spellTargetingGround = true;
				int num = 1;
				Vector4 abilityLevel = this.character.stats.GetAbilityLevel(this.index);
				if (this.paganRow._Slider1 == "Radius")
				{
					num = (int)abilityLevel.x;
				}
				else if (this.paganRow._Slider2 == "Radius")
				{
					num = (int)abilityLevel.y;
				}
				else if (this.paganRow._Slider3 == "Radius")
				{
					num = (int)abilityLevel.z;
				}
				Links.x.gameplay.tileEffectRadius = num;
				if (Links.x.joy)
				{
					Links.x.gameplay.waitingForActionUp = true;
					Links.x.gameplay.StartControllerTargeting();
				}
				Links.x.gameplay.SetPartyColliders(false);
			}
			else if (this.abilityRow._RadiusCenter.Contains("TargetParty"))
			{
				Links.x.gameplay.RemoveSpellTargets();
				if (Links.x.joy)
				{
					Links.x.gameplay.waitingForActionUp = true;
					Links.x.gameplay.EndControllerTargeting();
				}
				Links.x.gameplay.spellTargetingParty = true;
				Shader.SetGlobalFloat("_TargetingParty", 1f);
				Links.x.gameplay.SetPartyColliders(true);
			}
			else if (this.abilityRow._RadiusCenter.Contains("TargetEnemy"))
			{
				Links.x.gameplay.RemoveSpellTargets();
				if (Links.x.joy)
				{
					Links.x.gameplay.waitingForActionUp = true;
					Links.x.gameplay.EndControllerTargeting();
				}
				Links.x.gameplay.spellTargetingEnemy = true;
				Links.x.gameplay.SetPartyColliders(false);
			}
			else
			{
				Links.x.gameplay.spellTargetingGround = false;
				if (Links.x.joy)
				{
					Links.x.gameplay.EndControllerTargeting();
				}
			}
			EventSystem.current.SetSelectedGameObject(null);
			if (this.character.mainSelected)
			{
				if (Links.x.combat.pickingRally)
				{
					Links.x.main.portrait.AnimatorSynergyDone();
					Links.x.combat.rallyCharacter.portrait.AnimatorSynergyDone();
				}
				Links.x.combat.pickingRally = false;
				Shader.SetGlobalFloat("_Combat", 1f);
				Links.x.combat.GetTargets(false, false, null);
				Links.x.gameplay.SetDomeSize();
				if (Links.x.pocketWheel.open && this.character.attackTime >= 1f && Links.x.joy)
				{
					Links.x.pocketWheel.WaitForTargets();
				}
			}
			this.character.portrait.skillBag.PlayFX(base.gameObject, this.isSpell);
			if ((this.isInstrument || this.character.portrait.skillBag.selectedSkillButton == this) && !this.inSpellMenu && !Links.x.gameplay.spellcasting)
			{
				base.StartCoroutine(this.DelayedRemoveOutline());
				return;
			}
			return;
		}
	}

	// Token: 0x06001461 RID: 5217 RVA: 0x0018B0D4 File Offset: 0x001892D4
	public void SetActionAbility()
	{
		this.character.actions.spellIndex = this.index;
		this.character.actions.paganRow = this.paganRow;
		this.character.actions.Ability(this.abilityName, this.uniqueName, false, false);
		if (this.slowedTime)
		{
			Links.x.combat.EndSlowTime();
		}
	}

	// Token: 0x06001462 RID: 5218 RVA: 0x0018B142 File Offset: 0x00189342
	private IEnumerator DelayedRemoveOutline()
	{
		yield return new WaitForSeconds(0.5f);
		this.RemoveOutline();
		yield break;
	}

	// Token: 0x06001463 RID: 5219 RVA: 0x0018B154 File Offset: 0x00189354
	public void ChooseSkill()
	{
		if (!this.inWindow)
		{
			return;
		}
		if (this == this.character.portrait.skillBag.selectedSkillButton && !this.isInstrument)
		{
			Links.x.gameplay.RemoveAbilityInfo();
			if (this.character.actions && this.character.actions.spellCasterFX)
			{
				Links.x.cellar.ReturnPooledGameObject(69, this.character.actions.spellCasterFX);
			}
			return;
		}
		this.StartSkill();
	}

	// Token: 0x06001464 RID: 5220 RVA: 0x0018B1F0 File Offset: 0x001893F0
	public void OpenDeleteConfirm()
	{
		if (Links.x.characterSheet.open)
		{
			Links.x.characterSheet.booksMenu.OpenSpellDelete(this.uniqueName);
			return;
		}
		Links.x.spellcrafting.OpenSpellDelete(this.uniqueName);
	}

	// Token: 0x06001465 RID: 5221 RVA: 0x0018B23E File Offset: 0x0018943E
	public void CloseDeleteConfirm()
	{
		if (Links.x.characterSheet.open)
		{
			Links.x.characterSheet.booksMenu.CloseSpellDelete();
			return;
		}
		Links.x.spellcrafting.CloseSpellDelete();
	}

	// Token: 0x040022D2 RID: 8914
	[Header("ABILITY INFO")]
	public string abilityName;

	// Token: 0x040022D3 RID: 8915
	public string uniqueName;

	// Token: 0x040022D4 RID: 8916
	public int index;

	// Token: 0x040022D5 RID: 8917
	public int componentID = -1;

	// Token: 0x040022D6 RID: 8918
	public float abilityCost;

	// Token: 0x040022D7 RID: 8919
	public bool forSale;

	// Token: 0x040022D8 RID: 8920
	public bool isSpell;

	// Token: 0x040022D9 RID: 8921
	public bool canUse;

	// Token: 0x040022DA RID: 8922
	public bool selected;

	// Token: 0x040022DB RID: 8923
	public bool isInstrument;

	// Token: 0x040022DC RID: 8924
	public bool isEquipped;

	// Token: 0x040022DD RID: 8925
	public bool inSpellMenu;

	// Token: 0x040022DE RID: 8926
	public bool inWindow;

	// Token: 0x040022DF RID: 8927
	public bool canBuy;

	// Token: 0x040022E0 RID: 8928
	public Library.Abilities abilityRow;

	// Token: 0x040022E1 RID: 8929
	private Library.Effects effectRow;

	// Token: 0x040022E2 RID: 8930
	private Library.Pagan paganRow;

	// Token: 0x040022E3 RID: 8931
	public Vector4 spellStats;

	// Token: 0x040022E4 RID: 8932
	private string header;

	// Token: 0x040022E5 RID: 8933
	private string desc;

	// Token: 0x040022E6 RID: 8934
	private string spellDesc;

	// Token: 0x040022E7 RID: 8935
	public Material spellMat1;

	// Token: 0x040022E8 RID: 8936
	public Material spellMat2;

	// Token: 0x040022E9 RID: 8937
	public Material spellMat3;

	// Token: 0x040022EA RID: 8938
	public Material spellMat4;

	// Token: 0x040022EB RID: 8939
	public Material songMat;

	// Token: 0x040022EC RID: 8940
	[Header("LINKS")]
	public TextMeshProUGUI nameText;

	// Token: 0x040022ED RID: 8941
	public TextMeshProUGUI triggerReadyText;

	// Token: 0x040022EE RID: 8942
	public Image triggerBackground;

	// Token: 0x040022EF RID: 8943
	public Image iconBG;

	// Token: 0x040022F0 RID: 8944
	public Image border;

	// Token: 0x040022F1 RID: 8945
	public Image difficulty;

	// Token: 0x040022F2 RID: 8946
	public Image spirit;

	// Token: 0x040022F3 RID: 8947
	public RectTransform rt;

	// Token: 0x040022F4 RID: 8948
	public Button button;

	// Token: 0x040022F5 RID: 8949
	public Button delete;

	// Token: 0x040022F6 RID: 8950
	public Character character;

	// Token: 0x040022F7 RID: 8951
	private StringFast str = new StringFast(64);

	// Token: 0x040022F8 RID: 8952
	private List<TileEffects> currentTileEffects;

	// Token: 0x040022F9 RID: 8953
	public GameObject deleteButton;

	// Token: 0x040022FA RID: 8954
	public RectTransform nameTextRT;

	// Token: 0x040022FB RID: 8955
	private bool slowedTime;

	// Token: 0x040022FC RID: 8956
	private bool updateDescOnEnable;

	// Token: 0x040022FD RID: 8957
	[Header("GRAPHICS & SOUNDS")]
	public Sprite empty;

	// Token: 0x040022FE RID: 8958
	public Color faunaSchool;

	// Token: 0x040022FF RID: 8959
	public Color vinesSchool;

	// Token: 0x04002300 RID: 8960
	public Color scoriaSchool;

	// Token: 0x04002301 RID: 8961
	public Color fluteColor;

	// Token: 0x04002302 RID: 8962
	public Color drumColor;

	// Token: 0x04002303 RID: 8963
	public Color hornColor;

	// Token: 0x04002304 RID: 8964
	public Color pipeColor;

	// Token: 0x04002305 RID: 8965
	public Color defenseColor;

	// Token: 0x04002306 RID: 8966
	public Color rangeColor;

	// Token: 0x04002307 RID: 8967
	public Color meleeColor;

	// Token: 0x04002308 RID: 8968
	public Color triggerNotReady;

	// Token: 0x04002309 RID: 8969
	public string halfText;

	// Token: 0x0400230A RID: 8970
	public string fullText;

	// Token: 0x0400230B RID: 8971
	public string readyText;

	// Token: 0x0400230C RID: 8972
	public string soundName = "Clicks Stone B";

	// Token: 0x0400230D RID: 8973
	private bool clickedDown;

	// Token: 0x0400230E RID: 8974
	public Sprite songBack;

	// Token: 0x0400230F RID: 8975
	public Color spellColor;

	// Token: 0x04002310 RID: 8976
	public Color songColor;

	// Token: 0x04002311 RID: 8977
	public Material songMaterial;

	// Token: 0x04002312 RID: 8978
	public Material spellMaterial;

	// Token: 0x04002313 RID: 8979
	public GameObject star;
}
