Example #1
0
        private static void doMeleeAttack(Humanoid ___m_character, ItemDrop.ItemData ___m_weapon, Attack __instance,
                                          EffectList ___m_hitEffect, Skills.SkillType ___m_specialHitSkill, DestructibleType ___m_specialHitType,
                                          bool ___m_lowerDamagePerHit, float ___m_forceMultiplier, float ___m_staggerMultiplier, float ___m_damageMultiplier,
                                          int ___m_attackChainLevels, int ___m_currentAttackCainLevel, DestructibleType ___m_resetChainIfHit,
                                          ref int ___m_nextAttackChainLevel, EffectList ___m_hitTerrainEffect, float ___m_attackHitNoise, Vector3 pos,
                                          Collider col, Vector3 dir, GameObject ___m_spawnOnTrigger)
        {
            Vector3 zero  = Vector3.zero;
            bool    flag2 = false; //rename
            HashSet <Skills.SkillType> skillTypeSet = new HashSet <Skills.SkillType>();
            bool hitOccured = false;

            ___m_weapon.m_shared.m_hitEffect.Create(pos, Quaternion.identity);
            ___m_hitEffect.Create(pos, Quaternion.identity);

            GameObject hitObject = Projectile.FindHitObject(col);

            if (!(hitObject == ___m_character.gameObject))
            {
                Vagon component1 = hitObject.GetComponent <Vagon>();
                if (!component1 || !component1.IsAttached(___m_character))
                {
                    Character component2 = hitObject.GetComponent <Character>();
                    if (!(component2 != null) ||
                        (___m_character.IsPlayer() || BaseAI.IsEnemy(___m_character, component2)) &&
                        (!___m_weapon.m_shared.m_dodgeable || !component2.IsDodgeInvincible()))
                    {
                        hitOccured = true;
                    }
                }
            }

            if (!hitOccured)
            {
                return;
            }

            IDestructible component = hitObject.GetComponent <IDestructible>();

            if (component != null)
            {
                DestructibleType destructibleType = component.GetDestructibleType();
                Skills.SkillType skill            = ___m_weapon.m_shared.m_skillType;

                if (___m_specialHitSkill != Skills.SkillType.None &&
                    (destructibleType & ___m_specialHitType) != DestructibleType.None)
                {
                    skill = ___m_specialHitSkill;
                }

                float randomSkillFactor = ___m_character.GetRandomSkillFactor(skill);

                if (___m_lowerDamagePerHit)
                {
                    randomSkillFactor /= 0.75f;
                }

                HitData hitData = new HitData();
                hitData.m_toolTier     = ___m_weapon.m_shared.m_toolTier;
                hitData.m_statusEffect = ___m_weapon.m_shared.m_attackStatusEffect
                    ? ___m_weapon.m_shared.m_attackStatusEffect.name
                    : "";
                hitData.m_pushForce         = ___m_weapon.m_shared.m_attackForce * randomSkillFactor * ___m_forceMultiplier;
                hitData.m_backstabBonus     = ___m_weapon.m_shared.m_backstabBonus;
                hitData.m_staggerMultiplier = ___m_staggerMultiplier;
                hitData.m_dodgeable         = ___m_weapon.m_shared.m_dodgeable;
                hitData.m_blockable         = ___m_weapon.m_shared.m_blockable;
                hitData.m_skill             = skill;
                hitData.m_damage            = ___m_weapon.GetDamage();
                hitData.m_point             = pos;
                hitData.m_dir         = dir;
                hitData.m_hitCollider = col;
                hitData.SetAttacker(___m_character);
                hitData.m_damage.Modify(___m_damageMultiplier);
                hitData.m_damage.Modify(randomSkillFactor);
                hitData.m_damage.Modify((float)getLevelDamageFactorMethod.Invoke(__instance, null));
                if (___m_attackChainLevels > 1 && ___m_currentAttackCainLevel == ___m_attackChainLevels - 1)
                {
                    hitData.m_damage.Modify(2f);
                    hitData.m_pushForce *= 1.2f;
                }
                hitData.m_damage.Modify(MeshCooldown.calcDamageMultiplier());

                ___m_character.GetSEMan().ModifyAttack(skill, ref hitData);
                if (component is Character)
                {
                    flag2 = true;
                }
                component.Damage(hitData);
                if ((destructibleType & ___m_resetChainIfHit) != DestructibleType.None)
                {
                    ___m_nextAttackChainLevel = 0;
                }
                skillTypeSet.Add(skill);
            }

            ___m_weapon.m_shared.m_hitTerrainEffect.Create(pos,
                                                           Quaternion.identity); // Quaternion.identity might need to be replaced
            ___m_hitTerrainEffect.Create(pos, Quaternion.identity);

            if (___m_weapon.m_shared.m_spawnOnHitTerrain)
            {
                spawnOnHitTerrainMethod.Invoke(__instance,
                                               new object[] { pos, ___m_weapon.m_shared.m_spawnOnHitTerrain });
            }

            if (___m_weapon.m_shared.m_useDurability && ___m_character.IsPlayer())
            {
                ___m_weapon.m_durability -= ___m_weapon.m_shared.m_useDurabilityDrain;
            }
            ___m_character.AddNoise(___m_attackHitNoise);

            if (___m_weapon.m_shared.m_spawnOnHit)
            {
                Object.Instantiate(___m_weapon.m_shared.m_spawnOnHit, pos,
                                   Quaternion.identity).GetComponent <IProjectile>()
                ?.Setup(___m_character, zero, ___m_attackHitNoise, null, ___m_weapon);
            }
            foreach (Skills.SkillType skill in skillTypeSet)
            {
                ___m_character.RaiseSkill(skill, flag2 ? 1.5f : 1f);
            }

            if (!___m_spawnOnTrigger)
            {
                return;
            }
            Object.Instantiate(___m_spawnOnTrigger, zero,
                               Quaternion.identity).GetComponent <IProjectile>()?.Setup(___m_character,
                                                                                        ___m_character.transform.forward, -1f, null, ___m_weapon);

            return;
        }