public void EnemyHit(RealmTime time, EnemyHitPacket pkt)
 {
     try
     {
         var entity = Owner.GetEntity(pkt.TargetId);
         var prj = (this as IProjectileOwner).Projectiles[pkt.BulletId];
         prj.Damage = (int)statsMgr.GetAttackDamage(prj.Descriptor.MinDamage, prj.Descriptor.MaxDamage);
         prj.ForceHit(entity, time);
         if (pkt.Killed && !(entity is Wall))
         {
             Client.SendPacket(new UpdatePacket
             {
                 Tiles = new UpdatePacket.TileData[0],
                 NewObjects = new[] { entity.ToDefinition() },
                 RemovedObjectIds = new[] { pkt.TargetId }
             });
             _clientEntities.Remove(entity);
         }
     }
     catch
     {
     }
 }
 public void EnemyHit(RealmTime time, EnemyHitPacket pkt)
 {
     var entity = Owner.GetEntity(pkt.TargetId);
     if (entity != null && pkt.Killed)   //Tolerance
     {
         Projectile prj = (this as IProjectileOwner).Projectiles[pkt.BulletId];
         Position? entPos = entity.TryGetHistory((time.tickTimes - tickMapping) - pkt.Time);
         Position? prjPos = prj == null ? null : (Position?)prj.GetPosition(pkt.Time + tickMapping - prj.BeginTime);
         var tol1 = (entPos == null || prjPos == null) ? 10 : (prjPos.Value.X - entPos.Value.X) * (prjPos.Value.X - entPos.Value.X) + (prjPos.Value.Y - entPos.Value.Y) * (prjPos.Value.Y - entPos.Value.Y);
         var tol2 = prj == null ? 10 : (prj.X - entity.X) * (prj.X - entity.X) + (prj.Y - entity.Y) * (prj.Y - entity.Y);
         if (prj != null && (tol1 < 1 || tol2 < 1))
         {
             prj.ForceHit(entity, time);
         }
         else
         {
             Console.WriteLine("CAN'T TOLERANT! " + tol1 + " " + tol2);
             psr.SendPacket(new UpdatePacket()
             {
                 Tiles = new UpdatePacket.TileData[0],
                 NewObjects = new ObjectDef[] { entity.ToDefinition() },
                 RemovedObjectIds = new int[] { pkt.TargetId }
             });
             clientEntities.Remove(entity);
         }
     }
     else if (pkt.Killed)
     {
         psr.SendPacket(new UpdatePacket()
         {
             Tiles = new UpdatePacket.TileData[0],
             NewObjects = Empty<ObjectDef>.Array,
             RemovedObjectIds = new int[] { pkt.TargetId }
         });
     }
 }
