Пример #1
0
    private bool GetTargetPoint(out Vector3 targetPoint)
    {
        var closestCollider = TargetPicker.PickClosest(
            TargetPickerBounds, armIKController.SymmetricalPosition(NoTargetAnchor.position),
            colliders => {
            // Prefer to grab player body parts.
            var playerColliders = colliders
                                  .Where(c => (c.gameObject.layer & playerLayerMask) != 0);

            if (playerColliders.Any())
            {
                colliders = playerColliders;
            }

            // Try to find at least collider with rigidbody.
            var rigidbodyColliders = colliders
                                     .Where(c => c.rigidbody != null);

            if (rigidbodyColliders.Any())
            {
                colliders = rigidbodyColliders;
            }
            else
            {
                colliders = Enumerable.Empty <Collider> ();
            }

            return(colliders);
        }, out targetPoint
            );

        return(closestCollider != null);
    }
Пример #2
0
    public static Collider PickClosest(
        CollisionDispatcher boundingFigure, Vector3 origin,
        System.Func <IEnumerable <Collider>, IEnumerable <Collider> > filter,
        out Vector3 closestPoint
        )
    {
        var colliders = boundingFigure.Colliders
                        .Where(c => c != null);         // Some of the accumulated colliders could be destroyed.

        colliders = filter(colliders);

        var closestCollider = TargetPicker.ClosestPointOnBounds(
            colliders,
            origin,
            out closestPoint
            );

        return(closestCollider);
    }
Пример #3
0
    void FixedUpdate()
    {
        Vector3 closestPoint;

        var closestCollider = TargetPicker.PickClosest(
            TargetPickerBounds, armIKController.SymmetricalPosition(NoTargetAnchor.position),                //armIKController.WristWorldAnchor,
            colliders => {
            // Prefer to grab player body parts.
            var playerColliders = colliders
                                  .Where(c => (c.gameObject.layer & playerLayerMask) != 0);

            if (playerColliders.Any())
            {
                colliders = playerColliders;
            }

            // Prefer colliders with rigidbody attached over static.
            var rigidbodyColliders = colliders
                                     .Where(c => c.attachedRigidbody != null);

            if (rigidbodyColliders.Any())
            {
                colliders = rigidbodyColliders;
            }

            return(colliders);
        }, out closestPoint
            );

        if (closestCollider != null)
        {
            // Stretch arm toward closest point on suitable collider.
            armIKController.WristTargetPosition = closestPoint;
        }
        else
        {
            // Stretch arm forward.
            armIKController.WristTargetPosition = armIKController.SymmetricalPosition(NoTargetAnchor.position);
        }
    }
 private void Start()
 {
     Instance = this;
     _        = UIRoot;
     tglPik.onValueChanged.AddListener(delegate(bool b)
     {
         EnablePick          = tglPik.isOn;
         tglHvr.interactable = TargetPicker.EnablePick;
         if (!EnablePick)
         {
             tglHvr.isOn = false;
         }
         tglUi.isOn = tglPik.isOn;
         if (!tglHvr.isOn && outLiner)
         {
             outLiner.transform.SetParent(transform);
             outLiner.SetActive(false);
         }
     });
     tglHvr.onValueChanged.AddListener(delegate(bool b)
     {
         AlwaysRaycast = tglHvr.isOn;
     });
     tglIns.onValueChanged.AddListener(delegate(bool b)
     {
         ins.gameObject.SetActive(tglIns.isOn);
     });
     tglHie.onValueChanged.AddListener(delegate(bool b)
     {
         hie.gameObject.SetActive(tglHie.isOn);
     });
     tglUi.onValueChanged.AddListener(delegate(bool b)
     {
         UIRoot.SetActive(!tglUi.isOn);
         InputBlocker.uirootenabled = !tglUi.isOn;
         //blck1.enabled = tglUi.isOn;
         //blck2.enabled = tglUi.isOn;
     });
 }
