Exemplo n.º 1
0
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();
                if (target == null)
                {
                    continue;
                }

                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    continue;
                }
                //                  TurningOnAndOffFoV(target);         Possible feature to be able to not see the FoV of each enemy and be able to turn it on only for enemies that player wants
                if (Input.GetMouseButtonDown(0))
                {
                    if (!CheckForDoubleClick())
                    {
                        agent.speed = 3f;
                        GetComponent <Fighter>().Attack(target.gameObject);
                    }
                    else if (CheckForDoubleClick())
                    {
                        agent.speed = 5.66f;
                        GetComponent <Fighter>().Attack(target.gameObject);
                    }
                }
                SetCursor(CursorType.Combat);
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());

            foreach (RaycastHit hit in hits)
            {
                //check if the clickable object has a combat target if not fail
                CombatTarget target = hit.collider.GetComponent <CombatTarget>();
                if (target == null)
                {
                    continue;
                }

                //Checks if it has a health compnent if not fail
                if (!fighter.CanAttack(target.gameObject))
                {
                    continue;
                }

                if (Input.GetMouseButtonDown(0))
                {
                    fighter.Attack(target.gameObject);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());

            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();

                if (!target)
                {
                    continue;
                }

                GameObject targetGameObject = target.gameObject;

                if (!fighter.CanAttack(targetGameObject))
                {
                    continue;
                }

                if (Input.GetMouseButton(0))
                {
                    fighter.Attack(targetGameObject);
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());

            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();

                // if the hit target does not have a CombatTarget component we
                // probably clicked the player and we don't want to attack that
                if (target == null)
                {
                    continue;
                }

                // If the target is not (longer) attackable please don't regard it at all.
                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    continue;
                }

                if (Input.GetMouseButtonDown(0))
                {
                    GetComponent <Fighter>().Attack(target.gameObject);
                }

                // This is put outside here for later planned cursor affordance
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        private bool InteractWithCombat()
        {
            Ray ray = GetMouseRay();

            RaycastHit[] hits = Physics.RaycastAll(ray);

            foreach (var hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();

                if (target == null)
                {
                    continue;
                }

                if (!_fighter.CanAttack(target.gameObject))
                {
                    continue;
                }

                if (Input.GetMouseButton(1))
                {
                    _fighter.Attack(target.gameObject);
                }

                return(true);
            }

            return(false);
        }
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits) //guckt ob ein angeklicktes Objekt das CombatTarget.cs besitzt
            {
                //guckt ob das raycastete Objekt (hover) ein CombatTarget hat, falls nicht, wird die schleife einfach wieder verlassen
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();
                if (target == null)
                {
                    continue;
                }

                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    continue;   //wenn false zurück gegeben wird, wird die Schleife verlassen
                }

                if (Input.GetMouseButton(0)) //Falls es ein CombatTarget hat und angeklickt wird, wird Angegriffen
                {
                    GetComponent <Fighter>().Attack(target.gameObject);
                }
                return(true);
            }
            return(false);
        }
        //returns all of the things that it hits
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());

            //execute block for each hit of the targets that were hit
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();

                //if it can attack then go to the next thing in the for loop
                if (!GetComponent <Fighter>().CanAttack(target))
                {
                    continue;
                }

                //attacks the target
                if (Input.GetMouseButtonDown(0))
                {
                    GetComponent <Fighter>().Attack(target);
                }
                return(true);
            }
            //return false if no targets were located bascially charcter doesnt move if target is hit
            return(false);
        }
Exemplo n.º 8
0
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                // original try.
                // if(hit.collider != null ){
                //     var player = GetComponent<Combat.Fighter>();
                //     player.Fight();
                // }
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();
                if (!GetComponent <Fighter>().CanAttack(target))
                {
                    continue;
                }

                if (Input.GetMouseButtonDown(0))
                {
                    print("in here");
                    GetComponent <Fighter>().Attack(target);
                    target.GetComponent <Health>().TakeDamage(5f);
                }
                return(true);
            }
            return(false);
        }
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                //if any item has rigidbody or collider then it's enemy
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();

                //if target doesn't have combat target, leave
                if (target == null)
                {
                    continue;
                }

                //No target, so leave the rest below & check new item
                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    continue;
                }

                //if there's enemy, Attack
                if (Input.GetMouseButton(0))
                {
                    GetComponent <Fighter>().Attack(target.gameObject);
                }
                return(true);
            }
            return(false); //No enemy to kill
        }
