Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StatsForm"/> class.
        /// </summary>
        /// <param name="userInfo">The user info.</param>
        /// <param name="parent">The parent.</param>
        /// <exception cref="ArgumentNullException"><paramref name="userInfo" /> is <c>null</c>.</exception>
        public StatsForm(UserInfo userInfo, Control parent) : base(parent, Vector2.Zero, new Vector2(225, 275))
        {
            if (userInfo == null)
                throw new ArgumentNullException("userInfo");

            _addStatGrh = new Grh(GrhInfo.GetData("GUI", "AddStat"));

            _userInfo = userInfo;

            _yOffset = 2;

            NewUserInfoLabel("Level", x => x.Level.ToString());
            NewUserInfoLabel("Exp", x => x.Exp.ToString());
            NewUserInfoLabel("StatPoints", x => x.StatPoints.ToString());

            AddLine();

            NewUserInfoLabel("HP", x => x.HP + " / " + x.ModStats[StatType.MaxHP]);
            NewUserInfoLabel("MP", x => x.MP + " / " + x.ModStats[StatType.MaxMP]);

            AddLine();

            NewStatLabel(StatType.MinHit);
            NewStatLabel(StatType.MaxHit);
            NewStatLabel(StatType.Defence);

            AddLine();

            NewStatLabel(StatType.Str);
            NewStatLabel(StatType.Agi);
            NewStatLabel(StatType.Int);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SkeletonBodyItem"/> class.
 /// </summary>
 /// <param name="itemInfo">SkeletonBodyItemInfo to create the SkeletonBodyItem from</param>
 public SkeletonBodyItem(SkeletonBodyItemInfo itemInfo)
 {
     _itemInfo = itemInfo;
     var grhData = GrhInfo.GetData(_itemInfo.GrhIndex);
     if (grhData != null)
         Grh = new Grh(grhData, AnimType.Loop, 0);
 }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WaterRefractionEffect"/> class.
        /// </summary>
        /// <param name="waveNoise">The sprite to use for the wave noise.</param>
        /// <param name="position">The initial world position of the effect.</param>
        /// <param name="size">The size of the effect in pixels.</param>
        /// <param name="shader">The <see cref="Shader"/> to use to draw the water's refraction map. If null, the
        /// <see cref="WaterRefractionEffect.DefaultShader"/> will be used. If you provide your own shader, you must
        /// make sure that you either use the same effect parameters the default shader uses, or override this class
        /// so you can override the <see cref="WaterRefractionEffect.SetShaderParameters"/> method and set the parameters
        /// you require.</param>
        /// <exception cref="ArgumentNullException"><paramref name="waveNoise"/> is null.</exception>
        public WaterRefractionEffect(Grh waveNoise, Vector2 position, Vector2 size, Shader shader = null)
        {
            if (waveNoise == null)
            {
                throw new ArgumentNullException("waveNoise");
            }

            _waveNoise = waveNoise;
            _position  = position;
            _size      = size;

            _shader = shader ?? DefaultShader;

            // Copy over the default values
            WaveIntensity = DefaultWaveIntensity;
            WaveSpeed     = DefaultWaveSpeed;
            WaterAlpha    = DefaultWaterAlpha;
            Magnification = DefaultMagnification;
            IsEnabled     = true;

            // Ensure we are able to use the effect
            if (_shader == null)
            {
                const string errmsg =
                    "Shaders not supported or unable to acquire a valid default shader. Expiring effect `{0}`...";
                if (log.IsInfoEnabled)
                {
                    log.InfoFormat(errmsg, this);
                }
                Dispose();
            }
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrhEffectSeekPosition"/> class.
        /// </summary>
        /// <param name="grh">Grh to draw.</param>
        /// <param name="position">Position to draw on the map.</param>
        /// <param name="target">The destination position.</param>
        /// <param name="speed">How fast this object moves towards the target in pixels per second.</param>
        public MapGrhEffectSeekPosition(Grh grh, Vector2 position, Vector2 target, float speed)
            : base(grh, position)
        {
            speed = speed / 1000f;

            _startTime = TickCount.Now;
            _startPosition = position;
            _targetPosition = target;

            // Calculate the angle between the position and target
            var diff = position - target;
            var angle = Math.Atan2(diff.Y, diff.X);

            var cos = Math.Cos(angle);
            var sin = Math.Sin(angle);

            // Multiply the normalized direction vector (the cos and sine values) by the speed to get the velocity
            // to use for each elapsed millisecond
            _velocity = -new Vector2((float)(cos * speed), (float)(sin * speed));

            // Precalculate the amount of time it will take to hit the target. This way, we can check if we have reached
            // the destination simply by checking the current time.
            var dist = Vector2.Distance(position, target);
            var reqTime = (int)Math.Ceiling(dist / speed);

            _endTime = (TickCount)(_startTime + reqTime);
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrhEffectSeekPosition"/> class.
        /// </summary>
        /// <param name="grh">Grh to draw.</param>
        /// <param name="position">Position to draw on the map.</param>
        /// <param name="target">The destination position.</param>
        /// <param name="speed">How fast this object moves towards the target in pixels per second.</param>
        public MapGrhEffectSeekPosition(Grh grh, Vector2 position, Vector2 target, float speed)
            : base(grh, position)
        {
            speed = speed / 1000f;

            _startTime      = TickCount.Now;
            _startPosition  = position;
            _targetPosition = target;

            // Calculate the angle between the position and target
            var diff  = position - target;
            var angle = Math.Atan2(diff.Y, diff.X);

            var cos = Math.Cos(angle);
            var sin = Math.Sin(angle);

            // Multiply the normalized direction vector (the cos and sine values) by the speed to get the velocity
            // to use for each elapsed millisecond
            _velocity = -new Vector2((float)(cos * speed), (float)(sin * speed));

            // Precalculate the amount of time it will take to hit the target. This way, we can check if we have reached
            // the destination simply by checking the current time.
            var dist    = Vector2.Distance(position, target);
            var reqTime = (int)Math.Ceiling(dist / speed);

            _endTime = (TickCount)(_startTime + reqTime);
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditGrhForm"/> class.
        /// </summary>
        /// <param name="gd">The <see cref="GrhData"/> to edit.</param>
        /// <param name="mapGrhWalls">The <see cref="MapGrhWalls"/> instance.</param>
        /// <param name="createWall">Delegate describing how to create wall instances.</param>
        /// <param name="deleteOnCancel">If the <see cref="GrhData"/> will be deleted if the editing is canceled.</param>
        /// <exception cref="ArgumentNullException"><paramref name="gd" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="mapGrhWalls" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="createWall" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Cannot edit an <see cref="AutomaticAnimatedGrhData"/>.</exception>
        public EditGrhForm(GrhData gd, MapGrhWalls mapGrhWalls, CreateWallEntityHandler createWall, bool deleteOnCancel)
        {
            if (gd == null)
                throw new ArgumentNullException("gd");
            if (mapGrhWalls == null)
                throw new ArgumentNullException("mapGrhWalls");
            if (createWall == null)
                throw new ArgumentNullException("createWall");
            if (gd is AutomaticAnimatedGrhData)
                throw new ArgumentException("Cannot edit an AutomaticAnimatedGrhData.", "gd");

            DeleteOnCancel = deleteOnCancel;
            WasCanceled = false;

            // Set the local members
            _createWall = createWall;
            _gd = gd;
            _mapGrhWalls = mapGrhWalls;

            _grh = new Grh(gd, AnimType.Loop, TickCount.Now);

            InitializeComponent();

            ShowGrhInfo();
        }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MiniMapForm"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="screen">The game play screen.</param>
 public MiniMapForm(Control parent, GameplayScreen screen) : base(parent, new Vector2(50, 50), new Vector2(250, 250))
 {
     _topLeftPos = new Vector2(this.Position.X + this.Border.LeftWidth, this.Position.Y + this.Border.TopHeight);
     _scaledMapGrh = new Grh(null);
     _entityCharGrh = new Grh(GrhInfo.GetData("GUI", "MiniMapCharacter"));
     _entityNPCGrh = new Grh(GrhInfo.GetData("GUI", "MiniMapNPC"));
     _gamePlayScreen = screen;
 }
Example #8
0
        public ItemEntity(MapEntityIndex mapEntityIndex, Vector2 pos, Vector2 size, GrhIndex graphicIndex, TickCount currentTime)
            : base(pos, size)
        {
            Amount = 0;

            ((IDynamicEntitySetMapEntityIndex)this).SetMapEntityIndex(mapEntityIndex);
            _grh = new Grh(GrhInfo.GetData(graphicIndex), AnimType.Loop, currentTime);
        }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrh"/> class.
        /// </summary>
        /// <param name="reader">The reader to read the values from.</param>
        /// <param name="currentTime">The current time.</param>
        /// <exception cref="ArgumentNullException"><paramref name="reader" /> is <c>null</c>.</exception>
        public MapGrh(IValueReader reader, TickCount currentTime)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            _grh = new Grh(null, AnimType.Loop, currentTime);

            ReadState(reader);
        }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SkeletonBodyItem"/> class.
        /// </summary>
        /// <param name="itemInfo">SkeletonBodyItemInfo to create the SkeletonBodyItem from</param>
        public SkeletonBodyItem(SkeletonBodyItemInfo itemInfo)
        {
            _itemInfo = itemInfo;
            var grhData = GrhInfo.GetData(_itemInfo.GrhIndex);

            if (grhData != null)
            {
                Grh = new Grh(grhData, AnimType.Loop, 0);
            }
        }
Example #11
0
        /// <summary>
        /// Reads the <see cref="BackgroundImage"/> from an <see cref="IValueReader"/>.
        /// </summary>
        /// <param name="reader">The <see cref="IValueReader"/> to read from.</param>
        protected virtual void Read(IValueReader reader)
        {
            Name      = reader.ReadString(_valueKeyName);
            Alignment = reader.ReadEnum <Alignment>(_valueKeyAlignment);
            Color     = reader.ReadColor(_valueKeyColor);
            Depth     = reader.ReadFloat(_valueKeyDepth);
            Offset    = reader.ReadVector2(_valueKeyOffset);
            var grhIndex = reader.ReadGrhIndex(_valueKeyGrhIndex);

            _sprite = new Grh(grhIndex, AnimType.Loop, Map.GetTime());
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrhEffectLoopOnce"/> class.
        /// </summary>
        /// <param name="grh">Grh to draw.</param>
        /// <param name="position">Position to draw on the map.</param>
        /// <param name="target">The <see cref="ISpatial"/> to seek out.</param>
        /// <param name="speed">How fast this object moves towards the target in pixels per second.</param>
        /// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
        public MapGrhEffectSeekSpatial(Grh grh, Vector2 position, ISpatial target, float speed)
            : base(grh, position)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            _lastUpdate = TickCount.Now;

            _target = target;
            _speed = speed / 1000f;
        }
Example #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrh"/> class.
        /// </summary>
        /// <param name="reader">The reader to read the values from.</param>
        /// <param name="currentTime">The current time.</param>
        /// <exception cref="ArgumentNullException"><paramref name="reader" /> is <c>null</c>.</exception>
        public MapGrh(IValueReader reader, TickCount currentTime)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            _grh = new Grh(null, AnimType.Loop, currentTime);

            ReadState(reader);
        }
Example #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrh"/> class.
        /// </summary>
        /// <param name="grh">Grh to draw.</param>
        /// <param name="position">Position to draw on the map.</param>
        public MapGrh(Grh grh, Vector2 position)
        {
            if (grh == null)
                throw new ArgumentNullException("grh");

            _grh = grh;
            _position = position;

            // Set the initial size value
            var grhSize = Grh.Size;
            Vector2.Multiply(ref _scale, ref grhSize, out _scaledGrhSizeCache);
        }
Example #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrh"/> class.
        /// </summary>
        /// <param name="grh">Grh to draw.</param>
        /// <param name="position">Position to draw on the map.</param>
        /// <param name="isForeground">If true, this will be drawn in the foreground layer. If false,
        /// it will be drawn in the background layer.</param>
        public MapGrh(Grh grh, Vector2 position, bool isForeground)
        {
            if (grh == null)
            {
                Debug.Fail("grh is null.");
                return;
            }

            _grh         = grh;
            _position    = position;
            IsForeground = isForeground;
        }
Example #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrh"/> class.
        /// </summary>
        /// <param name="grh">Grh to draw.</param>
        /// <param name="position">Position to draw on the map.</param>
        /// <param name="isForeground">If true, this will be drawn in the foreground layer. If false,
        /// it will be drawn in the background layer.</param>
        public MapGrh(Grh grh, Vector2 position, bool isForeground)
        {
            if (grh == null)
            {
                Debug.Fail("grh is null.");
                return;
            }

            _grh = grh;
            _position = position;
            IsForeground = isForeground;
        }
Example #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrh"/> class.
        /// </summary>
        /// <param name="reader">The reader to read the values from.</param>
        /// <param name="currentTime">The current time.</param>
        /// <exception cref="ArgumentNullException"><paramref name="reader" /> is <c>null</c>.</exception>
        public MapGrh(IValueReader reader, TickCount currentTime)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            _grh = new Grh(null, AnimType.Loop, currentTime);

            ReadState(reader);

            // Set the initial size value
            var grhSize = Grh.Size;
            Vector2.Multiply(ref _scale, ref grhSize, out _scaledGrhSizeCache);
        }
Example #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrhEffectLoopOnce"/> class.
        /// </summary>
        /// <param name="grh">Grh to draw.</param>
        /// <param name="position">Position to draw on the map.</param>
        /// <param name="target">The <see cref="ISpatial"/> to seek out.</param>
        /// <param name="speed">How fast this object moves towards the target in pixels per second.</param>
        /// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
        public MapGrhEffectSeekSpatial(Grh grh, Vector2 position, ISpatial target, float speed)
            : base(grh, position)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            _lastUpdate = TickCount.Now;

            _target = target;
            _speed  = speed / 1000f;
        }
