예제 #1
0
        public void Initialize(StateInitDesc initDesc)
        {
            Kernel          = initDesc.Kernel;
            _dataContent    = initDesc.DataContent;
            _archiveManager = initDesc.ArchiveManager;
            _graphics       = initDesc.GraphicsDevice;
            _input          = initDesc.InputManager;
            _stateChange    = initDesc.StateChange;
            _shader         = new KingdomShader(initDesc.ContentManager);
            _camera         = new Camera()
            {
                CameraPosition             = new Vector3(0, 100, 200),
                CameraRotationYawPitchRoll = new Vector3(90, 0, 10),
            };
            _menuState      = new MenuState(this);
            _worldId        = initDesc.StateSettings.GetInt("WorldId", 2);
            _placeId        = initDesc.StateSettings.GetInt("PlaceId", 4);
            _spawnId        = initDesc.StateSettings.GetInt("SpawnId", 99);
            _spawnScriptMap = initDesc.StateSettings.GetInt("SpawnScriptMap", 0x06);
            _spawnScriptBtl = initDesc.StateSettings.GetInt("SpawnScriptBtl", 0x01);
            _spawnScriptEvt = initDesc.StateSettings.GetInt("SpawnScriptEvt", 0x16);

            BasicallyForceToReloadEverything();
            _menuState.Initialize(initDesc);
        }
예제 #2
0
파일: MapState.cs 프로젝트: shinerkz/OpenKh
        public void Initialize(StateInitDesc initDesc)
        {
            Kernel          = initDesc.Kernel;
            _dataContent    = initDesc.DataContent;
            _archiveManager = initDesc.ArchiveManager;
            _graphics       = initDesc.GraphicsDevice;
            _input          = initDesc.InputManager;
            _stateChange    = initDesc.StateChange;
            _shader         = new KingdomShader(initDesc.ContentManager);
            _camera         = new Camera()
            {
                CameraPosition             = new Vector3(0, 100, 200),
                CameraRotationYawPitchRoll = new Vector3(90, 0, 10),
            };
            _menuState = new MenuState(this);

            Kernel.World    = initDesc.StateSettings.GetInt("WorldId", Kernel.World);
            Kernel.Area     = initDesc.StateSettings.GetInt("PlaceId", Kernel.Area);
            Kernel.Entrance = initDesc.StateSettings.GetInt("SpawnId", Kernel.Entrance);
            Field           = new Kh2Field(
                Kernel,
                _camera,
                initDesc.StateSettings,
                _graphics.GraphicsDevice,
                _shader,
                _input);

            BasicallyForceToReloadEverything();
            _menuState.Initialize(initDesc);
        }
예제 #3
0
 public PlayerChoiceOpportunity SetOutcome(string GestureClassName, IStateChange Outcome)
 {
     if (!Classifier.Dataset.ClassNames.Contains(GestureClassName))
     {
         throw new Exception($"Cannot find gesture class {GestureClassName} in classifier's list (which is {Classifier.Dataset.ClassNames.Join()})");
     }
     OutcomeOptions.Add(GestureClassName, Outcome);
     return(this);
 }
예제 #4
0
 private void CheckCorrectOverloadForViewModel <T, C>(IStateChange <T, C> change)
     where T : class, IStateChangeEntityBase <C>
     where C : Enum
 {
     if (change.GetType().BaseType.GenericTypeArguments.Length == 3)
     {
         throw new Exception($"Wront overload method! Change has a third ViewModel generic type! Use the other overload method of {nameof(BasicWorkFlowManage)} " +
                             $"or remove the view model from the generic type arguments of change basetype");
     }
 }
예제 #5
0
        public void ManageTransition <T, C, L>(IStateChange <T, C, L> change, C newState, L model)
            where T : class, IStateChangeEntityBase <C>
            where C : Enum
            where L : class
        {
            CheckCorrectOverloadForTasks(change);

            BasicWorkFlowManage(change, newState);
            change.IsValid(model);
            change.StateAction(model);

            ChangeStatus(change, newState);
        }
