コード例 #1
0
    public void AIDecision(int decision)
    {
        if (isDowned == true)
        {
            return;
        }

        switch (decision)
        {
        case 1:
            // nothing
            Debug.Log("AI - Nothing");
            FloatText.CreateFloatText("Loafing...", Color.blue, transform.position + 2 * Vector3.up);
            currentEnemy = null;
            break;

        case 2:
        case 3:
        case 4:
            // Have player selected in the game loop through local player list
            Attacking(-3);
            Debug.Log("AI - Attacking");
            currentEnemy = null;
            break;

        case 5:
            health += 1;
            Debug.Log("AI - Healing - " + health);
            currentEnemy = null;
            FloatText.CreateFloatText("+1", Color.green, transform.position + 2 * Vector3.up);
            break;
        }
    }
コード例 #2
0
    // handles attacking phase
    public void Attacking(int extraDamage)
    {
        int hitting = Random.Range(1, 7) + attack;

        Debug.Log("TO HIT: " + hitting);
        if (hitting > currentEnemy.GetComponent <CharacterBase>().defense)
        {
            currentEnemy.GetComponent <CharacterBase>().health -= attack + extraDamage;
            Debug.Log("HIT! - " + currentEnemy.GetComponent <CharacterBase>().charName + ": "
                      + currentEnemy.GetComponent <CharacterBase>().health);

            FloatText.CreateFloatText("−" + (attack + extraDamage), new Color(100, 0, 0.1f),
                                      currentEnemy.transform.position + 2 * Vector3.up);
        }
        else
        {
            Debug.Log(
                "MISS! - " + currentEnemy.GetComponent <CharacterBase>().charName + ": " +
                currentEnemy.GetComponent <CharacterBase>().health);
            FloatText.CreateFloatText("Miss", new Color(0, 0.2f, 1),
                                      currentEnemy.transform.position + 2 * Vector3.up);
        }

        if (currentEnemy.GetComponent <CharacterBase>().health <= 0)
        {
            currentEnemy.GetComponent <CharacterBase>().GetDown();
        }
    }
コード例 #3
0
    // Start is called before the first frame update
    void Start()
    {
        // players = teamSelector.players;

        // IF the player prefs key name is not set, squack at the dev
        if (playerPrefsKey.Length < 1)
        {
            if (debug)
            {
                Debug.LogError("'playerPrefsKey' is undefined!");
            }
        }
        // ELSE... (the player preferences key name is set)
        else
        {
            // Getting the list of players to spawn
            string toSpawn = PlayerPrefs.GetString(playerPrefsKey);
            players = new List <string>(toSpawn.Split(','));

            Vector3 start = center - separation * (players.Count - 1) / 2;

            spawnLocations = new Vector3[players.Count];

            for (int i = 0; i < players.Count; i++)
            {
                spawnLocations[i] = start + i * separation;
            }

            turnyBernie.objectList     = new List <CharacterBase>();
            turnyBernie.spawnPositions = spawnLocations;

            // Spawning the players
            for (int num = 0; num < players.Count; num++)
            {
                // Defining the current prefab
                GameObject current = null;

                // SWITCH for each player type
                switch (players[num])
                {
                case "Mando":
                    current = mandoPref;
                    break;

                case "Wook":
                    current = wookPref;
                    break;

                case "Jed":
                    current = jedPref;
                    break;

                case "Bo":
                    current = boPref;
                    break;

                default:
                    if (debug)
                    {
                        Debug.LogError("Prefab type of, '" + players[num] + "' is not defined!");
                    }
                    break;
                }

                // Spawning the current game object in the right spawn location
                if (current == null)
                {
                    throw new Exception("Player prefab not found??? The character requested was \"" + players[num] + "\".");
                }

                CharacterBase script = Instantiate(current, spawnLocations[num], Quaternion.identity).GetComponent <CharacterBase>();
                playerObjects.Add(script);
                Instantiate(statPref).GetComponent <StatDisplay>().SetCharacter(script);
                turnyBernie.objectList.Add(script);
            }
            GameObject badddie = GameObject.Find("Rancor");
            boss = badddie.GetComponent <CharacterBase>();
            Instantiate(statPref).GetComponent <StatDisplay>().SetCharacter(boss);
            foreach (CharacterBase player in playerObjects)
            {
                player.currentEnemy = boss;
            }

            turnyBernie.objectList.Add(boss);

            /*
             * int startingBossHealth = 25;
             * for (int x = 0; x < playerObjects.Count - 1; x++)
             *  startingBossHealth -= 5;
             *
             * badddie.GetComponent<CharacterBase>().health -= startingBossHealth;
             */
            boss.health = 15 + 5 * (playerObjects.Count);

            FloatText.CreateFloatText(
                "Battle start!",
                new Color(0x7F, 0xFF, 0x00),
                center + Vector3.up * 2 + Vector3.forward,
                8, 1.5f, 0.5f
                );
        }
    }