Example #19
0
        /// <summary>
        /// Checks if a specified object is in view of the camera.
        /// </summary>
        /// <param name="grh">The <see cref="Grh"/> to check.</param>
        /// <param name="position">The position of the <see cref="Grh"/>.</param>
        /// <returns>True if in the view area; otherwise false.</returns>
        public bool InView(Grh grh, Vector2 position)
        {
            if (grh == null)
            {
                const string errmsg = "grh is null.";
                Debug.Fail(errmsg);
                if (log.IsErrorEnabled)
                {
                    log.Error(errmsg);
                }
                return(false);
            }

            return(InView(position, grh.Size));
        }
Example #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrh"/> class.
        /// </summary>
        /// <param name="grh">Grh to draw.</param>
        /// <param name="position">Position to draw on the map.</param>
        public MapGrh(Grh grh, Vector2 position)
        {
            if (grh == null)
            {
                throw new ArgumentNullException("grh");
            }

            _grh      = grh;
            _position = position;

            // Set the initial size value
            var grhSize = Grh.Size;

            Vector2.Multiply(ref _scale, ref grhSize, out _scaledGrhSizeCache);
        }
Example #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrh"/> class.
        /// </summary>
        /// <param name="reader">The reader to read the values from.</param>
        /// <param name="currentTime">The current time.</param>
        /// <exception cref="ArgumentNullException"><paramref name="reader" /> is <c>null</c>.</exception>
        public MapGrh(IValueReader reader, TickCount currentTime)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            _grh = new Grh(null, AnimType.Loop, currentTime);

            ReadState(reader);

            // Set the initial size value
            var grhSize = Grh.Size;

            Vector2.Multiply(ref _scale, ref grhSize, out _scaledGrhSizeCache);
        }