예제 #6
0
 public void Subscribe(Guid guid)
 {
     try
     {
         IStateChange callback = OperationContext.Current.GetCallbackChannel <IStateChange>();
         using (subscribersLock.WriteLock())
             subscribers.Add(new Client {
                 id = guid
             }, callback);
     }
     catch (Exception ex)
     {
         Log.ErrorException("Subscribe", ex);
     }
 }
예제 #7
0
        /// <summary>
        /// !!! Calls SaveChanges on <see cref="IRLSRepository{Entity, ACLEntity}"/>
        /// </summary>
        /// <typeparam name="T">Entity</typeparam>
        /// <typeparam name="C">State</typeparam>
        /// <typeparam name="K">Task entity</typeparam>
        /// <param name="change"></param>
        public K[] ManageTransition <T, C, K, AclEntity>(IStateChange <T, C> change, C newState, IRLSRepository <K, AclEntity> RlsRepository)
            where T : class, IStateChangeEntityBase <C>
            where C : Enum
            where K : TaskEntity, new()
            where AclEntity : class, IACLEntity, new()
        {
            CheckCorrectOverloadForViewModel(change);
            BasicWorkFlowManage(change, newState);

            change.IsValid();
            change.StateAction();

            var tasks = TaskCreationManage <T, C, K, AclEntity>(change, RlsRepository);

            ChangeStatus(change, newState);
            return(tasks);
        }
예제 #8
0
        public K[] ManageTransition <T, C, K, L, AclEntity>(IStateChange <T, C, L> change, C newState, L model, IRLSRepository <K, AclEntity> RlsRepository)
            where T : class, IStateChangeEntityBase <C>
            where C : Enum
            where K : TaskEntity, new()
            where L : class
            where AclEntity : class, IACLEntity, new()
        {
            BasicWorkFlowManage(change, newState);

            change.IsValid(model);
            change.StateAction(model);

            var tasks = TaskCreationManage <T, C, K, AclEntity>(change, RlsRepository);

            ChangeStatus(change, newState);
            return(tasks);
        }
예제 #9
0
 public void Unsubscribe(Guid guid)
 {
     try
     {
         IStateChange callback = OperationContext.Current.GetCallbackChannel <IStateChange>();
         using (subscribersLock.WriteLock())
         {
             var query = from c in subscribers.Keys
                         where c.id == guid
                         select c;
             subscribers.Remove(query.First());
         }
     }
     catch (Exception ex)
     {
         Log.ErrorException("Unsubscribe", ex);
     }
 }
예제 #10
0
        private void CheckCorrectOverloadForTasks <T, C>(IStateChange <T, C> change)
            where T : class, IStateChangeEntityBase <C>
            where C : Enum
        {
            var implementedInterfaces = change.GetType().GetInterfaces().Select(x => x.Name);

            if (implementedInterfaces.Any(x => x.IndexOf("IProducesTask") == 0))
            {
                throw new Exception($"Change implements {nameof(IProducesTask<TaskEntity>)} interface! Use the other overload method of {nameof(BasicWorkFlowManage)} " +
                                    $"or remove interface from change!");
            }

            if (implementedInterfaces.Any(x => x.IndexOf("IHasTaskPrerequity") == 0))
            {
                throw new Exception($"Change implements {nameof(IHasTaskPrerequity)} interface! Use the other overload method of {nameof(BasicWorkFlowManage)} " +
                                    $"or remove interface from change!");
            }
        }