コード例 #4
0
    public void UseSpecial()
    {
        // sets specials and determines which one is used
        if (special > 0)
        {
            switch (charName)
            {
            case "Mando":
                FloatText.CreateFloatText("Empowered hit", Color.black, transform.position + 2 * Vector3.up);
                Attacking(3);

                special--;
                break;

            case "Wook":
                FloatText.CreateFloatText("Triple shot", Color.black, transform.position + 2 * Vector3.up);
                for (int x = 0; x < 3; x++)
                {
                    Attacking(0, Vector3.left * (x - 1));
                }

                special--;
                break;

            case "Jed":
                if (!currentTarget)
                {
                    SelectTarget();
                }
                else
                {
                    if (currentTarget.health <= 0)
                    {
                        currentTarget.GetComponent <CharacterBase>().Revive();
                        currentTarget.GetComponent <CharacterBase>().health = 2;
                        currentTarget = null;

                        special--;
                        CompleteTurn();
                    }
                    else
                    {
                        FloatText.CreateFloatText("He stilll live", new Color(1, 0, 0.8f), currentTarget.transform.position + 2 * Vector3.up);
                        CompleteTurn();
                    }
                    currentTarget = null;
                }
                break;

            case "Bo":
                if (!currentTarget)
                {
                    SelectTarget();
                }
                else
                {
                    if (currentTarget.health > 0)
                    {
                        FloatText.CreateFloatText("Heal!", Color.black, transform.position + 2 * Vector3.up);
                        currentTarget.GetComponent <CharacterBase>().health += 1;
                        FloatText.CreateFloatText("+1", Color.green, currentTarget.transform.position + 2 * Vector3.up);
                        Debug.Log("HEAL! - " + currentTarget.GetComponent <CharacterBase>().health);
                        CompleteTurn();

                        special--;
                    }
                    else
                    {
                        FloatText.CreateFloatText("He ded :(", Color.green, currentTarget.transform.position + 2 * Vector3.up);
                    }
                    currentTarget = null;
                }
                break;
            }

            // decrements special
        }
        else
        {
            throw new System.Exception("Check if your character can special before specialing. Pooor " + charName);
        }
    }
