예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (fpsController.enabled)
        {
            EquipSystem equipSystem = GetComponent <EquipSystem>();
            if (CrossPlatformInputManager.GetButtonDown("Interact") && itemInView != null)
            {
                //Interacting with objects in the world
                itemInView.GetComponent <InteractableBase>().OnInteract();
            }
            else if (equipSystem && equipSystem.currentEquippedItem)
            {
                Pickupable pickupable = equipSystem.currentEquippedItem.GetComponent <Pickupable>();
                if (pickupable)
                {
                    //Using item that the player has equipped
                    if (CrossPlatformInputManager.GetButtonDown("Fire1"))
                    {
                        pickupable.OnUse();
                        UseItem?.Invoke(pickupable);
                    }
                    else if (CrossPlatformInputManager.GetButtonDown("DropItem"))
                    {
                        equipSystem.DropItem(pickupable.item);
                    }
                }
            }
        }

        if (CrossPlatformInputManager.GetButtonDown("Cancel"))
        {
            CancelAction?.Invoke();
        }
    }
예제 #2
0
    //死亡
    public override void Die()
    {
        actionManager.Destory();

        //InGameManager.GetInstance().inGameUIManager.DelRole(this.instanceId);
        //base.Die();
        SetAnimatorState(AnimatorState.Dead, 1);

        if (camp == enMSCamp.en_camp_enemy)
        {
            if (killMe.GetObjType() == enObjType.character)
            {
                //爆装备
                InGameBaseCharacter source = (InGameBaseCharacter)killMe;
                if (UnityEngine.Random.Range(0, 100) < conf.outodds)
                {
                    EquipSystem.GetInstance().OutEquip(gameObject, level,
                                                       source.propertys.GetProperty(enCharacterProperty.equipdrop) +
                                                       this.conf.equipdrop);
                }
                EventData.CreateEvent(EventID.EVENT_DATA_KILLENEMY).AddData(source, this).Send();
            }
        }

        transform.GetComponent <BoxCollider>().enabled    = false;
        transform.GetComponent <SphereCollider>().enabled = false;
        Invoke("Delself", 3);
    }
예제 #3
0
 public static EquipSystem GetInstance()
 {
     if (instance == null)
     {
         instance = new EquipSystem();
     }
     return(instance);
 }
예제 #4
0
    void StartAtk()
    {
        state = ActionState.atkbegin;

        if (target == null || target.IsDie())
        {
            state = ActionState.non;
            return;
        }
        if (Vector2.Distance(parent.transform.position, target.transform.position) > parent.GetAtkDis(target))
        {
            state = ActionState.move;
            return;
        }

        if (GameConst.CAMP_ATK[(int)target.camp, (int)parent.camp] == 0)
        {
            if (target.GetObjType() == InGameBaseObj.enObjType.equip)
            {
                InGameBaseEquip equip = (InGameBaseEquip)target;
                EquipData       e     = EquipSystem.GetInstance().RandEquipProperty(equip);
                InGameManager.GetInstance().inGamePlayerManager.AddEquip(e);
                MonoBehaviour.Destroy(equip.gameObject);
                parent.StopAction();
                return;
            }
            else if (target.GetObjType() == InGameBaseObj.enObjType.map)
            {
                InGameBaseMapObj mapobj = (InGameBaseMapObj)target;
                bool             isfin  = mapobj.HandleFuntion(parent);

                if (!isfin)
                {
                    Debug.Log("stop action");
                    parent.StopAction();
                    return;
                }
                Debug.Log("continue action");
            }
        }

        parent.SetAnimatorState(parent.GetAtkAnimator(), parent.GetAtkSpeed());
        atkTime = 0;

        parent.SetDir(target.transform.position.x - parent.transform.position.x);
    }
예제 #5
0
    public bool OnItemUse(ItemBase item)
    {
        if (!allKeysInInventory)
        {
            bool isCorrectKey = keysNeeded.Contains(item);

            //Remove key if it is correct
            if (isCorrectKey)
            {
                keysNeeded.Remove(item);
            }

            //Unlock door and play message if there are no more keys needed
            if (isLocked && keysNeeded.Count == 0)
            {
                isLocked = false;
                if (OnKeyDoorUnlocked != null)
                {
                    OnKeyDoorUnlocked();
                }
            }

            UseItem?.Invoke();
            return(isCorrectKey);
        }
        else
        {
            List <int>       correctKeysIndex = new List <int>();
            InventoryManager inventoryManager = GameManager.Get().playerRef.GetComponent <InventoryManager>();
            for (int i = 0; i < inventoryManager.currentInventory.maxSlots; i++)
            {
                bool isCorrectKey = keysNeeded.Contains(inventoryManager.currentInventory.inventory[i].item);
                if (isCorrectKey)
                {
                    correctKeysIndex.Add(i);
                }
            }

            if (correctKeysIndex.Count >= keysNeeded.Count)
            {
                List <ItemBase> itemsToDelete = new List <ItemBase>();

                for (int i = 0; i < correctKeysIndex.Count; i++)
                {
                    itemsToDelete.Add(inventoryManager.currentInventory.inventory[correctKeysIndex[i]].item);
                }

                for (int i = 0; i < itemsToDelete.Count; i++)
                {
                    inventoryManager.RemoveFromInventory(itemsToDelete[i], 1);
                }
                itemsToDelete.Clear();
                EquipSystem equipSystem = GameManager.Get().playerRef.GetComponent <EquipSystem>();
                Destroy(equipSystem.currentEquippedItem.gameObject);
                correctKeysIndex.Clear();

                isLocked = false;

                if (OnKeyDoorUnlocked != null)
                {
                    OnKeyDoorUnlocked();
                }

                return(true);
            }
            else
            {
                correctKeysIndex.Clear();
                return(false);
            }
        }
    }