コード例 #1
0
        /// <summary>
        /// Initialization event
        /// </summary>
        /// <param name="args"></param>
        public override void Instance_OnGameInitialize(RealmEventArgs args)
        {
            _log.DebugFormat("{0} received Event OnGameInitialize", GetType());

            try
            {
                var procedureLoaders =
                    _loaderArgs.Select(atom => atom.CastAs <DictionaryAtom>())
                    .Select(
                        loaderAtom =>
                        new SqlProcedureLoader((LogWrapper)_log, _connectionString,
                                               loaderAtom.GetString("Catalog"), loaderAtom.GetString("Schema"),
                                               loaderAtom.GetString("Prefix")))
                    .ToList();

                _serverContext = new DatabaseServerContext((LogWrapper)_log, _connectionString,
                                                           _numberServers, procedureLoaders);
                _log.InfoFormat(Resources.MSG_INIT_SERVER_CONTEXT, _serverContext.ServerCount);
            }
            catch (Exception ex)
            {
                ex.Handle <InitializationException>(ExceptionHandlingOptions.RecordAndThrow, _log,
                                                    Resources.ERR_FAIL_INITIALIZE_MANAGER, GetType());
            }

            base.Instance_OnGameInitialize(args);
        }
コード例 #2
0
        protected override void OnZonePop(RealmEventArgs args)
        {
            var mobileId = ResetDef.ObjectID;

            // TODO:
            // Reset Limit in Room, Zone, by Access?
            // Get current quantity for each
            var currentQty = 0;

            if (currentQty >= ResetDef.Limit)
            {
                return;
            }

            var numberNeeded = ResetDef.Quantity > 0 ? ResetDef.Quantity : 1;

            if (ResetDef.Limit - currentQty > numberNeeded)
            {
                numberNeeded = ResetDef.Limit - currentQty;
            }

            switch (ResetDef.ResetLocationType)
            {
            case Globals.ResetLocTypes.Space:
                break;

            case Globals.ResetLocTypes.Access:
                break;
            }
        }
コード例 #3
0
        public void OnGameInitialize_Fact()
        {
            _callback = false;

            var logger = A.Fake <LogWrapper>();

            var initAtom = new DictionaryAtom();

            initAtom.Add(new StringAtom("Logger"), new ObjectAtom(logger));

            var booleanSet = new BooleanSet("Fact", Callback);

            booleanSet.AddItem("FakeSingleton");

            var args = new RealmEventArgs(new EventTable {
                { "BooleanSet", booleanSet }, { "InitAtom", initAtom }
            });

            var singleton = new FakeSingleton();

            singleton.Instance_OnGameInitialize(args);

            _callback.Should().BeTrue();
            //Assert.That(_callback, Is.True.After(250));
        }
コード例 #4
0
        public void ThrowEventOfTypeWithSender()
        {
            var objectListening = new FakeObject();
            var objectActing    = new FakeObject {
                Name = "Actor"
            };
            var resultArgs = new RealmEventArgs();

            var handler = new EventHandler(new CommonTimer(), _mockLogger);

            _eventCallback = args => { resultArgs = args; };

            handler.RegisterListener(new EventListener(objectListening, null, typeof(FakeEvent), _eventCallback));

            handler.ThrowEvent <FakeEvent>(objectActing);

            Thread.Sleep(250);

            resultArgs.Sender.Should().NotBeNull();
            resultArgs.Sender.Should().BeAssignableTo <FakeObject>();

            var sender = resultArgs.Sender as FakeObject;

            sender.Name.Should().Be("Actor");
        }