예제 #11
0
        private K[] TaskCreationManage <T, C, K, AclEntity>(IStateChange <T, C> change, IRLSRepository <K, AclEntity> RlsRepository)
            where T : class, IStateChangeEntityBase <C>
            where C : Enum
            where K : TaskEntity, new()
            where AclEntity : class, IACLEntity, new()
        {
            K[] CreateTasksIfNeeded()
            {
                if (change is IProducesTask <K> taskChange)
                {
                    var config     = change.GetConfiguration();
                    var tasksAdded = new List <K>();
                    var acls       = new List <AclEntity>();
                    var secObjectsToAssignTasksTo = taskChange.AssignTaskToSecurityObjects();
                    if (config.TaskAssignType == TaskAssignType.Default)
                    {
                        throw new Exception($"{nameof(config.TaskAssignType)} is default! Please set up the setting correctly!");
                    }
                    if (config.TaskAssignType != TaskAssignType.Default)
                    {
                        if (config.TaskAssignType == TaskAssignType.AssignMany)
                        {
                            foreach (var securityObject in secObjectsToAssignTasksTo)
                            {
                                var task = new K
                                {
                                    EntityId = change.Entity.Id,
                                    Status   = TaskStatus.Pending,
                                    UniqueID = change.GetType().FullName
                                };
                                tasksAdded.Add(task);
                            }
                        }
                        else
                        {
                            var task = new K
                            {
                                EntityId = change.Entity.Id,
                                Status   = TaskStatus.Pending,
                                UniqueID = change.GetType().FullName
                            };
                            tasksAdded.Add(task);
                        }
                    }

                    foreach (var task in tasksAdded)
                    {
                        RlsRepository.Add(task);
                    }
                    // Must call this, to let the tasks have a generated id
                    RlsRepository.SaveChanges();

                    foreach (var task in tasksAdded)
                    {
                        if (config.TaskAssignType == TaskAssignType.AssignMany)
                        {
                            foreach (var user in secObjectsToAssignTasksTo)
                            {
                                acls.Add(new AclEntity
                                {
                                    EntityID         = task.Id,
                                    Permission       = PermissionEnum.Full,
                                    SecurityObjectID = user
                                });
                            }
                        }
                        else
                        {
                            acls.Add(new AclEntity
                            {
                                EntityID         = task.Id,
                                Permission       = PermissionEnum.Full,
                                SecurityObjectID = secObjectsToAssignTasksTo.First()
                            });
                        }
                    }
                    RlsRepository.AddAcls(acls.ToArray());
                    RlsRepository.SaveChanges();

                    return(tasksAdded.ToArray());
                }

                return(null);
            }

            void CheckForTasksIfNeeded()
            {
                if (change is IHasTaskPrerequity changeHasTasks)
                {
                    var tasksToCheck = changeHasTasks.getCreatedTask();
                    if (tasksToCheck.Any(x => x.Status == TaskStatus.Pending))
                    {
                        throw new StateTransitionException($"Can't performe state transition because there are tasks to be finished! " +
                                                           $"{string.Join(", ", tasksToCheck.Where(x => x.Status == TaskStatus.Pending).Select(x => x.Id))}");
                    }
                }
            }

            void CallAlterTasks(K[] tasks2)
            {
                if (change is IValidateTasks <K> validateTask && (tasks2 != null))
                {
                    foreach (var task in tasks2)
                    {
                        validateTask.AlterTasks(task);
                    }
                }
            }

            var tasks = CreateTasksIfNeeded();

            CheckForTasksIfNeeded();

            CallAlterTasks(tasks);

            return(tasks);
        }
예제 #12
0
 public DebugOverlay(IStateChange stateChange)
 {
     _stateChange = stateChange;
 }
예제 #13
0
 private IStateChange[] GetStateChangeHooks(IList list)
 {
     IStateChange[] ret = new IStateChange [list.Count];
     list.CopyTo (ret, 0);
     return ret;
 }
