Exemplo n.º 1
0
    public void StopDragItem(int index)
    {
        if (itemBox != null)
        {
            // IF the item box is dragged outside of the inventory boundaries
            if (!isWithinBounds(itemBox.transform.position, GetComponent <BoxCollider2D>()))
            {
                if (index < currInventory.items.Count)
                {
                    // IF the external inventory is open and IF the item box is inside its boundaries
                    if (externalInventoryReference != null && isWithinBounds(itemBox.transform.position, externalInventoryBoundsReference.GetComponent <BoxCollider2D>()))
                    {
                        if (externalInventoryReference.AddItem(currInventory.items[index]))
                        {
                            currInventory.removeItem(currInventory.items[index]);
                        }

                        externalInventoryBoundsReference.GetComponent <UI_InventoryController>().openInventory(externalInventoryReference);
                    }
                    else
                    {
                        currInventory.DropItem(currInventory.items[index]);
                    }
                }
            }

            Debug.Log(externalInventoryReference == null);

            openInventory(currInventory);
            itemBox.transform.position = startPos;

            inventoryChanged = true;
        }
    }
Exemplo n.º 2
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     // Debug.Log(string.Format("Item collided with: {0}", other.name));
     if (other.transform.CompareTag("Player"))
     {
         _inventoryHandler.AddItem(Item);
         Destroy(gameObject);
     }
 }
Exemplo n.º 3
0
 public void AddAndRemoveItem()
 {
     Assert.DoesNotThrow(() => m_Inventory.AddItem(m_ExistantItem), "Couldn't add item");
     Assert.AreEqual(1, m_Inventory.Count, "Item count incorrect");
     Assert.IsTrue(
         m_Inventory.HasItem(m_ExistantItem.Name, m_ExistantItem.Category),
         "Couldn't find item");
     Assert.DoesNotThrow(() => m_Inventory.RemoveItem(m_ExistantItem), "Couldn't remove item");
     Assert.AreEqual(0, m_Inventory.Count, "Item count incorrect after remove");
     Assert.IsFalse(
         m_Inventory.HasItem(m_ExistantItem.Name, m_ExistantItem.Category),
         "Inventory still has the item");
 }
Exemplo n.º 4
0
    private void Instance_OnSpeechSpoke(Speech speech)
    {
        if (speech == this && !itemGiven_)
        {
            itemGiven_ = true;

            InventoryHandler ih = InventoryHandler.Instance;

            if (ih)
            {
                ih.AddItem(itemIdToGive_, amount);
            }
        }
    }
Exemplo n.º 5
0
    override public void Interact(GameObject go)
    {
        base.Interact(go);

        if (!go)
        {
            return;
        }

        Character        character = go.GetComponent <Character>();
        InventoryHandler ih        = InventoryHandler.Instance;

        if (character && ih)
        {
            Debug.Log("adding item");
            ih.AddItem(itemId_);
            Destroy(gameObject);
        }
    }
