Ejemplo n.º 1
0
    void Attack()
    {
        if (PhotonNetwork.isMasterClient || !GamePlayManager.IsMultiPlayer)
        {
            if (currentUnit.attackTarget == null)
            {
                GamePlayManager.RaiseGameplayEvent("", GamePlayManager.GameplayEvent.TurnEnd);
                return;
            }
            //player attack enemy
            if (currentUnit.tag.Contains("Player"))
            {
                spellController.ShowFX(currentUnit, currentUnit.selectedSpell.FX, currentUnit.selectedSpell);

                int damage = spellController.DmgCalculator(currentUnit.savedCharacter, currentUnit.attackTarget.savedCharacter, currentUnit.selectedSpell);
                //currentUnit.attackTarget.TakeDamage(damage);
                foreach (var go in UintInSpellRange())
                {
                    if (currentUnit.selectedSpell.Target.Contains("Enemy"))
                    {
                        go.TakeDamage(damage);
                    }
                    else if (currentUnit.selectedSpell.Target.Contains("Player"))
                    {
                        go.GetHealth(damage);
                    }
                }

                if (currentUnit.selectedSpell.Cooldown > 0)
                {
                    playManager.uiManager.ActionBar.selectedSpellSlot.EnableCD(currentUnit.selectedSpell.Cooldown);
                }
            }
            //enemy attack player
            else
            {
                int damage = spellController.DmgCalculator(currentUnit.savedCharacter, currentUnit.attackTarget.savedCharacter, currentUnit.selectedSpell);
                currentUnit.attackTarget.TakeDamage(1);
                spellController.ShowFX(currentUnit.attackTarget.gameObject, currentUnit.selectedSpell);
            }

            StartCoroutine(GamePlayManager.Wait(() =>
            {
                GamePlayManager.RaiseGameplayEvent("", GamePlayManager.GameplayEvent.TurnEnd);
            }, .75f));
        }
        else if (!PhotonNetwork.isMasterClient && GamePlayManager.IsMultiPlayer)
        {
            foreach (var go in allCharacterUnit)
            {
                if (playManager.conditions.AllSavedChaharacterData.ContainsKey(go.name))
                {
                    go.savedCharacter = playManager.conditions.AllSavedChaharacterData[go.name];
                }
            }

            if (!string.IsNullOrEmpty(playManager.conditions.TargetChaName))
            {
                currentUnit.attackTarget = allCharacterDictionary[playManager.conditions.TargetChaName];
                currentUnit.RandomSpell(playManager.conditions.SelectedSpell);
            }

            if (currentUnit.attackTarget == null)
            {
                return;
            }

            //player attack enemy
            if (currentUnit.tag.Contains("Player"))
            {
                spellController.ShowFX(currentUnit, currentUnit.selectedSpell.FX);

                int damage = spellController.DmgCalculator(currentUnit.savedCharacter, currentUnit.attackTarget.savedCharacter, currentUnit.selectedSpell);
                currentUnit.attackTarget.TakeDamage(damage);
                if (currentUnit.selectedSpell.Cooldown > 0)
                {
                    playManager.uiManager.ActionBar.selectedSpellSlot.EnableCD(currentUnit.selectedSpell.Cooldown);
                }
            }
            //enemy attack player
            else
            {
                int damage = spellController.DmgCalculator(currentUnit.savedCharacter, currentUnit.attackTarget.savedCharacter, currentUnit.selectedSpell);
                currentUnit.attackTarget.TakeDamage(damage / 10);
                spellController.ShowFX(currentUnit, currentUnit.selectedSpell.FX);
            }
        }
    }