Beispiel #1
0
        /// <summary>
        /// Starts an animation for a DependencyProperty. The animation will
        /// begin when the next frame is rendered.
        /// </summary>
        /// <param name="dp">
        /// The DependencyProperty to animate.
        /// </param>
        /// <param name="animation">
        /// <para>The AnimationTimeline to used to animate the property.</para>
        /// <para>If the AnimationTimeline's BeginTime is null, any current animations
        /// will be removed and the current value of the property will be held.</para>
        /// <para>If this value is null, all animations will be removed from the property
        /// and the property value will revert back to its base value.</para>
        /// </param>
        /// <param name="handoffBehavior">
        /// Specifies how the new animation should interact with any current
        /// animations already affecting the property value.
        /// </param>
        public void BeginAnimation(DependencyProperty dp, AnimationTimeline animation, HandoffBehavior handoffBehavior)
        {
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }

            if (!AnimationStorage.IsPropertyAnimatable(this, dp))
            {
        #pragma warning disable 56506 // Suppress presharp warning: Parameter 'dp' to this public method must be validated:  A null-dereference can occur here.
                throw new ArgumentException(SR.Get(SRID.Animation_DependencyPropertyIsNotAnimatable, dp.Name, this.GetType()), "dp");
        #pragma warning restore 56506
            }

            if (animation != null &&
                !AnimationStorage.IsAnimationValid(dp, animation))
            {
                throw new ArgumentException(SR.Get(SRID.Animation_AnimationTimelineTypeMismatch, animation.GetType(), dp.Name, dp.PropertyType), "animation");
            }

            if (!HandoffBehaviorEnum.IsDefined(handoffBehavior))
            {
                throw new ArgumentException(SR.Get(SRID.Animation_UnrecognizedHandoffBehavior));
            }

            if (IsSealed)
            {
                throw new InvalidOperationException(SR.Get(SRID.IAnimatable_CantAnimateSealedDO, dp, this.GetType()));
            }

            AnimationStorage.BeginAnimation(this, dp, animation, handoffBehavior);
        }
Beispiel #2
0
        public void Act()
        {
            if (AI == null)
            {
                return;
            }

            (string actionName, NpcAction actionType) = AI.GetAction(this);

            Animation       = AnimationStorage.GetSequenceIdBySequenceName(Model, actionName);
            CurrentAction   = actionType;
            CurrentMovement = AI.GetMovementAction(this);

            switch (CurrentAction)
            {
            case NpcAction.Idle:
                Move(MobMovement.Hold);     // temp, maybe remove the option to specify movement in AI
                break;

            case NpcAction.Bore:
                Move(MobMovement.Hold);     // temp, maybe remove the option to specify movement in AI
                break;

            case NpcAction.Walk:
                Move(CurrentMovement);
                break;

            case NpcAction.Jump:
            default:
                break;
            }
        }
Beispiel #3
0
 public Mob(int objectId, NpcMetadata metadata) : base(objectId, metadata)
 {
     Animation = AnimationStorage.GetSequenceIdBySequenceName(metadata.Model, "Idle_A");
     AI        = MobAIManager.GetAI(metadata.AiInfo);
     Stats     = new(metadata);
     State     = NpcState.Normal;
 }
Beispiel #4
0
        public override void Perish()
        {
            IsDead = true;
            State  = NpcState.Dead;
            int randAnim = RandomProvider.Get().Next(Value.StateActions[NpcState.Dead].Length);

            Animation = AnimationStorage.GetSequenceIdBySequenceName(Value.Model, Value.StateActions[NpcState.Dead][randAnim].Item1);
        }
Beispiel #5
0
        public Mob(int id)
        {
            NpcMetadata mob = NpcMetadataStorage.GetNpcMetadata(id);

            if (mob != null)
            {
                Id         = mob.Id;
                Animation  = AnimationStorage.GetSequenceIdBySequenceName(mob.Model, "Walk_A"); //Walking animation as default
                Stats      = mob.Stats;
                Experience = mob.Experience;
                Friendly   = mob.Friendly;
            }
        }
