D:\ValheimDev\Dumps\Old\assembly_valheim\Pickable.cs D:\ValheimDev\Dumps\Latest\assembly_valheim\Pickable.cs
using System; using System;
using UnityEngine; using UnityEngine;
   
public class Pickable : MonoBehaviour, Hoverable, Interactable public class Pickable : MonoBehaviour, Hoverable, Interactable
{ {
    private void Awake()     private void Awake()
    {     {
        this.m_nview = base.GetComponent<ZNetView>();         this.m_nview = base.GetComponent<ZNetView>();
        ZDO zdo = this.m_nview.GetZDO();         ZDO zdo = this.m_nview.GetZDO();
        if (zdo == null)         if (zdo == null)
        {         {
            return;             return;
        }         }
.        this.m_nview.Register<bool>("SetPicked", new Action<long, bool>(this.RPC_SetPicked));         this.m_nview.Register<bool>("RPC_SetPicked", new Action<long, bool>(this.RPC_SetPicked));
        this.m_nview.Register("Pick", new Action<long>(this.RPC_Pick));         this.m_nview.Register("RPC_Pick", new Action<long>(this.RPC_Pick));
        this.m_picked = zdo.GetBool(ZDOVars.s_picked, false);         this.m_picked = zdo.GetBool(ZDOVars.s_picked, this.m_defaultPicked);
        if (this.m_picked && this.m_hideWhenPicked)         this.m_pickedTime = this.m_nview.GetZDO().GetLong(ZDOVars.s_pickedTime, 0L); 
          if (this.m_enabled == 2)
        {         {
.            this.m_hideWhenPicked.SetActive(false);             this.m_enabled = (zdo.GetBool(ZDOVars.s_enabled, true) ? 1 : 0);
        }         }
.        if (this.m_respawnTimeMinutes > 0)          else if (this.m_nview.IsOwner()) 
        {         {
.            base.InvokeRepeating("UpdateRespawn", UnityEngine.Random.Range(1f, 5f), 60f);             zdo.Set(ZDOVars.s_enabled, this.m_enabled == 1);
        }         }
.        if (this.m_respawnTimeMinutes <= 0 && this.m_hideWhenPicked == null && this.m_nview.GetZDO().GetBool(ZDOVars.s_picked, false))         if (this.m_hideWhenPicked) 
          { 
              this.m_hideWhenPicked.SetActive(!this.m_picked && this.m_enabled == 1); 
          } 
          float num = 60f; 
          if (this.m_respawnTimeMinutes > 0f) 
          { 
              base.InvokeRepeating("UpdateRespawn", UnityEngine.Random.Range(1f, 5f), num); 
          } 
          if (this.m_respawnTimeMinutes <= 0f && this.m_hideWhenPicked == null && this.m_nview.GetZDO().GetBool(ZDOVars.s_picked, false))
        {         {
            this.m_nview.ClaimOwnership();             this.m_nview.ClaimOwnership();
            this.m_nview.Destroy();             this.m_nview.Destroy();
            ZLog.Log("Destroying old picked " + base.name);             ZLog.Log("Destroying old picked " + base.name);
        }         }
    }     }
   
    public string GetHoverText()     public string GetHoverText()
    {     {
.        if (this.m_picked)         if (this.m_picked || this.m_enabled == 0)
        {         {
            return "";             return "";
        }         }
        return Localization.instance.Localize(this.GetHoverName() + "\n[<color=yellow><b>$KEY_Use</b></color>] $inventory_pickup");         return Localization.instance.Localize(this.GetHoverName() + "\n[<color=yellow><b>$KEY_Use</b></color>] $inventory_pickup");
    }     }
   
    public string GetHoverName()     public string GetHoverName()
    {     {
        if (!string.IsNullOrEmpty(this.m_overrideName))         if (!string.IsNullOrEmpty(this.m_overrideName))
        {         {
            return this.m_overrideName;             return this.m_overrideName;
        }         }
        return this.m_itemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_name;         return this.m_itemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_name;
    }     }
   
    private void UpdateRespawn()     private void UpdateRespawn()
    {     {
        if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())         if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())
        {         {
            return;             return;
        }         }
        if (!this.m_picked)         if (!this.m_picked)
        {         {
            return;             return;
        }         }
.        long @long = this.m_nview.GetZDO().GetLong(ZDOVars.s_pickedTime, 0L);          if (this.m_pickedTime == 0L) 
        DateTime dateTime = new DateTime(@long);          { 
        if ((ZNet.instance.GetTime() - dateTime).TotalMinutes > (double)this.m_respawnTimeMinutes)              this.m_pickedTime = ZNet.instance.GetTime().Ticks - TimeSpan.FromMinutes((double)UnityEngine.Random.Range(this.m_respawnTimeInitMin * 100f, this.m_respawnTimeInitMax * 100f)).Ticks; 
              if (this.m_pickedTime < 1L) 
              { 
                  this.m_pickedTime = 1L; 
              } 
              this.m_nview.GetZDO().Set(ZDOVars.s_pickedTime, this.m_pickedTime); 
          } 
          if (this.m_enabled == 0) 
          { 
              if (this.m_hideWhenPicked) 
              { 
                  this.m_hideWhenPicked.SetActive(false); 
              } 
              return; 
          } 
          if (this.ShouldRespawn()) 
          { 
              this.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_SetPicked", new object[] { false }); 
          } 
      } 
   