Exemplo n.º 10
0
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();
                if (target == null)
                {
                    continue;
                }

                // GameObject targetGameObject = target.gameObject;
                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    continue;
                }

                if (Input.GetMouseButton(0) && !target.tag.Equals("Player"))
                {
                    GetComponent <Fighter>().Attack(target.gameObject);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 11
0
        // InteractWithCombat occurs when the player clicks down on an enemy target.
        private bool InteractWithCombat()
        {
            // When the mouse ray hits an enemy target, it will call the Attack method
            // in the Fighter component.
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();
                if (target == null)
                {
                    continue;
                }

                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    continue;
                }

                if (Input.GetMouseButton(0))
                {
                    GetComponent <Fighter>().Attack(target.gameObject);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 12
0
        private bool InteractWithCombat()
        {
            // to find an object that might be obscured by another
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());

            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();

                if (target == null)
                {
                    continue;
                }

                if (!fighter.CanAttack(target.gameObject))
                {
                    continue;
                }

                if (Input.GetMouseButton(0))
                {
                    fighter.Attack(target.gameObject);
                }
                // just hovering over the target OR is actively attacking it
                // able to change the UI cursor, for example
                // if i'm hovering an enemy, i wont display the movement cursor. Instead, i'll show the attack cursor
                return(true);
            }
            return(false);
        }
Exemplo n.º 13
0
    /// <summary>
    /// Uses the ability on what the player is current targeting or attacking.
    /// </summary>
    /// <param name="user"></param>
    /// <returns></returns>
    private bool UseOnTarget(GameObject user, Transform target)
    {
        //Get references to combat target and make sure its valid
        CombatTarget combattarget = target.GetComponent <CombatTarget>();

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

        //Get Health component of target
        var targethealth = target.GetComponent <Health>();

        //Check if target is in range of the ability
        if (!InAbilityRange(target))
        {
            return(false);
        }

        //Check if the player has enough stat to use the ability
        if (!CanUseAbility())
        {
            return(false);
        }

        //Determine what type of effect on target
        if (m_DamageType == StatType.PhysicalDamage)
        {
            AttackTarget(user, targethealth);
            return(true);
        }
        return(false);
    }
Exemplo n.º 14
0
        private bool InteractWithCombat()
        {
            //collect all hits along raycast
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());

            //iterate through all hits from raycast
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();

                //if the player (fighter) cannot attack continue (skip the rest of the code and move to next iteration)
                if (!GetComponent <Fighter>().CanAttack(target))
                {
                    continue;
                }

                //else taget != null
                //if left mouse buttin is clicked
                if (Input.GetMouseButtonDown(0))
                {
                    //trigger attack function with correct target parameter
                    GetComponent <Fighter>().Attack(target);
                }

                //return true that we are interacting with combat
                return(true);
            }

            //return false that we are not interacting with combat
            return(false);
        }
Exemplo n.º 15
0
        private CombatTarget checkCombatHover()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();
                if (target == null)
                {
                    continue;
                }
                if (target.tag == "Player")
                {
                    continue;
                }

                if (!GetComponent <Fighter>().IsTargetAlive(target.gameObject))
                {
                    continue;
                }

                SetCursor(CursorType.Combat);
                return(target);
            }
            return(null);
        }