Пример #5
0
    /// <summary>
    /// Shoots the projectile like an arrow or something.
    /// Shoots the projectile and then starts the coroutine until it gets there
    /// Once our projectile has hit, we can have the hero take damage and
    /// then we can tell the game our turn has finished
    /// </summary>
    /// <returns>The projectile.</returns>
    public IEnumerator shootProjectile()
    {
        Debug.Log("we have shot our projectile. go into animation cooldown round");
        anim.SetTrigger("ShotProjectile");

        // then we have to start a new coroutine for shooting the arrow
        ProjectileAnimator sa = GameObject.Find("Arrow").GetComponent <ProjectileAnimator>();

        yield return(StartCoroutine(sa.FireProjectile()));

        // okay let's kill it
        ShakeCamera();
        screenFlash();

        EnemyUnit    attackingPlayer    = gameObject.GetComponent <EnemyUnit> ();
        TargetPicker playerTargetPicker = gameObject.AddComponent <TargetPicker>();

        playerTargetPicker.currentPlayer = attackingPlayer;
        playerTargetPicker.battleList    = gameObject.GetComponent <BattleMenu> ().allCombatants;
        playerTargetPicker.loadBattle();
        targetUnit = playerTargetPicker.RandomTarget().gameObject.GetComponent <PlayerUnit> ();


        int damageDealt = Mathf.RoundToInt(Random.Range(attackDamage * 0.8f, attackDamage * 1.2f));

        targetUnit.playerHealth.TakeDamage(damageDealt);

        Destroy(playerTargetPicker);

        // for now we'll relinquish our turn here
        // tell our battle manager that we are done
        BattleManager batMan = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <BattleManager> ();

        batMan.turnFinished       = true;
        batMan.attackDone         = " Fired an arrow at " + targetUnit.playerName;
        Toolbox.Instance.isLocked = false;
    }
Пример #6
0
    /// <summary>
    /// Attack the player
    /// We won't do this like this eventually, but for now, this can be how it's done
    /// This needs to be fixed
    /// </summary>
    public IEnumerator Attack()
    {
        // Reset the timer.
        //timer = 0f;
        Debug.Log("we are attacking");

        string attackDone = "";


        // if player name is grue, we'll do this
        // otherwise, let's do this in a moment

        /*if (gameObject.name == "Grue")
         * {
         *
         *
         *      GameObject spellObject = GameObject.FindGameObjectWithTag ("Spell");
         *      spellObject.GetComponent<SpriteRenderer> ().enabled = false;
         *      ProjectileAnimator sf = spellObject.GetComponent<ProjectileAnimator> ();
         *      yield return StartCoroutine (sf.CastSpell ());
         *
         *      // If the player has health to lose...
         *      if (targetUnit.playerHealth.currentHealth > 0)
         *      {
         *              // ... damage the player.
         *              targetUnit.playerHealth.TakeDamage (attackDamage);
         *      }
         *
         *      sf.StopSpell ();
         *
         *
         *
         *      attackDone = "casts Lightning on the Princess";
         *
         *      // tell our battle manager that we are done
         *      BattleManager batMan = GameObject.FindGameObjectWithTag ("MainCamera").GetComponent<BattleManager> ();
         *      batMan.turnFinished = true;
         *      batMan.attackDone = attackDone;
         *      Toolbox.Instance.isLocked = false;
         *
         * }
         *
         * // otherwise, we are in here
         * else if (gameObject.name == "Archer")
         * {
         *      // there needs to be a way to launch projectile in this game instead of following the traditional set
         *      // of animations.
         *      // So there should be a way to "skip" attack animation.
         *      // because during that, the arrow should just be flying.
         *      // in here, we'll charge to attack
         *      // we'll transition into projectile status
         *      // and then we'll be done.
         *      // set our anim to...!
         *      anim.SetTrigger("IsCharging");
         *
         *      // once we are done charging, we fire our array
         *      // animation is charging fires off an arrow in the enemy character item for now
         *      // then once that is done, we can do the rest of our animations and go back into idle state.
         *      // we do not relinquish our turn until the arrow hits
         * }
         *
         * else
         * {
         *
         *      // first we want to gallop in that direction.
         *      // then we want to attack
         *      // then we want to retreat
         *      basePosition = new Vector2(transform.position.x, transform.position.y);
         *
         *
         *      // set our anim to...!
         *      anim.SetTrigger("IsCharging");
         *      attacking = true;
         *
         *
         *      // once we are done setting our trigger, let's keep moving forward until we hit our
         *      // collision zone
         *
         *
         *      attackDone = "NO REAL ATTACKS DONE! MIND GAMES!";
         *
         *
         * }*/

        EnemyUnit    attackingPlayer    = gameObject.GetComponent <EnemyUnit> ();
        TargetPicker playerTargetPicker = gameObject.AddComponent <TargetPicker>();

        playerTargetPicker.currentPlayer = attackingPlayer;
        playerTargetPicker.battleList    = Camera.main.GetComponent <BattleMenu> ().allCombatants;
        playerTargetPicker.loadBattle();
        targetUnit = playerTargetPicker.RandomTarget().gameObject.GetComponent <PlayerUnit> ();


        int damageDealt = Mathf.RoundToInt(Random.Range(attackDamage * 0.8f, attackDamage * 1.2f));


        // If the player has health to lose...
        if (targetUnit.playerHealth.currentHealth > 0)
        {
            // ... damage the player.
            targetUnit.playerHealth.TakeDamage(damageDealt);
            ShakeCamera();
        }

        attackDone = " attacks " + targetUnit.playerName;

        Destroy(playerTargetPicker);
        // tell our battle manager that we are done
        BattleManager batMan = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <BattleManager> ();

        batMan.turnFinished       = true;
        batMan.attackDone         = attackDone;
        Toolbox.Instance.isLocked = false;

        yield return(new WaitForSeconds(0.1f));
    }
