Exemple #1
0
    protected override bool InnerIsFulfilled()
    {
        ItemInWorld item = tree.AttachedBrain.GetComponent <Toy>().AssignedItemToPickUp;

        if (item == null)
        {
            return(false);
        }

        location.SetValue(item.transform.position);

        return(true);
    }
Exemple #2
0
    /// <summary>
    /// Helper method for instantiating an item
    /// </summary>
    /// <param name="item">The item to be instantiated from.</param>
    /// <param name="startingPos">The starting postion</param>
    /// <param name="rotation">The starting rotation</param>
    public static ItemInWorld CreateItem(Item item, Vector3 startingPos = default, Quaternion rotation = default)
    {
        ItemInWorld itemInWorld = Instantiate(item.ModelPrefab, startingPos, rotation).AddComponent <ItemInWorld>();

        itemInWorld.transform.parent = MapValuesDict.Instance.ItemsInWorld;
        itemInWorld.transform.localScale.Scale(MapValuesDict.Instance.ObjectScaleVector);
        itemInWorld.item = item;
        Rigidbody body = itemInWorld.gameObject.AddComponent <Rigidbody>();

        body.collisionDetectionMode = CollisionDetectionMode.Continuous;
        Vector3 randomDir = new Vector3(Random.value * 2 - 1, 0, Random.value * 2 - 1).normalized;

        randomDir.y   = 2;
        body.velocity = randomDir;
        return(itemInWorld);
    }
Exemple #3
0
    protected override bool InnerIsFulfilled()
    {
        // set the position from where to check
        Vector3 position;

        if (positionValue == null) // if the positionValue is null then use the toy
        {
            position = tree.AttachedBrain.transform.position;
        }
        else
        {
            // If there was no position inside the value then return fals
            if (positionValue.TryGetValue(out position) == false)
            {
                return(false);
            }
        }

        // Get all colliders and look if any of them are Items. Get the closest one
        Collider[]  colls    = Physics.OverlapSphere(position, distanceToCheck);
        float       closest  = float.MaxValue;
        ItemInWorld bestItem = null;

        for (int i = 0; i < colls.Length; i++)
        {
            if (colls[i].TryGetComponent(out ItemInWorld item) == true)
            {
                float newDistance = (position - item.transform.position).sqrMagnitude;
                if (newDistance < closest)
                {
                    bestItem = item;
                    closest  = newDistance;
                }
            }
        }

        // If no item was found return false
        if (bestItem == null)
        {
            return(false);
        }

        // Set the itemValue and return true
        itemValue.SetValue(bestItem);
        return(true);
    }
Exemple #4
0
    private void AddItem(RPGItem item, int Amount)
    {
        foreach (ItemInWorld i in ShopItems)
        {
            if (i.rpgItem.UniqueId == item.UniqueId)
            {
                i.CurrentAmount += Amount;
                return;
            }
        }

        ItemInWorld itemInWorld = new ItemInWorld();

        itemInWorld.UniqueItemId  = item.UniqueId;
        itemInWorld.rpgItem       = item;
        itemInWorld.CurrentAmount = Amount;
        ShopItems.Add(itemInWorld);
    }
Exemple #5
0
    void CreateInputDetect()
    {
        Event e = Event.current;

        // Debug.Log(e.ToString());
        switch (e.type)
        {
        case EventType.KeyUp:
            if (e.control == true || e.keyCode == KeyCode.LeftControl)
            {
                GameObject g = new GameObject();
                g.transform.position = pos;
                editing = g.AddComponent <ItemInWorld>();
                g.name  = "ItemInWorld - ";
                g.AddComponent <SpriteRenderer>();
                refreshItemsInWorld();
            }
            return;
        }
    }
Exemple #6
0
    protected void AddItem(RPGItem item, List <ItemInWorld> BaseLootItems)
    {
        foreach (ItemInWorld i in BaseLootItems)
        {
            if (i.rpgItem.UniqueId == item.UniqueId)
            {
                return;
            }
        }

        ItemInWorld itemInWorld = new ItemInWorld();

        itemInWorld.rpgItem      = item;
        itemInWorld.UniqueItemId = item.UniqueId;
        //if (item.Stackable)
        itemInWorld.CurrentAmount = StackAmount;
        //else
        //itemInWorld.CurrentAmount = 1;
        BaseLootItems.Add(itemInWorld);
    }
Exemple #7
0
    private IEnumerator Gather(Resource resource, DynamicValue delayedTime)
    {
        if (resource.TryCollecting(ActiveTool != null ? ActiveTool.Tool : null))
        {
            Animator.SetTrigger("hit");
            yield return(new WaitForSeconds(0.1f));

            float animationTime = MecanimUtil.GetActiveAnimationDuration(Animator, 0);
            yield return(new WaitForSeconds(animationTime * 0.8f));

            Resource.GatheringDrop gatheringDrop = resource.Gather(out ResourceItem item);
            switch (gatheringDrop)
            {
            case Resource.GatheringDrop.SpawnInWorld:
                ItemInWorld.CreateItem(item, transform.position + transform.up * 1.8f);
                break;

            case Resource.GatheringDrop.DirectlyIntoInventory:
                if (Inventory.CapacityLeft < item.TotalWeight && Inventory.Add(item) == false)
                {
                    goto case Resource.GatheringDrop.SpawnInWorld;
                }
                break;

            default:
                Debug.LogError("case " + gatheringDrop + " not found!");
                break;
            }

            delayedTime.SetValue(new DelayedTime(true, animationTime * 0.2f + 1));
        }
        else
        {
            Animator.SetTrigger("fail");
            yield return(new WaitForSeconds(0.1f));

            float animationTime = MecanimUtil.GetActiveAnimationDuration(Animator, 0) + 1;
            delayedTime.SetValue(new DelayedTime(true, animationTime));
        }
    }
