コード例 #1
0
        private bool MovePlayerToMousePos()
        {
            // target will be the position of the hit point on the navmesh
            Vector3 target;
            // pass target by reference (bc it is an out param, it MUST be modified inside the method)
            bool canHit = RaycastNavMesh(out target);

            if (canHit)
            {
                // checks if player is close enough
                if (!mover.CanMoveTo(target))
                {
                    return(false);
                }

                if (Input.GetMouseButton(0))
                {
                    // cancel fighting and start regular movement action
                    // GetComponent<Fighter>().Cancel();
                    mover.StartMoveAction(target, 1f);
                }
                SetCursor(CursorType.Movement);
                return(true);
            }

            // if can't hit, then don't do anything
            return(false);
        }
コード例 #2
0
        private bool InteractWithMovement()
        {
            Vector3 target;
            bool    hasHit = RaycastNavMesh(out target);

            if (hasHit)
            {
                if (!mover.CanMoveTo(target))
                {
                    return(false);
                }

                if (Input.GetMouseButtonDown(0))
                {
                    movementStarted = true;
                }

                if (Input.GetMouseButton(0))
                {
                    mover.StartMoveAction(target);
                }
                SetCursor(CursorType.Movement);
                return(true);
            }
            return(false);
        }
コード例 #3
0
ファイル: Fighter.cs プロジェクト: MostyXS/IntermediateRPG
        public bool CanAttack(GameObject combatTarget)
        {
            if (!mover.CanMoveTo(combatTarget.transform.position) &&
                !GetIsInRange(combatTarget.transform))
            {
                return(false);
            }

            return(combatTarget && !combatTarget.GetComponent <Health>().IsDead());
        }
コード例 #4
0
ファイル: Fighter.cs プロジェクト: sdi1982/Unity-RPG-Scripts
        public bool CanAttack(GameObject target)
        {
            if (target == null || (!m_Mover.CanMoveTo(target.transform.position) && !GetIsInRange(target.transform)))
            {
                return(false);
            }

            Health targetToAttack = target.GetComponent <Health>();

            return(targetToAttack != null && !targetToAttack.IsDead);
        }
コード例 #5
0
        public bool CanAttack(GameObject combatTarget)
        {
            if (combatTarget == null)
            {
                return(false);
            }
            if (!_mover.CanMoveTo(combatTarget.transform.position) && !IsInRange(combatTarget.transform))
            {
                return(false);
            }
            var targetToTest = combatTarget.GetComponent <Health>();

            return(targetToTest != null && !targetToTest.IsDead);
        }
コード例 #6
0
ファイル: Fighter.cs プロジェクト: leozhang1/FirstRPG
        public bool CanAttack(GameObject combTarg)
        {
            if (combTarg == null)
            {
                return(false);
            }
            if (!mover.CanMoveTo(combTarg.transform.position) &&
                !GetIsInRange(combTarg.transform))
            {
                return(false);
            }

            return(combTarg.GetComponent <Health>() != null &&
                   !combTarg.GetComponent <Health>().isDead);
        }
コード例 #7
0
        public bool CanAttack(GameObject combatTarget)
        {
            if (combatTarget == null)
            {
                return(false);
            }
            if (false == mover.CanMoveTo(combatTarget.transform.position) &&
                false == GetIsInRange(combatTarget.transform))
            {
                return(false);
            }

            var targetToTest = combatTarget.GetComponent <Health>();

            return(null != targetToTest && false == targetToTest.IsDead());
        }
コード例 #8
0
 public bool HandleRaycast(PlayerController callingController)
 {
     if (Input.GetMouseButtonDown(0) && ChceckIfDistanceIsSmallEnough())
     {
         pickup.PickupItem();
         CheckIfIsQuestItem();
     }
     else if (Input.GetMouseButtonDown(0) && !ChceckIfDistanceIsSmallEnough())
     {
         if (mover.CanMoveTo(transform.position))
         {
             mover.StartMoveAction(transform.position);
         }
     }
     return(true);
 }
コード例 #9
0
    private static Cell[] getCeldasAccesibles(Cell celda, Mover mover)
    {
        Cell[]      vecinas    = celda.Map.getNeightbours(celda);
        List <Cell> accesibles = new List <Cell>();

        foreach (Cell c in vecinas)
        {
            if (c != null)
            {
                if (mover.CanMoveTo(celda, c))
                {
                    accesibles.Add(c);
                }
            }
        }

        return(accesibles.ToArray() as Cell[]);
    }
コード例 #10
0
        /// <summary>
        /// Checks if the target can be attacked
        /// </summary>
        /// <param name="combatTarget">The target to be attacked</param>
        /// <returns>If the target can be attacked</returns>
        public bool CanAttack(GameObject combatTarget)
        {
            // No target exists
            if (combatTarget == null)
            {
                return(false);
            }

            // Enemy is too far
            if (!m_mover.CanMoveTo(combatTarget.transform.position))
            {
                return(false);
            }

            // Check if the target has the Health component
            Health targetToTest = combatTarget.GetComponent <Health>();

            // If target has Health component and is not already dead
            return(targetToTest != null && !targetToTest.IsDead);
        }
コード例 #11
0
        private bool InteractWithMovement()
        {
            bool hasHit = RaycastNavMesh(out Vector3 target);

            if (!hasHit)
            {
                return(false);
            }
            if (!m_Mover.CanMoveTo(target))
            {
                return(false);
            }

            if (Input.GetMouseButton(0))
            {
                m_Mover.StartMovement(target, 1f);
            }

            SetCursor(CursorType.Movement);
            return(true);
        }