      private bool ShouldRespawn() 
      { 
          if (!this.m_nview) 
        {         {
.            this.m_nview.InvokeRPC(ZNetView.Everybody, "SetPicked", new object[] { false });             return false;
        }         }
.          long @long = this.m_nview.GetZDO().GetLong(ZDOVars.s_pickedTime, 0L);
          DateTime dateTime = new DateTime(@long);
          TimeSpan timeSpan = ZNet.instance.GetTime() - dateTime;
          return (@long <= 1L || timeSpan.TotalMinutes > (double)this.m_respawnTimeMinutes) && (this.m_spawnCheck == null || this.m_spawnCheck(this));
    }     }
   
    public bool Interact(Humanoid character, bool repeat, bool alt)     public bool Interact(Humanoid character, bool repeat, bool alt)
    {     {
.        if (!this.m_nview.IsValid())         if (!this.m_nview.IsValid() || this.m_enabled == 0)
        {         {
            return false;             return false;
        }         }
        if (this.m_tarPreventsPicking)         if (this.m_tarPreventsPicking)
        {         {
            if (this.m_floating == null)             if (this.m_floating == null)
            {             {
                this.m_floating = base.GetComponent<Floating>();                 this.m_floating = base.GetComponent<Floating>();
            }             }
            if (this.m_floating && this.m_floating.IsInTar())             if (this.m_floating && this.m_floating.IsInTar())
            {             {
                character.Message(MessageHud.MessageType.Center, "$hud_itemstucktar", 0, null);                 character.Message(MessageHud.MessageType.Center, "$hud_itemstucktar", 0, null);
                return this.m_useInteractAnimation;                 return this.m_useInteractAnimation;
            }             }
        }         }
.        this.m_nview.InvokeRPC("Pick", Array.Empty<object>());         this.m_nview.InvokeRPC("RPC_Pick", Array.Empty<object>());
        return this.m_useInteractAnimation;         return this.m_useInteractAnimation;
    }     }
   
    private void RPC_Pick(long sender)     private void RPC_Pick(long sender)
    {     {
        if (!this.m_nview.IsOwner())         if (!this.m_nview.IsOwner())
        {         {
            return;             return;
        }         }
        if (this.m_picked)         if (this.m_picked)
        {         {
            return;             return;
        }         }
        Vector3 vector = (this.m_pickEffectAtSpawnPoint ? (base.transform.position + Vector3.up * this.m_spawnOffset) : base.transform.position);         Vector3 vector = (this.m_pickEffectAtSpawnPoint ? (base.transform.position + Vector3.up * this.m_spawnOffset) : base.transform.position);
        this.m_pickEffector.Create(vector, Quaternion.identity, null, 1f, -1);         this.m_pickEffector.Create(vector, Quaternion.identity, null, 1f, -1);
        int num = (this.m_dontScale ? this.m_amount : Mathf.Max(this.m_minAmountScaled, Game.instance.ScaleDrops(this.m_itemPrefab, this.m_amount)));         int num = (this.m_dontScale ? this.m_amount : Mathf.Max(this.m_minAmountScaled, Game.instance.ScaleDrops(this.m_itemPrefab, this.m_amount)));
        int num2 = 0;         int num2 = 0;
        for (int i = 0; i < num; i++)         for (int i = 0; i < num; i++)
        {         {
            this.Drop(this.m_itemPrefab, num2++, 1);             this.Drop(this.m_itemPrefab, num2++, 1);
        }         }
        if (!this.m_extraDrops.IsEmpty())         if (!this.m_extraDrops.IsEmpty())
        {         {
            foreach (ItemDrop.ItemData itemData in this.m_extraDrops.GetDropListItems())             foreach (ItemDrop.ItemData itemData in this.m_extraDrops.GetDropListItems())
            {             {
                this.Drop(itemData.m_dropPrefab, num2++, itemData.m_stack);                 this.Drop(itemData.m_dropPrefab, num2++, itemData.m_stack);
            }             }
        }         }
        if (this.m_aggravateRange > 0f)         if (this.m_aggravateRange > 0f)
        {         {
            BaseAI.AggravateAllInArea(base.transform.position, this.m_aggravateRange, BaseAI.AggravatedReason.Theif);             BaseAI.AggravateAllInArea(base.transform.position, this.m_aggravateRange, BaseAI.AggravatedReason.Theif);
        }         }
.        this.m_nview.InvokeRPC(ZNetView.Everybody, "SetPicked", new object[] { true });         this.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_SetPicked", new object[] { true });
    }     }
   
    private void RPC_SetPicked(long sender, bool picked)     private void RPC_SetPicked(long sender, bool picked)
    {     {
        this.SetPicked(picked);         this.SetPicked(picked);
    }     }
   