Beispiel #6
0
        /// <summary>
        ///     Allows subclasses to participate in property animated value computation
        /// </summary>
        /// <param name="dp"></param>
        /// <param name="metadata"></param>
        /// <param name="entry">EffectiveValueEntry computed by base</param>
        internal sealed override void EvaluateAnimatedValueCore(
            DependencyProperty dp,
            PropertyMetadata metadata,
            ref EffectiveValueEntry entry)
        {
            if (IAnimatable_HasAnimatedProperties)
            {
                AnimationStorage storage = AnimationStorage.GetStorage(this, dp);

                if (storage != null)
                {
                    storage.EvaluateAnimatedValue(metadata, ref entry);
                }
            }
        }
Beispiel #7
0
        public void Act()
        {
            if (AI == null)
            {
                return;
            }

            (string actionName, NpcAction actionType) = AI.GetAction(this);

            if (actionName != null)
            {
                Animation = AnimationStorage.GetSequenceIdBySequenceName(Value.Model, actionName);
            }

            Action   = actionType;
            Movement = AI.GetMovementAction(this);

            switch (Action)
            {
            case NpcAction.Idle:
            case NpcAction.Bore:
                Move(MobMovement.Hold);     // temp, maybe remove the option to specify movement in AI
                break;

            case NpcAction.Walk:
            case NpcAction.Run:
                Move(Movement);
                break;

            case NpcAction.Skill:
                // Cast skill
                if (!OnCooldown)
                {
                    Attack();
                    Move(MobMovement.Hold);
                    break;
                }

                Move(Movement);
                break;

            case NpcAction.Jump:
            default:
                break;
            }
        }
Beispiel #8
0
        public Mob(int id)
        {
            NpcMetadata mob = NpcMetadataStorage.GetNpcMetadata(id);

            if (mob != null)
            {
                Id           = mob.Id;
                Model        = mob.Model;
                Animation    = AnimationStorage.GetSequenceIdBySequenceName(Model, "Idle_A");
                StateActions = mob.StateActions;
                MoveRange    = mob.MoveRange;
                Stats        = mob.Stats;
                Experience   = mob.Experience;
                Friendly     = mob.Friendly;
                AI           = MobAIManager.GetAI(mob.AiInfo);
                State        = NpcState.Normal;
            }
        }
Beispiel #9
0
    public void CreateMonster(int[] spawnPointIds, bool spawnAnimation, int arg3)
    {
        foreach (int spawnPointId in spawnPointIds)
        {
            MapEventNpcSpawnPoint spawnPoint = MapEntityMetadataStorage.GetMapEventNpcSpawnPoint(Field.MapId, spawnPointId);
            if (spawnPoint is null)
            {
                continue;
            }

            for (int i = 0; i < spawnPoint.Count; i++)
            {
                foreach (string npcId in spawnPoint.NpcIds)
                {
                    if (!int.TryParse(npcId, out int id))
                    {
                        continue;
                    }

                    short animation = -1;
                    if (spawnAnimation)
                    {
                        NpcMetadata npcMetadata = NpcMetadataStorage.GetNpcMetadata(id);
                        if (npcMetadata is null || !npcMetadata.StateActions.TryGetValue(NpcState.Normal, out (string, NpcAction, short)[] stateAction))
                        {
                            continue;
                        }

                        if (stateAction.Length == 0)
                        {
                            continue;
                        }

                        animation = AnimationStorage.GetSequenceIdBySequenceName(npcMetadata.NpcMetadataModel.Model, stateAction[0].Item1);
                    }

                    Npc npc = Field.RequestNpc(id, spawnPoint.Position, spawnPoint.Rotation, animation);
                    npc.SpawnPointId = spawnPointId;
                }
            }
        }
    }
