예제 #1
0
        public void TargetHit(IBattleEntity target, TargetHitType hitType, Skill skill, short?skillEffect = null,
                              short?mapX = null, short?mapY = null, ComboDTO skillCombo = null, bool showTargetAnimation = false,
                              bool isPvp = false)
        {
            if (target == null || Entity == null)
            {
                return;
            }

            if (!target.IsTargetable(Entity.SessionType(), isPvp) ||
                target.Faction == Entity.Faction && ServerManager.Instance.Act4Maps.Any(m => m == Entity.MapInstance))
            {
                if (Session is Character cha)
                {
                    cha.Session.SendPacket($"cancel 2 {target.GetId()}");
                }

                return;
            }

            MapInstance mapInstance = target.MapInstance;
            int         hitmode     = 0;
            bool        onyxWings   = false;
            int         damage      = DamageHelper.Instance.GenerateDamage(this, target, skill, ref hitmode, ref onyxWings);

            if (skill != null && SkillHelper.Instance.NoDamageSkills != null)
            {
                if (SkillHelper.Instance.NoDamageSkills.Any(s => s == skill.SkillVNum))
                {
                    target.DealtDamage = 0;
                    damage             = 0;
                }
            }

            if (Session is Character charact && mapInstance != null && hitmode != 1)
            {
                target.RemoveBuff(548);
                if (onyxWings)
                {
                    short onyxX  = (short)(charact.PositionX + 2);
                    short onyxY  = (short)(charact.PositionY + 2);
                    int   onyxId = mapInstance.GetNextId();
                    var   onyx   = new MapMonster
                    {
                        MonsterVNum   = 2371,
                        MapX          = onyxX,
                        MapY          = onyxY,
                        MapMonsterId  = onyxId,
                        IsHostile     = false,
                        IsMoving      = false,
                        ShouldRespawn = false
                    };
                    mapInstance.Broadcast($"guri 31 1 {charact.CharacterId} {onyxX} {onyxY}");
                    onyx.Initialize(mapInstance);
                    mapInstance.AddMonster(onyx);
                    mapInstance.Broadcast(onyx.GenerateIn());
                    target.GetDamage(target.DealtDamage / 2, Entity, false);
                    Observable.Timer(TimeSpan.FromMilliseconds(350)).Subscribe(o =>
                    {
                        mapInstance.Broadcast(
                            $"su 3 {onyxId} {(target is Character ? "1" : "3")} {target.GetId()} -1 0 -1 {skill.Effect} -1 -1 1 {(int)(target.CurrentHp / (double)target.MaxHp * 100)} {(target.BattleEntity.IsReflecting ? 0 : target.DealtDamage) / 2} 0 0");
                        mapInstance.RemoveMonster(onyx);
                        mapInstance.Broadcast(onyx.GenerateOut());
                    });
                }

                if (target is Character tchar)
                {
                    if (tchar.ReflectiveBuffs.Any())
                    {
                        int?multiplier = 0;

                        foreach (KeyValuePair <short, int?> entry in tchar.ReflectiveBuffs)
                        {
                            multiplier += entry.Value;
                        }
                        ushort damaged = (ushort)(damage > tchar.Level * multiplier ? tchar.Level * multiplier : damage);
                        mapInstance.Broadcast(
                            $"su 1 {tchar.GetId()} 1 {charact.GetId()} -1 0 -1 {skill.Effect} -1 -1 1 {(int)(tchar.Hp / (double)target.MaxHp * 100)} {damaged} 0 1");
                        charact.Hp = charact.Hp - damaged <= 0 ? 1 : charact.Hp - damaged;
                        charact.Session.SendPacket(charact.GenerateStat());
                        target.DealtDamage = 0;
                    }
                }
                else if (target is MapMonster tmon)
                {
                    if (tmon.ReflectiveBuffs.Any())
                    {
                        int?multiplier = 0;

                        foreach (KeyValuePair <short, int?> entry in tmon.ReflectiveBuffs)
                        {
                            multiplier += entry.Value;
                        }

                        ushort damaged = (ushort)(damage > tmon.Monster.Level * multiplier ? tmon.Monster.Level * multiplier : damage);
                        charact.Hp -= charact.Hp - damaged <= 0 ? 1 : charact.Hp - damaged;
                        charact.Session.SendPacket(charact.GenerateStat());
                        mapInstance.Broadcast(
                            $"su 3 {tmon.GetId()} 1 {charact.GetId()} -1 0 -1 {skill.Effect} -1 -1 1 {(int)(tmon.CurrentHp / (double)target.MaxHp * 100)} {damaged} 0 1");
                        target.DealtDamage = 0;
                    }
                }
            }

            if (target.GetSession() is Character character)
            {
                damage             = (ushort)(character.HasGodMode ? 0 : damage);
                target.DealtDamage = (ushort)(character.HasGodMode ? 0 : damage);
                if (character.IsSitting)
                {
                    character.IsSitting = false;
                    character.MapInstance.Broadcast(character.GenerateRest());
                }
            }
            else if (target.GetSession() is Mate mate)
            {
                if (mate.IsSitting)
                {
                    mate.IsSitting = false;
                    mate.Owner.MapInstance.Broadcast(mate.GenerateRest());
                }
            }

            int castTime = 0;

            if (skill != null && skill.CastEffect != 0)
            {
                Entity.MapInstance.Broadcast(Entity.GenerateEff(skill.CastEffect), Entity.GetPos().X,
                                             Entity.GetPos().Y);
                castTime = skill.CastTime * 100;
            }

            Observable.Timer(TimeSpan.FromMilliseconds(castTime)).Subscribe(o => TargetHit2(target, hitType, skill,
                                                                                            damage, hitmode, skillEffect, mapX, mapY, skillCombo, showTargetAnimation, isPvp));
        }