예제 #1
0
    public void DoBattle(uint id, int time)
    {
        // assign basic variables
        Player attacker = (this.AttackerIndex == 0) ? Player[0] : Player[1];
        Player defender = (this.AttackerIndex == 0) ? Player[1] : Player[0];

        Note.Core attackData = (this.AttackerIndex == 0) ? GetData(0, id) : GetData(1, id);
        Note.Core defendData = (this.AttackerIndex == 0) ? GetData(1, id) : GetData(0, id);
        // show miss layer
        if (attackData.Judge < 50)
        {
            JudgeAnim[0].Play("miss", -1, 0);
        }
        if (defendData.Judge < 50)
        {
            JudgeAnim[1].Play("miss", -1, 0);
        }
        // calculate combo
        CurrentCombo = GetNextCombo(
            attackData.Button,
            attackData.Type,
            attacker.GetAttackSkill(attackData.Button)
            );
        ComboText.text = CurrentCombo.ToString() + " Combo";

        // call BattleCore
        BattleCore(attacker, attackData, defender, defendData, time);

        // post-battle logic
        this.LastButton = attackData.Button;
        this.LastType   = attackData.Type;
        if (attacker.Hp.Value <= 0)
        {
            GameObject.Find("BeatGenerator").SetActive(false);
            GameObject.Find("InputManager1").SetActive(false);
            GameObject.Find("InputManager2").SetActive(false);
            attacker.Anim.speed = 0.5f;
            defender.Anim.speed = 0.5f;
            attacker.Anim.Play("lose");
            StartCoroutine(EndGame((AttackerIndex == 0) ? 1 : 0));
        }
        else if (defender.Hp.Value <= 0)
        {
            GameObject.Find("BeatGenerator").SetActive(false);
            GameObject.Find("InputManager1").SetActive(false);
            GameObject.Find("InputManager2").SetActive(false);
            attacker.Anim.speed = 0.5f;
            defender.Anim.speed = 0.5f;
            defender.Anim.Play("lose");
            StartCoroutine(EndGame(AttackerIndex));
        }
    }
예제 #2
0
 // interpret input & put data into queue
 private void OnSocketRead(string input)
 {
     // message format is
     // "player noteId button type judge"
     string[] splitInput = input.Split(' ');
     int player = System.Convert.ToInt32(splitInput[0]);
     Note.Core newData = new Note.Core {
         Id = System.Convert.ToUInt32(splitInput[1]),
         Button = (Note.Button)System.Enum.Parse(typeof(Note.Button), splitInput[2]),
         Type = (InputType)System.Enum.Parse(typeof(InputType), splitInput[3]),
         Judge = System.Convert.ToUInt32(splitInput[4])
     };
     // add interpreted data into data queue
     BattleMan.DataQueue[player].Enqueue(newData);
 }
예제 #3
0
    // interpret input & put data into queue
    private void OnSocketRead(string input)
    {
        // message format is
        // "player noteId button type judge"
        string[] splitInput = input.Split(' ');
        int      player     = System.Convert.ToInt32(splitInput[0]);

        Note.Core newData = new Note.Core {
            Id     = System.Convert.ToUInt32(splitInput[1]),
            Button = (Note.Button)System.Enum.Parse(typeof(Note.Button), splitInput[2]),
            Type   = (InputType)System.Enum.Parse(typeof(InputType), splitInput[3]),
            Judge  = System.Convert.ToUInt32(splitInput[4])
        };
        // add interpreted data into data queue
        BattleMan.DataQueue[player].Enqueue(newData);
    }