Example #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundImage"/> class.
        /// </summary>
        /// <param name="cameraProvider">The camera provider.</param>
        /// <param name="map">The map that this <see cref="BackgroundImage"/> is on.</param>
        /// <exception cref="ArgumentNullException"><paramref name="cameraProvider" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="map" /> is <c>null</c>.</exception>
        protected BackgroundImage(ICamera2DProvider cameraProvider, IMap map)
        {
            if (cameraProvider == null)
                throw new ArgumentNullException("cameraProvider");
            if (map == null)
                throw new ArgumentNullException("map");

            _cameraProvider = cameraProvider;
            _map = map;

            // Set the default values
            Offset = Vector2.Zero;
            Alignment = Alignment.TopLeft;

            _sprite = new Grh(null, AnimType.Loop, map.GetTime());
        }
Example #23
0
        /// <summary>
        /// Edits the specified object's value using the editor style indicated by the
        /// <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"/> method.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be
        /// used to gain additional context information.</param>
        /// <param name="provider">An <see cref="T:System.IServiceProvider"/> that this editor can use to
        /// obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns>
        /// The new value of the object. If the value of the object has not changed, this should return the
        /// same object it was passed.
        /// </returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (svc != null)
            {
                using (var editorForm = new GrhUITypeEditorForm(value))
                {
                    var pt = context.PropertyDescriptor.PropertyType;

                    if (svc.ShowDialog(editorForm) == DialogResult.OK)
                    {
                        var sel = editorForm.SelectedValue;

                        // Handle setting the value based on the type we are working with
                        if (pt == typeof(GrhIndex) || pt == typeof(GrhIndex?))
                            value = sel;
                        else if (pt == typeof(Grh))
                        {
                            var asGrh = value as Grh;
                            if (asGrh != null)
                                asGrh.SetGrh(sel);
                            else
                                value = new Grh(sel, AnimType.Loop, 0);
                        }
                        else if (pt == typeof(GrhData))
                            value = GrhInfo.GetData(sel);
                        else
                        {
                            const string errmsg =
                                "Don't know how to handle the source property type `{0}`. In value: {1}. Editor type: {2}";
                            if (log.IsErrorEnabled)
                                log.ErrorFormat(errmsg, pt, value, editorForm.GetType());
                            Debug.Fail(string.Format(errmsg, pt, value, editorForm.GetType()));
                        }
                    }
                    else
                    {
                        if (pt == typeof(GrhIndex?))
                            value = null;
                    }
                }
            }

            return value;
        }
