Example #1
0
        public override void Tick(RealmTime time)
        {
            base.Tick(time);

            if (Players.Count > 0)
            {
                if (Enemies.Count < 1)
                {
                    if (!Waiting)
                    {
                        Wave++;
                        Waiting = true;
                        Timers.Add(new WorldTimer(1500, (w, t) =>
                        {
                            foreach (var i in Players)
                            {
                                i.Value.Client.SendPacket(new NotificationPacket
                                {
                                    Color    = new ARGB(0xffff00ff),
                                    ObjectId = i.Value.Id,
                                    Text     = "Wave " + Wave.ToString(CultureInfo.InvariantCulture) + " Starting in 5..."
                                });
                            }
                            Timers.Add(new WorldTimer(1000, (w1, t1) =>
                            {
                                foreach (var i in Players)
                                {
                                    i.Value.Client.SendPacket(new NotificationPacket
                                    {
                                        Color    = new ARGB(0xffff00ff),
                                        ObjectId = i.Value.Id,
                                        Text     = "Wave " + Wave.ToString(CultureInfo.InvariantCulture) + " Starting in 4..."
                                    });
                                }
                                Timers.Add(new WorldTimer(1000, (w2, t2) =>
                                {
                                    foreach (var i in Players)
                                    {
                                        i.Value.Client.SendPacket(new NotificationPacket
                                        {
                                            Color    = new ARGB(0xffff00ff),
                                            ObjectId = i.Value.Id,
                                            Text     = "Wave " + Wave.ToString(CultureInfo.InvariantCulture) + " Starting in 3..."
                                        });
                                    }
                                    Timers.Add(new WorldTimer(1000, (w3, t3) =>
                                    {
                                        foreach (var i in Players)
                                        {
                                            i.Value.Client.SendPacket(new NotificationPacket
                                            {
                                                Color    = new ARGB(0xffff00ff),
                                                ObjectId = i.Value.Id,
                                                Text     = "Wave " + Wave.ToString(CultureInfo.InvariantCulture) + " Starting in 2..."
                                            });
                                        }
                                        Timers.Add(new WorldTimer(1000, (w4, t4) =>
                                        {
                                            foreach (var i in Players)
                                            {
                                                i.Value.Client.SendPacket(new NotificationPacket
                                                {
                                                    Color    = new ARGB(0xffff00ff),
                                                    ObjectId = i.Value.Id,
                                                    Text     = "Wave " + Wave.ToString(CultureInfo.InvariantCulture) + " Starting..."
                                                });
                                            }
                                            Timers.Add(new WorldTimer(500, (w5, t5) =>
                                            {
                                                SpawnEnemies();
                                                Waiting = false;
                                            }));
                                        }));
                                    }));
                                }));
                            }));
                        }));
                    }
                }
                else
                {
                    foreach (var i in Enemies)
                    {
                        if (OutOfBounds(i.Value.X, i.Value.Y))
                        {
                            LeaveWorld(i.Value);
                        }
                    }
                }
            }
            else
            {
                foreach (var i in Enemies)
                {
                    LeaveWorld(i.Value);
                    Wave = 0;
                }
            }
        }