Пример #7
0
    /// <summary>
    /// When one of our menu buttons is clicked, we go here to deal with the command issued
    /// </summary>
    /// <param name="buttonCommand">Button command.</param>
    public IEnumerator ButtonClicked(Options buttonCommand)
    {
        isActive = false;
        Destroy(waitingObject);

        if (selectionMade)
        {
            /// what type of options list do we have? conversation or more main menu?
            if (menuType == "conversation")
            {
                if (buttonCommand.command == "exit")
                {
                    yield break;
                }
                else if (buttonCommand.command == "accept")
                {
                    hasAccepted = true;
                    yield break;
                }

                Commands command = new Commands();
                command.resolveConversationCommands(buttonCommand);
            }

            // if we have a main menu, we can send those commands over to commands as well
            // and just run our functions for that.
            else if (menuType == "PauseMenu")
            {
                Commands command = new Commands();
                command.resolvePauseMenuCommands(buttonCommand);
                // what is our command?
            }
            else if (menuType == "BattleMenu")
            {
                // yield on starting a new
                // add targetpicker to this player character, and then use that
                // to get the list of players from his battlemenu? who has the list of
                // units to attack?
                // player -> battle menu -> all combatants shoved into player -> add component -> targetpicker
                TargetPicker playerTargetPicker = attackingPlayer.GetOrAddComponent <TargetPicker>();
                playerTargetPicker.currentPlayer = attackingPlayer;
                playerTargetPicker.battleList    = attackingPlayer.GetComponent <BattleMenu> ().allCombatants;
                playerTargetPicker.loadBattle();


                // disable button presses
                // check and see which item is highlighted here before we enter and make that
                // our indexselected
                for (var i = 0; i < menuOptions.Count; i++)
                {
                    // if the item is highlighted, set our value to that
                    // set i to max
                    Button currentButton = optionsBox.transform.GetChild(i).gameObject.GetComponent <Button>();
                    currentButton.interactable = false;
                }

                // now that we've loaded the battle, we want to do an enumerator that waits
                // for an input from our user. Either we get a "back up" with a null, or we get
                // a character to attack (for now let's just assume it will be an enemy)
                yield return(StartCoroutine(playerTargetPicker.selectTarget()));


                while (!playerTargetPicker.hasChosenTarget)
                {
                    yield return(null);
                }



                if (playerTargetPicker.chosenTarget == null)
                {
                    Destroy(playerTargetPicker);

                    // if we get a null, make the buttons live again and we'll try again?
                    // disable button presses
                    // check and see which item is highlighted here before we enter and make that
                    // our indexselected
                    // check and see which item is highlighted here before we enter and make that
                    // our indexselected
                    for (var i = 0; i < menuOptions.Count; i++)
                    {
                        // if the item is highlighted, set our value to that
                        // set i to max
                        Button currentButton = optionsBox.transform.GetChild(i).gameObject.GetComponent <Button>();
                        currentButton.interactable = true;

                        if (i == 0 && indexSelected <= 0)
                        {
                            currentButton.Select();
                        }
                        else if (i == indexSelected)
                        {
                            currentButton.Select();
                        }
                    }

                    selectionMade = false;
                    isActive      = true;

                    yield break;
                }


                // get our command object
                Commands command = new Commands();

                GameObject targetObject = playerTargetPicker.chosenTarget.gameObject;
                command.setAttackingPlayer(attackingPlayer);
                if (targetObject.GetComponent <PlayerUnit> () != null)
                {
                    command.setPlayerBeingBuffed(targetObject.GetComponent <PlayerUnit> ());
                }
                if (targetObject.GetComponent <EnemyUnit> ())
                {
                    command.setEnemyUnderAttack(targetObject.GetComponent <EnemyUnit>());
                }

                Destroy(playerTargetPicker);

                // let's resolve our battle commands
                buttonCommand.playerToAlter = "Player";
                command.resolveBattleCommands(buttonCommand);
            }
        }

        yield return(new WaitForSeconds(0.01f));
    }