Beispiel #10
0
        /// <summary>
        /// Calls methods on the DrawingContext that are equivalent to the
        /// Drawing with the Drawing's current value.
        /// </summary>
        internal override void WalkCurrentValue(DrawingContextWalker ctx)
        {
            int popCount = 0;

            // We avoid unneccessary ShouldStopWalking checks based on assumptions
            // about when ShouldStopWalking is set.  Guard that assumption with an
            // assertion.
            //
            // ShouldStopWalking is currently only set during a hit-test walk after
            // an object has been hit.  Because a DrawingGroup can't be hit until after
            // the first Drawing is tested, this method doesn't check ShouldStopWalking
            // until after the first child.
            //
            // We don't need to add this check to other Drawing subclasses for
            // the same reason -- if the Drawing being tested isn't a DrawingGroup,
            // they are always the 'first child'.
            //
            // If this assumption is ever broken then the ShouldStopWalking
            // check should be done on the first child -- including in the
            // WalkCurrentValue method of other Drawing subclasses.
            Debug.Assert(!ctx.ShouldStopWalking);

            //
            // Draw the transform property
            //

            // Avoid calling PushTransform if the base value is set to the default and
            // no animations have been set on the property.
            if (!IsBaseValueDefault(DrawingGroup.TransformProperty) ||
                (null != AnimationStorage.GetStorage(this, DrawingGroup.TransformProperty)))
            {
                ctx.PushTransform(Transform);

                popCount++;
            }

            //
            // Draw the clip property
            //

            // Avoid calling PushClip if the base value is set to the default and
            // no animations have been set on the property.
            if (!IsBaseValueDefault(DrawingGroup.ClipGeometryProperty) ||
                (null != AnimationStorage.GetStorage(this, DrawingGroup.ClipGeometryProperty)))
            {
                ctx.PushClip(ClipGeometry);

                popCount++;
            }

            //
            // Draw the opacity property
            //

            // Avoid calling PushOpacity if the base value is set to the default and
            // no animations have been set on the property.
            if (!IsBaseValueDefault(DrawingGroup.OpacityProperty) ||
                (null != AnimationStorage.GetStorage(this, DrawingGroup.OpacityProperty)))
            {
                // Push the current value of the opacity property, which
                // is what Opacity returns.
                ctx.PushOpacity(Opacity);

                popCount++;
            }

            // Draw the opacity mask property
            //
            if (OpacityMask != null)
            {
                ctx.PushOpacityMask(OpacityMask);
                popCount++;
            }

            //
            // Draw the effect property
            //

            // Push the current value of the effect property, which
            // is what BitmapEffect returns.
            if (BitmapEffect != null)
            {
                // Disable warning about obsolete method.  This code must remain active
                // until we can remove the public BitmapEffect APIs.
                #pragma warning disable 0618
                ctx.PushEffect(BitmapEffect, BitmapEffectInput);
                #pragma warning restore 0618
                popCount++;
            }

            //
            // Draw the Children collection
            //

            // Get the current value of the children collection
            DrawingCollection collection = Children;

            // Call Walk on each child
            if (collection != null)
            {
                for (int i = 0; i < collection.Count; i++)
                {
                    Drawing drawing = collection.Internal_GetItem(i);
                    if (drawing != null)
                    {
                        drawing.WalkCurrentValue(ctx);

                        // Don't visit the remaining children if the previous
                        // child caused us to stop walking.
                        if (ctx.ShouldStopWalking)
                        {
                            break;
                        }
                    }
                }
            }

            //
            // Call Pop() for every Push
            //
            // Avoid placing this logic in a finally block because if an exception is
            // thrown, the Walk is simply aborted.  There is no requirement to Walk
            // through Pop instructions when an exception is thrown.
            //

            for (int i = 0; i < popCount; i++)
            {
                ctx.Pop();
            }
        }