예제 #1
0
        public override void Use()
        {
            ConsumableData consumableData = RoleData.GetCurrConsumableItem();

            if (consumableData != null)
            {
                RoleData.SubConsumableItem(consumableData.id);
                BuffController.AddBuff(consumableData.buffId);
            }
            else
            {
                Debug.Log("身上没有消耗品");
            }
        }
예제 #2
0
        public override void Interact()
        {
            TriggerController selfTriggerController  = gameObject.GetChild("InteractiveCube").GetComponent <TriggerController>();
            TriggerController otherTriggerController = selfTriggerController.GetFirstKeepingTriggerController();

            if (selfTriggerController != null && otherTriggerController != null && otherTriggerController.ITriggerDelegate != null)
            {
                GameObject interactObject = otherTriggerController.ITriggerDelegate.GetGameObject();

                if (interactObject.tag == "NPC")
                {
                    RolePromptController rolePromptController = GetComponentInChildren <RolePromptController>();
                    rolePromptController.killtalk();
                    OnInteractAction(interactObject);
                    AnimManager.Instance.PrintBubble("[color=#FFFFFF,#000000]fgtdfg[/color]", interactObject);
                }
                else if (interactObject.tag == "Ladder")
                {
                    LadderController ladderController = interactObject.GetComponent <LadderController>();
                    BoxCollider      boxCollider      = otherTriggerController.gameObject.GetComponent <BoxCollider>();
                    Bounds           bou = boxCollider.bounds;
                    gameObject.layer = LayerMask.NameToLayer("Default");
                    if ((interactObject.transform.position.y + bou.center.y + ((bou.size.y / 2) - 1.6f)) < transform.position.y)
                    {
                        switch (ladderController.laddertype)
                        {
                        case laddertype.Left:
                            transform.position = new Vector3(interactObject.transform.position.x + CharacterController.radius, transform.position.y - 1.6f, interactObject.transform.position.z);
                            break;

                        case laddertype.Right:
                            transform.position = new Vector3(interactObject.transform.position.x - CharacterController.radius, transform.position.y - 1.6f, interactObject.transform.position.z);
                            break;

                        case laddertype.Center:
                            transform.position = new Vector3(interactObject.transform.position.x, transform.position.y - 1.6f, interactObject.transform.position.z - 0.1f);
                            break;
                        }
                    }
                    else
                    {
                        switch (ladderController.laddertype)
                        {
                        case laddertype.Left:
                            transform.position = new Vector3(interactObject.transform.position.x + CharacterController.radius, transform.position.y, interactObject.transform.position.z);
                            break;

                        case laddertype.Right:
                            transform.position = new Vector3(interactObject.transform.position.x - CharacterController.radius, transform.position.y, interactObject.transform.position.z);
                            break;

                        case laddertype.Center:
                            transform.position = new Vector3(interactObject.transform.position.x, transform.position.y, interactObject.transform.position.z - 0.1f);
                            break;
                        }
                    }
                    if (animatorParams.ContainsKey("ladder_type"))
                    {
                        _animator.SetInteger("ladder_type", (int)ladderController.laddertype);
                    }
                    if (animatorParams.ContainsKey("start_climb_ladder"))
                    {
                        _animator.SetBool("start_climb_ladder", true);
                    }
                }
                else if (interactObject.GetComponent <IInteractable>() != null)
                {
                    IInteractable interactable = interactObject.GetComponent <IInteractable>();
                    if (interactable.CanInteract())
                    {
                        interactable.Interact();
                    }
                }
                else if (interactObject.GetComponent <PortalController>())
                {
                    PortalController portalController = interactObject.GetComponent <PortalController>();
                    if (portalController)
                    {
                        this.OpenPortal(portalController);
                    }
                }
                else if (interactObject.GetComponent <FenceDoorController>())
                {
                    FenceDoorController fenceDoorController = interactObject.GetComponent <FenceDoorController>();
                    if (fenceDoorController)
                    {
                        fenceDoorController.OpenPortal();
                    }
                }
                else
                {
                    if (interactObject != null && interactObject.Equals(null) == false)
                    {
                        DropItemController dropItemController = interactObject.GetComponent <DropItemController>();
                        if (dropItemController != null)
                        {
                            var itemData = ItemManager.Instance.getItemDataById <ItemData>(dropItemController.ItemId);
                            GameManager.Instance.PickupTips("Textures/Icon/" + itemData.icon, itemData.name, itemData.count.ToString());
                            switch (itemData.itemType)
                            {
                            case ItemType.Consumable:
                                Debug.Log("捡到消耗品 id = " + itemData.id);

                                Destroy(interactObject);
                                ConsumableData consumableData = ItemManager.Instance.getItemDataById <ConsumableData>(itemData.id);
                                if (consumableData != null)
                                {
                                    switch (consumableData.consumableUseType)
                                    {
                                    case ConsumableUseType.deposit:
                                        RoleData.AddConsumableItem(itemData.id, itemData.count);
                                        PickupConsumable();
                                        break;

                                    case ConsumableUseType.ImmediateUse:
                                        BuffController.AddBuff(consumableData.buffId);
                                        break;
                                    }
                                }
                                break;

                            case ItemType.Other:
                                RoleData.OtherItemList.Add(itemData);
                                dropItemController.RemoveSelf();
                                break;

                            case ItemType.Equip:
                                var weaponData = ItemManager.Instance.getItemDataById <WeaponData>(dropItemController.ItemId);
                                if (weaponData != null)
                                {
                                    this.JuageEquipPossessType(weaponData);
                                }
                                else
                                {
                                    var equipData = ItemManager.Instance.getItemDataById <EquipData>(itemData.id);
                                    RoleData.EquipData.UseEquip(equipData, interactObject.transform.localPosition + new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(1.0f, 1.5f), Random.Range(-0.5f, 0.5f)));
                                }
                                Destroy(interactObject);
                                break;
                            }
                        }
                        else
                        {
                            var interactive = interactObject.GetComponent <ITriggerDelegate>();
                            if (interactive != null)
                            {
                                Event evt = new Event();
                                evt.Type = EventType.Interact;
                                evt.Data = GetGameObject();
                                interactive.OnEvent(evt);
                            }
                        }
                    }
                }
            }
        }