Example #24
0
        /// <summary>
        /// Draws the <see cref="SkeletonBodyItem"/>.
        /// </summary>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="position">Position to draw at.</param>
        /// <param name="scale">Amount to scale the Grh in percent (1.0f for no scaling).</param>
        /// <param name="color">The color.</param>
        /// <param name="effect">SpriteEffects to use when drawing.</param>
        internal void Draw(ISpriteBatch sb, Vector2 position, float scale, Color color, SpriteEffects effect)
        {
            // Validate
            if (Source == null)
            {
                return;
            }

            // Find the effect
            Vector2 m;

            switch (effect)
            {
            case SpriteEffects.FlipHorizontally:
                m = new Vector2(-1, 1);
                break;

            case SpriteEffects.FlipVertically:
                m = new Vector2(1, -1);
                break;

            default:
                m = new Vector2(1, 1);
                break;
            }

            // Calculate the angle
            float angle;

            if (Dest == null)
            {
                angle = 0.0f;
            }
            else
            {
                angle = SkeletonNode.GetAngle(Source.Position * m, Dest.Position * m) - MathHelper.PiOver2;
            }

            // Draw
            var v = Source.Position + ItemInfo.Offset;

            Grh.Draw(sb, (v * m) + position, color, effect, angle, ItemInfo.Origin, scale);
        }
Example #25
0
        /// <summary>
        /// Updates the <see cref="MapGrh"/>.
        /// </summary>
        /// <param name="currentTime">Current game time.</param>
        public virtual void Update(TickCount currentTime)
        {
            Grh.Update(currentTime);

            Vector2 grhSize = Grh.Size;
            Vector2 previousScaledGrhSizeCache = _scaledGrhSizeCache;

            Vector2.Multiply(ref _scale, ref grhSize, out _scaledGrhSizeCache);

            // Check if the scaled size has changed, but we have not updated the cache. The most common ways for this to happen is if the GrhData changes, or the
            // Grh is animated but not all frames are the same size.
            if (_scaledGrhSizeCache != previousScaledGrhSizeCache)
            {
                if (Resized != null)
                {
                    Resized.Raise(this, EventArgsHelper.Create(previousScaledGrhSizeCache));
                }
            }
        }
Example #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundImage"/> class.
        /// </summary>
        /// <param name="cameraProvider">The camera provider.</param>
        /// <param name="map">The map that this <see cref="BackgroundImage"/> is on.</param>
        /// <exception cref="ArgumentNullException"><paramref name="cameraProvider" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="map" /> is <c>null</c>.</exception>
        protected BackgroundImage(ICamera2DProvider cameraProvider, IMap map)
        {
            if (cameraProvider == null)
            {
                throw new ArgumentNullException("cameraProvider");
            }
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }

            _cameraProvider = cameraProvider;
            _map            = map;

            // Set the default values
            Offset    = Vector2.Zero;
            Alignment = Alignment.TopLeft;

            _sprite = new Grh(null, AnimType.Loop, map.GetTime());
        }
