public void SetUp()
        {
            SystemContainer = new SystemContainer();

            SystemContainer.PositionSystem = Substitute.For <IPositionSystem>();
            SystemContainer.EventSystem    = Substitute.For <IEventSystem>();
            SystemContainer.Random         = Substitute.For <IRandom>();

            entityEngine = Substitute.For <IEntityEngine>();
            entityEngine.New(Arg.Any <string>(), Arg.Any <IEntityComponent[]>()).ReturnsForAnyArgs(callInfo =>
            {
                var entity  = new Entity(0, "entity", callInfo.ArgAt <IEntityComponent[]>(1));
                entity.Name = callInfo.ArgAt <string>(0);
                return(entity);
            });

            entityEngine.Load(Arg.Any <uint>(), Arg.Any <Entity>()).ReturnsForAnyArgs(callInfo =>
            {
                var entity = callInfo.ArgAt <Entity>(1);

                return(entity);
            });
            entityEngine.ComponentTypes.ReturnsForAnyArgs(new[] { typeof(Appearance), typeof(Position), typeof(Stairs), typeof(AttackClosestEnemyBehaviour), typeof(Script) });

            SystemContainer.EntityEngine = entityEngine;
        }
Beispiel #2
0
        public void TestSystemsNotDuplicated()
        {
            ITestSystem1 system1 = Substitute.For <ITestSystem1>();
            ITestSystem2 system2 = Substitute.For <ITestSystem2>();
            ITestSystem3 system3 = Substitute.For <ITestSystem3>();
            ITestSystem4 system4 = Substitute.For <ITestSystem4>();

            system1.GetDependencies();
            system2.GetDependencies().Returns(new Type[] { typeof(ITestSystem1) });
            system3.GetDependencies().Returns(new Type[] { typeof(ITestSystem1), typeof(ITestSystem2) });
            system4.GetDependencies().Returns(new Type[] { typeof(ITestSystem2), typeof(ITestSystem3) });

            var context = new SystemContext();

            context.Register <ITestSystem1>(() => system1);
            context.Register <ITestSystem2>(() => system2);
            context.Register <ITestSystem3>(() => system3);
            context.Register <ITestSystem4>(() => system4);
            var container = new SystemContainer();

            container.SetContext(context);
            Assert.IsTrue(container.Init());

            system1.ReceivedWithAnyArgs(1).Init(null);
            system2.ReceivedWithAnyArgs(1).Init(null);
            system3.ReceivedWithAnyArgs(1).Init(null);
            system4.ReceivedWithAnyArgs(1).Init(null);
        }
Beispiel #3
0
        private void HandleTransitionOutFinished()
        {
            _currentTransitionController.TransitionOutFinished -= HandleTransitionOutFinished;

            if (_currentState != null)
            {
                _currentState.Exit();

                // TODO: This would be a good place for GC if that becomes
                // something we actually need to wory about.

                // Shutdown old systems
                _systems.Shutdown();
            }

            // Setup new systems
            _systems = new SystemContainer();
            SystemContext context = _nextState.GetSystemContext();

            context.RegisterWeak(FrameworkSystems);
            _systems.SetContext(context);
            if (!_systems.Init())
            {
                _logger.LogError("Failed to init game state systems");
                HandleFailedToTransition();
            }

            _currentState = _nextState;
            _nextState.ReadyToTransitionIn += HandleGameStateReady;
            _nextState.Enter(_systems);
        }
