Inheritance: IDisposable
Ejemplo n.º 1
0
 public static World AddWorld(World world)
 {
     world.Id = Interlocked.Increment(ref nextWorldId);
     Worlds[world.Id] = world;
     if (world is GameWorld)
         Monitor.WorldAdded(world);
     return world;
 }
Ejemplo n.º 2
0
 public void WorldClosed(World world)
 {
     lock (worldLock)
     {
         var portal = portals[world];
         nexus.LeaveWorld(portal);
         portals.Remove(world);
     }
 }
Ejemplo n.º 3
0
 public World AddWorld(World world)
 {
     if (world.Manager != null)
         throw new InvalidOperationException("World already added.");
     world.Id = Interlocked.Increment(ref nextWorldId);
     Worlds[world.Id] = world;
     OnWorldAdded(world);
     return world;
 }
Ejemplo n.º 4
0
 public World AddWorld(int id, World world)
 {
     if (world.Manager != null)
         throw new InvalidOperationException("World already added.");
     world.Id = id;
     Worlds[id] = world;
     OnWorldAdded(world);
     return world;
 }
        public void WorldRemoved(World world)
        {
            //lock (worldLock)
            //{
            var portal = portals[world];
            nexus.LeaveWorld(portal);
            portals.Remove(world);

            //}
        }
 public void WorldClosed(World world)
 {
     lock (worldLock)
     {
         Portal portal = portals[world];
         nexus.LeaveWorld(portal);
         portals.Remove(world);
         log.InfoFormat("World {0}({1}) closed.", world.Id, world.Name);
     }
 }
Ejemplo n.º 7
0
 public void Oryx(World world, string text)
 {
     world.BroadcastPacket(new TextPacket()
     {
         BubbleTime = 0,
         Stars = -1,
         Name = "#Oryx the Mad God",
         Text = text
     }, null);
 }
Ejemplo n.º 8
0
 public static bool HasPlayerNearby(World world, double x, double y)
 {
     foreach (var i in world.PlayersCollision.HitTest(x, y, 16))
     {
         var d = Dist(i.X, i.Y, x, y);
         if (d < 16*16)
             return true;
     }
     return false;
 }
Ejemplo n.º 9
0
 public bool Tick(World world, RealmTime time)
 {
     remain -= time.thisTickTimes;
     if (remain < 0)
     {
         cb(world, time);
         return true;
     }
     return false;
 }
 public void Oryx(World world, string text)
 {
     world.BroadcastPacket(new TextPacket()
     {
         BubbleTime = 0,
         Stars = -1,
         Name = "#Oryx the Mad God",
         Text = text.ToSafeText()
     }, null);
     logger.InfoFormat("[{0}({1})] <Oryx the Mad God> {2}", world.Name, world.Id, text);
 }
Ejemplo n.º 11
0
 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);
     }
 }
Ejemplo n.º 12
0
 public void WorldOpened(World world)
 {
     lock (worldLock)
     {
         var pos = GetRandPosition();
         var portal = new Portal(0x71c, null)
         {
             Size = 150,
             WorldInstance = world,
             Name = world.Name
         };
         portal.Move(pos.X, pos.Y);
         nexus.EnterWorld(portal);
         portals.Add(world, portal);
     }
 }
Ejemplo n.º 13
0
 public void WorldAdded(World world)
 {
     lock (worldLock)
     {
         var pos = GetRandPosition();
         var portal = new Portal(0x0712, null)
         {
             Size = 80,
             WorldInstance = world,
             Name = world.Name
         };
         portal.Move(pos.X + 0.5f, pos.Y + 0.5f);
         nexus.EnterWorld(portal);
         portals.Add(world, portal);
     }
 }
Ejemplo n.º 14
0
 public void WorldOpened(World world)
 {
     lock (worldLock)
     {
         var pos = GetRandPosition();
         var portal = new Portal(manager, 0x71c, null)
         {
             Size = 150,
             WorldInstance = world,
             Name = world.Name
         };
         portal.Move(pos.X, pos.Y);
         nexus.EnterWorld(portal);
         portals.Add(world, portal);
         log.InfoFormat("World {0}({1}) opened.", world.Id, world.Name);
     }
 }
 public void WorldAdded(World world)
 {
     lock (worldLock)
     {
         Position pos = GetRandPosition();
         var portal = new Portal(manager, 0x0712, null)
         {
             Size = 80,
             WorldInstance = world,
             Name = world.Name
         };
         portal.Move(pos.X + 0.5f, pos.Y + 0.5f);
         nexus.EnterWorld(portal);
         portals.Add(world, portal);
         log.InfoFormat("World {0}({1}) added.", world.Id, world.Name);
     }
 }
 public bool Tick(World world, RealmTime time)
 {
     if (destroy)
     {
         world.Timers.Remove(this);
         return true;
     }
     remain -= time.thisTickTimes;
     if (remain < 0)
     {
         try
         {
             cb(world, time);
         }
         catch (Exception ex)
         {
             logger.Error(ex);
         }
         return true;
     }
     return false;
 }
 public void WorldRemoved(World world)
 {
     lock (worldLock)
     {
         if (!portals.ContainsKey(world))
             return;
         Portal portal = portals[world];
         nexus.LeaveWorld(portal);
         portals.Remove(world);
         log.InfoFormat("World {0}({1}) removed.", world.Id, world.Name);
     }
 }