Exemple #8
0
 public override void InnerRestart()
 {
     base.InnerRestart();
     item  = null;
     state = InnerState.Setup;
 }
Exemple #9
0
    private void AddItem(RPGItem item, int Amount)
    {
        foreach(ItemInWorld i in ShopItems)
        {
            if (i.rpgItem.UniqueId == item.UniqueId)
            {
                i.CurrentAmount += Amount;
                return;
            }
        }

        ItemInWorld itemInWorld = new ItemInWorld();
        itemInWorld.UniqueItemId = item.UniqueId;
        itemInWorld.rpgItem = item;
        itemInWorld.CurrentAmount = Amount;
        ShopItems.Add(itemInWorld);
    }
Exemple #10
0
    protected void AddItem(RPGItem item, List<ItemInWorld> BaseLootItems)
    {
        foreach(ItemInWorld i in BaseLootItems)
        {
            if (i.rpgItem.UniqueId == item.UniqueId)
                return;
        }

        ItemInWorld itemInWorld = new ItemInWorld();
        itemInWorld.rpgItem = item;
        itemInWorld.UniqueItemId = item.UniqueId;
        //if (item.Stackable)
            itemInWorld.CurrentAmount = StackAmount;
        //else
            //itemInWorld.CurrentAmount = 1;
        BaseLootItems.Add(itemInWorld);
    }
Exemple #11
0
    void OnSceneGUI()
    {
        if (items == null)
        {
            refreshItemsInWorld();
        }

        pos   = Event.current.mousePosition;
        pos.y = SceneView.currentDrawingSceneView.camera.pixelHeight - pos.y;
        pos   = SceneView.currentDrawingSceneView.camera.ScreenToWorldPoint(pos);
        pos.z = -0.01f;

        if (editing == null)
        {
            CreateInputDetect();
        }

        Handles.BeginGUI();

        foreach (ItemInWorld i in items)
        {
            if (i == editing)
            {
                if (inworldButton(i.transform.position, Color.cyan))
                {
                    editing = null;
                }

                if (inworldButton(i.transform.position + new Vector3(1, 0, 0), Color.red))
                {
                    DestroyImmediate(editing.gameObject);
                    refreshItemsInWorld();
                    editing = null;
                    return;
                }
            }
            else
            {
                if (inworldButton(i.transform.position, Color.blue))
                {
                    editing = i;
                }
            }
        }

        if (editing == null)
        {
            label("No item editing");
        }
        else
        {
            string item = getItems();

            if (item != "None")
            {
                setItem(id.getItem(item).GetComponent <Item>());
            }

            GUILayout.BeginHorizontal();
            if (button("-"))
            {
                editing.GetComponent <SpriteRenderer>().sortingOrder = editing.GetComponent <SpriteRenderer>().sortingOrder - 1;
                EditorUtility.SetDirty(editing.gameObject);
                EditorUtility.SetDirty(editing);
            }
            label(editing.GetComponent <SpriteRenderer>().sortingOrder.ToString());

            if (button("+"))
            {
                editing.GetComponent <SpriteRenderer>().sortingOrder = editing.GetComponent <SpriteRenderer>().sortingOrder + 1;
                EditorUtility.SetDirty(editing.gameObject);
                EditorUtility.SetDirty(editing);
            }
            GUILayout.EndHorizontal();



            if (editRot == true)
            {
                if (button("Edit Position"))
                {
                    editRot = false;
                }
                //  rotationHandle(editing.gameObject);
            }
            else
            {
                if (button("Edit Rotation"))
                {
                    editRot = true;
                }
                // rotationHandle(editing.gameObject);
            }

            if (button("Item Respawns = " + editing.respawn.ToString(), 150, 30))
            {
                editing.respawn = !editing.respawn;
            }

            if (editing.respawn == true)
            {
                GUILayout.BeginHorizontal();
                label("Respawn Rate (hours) = " + respawnRate.ToString(), 200, 30);
                int.TryParse(textInput(respawnRate.ToString()), out respawnRate);
                editing.respawnRate = respawnRate;
                EditorUtility.SetDirty(editing);
                GUILayout.EndHorizontal();
            }
        }
        Handles.EndGUI();

        if (editing == null)
        {
        }
        else
        {
            if (editRot == true)
            {
                rotationHandle(editing.gameObject);
            }
            else
            {
                positionHandle(editing.gameObject);
            }
        }
    }