public override bool Check(GameObject target)
        {
            Character _character = this.character.GetCharacter(target);

            if (character == null)
            {
                return(condition == Armed.IsArmed ? false : true);
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee == null)
            {
                return(condition == Armed.IsArmed ? false : true);
            }

            if (melee.currentWeapon != null && this.condition == Armed.IsArmed)
            {
                return(true);
            }
            if (melee.currentWeapon == null && this.condition == Armed.IsUnarmed)
            {
                return(true);
            }
            return(false);
        }
        public override bool Check(GameObject target)
        {
            Character _character = this.character.GetCharacter(target);

            if (character == null)
            {
                return(condition == Focus.IsFocused ? false : true);
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee == null)
            {
                return(condition == Focus.IsFocused ? false : true);
            }

            if (melee.HasFocusTarget && this.condition == Focus.IsFocused)
            {
                return(true);
            }
            if (!melee.HasFocusTarget && this.condition == Focus.IsNotFocused)
            {
                return(true);
            }
            return(false);
        }
        public void OnReceiveAttack(CharacterMelee attacker, MeleeClip attack,
                                    CharacterMelee.HitResult hitResult)
        {
            // TODO: Filter attack by type, such as hit result, by attack, by player attack, ...

            this.ExecuteTrigger(attacker.gameObject);
        }
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character _character = this.character.GetCharacter(target);

            if (character == null)
            {
                return(true);
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee != null)
            {
                switch (this.target)
                {
                case Target.SetTarget:
                    GameObject targetValue = this.value.GetGameObject(target);
                    if (targetValue != null && melee != targetValue)
                    {
                        melee.SetTargetFocus(targetValue.GetComponent <TargetMelee>());
                    }
                    break;

                case Target.ReleaseTarget:
                    melee.ReleaseTargetFocus();
                    break;
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        public override bool Check(GameObject target)
        {
            Character _character = this.character.GetCharacter(target);

            if (character == null)
            {
                return(blocking == Blocking.IsBlocking ? false : true);
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee == null)
            {
                return(blocking == Blocking.IsBlocking ? false : true);
            }

            switch (this.blocking)
            {
            case Blocking.IsBlocking: return(melee.IsBlocking);

            case Blocking.IsNotBlocking: return(!melee.IsBlocking);
            }

            return(false);
        }
Exemplo n.º 6
0
        // CONSTRUCTOR: ---------------------------------------------------------------------------

        public ComboSystem(CharacterMelee melee, List <Combo> combos)
        {
            this.melee           = melee;
            this.startAttackTime = -100;

            this.root = new TreeCombo <CharacterMelee.ActionKey, Combo>(CharacterMelee.ActionKey.A);

            foreach (Combo combo in combos)
            {
                CharacterMelee.ActionKey[] actions = combo.combo;
                TreeCombo <CharacterMelee.ActionKey, Combo> node = this.root;

                for (int i = 0; i < actions.Length; ++i)
                {
                    if (node.HasChild(actions[i]))
                    {
                        node = node.GetChild(actions[i]);
                    }
                    else
                    {
                        node = node.AddChild(new TreeCombo <CharacterMelee.ActionKey, Combo>(
                                                 actions[i]
                                                 ));
                    }

                    if (i == actions.Length - 1)
                    {
                        node.SetData(combo);
                    }
                }
            }
        }
Exemplo n.º 7
0
 public void OnReceiveAttack(CharacterMelee attacker, MeleeClip attack,
                             CharacterMelee.HitResult hitResult)
 {
     if (this.type == hitResult)
     {
         this.storeAttacker.Set(attacker.gameObject, gameObject);
         this.ExecuteTrigger(attacker.gameObject);
     }
 }
Exemplo n.º 8
0
        public void SetTracker(CharacterMelee melee)
        {
            int meleeID = melee.GetInstanceID();

            if (this.trackers.ContainsKey(meleeID))
            {
                return;
            }
            this.trackers.Add(meleeID, melee);
        }
Exemplo n.º 9
0
        // PRIVATE METHODS: -----------------------------------------------------------------------

        private void UpdateUI()
        {
            if (!this.melee)
            {
                Character _character = this.character.GetCharacter(gameObject);
                if (!_character)
                {
                    return;
                }

                this.melee = _character.GetComponent <CharacterMelee>();
                if (!this.melee)
                {
                    return;
                }
            }

            float maxPoise     = this.melee.maxPoise.GetValue(melee.gameObject);
            float percentPoise = this.melee.Poise / maxPoise;

            if (this.poiseImageFill)
            {
                this.poiseImageFill.fillAmount = percentPoise;
            }
            if (this.poiseTextCurrentValue)
            {
                this.poiseTextCurrentValue.text = this.melee.Poise.ToString("0.00");
            }
            if (this.poiseTextMaxValue)
            {
                this.poiseTextMaxValue.text = maxPoise.ToString("0.00");
            }

            float maxDefense = this.melee.currentShield
                ? this.melee.currentShield.maxDefense.GetValue(melee.gameObject)
                : 0f;

            float percentDefense = this.melee.Defense / maxDefense;

            if (this.defenseImageFill)
            {
                this.defenseImageFill.fillAmount = percentDefense;
            }
            if (this.defenseTextCurrentValue)
            {
                this.defenseTextCurrentValue.text = this.melee.Defense.ToString("0.00");
            }
            if (this.defenseTextMaxValue)
            {
                this.defenseTextMaxValue.text = maxDefense.ToString("0.00");
            }
        }
Exemplo n.º 10
0
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character _character = this.character.GetCharacter(target);

            if (character == null)
            {
                return(true);
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee != null)
            {
                melee.AddDefense(this.amount.GetValue(target));
            }

            return(true);
        }
Exemplo n.º 11
0
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character _character = this.character.GetCharacter(target);

            if (character == null)
            {
                return(true);
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee != null)
            {
                melee.SetInvincibility(this.duration.GetValue(target));
            }

            return(true);
        }