Ejemplo n.º 18
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;
     }
 }
Ejemplo n.º 19
0
 public static void AOEPet(World world, Position pos, float radius, Action<Entity> callback) //Null for player
 {
     foreach (
         var i in
             from i in world.EnemiesCollision.HitTest(pos.X, pos.Y, radius).Where(i => !i.isPet).OfType<Enemy>()
             let d = Dist(i.X, i.Y, pos.X, pos.Y)
             where d < radius
             select i)
         callback(i);
 }
Ejemplo n.º 20
0
 public static bool HasPlayerNearby(World world, double x, double y) => world.PlayersCollision.HitTest(x, y, 16).Select(i => Dist(i.X, i.Y, x, y)).Any(d => d < 16*16);
Ejemplo n.º 21
0
 public static void AOE(World world, Position pos, float radius, bool players, Action<Entity> callback)
 //Null for player
 {
     if (players)
         foreach (var i in from i in world.PlayersCollision.HitTest(pos.X, pos.Y, radius)
             let d = Dist(i.X, i.Y, pos.X, pos.Y)
             where d < radius
             select i)
             callback(i);
     else
         foreach (var i in from i in world.EnemiesCollision.HitTest(pos.X, pos.Y, radius).OfType<Enemy>()
             let d = Dist(i.X, i.Y, pos.X, pos.Y)
             where d < radius
             select i)
             callback(i);
 }
Ejemplo n.º 22
0
 protected void AOE(World world, float radius, short? objType, Action<Entity> callback) //Null for player
 {
     if (objType == null)
         foreach (var i in from i in world.PlayersCollision.HitTest(Host.Self.X, Host.Self.Y, radius)
             let d = Dist(i, Host.Self)
             where d < radius
             select i)
             callback(i);
     else
         foreach (var i in from i in world.EnemiesCollision.HitTest(Host.Self.X, Host.Self.Y, radius)
             where i.ObjectType == objType.Value
             let d = Dist(i, Host.Self)
             where d < radius
             select i)
             callback(i);
 }
Ejemplo n.º 23
0
 //Null for player
 public static void AOE(World world, Position pos, float radius, bool players, Action<Entity> callback)
 {
     if (players)
         foreach (var i in world.PlayersCollision.HitTest(pos.X, pos.Y, radius))
         {
             var d = Dist(i.X, i.Y, pos.X, pos.Y);
             if (d < radius)
                 callback(i);
         }
     else
         foreach (var i in world.EnemiesCollision.HitTest(pos.X, pos.Y, radius))
         {
             if (!(i is Enemy)) continue;
             var d = Dist(i.X, i.Y, pos.X, pos.Y);
             if (d < radius)
                 callback(i);
         }
 }
