Example #1
0
        public override AttackInfo OnAttack(Pet pet)
        {
            if (Alive)
            {
                AttackInfo info = new AttackInfo();
                info.Damage = 0;
                info.Critical = false;
                info.Type = AttackType.Miss;

                info.TargetID = MonsterID;
                info.TargetType = (byte)Type;
                info.TargetX = (short)Position.X;
                info.TargetY = (short)Position.Y;
                info.TargetZ = 0;

                info.AttackerID = pet.PetID;
                info.AttackerType = (byte)pet.Type;

                if (pet.TotalAttackRating > AttackRating)
                {
                    info.Type = AttackType.Hit;
                    if (PercentSuccess(10))
                        info.Critical = true;
                }
                else
                {
                    int chance = Random().Next(1, AttackRating);
                    if (chance <= pet.TotalAttackRating)
                        info.Type = AttackType.Hit;
                    else
                        info.Type = AttackType.Miss;
                }
                if (info.Type == AttackType.Hit)
                {
                    info.Damage = pet.TotalDamage - Defense / 3;
                    if (info.Damage <= 0)
                        info.Damage = 1;
                    if (info.Critical)
                        info.Damage *= 6;
                    if (info.Damage <= CurHealth)
                    {
                        CurHealth -= info.Damage;
                    }
                    else if (info.Damage >= CurHealth)
                    {
                        Alive = false;
                        CurHealth = 0;
                        DeathTime = DateTime.Now;
                        info.Dead = true;
                        info.Experience = Experience;
                    }
                }

                return info;
            }
            else
                return base.OnAttack(pet);
        }
Example #2
0
        public override AttackInfo OnAttack(Character ch)
        {
            if (ch.Alive)
            {
                AttackInfo info = new AttackInfo();
                info.Damage = 0;
                info.Critical = false;
                info.Type = AttackType.Miss;

                info.TargetID = PetID;
                info.TargetType = (byte)Type;
                info.TargetX = (short)Position.X;
                info.TargetY = (short)Position.Y;
                info.TargetZ = 0;

                info.AttackerID = ch.CharacterId;
                info.AttackerType = (byte)ch.Type;

                if (ch.TotalAttackRating > TotalAttackRating)
                {
                    info.Type = AttackType.Hit;
                    if (PercentSuccess(ch.Critical))
                        info.Critical = true;
                }
                else
                {
                    int chance = Random().Next(1, TotalAttackRating);
                    if (chance <= ch.TotalAttackRating)
                        info.Type = AttackType.Hit;
                    else
                        info.Type = AttackType.Miss;
                }
                if (info.Type == AttackType.Hit)
                {
                    info.Damage = ch.TotalDamage - TotalDefense / 3;
                    if (info.Damage <= 0)
                        info.Damage = 1;
                    if (info.Critical)
                        info.Damage *= 6;
                    if (info.Damage <= CurHealth)
                    {
                        CurHealth -= info.Damage;
                    }
                    else if (info.Damage >= CurHealth)
                    {
                        Alive = false;
                        CurHealth = 0;
                        info.Dead = true;
                    }
                }

                return info;
            }
            else
                return base.OnAttack(ch);
        }
