public void BehaveWall(Player killer, Wall w, World wallWorld) { this.Host = w; BehaviorCondition cond = BehaviorCondition.OnDeath; if (cond == BehaviorCondition.OnDeath) { wOwner = wallWorld; var dat = new Tuple<Player, int>[]{ new Tuple<Player, int>(killer, 500) }; Dictionary<Player, List<Item>> items = new Dictionary<Player, List<Item>>(); ProcessPublicBags(rand, dat); ProcessSoulBags(rand, dat); } }
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; } }
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 } }); }*/ }
public static void GenWalls(World Owner, Wall w) { Random r = new Random(); 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; GenWall(Owner, w.X + tx, w.Y + ty, r); } } }
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; int rsX = 1; int rsY = 1; do rsX = rand.Next(6, 12 + 1); while (rsX % 2 > 0); do rsY = rand.Next(6, 12 + 1); while (rsY % 2 > 0); //Console.Out.WriteLine("Room size: " + rsX + ", " + rsY); switch (dirs.First()) { case "up": mainX = x - (rsX / 2); mainY = y - rsY; entranceY = y - 1; break; case "down": mainX = x - (rsX / 2); mainY = y + 1; entranceY = y + 1; break; case "left": mainX = x - rsX; mainY = y - ((rsY - 2)/2); entranceX = x - 1; break; case "right": mainX = x + 1; mainY = y - ((rsY - 2)/2); entranceX = x + 1; break; } entranceX -= 0.5f; entranceY -= 0.5f; List<WmapTile> addedTiles = new List<WmapTile>(); for(int ty = (int)mainY; ty <= mainY + (rsY - 1); ty++) for (int tx = (int)mainX; tx <= mainX + (rsX - 1); 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; float blackPotSpotX = (float)rand.Next((int)mainX + 1, (int)mainX + rsX); float blackPotSpotY = (float)rand.Next((int)mainY + 1, (int)mainY + rsY); for(int ty = (int)mainY; ty <= mainY + (rsY - 1); ty++) for (int tx = (int)mainX; tx <= mainX + (rsX - 1); tx++) { WmapTile ctile = addedTiles[tileNum]; world.Map[tx, ty] = ctile; if ((tx == (int)mainX || tx == (int)mainX + (rsX - 1) || ty == (int)mainY || ty == (int)mainY + (rsY - 1)) && !(tx == entranceX && ty == entranceY)) { //Console.Out.WriteLine(tx + ", " + ty + " - " + entranceX + ", " + entranceY); //Console.Out.WriteLine("Placed wall"); GenWall(world, tx + 0.5f, ty + 0.5f, rand); } else { //Console.Out.WriteLine("Placed treasure"); if (rand.Next(1, 25) == 1) { if ((world as Mine).RoomsFound == 3 ? (tx != blackPotSpotX && ty != blackPotSpotY) : true) { Entity e = Entity.Resolve((short)rand.Next(0x196f, 0x1972)); e.Move(tx + 0.5f, ty + 0.5f); world.EnterWorld(e); } } } } (world as Mine).RoomsFound++; if ((world as Mine).RoomsFound == 4) { Entity e = Entity.Resolve(XmlDatas.IdToType["Pot of Descent"]); e.Move(blackPotSpotX + 0.5f, blackPotSpotY + 0.5f); world.EnterWorld(e); } //Console.Out.WriteLine("Placed tiles!"); return true; } catch(Exception e) { return false; } }
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); }