Exemplo n.º 6
0
    private void Update()
    {
        Vector3 uV = new Vector3(0.0f, -1.0f, 0.0f);

        Ray ray = new Ray(transform.position, transform.forward);

        if (pI.IsStrafingRight)
        {
            ray = new Ray(transform.position, Quaternion.AngleAxis(
                              90, transform.forward) * uV);
        }
        else if (pI.IsStrafingLeft)
        {
            ray = new Ray(transform.position, Quaternion.AngleAxis(
                              -90, transform.forward) * uV);
        }
        else if (pI.IsWalkingBack)
        {
            ray = new Ray(transform.position, -transform.forward);
        }

        IsColliding = Physics.Raycast(ray, out currentWorldObject,
                                      pI.MoveDistance, ~0, QueryTriggerInteraction.Ignore);


        if (!pI.CanInput)
        {
            if (pI.Bump)
            {
                GameObject temp = currentWorldObject.transform?.gameObject;
                temp?.GetComponent <BreakingWall>()?.Break();
            }

            return;
        }

        if (IsColliding)
        {
            // Definetly change this to do it one time.
            ObjectTouched = currentWorldObject.transform.gameObject;
            // This could be better
            if ((ObjectTouched.layer == 8) || (ObjectTouched.layer == 9))
            {
                objectHolder = ObjectTouched.GetComponent <DataHolder>();
                objectData   = objectHolder?.GetData(inventory.equipedItem);

                mD.DisplayMessage(objectData);
            }
        }

        else
        {
            IsColliding   = false;
            objectData    = null;
            ObjectTouched = null;
            mD.CleanMessage();
        }

        if ((ObjectTouched != null) &&
            !pI.IsStrafingLeft && !pI.IsStrafingRight)
        {
            if (!pI.IsWalking && pI.IsInteracting && IsColliding)
            {
                if (objectData == null)
                {
                    return;
                }

                switch (objectData.InteractionType)
                {
                case InteractionType.isGrabable:
                    inventory.AddItem(objectData as ItemData);
                    objectHolder.DestroyObject();
                    mD.CleanMessage();
                    objectData = null;
                    break;

                case InteractionType.isUsable:
                    interactor =
                        ObjectTouched.GetComponent <ManualInteractor>();

                    InteractionResult itemused =
                        interactor.Toggle(
                            inventory?.equipedItem, transform.position);

                    switch (itemused)
                    {
                    case InteractionResult.WrongIntMessage:
                        StartDialogue(wrongInteaction);
                        break;

                    case InteractionResult.UseItem:
                        inventory.ClearEquiped();
                        break;
                    }
                    break;

                case InteractionType.isExit:
                    interactor =
                        ObjectTouched.GetComponent <ManualInteractor>();
                    interactor.Toggle(
                        inventory?.equipedItem, transform.position);
                    break;

                case InteractionType.isNPC:
                    StartDialogue((objectData as NpcData).Dialogue);
                    break;

                default:
                    print("Porque é que essa coisa é trigger ?");
                    break;
                }
            }

            pI.IsInteracting = false;
        }
    }
Exemplo n.º 7
0
    /// <summary>
    /// Callback Funktion für die Erkennung einer Kollision des Objekts an dem das Script angefügt ist.
    /// </summary>
    /// <param name="other">Objekt mit dem "this" kollidiert ist.</param>
    private void OnTriggerEnter(Collider other)
    {
        // Wenn der Kollisionsmodus deaktiviert ist, beende die Methode
        if (!GlobalDataHandler.GetCollisionState())
        {
            return;
        }

        switch (other.gameObject.tag)
        {
        // Einsammeln eines Collectibles
        case "Collectible":
            InventoryHandler.AddItem(other.gameObject);
            if (GlobalDataHandler.GetActualSceneName() != "Tutorial")
            {
                _objList.RemoveFromList(other.gameObject);
            }
            break;

        // Kollisonsbehandlung mit einem Hindernis der Level
        case "Obstacle":
            EventManager.HitObstacleObjectCollected();
            EventManager.GameEnd();
            if (GlobalDataHandler.GetActualSceneName() != "Tutorial")
            {
                _objList.RemoveItem(other.gameObject);
            }
            break;

        // Einsammeln eines Coins
        case "Points":
            EventManager.ScoreObjectCollected();
            //Fügt dem Inventar hinzu bis die Punkte oben am Score angekommen sind
            other.transform.parent = InventoryHandler.transform;
            if (GlobalDataHandler.GetActualSceneName() != "Tutorial")
            {
                _objList.RemoveFromList(other.gameObject);
            }
            break;

        // Kollisonsbehandlung mit einem Hindernis in dem Tutorial
        case "TutorialObstacle":
            GlobalDataHandler.SetRunMode(RunMode.Idle);
            EventManager.HitTutorialObstacle(CtrlPointHandler.GetActualCtrlPointPosZ());
            break;

        // Durchlaufen eines Portals
        case "Portal":
            if (GlobalDataHandler.GetActualSceneName() == "Tutorial")
            {
                EventManager.DeleteVrStuff();
            }

            EventManager.SwitchScene(other.name);
            break;

        // Durchlaufen eines Kontrollpunktes
        case "Checkpoint":
            if (GlobalDataHandler.GetRunMode() != RunMode.Idle && GlobalDataHandler.GetCollisionState())
            {
                EventManager.EnterCtrlPoint();
            }

            break;
        }
    }