コード例 #1
0
    private void PlayerAttacking(SOEnemy enemy)
    {
        int damage           = ReturnPlayerDamage();
        int additionalDamage = ReturnPlayerAdditionalDamage();

        if (enemy.enemyType == _playerWeapon.VsType)
        {
            healthManager.EnemyLoseHealth(enemy, additionalDamage);
            showDamage.ShowEnemyDamage(additionalDamage);
        }
        else
        {
            healthManager.EnemyLoseHealth(enemy, damage);
            if (healthManager.EnemyDied)
            {
                OnBattleEnd();
            }
            showDamage.ShowEnemyDamage(damage);
        }
        if (_playerWeapon.ShouldStun)
        {
            StunChanceNumber();
            if (_randomStunChanceNumber <= _playerWeapon.StunChance)
            {
                EnemyIsStunned = true;
                Debug.Log("enemy stunned");
            }
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        print("Current battle state: " + state);

        if (Input.GetKeyDown(KeyCode.L))
        {
            Lose();
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            Win();
        }

        if (Input.GetKeyDown(KeyCode.N))
        {
            NextState();
        }

        if (state == States.START)
        {
            PlayerEnter.Enter = true;
            if (!SRanOnce)
            {
                timeS    = Time.time;
                SRanOnce = true;
            }
            if (Time.time - timeS >= 2.5f && timeS != -1)
            {
                NextState();
            }
        }

        if (state == States.PLAYERCHOICE)
        {
            SRanOnce  = false;
            EMRanOnce = false;
            if (!PCRanOnce)
            {
                abilityChooser.GetStarted();
                PCRanOnce = true;
            }
            if (!healing)
            {
                if (Input.GetKeyDown(KeyCode.DownArrow) && abilityChooser.selectedAbility < 3)
                {
                    abilityChooser.SelectAbility(abilityChooser.selectedAbility + 1);
                }
                if (Input.GetKeyDown(KeyCode.UpArrow) && abilityChooser.selectedAbility > 1)
                {
                    abilityChooser.SelectAbility(abilityChooser.selectedAbility - 1);
                }
            }
            else
            {
                if (Input.GetKeyDown(KeyCode.DownArrow) && abilityChooser.selectedHealer < 7)
                {
                    abilityChooser.SelectHealer(abilityChooser.selectedHealer + 1);
                }
                if (Input.GetKeyDown(KeyCode.UpArrow) && abilityChooser.selectedHealer > 1)
                {
                    abilityChooser.SelectHealer(abilityChooser.selectedHealer - 1);
                }
            }
            if (Input.GetKeyDown(KeyCode.Return))
            {
                print("Ability chosen: " + abilityChooser.selectedAbility);
                if (abilityChooser.selectedAbility != 3)
                {
                    NextState();
                }
                else if (!healing)
                {
                    abilityChooser.WhiteText(false);
                    abilityChooser.SelectHealer(1);
                    healing = true;
                }
                else
                {
                    abilityChooser.WhiteHealText(false);
                    NextState();
                }
            }
            if ((Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.LeftArrow)) && healing)
            {
                healing = false;
                abilityChooser.WhiteHealText(false);
                abilityChooser.SelectAbility(3);
            }
        }

        if (state == States.PLAYERMOVE)
        {
            PCRanOnce = false; healing = false;
            if (!PMRanOnce)
            {
                timePM      = Time.time;
                actionValue = abilityChooser.GetLastDoneDamage();
                abilityChooser.WhiteText(true);
                if (actionValue >= 0)
                {
                    healthManager.EnemyLoseHealth(actionValue);
                }
                else
                {
                    healthManager.LoseHealth(actionValue);
                }
                PMRanOnce = true;
            }
            if (Time.time - timePM >= 1.5f && timePM != -1)
            {
                if (healthManager.GetHealth_e() >= 1)
                {
                    NextState();
                }
                else if (healthManager.GetHealth_e() <= 0)
                {
                    if (e.ID == 5)
                    {
                        if (GameManager.instance.questManager.questLog.ContainsKey("Quest006"))
                        {
                            if (!GameManager.instance.questManager.questLog["Quest006"].QuestCompleted())
                            {
                                GameManager.instance.questManager.CompleteObjective("Quest006DefeatNoni");
                                GameManager.instance.questManager.AddQuestToLog("Quest007");
                            }
                        }

                        if (GameManager.instance.questManager.questLog.ContainsKey("Quest008"))
                        {
                            if (!GameManager.instance.questManager.questLog["Quest008"].QuestCompleted())
                            {
                                GameManager.instance.questManager.CompleteObjective("Quest008DefeatNoni");
                                GameManager.instance.questManager.AddQuestToLog("Quest009");
                            }
                        }
                    }

                    if (e.ID == 6)
                    {
                        if (GameManager.instance.questManager.questLog.ContainsKey("Quest009"))
                        {
                            if (!GameManager.instance.questManager.questLog["Quest009"].QuestCompleted())
                            {
                                GameManager.instance.questManager.CompleteObjective("Quest009FindDefeatMeemstar");
                                GameManager.instance.questManager.AddQuestToLog("Quest010");
                            }
                        }
                    }

                    if (e.ID == 7)
                    {
                        if (GameManager.instance.questManager.questLog.ContainsKey("Quest013"))
                        {
                            if (!GameManager.instance.questManager.questLog["Quest013"].QuestCompleted())
                            {
                                GameManager.instance.questManager.CompleteObjective("Quest013KillServer");
                                GameManager.instance.questManager.AddQuestToLog("Quest014");
                            }
                        }
                    }

                    Win();
                }
            }
        }

        if (state == States.ENEMYCHOICE)
        {
            PMRanOnce  = false;
            flashTimer = Mathf.PingPong(Time.time * 2, 1);

            if (!ECRanOnce)
            {
                timeEC = Time.time;
            }
            else
            {
                if (flashTimer >= 0.9)
                {
                    if (attNum == 1)
                    {
                        if (e.Type != "server")
                        {
                            enemyChooser.enemyStat.text = "<color=red>Attack 1: " + e.Attack1Title + "\n" +
                                                          "Damage: " + (e.Attack1Damage - PersistentInventoryScript.instance.itemDefense / 5) + "</color>\n" +
                                                          "Attack 2: " + e.Attack2Title + "\n" +
                                                          "Damage: " + (e.Attack2Damage - PersistentInventoryScript.instance.itemDefense / 5);
                        }
                        else
                        {
                            enemyChooser.enemyStat.text = "<color=red>Attack 1: " + e.Attack1Title + "\n" +
                                                          "Damage: ???</color>\n" +
                                                          "Attack 2: " + e.Attack2Title + "\n" +
                                                          "Damage: " + (e.Attack2Damage - PersistentInventoryScript.instance.itemDefense / 5);
                        }
                    }
                    if (attNum == 2)
                    {
                        if (e.Type != "server")
                        {
                            enemyChooser.enemyStat.text = "Attack 1: " + e.Attack1Title + "\n" +
                                                          "Damage: " + (e.Attack1Damage - PersistentInventoryScript.instance.itemDefense / 5) + "\n" +
                                                          "<color=red>Attack 2: " + e.Attack2Title + "\n" +
                                                          "Damage: " + (e.Attack2Damage - PersistentInventoryScript.instance.itemDefense / 5) + "</color>";
                        }
                        else
                        {
                            enemyChooser.enemyStat.text = "Attack 1: " + e.Attack1Title + "\n" +
                                                          "Damage: ???\n" +
                                                          "<color=red>Attack 2: " + e.Attack2Title + "\n" +
                                                          "Damage: " + (e.Attack2Damage - PersistentInventoryScript.instance.itemDefense / 5) + "</color>";
                        }
                    }
                }
                if (flashTimer <= 0.1)
                {
                    WhiteText();
                }
            }
            if (Time.time - timeEC >= 1f && timeEC != -1)
            {
                showEnterKey = true;
                if (Input.GetKeyDown(KeyCode.Return))
                {
                    NextState();
                }
            }
        }

        if (state == States.ENEMYMOVE)
        {
            ECRanOnce    = false;
            showEnterKey = false;
            WhiteText();
            if (!EMRanOnce)
            {
                int damage;
                if (attNum == 1)
                {
                    if (e.Type != "server")
                    {
                        damage = e.Attack1Damage - PersistentInventoryScript.instance.itemDefense / 5;
                        if (damage < 1)
                        {
                            damage = 1;
                        }
                        healthManager.LoseHealth(damage);
                    }
                    else
                    {
                        damage = (e.Attack1Damage + Random.Range(-10, 10)) - PersistentInventoryScript.instance.itemDefense / 5;
                        if (damage < 1)
                        {
                            damage = 1;
                        }
                        healthManager.LoseHealth(damage);
                        ChangeServerSprite();
                    }
                }
                if (attNum == 2)
                {
                    damage = e.Attack2Damage - PersistentInventoryScript.instance.itemDefense / 5;
                    if (damage < 1)
                    {
                        damage = 1;
                    }
                    healthManager.LoseHealth(damage);
                }
                EMRanOnce = true;
                timeEM    = Time.time;
            }
            if (Time.time - timeEM >= 1.5f && timeEM != -1)
            {
                if (healthManager.GetHealth() >= 1)
                {
                    NextState();
                }
                else if (healthManager.GetHealth() <= 0)
                {
                    Lose();
                }
            }
        }

        if (showEnterKey)
        {
            if (enterKeyColor.a < 1f)
            {
                enterKeyColor.a += 0.005f;
                enterKey.GetComponent <Image>().color = enterKeyColor;
            }
            enterKey.transform.localScale = new Vector3(Mathf.PingPong(Time.time * 0.5f, 0.3f) + 1f, Mathf.PingPong(Time.time * 0.5f, 0.3f) + 1f, 1f);
        }
        else
        {
            if (enterKeyColor.a > 0)
            {
                enterKeyColor.a -= 0.01f;
                enterKey.GetComponent <Image>().color = enterKeyColor;
                Vector3 s = enterKey.transform.localScale;
                enterKey.transform.localScale = new Vector3(s.x - s.x / 100, s.y - s.y / 100, 1f);
            }
        }
    }