Beispiel #4
0
        public void Init(SystemContainer container)
        {
            _obj = new GameObject("UpdateManager");
            UpdateBehaviour behaviour = _obj.AddComponent <UpdateBehaviour>();

            behaviour.StartCoroutine(UpdateCoroutine());
        }
        public static PrivateAlliance Create(AllianceDescription description)
        {
            var systemStorage = SystemContainer.GetByName(k.es_private_alliance);
            var newAlliance   = Create(EntityDefault.GetByName(DefinitionNames.PRIVATE_ALLIANCE), systemStorage, description, EntityIDGenerator.Random);

            return((PrivateAlliance)newAlliance);
        }
        public void HandleRequest(IZoneRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var x = request.Data.GetOrDefault(k.x, (double)-1);
                var y = request.Data.GetOrDefault(k.y, (double)-1);

                var character = request.Session.Character;
                var player    = request.Zone.GetPlayerOrThrow(character);
                if (x < 0 || y < 0)
                {
                    x = player.CurrentPosition.intX + 0.5;
                    y = player.CurrentPosition.intY + 0.5;
                }

                //optionals
                var definition = request.Data.GetOrDefault <int>(k.definition);
                if (definition == 0)
                {
                    definition = request.Zone.Configuration.TeleportColumn.Definition;
                }

                var position = request.Zone.FixZ(new Position(x, y).Center);
                position.IsValid(request.Zone.Size).ThrowIfFalse(ErrorCodes.IllegalPosition);

                var eid         = (long)request.Data.GetOrDefault <int>(k.eid); //user comfort
                var idGenerator = eid == 0 ? EntityIDGenerator.Random : EntityIDGenerator.Fix(eid);

                var teleportColumn = (TeleportColumn)Entity.Factory.Create(definition, idGenerator);

                var container = SystemContainer.GetByName(k.es_teleport_column);
                teleportColumn.Parent = container.Eid;

                var name = request.Data.GetOrDefault <string>(k.name);
                if (name.IsNullOrEmpty())
                {
                    var tpAmountOnZone = request.Zone.Units.OfType <TeleportColumn>().Count();
                    name = "tp_zone_" + request.Zone.Id + "_" + (tpAmountOnZone + 1);
                }

                teleportColumn.Name = name;
                teleportColumn.Save();

                request.Zone.UnitService.AddDefaultUnit(teleportColumn, position, "tpc", false);
                teleportColumn.AddToZone(request.Zone, position);

                var result = request.Zone.GetBuildingsDictionaryForCharacter(character);

                Transaction.Current.OnCommited(() =>
                {
                    Logger.Info("");
                    Logger.Info("NEW TELEPORT COLUMN EID:" + teleportColumn.Eid);
                    Logger.Info("");
                    Message.Builder.SetCommand(Commands.ZoneGetBuildings).WithData(result).ToClient(request.Session).Send();
                });

                scope.Complete();
            }
        }
Beispiel #7
0
        public static IEntity DeserializeOutsideEngine(string input)
        {
            var fakeSystemContainer = new SystemContainer();

            fakeSystemContainer.CreateSystems("");

            return(Deserialize(fakeSystemContainer, input));
        }
        public void Execute()
        {
            var player = SystemContainer.GetSystem <Player.Player>();

            if (player.HasQuest(quest))
            {
                var playerQuest = player.data.quests.First(q => q.name == quest.name);
                playerQuest.SetStage(stage);
            }
        }
Beispiel #9
0
        public void Init(SystemContainer systems)
        {
            ILogger logger = systems.Get <ILoggerSystem>();

            if (logger == null)
            {
                logger = new NullLogger();
            }
            _logger = logger;
        }
Beispiel #10
0
 private void Awake()
 {
     lastLoadTime = Time.time;
     if (SceneManager.sceneCount == 1)
     {
         SceneManager.LoadSceneAsync("MainMenu", LoadSceneMode.Additive);
     }
     SystemContainer.Register(this);
     saveableObjects = new Dictionary <string, SaveableObject>();
 }
Beispiel #11
0
 public void Execute()
 {
     if (giveItem)
     {
         SystemContainer.GetSystem <Player.Player>().inventory.AddItem(item.id);
     }
     else if (giveMoney)
     {
         SystemContainer.GetSystem <Player.Player>().data.money += money;
     }
 }
        public void SetUp()
        {
            systemContainer = new SystemContainer();

            systemContainer.CreateSystems("seed");

            systemContainer.EntityEngine.Initialise(systemContainer);

            entity = GetTestEntity();

            statSystem = systemContainer.StatSystem;
        }
        public void SetUp()
        {
            systemContainer = new SystemContainer();

            systemContainer.CreateSystems("seed");

            positionSystem = systemContainer.PositionSystem;
            systemContainer.EntityEngine.Initialise(systemContainer);

            mover = GetTestEntity();
            map   = SetUpTestMap();
        }
