Пример #1
0
        /// <summary>
        /// Does the actual work of hitting the target with an ability
        /// </summary>
        /// <param name="ability"></param>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public override void PerformAbilityHit(BaseCharacter source, GameObject target, AbilityEffectOutput abilityEffectInput)
        {
            //Debug.Log(MyAbilityEffectName + ".AttackAbility.PerformAbilityEffect(" + source.name + ", " + target.name + ")");
            if (abilityEffectInput == null)
            {
                //Debug.Log("AttackEffect.PerformAbilityEffect() abilityEffectInput is null!");
            }
            if (source == null || target == null)
            {
                // something died or despawned mid cast
                return;
            }
            if (source.MyCharacterCombat.DidAttackMiss() == true)
            {
                //Debug.Log(MyName + ".AttackEffect.PerformAbilityHit(" + source.name + ", " + target.name + "): attack missed");
                source.MyCharacterCombat.ReceiveCombatMiss(target);
                return;
            }
            int             healthFinalAmount = 0;
            CombatMagnitude combatMagnitude   = CombatMagnitude.normal;

            if (useHealthAmount == true)
            {
                float healthTotalAmount = healthBaseAmount + (healthAmountPerLevel * source.MyCharacterStats.MyLevel);
                KeyValuePair <float, CombatMagnitude> abilityKeyValuePair = CalculateAbilityAmount(healthTotalAmount, source, target.GetComponent <CharacterUnit>(), abilityEffectInput);
                healthFinalAmount = (int)abilityKeyValuePair.Key;
                combatMagnitude   = abilityKeyValuePair.Value;
            }
            healthFinalAmount += (int)(abilityEffectInput.healthAmount * inputMultiplier);

            AbilityEffectOutput abilityEffectOutput = new AbilityEffectOutput();

            abilityEffectOutput.healthAmount = healthFinalAmount;
            if (healthFinalAmount > 0)
            {
                // this effect may not have any damage and only be here for spawning a prefab or making a sound
                target.GetComponent <CharacterUnit>().MyCharacter.MyCharacterCombat.TakeDamage(healthFinalAmount, source.MyCharacterUnit.transform.position, source, combatMagnitude, this, abilityEffectInput.refectDamage);
            }
            abilityEffectOutput.prefabLocation = abilityEffectInput.prefabLocation;

            // handle weapon on hit effects
            if (source.MyCharacterCombat != null && source.MyCharacterCombat.MyOnHitEffect != null && damageType == DamageType.physical && source.MyCharacterCombat.MyOnHitEffect.MyName != MyName)
            {
                List <AbilityEffect> onHitEffectList = new List <AbilityEffect>();
                onHitEffectList.Add(source.MyCharacterCombat.MyOnHitEffect);
                PerformAbilityEffects(source, target, abilityEffectOutput, onHitEffectList);
            }
            else
            {
                //Debug.Log(MyName + ".AttackEffect.PerformAbilityHit(" + (source == null ? "null" : source.name) + ", " + (target == null ? "null" : target.name) + "): no on hit effect set");
            }

            // handle regular effects
            base.PerformAbilityHit(source, target, abilityEffectOutput);
        }
