Пример #1
0
            public override void StartLoading()
            {
                var user = plugin as IUser;

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

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

                var storedMovingMeeleAttacker = storedData.MovingMeeleAttacker;


                MovingMeele = new MovingMeeleAttacker(level,
                                                      storedMovingMeeleAttacker.SearchForTarget,
                                                      storedMovingMeeleAttacker.SearchRectangleSize.ToIntVector2(),
                                                      storedMovingMeeleAttacker.TimeBetweenSearches,
                                                      storedMovingMeeleAttacker.TimeBetweenPositionChecks,
                                                      storedMovingMeeleAttacker.TimeBetweenAttacks,
                                                      storedMovingMeeleAttacker.Enabled,
                                                      storedMovingMeeleAttacker.TimeToNextSearch,
                                                      storedMovingMeeleAttacker.TimeToNextPositionCheck,
                                                      storedMovingMeeleAttacker.TimeToNextAttack,
                                                      user
                                                      );

                targetID = storedMovingMeeleAttacker.TargetID;
            }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="plugin"></param>
        /// <param name="level"></param>
        /// <param name="searchForTarget"></param>
        /// <param name="searchRectangleSize">The size of the rectangle with the Entity in the center that will be checked for possible targets</param>
        /// <param name="timeBetweenSearches">Time between searching the rectangle of size <paramref name="searchRectangleSize"/> if <paramref name="searchForTarget"/> is true</param>
        /// <param name="timeBetweenPositionChecks">Time between the attacker checks if the targets position changed and recalculates its path</param>
        /// <param name="timeBetweenAttacks">Time between each attack</param>
        /// <returns></returns>
        public static MovingMeeleAttacker CreateNew <T>(T plugin,
                                                        ILevelManager level,
                                                        bool searchForTarget,
                                                        IntVector2 searchRectangleSize,
                                                        float timeBetweenSearches,
                                                        float timeBetweenPositionChecks,
                                                        float timeBetweenAttacks
                                                        )
            where T : UnitInstancePlugin, IUser
        {
            if (plugin == null)
            {
                throw new ArgumentNullException(nameof(plugin));
            }

            var newInstance = new MovingMeeleAttacker(level,
                                                      searchForTarget,
                                                      searchRectangleSize,
                                                      timeBetweenSearches,
                                                      timeBetweenPositionChecks,
                                                      timeBetweenAttacks,
                                                      true,
                                                      plugin);

            plugin.Entity.AddComponent(newInstance);
            return(newInstance);
        }
Пример #3
0
            public static StDefaultComponent SaveState(MovingMeeleAttacker movingMeele)
            {
                var storedMovingMeeleAttacker = new StMovingMeeleAttacker
                {
                    Enabled                   = movingMeele.Enabled,
                    SearchForTarget           = movingMeele.SearchForTarget,
                    SearchRectangleSize       = movingMeele.SearchRectangleSize.ToStIntVector2(),
                    TimeBetweenSearches       = movingMeele.TimeBetweenSearches,
                    TimeBetweenPositionChecks = movingMeele.timeBetweenPositionChecks,
                    TimeBetweenAttacks        = movingMeele.TimeBetweenAttacks,
                    TargetID                  = movingMeele.Target?.ID ?? 0,
                    TimeToNextAttack          = movingMeele.TimeToNextAttack,
                    TimeToNextPositionCheck   = movingMeele.timeToNextPositionCheck,
                    TimeToNextSearch          = movingMeele.TimeToNextSearch
                };

                return(new StDefaultComponent {
                    MovingMeeleAttacker = storedMovingMeeleAttacker
                });
            }