예제 #14
0
        public void Initialize(StateInitDesc initDesc)
        {
            _kernel         = initDesc.Kernel;
            _archiveManager = initDesc.ArchiveManager;
            _inputManager   = initDesc.InputManager;
            _stateChange    = initDesc.StateChange;

            drawing = new MonoDrawing(initDesc.GraphicsDevice.GraphicsDevice, initDesc.ContentManager);
            var viewport = initDesc.GraphicsDevice.GraphicsDevice.Viewport;

            drawing.SetProjection(
                viewport.Width,
                viewport.Height,
                Global.ResolutionWidth,
                Global.ResolutionHeight,
                1.0f);

            cachedSurfaces = new Dictionary <string, IEnumerable <ISurface> >();

            if (_kernel.IsReMix)
            {
                _archiveManager.LoadArchive($"menu/{_kernel.Region}/titlejf.2ld");
            }
            _archiveManager.LoadArchive($"menu/{_kernel.Region}/title.2ld");
            _archiveManager.LoadArchive($"menu/{_kernel.Region}/save.2ld");

            _isTheaterModeUnlocked = false;
            if (_kernel.IsReMix)
            {
                if (_isTheaterModeUnlocked)
                {
                    _titleLayout = ReMixTheaterTitleLayout;
                }
                else
                {
                    _titleLayout = ReMixTitleLayout;
                }
            }
            else if (_kernel.RegionId == Constants.RegionFinalMix)
            {
                if (_isTheaterModeUnlocked)
                {
                    _titleLayout = FinalMixTheaterTitleLayout;
                }
                else
                {
                    _titleLayout = FinalMixTitleLayout;
                }
            }
            else
            {
                _titleLayout = VanillaTitleLayout;
            }

            layoutRendererBg = CreateLayoutRenderer("titl");
            layoutRendererFg = CreateLayoutRenderer("titl");
            layoutRendererBg.SelectedSequenceGroupIndex = _titleLayout.Copyright;

            if (_titleLayout.HasTheater)
            {
                layoutRendererTheater = CreateLayoutRenderer("even");
            }

            SetOption(0);
        }
예제 #15
0
 public void SetStateChanger(IStateChange mainWindow)
 {
     _stateChanger = mainWindow;
 }
예제 #16
0
        public void Initialize(StateInitDesc initDesc)
        {
            Kernel          = initDesc.Kernel;
            _archiveManager = initDesc.ArchiveManager;
            InputManager    = initDesc.InputManager;
            _stateChange    = initDesc.StateChange;

            var viewport = initDesc.GraphicsDevice.GraphicsDevice.Viewport;

            _shader = new KingdomShader(initDesc.ContentManager);
            drawing = new MonoSpriteDrawing(initDesc.GraphicsDevice.GraphicsDevice, _shader);
            drawing.SetProjection(
                viewport.Width,
                viewport.Height,
                Global.ResolutionWidth,
                Global.ResolutionHeight,
                1.0f);

            if (Kernel.IsReMix)
            {
                _archiveManager.LoadArchive($"menu/{Kernel.Region}/titlejf.2ld");
            }
            _archiveManager.LoadArchive($"menu/{Kernel.Region}/title.2ld");
            _archiveManager.LoadArchive($"menu/{Kernel.Region}/save.2ld");

            _isTheaterModeUnlocked = false;
            if (Kernel.IsReMix)
            {
                if (_isTheaterModeUnlocked)
                {
                    _titleLayoutDesc = ReMixTheaterTitleLayout;
                }
                else
                {
                    _titleLayoutDesc = ReMixTitleLayout;
                }
            }
            else if (Kernel.RegionId == Kh2.Constants.RegionFinalMix)
            {
                if (_isTheaterModeUnlocked)
                {
                    _titleLayoutDesc = FinalMixTheaterTitleLayout;
                }
                else
                {
                    _titleLayoutDesc = FinalMixTitleLayout;
                }
            }
            else
            {
                _titleLayoutDesc = VanillaTitleLayout;
            }

            var messageContext = Kernel.SystemMessageContext;

            _messageRenderer = new Kh2MessageRenderer(drawing, messageContext);

            IEnumerable <ISpriteTexture> images;

            (_titleLayout, images) = GetLayoutResources("titl", "titl");

            layoutRendererBg = new LayoutRenderer(_titleLayout, drawing, images);
            layoutRendererFg = new LayoutRenderer(_titleLayout, drawing, images);
            layoutRendererBg.SelectedSequenceGroupIndex = _titleLayoutDesc.Copyright;
            _sequenceRendererMenu = new SequenceRenderer(_titleLayout.SequenceItems[0], drawing, images.First());

            Log.Info($"Theater={_titleLayoutDesc.HasTheater}");
            if (_titleLayoutDesc.HasTheater)
            {
                (_theaterLayout, images) = GetLayoutResources("even", "even");
                layoutRendererTheater    = new LayoutRenderer(_theaterLayout, drawing, images);
            }


            SetOption(0);
        }