예제 #4
0
    // core battle logic
    private void BattleCore(Player attacker, Note.Core attackData,
                            Player defender, Note.Core defendData, int time)
    {
        AttackSkill attackerSkill  = attacker.GetAttackSkill(attackData.Button);
        DefendSkill defenderSkill  = defender.GetDefendSkill(defendData.Button);
        Animator    attackerEffect = EffectAnim[AttackerIndex];
        Animator    defenderEffect = EffectAnim[(AttackerIndex == 0) ? 1 : 0];

        DefendSkill.DefendState defendResult;
        // if both player didn't press button, set result to NONE
        if (defendData.Button == Note.Button.NONE && attackData.Button == Note.Button.NONE)
        {
            defendResult = DefendSkill.DefendState.NONE;
        }
        else if (defendData.Button == Note.Button.NONE &&
                 attackData.Type == InputManager.InputType.DOWN &&
                 attackerSkill.IsLongButton)
        {
            defendResult = DefendSkill.DefendState.GUARD;
        }
        // if defender didn't press button, set result to HIT
        else if (defendData.Button == Note.Button.NONE)
        {
            defendResult = DefendSkill.DefendState.HIT;
        }
        // if attacker didn't press button, set result to GUARD
        else if (attackData.Button == Note.Button.NONE)
        {
            defendResult = DefendSkill.DefendState.GUARD;
        }
        // both players pressed button
        else
        {
            defendResult = defenderSkill.DoDefend(attackerSkill.Name,
                                                  attackData.Judge <= defendData.Judge,
                                                  attackData.Type == InputManager.InputType.UP);
        }
        switch (defendResult)
        {
        case DefendSkill.DefendState.GUARD: {
            // defender Guards attack, and attacker keeps attack
            try {
                if (defenderSkill.Name == "Guard")
                {
                    defenderEffect.Play("guardsuccess", -1, 0);
                }
                defender.Anim.SetTrigger("action");
                defender.DecreaseHp(attackerSkill.Damage[this.CurrentCombo - 1]
                                    * (1 - defenderSkill.DefendRate));
                defender.IncreaseSp((int)defenderSkill.SkillPoint);
            } catch {}
            try {
                if (attackerSkill.IsLongButton && attackData.Type == InputManager.InputType.DOWN)
                {
                    this.LongButtonTime = time;
                }
                attacker.Anim.SetTrigger("action");
                attacker.DecreaseHp(defenderSkill.Damage);
            } catch {}
            break;
        }

        case DefendSkill.DefendState.CANCEL: {
            // defender Guards attack, and attacker's combo is reset
            try {
                defender.Anim.SetTrigger("action");
                defender.DecreaseHp(attackerSkill.Damage[this.CurrentCombo - 1]
                                    * (1 - defenderSkill.DefendRate));
                defender.IncreaseSp((int)defenderSkill.SkillPoint);
            } catch {}
            try {
                attackerEffect.Play("cancel", -1, 0);
                attacker.Anim.Play("hit", -1, 0);
                attacker.DecreaseHp(defenderSkill.Damage);
            } catch {}
            this.CurrentCombo = 0;
            break;
        }

        case DefendSkill.DefendState.HIT: {
            // attacker succeeded to hit defender
            try {
                if (attackerSkill.IsLongButton && attackData.Type == InputManager.InputType.UP)
                {
                    defender.Anim.Play("hit", -1, 0);
                    float damage = (time - this.LongButtonTime) / 25000.0f;
                    if (damage > 100)
                    {
                        defenderEffect.Play("str_full", -1, 0);
                    }
                    else
                    {
                        defenderEffect.Play("str_nor", -1, 0);
                    }
                    damage = System.Math.Min(damage, 100);
                    defender.DecreaseHp(damage);
                }
                else if (attackerSkill.IsLongButton && attackData.Type == InputManager.InputType.KEEP)
                {
                    // do nothing
                }
                else
                {
                    if (attackerSkill.Name == "Consecutive" && CurrentCombo == 1)
                    {
                        defenderEffect.Play("con1", -1, 0);
                    }
                    else if (attackerSkill.Name == "Consecutive" && CurrentCombo == 2)
                    {
                        defenderEffect.Play("con2", -1, 0);
                    }
                    else if (attackerSkill.Name == "Consecutive" && CurrentCombo == 3)
                    {
                        defenderEffect.Play("con3", -1, 0);
                    }
                    else if (attackerSkill.Name == "Normal")
                    {
                        defenderEffect.Play("kyunje", -1, 0);
                    }
                    defender.Anim.Play("hit", -1, 0);
                    defender.DecreaseHp(attackerSkill.Damage[CurrentCombo - 1]);
                }
            } catch {}
            attacker.Anim.SetTrigger("action");
            attacker.IncreaseSp((int)attackerSkill.SkillPoint[CurrentCombo - 1]);
            break;
        }

        case DefendSkill.DefendState.NONE: {
            // defender.Anim.Play("hit");
            // attacker.Anim.Play("hit");
            break;
        }

        default: break;
        }
        if (CurrentCombo == 3 && attackData.Button == Note.Button.BLUE &&
            defendResult == DefendSkill.DefendState.HIT)
        {
            CancelFlip = true;
        }
        if (attackData.Button == Note.Button.RED &&
            attackData.Type == InputManager.InputType.UP &&
            defendResult == DefendSkill.DefendState.HIT &&
            (time - this.LongButtonTime) / 25000.0f > 100)
        {
            CancelFlip = true;
        }
    }