Exemplo n.º 1
0
        public static void ModifyHitBy <A, D>(A attacker, D target, ref int damage, ref float knockback, ref bool crit)
            where A : Wrapper, IOffensiveType, IAbility, IDamageClass, IStatsBuffed
            where D : Wrapper, ITarget, IPrimaryType, ISecondaryType, IAbility
        {
            #region Testing

            //bool testing = false;
            //if (defenseWrapper is NPCWrapper npc && attackWrapper is ProjectileWrapper proj)
            //{
            //    switch (npc.GetNPC().type)
            //    {
            //        case NPCID.BlueJellyfish:
            //        case NPCID.GreenJellyfish:
            //        case NPCID.PinkJellyfish:
            //        case NPCID.BloodJelly:
            //        case NPCID.FungoFish:
            //            if (proj.Projectile.type == ProjectileID.WaterBolt)
            //            {
            //                testing = true;
            //            }
            //            break;
            //    }
            //}

            #endregion

            DamageReturn damageReturn = Damage(attacker, target);

            damage = (int)(damage * damageReturn.damage);
            if (attacker is NPCWrapper)
            {
                damage = (int)(damage * attacker.DamageMultiplication());
            }
            knockback = (knockback * damageReturn.knockback);

            float  dmg  = damageReturn.damage;
            string text = ((float)(int)(dmg * 100) / 100).ToString() + "x!";

            Color color = new Color(new Vector3(1, 1, 1));
            if (dmg != 1)
            {
                if (dmg == 0)
                {
                    color = new Color(new Vector3(0.2f, 0.2f, 0.2f));
                }

                else if (dmg > 1)
                {
                    color = new Color(new Vector3(1 - (dmg / 3), 1, 1 - (dmg / 3)));
                }

                else if (dmg < 1)
                {
                    color = new Color(new Vector3((dmg * 4) / 5 + 0.2f, (dmg) / 5 + 0.2f, 0));
                }
            }

            CombatText.NewText(target.GetRect(), color, text, false, true);
        }
Exemplo n.º 2
0
        public static B CanBeHitBy <A, D, B>(A attack, D defense, B @base, B @false)
            where A : Wrapper, IOffensiveType, IAbility, IDamageClass, IStatsBuffed
            where D : Wrapper, ITarget, IPrimaryType, ISecondaryType, IAbility
        {
            DamageReturn damageReturn = Damage(attack, defense);

            if (damageReturn.damage != 0)
            {
                return(@base);
            }
            else
            {
                return(@false);
            }
        }
Exemplo n.º 3
0
        public static void OnHit <A, D>(A attacker, D defender)
            where A : Wrapper, IOffensiveType, IAbility, IDamageClass, IHitbox, ITeam, IStatsBuffed
            where D : Wrapper, ITarget, IPrimaryType, ISecondaryType, IAbility, ITeam
        {
            if (attacker.Hitbox.Intersects(defender.GetRect()) && defender.Active && (attacker.GetTeam() != defender.GetTeam()))
            {
                Ability attackerAbility = GetAbility(attacker);
                Ability defenderAbility = GetAbility(attackerAbility.ModifyOpponentsAbility(defender.GetAbility));

                DamageReturn damageReturn = Damage(attacker, defender);
                defenderAbility.BuffOnHit(new BuffOnHitParameters(attacker.Offensive, defender, attacker));

                if (defender.GetCombatTextCooldown() <= 0)
                {
                    Message messageOnHit    = defenderAbility.MessageOnHit(new MessageOnHitParameters(attacker.Offensive, defender, attacker, attacker)).message;
                    Message messageHitEnemy = GetAbility(attacker.GetAbility).MessageHitEnemy(new MessageHitEnemyParameters(attacker.Offensive, defender, defender, defender)).message;
                    void ReadMessage(Message message)
                    {
                        if (message.hasMessage && !string.IsNullOrEmpty(message.text))
                        {
                            Color color = message.setColor ? message.textColor : new Color(255, 255, 255);
                            CombatText.NewText(defender.GetRect(), color, message.text);
                            defender.UseCombatTextCooldown();
                        }
                    }

                    ReadMessage(messageOnHit);
                    ReadMessage(messageHitEnemy);
                }

                if (defender.GetCombatHealCooldown() <= 0)
                {
                    if (damageReturn.heal)
                    {
                        float healPercent;
                        switch (defender.EntityType)
                        {
                        case EntityType.Player:
                            healPercent = 0.10f;
                            break;

                        case EntityType.NPC:
                            if (defender.Boss)
                            {
                                healPercent = 0.04f;
                            }
                            else
                            {
                                healPercent = 0.125f;
                            }
                            break;

                        default:
                            healPercent = 0;
                            break;
                        }
                        int healAmount = Math.Max((int)(defender.LifeMax * healPercent), 1);
                        if (defender.Life < defender.LifeMax)
                        {
                            defender.Heal(healAmount);
                        }
                    }
                    defender.UseCombatHealCooldown();
                }

                if (attacker is ProjectileWrapper projectileWrapper && defender is IAttractProjectileTarget attractProjectileTarget)
                {
                    if (defenderAbility.AttractProjectile(new AttractProjectileParameters(projectileWrapper, defender)))
                    {
                        projectileWrapper.Kill();
                    }
                }
            }
        }