예제 #17
0
 public void registerNotification(IStateChange listener)
 {
     this.listenersList.Add(listener);
 }
예제 #18
0
 private IStateChange[] GetStateChangeHooks(IList list)
 {
     IStateChange[] ret = new IStateChange [list.Count];
     list.CopyTo(ret, 0);
     return(ret);
 }
예제 #19
0
        private void BasicWorkFlowManage <T, C>(IStateChange <T, C> change, C newState)
            where T : class, IStateChangeEntityBase <C>
            where C : Enum
        {
            void HasSufficentPermission()
            {
                var changeConfiguration = change.GetConfiguration();

                if (changeConfiguration != null &&
                    changeConfiguration.HasPermissionToFullfillChange != null &&
                    changeConfiguration.HasPermissionToFullfillChange.Length > 0)
                {
                    if (changeConfiguration.HasPermissionToFullfillChange.Any(x => CurrentUserGoups.Contains(x.Id)))
                    {
                        return;
                    }
                    else
                    {
                        throw new StateTransitionException($"User has no permission to perform this transition. Change type: {change.GetType().Name}");
                    }
                }
                else
                {
                    throw new Exception($"Invalid {nameof(StateChangeConfiguration)}. Override {nameof(change.GetConfiguration)} properly!");
                }
            }

            void StateTransitionValid()
            {
                var changeConfiguration = change.GetConfiguration();

                if (changeConfiguration == null)
                {
                    throw new Exception($"Invalid {nameof(StateChangeConfiguration)} object!");
                }

                if (changeConfiguration.AllowedStartStates != null &&
                    changeConfiguration.AllowedStartStates.Length > 0)
                {
                    if (!changeConfiguration.AllowedStartStates.Contains(change.Entity.CurrentState))
                    {
                        throw new StateTransitionException($"Tried transition from {change.Entity.CurrentState} to {newState}, which is disallowed! " +
                                                           $"(possible state change outside of {nameof(StateManagger)}");
                    }
                }

                if (changeConfiguration.AllowedEndStates != null &&
                    changeConfiguration.AllowedEndStates.Length > 0)
                {
                    if (!changeConfiguration.AllowedEndStates.Contains(newState))
                    {
                        throw new StateTransitionException($"Tried transition to '{newState}', which is disallowed end state!");
                    }
                }
            }

            void TestChangeRule()
            {
                change.IsValid();
            }

            HasSufficentPermission();

            StateTransitionValid();

            TestChangeRule();
        }
예제 #20
0
 public StateChangeEvent(IStateChange state)
 {
     this.State = state;
 }
예제 #21
0
 private void ChangeStatus <T, C>(IStateChange <T, C> change, C newState)
     where T : class, IStateChangeEntityBase <C>
     where C : Enum
 {
     change.Entity.CurrentState = newState;
 }
예제 #22
0
 public VirtualClick(IStateChange callback, GameObject buttonModel)
 {
     this.callback    = callback;
     this.buttonModel = buttonModel;
 }
예제 #23
0
 public void SetStateChanger(IStateChange drinkView)
 {
     _stateChanger = drinkView;
 }