Example #3
0
 public void EnemyHit(RealmTime time, EnemyHitPacket pkt)
 {
     try
     {
         var entity = Owner.GetEntity(pkt.TargetId);
         Projectile prj = (this as IProjectileOwner).Projectiles[pkt.BulletId];
         prj.Damage = (int)statsMgr.GetAttackDamage(prj.Descriptor.MinDamage, prj.Descriptor.MaxDamage);
         if (entity is Wall)
         {
             if (entity.ObjectDesc.ObjectId == "Vlux Mine")
             {
                 if (prj.Descriptor.MinDamage < 140)
                 {
                     prj.Damage = 0;
                 }
             }
         }
         prj.ForceHit(entity, time);
         if (pkt.Killed && !(entity is Wall))
         {
             psr.SendPacket(new UpdatePacket()
             {
                 Tiles = new UpdatePacket.TileData[0],
                 NewObjects = new ObjectDef[] { entity.ToDefinition() },
                 RemovedObjectIds = new int[] { pkt.TargetId }
             });
             clientEntities.Remove(entity);
         }
         else if ((entity is Wall) && Owner.Mining && (entity as Wall).HP < 0)
         {
             Wall w = (entity as Wall);
             try { (w.CondBehaviors[0] as LootBehavior).BehaveWall(this, w, Owner); }
             catch (Exception e) { Console.Out.WriteLine("Loot drop error - Wall"); Console.Out.WriteLine(e); }
             GenLogic.GenRandomRoom(Owner, w.X, w.Y, w);
             GenLogic.GenWalls(Owner, w);
         }
     }
     catch
     {
         /*Console.ForegroundColor = ConsoleColor.DarkMagenta;
         Console.WriteLine("CAN'T REGISTER HIT by player " + Name);
         Console.ForegroundColor = ConsoleColor.White;
          *
          * Disabled, this message spams when an enemy dies*/
     }
     /*
     if (entity != null && pkt.Killed)   //Tolerance
     {
         Projectile prj = (this as IProjectileOwner).Projectiles[pkt.BulletId];
         Position? entPos = entity.TryGetHistory((time.tickTimes - tickMapping) - pkt.Time);
         Position? prjPos = prj == null ? null : (Position?)prj.GetPosition(pkt.Time + tickMapping - prj.BeginTime);
         var tol1 = (entPos == null || prjPos == null) ? 10 : (prjPos.Value.X - entPos.Value.X) * (prjPos.Value.X - entPos.Value.X) + (prjPos.Value.Y - entPos.Value.Y) * (prjPos.Value.Y - entPos.Value.Y);
         var tol2 = prj == null ? 10 : (prj.X - entity.X) * (prj.X - entity.X) + (prj.Y - entity.Y) * (prj.Y - entity.Y);
         if (prj != null && (tol1 < 1 || tol2 < 1))
         {
             prj.ForceHit(entity, time);
         }
         else
         {
             Console.ForegroundColor = ConsoleColor.DarkMagenta;
             Console.WriteLine("CAN'T REGISTER HIT!" + " X: " + tol1 + " Y: " + tol2);
             Console.ForegroundColor = ConsoleColor.White;
             psr.SendPacket(new UpdatePacket()
             {
                 Tiles = new UpdatePacket.TileData[0],
                 NewObjects = new ObjectDef[] { entity.ToDefinition() },
                 RemovedObjectIds = new int[] { pkt.TargetId }
             });
             clientEntities.Remove(entity);
         }
     }
     else if (pkt.Killed)
     {
         psr.SendPacket(new UpdatePacket()
         {
             Tiles = new UpdatePacket.TileData[0],
             NewObjects = Empty<ObjectDef>.Array,
             RemovedObjectIds = new int[] { pkt.TargetId }
         });
     }*/
 }
 public void EnemyHit(RealmTime time, EnemyHitPacket pkt)
 {
     try
     {
         var entity = Owner.GetEntity(pkt.TargetId);
         Projectile prj = (this as IProjectileOwner).Projectiles[pkt.BulletId];
         prj.Damage = (int)statsMgr.GetAttackDamage(prj.Descriptor.MinDamage, prj.Descriptor.MaxDamage);
         prj.ForceHit(entity, time);
         if (pkt.Killed && !(entity is Wall))
         {
             psr.SendPacket(new UpdatePacket()
             {
                 Tiles = new UpdatePacket.TileData[0],
                 NewObjects = new ObjectDef[] { entity.ToDefinition() },
                 RemovedObjectIds = new int[] { pkt.TargetId }
             });
             clientEntities.Remove(entity);
         }
     }
     catch
     {
         /*Console.ForegroundColor = ConsoleColor.DarkMagenta;
         Console.WriteLine("CAN'T REGISTER HIT by player " + Name);
         Console.ForegroundColor = ConsoleColor.White;
          *
          * Disabled, this message spams when an enemy dies*/
     }
     /*
     if (entity != null && pkt.Killed)   //Tolerance
     {
         Projectile prj = (this as IProjectileOwner).Projectiles[pkt.BulletId];
         Position? entPos = entity.TryGetHistory((time.tickTimes - tickMapping) - pkt.Time);
         Position? prjPos = prj == null ? null : (Position?)prj.GetPosition(pkt.Time + tickMapping - prj.BeginTime);
         var tol1 = (entPos == null || prjPos == null) ? 10 : (prjPos.Value.X - entPos.Value.X) * (prjPos.Value.X - entPos.Value.X) + (prjPos.Value.Y - entPos.Value.Y) * (prjPos.Value.Y - entPos.Value.Y);
         var tol2 = prj == null ? 10 : (prj.X - entity.X) * (prj.X - entity.X) + (prj.Y - entity.Y) * (prj.Y - entity.Y);
         if (prj != null && (tol1 < 1 || tol2 < 1))
         {
             prj.ForceHit(entity, time);
         }
         else
         {
             Console.ForegroundColor = ConsoleColor.DarkMagenta;
             Console.WriteLine("CAN'T REGISTER HIT!" + " X: " + tol1 + " Y: " + tol2);
             Console.ForegroundColor = ConsoleColor.White;
             psr.SendPacket(new UpdatePacket()
             {
                 Tiles = new UpdatePacket.TileData[0],
                 NewObjects = new ObjectDef[] { entity.ToDefinition() },
                 RemovedObjectIds = new int[] { pkt.TargetId }
             });
             clientEntities.Remove(entity);
         }
     }
     else if (pkt.Killed)
     {
         psr.SendPacket(new UpdatePacket()
         {
             Tiles = new UpdatePacket.TileData[0],
             NewObjects = Empty<ObjectDef>.Array,
             RemovedObjectIds = new int[] { pkt.TargetId }
         });
     }*/
 }
 public void EnemyHit(RealmTime time, EnemyHitPacket pkt)
 {
     try
     {
         var entity = Owner.GetEntity(pkt.TargetId);
         bool infiniWalling = false;
         if (Owner.Mining)
         {
             if((entity is Wall))
             {
                 infiniWalling = true;
                 Wall w = (entity as Wall);
                 w.HP = 0;
                 GenLogic.GenRandomRoom(Owner, w.X, w.Y, w);
                 for (var tx = -1; tx <= 1; tx++)
                     for (var ty = -1; ty <= 1; ty++)
                     {
                         if (Owner.Map[(int)w.X + tx, (int)w.Y + ty].TileId == 0xff && Owner.Map[(int)w.X + tx, (int)w.Y + ty].ObjId == 0)
                         {
                             WmapTile tile = Owner.Map[(int)w.X + tx, (int)w.Y + ty];
                             tile.TileId = Owner.Map[(int)w.X, (int)w.Y].TileId;
                             Owner.Map[(int)w.X + tx, (int)w.Y + ty] = tile;
                             Wall e = new Wall(w.ObjectType, XmlDatas.TypeToElement[w.ObjectType]);
                             e.Move(w.X + tx, w.Y + ty);
                             Owner.EnterWorld(e);
                         }
                     }
             }
         }
         Projectile prj = (this as IProjectileOwner).Projectiles[pkt.BulletId];
         prj.Damage = (int)statsMgr.GetAttackDamage(prj.Descriptor.MinDamage, prj.Descriptor.MaxDamage);
         prj.ForceHit(entity, time);
         if (pkt.Killed && !(entity is Wall))
         {
             psr.SendPacket(new UpdatePacket()
             {
                 Tiles = new UpdatePacket.TileData[0],
                 NewObjects = new ObjectDef[] { entity.ToDefinition() },
                 RemovedObjectIds = new int[] { pkt.TargetId }
             });
             clientEntities.Remove(entity);
         }
     }
     catch
     {
         /*Console.ForegroundColor = ConsoleColor.DarkMagenta;
         Console.WriteLine("CAN'T REGISTER HIT by player " + Name);
         Console.ForegroundColor = ConsoleColor.White;
          *
          * Disabled, this message spams when an enemy dies*/
     }
     /*
     if (entity != null && pkt.Killed)   //Tolerance
     {
         Projectile prj = (this as IProjectileOwner).Projectiles[pkt.BulletId];
         Position? entPos = entity.TryGetHistory((time.tickTimes - tickMapping) - pkt.Time);
         Position? prjPos = prj == null ? null : (Position?)prj.GetPosition(pkt.Time + tickMapping - prj.BeginTime);
         var tol1 = (entPos == null || prjPos == null) ? 10 : (prjPos.Value.X - entPos.Value.X) * (prjPos.Value.X - entPos.Value.X) + (prjPos.Value.Y - entPos.Value.Y) * (prjPos.Value.Y - entPos.Value.Y);
         var tol2 = prj == null ? 10 : (prj.X - entity.X) * (prj.X - entity.X) + (prj.Y - entity.Y) * (prj.Y - entity.Y);
         if (prj != null && (tol1 < 1 || tol2 < 1))
         {
             prj.ForceHit(entity, time);
         }
         else
         {
             Console.ForegroundColor = ConsoleColor.DarkMagenta;
             Console.WriteLine("CAN'T REGISTER HIT!" + " X: " + tol1 + " Y: " + tol2);
             Console.ForegroundColor = ConsoleColor.White;
             psr.SendPacket(new UpdatePacket()
             {
                 Tiles = new UpdatePacket.TileData[0],
                 NewObjects = new ObjectDef[] { entity.ToDefinition() },
                 RemovedObjectIds = new int[] { pkt.TargetId }
             });
             clientEntities.Remove(entity);
         }
     }
     else if (pkt.Killed)
     {
         psr.SendPacket(new UpdatePacket()
         {
             Tiles = new UpdatePacket.TileData[0],
             NewObjects = Empty<ObjectDef>.Array,
             RemovedObjectIds = new int[] { pkt.TargetId }
         });
     }*/
 }