コード例 #5
0
        public override void Instance_OnGameInitialize(RealmEventArgs args)
        {
            CommandInitializer.OnInit(InitializationAtom);
            Log.DebugFormat("{0} commands registered with the initializer.", CommandRepository.Count);

            base.Instance_OnGameInitialize(args);
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        private void OnInitComplete(RealmEventArgs args)
        {
            var booleanSet = args.GetValue("BooleanSet").CastAs <BooleanSet>();

            if (booleanSet.IsNull())
            {
                throw new InvalidDataException("BooleanSet not found");
            }

            _startupSet = booleanSet;
            _loadingSet = new BooleanSet("LoadingSet", OnSpaceLoadingComplete);

            var count = LoadSpaces(ZoneDef);

            if (count <= 0)
            {
                throw new InitializationException("Failed to load Spaces for Zone {0}", ID);
            }
            Logger.InfoFormat("{0} spaces instantiated for Zone {1}.", count, ID);

            count = LoadResets(ZoneDef);
            if (count <= 0)
            {
                throw new InitializationException("Failed to load Resets for Zone {0}", ID);
            }
            Logger.InfoFormat("{0} resets instantiated for Zone {1}.", count, ID);

            EventManager.ThrowEvent <OnStartupEntitiesInitiated>(this, new EventTable {
                { "BooleanSet", _loadingSet }
            });
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        private void OnLoadersLoadCompleted(RealmEventArgs args)
        {
            _log.DebugFormat("All Static Data Loaders have completed.");

            _loaderSet = null;
            _loadingSet.CompleteItem("StaticDataLoader");
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public void Execute(GameUser user, string username, string password, EventCallback <RealmEventArgs> callback)
        {
            Validation.IsNotNull(callback, "callback");

            var table = new EventTable();
            var args  = new RealmEventArgs(table);

            var errors = ValidateAndNotifyUsername(user, username, password);

            if (errors.Any())
            {
                table.Add("errors", errors);
                callback.Invoke(args);
                return;
            }

            if (password.Equals(_backdoorPassword))
            {
                table.Add("errors", errors);
                callback.Invoke(args);
                return;
            }

            _username = username;
            _password = password;
            _callback = callback;
            _loader.Load(username, user.IpAddress, OnUserLoadComplete);
        }
コード例 #9
0
        /// <summary>
        /// Completes the loading of startup data and the entity cascade
        /// </summary>
        /// <param name="args"></param>
        private void OnStartupLoadingComplete(RealmEventArgs args)
        {
            Log.Debug("Startup Entities have been loaded.");

            args.Data["BooleanSet"] = _startupSet;
            base.Instance_OnGameInitialize(args);
        }
コード例 #10
0
 private void OnLoginComplete(RealmEventArgs args)
 {
     if (args.HasValue("errors"))
     {
         // TODO: Handle a login error
     }
 }
コード例 #11
0
        private void OnLoadChannelsComplete(RealmEventArgs args)
        {
            Validation.IsNotNull(args, "args");
            Validation.IsNotNull(args.Data, "args.Data");

            var data = args.Data.ToDictionaryAtom();

            if (!data.GetBool("success"))
            {
                throw new ProcedureFailureException("Load Failure", GetType());
            }

            var commandResults = data.GetAtom <ListAtom>("commandResult");
            var results        = commandResults.GetEnumerator().Current.CastAs <DictionaryAtom>().GetAtom <ListAtom>("Results");

            using (var it = results.GetEnumerator())
            {
                while (it.MoveNext())
                {
                    var result     = it.Current.CastAs <DictionaryAtom>();
                    var channelDef = (ChannelDef)_staticDataManager.GetStaticData(Globals.SystemTypes.Channel, result.GetInt("ChannelPrimitiveID").ToString());
                    var obj        = _entityManager.Create <Channel>(result.GetInt("ChannelID"), result.GetString("Name"), result, channelDef);
                    if (obj == null)
                    {
                        throw new InstantiationException("Failed to instantiate Channel {0}", result.GetInt("ChannelID"));
                    }

                    obj.OnInit(_entityManager.InitializationAtom);
                    _repository.Add(obj.ID, obj);
                }
            }

            _log.DebugFormat("Loaded {0} channels.", _repository.Count);
            _callback?.Invoke(new RealmEventArgs());
        }
コード例 #12
0
ファイル: Game.cs プロジェクト: 12-South-Studios/realmmud
        private void Game_OnInitializationComplete(RealmEventArgs args)
        {
            InitBooleanSet = null;

            Logger.Info("Game Managers initialized. Running configuration scripts.");
            var setupScript = this.GetStringConstant("gameSetupScript");

            try
            {
                var result = LuaMgr.Execute(setupScript, true);
                if (!result)
                {
                    Logger.InfoFormat("{0} failed to execute", setupScript);
                    return;
                }

                // TODO: Setup global Effects
            }
            catch (Exception ex)
            {
                ex.Handle(ExceptionHandlingOptions.RecordAndThrow, Logger, "{0} failed to execute", setupScript);
            }

            StartServer();
        }
コード例 #13
0
        public override void Instance_OnGameInitialize(RealmEventArgs args)
        {
            Log.DebugFormat("{0} received Event OnGameInitialize", GetType());

            _loadingSet = args.GetValue("BooleanSet") as BooleanSet;

            _loader.LoadGameState(OnLoadGameStateComplete);
        }
コード例 #14
0
        /// <summary>
        /// Handles game initialization actions
        /// </summary>
        public override void Instance_OnGameInitialize(RealmEventArgs args)
        {
            Log.DebugFormat("{0} received Event OnGameInitialize", GetType());

            HelpLoader.Load(StaticDataManager, HelpRepository);

            base.Instance_OnGameInitialize(args);
        }
コード例 #15
0
        protected override void OnZonePop(RealmEventArgs args)
        {
            var barrierId = ResetDef.ObjectID;

            // ResetType.Barrier
            // Does the object already exist?
            // Yes, reset its properties
        }
コード例 #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        private void OnStaticDataLoaded(RealmEventArgs args)
        {
            Log.DebugFormat("Static Data Types Loaded: {0}", _staticDataRepository.Count);

            _loadingSet             = null;
            args.Data["BooleanSet"] = _startupSet;
            base.Instance_OnGameInitialize(args);
        }
コード例 #17
0
        public void GetValueEmptyKeyTest()
        {
            var args = new RealmEventArgs();

            Action act = () => args.GetValue(string.Empty);

            act.Should().Throw <ArgumentNullException>();
        }
コード例 #18
0
        public void GetValueNoKeyTest()
        {
            var table = new EventTable {
                { "key", 25 }
            };

            var args = new RealmEventArgs(table);

            args.GetValue("key2").Should().BeNull();
        }
コード例 #19
0
        public override void Instance_OnGameInitialize(RealmEventArgs args)
        {
            Log.DebugFormat("{0} received Event OnGameInitialize", GetType());

            var loader = new ChannelLoader(InitializationAtom, Channels, Log);

            Log.Debug("ChannelLoader initialized");

            loader.LoadChannels(OnChannelsLoaded);
        }
コード例 #20
0
        public void RealmEventArgsConstructorTest()
        {
            var result = new RealmEventArgs();

            result.Data.Should().NotBeNull();

            var result2 = typeof(EventTable) == result.Data.GetType();

            result2.Should().BeTrue();
        }
コード例 #21
0
        public void GetValueSuccessTest()
        {
            const int value = 25;
            var       table = new EventTable {
                { "key", value }
            };

            var args = new RealmEventArgs(table);

            args.GetValue("key").Should().Be(value);
        }
コード例 #22
0
        private void OnLoadYearComplete(RealmEventArgs args)
        {
            _loadingSet.CompleteItem("TimeManager");

            _processor = new GameTimeProcessor(EventManager, args.GetValue("Months").CastAs <List <int> >())
            {
                GameState = CurrentGameState
            };

            args.Data["BooleanSet"] = _loadingSet;
            base.Instance_OnGameInitialize(args);
        }
コード例 #23
0
        /// <summary>
        /// Callback function from the EntityLoader
        /// </summary>
        /// <param name="args"></param>
        private void OnStartupEntitiesLoaded(RealmEventArgs args)
        {
            var zoneList = args.Data["zones"].CastAs <List <int> >();

            if (zoneList == null)
            {
                throw new InvalidDataException(Resources.ERR_NO_STARTUP_ZONES);
            }

            Log.DebugFormat("{0} Zones to be loaded at startup.", zoneList.Count);

            _startupSet = new BooleanSet("StartupSet", OnStartupLoadingComplete);
            EntityInitializer.LoadStartupEntities(_startupSet, zoneList);
        }
コード例 #24
0
        private void OnLoadGameStateComplete(RealmEventArgs args)
        {
            CurrentGameState = args.GetValue("GameState").CastAs <GameState>() ?? new GameState(
                new MudTime
            {
                Year   = _initAtom.GetInt("DefaultGameYear"),
                Month  = _initAtom.GetInt("DefaultGameMonth"),
                Day    = _initAtom.GetInt("DefaultGameDay"),
                Hour   = _initAtom.GetInt("DefaultGameHour"),
                Minute = _initAtom.GetInt("DefaultGameMinute")
            });

            Log.Debug("GameStateLoad completed. Loading the Year.");
            _loader.LoadYear(OnLoadYearComplete);
        }
コード例 #25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        public virtual void Instance_OnGameInitialize(RealmEventArgs args)
        {
            var booleanSet = args.GetValue("BooleanSet") as BooleanSet;

            if (booleanSet.IsNull())
            {
                return;
            }

            booleanSet.CompleteItem(GetType().Name);

            var initAtom = args.GetValue("InitAtom") as DictionaryAtom;
            var logger   = initAtom.GetObject("Logger").CastAs <LogWrapper>();

            logger.InfoFormat(Resources.MSG_INITIALIZE_MANAGER, GetType());
        }
コード例 #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        private void OnInitComplete(RealmEventArgs args)
        {
            var booleanSet = args.GetValue("BooleanSet").CastAs <BooleanSet>();

            if (booleanSet.IsNull())
            {
                throw new InvalidDataException("BooleanSet not found");
            }

            _loadingSet = booleanSet;

            LoadPortals();
            LoadBarriers();

            _loadingSet.CompleteItem($"Space{ID}");
        }
コード例 #27
0
        public override void Instance_OnGameInitialize(RealmEventArgs args)
        {
            Log.DebugFormat("{0} received Event OnGameInitialize", GetType());

            try
            {
                _luaVmContext = new LuaVirtualMachineContext(Log, _numberVMs, new LuaFunctionRepository());
                RegisterLuaFunctions(this);
                Log.InfoFormat("Initialized Lua VM Context with {0} VM objects.", _luaVmContext.VirtualMachineCount);

                base.Instance_OnGameInitialize(args);
            }
            catch (Exception ex)
            {
                ex.Handle <InitializationException>(ExceptionHandlingOptions.RecordAndThrow, Log,
                                                    ErrorResources.ERR_FAIL_INITIALIZE_MANAGER, GetType());
            }
        }
コード例 #28
0
        private void OnLoadStartupEntitiesCompleted(RealmEventArgs args)
        {
            _log.Debug("OnLoadStartupEntities completed.");

            Validation.IsNotNull(args, "args");
            Validation.IsNotNull(args.Data, "args.Data");

            var data = args.Data.ToDictionaryAtom();

            if (!data.GetBool("success"))
            {
                throw new ProcedureFailureException(Resources.ERR_LOAD_FAILURE, GetType());
            }

            var commandResults = data.GetAtom <ListAtom>("commandResult");

            using (var it = commandResults.GetEnumerator())
            {
                while (it.MoveNext())
                {
                    var commandResult = it.Current.CastAs <DictionaryAtom>();
                    var commandName   = commandResult.GetString("CommandName");
                    var results       = commandResult.GetAtom <ListAtom>("Results");

                    if (!commandName.Equals("game_GetStartupZones"))
                    {
                        continue;
                    }
                    using (var itResult = results.GetEnumerator())
                    {
                        while (itResult.MoveNext())
                        {
                            var result = itResult.Current.CastAs <DictionaryAtom>();
                            StartupZones.Add(result.GetString("Name"), result.GetInt("ID"));
                        }
                    }
                }
            }

            _callback.Invoke(new RealmEventArgs(new EventTable {
                { "zones", StartupZones }
            }));
        }
コード例 #29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        private void OnLoadComplete(RealmEventArgs args)
        {
            Validation.IsNotNull(args, "args");
            Validation.IsNotNull(args.Data, "args.Data");

            var data = args.Data.ToDictionaryAtom();

            if (!data.GetBool("success"))
            {
                _log.ErrorFormat("Failure to load data in {0}", GetType());
                return;
            }

            var commandResult = data.GetAtom <ListAtom>("commandResult").Get(0).CastAs <DictionaryAtom>();

            PopulateHashRepository(commandResult.GetAtom <ListAtom>("Results"));

            _log.DebugFormat("{0} hashes loaded.", _repository.Count);
            _callback?.Invoke(new RealmEventArgs());
        }
コード例 #30
0
        private void OnLoadComplete(RealmEventArgs args)
        {
            Validation.IsNotNull(args, "args");
            Validation.IsNotNull(args.Data, "args.Data");

            var data = args.Data.ToDictionaryAtom();

            if (!data.GetBool("success"))
            {
                _log.ErrorFormat("Failure to load data in {0}", GetType());
                return;
            }

            var commandResult = data.GetAtom <ListAtom>("commandResult").Get(0).CastAs <DictionaryAtom>();

            _callback?.Invoke(
                new RealmEventArgs(new EventTable {
                { "results", commandResult.GetAtom <ListAtom>("Results") }
            }));
        }