/// Creates and returns a deep clone of this component
        public object clone()
        {
            AbilityComponent        copy     = MemberwiseClone() as AbilityComponent;
            List <AbilityComponent> children = new List <AbilityComponent>();

            if (AnimationAsset != null)
            {
                copy.AnimationAsset =
                    AnimationAsset.clone() as GameAsset <SpriteAnimation>;
            }

            if (ProjectileAsset != null)
            {
                copy.ProjectileAsset =
                    ProjectileAsset.clone() as GameAsset <Projectile>;
            }

            if (EffectAsset != null)
            {
                copy.EffectAsset =
                    EffectAsset.clone() as GameAsset <AbilityEffect>;
            }

            AbilityComponent child;

            Children.ForEach(orig => {
                child        = orig.clone() as AbilityComponent;
                child.Parent = copy;
                children.Add(child);
            });

            copy.Children = children;
            return(copy);
        }
Beispiel #2
0
        /// Helper for getting target spots traversing
        /// recursivly through the components
        private void getTargets(AbilityComponent component, List <Point> targets)
        {
            AbilityComponent comp = component;
            Point            pos  = Point.Zero;

            while (comp != null)
            {
                pos += comp.Position;
                comp = comp.Parent;
            }

            targets.Add(pos);
            component.Children.ForEach(c => getTargets(c, targets));
        }
        /// Updates this components animation and projectile
        /// as well as its children
        public void update(GameTime gameTime)
        {
            if (!IsExecuting)
            {
                return;
            }
            timer += gameTime.ElapsedGameTime.Milliseconds;
            if (timer < TimeOffset)
            {
                return;
            }

            if (Animation != null && animationReady)
            {
                animationReady = false;
                Ability.User.ContainingMap.addAnimation(animation, true);
            }

            if (Projectile != null && projectileReady)
            {
                Ability.User.ContainingMap.addEntity(projectile);
                projectileReady = false;
                projectile.shoot();
            }

            int i;

            for (i = waitList.Count - 1; i >= 0; --i)
            {
                AbilityComponent child = waitList[i];

                if (framer >= child.FrameOffset)
                {
                    child.execute();
                    waitList.RemoveAt(i);
                    activeList.Add(child);
                }
            }

            for (i = activeList.Count - 1; i >= 0; --i)
            {
                AbilityComponent child = activeList[i];
                if (child.IsExecuting)
                {
                    child.update(gameTime);
                }
                else
                {
                    activeList.RemoveAt(i);
                }
            }

            if (Animation != null)
            {
                framer = animation.CurrentFrame;
            }

            if (waitList.Count == 0 && activeList.Count == 0 &&
                (Animation == null || !animation.IsRunning) &&
                (Projectile == null || projectile.ContainingMap == null))
            {
                IsExecuting = false;
                // TODO stop user animation ?
            }
        }