Exemplo n.º 12
0
        private void Start()
        {
            Character _character = this.character.GetCharacter(gameObject);

            if (_character == null)
            {
                return;
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee == null)
            {
                return;
            }

            melee.EventAttack += this.OnAttack;
        }
Exemplo n.º 13
0
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character _character = this.character.GetCharacter(target);

            if (character == null)
            {
                return(true);
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee != null)
            {
                melee.EquipShield(this.shield);
            }

            return(true);
        }
Exemplo n.º 14
0
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character _character = this.character.GetCharacter(target);

            if (character == null)
            {
                return(true);
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee != null)
            {
                CoroutinesManager.Instance.StartCoroutine(melee.Sheathe());
            }

            return(true);
        }
Exemplo n.º 15
0
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character _character = this.character.GetCharacter(target);

            if (character == null)
            {
                return(true);
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee != null)
            {
                CoroutinesManager.Instance.StartCoroutine(melee.Draw(
                                                              this.drawPreviousWeapon ? melee.previousWeapon : this.meleeWeapon,
                                                              this.drawPreviousWeapon ? melee.previousShield : this.meleeShield
                                                              ));
            }

            return(true);
        }
Exemplo n.º 16
0
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character _character = this.character.GetCharacter(target);

            if (character == null)
            {
                return(true);
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee != null)
            {
                switch (this.blocking)
                {
                case Block.StartBlocking: melee.StartBlocking(); break;

                case Block.StopBlocking: melee.StopBlocking(); break;
                }
            }

            return(true);
        }
        // OVERRIDERS: ----------------------------------------------------------------------------

        public override bool Check(GameObject target)
        {
            Character _character = this.character.GetCharacter(target);

            if (character == null)
            {
                return(false);
            }

            CharacterMelee melee = _character.GetComponent <CharacterMelee>();

            if (melee == null)
            {
                return(false);
            }


            float var1 = melee.Defense;
            float var2 = this.compareTo.GetValue(target);

            switch (this.comparison)
            {
            case Comparison.Equal: return(Mathf.Approximately(var1, var2));

            case Comparison.EqualInteger: return(Mathf.RoundToInt(var1) == Mathf.RoundToInt(var2));

            case Comparison.Less: return(var1 < var2);

            case Comparison.LessOrEqual: return(var1 <= var2);

            case Comparison.Greater: return(var1 > var2);

            case Comparison.GreaterOrEqual: return(var1 >= var2);
            }

            return(false);
        }
        // CALLBACK METHODS: ----------------------------------------------------------------------

        public HitResult OnReceiveAttack(CharacterMelee attacker, MeleeClip attack)
        {
            if (this.currentWeapon == null)
            {
                return(HitResult.ReceiveDamage);
            }
            if (this.IsInvincible)
            {
                return(HitResult.Ignore);
            }

            float attackAngle = Vector3.Angle(
                attacker.transform.TransformDirection(Vector3.forward),
                this.transform.TransformDirection(Vector3.forward)
                );

            float defenseAngle = this.currentShield != null
                ? this.currentShield.defenseAngle.GetValue(gameObject)
                : 0f;

            if (this.currentShield != null &&
                attack.isBlockable && this.IsBlocking &&
                180f - attackAngle < defenseAngle / 2f)
            {
                this.AddDefense(-attack.defenseDamage);
                if (this.Defense > 0)
                {
                    if (Time.time < this.startBlockingTime + this.currentShield.perfectBlockWindow)
                    {
                        if (attacker != null)
                        {
                            MeleeClip attackerReaction = this.Character.IsGrounded()
                                ? this.currentShield.groundPerfectBlockReaction
                                : this.currentShield.airbornPerfectBlockReaction;

                            attackerReaction.Play(attacker);
                        }

                        if (this.currentShield.perfectBlockClip != null)
                        {
                            this.currentShield.perfectBlockClip.Play(this);
                        }

                        this.ExecuteEffects(
                            this.blade.GetImpactPosition(),
                            this.currentShield.audioPerfectBlock,
                            this.currentShield.prefabImpactPerfectBlock
                            );

                        this.comboSystem.OnPerfectBlock();
                        return(HitResult.PerfectBlock);
                    }

                    MeleeClip blockReaction = this.currentShield.GetBlockReaction();
                    if (blockReaction != null)
                    {
                        blockReaction.Play(this);
                    }

                    this.ExecuteEffects(
                        this.blade.GetImpactPosition(),
                        this.currentShield.audioBlock,
                        this.currentShield.prefabImpactBlock
                        );

                    this.comboSystem.OnBlock();
                    return(HitResult.AttackBlock);
                }
                else
                {
                    this.Defense = 0f;
                    this.StopBlocking();

                    if (this.EventBreakDefense != null)
                    {
                        this.EventBreakDefense.Invoke();
                    }
                }
            }

            this.AddPoise(-attack.poiseDamage);
            bool isFrontalAttack = attackAngle >= 90f;
            bool isKnockback     = this.Poise <= float.Epsilon;

            MeleeClip hitReaction = this.currentWeapon.GetHitReaction(
                this.Character.IsGrounded(),
                isFrontalAttack,
                isKnockback
                );

            this.ExecuteEffects(
                attacker.blade.GetImpactPosition(),
                isKnockback
                    ? this.currentWeapon.audioImpactKnockback
                    : this.currentWeapon.audioImpactNormal,
                isKnockback
                    ? this.currentWeapon.prefabImpactKnockback
                    : this.currentWeapon.prefabImpactNormal
                );

            attack.ExecuteHitPause();
            if (!this.IsUninterruptable)
            {
                hitReaction.Play(this);
            }

            return(HitResult.ReceiveDamage);
        }
        private void LateUpdate()
        {
            this.IsAttacking = false;

            if (this.comboSystem != null)
            {
                int phase = this.comboSystem.GetCurrentPhase();
                this.IsAttacking = phase >= 0f;

                if (this.blade != null && phase == 1)
                {
                    GameObject[] hits = this.blade.CaptureHits();
                    for (int i = 0; i < hits.Length; ++i)
                    {
                        int hitInstanceID = hits[i].GetInstanceID();

                        if (this.targetsEvaluated.Contains(hitInstanceID))
                        {
                            continue;
                        }
                        if (hits[i].transform.IsChildOf(this.transform))
                        {
                            continue;
                        }

                        HitResult hitResult = HitResult.ReceiveDamage;

                        CharacterMelee targetMelee = hits[i].GetComponent <CharacterMelee>();
                        MeleeClip      attack      = this.comboSystem.GetCurrentClip();

                        if (targetMelee != null)
                        {
                            hitResult = targetMelee.OnReceiveAttack(this, attack);
                        }

                        IgniterMeleeOnReceiveAttack[] triggers = (
                            hits[i].GetComponentsInChildren <IgniterMeleeOnReceiveAttack>()
                            );

                        bool hitSuccess = triggers.Length > 0;
                        if (hitSuccess)
                        {
                            for (int j = 0; j < triggers.Length; ++j)
                            {
                                triggers[j].OnReceiveAttack(this, attack, hitResult);
                            }
                        }

                        if (hitSuccess || targetMelee != null)
                        {
                            Vector3 position = this.blade.GetImpactPosition();
                            attack.ExecuteActionsOnHit(position, hits[i].gameObject);
                        }

                        if (attack.pushForce > float.Epsilon)
                        {
                            Rigidbody[] rigidbodies = hits[i].GetComponents <Rigidbody>();
                            for (int j = 0; j < rigidbodies.Length; ++j)
                            {
                                Vector3 direction = rigidbodies[j].transform.position - transform.position;
                                rigidbodies[j].AddForce(direction.normalized * attack.pushForce, ForceMode.Impulse);
                            }
                        }

                        this.targetsEvaluated.Add(hitInstanceID);
                    }
                }
            }
        }
Exemplo n.º 20
0
        public void ReleaseTracker(CharacterMelee melee)
        {
            int meleeID = melee.GetInstanceID();

            this.trackers.Remove(meleeID);
        }
        // INITIALIZERS: --------------------------------------------------------------------------

        public void Setup(CharacterMelee melee)
        {
            this.Melee = melee;
        }