Пример #2
0
        /// <summary>
        /// Does the actual work of hitting the target with an ability
        /// </summary>
        /// <param name="ability"></param>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public override void PerformAbilityHit(BaseCharacter source, GameObject target, AbilityEffectOutput abilityEffectInput)
        {
            //Debug.Log(abilityEffectName + ".HealEffect.PerformAbilityEffect(" + source.name + ", " + (target == null ? "null" : target.name) + ") effect: " + abilityEffectName);
            int             healthFinalAmount = 0;
            CombatMagnitude combatMagnitude   = CombatMagnitude.normal;

            if (useHealthAmount == true)
            {
                float healthTotalAmount = healthBaseAmount + (healthAmountPerLevel * source.MyCharacterStats.MyLevel);
                KeyValuePair <float, CombatMagnitude> abilityKeyValuePair = CalculateAbilityAmount(healthTotalAmount, source, target.GetComponent <CharacterUnit>(), abilityEffectInput);
                healthFinalAmount = (int)abilityKeyValuePair.Key;
                combatMagnitude   = abilityKeyValuePair.Value;
                //healthFinalAmount = (int)CalculateAbilityAmount(healthTotalAmount, source, target.GetComponent<CharacterUnit>(), abilityEffectInput).Key;
            }
            healthFinalAmount += (int)(abilityEffectInput.healthAmount * inputMultiplier);

            AbilityEffectOutput abilityEffectOutput = new AbilityEffectOutput();

            abilityEffectOutput.healthAmount = healthFinalAmount;
            if (healthFinalAmount > 0)
            {
                target.GetComponent <CharacterUnit>().MyCharacter.MyCharacterStats.RecoverHealth(healthFinalAmount, source, true, combatMagnitude);
            }
            int manaFinalAmount = 0;

            combatMagnitude = CombatMagnitude.normal;
            if (useManaAmount == true)
            {
                float manaTotalAmount = manaBaseAmount + (manaAmountPerLevel * source.MyCharacterStats.MyLevel);
                KeyValuePair <float, CombatMagnitude> abilityKeyValuePair = CalculateAbilityAmount(manaBaseAmount, source, target.GetComponent <CharacterUnit>(), abilityEffectInput);
                manaFinalAmount = (int)abilityKeyValuePair.Key;
                combatMagnitude = abilityKeyValuePair.Value;
                //manaFinalAmount = (int)CalculateAbilityAmount(manaBaseAmount, source, target.GetComponent<CharacterUnit>(), abilityEffectInput).Key;
            }
            manaFinalAmount += (int)(abilityEffectInput.manaAmount * inputMultiplier);
            abilityEffectOutput.manaAmount = manaFinalAmount;
            if (manaFinalAmount > 0)
            {
                target.GetComponent <CharacterUnit>().MyCharacter.MyCharacterStats.RecoverMana(manaFinalAmount, source, true, combatMagnitude);
            }
            abilityEffectOutput.prefabLocation = abilityEffectInput.prefabLocation;
            base.PerformAbilityHit(source, target, abilityEffectOutput);
        }
Пример #3
0
        /*
         *  public override void ClearAggro(GameObject target) {
         *      base.ClearAggro(target);
         *      aiController.ClearTarget();
         *  }
         */

        public override bool TakeDamage(int damage, Vector3 sourcePosition, BaseCharacter source, CombatType combatType, CombatMagnitude combatMagnitude, string abilityName)
        {
            //Debug.Log("AICombat.TakeDamage(" + damage + ", " + sourcePosition + ", " + source + ")");
            if (!((baseCharacter.MyCharacterController as AIController).MyCurrentState is EvadeState) && !((baseCharacter.MyCharacterController as AIController).MyCurrentState is DeathState))
            {
                // order is important here.  we want to set target before taking damage because taking damage could kill us, and we don't want to re-trigger and agro on someone after we are dead

                // this should happen automatically inside the update loop of idle state
                //baseCharacter.MyCharacterController.SetTarget(source);
                return(base.TakeDamage(damage, sourcePosition, source, combatType, combatMagnitude, abilityName));
            }
            return(false);
        }
