Exemplo n.º 1
0
 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 }
         });
     }*/
 }
Exemplo n.º 2
0
 public static bool GenRandomRoom(World world, float x, float y, Wall theWall)
 {
     try
     {
         Random rand = new Random();
         if (rand.Next(1, 60) != 1)
             return false;
         //Console.Out.WriteLine("Generating room...");
         List<string> dirs = new List<string>();
         for (int tx = -1; tx <= 1; tx++)
             for (int ty = -1; ty <= 1; ty++)
             {
                 WmapTile targetTile = world.Map[(int)x + tx, (int)y + ty];
                 WmapTile thisTile = world.Map[(int)x, (int)y];
                 if (targetTile.TileId == 0xff)
                 {
                     if (tx == -1 && ty == 0)
                         dirs.Add("left");
                     else if (tx == 1 && ty == 0)
                         dirs.Add("right");
                     else if (tx == 0 && ty == 1)
                         dirs.Add("down");
                     else if (tx == 0 && ty == -1)
                         dirs.Add("up");
                 }
             }
         if (dirs.Count < 1)
             return false;
         dirs.Shuffle();
         //Console.Out.WriteLine("Room direction: " + dirs.First());
         float mainX = x;
         float mainY = y;
         float entranceX = x;
         float entranceY = y;
         switch (dirs.First())
         {
             case "up":
                 mainX = x - 6; mainY = y - 8;
                 entranceY = y - 1; break;
             case "down":
                 mainX = x - 6; mainY = y + 1;
                 entranceY = y + 1; break;
             case "left":
                 mainX = x - 12; mainY = y - 3;
                 entranceX = x - 1; break;
             case "right":
                 mainX = x + 1; mainY = y - 3;
                 entranceX = x + 1; break;
         }
         List<WmapTile> addedTiles = new List<WmapTile>();
         for (int ty = (int)mainY; ty <= mainY + 7; ty++)
             for (int tx = (int)mainX; tx <= mainX + 11; tx++)
             {
                 WmapTile tTile = world.Map[tx, ty];
                 if (tTile.TileId != 0xff || tTile.ObjType != 0)
                 {
                     //Console.Out.WriteLine("Found collision while generating room!");
                     return false;
                 }
                 tTile.TileId = world.Map[(int)x, (int)y].TileId;
                 addedTiles.Add(tTile);
             }
         //Console.Out.WriteLine("Generated tiles, placing...");
         int tileNum = 0;
         for (int ty = (int)mainY; ty <= mainY + 7; ty++)
             for (int tx = (int)mainX; tx <= mainX + 11; tx++)
             {
                 WmapTile ctile = addedTiles[tileNum];
                 if ((tx == (int)mainX || tx == (int)mainX + 11 || ty == (int)mainY || ty == (int)mainY + 7) && !(tx == entranceX && ty == entranceY))
                 {
                     //Console.Out.WriteLine("Placed wall");
                     Wall e = new Wall(theWall.ObjectType, XmlDatas.TypeToElement[theWall.ObjectType]);
                     e.Move(tx, ty);
                     world.EnterWorld(e);
                     ctile.ObjType = theWall.ObjectType;
                 }
                 else
                 {
                     //Console.Out.WriteLine("Placed treasure");
                     if (rand.Next(1, 30) == 1)
                     {
                         Entity e = Entity.Resolve(XmlDatas.IdToType["Coral Gift"]);
                         e.Move(tx + 0.5f, ty + 0.5f);
                         world.EnterWorld(e);
                         ctile.ObjType = XmlDatas.IdToType["Coral Gift"];
                     }
                 }
                 world.Map[tx, ty] = ctile;
             }
         //Console.Out.WriteLine("Placed tiles!");
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }
Exemplo n.º 3
0
 public static void GenWall(World world, float x, float y, Random rand)
 {
     short objType = 0x1960;
     List<Tuple<short,int>> ores = (world as Mine).GetOres();
     ores.Shuffle();
     if (rand.Next(0, ores.First().Item2) == 1)
     {
         objType = ores.First().Item1;
     }
     Wall e = new Wall(objType, XmlDatas.TypeToElement[objType]);
     e.Move(x, y);
     world.EnterWorld(e);
 }