Example #3
0
        public override AttackInfo OnAttack(Character ch)
        {
            if (Alive && ch.Alive)
            {
                AttackInfo info = new AttackInfo();
                info.Damage = 0;
                info.Critical = false;
                info.Type = AttackType.Miss;

                info.TargetID = CharacterId;
                info.TargetType = (byte)Type;
                info.TargetX = (short)Position.X;
                info.TargetY = (short)Position.Y;
                info.TargetZ = 0;

                info.AttackerID = ch.CharacterId;
                info.AttackerType = (byte)ch.Type;

                if (ch.TotalAttackRating > TotalAttackRating)
                {
                    info.Type = AttackType.Hit;
                    if (PercentSuccess(ch.Critical))
                        info.Critical = true;
                }
                else
                {
                    int chance = Random().Next(1, TotalAttackRating);
                    if (chance <= ch.TotalAttackRating)
                        info.Type = AttackType.Hit;
                    else
                        info.Type = AttackType.Miss;
                }
                if (info.Type == AttackType.Hit)
                {
                    info.Damage = ch.TotalDamage - TotalDefence / 3;
                    if (info.Damage <= 0)
                        info.Damage = 1;
                    if (info.Critical)
                        info.Damage *= 6;

                    if (UsingReflection())
                    {
                        float damageInc = ReflectPerc;
                        float increase = (damageInc / 100);
                        int amount = (int)(info.Damage * increase);
                        info.Damage -= amount;
                        if (info.Damage <= 0)
                            info.Damage = 1;

                        info.DoRefDamage = true;
                    }

                    if (UsingShadow())
                    {
                        if (info.Damage <= tempPet.CurHealth)
                        {
                            tempPet.CurHealth -= info.Damage;
                            info.PetDamaged = true;
                        }
                        else if (info.Damage >= tempPet.CurHealth)
                        {
                            info.PetDamaged = true;
                            info.PetDied = true;
                        }
                    }
                    else
                    {
                        if (info.Damage <= CurrentHp)
                        {
                            CurrentHp -= info.Damage;
                        }
                        else if (info.Damage >= CurrentHp)
                        {
                            Alive = false;
                            CurrentHp = 0;
                            DeathTime = DateTime.Now;
                            info.Dead = true;
                        }
                    }
                }

                return info;
            }
            else
                return base.OnAttack(ch);
        }
Example #4
0
 public ClientAttackEventArgs(AttackInfo i)
 {
     info = i;
 }
Example #5
0
 public static byte[] SendAttack2(AttackInfo i, BaseEntity target)
 {
     Packet p = new Packet(200);
     p.WriteByte((byte)i.Type);
     p.WriteByte(i.AttackerType);
     p.WriteInt(i.AttackerID);
     p.WriteShort(i.TargetX);
     p.WriteShort(i.TargetY);
     p.WriteByte(i.TargetZ);
     p.WriteByte(i.TargetType);
     p.WriteInt(i.TargetID);
     if (target is Monster)
     {
         Monster m = target as Monster;
         p.WriteInt(m.MaxHealth);
         p.WriteInt(m.CurHealth);
     }
     if (target is Character)
     {
         Character ch = target as Character;
         p.WriteInt(ch.MaxHp);
         p.WriteInt(ch.CurrentHp);
     }
     if (target is Pet)
     {
         Pet pet = target as Pet;
         p.WriteInt(pet.MaxHealth);
         p.WriteInt(pet.CurHealth);
     }
     p.WriteInt(i.Damage);
     p.WriteInt(i.Experience);
     p.WriteHexString("00");
     p.WriteByte(Convert.ToByte(i.Critical));
     return p.GetWrittenBuffer(PacketIds.SendAttack2);
 }
Example #6
0
 public static byte[] SendAttack1(AttackInfo i)
 {
     Packet p = new Packet(200);
     p.WriteByte(i.AttackerType);
     p.WriteInt(i.AttackerID);
     p.WriteShort(i.TargetX);
     p.WriteShort(i.TargetY);
     p.WriteByte(i.TargetZ);
     p.WriteByte(i.TargetType);
     p.WriteInt(i.TargetID);
     p.WriteHexString("00 0D");
     return p.GetWrittenBuffer(PacketIds.SendAttack1);
 }
Example #7
0
        public static AttackInfo RecvAttack2(Packet p)
        {
            p.Skip(2);
            byte attackertype = p.ReadByte();
            int attackerid = p.ReadInt();
            short targetx = p.ReadShort();
            short targety = p.ReadShort();
            byte targetz = p.ReadByte();
            byte targettype = p.ReadByte();
            int targetid = p.ReadInt();

            AttackInfo i = new AttackInfo
            {
                PacketID = 2,
                AttackerType = attackertype,
                AttackerID = attackerid,
                TargetX = targetx,
                TargetY = targety,
                TargetZ = targetz,
                TargetType = targettype,
                TargetID = targetid
            };

            return i;
        }