Example #27
0
        /// <summary>
        /// Reads the state of the object from an <see cref="IValueReader"/>. Values should be read in the exact
        /// same order as they were written.
        /// </summary>
        /// <param name="reader">The <see cref="IValueReader"/> to read the values from.</param>
        public void ReadState(IValueReader reader)
        {
            PositionProvider = null;
            Tag = null;

            Position  = reader.ReadVector2(_positionValueKey);
            Size      = reader.ReadVector2(_sizeValueKey);
            Color     = reader.ReadColor(_colorValueKey);
            Rotation  = reader.ReadFloat(_rotationValueKey);
            IsEnabled = reader.ReadBool(_isEnabledValueKey);

            var grhIndex = reader.ReadGrhIndex(_spriteValueKey);

            if (grhIndex.IsInvalid)
            {
                Sprite = new Grh(grhIndex, AnimType.Loop, 0);
            }
            else
            {
                Sprite = null;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ExplosionRefractionEffect"/> class.
        /// </summary>
        /// <param name="explosionNoise">The sprite used to create the explosion's refraction map.</param>
        /// <param name="center">The world position of the effect.</param>
        /// <param name="lifeSpan">The life span in milliseconds. If 0, the <see cref="DefaultLifeSpan"/> will be used.</param>
        /// <param name="shader">The <see cref="Shader"/> to use to draw the explosion's refraction map. If null, the
        /// <see cref="ExplosionRefractionEffect.DefaultShader"/> will be used. If you provide your own shader, you must
        /// make sure that you either use the same effect parameters the default shader uses, or override this class
        /// so you can override the <see cref="ExplosionRefractionEffect.SetShaderParameters"/> method and set the parameters
        /// you require.</param>
        /// <exception cref="ArgumentNullException"><paramref name="explosionNoise"/> is null.</exception>
        public ExplosionRefractionEffect(Grh explosionNoise, Vector2 center, ushort lifeSpan = (ushort)0, Shader shader = null)
        {
            if (explosionNoise == null)
            {
                throw new ArgumentNullException("explosionNoise");
            }

            _explosionNoise = explosionNoise;
            _startTime      = TickCount.Now;
            _center         = center;

            _shader = shader ?? DefaultShader;

            if (lifeSpan <= 0)
            {
                _lifeSpan = DefaultLifeSpan;
            }
            else
            {
                _lifeSpan = 0;
            }

            // Copy over the default values
            Intensity     = DefaultIntensity;
            ExpansionRate = DefaultExpansionRate;
            IsEnabled     = true;

            // Ensure we are able to use the effect
            if (_shader == null)
            {
                const string errmsg =
                    "Shaders not supported or unable to acquire a valid default shader. Expiring effect `{0}`...";
                if (log.IsInfoEnabled)
                {
                    log.InfoFormat(errmsg, this);
                }
                Dispose();
            }
        }
Example #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WaterRefractionEffect"/> class.
 /// </summary>
 /// <param name="waveNoise">The sprite to use for the wave noise.</param>
 /// <param name="positionProvider">The <see cref="ISpatial"/> that will provide the positioning.</param>
 /// <param name="size">The size of the effect in pixels.</param>
 /// <param name="shader">The <see cref="Shader"/> to use to draw the water's refraction map. If null, the
 /// <see cref="WaterRefractionEffect.DefaultShader"/> will be used. If you provide your own shader, you must
 /// make sure that you either use the same effect parameters the default shader uses, or override this class
 /// so you can override the <see cref="WaterRefractionEffect.SetShaderParameters"/> method and set the parameters
 /// you require.</param>
 /// <exception cref="ArgumentNullException"><paramref name="waveNoise"/> is null.</exception>
 /// <exception cref="NullReferenceException"><paramref name="positionProvider"/> is null.</exception>
 public WaterRefractionEffect(Grh waveNoise, ISpatial positionProvider, Vector2 size, Shader shader = null)
     : this(waveNoise, positionProvider.Position, size, shader)
 {
     PositionProvider = positionProvider;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ExplosionRefractionEffect"/> class.
        /// </summary>
        /// <param name="explosionNoise">The sprite used to create the explosion's refraction map.</param>
        /// <param name="center">The world position of the effect.</param>
        /// <param name="lifeSpan">The life span in milliseconds. If 0, the <see cref="DefaultLifeSpan"/> will be used.</param>
        /// <param name="shader">The <see cref="Shader"/> to use to draw the explosion's refraction map. If null, the
        /// <see cref="ExplosionRefractionEffect.DefaultShader"/> will be used. If you provide your own shader, you must
        /// make sure that you either use the same effect parameters the default shader uses, or override this class
        /// so you can override the <see cref="ExplosionRefractionEffect.SetShaderParameters"/> method and set the parameters
        /// you require.</param>
        /// <exception cref="ArgumentNullException"><paramref name="explosionNoise"/> is null.</exception>
        public ExplosionRefractionEffect(Grh explosionNoise, Vector2 center, ushort lifeSpan = (ushort)0, Shader shader = null)
        {
            if (explosionNoise == null)
                throw new ArgumentNullException("explosionNoise");

            _explosionNoise = explosionNoise;
            _startTime = TickCount.Now;
            _center = center;

            _shader = shader ?? DefaultShader;

            if (lifeSpan <= 0)
                _lifeSpan = DefaultLifeSpan;
            else
                _lifeSpan = 0;

            // Copy over the default values
            Intensity = DefaultIntensity;
            ExpansionRate = DefaultExpansionRate;
            IsEnabled = true;

            // Ensure we are able to use the effect
            if (_shader == null)
            {
                const string errmsg =
                    "Shaders not supported or unable to acquire a valid default shader. Expiring effect `{0}`...";
                if (log.IsInfoEnabled)
                    log.InfoFormat(errmsg, this);
                Dispose();
            }
        }
Example #31
0
        public ItemEntity(GrhIndex graphicIndex, byte amount, TickCount currentTime) : base(Vector2.Zero, Vector2.Zero)
        {
            Amount = amount;

            _grh = new Grh(GrhInfo.GetData(graphicIndex), AnimType.Loop, currentTime);
        }
Example #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapGrhEffect"/> class.
 /// </summary>
 /// <param name="grh">Grh to draw.</param>
 /// <param name="position">Position to draw on the map.</param>
 /// <param name="isForeground">If true, this will be drawn in the foreground layer. If false,
 /// it will be drawn in the background layer.</param>
 protected MapGrhEffect(Grh grh, Vector2 position, bool isForeground) : base(grh, position, isForeground)
 {
 }
Example #33
0
        /// <summary>
        /// Checks if a specified object is in view of the camera.
        /// </summary>
        /// <param name="grh">The <see cref="Grh"/> to check.</param>
        /// <param name="position">The position of the <see cref="Grh"/>.</param>
        /// <returns>True if in the view area; otherwise false.</returns>
        public bool InView(Grh grh, Vector2 position)
        {
            if (grh == null)
            {
                const string errmsg = "grh is null.";
                Debug.Fail(errmsg);
                if (log.IsErrorEnabled)
                    log.Error(errmsg);
                return false;
            }

            return InView(position, grh.Size);
        }
Example #34
0
 /// <summary>
 /// Updates the <see cref="SkeletonBodyItem"/>.
 /// </summary>
 /// <param name="currentTime">The current time.</param>
 internal void Update(TickCount currentTime)
 {
     Grh.Update(currentTime);
 }
Example #35
0
 /// <summary>
 /// Asynchronously gets the <see cref="Image"/> for the given argument.
 /// </summary>
 /// <param name="grh">The <see cref="Grh"/> to get the <see cref="Image"/> for.</param>
 /// <param name="callback">The <see cref="GrhImageListAsyncCallback"/> to invoke when the operation has finished.</param>
 /// <param name="userState">The optional user state object to pass to the <paramref name="callback"/>.</param>
 public void GetImageAsync(Grh grh, GrhImageListAsyncCallback callback, object userState)
 {
     if (grh == null)
     {
         if (callback != null)
             callback(this, null, ErrorImage, userState);
     }
     else
         GetImage(grh.CurrentGrhData, true, callback, userState);
 }
Example #36
0
        /// <summary>
        /// Gets the <see cref="Image"/> for the given argument.
        /// </summary>
        /// <param name="grh">The <see cref="Grh"/> to get the <see cref="Image"/> for.</param>
        /// <returns>The <see cref="Image"/> for the <paramref name="grh"/>.</returns>
        public Image GetImage(Grh grh)
        {
            if (grh == null)
                return _errorImage;

            return GetImage(grh.CurrentGrhData, false, null, null);
        }
Example #37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapGrhEffect"/> class.
 /// </summary>
 /// <param name="grh">Grh to draw.</param>
 /// <param name="position">Position to draw on the map.</param>
 protected MapGrhEffect(Grh grh, Vector2 position) : base(grh, position)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MapGrhEffectLoopOnce"/> class.
 /// </summary>
 /// <param name="grh">Grh to draw.</param>
 /// <param name="position">Position to draw on the map.</param>
 /// <param name="isForeground">If true, this will be drawn in the foreground layer. If false,
 /// it will be drawn in the background layer.</param>
 public MapGrhEffectLoopOnce(Grh grh, Vector2 position, bool isForeground) : base(grh, position, isForeground)
 {
 }
Example #39
0
        /// <summary>
        /// Reads the state of the object from an <see cref="IValueReader"/>. Values should be read in the exact
        /// same order as they were written.
        /// </summary>
        /// <param name="reader">The <see cref="IValueReader"/> to read the values from.</param>
        public void ReadState(IValueReader reader)
        {
            PositionProvider = null;
            Tag = null;

            Position = reader.ReadVector2(_positionValueKey);
            Size = reader.ReadVector2(_sizeValueKey);
            Color = reader.ReadColor(_colorValueKey);
            Rotation = reader.ReadFloat(_rotationValueKey);
            IsEnabled = reader.ReadBool(_isEnabledValueKey);

            var grhIndex = reader.ReadGrhIndex(_spriteValueKey);
            if (!grhIndex.IsInvalid)
                Sprite = new Grh(grhIndex, AnimType.Loop, 0);
            else
                Sprite = null;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExplosionRefractionEffect"/> class.
 /// </summary>
 /// <param name="explosionNoise">The sprite used to create the explosion's refraction map.</param>
 /// <param name="positionProvider">The <see cref="ISpatial"/> that provides the position of this
 /// <see cref="ExplosionRefractionEffect"/>.</param>
 /// <param name="lifeSpan">The life span in milliseconds. If 0, the <see cref="DefaultLifeSpan"/> will be used.</param>
 /// <param name="shader">The <see cref="Shader"/> to use to draw the explosion's refraction map. If null, the
 /// <see cref="ExplosionRefractionEffect.DefaultShader"/> will be used. If you provide your own shader, you must
 /// make sure that you either use the same effect parameters the default shader uses, or override this class
 /// so you can override the <see cref="ExplosionRefractionEffect.SetShaderParameters"/> method and set the parameters
 /// you require.</param>
 /// <exception cref="ArgumentNullException"><paramref name="explosionNoise"/> is null.</exception>
 /// <exception cref="NullReferenceException"><paramref name="positionProvider"/> is null.</exception>
 public ExplosionRefractionEffect(Grh explosionNoise, ISpatial positionProvider, ushort lifeSpan = (ushort)0,
                                  Shader shader = null) : this(explosionNoise, positionProvider.Center, lifeSpan, shader)
 {
     PositionProvider = positionProvider;
 }
Example #41
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WaterRefractionEffect"/> class.
        /// </summary>
        /// <param name="waveNoise">The sprite to use for the wave noise.</param>
        /// <param name="position">The initial world position of the effect.</param>
        /// <param name="size">The size of the effect in pixels.</param>
        /// <param name="shader">The <see cref="Shader"/> to use to draw the water's refraction map. If null, the
        /// <see cref="WaterRefractionEffect.DefaultShader"/> will be used. If you provide your own shader, you must
        /// make sure that you either use the same effect parameters the default shader uses, or override this class
        /// so you can override the <see cref="WaterRefractionEffect.SetShaderParameters"/> method and set the parameters
        /// you require.</param>
        /// <exception cref="ArgumentNullException"><paramref name="waveNoise"/> is null.</exception>
        public WaterRefractionEffect(Grh waveNoise, Vector2 position, Vector2 size, Shader shader = null)
        {
            if (waveNoise == null)
                throw new ArgumentNullException("waveNoise");

            _waveNoise = waveNoise;
            _position = position;
            _size = size;

            _shader = shader ?? DefaultShader;

            // Copy over the default values
            WaveIntensity = DefaultWaveIntensity;
            WaveSpeed = DefaultWaveSpeed;
            WaterAlpha = DefaultWaterAlpha;
            Magnification = DefaultMagnification;
            IsEnabled = true;

            // Ensure we are able to use the effect
            if (_shader == null)
            {
                const string errmsg =
                    "Shaders not supported or unable to acquire a valid default shader. Expiring effect `{0}`...";
                if (log.IsInfoEnabled)
                    log.InfoFormat(errmsg, this);
                Dispose();
            }
        }
Example #42
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WaterRefractionEffect"/> class.
 /// </summary>
 /// <param name="waveNoise">The sprite to use for the wave noise.</param>
 /// <param name="positionProvider">The <see cref="ISpatial"/> that will provide the positioning.</param>
 /// <param name="size">The size of the effect in pixels.</param>
 /// <param name="shader">The <see cref="Shader"/> to use to draw the water's refraction map. If null, the
 /// <see cref="WaterRefractionEffect.DefaultShader"/> will be used. If you provide your own shader, you must
 /// make sure that you either use the same effect parameters the default shader uses, or override this class
 /// so you can override the <see cref="WaterRefractionEffect.SetShaderParameters"/> method and set the parameters
 /// you require.</param>
 /// <exception cref="ArgumentNullException"><paramref name="waveNoise"/> is null.</exception>
 /// <exception cref="NullReferenceException"><paramref name="positionProvider"/> is null.</exception>
 public WaterRefractionEffect(Grh waveNoise, ISpatial positionProvider, Vector2 size, Shader shader = null)
     : this(waveNoise, positionProvider.Position, size, shader)
 {
     PositionProvider = positionProvider;
 }
Example #43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapGrhEffect"/> class.
 /// </summary>
 /// <param name="grh">Grh to draw.</param>
 /// <param name="position">Position to draw on the map.</param>
 /// <param name="isForeground">If true, this will be drawn in the foreground layer. If false,
 /// it will be drawn in the background layer.</param>
 protected MapGrhEffect(Grh grh, Vector2 position, bool isForeground) : base(grh, position, isForeground)
 {
 }
Example #44
0
 private void AddEntityGrh(ISpatial entity, Grh grh)
 {
     // Find the scaling value so we can position the entities correctly
     var scaleX = GamePlayScreen.Map.Size.X / ScaledMapGrh.Size.X;
     var scaleY = GamePlayScreen.Map.Size.Y / ScaledMapGrh.Size.Y;
     var scaledPos = new Vector2((entity.Position.X / scaleX) - grh.Size.X / 2, (entity.Position.Y / scaleY) - grh.Size.Y / 2);
     // Add the grh as well as the position
     _grhEntities.Add(new Tuple<Grh, Vector2>(new Grh(grh.GrhData), scaledPos));
 }
Example #45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapGrhEffectLoopOnce"/> class.
 /// </summary>
 /// <param name="grh">Grh to draw.</param>
 /// <param name="position">Position to draw on the map.</param>
 public MapGrhEffectLoopOnce(Grh grh, Vector2 position) : base(grh, position)
 {
 }
Example #46
0
            public SkillPictureBox(SkillsForm parent, SkillInfo<SkillType> skillInfo, Vector2 position)
                : base(parent, position, _iconSize)
            {
                _knownSkills = parent.KnownSkills;

                SkillInfo = skillInfo;
                Sprite = new Grh(GrhInfo.GetData(SkillInfo.Icon));
                _cooldownManager = parent.CooldownManager;
            }
Example #47
0
            /// <summary>
            /// Initializes a new instance of the <see cref="StatusEffectCollectionItem"/> class.
            /// </summary>
            /// <param name="statusEffectType">The <see cref="StatusEffectType"/> to use.</param>
            /// <param name="power">The power of the status effect.</param>
            /// <param name="disableTime">The game time at which this status effect will be disabled.</param>
            public StatusEffectCollectionItem(StatusEffectType statusEffectType, ushort power, int disableTime)
            {
                _statusEffectType = statusEffectType;
                _power = power;
                _disableTime = disableTime;

                _statusEffectInfo = StatusEffectInfoManager.Instance.GetAttribute(statusEffectType);
                _grh = new Grh(_statusEffectInfo.Icon);
            }
Example #48
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapGrhEffectTimed"/> class.
 /// </summary>
 /// <param name="grh">Grh to draw.</param>
 /// <param name="position">Position to draw on the map.</param>
 /// <param name="life">How long the effect will last in milliseconds.</param>
 public MapGrhEffectTimed(Grh grh, Vector2 position, int life) : base(grh, position)
 {
     _expireTime = (TickCount)(TickCount.Now + life);
 }
Example #49
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapGrhEffectLoopOnce"/> class.
 /// </summary>
 /// <param name="grh">Grh to draw.</param>
 /// <param name="position">Position to draw on the map.</param>
 /// <param name="isForeground">If true, this will be drawn in the foreground layer. If false,
 /// it will be drawn in the background layer.</param>
 public MapGrhEffectLoopOnce(Grh grh, Vector2 position, bool isForeground) : base(grh, position, isForeground)
 {
 }
Example #50
0
        public ItemEntity() : base(Vector2.Zero, Vector2.Zero)
        {
            Amount = 1;

            _grh = new Grh(null);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MapGrhEffectTimed"/> class.
 /// </summary>
 /// <param name="grh">Grh to draw.</param>
 /// <param name="position">Position to draw on the map.</param>
 /// <param name="isForeground">If true, this will be drawn in the foreground layer. If false,
 /// it will be drawn in the background layer.</param>
 /// <param name="life">How long the effect will last in milliseconds.</param>
 public MapGrhEffectTimed(Grh grh, Vector2 position, bool isForeground, int life) : base(grh, position, isForeground)
 {
     _expireTime = (TickCount)(TickCount.Now + life);
 }
Example #52
0
        /// <summary>
        /// Places a <see cref="MapGrh"/> on the map.
        /// </summary>
        /// <param name="map">The map to place the <see cref="MapGrh"/> on.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>.</param>
        /// <param name="screenPos">The screen position to place the <see cref="MapGrh"/>.</param>
        /// <param name="useTileMode">If TileMode should be used.</param>
        /// <param name="gd">The <see cref="GrhData"/> to place. Set to null to attempt to use the <see cref="GrhData"/> that is
        /// currently selected in the <see cref="GlobalState"/>.</param>
        /// <returns>The <see cref="MapGrh"/> instance that was added, or null if the the <see cref="MapGrh"/> could not be
        /// added for any reason.</returns>
        public static MapGrh PlaceMapGrh(Map map, ICamera2D camera, Vector2 screenPos, bool useTileMode, GrhData gd = null)
        {
            // Get the GrhData to place from the global state
            if (gd == null)
                gd = GlobalState.Instance.Map.GrhToPlace.GrhData;

            // Ensure we have a GrhData to place
            if (gd == null)
                return null;

            // Get the world position to place it
            var drawPos = camera.ToWorld(screenPos);
            drawPos = GridAligner.Instance.Align(drawPos, useTileMode).Round();

            // Cache some other values
            var selGrhGrhIndex = gd.GrhIndex;
            var isForeground = EditorSettings.Default.MapGrh_DefaultIsForeground;
            var depth = EditorSettings.Default.MapGrh_DefaultDepth;
            var drawPosArea = drawPos.ToRectangle(new Vector2(2), true);

            if (!useTileMode)
            {
                // Make sure the same MapGrh doesn't already exist at that position
                if (map.Spatial.Contains<MapGrh>(drawPosArea,
                    x =>
                    x.Grh.GrhData.GrhIndex == selGrhGrhIndex && x.IsForeground == isForeground &&
                    Math.Round(x.Position.QuickDistance(drawPos)) <= 1))
                    return null;
            }
            else
            {
                // Make sure the same MapGrh doesn't already exist at that position on the same layer
                if (map.Spatial.Contains<MapGrh>(drawPosArea,
                    x =>
                    x.Grh.GrhData.GrhIndex == selGrhGrhIndex && x.IsForeground == isForeground &&
                    Math.Round(x.Position.QuickDistance(drawPos)) <= 1))
                    return null;

                // In TileMode, do not allow ANY MapGrh at the same position and layer depth. And if it does exist, instead of aborting,
                // delete the existing one.
                var existingMapGrhs = map.Spatial.GetMany<MapGrh>(drawPosArea,
                    x =>
                    x.LayerDepth == depth && x.IsForeground == isForeground && Math.Round(x.Position.QuickDistance(drawPos)) <= 1);
                foreach (var toDelete in existingMapGrhs)
                {
                    Debug.Assert(toDelete != null);
                    if (log.IsDebugEnabled)
                        log.DebugFormat("TileMode caused MapGrh `{0}` to be overwritten.", toDelete);

                    map.RemoveMapGrh(toDelete);
                }

                Debug.Assert(
                    !map.Spatial.Contains<MapGrh>(drawPosArea,
                        x =>
                        x.LayerDepth == depth && x.IsForeground == isForeground &&
                        Math.Round(x.Position.QuickDistance(drawPos)) <= 1));
            }

            // Create the new MapGrh and add it to the map
            var g = new Grh(gd, AnimType.Loop, map.GetTime());
            var mg = new MapGrh(g, drawPos, isForeground) { LayerDepth = depth };
            map.AddMapGrh(mg);

            return mg;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExplosionRefractionEffect"/> class.
 /// </summary>
 /// <param name="explosionNoise">The sprite used to create the explosion's refraction map.</param>
 /// <param name="positionProvider">The <see cref="ISpatial"/> that provides the position of this
 /// <see cref="ExplosionRefractionEffect"/>.</param>
 /// <param name="lifeSpan">The life span in milliseconds. If 0, the <see cref="DefaultLifeSpan"/> will be used.</param>
 /// <param name="shader">The <see cref="Shader"/> to use to draw the explosion's refraction map. If null, the
 /// <see cref="ExplosionRefractionEffect.DefaultShader"/> will be used. If you provide your own shader, you must
 /// make sure that you either use the same effect parameters the default shader uses, or override this class
 /// so you can override the <see cref="ExplosionRefractionEffect.SetShaderParameters"/> method and set the parameters
 /// you require.</param>
 /// <exception cref="ArgumentNullException"><paramref name="explosionNoise"/> is null.</exception>
 /// <exception cref="NullReferenceException"><paramref name="positionProvider"/> is null.</exception>
 public ExplosionRefractionEffect(Grh explosionNoise, ISpatial positionProvider, ushort lifeSpan = (ushort)0,
                                  Shader shader = null) : this(explosionNoise, positionProvider.Center, lifeSpan, shader)
 {
     PositionProvider = positionProvider;
 }