예제 #1
0
 private void Awake()
 {
     instance         = this;
     tcc_Main         = GetComponent <TopDownControllerMain>();
     tcc_Interact     = GetComponent <TopDownControllerInteract>();
     td_characterCard = GetComponent <TopDownCharacterCard>();
 }
예제 #2
0
 private void Start()
 {
     tdc_Main            = GetComponent <TopDownControllerMain>();
     td_EquipmentManager = GetComponent <TopDownEquipmentManager>();
     startPos            = transform.position;
     tdc_CharacterCard   = GetComponent <TopDownCharacterCard>();
     //tdc_CharacterCard.activePlayerAi = true;
 }
예제 #3
0
    public void OnEnable()
    {
        td_target = (TopDownControllerMain)target;

        if (TopDownIcon == null)
        {
            TopDownIcon = Resources.Load("TopDownIcon") as Texture;
        }
    }
    private void Start()
    {
        td_CheckUI = TopDownCheckUI.instance;

        tdcc_Main             = GetComponent <TopDownControllerMain>();
        tdcc_NavMeshAgent     = GetComponent <NavMeshAgent>();
        tdcc_InputManager     = TopDownInputManager.instance;
        tdcc_EquipmentManager = GetComponent <TopDownEquipmentManager>();
        tdr_Spellcaster       = GetComponent <TopDownRpgSpellcaster>();
        if (GameObject.FindGameObjectWithTag("MainCamera"))
        {
            tdcc_CameraMain = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
        }
        else if (GameObject.FindObjectOfType <Camera>())
        {
            tdcc_CameraMain = GameObject.FindObjectOfType <Camera>();
        }
    }
 public void ClearCharacterUI()
 {
     occupied        = false;
     characterInSlot = null;
     name.text       = string.Empty;
     if (uiManager.characterPortraitType == CharacterPortraitType.Static)
     {
         portraitPrechosen.sprite  = null;
         portraitPrechosen.enabled = false;
     }
     else if (uiManager.characterPortraitType == CharacterPortraitType.Runtime)
     {
         portraitRuntime.enabled = false;
     }
     if (thisSlotInventory != null)
     {
         inventory = null;
         thisSlotInventory.SetActive(false);
     }
 }
