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

// Token: 0x020000B5 RID: 181
public class Item : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler
{
	// Token: 0x06001140 RID: 4416 RVA: 0x00151BFA File Offset: 0x0014FDFA
	private void Start()
	{
		this.tr = base.transform;
		this.img = this.tr.gameObject.GetComponent<Image>();
	}

	// Token: 0x06001141 RID: 4417 RVA: 0x00151C1E File Offset: 0x0014FE1E
	public void Use()
	{
	}

	// Token: 0x06001142 RID: 4418 RVA: 0x00151C20 File Offset: 0x0014FE20
	public void SetDayNight(bool state)
	{
		if (state)
		{
			this.clickable = true;
			foreach (MeshRenderer meshRenderer in this.renderers)
			{
				if (this.useSprite)
				{
					this.sprite.enabled = true;
				}
				else
				{
					meshRenderer.enabled = true;
				}
			}
			using (List<BoxCollider>.Enumerator enumerator2 = this.colliders.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					BoxCollider boxCollider = enumerator2.Current;
					boxCollider.enabled = true;
				}
				return;
			}
		}
		this.clickable = false;
		foreach (MeshRenderer meshRenderer2 in this.renderers)
		{
			if (this.useSprite)
			{
				this.sprite.enabled = false;
			}
			else
			{
				meshRenderer2.enabled = false;
			}
		}
		foreach (BoxCollider boxCollider2 in this.colliders)
		{
			boxCollider2.enabled = false;
		}
		Links.x.inventory.groundBag.RemovePopItem(this);
		Links.x.inventory.groundBag.HitScreenItem(this, false);
		this.OutOfRange();
	}

	// Token: 0x06001143 RID: 4419 RVA: 0x00151DAC File Offset: 0x0014FFAC
	public void SetSprite(bool isDragging)
	{
		if (!this.rt)
		{
			this.rt = base.gameObject.GetComponent<RectTransform>();
		}
		if (isDragging)
		{
			this.img.sprite = this.fullSprite;
			this.img.SetNativeSize();
		}
		else if (this.isEquipped || this.inGroundMenu || (Links.x.inventory.hoveringOverEquipmentSlot && Links.x.joy && Links.x.inventory.dragging && !Links.x.gameplay.actionStart))
		{
			this.img.sprite = this.maskedSprite;
			this.img.SetNativeSize();
		}
		else
		{
			this.img.sprite = this.fullSprite;
			this.img.SetNativeSize();
		}
		if (this.inGroundMenu && !isDragging)
		{
			base.gameObject.transform.localScale = new Vector3(1f, 1f, 1f);
			this.stack.gameObject.transform.localScale = new Vector3(1f, 1f, 1f);
			this.stack.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(19f, 19f, 0f);
			if (this.img.enabled && !isDragging && this.backImage)
			{
				this.backImage.enabled = true;
				return;
			}
		}
		else
		{
			if (!isDragging && (this.isEquipped || this.inGroundMenu || (Links.x.inventory.hoveringOverEquipmentSlot && Links.x.joy && Links.x.inventory.dragging && !Links.x.gameplay.actionStart)))
			{
				base.gameObject.transform.localScale = new Vector3(0.22f, 0.22f, 0.22f);
				this.stack.gameObject.transform.localScale = new Vector3(5.5f, 5.5f, 5.5f);
				this.stack.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(19f, 19f, 0f);
				return;
			}
			base.gameObject.transform.localScale = new Vector3(0.14f, 0.14f, 0.14f);
			this.stack.gameObject.transform.localScale = new Vector3(7f, 7f, 7f);
			this.stack.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector3(19f * (float)this.invRow._SizeY, 19f * (float)this.invRow._SizeX, 0f);
		}
	}

	// Token: 0x06001144 RID: 4420 RVA: 0x001520B4 File Offset: 0x001502B4
	public void Reset()
	{
		if (this.inRangeFX)
		{
			Links.x.cellar.ReturnPooledGameObject(33, this.inRangeFX);
		}
		this.inRangeFX = null;
		this.equipSlot = -1;
		this.stackable = false;
		this.itemTag = "";
		this.bag = null;
		this.closeEnoughToPickup = false;
		this.onGround = false;
		this.inGroundMenu = false;
		this.worldItem = null;
		this.socketA = new Vector3(-1f, -1f, -1f);
		this.socketB = new Vector3(-1f, -1f, -1f);
		this.forSale = false;
		this.bagGridID = -1;
		this.active = false;
		this.inRange = false;
		this.onList = false;
		this.dropNode = null;
		this.isEquipped = false;
		this.sceneItemName = "";
		this.clickCoroutine = null;
		this.noDrag = false;
		if (this.gridImg != null)
		{
			this.gridImg.Clear();
		}
		this.linkedCreatures = null;
		this.linkedCharacter = null;
		if (this.img)
		{
			this.img.enabled = true;
		}
	}

	// Token: 0x06001145 RID: 4421 RVA: 0x001521E0 File Offset: 0x001503E0
	public void StartGround(GraphNode graphNode, GraphNode bigTileNode)
	{
		if (!this.tr)
		{
			this.tr = base.transform;
		}
		base.gameObject.layer = 11;
		this.onGround = true;
		if (this.invRow._Tag.Contains("Consum"))
		{
			this.edible = true;
		}
		if (this.invRow._Tag.Contains("Spell"))
		{
			this.spellItem = true;
		}
		if (this.invRow._Tag.Contains("Ammunition"))
		{
			this.ammo = true;
		}
		if (this.equipSlot < 0 && this.ID == Links.x.library.bombID)
		{
			this.alwaysRefill = true;
		}
		this.dropNode = graphNode;
		this.colliders = new List<BoxCollider>();
		BoxCollider boxCollider = base.gameObject.GetComponent<BoxCollider>();
		float num;
		if (boxCollider)
		{
			this.colliders.Add(boxCollider);
			num = boxCollider.size.y * this.tr.localScale.y;
		}
		else
		{
			boxCollider = base.gameObject.AddComponent<BoxCollider>();
			this.colliders.Add(boxCollider);
			num = boxCollider.size.y * this.tr.localScale.y;
		}
		this.renderers = new List<MeshRenderer>();
		foreach (object obj in this.tr)
		{
			Transform transform = (Transform)obj;
			boxCollider = transform.gameObject.GetComponent<BoxCollider>();
			if (boxCollider)
			{
				this.colliders.Add(boxCollider);
				if (num < boxCollider.size.y * transform.localScale.y)
				{
					num = boxCollider.size.y * transform.localScale.y;
				}
			}
			transform.gameObject.layer = 11;
			MeshRenderer component = transform.gameObject.GetComponent<MeshRenderer>();
			if (component)
			{
				if (!this.renderers.Contains(component))
				{
					this.renderers.Add(component);
					if (!this.forSale)
					{
						this.SetDurabilityVisual(component);
					}
				}
				component.sharedMaterial = Links.x.itemGroundMaterial;
			}
		}
		MeshRenderer component2 = base.gameObject.GetComponent<MeshRenderer>();
		if (component2 && !this.renderers.Contains(component2))
		{
			this.renderers.Add(component2);
			this.SetDurabilityVisual(component2);
		}
		Links.x.inventory.groundBag.UpdateGroundList(this, true);
		if (this.dropNode != null)
		{
			this.dropNode.item = 1;
		}
		if (Links.x.gaia.sceneLoaded && !this.forSale)
		{
			MasterAudio.PlaySoundAndForget("Inventory", 0.5f, new float?(1f), 0f, this.invRow._Sound, null);
			if (!Records.x.inMenus)
			{
				Links.x.gameplay.StartHoverTimer(this);
			}
		}
		this.tr.rotation = Quaternion.Euler(Vector3.zero);
		this.useSprite = true;
		if (this.useSprite)
		{
			base.gameObject.transform.rotation = Quaternion.Euler(Vector3.zero);
			if (this.tr.childCount > 0)
			{
				this.sprite = this.tr.GetChild(0).gameObject.GetComponent<SpriteRenderer>();
			}
			if (!this.sprite)
			{
				GameObject gameObject = new GameObject("Sprite");
				gameObject.transform.SetParent(this.tr, false);
				gameObject.transform.localPosition = new Vector3(0f, 0.3f, 0f);
				gameObject.transform.localRotation = Quaternion.Euler(Vector3.zero);
				gameObject.transform.localScale = new Vector3(0.95f, 0.95f, 0.95f);
				this.sprite = gameObject.AddComponent<SpriteRenderer>();
				boxCollider.center = new Vector3(0f, 0.05f, 0f);
				boxCollider.size = new Vector3(1f, 1f, 1f);
			}
			Records.x.AddBillboard(this.tr.GetChild(0), true);
			this.sprite.sprite = Links.x.archives.GetItem(this.invRow._UIModel);
			this.sprite.material = Links.x.groundItemSprite;
			this.sprite.gameObject.layer = 11;
			foreach (MeshRenderer meshRenderer in this.renderers)
			{
				meshRenderer.enabled = false;
			}
		}
		this.active = true;
		this.SetDayNight(true);
	}

	// Token: 0x06001146 RID: 4422 RVA: 0x001526E4 File Offset: 0x001508E4
	public void SetDurabilityVisual(MeshRenderer r)
	{
		if (!this.forSale && !this.onGround && r)
		{
			if (this.invRow._DurabilityMax > 0 && !this.invRow._Name.Contains("Torch"))
			{
				if (this.durability.x < (float)Records.x.durabilityThreshold)
				{
					r.material.SetFloat("_Glow", 1f);
				}
				else
				{
					r.material.SetFloat("_Glow", 0f);
				}
			}
			if (this.invRow._Life > 0)
			{
				int num = (int)this.durability.x - (int)Mathf.Floor((float)Links.x.gameplay.GetCurrentGameTimeHours());
				if (!this.invRow._Effect.Contains("Cure"))
				{
					if (num <= 10)
					{
						r.material.SetFloat("_Glow", 1f);
					}
					else
					{
						r.material.SetFloat("_Glow", 0f);
					}
				}
			}
			if (this.socketA.x > 0f && (this.invRow._Tag == "Weapon" || this.invRow._Tag == "Jewelry"))
			{
				r.material.SetFloat("_Sparkle", 1f);
				return;
			}
			r.material.SetFloat("_Sparkle", 0f);
		}
	}

	// Token: 0x06001147 RID: 4423 RVA: 0x00152860 File Offset: 0x00150A60
	public void SetDurabilityVisual()
	{
		if (!this.forSale && !this.onGround)
		{
			if (!this.img)
			{
				this.img = this.tr.gameObject.GetComponent<Image>();
			}
			if (this.img)
			{
				this.img.material = Links.x.inventory.inventoryItemMaterial;
				bool flag = false;
				if (this.socketA.x > 0f && (this.invRow._Tag == "Weapon" || this.invRow._Tag == "Jewelry"))
				{
					flag = true;
				}
				if (this.invRow._DurabilityMax > 0 && !this.invRow._Name.Contains("Torch"))
				{
					if (this.durability.x <= (float)Records.x.durabilityThreshold)
					{
						if (this.durability.x <= 0f)
						{
							this.img.material = Links.x.inventory.inventoryItemBrokenMaterial;
							if (flag)
							{
								this.img.material = Links.x.inventory.inventoryItemMagicBrokenMaterial;
							}
						}
						else
						{
							this.img.material = Links.x.inventory.inventoryItemLowDurabilityMaterial;
							if (flag)
							{
								this.img.material = Links.x.inventory.inventoryItemMagicLowDurabilityMaterial;
							}
						}
					}
					else if (flag)
					{
						this.img.material = Links.x.inventory.inventoryItemMagic;
					}
					else
					{
						this.img.material = Links.x.inventory.inventoryItemMaterial;
					}
				}
				if (this.invRow._Life > 0)
				{
					if ((int)this.durability.x - (int)Mathf.Floor((float)Links.x.gameplay.GetCurrentGameTimeHours()) <= 10 && !this.invRow._Effect.Contains("Cure"))
					{
						this.img.material = Links.x.inventory.inventoryItemLowDurabilityMaterial;
						return;
					}
					this.img.material = Links.x.inventory.inventoryItemMaterial;
				}
			}
		}
	}

	// Token: 0x06001148 RID: 4424 RVA: 0x00152A9C File Offset: 0x00150C9C
	public void SetupLinkedItem()
	{
		PromptActions component = this.linkedPrompt.gameObject.GetComponent<PromptActions>();
		component.AddLinkedItem(this);
		if (component.state == 1)
		{
			this.active = true;
		}
		else
		{
			this.active = false;
			base.gameObject.SetActive(false);
		}
		if (this.inRangeFX)
		{
			this.OutOfRange();
		}
	}

	// Token: 0x06001149 RID: 4425 RVA: 0x00152AF8 File Offset: 0x00150CF8
	public void CheckStackSize()
	{
		if (this.stack)
		{
			if (this.stackSize > 0 && this.stackable)
			{
				this.stack.SetActive(true);
				this.stackText.text = this.stackSize.ToString();
				this.stackText.enabled = true;
			}
			else
			{
				this.stack.SetActive(false);
			}
		}
		this.SetDurabilityVisual();
	}

	// Token: 0x0600114A RID: 4426 RVA: 0x00152B68 File Offset: 0x00150D68
	public void ToggleSocket(bool state)
	{
		for (int i = 0; i < this.socketImg.Count; i++)
		{
			if (this.socketImg[i] && this.socketFill[i].enabled)
			{
				this.socketImg[i].gameObject.SetActive(state);
			}
		}
	}

	// Token: 0x0600114B RID: 4427 RVA: 0x00152BC8 File Offset: 0x00150DC8
	public Image GetBackImage()
	{
		if (!this.backImage)
		{
			this.backImage = Links.x.cellar.GetImage(0);
		}
		return this.backImage;
	}

	// Token: 0x0600114C RID: 4428 RVA: 0x00152BF4 File Offset: 0x00150DF4
	public void DestroyItem(bool updateLists, bool removingScene)
	{
		this.active = false;
		int num = -1;
		if (this.bag)
		{
			num = this.bag.ItemIndex(this);
		}
		for (int i = 0; i < this.socketImg.Count; i++)
		{
			if (this.socketImg[i] && this.socketImg[i].transform.parent == this.tr)
			{
				this.socketImg[i].transform.SetParent(Links.x.cellar.tr, false);
				this.socketFill[i].enabled = false;
				this.socketImg[i].SetActive(false);
				if (this.invRow._Tag.Contains("Armor"))
				{
					Links.x.cellar.ReturnSocket(this.socketImg[i], "Repair");
				}
				else
				{
					Links.x.cellar.ReturnSocket(this.socketImg[i], "");
				}
			}
		}
		if (Links.x.inventory.hitItem == this)
		{
			Links.x.inventory.itemInfo.EndMenu();
		}
		if (this.bracket)
		{
			Links.x.cellar.ReturnPooledGameObject(61, this.bracket);
			this.bracket = null;
		}
		this.socketImg.Clear();
		this.socketFill.Clear();
		if (this.onGround)
		{
			this.OutOfRange();
		}
		this.inRange = false;
		if (!this.onGround)
		{
			Links.x.inventory.RemoveItemSlots(this, true);
		}
		if (this.stack)
		{
			this.stack.SetActive(false);
		}
		if (updateLists && !removingScene && num > -1)
		{
			this.bag.character.UpdateInvLists("BagRemove", num, 0, 0, Vector4.zero, new Vector3(-1f, -1f, -1f), new Vector3(-1f, -1f, -1f), null);
		}
		if (this.onGround)
		{
			if (this.useSprite)
			{
				Records.x.RemoveBillboard(this.tr.GetChild(0), true);
			}
			if (this.dropNode != null && !removingScene)
			{
				this.dropNode.item = 0;
			}
			Links.x.inventory.groundBag.HitItem(this, false);
			Links.x.inventory.groundBag.HoverItems(this, false);
			Links.x.inventory.groundBag.RemovePopItem(this);
			Links.x.inventory.groundBag.HitScreenItem(this, false);
			if (!removingScene)
			{
				Links.x.inventory.groundBag.UpdateGroundList(this, false);
			}
			Links.x.archives.RecycleItem(base.gameObject, "None");
			base.gameObject.SetActive(false);
		}
		else
		{
			Links.x.cellar.ReturnItem(this);
			this.active = false;
			base.gameObject.SetActive(false);
		}
		if (this.backImage)
		{
			if (this.bag)
			{
				this.bag.RemoveImage(this.backImage);
			}
			Links.x.cellar.ReturnImage(this.backImage, 0);
		}
		this.active = false;
		this.destroying = false;
	}

	// Token: 0x0600114D RID: 4429 RVA: 0x00152F70 File Offset: 0x00151170
	public void HoverOut()
	{
		if (this.onGround)
		{
			if (Links.x.mk || Links.x.joy)
			{
				Links.x.inventory.groundBag.HoverItems(this, false);
			}
			this.groundHovering = true;
			this.PostFXRenderers(false);
		}
	}

	// Token: 0x0600114E RID: 4430 RVA: 0x00152FC4 File Offset: 0x001511C4
	public void HoverIn()
	{
		if (this.onGround && !Records.x.inMenus)
		{
			this.groundHovering = false;
			if (Links.x.mk || Links.x.joy)
			{
				Links.x.inventory.groundBag.HoverItems(this, true);
			}
			this.PostFXRenderers(true);
		}
	}

	// Token: 0x0600114F RID: 4431 RVA: 0x00153021 File Offset: 0x00151221
	public void MovingTo()
	{
		this.movingTo = true;
		this.HoverIn();
	}

	// Token: 0x06001150 RID: 4432 RVA: 0x00153030 File Offset: 0x00151230
	public void StopMovingTo()
	{
		this.movingTo = false;
		this.HoverOut();
	}

	// Token: 0x06001151 RID: 4433 RVA: 0x00153040 File Offset: 0x00151240
	public void PostFXRenderers(bool state)
	{
		if (this.useSprite)
		{
			if (state)
			{
				Shader.SetGlobalFloat("_HoveringOnItem", 1f);
			}
			else if (!Links.x.inventory.groundBag.toggle)
			{
				Shader.SetGlobalFloat("_HoveringOnItem", 0f);
			}
			int num = 0;
			this.GetLinkedCharacter();
			if (this.linkedCharacter && !this.forSale)
			{
				num = 1;
			}
			if (state)
			{
				if (this.active)
				{
					Links.x.hoverObject = base.gameObject;
					Shader.SetGlobalVector("_DoorLightPosition", this.bounds.center + Links.x.rtsCamera.gameObject.transform.forward * -2f);
					Records.x.hoverLightColor = Color.white * 0.25f;
					Shader.SetGlobalFloat("_DoorLightRange", 2f);
					this.bounds = this.sprite.bounds;
					if (!this.bracket)
					{
						this.bracket = Links.x.cellar.GetBracket(num, this.bounds);
					}
					else
					{
						Links.x.cellar.SetBracketMaterial(num, this.bracket);
					}
				}
			}
			else
			{
				if (this.bracket)
				{
					Links.x.cellar.ReturnPooledGameObject(61, this.bracket);
					this.bracket = null;
				}
				if (Links.x.hoverObject == base.gameObject)
				{
					Links.x.hoverObject = null;
				}
			}
			if (this.renderers != null)
			{
				for (int i = 0; i < this.renderers.Count; i++)
				{
					if (state)
					{
						this.HoverInWorld();
					}
					else
					{
						this.HoverOutWorld();
					}
				}
			}
		}
		else if (this.renderers != null)
		{
			for (int j = 0; j < this.renderers.Count; j++)
			{
				if (state)
				{
					this.HoverInWorld();
				}
				else
				{
					this.HoverOutWorld();
				}
			}
		}
		if (state)
		{
			this.GetLinkedCharacter();
			if (this.linkedCharacter)
			{
				Links.x.hudControl.OpenTooltip(this, this.forSale);
				return;
			}
		}
		else
		{
			Links.x.hudControl.CloseTooltip();
		}
	}

	// Token: 0x06001152 RID: 4434 RVA: 0x00153278 File Offset: 0x00151478
	public void HoverInWorld()
	{
		if (this.active && this.useSprite)
		{
			this.sprite.material = Links.x.groundItemSpriteHover;
		}
	}

	// Token: 0x06001153 RID: 4435 RVA: 0x0015329F File Offset: 0x0015149F
	public void HoverOutWorld()
	{
		if (this.useSprite)
		{
			if (this.inRange)
			{
				this.sprite.material = Links.x.groundItemSpriteInRange;
				return;
			}
			this.sprite.material = Links.x.groundItemSprite;
		}
	}

	// Token: 0x06001154 RID: 4436 RVA: 0x001532DC File Offset: 0x001514DC
	public bool CheckToSteal(bool clicking)
	{
		bool flag = true;
		if (!Links.x.hasMain)
		{
			return false;
		}
		if (!Links.x.main.body.sneaking)
		{
			return false;
		}
		if (this.linkedCharacter && this.linkedCreatures)
		{
			flag = true;
			if (!this.CanSteal(this.linkedCharacter, clicking))
			{
				flag = false;
			}
			if (!flag)
			{
				goto IL_011A;
			}
			Transform parent = this.linkedCreatures.transform.parent;
			if (!parent || !(parent.gameObject != Links.x.diorama.creatures.gameObject))
			{
				goto IL_011A;
			}
			using (IEnumerator enumerator = parent.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					object obj = enumerator.Current;
					CreatureActions component = ((Transform)obj).gameObject.GetComponent<CreatureActions>();
					if (component && component != this.linkedCreatures)
					{
						Character firstCharacter = component.GetFirstCharacter();
						if (firstCharacter && firstCharacter.IsSentient() && !this.CanSteal(firstCharacter, clicking))
						{
							flag = false;
						}
					}
				}
				goto IL_011A;
			}
		}
		flag = false;
		IL_011A:
		if (flag && clicking)
		{
			Links.x.gameFeed.AddFeed(Links.x.gameFeed.GetPartyColorText(Links.x.main) + Links.x.main.stats.GetName() + "</color> stole " + this.invRow._DisplayName);
			this.linkedCreatures = null;
			Links.x.diorama.SetOriginalSceneItemLink(this.sceneItemName, null);
			this.forSale = false;
		}
		return flag;
	}

	// Token: 0x06001155 RID: 4437 RVA: 0x00153490 File Offset: 0x00151690
	private bool CanSteal(Character checkCharacter, bool clicking)
	{
		Character main = Links.x.main;
		bool flag = false;
		if (main.body.sneaking)
		{
			flag = true;
			Vector3 position = this.tr.position;
			position.y = main.raycastPosition.y;
			if (checkCharacter.node.Area == main.node.Area && Links.x.sensory.InAngleView(position, checkCharacter))
			{
				flag = false;
				if (Physics.Linecast(position, checkCharacter.raycastPosition, Links.x.sightBlockers))
				{
					flag = true;
				}
			}
			bool flag2 = flag;
			if (flag)
			{
				float num = Links.x.main.stats.Stealing();
				float num2 = checkCharacter.stats.HearStealing();
				flag = num >= num2;
			}
			if (flag)
			{
				if (clicking)
				{
					this.str.Clear();
					this.str.Append(Links.x.gameFeed.GetPartyColorText(main));
					this.str.Append(main.stats.GetName());
					this.str.Append("</color>");
					this.str.Append("'s stealth was better than ");
					this.str.Append(checkCharacter.stats.GetName());
					this.str.Append("'s hearing");
					if (Records.x.showRulesetInfo)
					{
						string text = main.stats.StealingCalculation(false);
						string text2 = checkCharacter.stats.HearStealing().ToString();
						this.str.Append(" <color #857C6C>... ");
						this.str.Append(text);
						this.str.Append(" vs. ");
						this.str.Append(text2);
						this.str.Append("</color>");
					}
					Links.x.gameFeed.AddFeed(this.str.ToString());
					main.stats.AddSkillProgress(21, checkCharacter.stats.HearStealing(), null);
				}
			}
			else if (clicking)
			{
				if (!Links.x.main.InSporeForest())
				{
					Records.x.AddBribeBadge(checkCharacter, "Seen", false, main);
				}
				if (flag2)
				{
					Links.x.gameFeed.AddFeed(checkCharacter.stats.GetName() + " heard an item move!");
				}
				else
				{
					Links.x.gameFeed.AddFeed(checkCharacter.stats.GetName() + " saw an item move!");
				}
				this.AlertOwner(true, main, checkCharacter);
				if (Records.x.showRulesetInfo)
				{
					this.str.Clear();
					this.str.Append(Links.x.gameFeed.GetPartyColorText(main));
					this.str.Append(main.stats.GetName());
					this.str.Append("</color>");
					this.str.Append(" could not steal without being heard ");
					string text3 = main.stats.StealingCalculation(false);
					string text4 = checkCharacter.stats.HearStealing().ToString();
					this.str.Append(" <color #857C6C>... ");
					this.str.Append(text3);
					this.str.Append(" vs. ");
					this.str.Append(checkCharacter.stats.GetName());
					this.str.Append("'s ");
					this.str.Append(text4);
					this.str.Append("</color>");
				}
				Links.x.gameFeed.AddFeed(this.str.ToString());
			}
		}
		return flag;
	}

	// Token: 0x06001156 RID: 4438 RVA: 0x00153848 File Offset: 0x00151A48
	public void AlertOwner(bool madeNoise, Character character, Character owner)
	{
		bool flag = false;
		if (!owner.stunned && !owner.dead && (!owner.sleeping || madeNoise) && (owner.tr.position - character.tr.position).sqrMagnitude < owner.stats.SightRadius(false, false, false) * owner.stats.SightRadius(false, false, false) && !Physics.Linecast(owner.raycastPosition, character.raycastPosition, Links.x.sightBlockers))
		{
			if (owner.sleeping)
			{
				owner.WakeUp();
			}
			if (!Links.x.main.InSporeForest())
			{
				Records.x.AddBribeBadge(owner, "Seen", false, character);
			}
			Links.x.sensory.AddPlayerFromDamage(owner, Links.x.main);
			flag = true;
		}
		Character character2;
		int num;
		if (!flag && Links.x.sensory.NonHostileAttacked(null, base.gameObject.transform.position, character, false, madeNoise, out character2, out num) == 0 && !Records.x.InCombat(false) && num == 0)
		{
			character.StartQuip("That was lucky");
		}
	}

	// Token: 0x06001157 RID: 4439 RVA: 0x00153974 File Offset: 0x00151B74
	public void GetLinkedCharacter()
	{
		if (!this.linkedCreatures)
		{
			return;
		}
		this.linkedCharacter = null;
		if (this.linkedCreatureID == 0)
		{
			CreatureActions component = this.linkedCreatures.GetComponent<CreatureActions>();
			if (component)
			{
				this.linkedCharacter = component.GetFirstCharacter();
				if (this.linkedCharacter && (this.linkedCharacter.dead || this.linkedCharacter.stunned))
				{
					this.linkedCharacter = null;
				}
			}
		}
		else
		{
			CreatureActions component2 = this.linkedCreatures.GetComponent<CreatureActions>();
			if (component2)
			{
				this.linkedCharacter = component2.GetCharacterAtIndex(this.linkedCreatureID);
			}
			if (this.linkedCharacter && (this.linkedCharacter.dead || this.linkedCharacter.stunned))
			{
				this.linkedCharacter = null;
			}
		}
		if (this.inRangeFX && !this.linkedCharacter && this.inRangeFX.name.Contains("Sale"))
		{
			this.OutOfRange();
			this.InRange();
		}
	}

	// Token: 0x06001158 RID: 4440 RVA: 0x00153A84 File Offset: 0x00151C84
	public float GetCost(bool addSkill, Character party, Character owner)
	{
		float num = Links.x.main.stats.DispositionCost(Links.x.diorama.sceneName, this.linkedCharacter);
		if (addSkill && num < 1f)
		{
			party.stats.AddSkillProgress(22, owner.stats.GetSkill(22) / 10f, null);
		}
		float num2 = (float)this.invRow._BuyPrice;
		if (!this.invRow._NeedFullStack)
		{
			num2 *= (float)this.stackSize;
		}
		if (num < 0f)
		{
			num *= -1f;
			num += 1f;
		}
		num2 *= num;
		return Mathf.Round(num2);
	}

	// Token: 0x06001159 RID: 4441 RVA: 0x00153B30 File Offset: 0x00151D30
	public void ClickedOnItemWithOwner(Character character, out bool stole, out bool pickedUp, out string quip)
	{
		stole = false;
		pickedUp = true;
		quip = "";
		if (!this.forSale)
		{
			Links.x.gameFeed.AddFeed(Links.x.gameFeed.GetPartyColorText(character) + character.stats.GetName() + "</color> picked up " + this.invRow._DisplayName);
			return;
		}
		if (character.body.sneaking)
		{
			if (this.CheckToSteal(true))
			{
				stole = true;
				return;
			}
			pickedUp = false;
			Links.x.main.EndSneak(true, false);
			Character nearestParty = Links.x.GetNearestParty(this.tr.position);
			if (this.linkedCreatures.transform.parent)
			{
				if (this.linkedCreatures)
				{
					this.GetLinkedCharacter();
				}
				Links.x.sensory.AddAllToCombat(this.linkedCharacter, nearestParty, true, false, true);
				return;
			}
		}
		else
		{
			if (this.linkedCreatures)
			{
				this.GetLinkedCharacter();
			}
			float cost = this.GetCost(true, character, this.linkedCharacter);
			if (Links.x.inventory.emeralds >= (int)cost)
			{
				Links.x.inventory.emeralds -= (int)cost;
				Links.x.inventory.groundBag.UpdateLabels();
				if (this.linkedCharacter)
				{
					Links.x.sensory.LookAtObject(character.body.headBone, 15f, false, character, 3f, 0.1f, this.linkedCharacter, 0);
					quip = Records.x.GetRandomMerchantQuip("Purchased");
				}
				Links.x.gameFeed.AddFeed(string.Concat(new string[]
				{
					Links.x.gameFeed.GetPartyColorText(character),
					character.stats.GetName(),
					"</color> purchased ",
					this.invRow._DisplayName,
					" for ",
					cost.ToString(),
					" emeralds"
				}));
				return;
			}
			this.StopMovingTo();
			Links.x.gameFeed.AddFeed("This item is too expensive");
			if (this.linkedCreatures)
			{
				this.GetLinkedCharacter();
				quip = Records.x.GetRandomMerchantQuip("Expensive");
			}
			pickedUp = false;
		}
	}

	// Token: 0x0600115A RID: 4442 RVA: 0x00153D84 File Offset: 0x00151F84
	public void PlayFX()
	{
		MasterAudio.PlaySoundAndForget("Inventory", 0.5f, new float?(1f), 0f, this.invRow._Sound, null);
		this.fx = Links.x.cellar.GetPooledGameObject(16);
		this.fx.transform.position = base.transform.position + new Vector3(0f, 0.5f, 0f);
		this.fx.SetActive(true);
	}

	// Token: 0x0600115B RID: 4443 RVA: 0x00153E1C File Offset: 0x0015201C
	public void Clicked(Character clickCharacter)
	{
		if (base.gameObject.activeInHierarchy && base.gameObject.activeSelf && this.active)
		{
			this.GetLinkedCharacter();
			if (this.clickCoroutine != null)
			{
				return;
			}
			if (!this.destroying)
			{
				this.GetLinkedCharacter();
				bool flag = false;
				bool flag2 = true;
				string text = "";
				if (this.linkedCharacter)
				{
					this.ClickedOnItemWithOwner(clickCharacter, out flag, out flag2, out text);
				}
				if (flag2)
				{
					this.HoverOut();
					this.clickCoroutine = this.ClickedWait(clickCharacter, flag, text);
					base.StartCoroutine(this.clickCoroutine);
				}
			}
		}
	}

	// Token: 0x0600115C RID: 4444 RVA: 0x00153EB1 File Offset: 0x001520B1
	private IEnumerator ClickedWait(Character clickCharacter, bool stole, string quip)
	{
		bool zoomed = false;
		if (this.forSale && !stole)
		{
			float startTime = Time.timeSinceLevelLoad;
			while (clickCharacter.moving && Time.timeSinceLevelLoad < startTime + 1f)
			{
				yield return null;
			}
			clickCharacter.SetRotation(Quaternion.LookRotation(base.gameObject.transform.position - clickCharacter.tr.position), false, true);
			clickCharacter.PlayAnimation("Use", 0f);
			yield return new WaitForSeconds(0.15f);
			Links.x.rtsCamera.Zoom(true, "");
			if (quip != "")
			{
				this.linkedCharacter.StartQuip(quip);
			}
			zoomed = true;
		}
		else
		{
			float startTime = Time.timeSinceLevelLoad;
			if (Records.x.editor || Records.x.secrets)
			{
				Debug.Log("Click waiting for move");
			}
			while (clickCharacter.moving && Time.timeSinceLevelLoad < startTime + 1f)
			{
				yield return null;
			}
			if (Records.x.editor || Records.x.secrets)
			{
				Debug.Log("Click waiting for turning");
			}
			startTime = Time.timeSinceLevelLoad;
			clickCharacter.SetRotation(Quaternion.LookRotation(base.gameObject.transform.position - clickCharacter.tr.position), false, true);
			while (clickCharacter.turning && Time.timeSinceLevelLoad < startTime + 1f)
			{
				yield return null;
			}
			clickCharacter.PlayAnimation("Use", 0f);
			yield return new WaitForSeconds(0.15f);
			if (Records.x.editor || Records.x.secrets)
			{
				Debug.Log("Click waiting");
			}
			if (quip != "")
			{
				this.linkedCharacter.StartQuip(quip);
			}
		}
		while (Links.x.inventory.lookingForSpot)
		{
			yield return null;
		}
		this.active = false;
		if (this.label)
		{
			Links.x.inventory.groundBag.RemoveItemLabel(this.label);
		}
		MasterAudio.PlaySoundAndForget("Inventory", 0.5f, new float?(1f), 0f, this.invRow._Sound, null);
		this.fx = Links.x.cellar.GetPooledGameObject(16);
		this.fx.transform.position = base.transform.position + new Vector3(0f, 0.5f, 0f);
		this.fx.SetActive(true);
		if (this.invRow._Tag == "Emerald")
		{
			if (!clickCharacter.npc)
			{
				if (this.invRow._Tag == "Gem")
				{
					int num = (int)this.invRow._Level * this.stackSize;
					Links.x.inventory.gems += num;
					string text = "gems";
					if (this.invRow._Level == 1f)
					{
						text = "gem";
					}
					Links.x.gameFeed.AddFeed("+" + num.ToString() + " " + text);
				}
				else
				{
					Links.x.inventory.emeralds += this.stackSize;
					string text2 = "emeralds";
					if (this.stackSize == 1)
					{
						text2 = "emerald";
					}
					Links.x.gameFeed.AddFeed("+" + this.invRow._Level.ToString() + " " + text2);
				}
			}
		}
		else
		{
			float num2 = 0f;
			if (this.forSale && !stole)
			{
				num2 = this.GetCost(false, clickCharacter, this.linkedCharacter);
			}
			Item item;
			ItemEquipped itemEquipped;
			Links.x.inventory.AddFromGround(this.label, this, 0, stole, num2, this.ID, this.stackSize, this.socketA, this.socketB, this.durability, clickCharacter, true, false, out item, out itemEquipped);
		}
		Links.x.inventory.UpdateMisc();
		if (!this.forSale || stole)
		{
			Links.x.itemPickupFX.gameObject.SetActive(true);
			Links.x.itemPickupFX.gameObject.GetComponent<HannahAnimator>().Play("Idle");
			Vector3 position = this.tr.position;
			Vector3 vector = Links.x.worldCamera.WorldToScreenPoint(position);
			vector.z = 0f;
			vector.x = vector.x * (1920f / (float)Screen.width) - 960f;
			vector.y = vector.y * (Links.x.canvasRT.sizeDelta.y / (float)Screen.height) - Links.x.canvasRT.sizeDelta.y / 2f;
			Links.x.itemPickupFX.localPosition = vector;
		}
		this.destroying = true;
		Links.x.inventory.groundBag.RemovePopItem(this);
		Links.x.inventory.groundBag.HitScreenItem(this, false);
		this.OutOfRange();
		this.fx.SetActive(false);
		Links.x.inventory.groundBag.SetCollectorUpdate();
		bool flag = false;
		if (!this.tr.gameObject.activeSelf)
		{
			this.FinishDestroy();
			flag = true;
		}
		if (!flag && this.tr.parent && !this.tr.parent.gameObject.activeSelf)
		{
			this.FinishDestroy();
			flag = true;
		}
		if (!flag)
		{
			if (this.forSale || this.alwaysRefill)
			{
				base.StartCoroutine(this.DestroyWait(quip));
			}
			else
			{
				this.FinishDestroy();
			}
		}
		if (zoomed)
		{
			yield return new WaitForSeconds(0.5f);
			if (this.forSale && !stole)
			{
				Links.x.cellar.GetAnimatedText("Text", this.GetCost(false, clickCharacter, this.linkedCharacter).ToString(), false).gameObject.transform.position = this.tr.position + new Vector3(Random.Range(0f, 0.5f), Random.Range(-0.5f, 0.5f), 0f);
				yield return new WaitForSeconds(0.25f);
				MasterAudio.PlaySoundAndForget("Inventory", 1f, new float?(1f), 0f, "Coins", null);
			}
			yield return new WaitForSeconds(2f);
			if (Links.x.rtsCamera.zoomCount <= 1)
			{
				Links.x.rtsCamera.Zoom(false, "");
			}
			else
			{
				Links.x.rtsCamera.zoomCount--;
			}
		}
		this.clickCoroutine = null;
		yield break;
	}

	// Token: 0x0600115D RID: 4445 RVA: 0x00153ED5 File Offset: 0x001520D5
	private IEnumerator DestroyWait(string quip)
	{
		if ((this.forSale || this.alwaysRefill) && (this.invRow._RefillsAtMerchant || this.alwaysRefill) && (this.linkedCreatures || this.alwaysRefill))
		{
			this.GetLinkedCharacter();
			if (this.linkedCharacter || this.alwaysRefill)
			{
				bool flag = this.alwaysRefill;
				if (!flag && !this.linkedCharacter.dead && !this.linkedCharacter.stunned)
				{
					flag = true;
				}
				if (flag)
				{
					if (this.useSprite)
					{
						this.sprite.enabled = false;
					}
					else
					{
						for (int i = 0; i < this.renderers.Count; i++)
						{
							this.renderers[i].enabled = false;
						}
					}
					for (int j = 0; j < this.colliders.Count; j++)
					{
						this.colliders[j].enabled = false;
					}
					this.OutOfRange();
					Links.x.inventory.groundBag.HitItem(this, false);
					Links.x.inventory.groundBag.HoverItems(this, false);
					Links.x.inventory.groundBag.RemovePopItem(this);
					Links.x.inventory.groundBag.HitScreenItem(this, false);
					this.active = false;
					this.instantiating = true;
					float timeToLerp = 4f;
					float percentage = 0f;
					float startTime = Time.time;
					while (percentage < 1f && !Links.x.diorama.savingItems)
					{
						percentage = (Time.time - startTime) / timeToLerp;
						yield return null;
					}
					if (this.dropNode != null)
					{
						this.dropNode.item = 0;
					}
					int num = -1;
					if (this.dropNode != null)
					{
						num = (int)this.dropNode.Area;
					}
					Item item = Links.x.inventory.groundBag.DropLoot(this.ID, this.stackSize, this.socketA, this.socketB, this.durability, null, this.tr.position, false, this.forSale, num);
					item.transform.rotation = this.tr.rotation;
					if (!this.alwaysRefill)
					{
						item.forSale = true;
						item.linkedCreatures = this.linkedCreatures;
						item.GetLinkedCharacter();
					}
					this.instantiating = false;
				}
			}
		}
		this.clickCoroutine = null;
		this.FinishDestroy();
		yield break;
	}

	// Token: 0x0600115E RID: 4446 RVA: 0x00153EE4 File Offset: 0x001520E4
	private void FinishDestroy()
	{
		this.DestroyItem(false, false);
		this.fx.SetActive(false);
		this.active = false;
		if (this.useSprite)
		{
			this.sprite.enabled = false;
		}
		else if (this.renderers != null)
		{
			for (int i = 0; i < this.renderers.Count; i++)
			{
				this.renderers[i].enabled = true;
			}
		}
		for (int j = 0; j < this.colliders.Count; j++)
		{
			this.colliders[j].enabled = true;
		}
	}

	// Token: 0x0600115F RID: 4447 RVA: 0x00153F7A File Offset: 0x0015217A
	public void BombBomb(Vector3 explodePosition)
	{
		Links.x.diorama.BombBomb(explodePosition, null);
		if (this.onGround)
		{
			this.DestroyItem(false, false);
		}
	}

	// Token: 0x06001160 RID: 4448 RVA: 0x00153FA0 File Offset: 0x001521A0
	public void OutOfRange()
	{
		if (this.inRangeFX)
		{
			Records.x.RemoveBillboard(this.inRangeFX.transform, false);
			if (this.inRangeFX.name.Contains("Sale"))
			{
				Links.x.cellar.ReturnPooledGameObject(90, this.inRangeFX);
			}
			else
			{
				Links.x.cellar.ReturnPooledGameObject(33, this.inRangeFX);
			}
			this.inRangeFX = null;
		}
		this.inRange = false;
		this.ToggleCloseEnoughToPickup(false);
	}

	// Token: 0x06001161 RID: 4449 RVA: 0x0015402C File Offset: 0x0015222C
	public void InRange()
	{
		if (this.destroying)
		{
			return;
		}
		if (!this.active || !base.gameObject.activeInHierarchy)
		{
			if (this.inRangeFX)
			{
				this.OutOfRange();
			}
			return;
		}
		if (this.sprite.enabled && !this.inRangeFX)
		{
			this.GetLinkedCharacter();
			int num = 33;
			if (this.linkedCharacter && this.forSale)
			{
				num = 90;
			}
			this.inRangeFX = Links.x.cellar.GetPooledGameObject(num);
			Records.x.AddBillboard(this.inRangeFX.transform, false);
			this.inRangeFX.transform.position = base.transform.position + new Vector3(0f, 0.5f, 0f);
			this.inRangeFX.SetActive(true);
		}
		this.inRange = true;
		this.ToggleCloseEnoughToPickup(false);
	}

	// Token: 0x06001162 RID: 4450 RVA: 0x00154128 File Offset: 0x00152328
	public void ToggleCloseEnoughToPickup(bool state)
	{
		if (Links.x.joy)
		{
			this.closeEnoughToPickup = state;
			if (this.inRangeFX)
			{
				if (state)
				{
					this.inRangeFX.transform.GetChild(1).gameObject.layer = 0;
					this.inRangeFX.transform.GetChild(2).gameObject.layer = 0;
					return;
				}
				this.inRangeFX.transform.GetChild(1).gameObject.layer = 5;
				this.inRangeFX.transform.GetChild(2).gameObject.layer = 5;
			}
		}
	}

	// Token: 0x06001163 RID: 4451 RVA: 0x001541CC File Offset: 0x001523CC
	public void GroundMenuDragEnd()
	{
		this.img.raycastTarget = true;
		Debug.Log(this);
	}

	// Token: 0x06001164 RID: 4452 RVA: 0x001541E0 File Offset: 0x001523E0
	public void InGroundMenuList()
	{
		this.img.raycastTarget = true;
		this.inGroundMenu = true;
		this.ToggleBackImage(true);
		this.ToggleSockets(false);
		Links.x.inventory.AddToGroundList(this);
	}

	// Token: 0x06001165 RID: 4453 RVA: 0x00154214 File Offset: 0x00152414
	public void LeaveGroundMenuList()
	{
		this.img.raycastTarget = false;
		this.inGroundMenu = false;
		this.ToggleBackImage(false);
		if (this.worldItem)
		{
			this.worldItem.DestroyItem(false, false);
		}
		this.worldItem = null;
		Links.x.inventory.RemoveFromGroundList(this);
	}

	// Token: 0x06001166 RID: 4454 RVA: 0x0015426C File Offset: 0x0015246C
	public void ToggleBackImage(bool state)
	{
		this.backImage.enabled = state;
		this.backImage.gameObject.SetActive(state);
		if (this.inGroundMenu)
		{
			this.backImage.fillCenter = false;
			bool joy = Links.x.joy;
			return;
		}
		this.backImage.fillCenter = true;
	}

	// Token: 0x06001167 RID: 4455 RVA: 0x001542C2 File Offset: 0x001524C2
	public void OnPointerDown(PointerEventData eventData)
	{
		this.img.raycastTarget = false;
	}

	// Token: 0x06001168 RID: 4456 RVA: 0x001542D0 File Offset: 0x001524D0
	public void OnPointerUp(PointerEventData eventData)
	{
	}

	// Token: 0x06001169 RID: 4457 RVA: 0x001542D4 File Offset: 0x001524D4
	public void OnPointerEnter(PointerEventData eventData)
	{
		if (this != Links.x.inventory.dragItem)
		{
			this.ToggleSockets(true);
			Links.x.inventory.hitGroundItem = this;
			this.img.color = new Color(1f, 1f, 1f, 1f);
		}
	}

	// Token: 0x0600116A RID: 4458 RVA: 0x00154334 File Offset: 0x00152534
	public void OnPointerExit(PointerEventData eventData)
	{
		if (this != Links.x.inventory.dragItem)
		{
			this.ToggleSockets(false);
			if (Links.x.inventory.hitGroundItem == this)
			{
				Links.x.inventory.hitGroundItem = null;
			}
			this.img.color = new Color(0.9f, 0.9f, 0.9f, 1f);
		}
	}

	// Token: 0x0600116B RID: 4459 RVA: 0x001543AC File Offset: 0x001525AC
	public void InventoryHoverIn(bool fromSecondary)
	{
		if (!this.onGround)
		{
			Links.x.inventory.hitGo = base.gameObject;
			if (this != Links.x.inventory.dragItem)
			{
				this.img.color = new Color(0.96f, 1f, 0.7f, 1f);
				if (this.forSale)
				{
					Links.x.inventory.HoveringOverItem(this, true, "Secondary");
				}
				else
				{
					Links.x.inventory.HoveringOverItem(this, true, "");
				}
				this.ToggleSockets(true);
			}
		}
	}

	// Token: 0x0600116C RID: 4460 RVA: 0x00154454 File Offset: 0x00152654
	public void InventoryHoverOut(bool fromSecondary)
	{
		if (!this.onGround)
		{
			Links.x.inventory.hitGo = null;
			this.img.color = new Color(1f, 1f, 1f, 1f);
			if (this != Links.x.inventory.dragItem)
			{
				if (this.forSale)
				{
					Links.x.inventory.HoveringOverItem(this, false, "Secondary");
				}
				else
				{
					Links.x.inventory.HoveringOverItem(this, false, "");
				}
				this.ToggleSockets(false);
			}
		}
	}

	// Token: 0x0600116D RID: 4461 RVA: 0x001544F4 File Offset: 0x001526F4
	public void PickUp()
	{
		if (!this.active)
		{
			return;
		}
		if (this.onList)
		{
			this.RemoveFromList();
		}
		this.OutOfRange();
		if (!Links.x.creation)
		{
			MasterAudio.PlaySoundAndForget("Inventory", 0.8f, new float?(1f), 0f, this.invRow._Sound, null);
		}
	}

	// Token: 0x0600116E RID: 4462 RVA: 0x00154562 File Offset: 0x00152762
	public void RemoveFromList()
	{
		Links.x.inventory.RemoveGoodItem(this);
	}

	// Token: 0x0600116F RID: 4463 RVA: 0x00154574 File Offset: 0x00152774
	public void DestroyGroundItem()
	{
		if (this.inRange)
		{
			this.OutOfRange();
		}
		this.onGround = false;
		this.active = false;
		base.gameObject.SetActive(false);
	}

	// Token: 0x06001170 RID: 4464 RVA: 0x0015459E File Offset: 0x0015279E
	public void EquippedOutline(bool state)
	{
		this.isEquipped = state;
	}

	// Token: 0x06001171 RID: 4465 RVA: 0x001545A7 File Offset: 0x001527A7
	public bool HasGridSlot(int index)
	{
		return this.gridImg.Contains(index);
	}

	// Token: 0x06001172 RID: 4466 RVA: 0x001545BC File Offset: 0x001527BC
	public void GetSocketImg(Image img, int socketIndex)
	{
		socketIndex = this.SocketIndex(socketIndex);
		Library.Sockets socket = Links.x.library.GetSocket(socketIndex);
		if (socket != null)
		{
			Library.Inventory invRowByIndex = Links.x.library.GetInvRowByIndex(socket._ItemID);
			if (invRowByIndex != null)
			{
				img.sprite = Links.x.archives.GetItem(invRowByIndex._UIModel);
				img.enabled = true;
			}
		}
	}

	// Token: 0x06001173 RID: 4467 RVA: 0x00154624 File Offset: 0x00152824
	public bool AddSocket(int socketIndex)
	{
		if (socketIndex > 0)
		{
			int firstOpenSocket = this.GetFirstOpenSocket();
			if (this.invRow._Tag.Contains("Armor") && firstOpenSocket > -1)
			{
				socketIndex = this.RepairAmount(socketIndex);
			}
			if (firstOpenSocket == 0)
			{
				this.socketA.x = (float)socketIndex;
				this.GetSocketImg(this.socketFill[0], (int)this.socketA.x);
				return true;
			}
			if (firstOpenSocket == 1)
			{
				this.socketA.y = (float)socketIndex;
				this.GetSocketImg(this.socketFill[1], (int)this.socketA.y);
				return true;
			}
			if (firstOpenSocket == 2)
			{
				this.socketA.z = (float)socketIndex;
				this.GetSocketImg(this.socketFill[2], (int)this.socketA.z);
				return true;
			}
			if (firstOpenSocket == 3)
			{
				this.socketB.x = (float)socketIndex;
				this.GetSocketImg(this.socketFill[3], (int)this.socketB.x);
				return true;
			}
			if (firstOpenSocket == 4)
			{
				this.socketB.y = (float)socketIndex;
				this.GetSocketImg(this.socketFill[4], (int)this.socketB.y);
				return true;
			}
			if (firstOpenSocket == 5)
			{
				this.socketB.z = (float)socketIndex;
				this.GetSocketImg(this.socketFill[5], (int)this.socketB.z);
				return true;
			}
		}
		return false;
	}

	// Token: 0x06001174 RID: 4468 RVA: 0x0015478C File Offset: 0x0015298C
	public int RepairAmount(int socketIndex)
	{
		Library.Sockets socket = Links.x.library.GetSocket(socketIndex);
		int num = socket._RepairAmount;
		string mainSkill = this.invRow._MainSkill;
		num = (int)Links.x.characterSheet.character.stats.SocketingRepair(socket._RepairAmount, false, mainSkill);
		if (this.durability.x + (float)num > (float)this.invRow._DurabilityMax)
		{
			num = this.invRow._DurabilityMax - (int)this.durability.x;
		}
		this.durability.x = this.durability.x + (float)num;
		Debug.Log("Repair amount " + num.ToString());
		Links.x.inventory.fx.gameObject.transform.position = base.gameObject.transform.position;
		Links.x.inventory.fx.Play("Idle");
		MasterAudio.PlaySoundAndForget("RepairArmor", 1f, new float?(1f), 0f, "", null);
		if (Links.x.inventory.itemInfo.open)
		{
			Links.x.inventory.itemInfo.SetNumbers(true);
		}
		this.SetDurabilityVisual();
		Links.x.characterSheet.GetStats();
		return socketIndex * 100 + num;
	}

	// Token: 0x06001175 RID: 4469 RVA: 0x001548F8 File Offset: 0x00152AF8
	public void RemoveSockets()
	{
		for (int i = 0; i < this.socketImg.Count; i++)
		{
			if (this.socketImg[i] && this.socketImg[i].transform.parent == this.tr)
			{
				this.socketImg[i].transform.SetParent(Links.x.cellar.tr, false);
				this.socketFill[i].enabled = false;
				this.socketImg[i].SetActive(false);
				if (this.invRow._Tag.Contains("Armor"))
				{
					Links.x.cellar.ReturnSocket(this.socketImg[i], "Repair");
				}
				else
				{
					Links.x.cellar.ReturnSocket(this.socketImg[i], "");
				}
			}
		}
		this.SetDurabilityVisual();
	}

	// Token: 0x06001176 RID: 4470 RVA: 0x00154A08 File Offset: 0x00152C08
	public void AddSocketImgs()
	{
		if (this.socketImg.Count == 0)
		{
			for (int i = 0; i < this.socketMax; i++)
			{
				GameObject gameObject;
				if (this.invRow._Tag.Contains("Armor"))
				{
					gameObject = Links.x.cellar.GetPooledGameObject(35);
				}
				else
				{
					gameObject = Links.x.cellar.GetPooledGameObject(4);
				}
				if (gameObject)
				{
					string text = "";
					if (Links.x.secondaryBag && this.tr.parent == Links.x.secondaryBag.gameObject.transform)
					{
						text = "Secondary";
					}
					gameObject.transform.position = Links.x.inventory.GetLocalGridPosition(this, i, text);
					gameObject.transform.SetParent(base.transform, true);
					gameObject.transform.localScale = new Vector3(1f, 1f, 1f);
					this.socketImg.Add(gameObject);
					Image component = gameObject.transform.GetChild(1).gameObject.GetComponent<Image>();
					component.enabled = false;
					this.socketFill.Add(component);
					if (i == 0 && this.socketA.x > 0f)
					{
						this.GetSocketImg(component, (int)this.socketA.x);
					}
					if (i == 1 && this.socketA.y > 0f)
					{
						this.GetSocketImg(component, (int)this.socketA.y);
					}
					if (i == 2 && this.socketA.z > 0f)
					{
						this.GetSocketImg(component, (int)this.socketA.z);
					}
					if (i == 3 && this.socketB.x > 0f)
					{
						this.GetSocketImg(component, (int)this.socketB.x);
					}
					if (i == 4 && this.socketB.y > 0f)
					{
						this.GetSocketImg(component, (int)this.socketB.y);
					}
					if (i == 5 && this.socketB.z > 0f)
					{
						this.GetSocketImg(component, (int)this.socketB.z);
					}
				}
			}
			this.ToggleSockets(false);
		}
	}

	// Token: 0x06001177 RID: 4471 RVA: 0x00154C48 File Offset: 0x00152E48
	public void UpdateSocketLocations()
	{
		if (this.socketImg.Count > 0)
		{
			for (int i = 0; i < this.socketMax; i++)
			{
				GameObject gameObject = this.socketImg[i];
				string text = "";
				if (Links.x.secondaryBag && this.tr.parent == Links.x.secondaryBag.gameObject.transform)
				{
					text = "Secondary";
				}
				gameObject.transform.position = Links.x.inventory.GetLocalGridPosition(this, i, text);
				gameObject.transform.SetParent(base.transform, true);
				gameObject.transform.localScale = new Vector3(1f, 1f, 1f);
			}
		}
	}

	// Token: 0x06001178 RID: 4472 RVA: 0x00154D1C File Offset: 0x00152F1C
	public int GetRealDurability()
	{
		int num = (int)this.durability.x;
		for (int i = 0; i < this.socketImg.Count; i++)
		{
			if (this.invRow._Tag.Contains("Armor"))
			{
				int socketID = this.GetSocketID(i, true);
				int socketID2 = this.GetSocketID(i, false);
				if (socketID2 > 0)
				{
					float num2 = (float)socketID - 100f * (float)socketID2;
					num -= (int)num2;
				}
			}
		}
		return num;
	}

	// Token: 0x06001179 RID: 4473 RVA: 0x00154D8D File Offset: 0x00152F8D
	public int SocketIndex(int id)
	{
		if (id < 100)
		{
			return id;
		}
		return (int)Mathf.Floor((float)id / 100f);
	}

	// Token: 0x0600117A RID: 4474 RVA: 0x00154DA4 File Offset: 0x00152FA4
	public int GetSocketID(int i, bool real)
	{
		int num = -1;
		if (i == 0)
		{
			num = (int)this.socketA.x;
		}
		if (i == 1)
		{
			num = (int)this.socketA.y;
		}
		if (i == 2)
		{
			num = (int)this.socketA.z;
		}
		if (i == 3)
		{
			num = (int)this.socketB.x;
		}
		if (i == 4)
		{
			num = (int)this.socketB.y;
		}
		if (i == 5)
		{
			num = (int)this.socketB.z;
		}
		if (num > 0 && num >= 100)
		{
			if (real)
			{
				return num;
			}
			if (!real)
			{
				return this.SocketIndex(num);
			}
		}
		return num;
	}

	// Token: 0x0600117B RID: 4475 RVA: 0x00154E34 File Offset: 0x00153034
	public int GetFirstOpenSocket()
	{
		int num = -1;
		for (int i = 0; i < this.socketImg.Count; i++)
		{
			if (this.invRow._Tag.Contains("Armor"))
			{
				if (this.invRow._Tag.Contains("Armor") && this.durability.x <= (float)this.invRow._DurabilityMax && num == -1 && !this.socketFill[i].enabled && this.socketImg[i].gameObject.activeSelf)
				{
					num = i;
				}
			}
			else if (!this.socketFill[i].enabled && num == -1)
			{
				num = i;
			}
		}
		return num;
	}

	// Token: 0x0600117C RID: 4476 RVA: 0x00154EF3 File Offset: 0x001530F3
	public void CheckIfPatchBreaks()
	{
	}

	// Token: 0x0600117D RID: 4477 RVA: 0x00154EF8 File Offset: 0x001530F8
	public void ToggleSockets(bool state)
	{
		if (this.inGroundMenu && Links.x.inventory.dragItem != this)
		{
			state = false;
		}
		for (int i = 0; i < this.socketImg.Count; i++)
		{
			if (this.invRow._Tag.Contains("Armor") && !this.inGroundMenu)
			{
				int realDurability = this.GetRealDurability();
				float num = (float)this.invRow._DurabilityMax / (float)this.socketMax;
				int durabilityMax = this.invRow._DurabilityMax;
				float num2 = num * (float)i + num;
				if ((float)realDurability < num2 || this.socketFill[this.socketImg.Count - 1 - i].enabled)
				{
					this.socketImg[this.socketImg.Count - 1 - i].SetActive(state);
				}
				else
				{
					this.socketImg[this.socketImg.Count - 1 - i].SetActive(false);
				}
			}
			else
			{
				this.socketImg[this.socketImg.Count - 1 - i].SetActive(state);
			}
		}
	}

	// Token: 0x04001C9B RID: 7323
	[Header("OBJECTS")]
	public GameObject stack;

	// Token: 0x04001C9C RID: 7324
	public TextMeshProUGUI stackText;

	// Token: 0x04001C9D RID: 7325
	public List<MeshRenderer> renderers;

	// Token: 0x04001C9E RID: 7326
	public List<BoxCollider> colliders;

	// Token: 0x04001C9F RID: 7327
	public Image img;

	// Token: 0x04001CA0 RID: 7328
	public Sprite maskedSprite;

	// Token: 0x04001CA1 RID: 7329
	public Sprite fullSprite;

	// Token: 0x04001CA2 RID: 7330
	public RectTransform rt;

	// Token: 0x04001CA3 RID: 7331
	public Creatures linkedCreatures;

	// Token: 0x04001CA4 RID: 7332
	public Character linkedCharacter;

	// Token: 0x04001CA5 RID: 7333
	public int linkedCreatureID;

	// Token: 0x04001CA6 RID: 7334
	public Prompts linkedPrompt;

	// Token: 0x04001CA7 RID: 7335
	[Header("DATA")]
	public int ID;

	// Token: 0x04001CA8 RID: 7336
	public Vector3 socketA = new Vector3(-1f, -1f, -1f);

	// Token: 0x04001CA9 RID: 7337
	public Vector3 socketB = new Vector3(-1f, -1f, -1f);

	// Token: 0x04001CAA RID: 7338
	public bool stackable;

	// Token: 0x04001CAB RID: 7339
	public int stackSize;

	// Token: 0x04001CAC RID: 7340
	public Library.Inventory invRow;

	// Token: 0x04001CAD RID: 7341
	public int socketMax;

	// Token: 0x04001CAE RID: 7342
	public string itemTag;

	// Token: 0x04001CAF RID: 7343
	public bool forSale;

	// Token: 0x04001CB0 RID: 7344
	private bool alwaysRefill;

	// Token: 0x04001CB1 RID: 7345
	public Vector4 durability;

	// Token: 0x04001CB2 RID: 7346
	public bool edible;

	// Token: 0x04001CB3 RID: 7347
	public bool spellItem;

	// Token: 0x04001CB4 RID: 7348
	public bool ammo;

	// Token: 0x04001CB5 RID: 7349
	public Creatures.Adventures deactivateFromQuest;

	// Token: 0x04001CB6 RID: 7350
	public Creatures.AdventureStates stateOfQuest_;

	// Token: 0x04001CB7 RID: 7351
	public string sceneItemName;

	// Token: 0x04001CB8 RID: 7352
	[Header("INFO")]
	public int bagGridID;

	// Token: 0x04001CB9 RID: 7353
	public bool onGround;

	// Token: 0x04001CBA RID: 7354
	public bool active;

	// Token: 0x04001CBB RID: 7355
	public bool inGroundMenu;

	// Token: 0x04001CBC RID: 7356
	public bool clickable;

	// Token: 0x04001CBD RID: 7357
	public int equipSlot;

	// Token: 0x04001CBE RID: 7358
	public int equipIndex = -1;

	// Token: 0x04001CBF RID: 7359
	public bool isEquipped;

	// Token: 0x04001CC0 RID: 7360
	public bool noDrag;

	// Token: 0x04001CC1 RID: 7361
	public List<int> gridImg;

	// Token: 0x04001CC2 RID: 7362
	public Transform tr;

	// Token: 0x04001CC3 RID: 7363
	public InventoryContainer bag;

	// Token: 0x04001CC4 RID: 7364
	public Image backImage;

	// Token: 0x04001CC5 RID: 7365
	private List<Character> characters;

	// Token: 0x04001CC6 RID: 7366
	[Header("SOCKETS")]
	public List<GameObject> socketImg = new List<GameObject>();

	// Token: 0x04001CC7 RID: 7367
	public List<Image> socketFill = new List<Image>();

	// Token: 0x04001CC8 RID: 7368
	[Header("GROUND UI")]
	public bool inRange;

	// Token: 0x04001CC9 RID: 7369
	public bool closeEnoughToPickup;

	// Token: 0x04001CCA RID: 7370
	public GameObject inRangeFX;

	// Token: 0x04001CCB RID: 7371
	public bool onList;

	// Token: 0x04001CCC RID: 7372
	public bool instantiating;

	// Token: 0x04001CCD RID: 7373
	public GraphNode dropNode;

	// Token: 0x04001CCE RID: 7374
	public Item worldItem;

	// Token: 0x04001CCF RID: 7375
	public Item slotItem;

	// Token: 0x04001CD0 RID: 7376
	public GroundItemText label;

	// Token: 0x04001CD1 RID: 7377
	public bool movingTo;

	// Token: 0x04001CD2 RID: 7378
	public bool destroying;

	// Token: 0x04001CD3 RID: 7379
	public GameObject fx;

	// Token: 0x04001CD4 RID: 7380
	public ResourceLocation resourceLocation;

	// Token: 0x04001CD5 RID: 7381
	public bool groundHovering;

	// Token: 0x04001CD6 RID: 7382
	public bool useSprite;

	// Token: 0x04001CD7 RID: 7383
	public SpriteRenderer sprite;

	// Token: 0x04001CD8 RID: 7384
	private IEnumerator clickCoroutine;

	// Token: 0x04001CD9 RID: 7385
	public GameObject bracket;

	// Token: 0x04001CDA RID: 7386
	private Bounds bounds;

	// Token: 0x04001CDB RID: 7387
	private StringFast str = new StringFast(32);
}