.    private void SetPicked(bool picked)     public void SetPicked(bool picked)
    {     {
        this.m_picked = picked;         this.m_picked = picked;
        if (this.m_hideWhenPicked)         if (this.m_hideWhenPicked)
        {         {
            this.m_hideWhenPicked.SetActive(!picked);             this.m_hideWhenPicked.SetActive(!picked);
        }         }
.        if (this.m_nview.IsOwner())         if (this.m_nview && this.m_nview.IsOwner())
        {         {
.            if (this.m_respawnTimeMinutes > 0 || this.m_hideWhenPicked != null)             if (this.m_respawnTimeMinutes > 0f || this.m_hideWhenPicked != null)
            {             {
                this.m_nview.GetZDO().Set(ZDOVars.s_picked, this.m_picked);                 this.m_nview.GetZDO().Set(ZDOVars.s_picked, this.m_picked);
.                if (picked && this.m_respawnTimeMinutes > 0)                 if (picked && this.m_respawnTimeMinutes > 0f)
                {                 {
                    DateTime time = ZNet.instance.GetTime();                     DateTime time = ZNet.instance.GetTime();
                    this.m_nview.GetZDO().Set(ZDOVars.s_pickedTime, time.Ticks);                     this.m_nview.GetZDO().Set(ZDOVars.s_pickedTime, time.Ticks);
                    return;                     return;
                }                 }
            }             }
            else if (picked)             else if (picked)
            {             {
                this.m_nview.Destroy();                 this.m_nview.Destroy();
            }             }
        }         }
    }     }
   
