Example #1
0
            public override void StartLoading()
            {
                var user = plugin as IUser;

                if (user == null)
                {
                    throw new
                          ArgumentException($"provided plugin does not implement the {nameof(MovingMeeleAttacker.IUser)} interface", nameof(plugin));
                }

                if (storedData.ComponentCase != StDefaultComponent.ComponentOneofCase.StaticMeeleAttacker)
                {
                    throw new ArgumentException("Invalid component type data passed to loader", nameof(storedData));
                }

                var storedStaticMeeleAttacker = storedData.StaticMeeleAttacker;

                StaticMeele = new StaticMeeleAttacker(level,
                                                      storedStaticMeeleAttacker.SearchForTarget,
                                                      storedStaticMeeleAttacker.SearchRectangleSize.ToIntVector2(),
                                                      storedStaticMeeleAttacker.TimeBetweenSearches,
                                                      storedStaticMeeleAttacker.TimeBetweenAttacks,
                                                      storedStaticMeeleAttacker.Enabled,
                                                      storedStaticMeeleAttacker.TimeToNextSearch,
                                                      storedStaticMeeleAttacker.TimeToNextAttack,
                                                      user);

                targetID = storedStaticMeeleAttacker.TargetID;
            }
Example #2
0
            public static StDefaultComponent SaveState(StaticMeeleAttacker staticMeele)
            {
                var storedStaticMeeleAttacker = new StStaticMeeleAttacker
                {
                    Enabled             = staticMeele.Enabled,
                    SearchForTarget     = staticMeele.SearchForTarget,
                    SearchRectangleSize = staticMeele.SearchRectangleSize.ToStIntVector2(),
                    TimeBetweenAttacks  = staticMeele.TimeBetweenAttacks,
                    TimeBetweenSearches = staticMeele.TimeBetweenSearches,
                    TimeToNextAttack    = staticMeele.TimeToNextAttack,
                    TimeToNextSearch    = staticMeele.TimeToNextSearch,
                    TargetID            = staticMeele.Target?.ID ?? 0
                };

                return(new StDefaultComponent {
                    StaticMeeleAttacker = storedStaticMeeleAttacker
                });
            }
Example #3
0
        public static StaticMeeleAttacker CreateNew <T>(T plugin,
                                                        ILevelManager level,
                                                        bool searchForTarget,
                                                        IntVector2 searchRectangleSize,
                                                        float timeBetweenSearches,
                                                        float timeBetweenAttacks
                                                        )
            where T : EntityInstancePlugin, IUser
        {
            if (plugin == null)
            {
                throw new ArgumentNullException(nameof(plugin));
            }

            var newInstance = new StaticMeeleAttacker(level,
                                                      searchForTarget,
                                                      searchRectangleSize,
                                                      timeBetweenSearches,
                                                      timeBetweenAttacks,
                                                      plugin);

            plugin.Entity.AddComponent(newInstance);
            return(newInstance);
        }