Example #2
0
        public void CloseBridge1()
        {
            WmapTile tile;

            foreach (var p in Players)
            {
                for (int i = 138; i < 152; i++)
                {
                    tile        = p.Value.Owner.Map[i, 163].Clone();
                    tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                    p.Value.Owner.Map[i, 163] = tile;

                    tile        = p.Value.Owner.Map[i, 164].Clone();
                    tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                    p.Value.Owner.Map[i, 164] = tile;

                    tile        = p.Value.Owner.Map[i, 165].Clone();
                    tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                    p.Value.Owner.Map[i, 165] = tile;

                    tile        = p.Value.Owner.Map[i, 177].Clone();
                    tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                    p.Value.Owner.Map[i, 177] = tile;

                    tile        = p.Value.Owner.Map[i, 178].Clone();
                    tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                    p.Value.Owner.Map[i, 178] = tile;

                    tile        = p.Value.Owner.Map[i, 179].Clone();
                    tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                    p.Value.Owner.Map[i, 179] = tile;
                }
            }

            Timers.Add(new WorldTimer(10000, (w, t) =>
            {
                foreach (var p in Players)
                {
                    for (int i = 138; i < 152; i++)
                    {
                        tile        = p.Value.Owner.Map[i, 166].Clone();
                        tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                        p.Value.Owner.Map[i, 166] = tile;

                        tile        = p.Value.Owner.Map[i, 167].Clone();
                        tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                        p.Value.Owner.Map[i, 167] = tile;

                        tile        = p.Value.Owner.Map[i, 175].Clone();
                        tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                        p.Value.Owner.Map[i, 175] = tile;

                        tile        = p.Value.Owner.Map[i, 176].Clone();
                        tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                        p.Value.Owner.Map[i, 176] = tile;
                    }
                }

                Timers.Add(new WorldTimer(10000, (w1, t1) =>
                {
                    foreach (var p in Players)
                    {
                        for (int i = 138; i < 152; i++)
                        {
                            tile        = p.Value.Owner.Map[i, 168].Clone();
                            tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                            p.Value.Owner.Map[i, 168] = tile;

                            tile        = p.Value.Owner.Map[i, 169].Clone();
                            tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                            p.Value.Owner.Map[i, 169] = tile;

                            tile        = p.Value.Owner.Map[i, 173].Clone();
                            tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                            p.Value.Owner.Map[i, 173] = tile;

                            tile        = p.Value.Owner.Map[i, 174].Clone();
                            tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                            p.Value.Owner.Map[i, 174] = tile;
                        }
                    }

                    Timers.Add(new WorldTimer(10000, (w2, t2) =>
                    {
                        foreach (var p in Players)
                        {
                            for (int i = 138; i < 152; i++)
                            {
                                tile        = p.Value.Owner.Map[i, 170].Clone();
                                tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                                p.Value.Owner.Map[i, 170] = tile;

                                tile        = p.Value.Owner.Map[i, 172].Clone();
                                tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                                p.Value.Owner.Map[i, 172] = tile;
                            }
                        }

                        Timers.Add(new WorldTimer(5000, (w3, t3) =>
                        {
                            foreach (var p in Players)
                            {
                                for (int i = 138; i < 152; i++)
                                {
                                    tile        = p.Value.Owner.Map[i, 171].Clone();
                                    tile.TileId = Manager.GameData.IdToTileType["shtrs Pure Evil"];
                                    p.Value.Owner.Map[i, 171] = tile;
                                }
                            }
                        }));
                    }));
                }));
            }));
        }