예제 #6
0
    private void Start()
    {
        navMeshAgent = GetComponent <NavMeshAgent>();
        if (GetComponent <TopDownControllerMain>())
        {
            tdc_Main = GetComponent <TopDownControllerMain>();
        }

        tdc_AudioManager = TopDownAudioManager.instance;

        if (GameObject.FindObjectOfType <TopDownAudioManager>())
        {
            tdc_AudioManager = GameObject.FindObjectOfType <TopDownAudioManager>();
        }
        else
        {
            GameObject audioManagerGo = Instantiate(Resources.Load("TD_AudioManager") as GameObject);
            tdc_AudioManager = audioManagerGo.GetComponent <TopDownAudioManager>();
        }
    }
    private void Start()
    {
        if (character != null)
        {
            name      = character.name;
            health    = character.health;
            maxHealth = character.health;
            energy    = character.energy;
            maxEnergy = character.energy;
        }
        else
        {
            name = aiName;
        }

        main             = GetComponent <TopDownControllerMain>();
        interact         = GetComponent <TopDownControllerInteract>();
        equipmentManager = GetComponent <TopDownEquipmentManager>();
        if (TopDownCharacterManager.instance != null)
        {
            characterManager = TopDownCharacterManager.instance;
        }
        if (TopDownUIManager.instance != null)
        {
            npcBar           = TopDownUIManager.instance.npcWorldName.GetComponent <TopDownUINpcNameBar>();
            placeBarOverHead = npcBar.placeBarOverHead;
            uiManager        = TopDownUIManager.instance;
        }

        if (GameObject.FindGameObjectWithTag("MainCamera"))
        {
            mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
        }
        else if (GameObject.FindObjectOfType <Camera>())
        {
            mainCamera = GameObject.FindObjectOfType <Camera>();
        }

        if (GetComponent <TopDownAI>())
        {
            maxHealth = health;
            GetComponent <TopDownAI>().name             = aiName;
            GetComponent <TopDownAI>().voiceSet         = aiVoiceSet;
            GetComponent <TopDownAI>().visionCollider   = aiVision;
            GetComponent <TopDownAI>().detectRadius     = aiDetectRadius;
            GetComponent <TopDownAI>().fieldOfViewAngle = aiFieldOfView;
        }

        if (GetComponent <TopDownControllerInteract>())
        {
            int layerInt = gameObject.layer;

            if (inventoryCamera != null)
            {
                inventoryCamera.GetComponent <Camera>().cullingMask = 1 << layerInt;

                if (TopDownCharacterManager.instance != null)
                {
                    if (TopDownCharacterManager.instance.controllingCharacter != gameObject)
                    {
                        inventoryCamera.SetActive(false);
                    }
                }
            }
        }

        Transform[] allChildren = GetComponentsInChildren <Transform>();
        for (int i = 0; i < allChildren.Length; i++)
        {
            if (allChildren[i].name.Contains("head") || allChildren[i].name.Contains("HEAD") || allChildren[i].name.Contains("Head"))
            {
                nameBarPosition = allChildren[i];
            }
        }
    }
    public void OnPointerClick(PointerEventData eventData)
    {
        main = TopDownCharacterManager.instance.controllingCharacter.GetComponent <TopDownControllerMain>();

        if (main.tdcm_animator.GetBool("TargetInFront") == false)   //We should be able to use slots only when out of combat
        {
            if (eventData.button == PointerEventData.InputButton.Right)
            {
                if (itemInSlot != null && inventory.holdingItem == null)
                {
                    if (GetComponent <TopDownUIItemSlot>().slotType != SlotType.Quickslot)
                    {
                        if (itemInSlot.isItem == true)
                        {
                            //If item we are trying to equip is two handed or ranged weapon, we want to check if there is a shield equipped and to deequip it
                            if (itemInSlot.weaponHoldingType == WeaponHoldingType.TwoHanded || itemInSlot.weaponType == WeaponType.Ranged)
                            {
                                if (inventory.currentEquipmentSlots.equipmentSlots[3].itemInSlot)
                                {
                                    inventory.currentEquipmentSlots.equipmentSlots[3].UseSlottedItem();
                                    //print(inventory.currentEquipmentManager.gameObject.name);

                                    inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[3]);
                                    ClearSlot(inventory.currentEquipmentSlots.equipmentSlots[3]);
                                }
                            }

                            //If item we are trying to equip is shield, we want to check if there is a two handed weapon equipped and to deequip it
                            if (itemInSlot.itemType == ItemType.Shield)
                            {
                                if (inventory.currentEquipmentSlots.equipmentSlots[2].itemInSlot != null && (inventory.currentEquipmentSlots.equipmentSlots[2].itemInSlot.weaponHoldingType == WeaponHoldingType.TwoHanded ||
                                                                                                             inventory.currentEquipmentSlots.equipmentSlots[2].itemInSlot.weaponType == WeaponType.Ranged))
                                {
                                    inventory.currentEquipmentSlots.equipmentSlots[2].UseSlottedItem();
                                    //print(inventory.currentEquipmentManager.gameObject.name);

                                    inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[2]);
                                    ClearSlot(inventory.currentEquipmentSlots.equipmentSlots[2]);
                                }
                            }

                            if (inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType] != null)
                            {
                                if (inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].itemInSlot == null)
                                {
                                    //Debug.Log("No item equiped.");

                                    UseSlottedItem();
                                    //print(inventory.currentEquipmentManager.gameObject.name);

                                    inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].AddItemToSlot(itemInSlot);
                                    if (slottedInQuick != null)
                                    {
                                        inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].slottedInQuick = slottedInQuick;
                                        slottedInQuick = null;
                                    }
                                    inventory.RemoveItem(itemInSlot);
                                }
                                else if (inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].itemInSlot == itemInSlot)
                                {
                                    //Debug.Log("This item is equiped.");

                                    UseSlottedItem();
                                    //print(inventory.currentEquipmentManager.gameObject.name);

                                    inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType]);
                                    inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].AddItemToSlot(itemInSlot);
                                }
                                else if (inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].itemInSlot != itemInSlot)
                                {
                                    //Debug.Log("Other item is equiped.");

                                    inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].UseSlottedItem();
                                    //print(inventory.currentEquipmentManager.gameObject.name);

                                    inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType]);
                                    inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].AddItemToSlot(itemInSlot);

                                    UseSlottedItem();
                                    //print(inventory.currentEquipmentManager.gameObject.name);

                                    inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].AddItemToSlot(itemInSlot);
                                    if (slottedInQuick != null)
                                    {
                                        inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].slottedInQuick = slottedInQuick;
                                        slottedInQuick = null;
                                    }
                                    inventory.RemoveItem(itemInSlot);
                                }
                            }

                            ClearSlot(this);

                            /*if (TopDownAudioManager.instance.inventoryItemUseAudio != null) {
                             *  Instantiate(TopDownAudioManager.instance.inventoryItemUseAudio, Vector3.zero, Quaternion.identity);
                             * }*/
                        }
                        else   //If this is scroll we want different behaviour

                        {
                            if (TopDownAudioManager.instance.spellUseAudio != null)
                            {
                                Instantiate(TopDownAudioManager.instance.spellUseAudio, Vector3.zero, Quaternion.identity);
                            }

                            TopDownCharacterManager.instance.controllingCharacter.GetComponent <TopDownRpgSpellcaster>().activeSpell   = itemInSlot;
                            TopDownCharacterManager.instance.controllingCharacter.GetComponent <TopDownRpgSpellcaster>().spellItemSlot = this;
                            TopDownCharacterManager.instance.controllingCharacter.GetComponent <TopDownRpgSpellcaster>().castingSpell  = true;

                            if (TopDownUIManager.instance.charInfoPanel.inventoryActive)
                            {
                                if (TopDownUIManager.instance.inventory.GetComponent <CanvasGroup>().alpha > 0)
                                {
                                    TopDownUIManager.instance.SetUIState(TopDownUIManager.instance.inventory);
                                    TopDownUIManager.instance.charInfoPanel.inventoryActive = false;
                                }
                            }
                            if (TopDownUIManager.instance.charInfoPanel.questLogActive)
                            {
                                if (TopDownUIManager.instance.questLog.GetComponent <CanvasGroup>().alpha > 0)
                                {
                                    TopDownUIManager.instance.SetUIState(TopDownUIManager.instance.questLog);
                                    TopDownUIManager.instance.charInfoPanel.inventoryActive = true;
                                }
                            }
                        }
                    }
                }
            }
            else if (eventData.button == PointerEventData.InputButton.Left)
            {
                if (inventory.holdingItem != null)
                {
                    if (GetComponent <TopDownUIItemSlot>().slotType == SlotType.Equipment)                                                                                        //Is the slot we clicked on of Equipment type
                    {
                        if (GetComponent <TopDownUIEquipmentSlot>().equipmentType == inventory.holdingItem.itemType)                                                              //Is the item we are holding of the same type as the Equipment Slot (so we do not equip helm on weapon etc...)
                        {
                            if (GetComponent <TopDownUIEquipmentSlot>().itemInSlot != inventory.holdingItem && GetComponent <TopDownUIEquipmentSlot>() != inventory.previousSlot) //We do not want to swap the same item

                            //If item we are trying to equip is two handed weapon, we want to check if there is a shield equipped and to deequip it
                            {
                                if (inventory.holdingItem.weaponHoldingType == WeaponHoldingType.TwoHanded)
                                {
                                    if (inventory.currentEquipmentSlots.equipmentSlots[3].itemInSlot != null)
                                    {
                                        inventory.currentEquipmentSlots.equipmentSlots[3].UseSlottedItem();

                                        inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[3]);
                                        ClearSlot(inventory.currentEquipmentSlots.equipmentSlots[3]);
                                    }
                                }

                                //If item we are trying to equip is shield, we want to check if there is a two handed weapon equipped and to deequip it
                                if (inventory.holdingItem.itemType == ItemType.Shield)
                                {
                                    if (inventory.currentEquipmentSlots.equipmentSlots[2].itemInSlot != null && inventory.currentEquipmentSlots.equipmentSlots[2].itemInSlot.weaponHoldingType == WeaponHoldingType.TwoHanded)
                                    {
                                        inventory.currentEquipmentSlots.equipmentSlots[2].UseSlottedItem();

                                        inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[2]);
                                        ClearSlot(inventory.currentEquipmentSlots.equipmentSlots[2]);
                                    }
                                }

                                TopDownItemObject tmpItem = inventory.currentEquipmentManager.currentEquipment[(int)inventory.holdingItem.itemType];

                                if (inventory.previousSlot.slottedInQuick != null)   //If item we are holding is slotted in Quick Slot, we want to keep the same Quick Slot reference
                                {
                                    slottedInQuick = inventory.previousSlot.slottedInQuick;
                                    inventory.previousSlot.slottedInQuick = null;
                                }
                                ClearSlot(inventory.previousSlot); //Clear previous Slot
                                inventory.previousSlot = null;
                                if (itemInSlot != null)
                                {
                                    inventory.currentEquipmentManager.UnequipItem(itemInSlot);
                                }
                                AddItemToSlot(inventory.holdingItem);
                                UseSlottedItem();

                                if (tmpItem != null)
                                {
                                    inventory.holdingItem = tmpItem;
                                    inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = inventory.holdingItem.itemIcon;
                                }
                                else
                                {
                                    inventory.holdingItem = null;
                                    inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null;
                                    inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f;
                                }
                            }
                            else
                            {
                                inventory.holdingItem = null;
                                inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null;
                                inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f;
                            }
                        }
                        else
                        {
                            //Debug.Log("This is NOT the same equipment type");
                        }
                    }
                    else if (GetComponent <TopDownUIItemSlot>().slotType == SlotType.Inventory)
                    {
                        if (itemInSlot == null)
                        {
                            if (inventory.previousSlot != null)
                            {
                                if (inventory.currentEquipmentManager.currentEquipment[(int)inventory.previousSlot.itemInSlot.itemType] == inventory.previousSlot.itemInSlot)
                                {
                                    inventory.previousSlot.itemInSlot.UnuseItem();
                                }
                                if (inventory.previousSlot.slottedInQuick != null)
                                {
                                    inventory.previousSlot.slottedInQuick.originalSlot = this;
                                    slottedInQuick = inventory.previousSlot.slottedInQuick;
                                    inventory.previousSlot.slottedInQuick = null;
                                }
                                ClearSlot(inventory.previousSlot);
                                inventory.previousSlot = null;
                            }
                            AddItemToSlot(inventory.holdingItem);
                            inventory.holdingItem = null;
                            inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null;
                            inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f;
                        }
                        else
                        {
                            if (itemInSlot == inventory.holdingItem && GetComponent <TopDownUIItemSlot>() == inventory.previousSlot)  //This is the same item, remove holding item (we must check if it is the same slot, because we can have multiple same items in inventory)
                            {
                                inventory.holdingItem = null;
                                inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null;
                                inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f;
                            }
                            else
                            {
                                if (inventory.previousSlot != null)
                                {
                                    if (inventory.previousSlot.slottedInQuick != null)
                                    {
                                        inventory.previousSlot.slottedInQuick.originalSlot = this;
                                        slottedInQuick = inventory.previousSlot.slottedInQuick;
                                        inventory.previousSlot.slottedInQuick = null;
                                    }

                                    TopDownItemObject tmpItemToGrab = itemInSlot;

                                    ClearSlot(inventory.previousSlot);
                                    inventory.previousSlot = null;

                                    AddItemToSlot(inventory.holdingItem);

                                    inventory.holdingItem = tmpItemToGrab;

                                    inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = tmpItemToGrab.itemIcon;
                                    inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 1f;

                                    ClearTooltip();
                                }

                                /*
                                 * TopDownItemObject tmpItem = inventory.holdingItem;
                                 *
                                 * if (inventory.previousSlot != null) {
                                 *  if (inventory.currentEquipmentManager.currentEquipment[(int)inventory.previousSlot.itemInSlot.itemType] == inventory.previousSlot.itemInSlot) {
                                 *      inventory.previousSlot.itemInSlot.UnuseItem();
                                 *  }
                                 *  if (inventory.previousSlot.slottedInQuick != null) {
                                 *      inventory.previousSlot.slottedInQuick.originalSlot = this;
                                 *      slottedInQuick = inventory.previousSlot.slottedInQuick;
                                 *      inventory.previousSlot.slottedInQuick = null;
                                 *  }
                                 *  ClearSlot(inventory.previousSlot);
                                 *  inventory.previousSlot = null;
                                 * }
                                 *
                                 * GrabItemInSlot();
                                 *
                                 * AddItemToSlot(tmpItem);
                                 */
                            }
                        }
                    }
                    else if (GetComponent <TopDownUIItemSlot>().slotType == SlotType.Quickslot)
                    {
                        if (GetComponent <TopDownUIQuickSlot>().originalSlot != null)
                        {
                            GetComponent <TopDownUIQuickSlot>().originalSlot.slottedInQuick = null;
                        }
                        ClearSlot(this);
                        AddItemToSlot(inventory.holdingItem);
                        if (inventory.previousSlot.slotType != SlotType.Quickslot)
                        {
                            if (inventory.previousSlot.slottedInQuick == null)
                            {
                                inventory.previousSlot.slottedInQuick = GetComponent <TopDownUIQuickSlot>();
                            }
                            else
                            {
                                if (inventory.previousSlot.slottedInQuick != this)
                                {
                                    inventory.previousSlot.slottedInQuick.originalSlot = null;
                                    ClearSlot(inventory.previousSlot.slottedInQuick);
                                    inventory.previousSlot.slottedInQuick = GetComponent <TopDownUIQuickSlot>();
                                }
                            }
                            GetComponent <TopDownUIQuickSlot>().originalSlot = inventory.previousSlot;
                        }
                        else
                        {
                            ClearSlot(inventory.previousSlot);
                            GetComponent <TopDownUIQuickSlot>().originalSlot = inventory.previousSlot.GetComponent <TopDownUIQuickSlot>().originalSlot;
                            inventory.previousSlot.GetComponent <TopDownUIQuickSlot>().originalSlot.slottedInQuick = GetComponent <TopDownUIQuickSlot>();
                            inventory.previousSlot.GetComponent <TopDownUIQuickSlot>().originalSlot = null;
                        }

                        inventory.holdingItem = null;
                        inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null;
                        inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f;
                    }
                }
                else
                {
                    if (itemInSlot != null)
                    {
                        GrabItemInSlot();
                    }
                }
            }
        }
    }