Beispiel #14
0
        public void Initialise_InitialisesSystems()
        {
            var systemContainer = new SystemContainer(new EntityDataProviders {
                PrototypeEntityDataProvider = loader
            });
            var system = Substitute.For <ISystem>();

            engine.Register(system);

            engine.Initialise(systemContainer);

            system.Received(1).Initialise();
        }
        public void SetUp()
        {
            entityId = 0;

            systemContainer = new SystemContainer();

            systemContainer.CreateSystems("seed");
            systemContainer.EventSystem = Substitute.For <IEventSystem>();
            systemContainer.EventSystem.Try(Arg.Any <EventType>(), Arg.Any <IEntity>(), Arg.Any <object>()).ReturnsForAnyArgs(true);

            systemContainer.EntityEngine.Initialise(systemContainer);

            learner = GetTestEntity();
        }
Beispiel #16
0
        public Node GetNextNode()
        {
            var player = SystemContainer.GetSystem <Player.Player>();

            if (player.HasQuest(quest))
            {
                var playerQuest = player.data.quests.First(q => q.name == quest.name);
                return(GetOutputPort("stages " + playerQuest.progress.currentStage).Connection.node);
            }
            else
            {
                return(GetOutputPort("doesntHaveQuest").Connection.node);
            }
        }
Beispiel #17
0
        private void Start()
        {
            data.position = transform.position;
            data.rotation = transform.rotation;

            for (int i = 0; i < startingInventory.Length; i++)
            {
                inventory.AddItem(startingInventory[i]);
                inventory.items[i].Equipped = true;
            }
            equipment.CheckEquipment();

            player = SystemContainer.GetSystem <Player.Player>();
            base.Start();
        }
        protected static Alliance Create(EntityDefault entityDefault, SystemContainer container, AllianceDescription allianceDescription, EntityIDGenerator generator)
        {
            var alliance = Factory.Create(entityDefault, generator);

            alliance.Parent = container.Eid;
            Repository.Insert(alliance);

            Db.Query().CommandText("insert into alliances (allianceEID, name, nick, defaultAlliance) values (@eid, @name, @nick, @defaultAlliance)")
            .SetParameter("@eid", alliance.Eid)
            .SetParameter("@name", allianceDescription.name)
            .SetParameter("@nick", allianceDescription.nick)
            .SetParameter("@defaultAlliance", allianceDescription.isDefault)
            .ExecuteNonQuery().ThrowIfEqual(0, ErrorCodes.SQLInsertError);

            return((Alliance)alliance);
        }
Beispiel #19
0
        public void TestCircularDependency()
        {
            ITestSystem1 system1 = Substitute.For <ITestSystem1>();
            ITestSystem2 system2 = Substitute.For <ITestSystem2>();

            system1.GetDependencies().Returns(new Type[] { typeof(ITestSystem2) });
            system2.GetDependencies().Returns(new Type[] { typeof(ITestSystem1) });

            var context = new SystemContext();

            context.Register <ITestSystem1>(() => system1);
            context.Register <ITestSystem2>(() => system2);
            var container = new SystemContainer();

            container.SetContext(context);
            Assert.IsFalse(container.Init());
        }
Beispiel #20
0
        public void Initialise_LoadsStaticEntities()
        {
            var systemContainer = new SystemContainer(new EntityDataProviders {
                PrototypeEntityDataProvider = loader
            });

            systemContainer.EntityEngine = engine;
            IEntity loadedEntity = null;

            loader.GetData().Returns(new List <string> {
                @"""TestEntity"""
            });

            engine.Initialise(systemContainer);

            (loadedEntity as Entity)?.IsStatic.Should().BeTrue();
        }