Пример #4
0
        public void InitializeCombatTextController(Interactable mainTarget, Sprite sprite, string displayText, CombatTextType combatTextType, CombatMagnitude combatMagnitude = CombatMagnitude.normal, AbilityEffectContext abilityEffectContext = null)
        {
            this.mainTarget           = mainTarget;
            image.sprite              = sprite;
            this.displayText          = displayText;
            this.textType             = combatTextType;
            this.combatMagnitude      = combatMagnitude;
            this.abilityEffectContext = abilityEffectContext;

            gameObject.SetActive(true);

            // if the combat text ui is not active, then we should just immediately disable this
            if (gameObject.activeInHierarchy == false)
            {
                CombatTextManager.MyInstance.returnControllerToPool(this);
                return;
            }

            //Debug.Log("Combat Text spawning: " + textType);
            randomX = Random.Range(0, randomXLimit);
            randomY = Random.Range(0, randomYLimit);
            //Debug.Log("Combat Text spawning: " + textType + "; randomX: " + randomX + "; randomY: " + randomY);
            targetPos = CameraManager.MyInstance.MyActiveMainCamera.WorldToScreenPoint(mainTarget.InteractableGameObject.transform.position);
            //alpha = text.color.a;
            alpha               = 1f;
            fadeOutTimer        = fadeTime;
            fadeRate            = 1.0f / fadeTime;
            directionMultiplier = 1;
            fontSizeMultiplier  = 1;
            yUIOffset           = 0f;

            string preText  = string.Empty;
            string postText = string.Empty;

            if (image.sprite == null)
            {
                image.color = new Color32(0, 0, 0, 0);
            }
            else
            {
                image.color = Color.white;
            }
            if (mainTarget.InteractableGameObject == PlayerManager.MyInstance.ActiveUnitController.gameObject)
            {
                directionMultiplier = -1;
                switch (textType)
                {
                case CombatTextType.normal:
                    textColor = Color.red;
                    int parseResult;
                    if (int.TryParse(displayText, out parseResult))
                    {
                        preText += parseResult > 0 ? "-" : "";
                    }
                    break;

                case CombatTextType.gainXP:
                    textColor           = Color.yellow;
                    preText            += "+";
                    postText           += " XP";
                    fontSizeMultiplier *= 2;
                    break;

                case CombatTextType.gainBuff:
                    textColor = Color.cyan;
                    preText  += "+";
                    //text.fontSize = text.fontSize * 2;
                    break;

                case CombatTextType.loseBuff:
                    textColor = Color.cyan;
                    preText  += "+";
                    //text.fontSize = text.fontSize * 2;
                    break;

                case CombatTextType.ability:
                    textColor           = Color.magenta;
                    preText            += "-";
                    fontSizeMultiplier *= 2;
                    break;

                default:
                    break;
                }
            }
            else
            {
                switch (textType)
                {
                case CombatTextType.normal:
                    textColor = Color.white;
                    break;

                case CombatTextType.ability:
                    textColor           = Color.yellow;
                    fontSizeMultiplier *= 2;
                    break;

                default:
                    break;
                }
            }
            // defaults
            switch (textType)
            {
            case CombatTextType.gainHealth:
                textColor           = Color.green;
                preText            += "+";
                fontSizeMultiplier *= 2;
                break;

            case CombatTextType.miss:
                textColor = Color.white;
                //preText += "";
                //text.fontSize = text.fontSize * 2;
                break;

            case CombatTextType.immune:
                textColor = Color.white;
                //preText += "";
                //text.fontSize = text.fontSize * 2;
                break;

            case CombatTextType.gainResource:
                if (abilityEffectContext?.powerResource != null)
                {
                    textColor = abilityEffectContext.powerResource.DisplayColor;
                    postText += " " + abilityEffectContext.powerResource.DisplayName;
                }
                else
                {
                    textColor = Color.blue;
                }
                preText += "+";
                // rage looks funny bigger
                //tmpProtext.fontSize = tmpProtext.fontSize * 2;
                break;

            default:
                break;
            }

            tmpProtext.color = textColor;
            string finalString = preText + displayText + postText;

            tmpProtext.text = finalString;
            if (combatMagnitude == CombatMagnitude.critical)
            {
                fontSizeMultiplier *= 2;
            }
            tmpProtext.fontSize = defaultFontSize * fontSizeMultiplier;

            // make criticals and other large text go farther up and to the right to avoid covering smaller text
            randomY += (fontSizeMultiplier / 2f) * randomYLimit;
            randomX += (fontSizeMultiplier / 2f) * randomXLimit;

            RunCombatTextUpdate();
        }
Пример #5
0
        public override bool ProcessAbilityHit(Interactable target, int finalAmount, IAbilityCaster source, CombatMagnitude combatMagnitude, AbilityEffect abilityEffect, AbilityEffectContext abilityEffectContext, PowerResource powerResource)
        {
            //Debug.Log(DisplayName + ".HealEffect.ProcessAbilityHit(" + (target == null ? "null" : target.gameObject.name) + ", " + finalAmount + ", " + source.AbilityManager.UnitGameObject.name + ")");

            abilityEffectContext.powerResource = powerResource;
            bool returnValue = CharacterUnit.GetCharacterUnit(target).BaseCharacter.CharacterStats.RecoverResource(abilityEffectContext, powerResource, finalAmount, source, true, combatMagnitude);

            if (returnValue == false)
            {
                return(false);
            }

            return(base.ProcessAbilityHit(target, finalAmount, source, combatMagnitude, abilityEffect, abilityEffectContext, powerResource));
        }
Пример #6
0
        public override bool TakeDamage(int damage, Vector3 sourcePosition, BaseCharacter source, CombatType combatType, CombatMagnitude combatMagnitude, string abilityName)
        {
            //Debug.Log("PlayerCombat.TakeDamage(" + damage + ", " + source.name + ")");
            // enter combat first because if we die from this hit, we don't want to enter combat when dead
            EnterCombat(source);
            // added damageTaken bool to prevent blood effects from showing if you ran out of range of the attack while it was in progress
            bool damageTaken = base.TakeDamage(damage, sourcePosition, source, combatType, combatMagnitude, abilityName);

            if (onHitAbility == null && SystemConfigurationManager.MyInstance.MyTakeDamageAbility != null && damageTaken)
            {
                MyBaseCharacter.MyCharacterAbilityManager.BeginAbility(SystemConfigurationManager.MyInstance.MyTakeDamageAbility, MyBaseCharacter.MyCharacterUnit.gameObject);
            }
            return(damageTaken);
        }