Ejemplo n.º 24
0
        public void OnEnemyKilled(Enemy enemy, Player killer)
        {
            if (enemy.ObjectDesc != null && enemy.ObjectDesc.Quest)
            {
                TauntData?dat = null;
                foreach (var i in criticalEnemies)
                {
                    if ((enemy.ObjectDesc.DisplayId ?? enemy.ObjectDesc.ObjectId) == i.Item1)
                    {
                        dat = i.Item2;
                        break;
                    }
                }
                if (dat == null)
                {
                    return;
                }

                if (dat.Value.killed != null)
                {
                    string[] arr = dat.Value.killed;
                    string   msg = arr[rand.Next(0, arr.Length)];
                    while (killer == null && msg.Contains("{PLAYER}"))
                    {
                        msg = arr[rand.Next(0, arr.Length)];
                    }
                    msg = msg.Replace("{PLAYER}", killer.Name);
                    BroadcastMsg(msg);
                }

                if (rand.NextDouble() < 0.25)
                {
                    Tuple <string, ISetPiece> evt = events[rand.Next(0, events.Count)];
                    if (
                        world.Manager.GameData.ObjectDescs[world.Manager.GameData.IdToObjectType[evt.Item1]].PerRealmMax ==
                        1)
                    {
                        events.Remove(evt);
                    }
                    SpawnEvent(evt.Item1, evt.Item2);

                    dat = null;
                    foreach (var i in criticalEnemies)
                    {
                        if (evt.Item1 == i.Item1)
                        {
                            dat = i.Item2;
                            break;
                        }
                    }
                    if (dat == null)
                    {
                        return;
                    }

                    if (dat.Value.spawn != null)
                    {
                        string[] arr = dat.Value.spawn;
                        string   msg = arr[rand.Next(0, arr.Length)];
                        BroadcastMsg(msg);
                    }
                }
                else
                {
                    bool enemyFound = false;
                    foreach (var i in world.Enemies)
                    {
                        if (i.Value == enemy)
                        {
                            continue;
                        }
                        ObjectDesc desc = i.Value.ObjectDesc;
                        if (desc == null)
                        {
                            continue;
                        }
                        bool isCritical = false;
                        foreach (var e in criticalEnemies)
                        {
                            if ((desc.DisplayId ?? desc.ObjectId) == e.Item1)
                            {
                                isCritical = true;
                                break;
                            }
                        }
                        if (!isCritical)
                        {
                            continue;
                        }
                        enemyFound = true;
                    }
                    if (!enemyFound)
                    {
                        BroadcastMsg("UHHH BUH BUH BUH UH BUH BUH BUH UH BUH BUH"); //omg trav dammit >.<
                        BroadcastMsg("I WILL SUFFER NO MORE OF YOUR IMPUDENCE!");
                        BroadcastMsg("I HAVE CLOSED THIS REALM! YOU WILL NOT LIVE TO SEE THE LIGHT OF DAY!");
                        this.closed = true;
                        world.Timers.Add(new WorldTimer(120000, (w, t) =>
                        {
                            BroadcastMsg("MY MINIONS HAVE FAILED ME!");
                            BroadcastMsg("BUT NOW YOU SHALL FEEL MY WRATH");
                            BroadcastMsg("COME MEET ME AT THE WALLS OF MY CASTLE");
                            w.BroadcastPacket(new ShowEffectPacket()
                            {
                                Color      = new ARGB(0xFF00FF00),
                                EffectType = EffectType.Earthquake,
                            }, null);
                            w.Timers.Add(new WorldTimer(15000, (s, g) =>
                            {
                                World chamber = s.Manager.AddWorld(new OryxChamber());
                                foreach (var i in s.Players)
                                {
                                    i.Value.Client.Reconnect(new ReconnectPacket()
                                    {
                                        Host   = "",
                                        Port   = 2050,
                                        GameId = chamber.Id,
                                        Name   = "Oryx's Chamber",
                                        Key    = Empty <byte> .Array
                                    });
                                }
                                var manager = world.Manager;
                                manager.RemoveWorld(world);
                                manager.AddWorld(world.Id, GameWorld.AutoName(1, true));
                            }));
                        }));
                        world.Manager.Monitor.WorldClosed(world);
                    }
                }
            }
        }
Ejemplo n.º 25
0
 public virtual void Init(World owner)
 {
     Owner = owner;
 }
 public void WorldRemoved(World world)
 {
     lock (worldLock)
     {
         if (portals.ContainsKey(world))
         {
             Portal portal = portals[world];
             nexus.LeaveWorld(portal);
             RealmManager.Realms.Add(portal.PortalName);
             RealmManager.CurrentRealmNames.Remove(portal.PortalName);
             portals.Remove(world);
             logger.InfoFormat("World {0}({1}) removed from monitor.", world.Id, world.Name);
         }
     }
 }
Ejemplo n.º 27
0
 protected void AOE(World world, float radius, short? objType, Action<Entity> callback) //Null for player
 {
     if (objType == null)
         foreach (var i in world.PlayersCollision.HitTest(Host.Self.X, Host.Self.Y, radius))
         {
             var d = Dist(i, Host.Self);
             if (d < radius)
                 callback(i);
         }
     else
         foreach (var i in world.EnemiesCollision.HitTest(Host.Self.X, Host.Self.Y, radius))
         {
             if (i.ObjectType != objType.Value) continue;
             var d = Dist(i, Host.Self);
             if (d < radius)
                 callback(i);
         }
 }
Ejemplo n.º 28
0
 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);
             }
         }
 }
Ejemplo n.º 29
0
 public static void CloseWorld(World world)
 {
     Monitor.WorldRemoved(world);
 }
Ejemplo n.º 30
0
 public static void AOE(World world, Entity self, float radius, bool players, Action<Entity> callback)
 //Null for player
 {
     if (players)
         foreach (var i in world.PlayersCollision.HitTest(self.X, self.Y, radius))
         {
             var d = Dist(i, self);
             if (d < radius)
                 callback(i);
         }
     else
         foreach (var i in world.EnemiesCollision.HitTest(self.X, self.Y, radius))
         {
             if (!(i is Enemy)) continue;
             var d = Dist(i, self);
             if (d < radius)
                 callback(i);
         }
 }
Ejemplo n.º 31
0
 public static void AOEPet(World world, Position pos, float radius, Action<Entity> callback) //Null for player
 {
     foreach (var i in world.EnemiesCollision.HitTest(pos.X, pos.Y, radius))
     {
         if (i.isPet) continue;
         if (!(i is Enemy)) continue;
         var d = Dist(i.X, i.Y, pos.X, pos.Y);
         if (d < radius)
             callback(i);
     }
 }
Ejemplo n.º 32
0
 public virtual void Init(World owner)
 {
     Owner = owner;
 }