コード例 #5
0
    ///
    void HandlePlayer()
    {
        if (special)
        {
            objectList[currentIndex].UseSpecial();
            return;
        }
        /// <summary>
        /// Attacking Functionality
        /// Test Code for checking if the Attacking(int) function works for players.
        /// </summary>
        if (Input.GetKeyUp(KeyCode.A))
        {
            // Grabs the player script from the current objects turn and
            objectList[currentIndex].Attacking(0);

            // Completes the players turn once Attacking(int) has finished
            objectList[currentIndex].CompleteTurn();

            if (!BattleStarter.speed)
            {
                Look(objectList[currentIndex].currentEnemy.transform.position);
                StartCoroutine("Stop", 1);

                paused = true;
            }
        }
        // Activates boolean to begin special functionality for players
        else if (Input.GetKeyDown(KeyCode.S))
        {
            if (objectList[currentIndex].CanSpecial)
            {
                special = true;
                Debug.Log("SPECIAL STARTED...");

                if (!BattleStarter.speed)
                {
                    FloatText.CreateFloatText("Specialing...", Color.black,
                                              objectList[currentIndex].transform.position + 2 * Vector3.up);
                    LookFrom(new Vector3(0, 14, -5), new Vector3(0, 0, -4));
                    StartCoroutine("Stop", 0.1f);
                    paused = true;
                }
            }
            else
            {
                FloatText.CreateFloatText("Can't special", Color.black,
                                          objectList[currentIndex].transform.position + 2 * Vector3.up);
            }
        }

        /// <summary>
        /// Special Funcitonality
        /// When the special boolean is true, it checks if the currentTarget object of the player is true.
        /// If not, call the SelectTarget function of the player which checks for a mouse click on a gameObject.
        /// If currentTarget recieves a valid element, activate the UseSpecial function, which activates the
        /// players' special ability. Once finished; UseSpecial is called, special boolean changes back to false,
        /// and the players' turn ends.
        /// </summary>
        if (special)
        {
            // Checks if currentTarget is null
            if (objectList[currentIndex].gameObject.GetComponent <CharacterBase>().currentTarget == null)
            {
                // Waits for user to click on a valid object
                objectList[currentIndex].gameObject.GetComponent <CharacterBase>().SelectTarget();
            }
            else
            {
                // Uses special ability and resets values to prepare for next players' turn
                objectList[currentIndex].gameObject.GetComponent <CharacterBase>().UseSpecial();
                Debug.Log("SPECIAL ENDED...");
                special = false;
                objectList[currentIndex].CompleteTurn();
            }
        }
    }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (!gameOver)
        {
            if (paused)
            {
                return;
            }
            CheckForEndGame();

            // IF the Turn Manager is attempting to complete a round...
            if (attemptingRound)
            {
                // IF the current turn object is not the last object...
                if (currentIndex < objectList.Count)
                {
                    ///

                    if (currentIndex != objectList.Count - 1)
                    {
                        if (objectList[currentIndex].GetComponent <CharacterBase>().isDowned)
                        {
                            objectList[currentIndex].CompleteTurn();
                        }
                        else
                        {
                            HandlePlayer();
                            if (paused)
                            {
                                return;
                            }
                        }
                    }
                    else
                    {
                        HandleAI(objectList[objectList.Count - 1].GetComponent <CharacterBase>());
                        Debug.Log("AI TURN");
                        CharacterBase recipient = objectList[Random.Range(0, objectList.Count - 1)];
                        recipient.AddSpecial();
                        FloatText.CreateFloatText("Specialable", new Color(1, 1, 0), recipient.transform.position + 2 * Vector3.up);
                    }
                    ///

                    // IF the current turn object has completed its action...
                    if (objectList[currentIndex].hasCompletedTurn)
                    {
                        // Telling the current object that it's turn is over
                        objectList[currentIndex].isCurrentTurn = false;
                        currentIndex++;
                        special = false;

                        // IF the previous object was not the last object...
                        if (currentIndex < objectList.Count)
                        {
                            // Telling the next object that it is the current turn
                            objectList[currentIndex].isCurrentTurn = true;
                            MoveCamera();

                            if (debug)
                            {
                                Debug_CurrentTurn();
                            }
                        }
                    }
                }
                else
                {
                    // End the round
                    attemptingRound = false;
                    foreach (CharacterBase prop in objectList)
                    {
                        prop.hasCompletedTurn = false;
                        prop.isCurrentTurn    = false;
                    }
                    if (debug)
                    {
                        Debug.Log("End of Round!");
                    }

                    StartRound();
                }
            }
        }
    }