Пример #7
0
        public override bool ProcessAbilityHit(GameObject target, int finalAmount, IAbilityCaster source, CombatMagnitude combatMagnitude, AbilityEffect abilityEffect, AbilityEffectContext abilityEffectContext, PowerResource powerResource)
        {
            bool returnValue = target.GetComponent <CharacterUnit>().MyCharacter.CharacterCombat.TakeDamage(abilityEffectContext, powerResource, finalAmount, source, combatMagnitude, this);

            if (returnValue == false)
            {
                return(false);
            }

            return(base.ProcessAbilityHit(target, finalAmount, source, combatMagnitude, abilityEffect, abilityEffectContext, powerResource));
        }
Пример #8
0
 public override void RecoverResource(AbilityEffectContext abilityEffectContext, PowerResource powerResource, int amount, IAbilityCaster source, bool showCombatText = true, CombatMagnitude combatMagnitude = CombatMagnitude.normal)
 {
     base.RecoverResource(abilityEffectContext, powerResource, amount, source, showCombatText, combatMagnitude);
     CombatLogUI.MyInstance.WriteSystemMessage("You gain " + amount + " " + powerResource.DisplayName);
 }
Пример #9
0
        public override void ProcessAbilityHit(GameObject target, int finalAmount, IAbilityCaster source, CombatMagnitude combatMagnitude, AbilityEffect abilityEffect, AbilityEffectContext abilityEffectInput, PowerResource powerResource)
        {
            abilityEffectInput.powerResource = powerResource;
            target.GetComponent <CharacterUnit>().MyCharacter.CharacterStats.RecoverResource(abilityEffectInput, powerResource, finalAmount, source, true, combatMagnitude);

            base.ProcessAbilityHit(target, finalAmount, source, combatMagnitude, abilityEffect, abilityEffectInput, powerResource);
        }
Пример #10
0
        public override bool TakeDamage(AbilityEffectContext abilityEffectContext, PowerResource powerResource, int damage, IAbilityCaster source, CombatMagnitude combatMagnitude, AbilityEffect abilityEffect, bool reflectDamage = false)
        {
            //Debug.Log("PlayerCombat.TakeDamage(" + damage + ", " + source.name + ")");
            // enter combat first because if we die from this hit, we don't want to enter combat when dead
            EnterCombat(source);
            // added damageTaken bool to prevent blood effects from showing if you ran out of range of the attack while it was in progress

            /*
             * bool damageTaken = base.TakeDamage(damage, sourcePosition, source, combatMagnitude, abilityEffect, reflectDamage = false);
             * return damageTaken;
             */
            return(base.TakeDamage(abilityEffectContext, powerResource, damage, source, combatMagnitude, abilityEffect, reflectDamage = false));
        }
Пример #11
0
        public override bool ProcessAbilityHit(Interactable target, int finalAmount, IAbilityCaster source, CombatMagnitude combatMagnitude, AbilityEffect abilityEffect, AbilityEffectContext abilityEffectInput, PowerResource powerResource)
        {
            abilityEffectInput.powerResource = powerResource;
            bool returnValue = CharacterUnit.GetCharacterUnit(target).BaseCharacter.CharacterStats.RecoverResource(abilityEffectInput, powerResource, finalAmount, source, true, combatMagnitude);

            if (returnValue == false)
            {
                return(false);
            }

            return(base.ProcessAbilityHit(target, finalAmount, source, combatMagnitude, abilityEffect, abilityEffectInput, powerResource));
        }
Пример #12
0
        public override void ProcessAbilityHit(GameObject target, int finalAmount, IAbilityCaster source, CombatMagnitude combatMagnitude, AbilityEffect abilityEffect, AbilityEffectContext abilityEffectInput, PowerResource powerResource)
        {
            target.GetComponent <CharacterUnit>().MyCharacter.CharacterCombat.TakeDamage(abilityEffectInput, powerResource, finalAmount, source, combatMagnitude, this, abilityEffectInput.reflectDamage);

            base.ProcessAbilityHit(target, finalAmount, source, combatMagnitude, abilityEffect, abilityEffectInput, powerResource);
        }