Beispiel #21
0
        private void OnEnable()
        {
            if (firstRun)
            {
                firstRun = false;
                return;
            }

            var player = SystemContainer.GetSystem <Player.Player>();

            container                = player.inventory;
            container.onItemAdded   += ItemAdded;
            container.onItemRemoved += ItemRemoved;
            moneyAmount.text         = player.data.money.ToString("N0");


            AddButtons();
            AddAllItems();
        }
        protected static Corporation Create(EntityDefault entityDefault, SystemContainer container, CorporationDescription corporationDescription, EntityIDGenerator generator)
        {
            var corporation = Factory.Create(entityDefault, generator);

            corporation.Parent = container.Eid;
            corporation.Save();

            const string insertCommandText = @"insert into corporations (eid, name, nick, wallet, taxrate, publicProfile, privateProfile,defaultcorp, founder) 
                                                                 values (@eid, @name, @nick, @wallet, @taxrate, @publicProfile, @privateProfile,@defaultcorp,@founder)";

            Db.Query().CommandText(insertCommandText)
            .SetParameter("@eid", corporation.Eid)
            .SetParameter("@name", corporationDescription.name)
            .SetParameter("@nick", corporationDescription.nick)
            .SetParameter("@wallet", 0)
            .SetParameter("@taxrate", corporationDescription.taxRate)
            .SetParameter("@publicProfile", GenxyConverter.Serialize((Dictionary <string, object>)corporationDescription.publicProfile))
            .SetParameter("@privateProfile", GenxyConverter.Serialize((Dictionary <string, object>)corporationDescription.privateProfile))
            .SetParameter("@defaultCorp", corporationDescription.isDefault).SetParameter("@founder", corporationDescription.founder)
            .ExecuteNonQuery().ThrowIfEqual(0, ErrorCodes.SQLInsertError);

            return((Corporation)corporation);
        }
Beispiel #23
0
 public void Init(SystemContainer container)
 {
 }
 public void Visit(SystemContainer container)
 {
     _error = ErrorCodes.InsufficientPrivileges; //never ever
 }
Beispiel #25
0
 protected virtual void Start()
 {
     SystemContainer.GetSystem <SaveGameManager>().Register(this);
 }
Beispiel #26
0
 public void AddChildContainer(SystemContainer childCon)
 {
     m_childSystems.Add(childCon);
 }
Beispiel #27
0
        /// <summary>
        /// Layout systems
        /// </summary>
        /// <param name="systemList">systems, which will be layouted</param>
        /// <param name="nodeList">nodes</param>
        private void DoSystemLayout(List<EcellObject> systemList, List<EcellObject> nodeList)
        {
            if (systemList == null || nodeList == null)
                return;

            Dictionary<string, EcellObject> sysDict = new Dictionary<string, EcellObject>();
            foreach (EcellObject sys in systemList)
                sysDict.Add(sys.Key, sys);
            Dictionary<string, SystemContainer> containerDict = new Dictionary<string, SystemContainer>();
            SystemContainer rootContainer = null;
            foreach (EcellObject sys in systemList)
            {
                SystemContainer container = new SystemContainer();
                container.Self = sys;
                if (sys.Children.Count == 0)
                    continue;
                SystemContainer childDummyContainer = new SystemContainer();
                childDummyContainer.ChildNodeNum = sys.Children.Count;
                childDummyContainer.IsDummyContainer = true;
                container.AddChildContainer(childDummyContainer);

                if (sys.Key.Equals("/"))
                    rootContainer = container;
                containerDict.Add(sys.Key, container);
            }
            foreach (SystemContainer sysCon in containerDict.Values)
            {
                if (containerDict.ContainsKey(sysCon.Self.ParentSystemID))
                {
                    containerDict[sysCon.Self.ParentSystemID].AddChildContainer(sysCon);
                }
            }
            // Settle system coordinates
            rootContainer.ArrangeAllCoordinates(0, 0);
        }
        public static PrivateCorporation Create(CorporationDescription corporationDescription)
        {
            var container = SystemContainer.GetByName(k.es_private_corporation);

            return((PrivateCorporation)Create(EntityDefault.GetByName(DefinitionNames.PRIVATE_CORPORATION), container, corporationDescription, EntityIDGenerator.Random));
        }
Beispiel #29
0
 public void LoadMainMenu()
 {
     Time.timeScale = 1;
     SystemContainer.GetSystem <SaveGameManager>().LoadMainMenu();
 }
Beispiel #30
0
 public void Load()
 {
     Debug.Log("Loading saved game");
     Time.timeScale = 1;
     SystemContainer.GetSystem <SaveGameManager>().LoadSaveGame();
 }
Beispiel #31
0
 public void NewGame()
 {
     Debug.Log("Starting new game");
     Time.timeScale = 1;
     SystemContainer.GetSystem <SaveGameManager>().LoadGame();
 }
Beispiel #32
0
 public void Save()
 {
     SystemContainer.GetSystem <SaveGameManager>().Save();
 }