コード例 #12
0
ファイル: Fighter.cs プロジェクト: svetliaka92/UnityRPG
        public bool CanAttack(GameObject combatTarget)
        {
            if (combatTarget == null ||
                combatTarget == this.gameObject)
            {
                return(false);
            }

            if (!mover.CanMoveTo(combatTarget.transform.position))
            {
                return(false);
            }

            Health test = combatTarget.GetComponent <Health>();

            if (test && !test.IsDead)
            {
                return(true);
            }

            return(false);
        }
コード例 #13
0
        private bool InteractWithMovement()
        {
            //RaycastHit hit;
            //bool hasHit = Physics.Raycast(GetMouseRay(), out hit);
            Vector3 target;
            bool    hasHit = RaycastNavMesh(out target);

            if (hasHit)
            {
                if (!mover.CanMoveTo(target))
                {
                    return(false);
                }

                if (Input.GetMouseButton(0))
                {
                    mover.StartMoveAction(target, 1f);
                }
                SetCursor(CursorType.Movement);
                return(true);
            }
            return(false);
        }
コード例 #14
0
        public bool CanAttack(GameObject combatTarget)
        {
            if (combatTarget == null)
            {
                return(false);
            }
            if (!mover.CanMoveTo(combatTarget.transform.position))
            {
                return(false);
            }

            Mana mana = GetComponent <Mana>();

            if (mana != null && currentWeaponConfig.ManaCost > mana.ManaValue)
            {
                return(false);
            }


            Health checkedTarget = combatTarget.GetComponent <Health>();

            return(checkedTarget != null && !checkedTarget.IsDead());
        }
コード例 #15
0
    public void onControllerEvent(ControllerEventArgs args)
    {
        // # Avoid responding controller event when inactive
        if (!active)
        {
            return;
        }

        // # Normal threatment
        // Multiple controller events only give one launch result per tick
        if (toLaunch == null)
        {
            // If options received (from entities)
            if (args.options != null)
            {
                // If there's only one, proceed to launch
                if (args.options.Length == 1)
                {
                    // The action is the event we have to launch,
                    // so in order to know who's launching, we put a mark
                    if (args.options[0].Action != null)
                    {
                        args.options[0].Action.setParameter("Executer", this.Entity);
                    }

                    if (args.cell != null)
                    {
                        actionCell = args.cell;
                    }

                    // If we've to move to perform the action
                    if (args.options[0].HasToMove)
                    {
                        GameEvent ge = new GameEvent();
                        ge.setParameter("entity", this.Entity);
                        ge.setParameter("cell", args.cell);
                        ge.setParameter("synchronous", true);
                        ge.setParameter("distance", args.options[0].Distance);
                        ge.Name  = "move";
                        movement = ge;
                        Game.main.enqueueEvent(ge);

                        // Here we've launched the movement. As it's synchronous, we'll receive
                        // the movement finished when the Mover considers it's done.
                    }

                    toLaunch = args.options[0].Action;
                }
                // If there're multiple actions we have to display a menu so player can choose
                else if (args.options.Length > 1)
                {
                    OptionsGUI gui = ScriptableObject.CreateInstance <OptionsGUI>();
                    gui.init(args, Camera.main.WorldToScreenPoint(args.entity.transform.position), args.options);
                    GUIManager.addGUI(gui, 100);
                }
            }
            // If the argument doesn't contain options but it has a cell, we'll try to move over there
            else if (args.cell != null)
            {
                GameEvent ge = new GameEvent();
                ge.setParameter("entity", this.Entity);
                ge.setParameter("cell", args.cell);
                ge.Name = "move";
                Game.main.enqueueEvent(ge);
            }
            // Otherwise, the controller event should contain keys pressed
            else
            {
                int to = -1;
                if (args.LEFT)
                {
                    to = 0;
                }
                else if (args.UP)
                {
                    to = 1;
                }
                else if (args.RIGHT)
                {
                    to = 2;
                }
                else if (args.DOWN)
                {
                    to = 3;
                }

                if (to > -1)
                {
                    if (Entity == null)
                    {
                        Debug.Log("Null!");
                    }
                    Cell destination = Entity.Position.Map.getNeightbours(Entity.Position)[to];
                    // Can move to checks if the entity can DIRECT move to this cells.
                    // This should solve bug #29
                    Mover em = this.Entity.GetComponent <Mover>();
                    if (em != null && em.CanMoveTo(destination))
                    {
                        GameEvent ge = new GameEvent();
                        ge.setParameter("entity", this.Entity);
                        ge.setParameter("cell", destination);
                        ge.Name = "move";
                        Game.main.enqueueEvent(ge);
                    }
                    else
                    {
                        GameEvent ge = new GameEvent();
                        ge.setParameter("entity", this.Entity);
                        ge.setParameter("direction", fromIndex(to));
                        ge.Name = "turn";
                        Game.main.enqueueEvent(ge);
                    }
                }
            }
        }
    }
コード例 #16
0
ファイル: RoutePlanifier.cs プロジェクト: NasK1991/IsoMonks
    private static Cell[] getCeldasAccesibles(Cell celda, Mover mover)
    {
        Cell[] vecinas = celda.Map.getNeightbours(celda);
        List<Cell> accesibles = new List<Cell>();
        foreach(Cell c in vecinas){
            if(c!=null){
                if (mover.CanMoveTo(celda, c))
                    accesibles.Add(c);
            }
        }

        return accesibles.ToArray() as Cell[];
    }