Example #3
0
        public static void Read(Packets Packet, NetIncomingMessage I)
        {
            switch (Packet)
            {
            case Packets.Connection:
                if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
                {
                    var ClientVersion = I.ReadUInt64();
                    if (ClientVersion == Globe.Version)
                    {
                        var Connector = Player.Add(new Player(I.ReadString())
                        {
                            Connection = I.SenderConnection
                        });
                        if (Connector != null)
                        {
                            if ((GameType == GameTypes.TeamDeathmatch) || (GameType == GameTypes.TeamStandard))
                            {
                                Connector.Team = (byte)((TeamCount(1) > TeamCount(2)) ? 2 : ((TeamCount(2) > TeamCount(1)) ? 1 : Globe.Random(1, 2)));
                            }
                            MultiPlayer.Send("Game", MultiPlayer.Construct("Game", Packet, Connector.Slot, Connector.Name, Connector.Team), I.SenderConnection);
                            var Details = new List <object>();
                            Details.Add((byte)GameType); Details.Add(RespawnTimer);
                            Details.Add(Connector.Team);
                            for (byte i = 0; i < Players.Length; i++)
                            {
                                if ((Players[i] != null) && (Players[i] != Connector))
                                {
                                    Details.Add(true);
                                    Details.Add(Players[i].Name);
                                    Details.Add(Players[i].Team);
                                }
                                else
                                {
                                    Details.Add(false);
                                }
                            }
                            I.SenderConnection.Approve(MultiPlayer.Construct("Game", Packets.Initial, (byte)Players.Length, Connector.Slot, Details));
                        }
                        else
                        {
                            I.SenderConnection.Deny("Full");
                        }
                    }
                    else
                    {
                        I.SenderConnection.Deny("Version indifference, Client: " + ClientVersion + " - Server: " + Globe.Version);
                    }
                }
                else if (MultiPlayer.Type("Game") == MultiPlayer.Types.Client)
                {
                    var Slot = I.ReadByte();
                    Player.Set(Slot, new Player(I.ReadString())
                    {
                        Team = I.ReadByte()
                    });
                }
                break;

            case Packets.Disconnection:
                var Disconnector = ((MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
                        ? Player.Get(I.SenderConnection)
                        : ((MultiPlayer.Type("Game") == MultiPlayer.Types.Client) ? Players[I.ReadByte()] : null));
                if (Disconnector != null)
                {
                    Player.Remove(Disconnector);
                }
                if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
                {
                    MultiPlayer.Send("Game", MultiPlayer.Construct("Game", Packets.Disconnection, Disconnector.Slot),
                                     I.SenderConnection);
                }
                break;

            case Packets.Initial:
                if (MultiPlayer.Type("Game") == MultiPlayer.Types.Client)
                {
                    Players   = new Player[I.ReadByte()];
                    Self      = Player.Set(I.ReadByte(), new Player(MpName));
                    GameType  = (GameTypes)I.ReadByte(); RespawnTimer = I.ReadDouble();
                    Self.Team = I.ReadByte();
                    for (byte i = 0; i < Players.Length; i++)
                    {
                        if (I.ReadBoolean())
                        {
                            Players[i] = new Player(i, I.ReadString())
                            {
                                Team = I.ReadByte()
                            };
                        }
                    }
                    State = States.RequestMap;
                    Timers.Add("Positions", (1 / 30d));
                }
                break;

            case Packets.RequestMap:
                if (MultiPlayer.Type() == MultiPlayer.Types.Server)
                {
                    List <object> Details = new List <object>();
                    Details.AddRange(GetSyncedMap);
                    Details.Add((byte)State);
                    MultiPlayer.SendTo(MultiPlayer.Construct(Packet, Details), I.SenderConnection);
                }
                else if (MultiPlayer.Type() == MultiPlayer.Types.Client)
                {
                    Map = ReadSyncedMap(I); State = (States)I.ReadByte();
                }
                break;

            case Packets.Position:
                var Sender = ((MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
                        ? Player.Get(I.SenderConnection)
                        : null);
                Vector2 Position;
                float   Angle;
                if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
                {
                    if (Sender != null)
                    {
                        Sender.Position = I.ReadVector2();
                        Sender.Angle    = I.ReadFloat();
                    }
                }
                else if (MultiPlayer.Type("Game") == MultiPlayer.Types.Client)
                {
                    var Count = (byte)((I.LengthBytes - 1) / 12);
                    for (byte i = 0; i < Count; i++)
                    {
                        Sender   = Players[I.ReadByte()];
                        Position = I.ReadVector2();
                        Angle    = I.ReadFloat();
                        if (Sender != null)
                        {
                            Sender.Position = Position;
                            Sender.Angle    = Angle;
                        }
                    }
                }
                break;

            case Packets.PlaceFore:
                byte ID = I.ReadByte(); ushort x = I.ReadUInt16(), y = I.ReadUInt16(); byte TAngle = I.ReadByte();
                Map.PlaceFore(ID, x, y, TAngle);
                if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
                {
                    MultiPlayer.Send(MultiPlayer.Construct(Packet, ID, x, y, TAngle), I.SenderConnection);
                }
                break;

            case Packets.ClearFore:
                x = I.ReadUInt16(); y = I.ReadUInt16();
                Map.ClearFore(x, y);
                if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
                {
                    MultiPlayer.Send(MultiPlayer.Construct(Packet, x, y), I.SenderConnection);
                }
                break;

            case Packets.PlaceBack:
                ID = I.ReadByte(); x = I.ReadUInt16(); y = I.ReadUInt16();
                Map.PlaceBack(ID, x, y);
                if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
                {
                    MultiPlayer.Send(MultiPlayer.Construct(Packet, ID, x, y), I.SenderConnection);
                }
                break;

            case Packets.ClearBack:
                x = I.ReadUInt16(); y = I.ReadUInt16();
                Map.ClearBack(x, y);
                if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
                {
                    MultiPlayer.Send(MultiPlayer.Construct(Packet, x, y), I.SenderConnection);
                }
                break;

            case Packets.Fire:
                Sender   = ((MultiPlayer.Type("Game") == MultiPlayer.Types.Server) ? Player.Get(I.SenderConnection) : Players[I.ReadByte()]);
                Position = I.ReadVector2(); Angle = I.ReadFloat();
                Sender.Fire(Position, Angle);
                if (MultiPlayer.Type() == MultiPlayer.Types.Server)
                {
                    MultiPlayer.Send(MultiPlayer.Construct(Packet, Sender.Slot, Position, Angle), I.SenderConnection);
                }
                break;

            case Packets.Death:
                Sender        = ((MultiPlayer.Type("Game") == MultiPlayer.Types.Server) ? Player.Get(I.SenderConnection) : Players[I.ReadByte()]);
                Sender.Killer = Players[I.ReadByte()];
                Sender.Die();
                if (MultiPlayer.Type() == MultiPlayer.Types.Server)
                {
                    MultiPlayer.Send(MultiPlayer.Construct(Packet, Sender.Slot, Sender.Killer.Slot), I.SenderConnection);
                }
                break;

            case Packets.Respawn:
                Sender   = ((MultiPlayer.Type("Game") == MultiPlayer.Types.Server) ? Player.Get(I.SenderConnection) : Players[I.ReadByte()]);
                Position = I.ReadVector2();
                Sender.Respawn(Position);
                if (MultiPlayer.Type() == MultiPlayer.Types.Server)
                {
                    MultiPlayer.Send(MultiPlayer.Construct(Packet, Sender.Slot, Position), I.SenderConnection);
                }
                break;

            case Packets.EndRound:
                VictoryStates VictoryState = (VictoryStates)I.ReadByte();
                byte          TeamWon = ((VictoryState == VictoryStates.Team) ? I.ReadByte() : (byte)0);
                byte          RoundEndMusicIndex = I.ReadByte();
                EndRound(VictoryState, TeamWon, RoundEndMusicIndex);
                break;

            case Packets.NewRound: NewRound(); break;
            }
        }
        public void MessageGenerator(Message message, int dueTime, int period)
        {
            TimerCallback tm = Mobile.InternalStorage.AddMessage;

            Timers.Add(new Timer(tm, message, dueTime, period));
        }
Example #5
0
        public override void Tick(RealmTime time)
        {
            base.Tick(time);
            if (Players.Count > 0)
            {
                if (!Flags["started"] && !Flags["counting"])
                {
                    foreach (var i in RealmManager.Clients.Values)
                    {
                        i.SendPacket(new TextPacket
                        {
                            Stars      = -1,
                            BubbleTime = 0,
                            Name       = "#Announcement",
                            Text       = "A paid arena game has been started. Closing in 1 minute!"
                        });
                    }
                    Flags["counting"] = true;
                    Countdown(60);
                }


                else if (Flags["started"] && !Flags["counting"])
                {
                    if (Enemies.Count < 1 + Pets.Count)
                    {
                        Wave++;
                        if (Wave < 6)
                        {
                            RandomBosses = new[] { "Red Demon", "Phoenix Lord", "Henchman of Oryx" };
                        }
                        if (Wave > 5 && Wave < 11)
                        {
                            RandomBosses = new[]
                            { "Red Demon", "Phoenix Lord", "Henchman of Oryx", "Stheno the Snake Queen" };
                        }
                        if (Wave > 10 && Wave < 16)
                        {
                            RandomBosses = new[]
                            { "Elder Tree", "Stheno the Snake Queen", "Archdemon Malphas", "Septavius the Ghost God" };
                        }
                        if (Wave > 15 && Wave < 21)
                        {
                            RandomBosses = new[]
                            {
                                "Elder Tree", "Archdemon Malphas", "Septavius the Ghost God",
                                "Thessal the Mermaid Goddess",
                                "Crystal Prisoner"
                            };
                        }
                        if (Wave > 20 && Wave < 36)
                        {
                            RandomBosses = new[]
                            {
                                "Thessal the Mermaid Goddess", "Crystal Prisoner", "Tomb Support", "Tomb Defender",
                                "Tomb Attacker", "Oryx the Mad God 2"
                            };
                        }
                        if (Wave > 35)
                        {
                            RandomBosses = new[]
                            {
                                "Thessal the Mermaid Goddess", "Crystal Prisoner", "Tomb Support", "Tomb Defender",
                                "Tomb Attacker", "Oryx the Mad God 2", "Phoenix Wright", "Bridge Sentinel"
                            };
                        }
                        var db = new Database();
                        //FamePot = (Wave/2)*10/(Players.Count == 1 ? 1 : 2);
                        if (Players.Count == 1)
                        {
                            FamePot = (Wave / 2) * 10;
                        }
                        else if (Wave % 2 == 1)
                        {
                            FamePot = ((Wave + 1) / 4) * 10;
                        }
                        else
                        {
                            FamePot = (Wave / 4) * 10;
                        }
                        foreach (var i in Players)
                        {
                            i.Value.CurrentFame =
                                i.Value.Client.Account.Stats.Fame = db.UpdateFame(i.Value.Client.Account, FamePot);
                            i.Value.UpdateCount++;
                            i.Value.Client.SendPacket(new NotificationPacket
                            {
                                Color    = new ARGB(0xFFFF6600),
                                ObjectId = i.Value.Id,
                                Text     = "+" + FamePot + " Fame"
                            });
                            if (Math.IEEERemainder(Wave, 15) == 0)
                            {
                                i.Value.Credits = i.Value.Client.Account.Credits = db.UpdateCredit(i.Value.Client.Account, 1);
                                i.Value.UpdateCount++;
                            }
                        }
                        db.Dispose();
                        var Invincible = new ConditionEffect();
                        Invincible.Effect     = ConditionEffectIndex.Invulnerable;
                        Invincible.DurationMS = 6000;
                        var Healing = new ConditionEffect();
                        Healing.Effect     = ConditionEffectIndex.Healing;
                        Healing.DurationMS = 6000;
                        foreach (var i in Players)
                        {
                            i.Value.Client.SendPacket(new SwitchMusicPacket()
                            {
                                Music = "Arena"
                            });
                            i.Value.ApplyConditionEffect(new[]
                            {
                                Invincible,
                                Healing
                            });
                        }
                        foreach (var i in Players)
                        {
                            try
                            {
                                if (!Participants.Contains(i.Value.Client.Account.Name))
                                {
                                    Participants.Add(i.Value.Client.Account.Name);
                                }
                            }
                            catch
                            {
                            }
                        }
                        Flags["counting"] = true;
                        Timers.Add(new WorldTimer(1000, (world, t) => Countdown(5)));
                    }
                    else
                    {
                        foreach (var i in Enemies)
                        {
                            if (OutOfBounds(i.Value.X, i.Value.Y))
                            {
                                LeaveWorld(i.Value);
                            }
                        }
                    }
                }
            }
            else
            {
                if (Participants.Count > 0)
                {
                    new Database().AddToArenaLb(Wave, Participants);
                    Participants.Clear();
                }
            }
        }
Example #6
0
        public async Task StartCharging()
        {
            if (this is Player)
            {
                var request = new
                {
                    Category = "Events",
                    Type     = "StartCharging",
                    Result   = "ok"
                };
                await(this as Player).GetSocketHandler().SendString(JSON.Encode(request));
            }
            IsCharging = true;
            if (Timers.ContainsKey("ChargeTimer"))
            {
                Timers["ChargeTimer"].Close();
                Timers["ChargeTimer"].Dispose();
                Timers.Remove("ChargeTimer");
            }
            var timer      = new System.Timers.Timer(100);
            var startTime  = DateTime.Now;
            var startValue = CurrentCharge;

            timer.Elapsed += (sen, arg) => {
                if (IsCharging == false)
                {
                    (sen as System.Timers.Timer).Stop();
                    (sen as System.Timers.Timer).Dispose();
                    Timers.Remove("ChargeTimer");
                    return;
                }

                if (this is Player)
                {
                    var handler = (this as Player).GetSocketHandler();
                    if (handler == null)
                    {
                        (sen as System.Timers.Timer).Stop();
                        (sen as System.Timers.Timer).Dispose();
                        Timers.Remove("ChargeTimer");
                        return;
                    }
                    CurrentCharge = Math.Min(MaxCharge, Math.Round(startValue + (DateTime.Now - startTime).TotalMilliseconds / 100 * .01 * MaxCharge));
                    dynamic update = new
                    {
                        Category = "Queries",
                        Type     = "StatUpdate",
                        Stat     = "CurrentCharge",
                        Amount   = CurrentCharge
                    };
                    handler.SendString(JSON.Encode(update));
                }
                foreach (var player in Storage.Current.Locations.Find(CurrentXYZ).GetNearbyPlayers().Where(p => p?.Player?.Name != Name))
                {
                    dynamic request = new
                    {
                        Category = "Events",
                        Type     = "CharacterCharging",
                        Location = CurrentXYZ
                    };
                    player.SendString(JSON.Encode(request));
                }
            };
            Timers.Add("ChargeTimer", timer);
            timer.Start();
        }
        /// <summary>
        /// Инициализация после получения всех данных и уже запущенной игре
        /// </summary>
        public static void InitGame()
        {
            try
            {
                Loger.Log("Client InitGame()");
                //Data.ChatsTime = (DateTime.UtcNow + ServerTimeDelta).AddDays(-1); //без этого указания будут получены все сообщения с каналов

                MainButtonWorker_OC.ShowOnStart();
                UpdateWorldController.ClearWorld();
                UpdateWorldController.InitGame();
                Data.UpdateTime = DateTime.MinValue;
                UpdateWorld(true);

                Data.LastServerConnect = DateTime.MinValue;

                Timers.Add(100, UpdateFastTimer);
                Timers.Add(500, UpdateChats);
                Timers.Add(5000, () => UpdateWorld(false));
                Timers.Add(10000, PingServer);
                Timers.Add(60000 * Data.DelaySaveGame, BackgroundSaveGame);
                TimerReconnect.Add(1000, CheckReconnectTimer);

                //устанавливаем событие на выход из игры
                GameExit.BeforeExit = () =>
                {
                    try
                    {
                        Loger.Log("Client BeforeExit ");
                        GameExit.BeforeExit = null;
                        TimersStop();
                        if (Current.Game == null)
                        {
                            return;
                        }

                        if (!Data.BackgroundSaveGameOff)
                        {
                            Loger.Log($"Client {SessionClientController.My.Login} SaveGameBeforeExit " + SaveFullName);
                            GameDataSaveLoader.SaveGame(SaveName);
                            var content = File.ReadAllBytes(SaveFullName);
                            if (content.Length > 1024)
                            {
                                Data.SaveFileData = content;
                                Data.SingleSave   = false;
                                UpdateWorld(false);

                                Loger.Log($"Client {SessionClientController.My.Login} SaveGameBeforeExit OK");
                            }
                        }
                        SessionClient.Get.Disconnect();
                    }
                    catch (Exception e)
                    {
                        Loger.Log("Client BeforeExit Exception: " + e.ToString());
                        throw;
                    }
                };
            }
            catch (Exception e)
            {
                ExceptionUtil.ExceptionLog(e, "Client InitGame Error");
                GameExit.BeforeExit = null;
                TimersStop();
                if (Current.Game == null)
                {
                    return;
                }
                SessionClient.Get.Disconnect();
            }
        }
Example #8
0
        public virtual void Tick(RealmTime time)
        {
            if (IsLimbo)
            {
                return;
            }

            if (disposable)
            {
                if (Players.Count <= 0 && !isDisposing)
                {
                    isDisposing = true;
                    if (RemovalMS < 25000)
                    {
                        //    log.WarnFormat("World \"{0}\" does not have a valid RemovalMS: {1}! Please allow at least 25 seconds. Default: 25000 ms", Name, RemovalMS);
                        RemovalMS = 25000;
                    }
                    //  log.InfoFormat("World {0}, ID:{1} is unused and will dispose in {2}MS.", Name, Id, RemovalMS);
                    WorldTimer timer = new WorldTimer(RemovalMS, (w, t) =>
                    {
                        manager.RemoveWorld(w);
                    });
                    Timers.Add(timer);
                }
                else if (isDisposing && Players.Count >= 1)
                {
                    isDisposing = false;
                    //      log.InfoFormat("World {0}, ID:{1} is in use and has cancelled disposal.", Name, Id);
                }
            }

            if (Timers != null && Timers.Count > 0)
            {
                for (int i = 0; i < Timers.Count; i++)
                {
                    if (Timers[i].Tick(this, time) && Timers.Count > 0)
                    {
                        Timers.RemoveAt(i);
                        i--;
                    }
                }
            }

            try //entity ticking now, possible huge range of issues that i can't yet remove the try catch - jade
            {
                foreach (var i in Players)
                {
                    i.Value.Tick(time);
                }

                if (isDisposing)
                {
                    return;
                }

                if (EnemiesCollision != null)
                {
                    foreach (Entity i in EnemiesCollision.GetActiveChunks(PlayersCollision))
                    {
                        i.Tick(time);
                    }
                    foreach (var i in StaticObjects.Where(x => x.Value is Decoy))
                    {
                        i.Value.Tick(time);
                    }
                }
                else
                {
                    foreach (var i in Enemies)
                    {
                        i.Value.Tick(time);
                    }
                    foreach (var i in StaticObjects)
                    {
                        i.Value.Tick(time);
                    }
                }
                foreach (var i in Projectiles)
                {
                    i.Value.Tick(time);
                }
            }
            catch (Exception e)
            {
                log.Error(e);
            }
        }
Example #9
0
 private void AddTimer()
 {
     Timers.Add(new TimerModel(TimeSpan.FromSeconds((new Random()).Next())));
 }