Exemplo n.º 16
0
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();
                if (target == null)
                {
                    continue;
                }


                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    // continue means go on to next item in foreach loop, not continue down the page
                    continue;
                }

                if (Input.GetMouseButtonDown(0))
                {
                    GetComponent <Fighter>().Attack(target.gameObject);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 17
0
    bool CombatMove()
    {
        RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
        foreach (RaycastHit hit in hits)
        {
            CombatTarget target = hit.transform.GetComponent <CombatTarget>();
            if (target == null)
            {
                continue;
            }

            GameObject targetGO = target.gameObject;
            if (!GetComponent <Fighter>().CanAttack(targetGO))
            {
                continue;
            }

            if (Input.GetMouseButton(1))
            {
                GetComponent <Fighter>().Attack(targetGO);
            }
            return(true);
        }
        return(false);
    }
Exemplo n.º 18
0
        private bool InteractWithCombat()
        {
            foreach (var raycastHit in Physics.RaycastAll(GetMouseRay()))
            {
                CombatTarget target = raycastHit.transform.GetComponent <CombatTarget>();
                if (target == null)
                {
                    continue;
                }

                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    continue;
                }

                if (Input.GetMouseButton(0))
                {
                    _fighter.Attack(target.gameObject);
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 19
0
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();
                if (target == null)
                {
                    continue;
                }

                GameObject targetGameObject = target.gameObject;
                // if the target is null, skip the rest of the statements in this foreach loop
                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    continue; // continue to the next section of the foreach loop
                }
                if (Input.GetMouseButton(0))
                {
                    GetComponent <Fighter>().Attack(target.gameObject);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 20
0
        //////////////////////////////////////////////////////////////////////////////////////////
        private bool InteractWithCombat()
        {
            //  For our combat we want to check for the Combat Target Component to
            //  make durr our target is an entity that can be targetet.
            RaycastHit[] hits = Physics.RaycastAll(GetCursorRay());

            foreach (var hit in hits)
            {
                CombatTarget combatTarget = hit.collider.GetComponent <CombatTarget>();
                if (combatTarget == null)
                {
                    continue;
                }

                if (!GetComponent <Fighter>().CanAttack(combatTarget.gameObject))
                {
                    continue;
                }

                if (Input.GetMouseButtonDown(0))
                {
                    this.GetComponent <Fighter>().TryToAttack(combatTarget.gameObject);
                }
                //  We want to return true here so we get the bool even if we just hover
                //  over target with the cursor (TODO: special mouse behaviour).
                return(true);
            }

            return(false);
        }
Exemplo n.º 21
0
        private bool InteractWithCombat()
        {
            //Funcka, któa ustawia przeciwka jako cel priorytetowy. Może zdażyć się, że przeciwnik bedzie np za przeszkodzą i go nie widzimy, wtedy nasza postać wykrywa go i atakuje
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            //Dla każdego hita stowrzy tzn recast.               Jeden hit --> cw hitsach :D ??
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();
                //Sprawdzamy czy występuje znaznaczony GameObject
                if (target == null)
                {
                    continue;
                }

                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    continue;
                }
                // Prawym kliknięciem myszy rozpoczyna atakować wroga
                if (Input.GetMouseButton(0))
                {
                    GetComponent <Fighter>().Attack(target.gameObject);
                }
                //Zwracany true poza petlą ponieważ chcemy, żeby została zwrócona wartość true, jesli zakończymy walkę
                return(true);
            }
            //Po upuszczeniu pętli zwracamy false poniewąż znaleźlismy więcej celów
            return(false);
        }
Exemplo n.º 22
0
        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();
                if (target == null)
                {
                    continue;
                }

                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    continue;
                }

                if (Input.GetMouseButton(0))
                {
                    GetComponent <Fighter>().Attack(target.gameObject);
                }
                SetCursor(CursorType.Combat);
                return(true);
            }
            return(false);
        }
        private bool InteractWithCombat()
        {
            // Each click by the mouse generates into a Raycast hit. Hits are stored and iterated to check if the player has clicked on
            // an interactable object, such as an enemy
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent <CombatTarget>();
                if (target == null)
                {
                    continue;
                }

                // Checks if hit is on a enemy, if true, then checks if enemy is alive. If the enemy is dead, then
                // nothing happens and the next hit in the RaycastHit array is iterated
                if (!GetComponent <Fighter>().CanAttack(target.gameObject))
                {
                    continue;
                }

                if (Input.GetMouseButtonDown(0))
                {
                    GetComponent <Fighter>().Attack(target.gameObject);
                }
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Combat raycasting should supercede movement. If I clock the target, but a tree is obscuruing it, the enemy should take priority
        /// </summary>
        private bool InteractWithCombat()
        {
            //Returns all of the things that the ray hits, not just the first
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());

            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.gameObject.GetComponent <CombatTarget>();
                // Health targetHealth = hit.transform.gameObject.GetComponent<Health>();
                Fighter thisFighter = GetComponent <Fighter>();
                //skip the rest of the body of this loop, and go to the next iteration...same as checking if its not null

                if (target == null)
                {
                    continue;
                }

                //skip the target if they are dead
                if (thisFighter.CanAttack(target.gameObject) == false)
                {
                    continue;
                }
                //atatcks are clicks, not holding down, so its mousedown ironically
                if (Input.GetMouseButton(0))
                {
                    GetComponent <Fighter>().Attack(target.gameObject);
                }
                //whether we are hovering over or clicking a combat target, we want to be in combat mode..that way we can display that to the user with a special cursor
                return(true);
            }
            //no hits were with combat targets
            return(false);
        }
Exemplo n.º 25
0
 protected override void Awake()
 {
     base.Awake();
     mainCamera      = Camera.main;
     actionScheduler = GetComponent <ActionScheduler>();
     myCombatTarget  = GetComponent <CombatTarget>();
     //myAnimator = GetComponent<PlayerAnimatorHandler>();?????
 }
Exemplo n.º 26
0
 // Start is called before the first frame update
 private void Start()
 {
     _main         = Camera.main;
     _mover        = GetComponent <Mover>();
     _fighter      = GetComponent <Fighter>();
     _scheduler    = GetComponent <ActionScheduler>();
     _combatTarget = GetComponent <CombatTarget>();
 }
Exemplo n.º 27
0
    private void Start()
    {
        CombatTarget combat = GetComponent <CombatTarget>();

        if (combat != null)
        {
            combat.enabled = false;
        }
    }
Exemplo n.º 28
0
        public bool CanAttack(CombatTarget combatTarget)
        {
            if (combatTarget == null)
            {
                return(false);
            }
            Health targetToTest = combatTarget.GetComponent <Health>();

            return(targetToTest != null && !targetToTest.IsDead());
        }
Exemplo n.º 29
0
        public bool CanAttack(CombatTarget combatTarget)
        {
            if (combatTarget == null)
            {
                return(false);
            }

            else
            {
                return(true);
            }
        }
Exemplo n.º 30
0
        private void InteractWithCombat(CombatTarget target)
        {
            Health targetHealth = target.gameObject.GetComponent <Health>();

            if (targetHealth.IsDead())
            {
                mousePressedWhileAttacking = false;
                return;
            }
            mousePressedWhileAttacking = true;
            GetComponent <Fighter>().Attack(target.gameObject);
        }