示例#1
0
    public override void Interact(/*Player player,*/ EntityDirection dir = EntityDirection.NONE)
    {
        if (!hasPlanted)
        {
            if (ItemManager.Instance.inventory.itemSlots[UIManager.Instance.selectedIndex].empty)
            {
                return;
            }

            string selectedKey = ItemManager.Instance.inventory.itemSlots[UIManager.Instance.selectedIndex].itemModel.key;
            if (selectedKey.Length < 6)
            {
                return;
            }

            string seedText = selectedKey.Substring(selectedKey.Length - 6);

            string foodKey = selectedKey.Substring(0, selectedKey.Length - 6); //remove seeds

            if (ItemManager.Instance.GetItemData(foodKey) == null || ItemManager.Instance.GetItemData(selectedKey) == null || seedText != "-seeds" || !ItemManager.Instance.inventory.hasEnoughItems(selectedKey, 1))
            {
                return;
            }

            this.itemKey     = foodKey;
            this.itemSeedKey = selectedKey;

            HarvestPrefab prefab = vegetablePrefabs.Find((p) => p.key == itemKey);

            HarvestableEntity newItem = Instantiate <HarvestableEntity>(prefab.entity);
            newItem.parent                  = this.transform;
            newItem.transform.parent        = this.transform;
            newItem.transform.position      = this.transform.position;
            newItem.transform.localPosition = new Vector3(newItem.transform.localPosition.x, newItem.transform.localPosition.y, -0.1f);
            this.harvest    = newItem;
            this.hasPlanted = true;
            ItemManager.Instance.inventory.RemoveItem(itemSeedKey, 1);
        }
        else
        {
            this.harvest.Interact();
        }
    }
示例#2
0
        protected override void SpawnInternal()
        {
            float      colliderDetectionRadius = asset.ColliderDetectionRadius;
            Vector3    spawnPosition           = GetRandomPosition();
            Quaternion spawnRotation           = GetRandomRotation();
            bool       overlapEntities         = false;

            Collider[] overlaps = Physics.OverlapSphere(spawnPosition, colliderDetectionRadius);
            foreach (Collider overlap in overlaps)
            {
                if (OverlapsEntities(overlap))
                {
                    overlapEntities = true;
                    break;
                }
            }
            if (!overlapEntities)
            {
                GameObject        spawnObj = Instantiate(asset.gameObject, spawnPosition, spawnRotation);
                HarvestableEntity entity   = spawnObj.GetComponent <HarvestableEntity>();
                entity.gameObject.SetActive(false);
                // This is the change from GROUND_DETECTION_DISTANCE to squareGizmosHeight
                if (entity.FindGroundedPosition(spawnPosition, squareGizmosHeight, out spawnPosition))
                {
                    entity.SetSpawnArea(this, spawnPosition);
                    BaseGameNetworkManager.Singleton.Assets.NetworkSpawn(spawnObj);
                }
                else
                {
                    // Destroy the entity (because it can't find ground position)
                    Destroy(entity.gameObject);
                    ++pending;
                    Logging.LogWarning(ToString(), "Cannot spawn harvestable, it cannot find grounded position, pending harvestable amount " + pending);
                }
            }
            else
            {
                ++pending;
                Logging.LogWarning(ToString(), "Cannot spawn harvestable, it is collided to another entities, pending harvestable amount " + pending);
            }
        }
示例#3
0
 public void PlantNow()
 {
     hasPlanted   = true;
     this.harvest = prePlantedEntity;
 }