.      public bool GetPicked()
      {
          return this.m_picked;
      }
   
      public void SetEnabled(bool value)
      {
          this.SetEnabled(value ? 1 : 0);
      }
   
      public void SetEnabled(int value)
      {
          this.m_enabled = value;
          if (this.m_nview && this.m_nview.IsOwner() && this.m_nview.GetZDO() != null)
          {
              this.m_nview.GetZDO().Set(ZDOVars.s_enabled, base.enabled);
          }
          if (this.m_hideWhenPicked)
          {
              this.m_hideWhenPicked.SetActive(base.enabled && this.ShouldRespawn());
          }
      }
   
      public int GetEnabled
      {
          get
          {
              return this.m_enabled;
          }
      }
   
      public bool CanBePicked()
      {
          return (this.m_hideWhenPicked && this.m_hideWhenPicked.activeInHierarchy) || (!this.m_picked && this.m_enabled == 1);
      }
   
    private void Drop(GameObject prefab, int offset, int stack)     private void Drop(GameObject prefab, int offset, int stack)
    {     {
        Vector2 vector = UnityEngine.Random.insideUnitCircle * 0.2f;         Vector2 vector = UnityEngine.Random.insideUnitCircle * 0.2f;
        Vector3 vector2 = base.transform.position + Vector3.up * this.m_spawnOffset + new Vector3(vector.x, 0.5f * (float)offset, vector.y);         Vector3 vector2 = base.transform.position + Vector3.up * this.m_spawnOffset + new Vector3(vector.x, 0.5f * (float)offset, vector.y);
        Quaternion quaternion = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f);         Quaternion quaternion = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f);
        GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(prefab, vector2, quaternion);         GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(prefab, vector2, quaternion);
        ItemDrop component = gameObject.GetComponent<ItemDrop>();         ItemDrop component = gameObject.GetComponent<ItemDrop>();
        if (component != null)         if (component != null)
        {         {
            component.SetStack(stack);             component.SetStack(stack);
            ItemDrop.OnCreateNew(component);             ItemDrop.OnCreateNew(component);
        }         }
        gameObject.GetComponent<Rigidbody>().velocity = Vector3.up * 4f;         gameObject.GetComponent<Rigidbody>().velocity = Vector3.up * 4f;
    }     }
   
    public bool UseItem(Humanoid user, ItemDrop.ItemData item)     public bool UseItem(Humanoid user, ItemDrop.ItemData item)
    {     {
        return false;         return false;
    }     }
   
    public GameObject m_hideWhenPicked;     public GameObject m_hideWhenPicked;
   
    public GameObject m_itemPrefab;     public GameObject m_itemPrefab;
   
    public int m_amount = 1;     public int m_amount = 1;
   
    public int m_minAmountScaled = 1;     public int m_minAmountScaled = 1;
   
    public bool m_dontScale;     public bool m_dontScale;
   
    public DropTable m_extraDrops = new DropTable();     public DropTable m_extraDrops = new DropTable();
   
    public string m_overrideName = "";     public string m_overrideName = "";
   
.    public int m_respawnTimeMinutes;     public float m_respawnTimeMinutes;
   
      public float m_respawnTimeInitMin; 
   
      public float m_respawnTimeInitMax; 
   
    public float m_spawnOffset = 0.5f;     public float m_spawnOffset = 0.5f;
   
    public EffectList m_pickEffector = new EffectList();     public EffectList m_pickEffector = new EffectList();
   
    public bool m_pickEffectAtSpawnPoint;     public bool m_pickEffectAtSpawnPoint;
   
    public bool m_useInteractAnimation;     public bool m_useInteractAnimation;
   
    public bool m_tarPreventsPicking;     public bool m_tarPreventsPicking;
   
    public float m_aggravateRange;     public float m_aggravateRange;
   
.      public bool m_defaultPicked;
   
      public bool m_defaultEnabled = true;
   
      public Pickable.SpawnCheck m_spawnCheck;
   
    private ZNetView m_nview;     private ZNetView m_nview;
   
    private Floating m_floating;     private Floating m_floating;
   
    private bool m_picked;     private bool m_picked;
.   
      private int m_enabled = 2;
   
      private long m_pickedTime;
   
      public delegate bool SpawnCheck(Pickable p);
} }