Beispiel #1
0
    public void SelectTarget(Skill skill, BattleKnightCharacter character, BattleKnightCharacter target)
    {
        this.animationFrames = 50;
        character.ActionAnimation("attack");

        this.battleLog.text = "Использовано умение: " + skill.title + "\n" + this.battleLog.text;;

        float hitValue   = Random.Range(0, 10001) * 1.0f / 100f;
        float critValue  = Random.Range(0, 10001) * 1.0f / 100f;
        float dodgeValue = Random.Range(0, 10001) * 1.0f / 100f;

        this.drawReports(skill.ApplyEffect(hitValue, critValue, dodgeValue, target.character));

        int childCount = this.actionButtonsContentPanel.transform.childCount;

        for (int i = 0; i < childCount; i++)
        {
            Destroy(this.actionButtonsContentPanel.transform.GetChild(i).gameObject);
        }
        foreach (GameObject targetButton in this.targetButtons)
        {
            Destroy(targetButton);
        }
        this.targetButtons.Clear();
        this.waitForPlayer = false;
    }
Beispiel #2
0
    public void UseSkill(Skill skill, BattleKnightCharacter character)
    {
        List <Character> possibleTargets = new List <Character> ();

        possibleTargets.AddRange(this.battleField.GetPossibleTargets(character.character, character.leftSide, skill.targetType));

        List <BattleKnightCharacter> unityTargets = new List <BattleKnightCharacter> ();

        for (var i = 0; i < this.leftSide.Length; i++)
        {
            if (possibleTargets.Contains(this.leftSide [i].character))
            {
                unityTargets.Add(this.leftSide [i]);
            }
        }
        for (var i = 0; i < this.rightSide.Length; i++)
        {
            if (possibleTargets.Contains(this.rightSide [i].character))
            {
                unityTargets.Add(this.rightSide [i]);
            }
        }

        if (unityTargets.Count == 1)
        {
            this.SelectTarget(skill, character, unityTargets [0]);
            return;
        }

        foreach (GameObject targetButton in this.targetButtons)
        {
            Destroy(targetButton);
        }
        this.targetButtons.Clear();

        foreach (BattleKnightCharacter target in unityTargets)
        {
            GameObject targetButton = GameObject.Instantiate(this.targetButtonPrefab) as GameObject;
            targetButton.transform.SetParent(this.canvas.transform, false);
            targetButton.transform.localScale = new Vector3(1, 1, 1);

            Vector2 point = Camera.main.WorldToScreenPoint(target.transform.position);
            point   = point - this.canvas.GetComponent <RectTransform> ().anchoredPosition;
            point.x = point.x + (target.leftSide ? 1 : -1) * 80.0f;
            targetButton.GetComponent <RectTransform> ().anchoredPosition = point;

            targetButton.GetComponentInChildren <Text> ().text = target.leftSide ? "<=" : "=>";

            Button button = targetButton.GetComponent <Button> ();
            BattleKnightCharacter tmpPlayer = target;
            button.onClick.AddListener(() => SelectTarget(skill, character, tmpPlayer));
            this.targetButtons.Add(targetButton);
        }
    }
Beispiel #3
0
    void FixedUpdate()
    {
        if (this.combatFinished)
        {
            if (Input.GetKey(KeyCode.R))
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene("BattleScene");
            }
            return;
        }

        // wait for animation
        if (this.animationFrames > 0)
        {
            this.animationFrames--;
            return;
        }

        // skip if we are waiting for player
        if (this.waitForPlayer)
        {
            return;
        }

        // check if one of sides is dead
        bool allLeftDead = true;

        for (int i = 0; i < this.maxLeft; i++)
        {
            allLeftDead = allLeftDead && this.leftSide [i].character.IsDead();
        }
        bool allRightDead = true;

        for (int i = 0; i < this.maxRight; i++)
        {
            allRightDead = allRightDead && this.rightSide [i].character.IsDead();
        }

        this.combatFinished = allLeftDead || allRightDead;
        if (this.combatFinished)
        {
            this.battleLog.text = "Бой окончен. Press 'R' to return to main menu" + "\n" + this.battleLog.text;
            return;
        }

        // determinate who can strike on current initiative
        if (this.currentActingPlayers.Count == 0)
        {
            if (this.currentInitiative < 0)
            {
                this.NewBattleRound();
                return;
            }
            for (int i = 0; i < this.maxLeft; i++)
            {
                if (this.leftSide [i].character.CanAct(this.currentInitiative))
                {
                    this.currentActingPlayers.Add(this.leftSide [i]);
                }
            }
            for (int i = 0; i < this.maxRight; i++)
            {
                if (this.rightSide [i].character.CanAct(this.currentInitiative))
                {
                    this.currentActingPlayers.Add(this.rightSide [i]);
                }
            }
            for (int n = 0; n < this.currentActingPlayers.Count; n++)
            {
                int k = Random.Range(n, this.currentActingPlayers.Count);
                BattleKnightCharacter value = this.currentActingPlayers[k];
                this.currentActingPlayers[k] = this.currentActingPlayers[n];
                this.currentActingPlayers[n] = value;
            }
            if (this.currentActingPlayers.Count == 0)
            {
                this.currentInitiative--;
            }
            else
            {
                this.battleLog.text = "Инициатива " + this.currentInitiative + "\n" + this.battleLog.text;;
            }
        }
        else
        {
            foreach (BattleKnightCharacter actingPlayer in this.currentActingPlayers)
            {
                if (!actingPlayer.character.CanAct(this.currentInitiative))
                {
                    this.currentActingPlayers.Remove(actingPlayer);
                    break;
                }
                this.battleLog.text = "Ход игрока " + actingPlayer.character.name + "\n" + this.battleLog.text;
                if (actingPlayer.character.isPlayer)
                {
                    this.waitForPlayer = true;
                    // generate here action buttons
                    foreach (Skill playerSkill in actingPlayer.character.PossibleSkills())
                    {
                        GameObject actionButton = Instantiate(this.actionButtonPrefab) as GameObject;
                        actionButton.transform.SetParent(this.actionButtonsContentPanel.transform, false);
                        actionButton.transform.localScale = new Vector3(1, 1, 1);

                        string skillButtonTitle = playerSkill.title;
                        if (!playerSkill.isUnlimited)
                        {
                            skillButtonTitle += " (" + playerSkill.maxUsages.ToString() + ")";
                        }
                        actionButton.GetComponentInChildren <Text> ().text = skillButtonTitle;

                        Button button   = actionButton.GetComponent <Button> ();
                        Skill  tmpSkill = playerSkill;
                        BattleKnightCharacter tmpPlayer = actingPlayer;
                        button.onClick.AddListener(() => UseSkill(playerSkill, tmpPlayer));
                    }
                }
                else
                {
                    this.animationFrames = 50;
                    actingPlayer.ActionAnimation("attack");
                    this.drawReports(actingPlayer.character.Act(this.battleField, actingPlayer.leftSide));
                }
                break;
            }
            if (this.currentActingPlayers.Count == 0)
            {
                this.currentInitiative--;
            }
        }
    }