Ejemplo n.º 1
0
        public static void AD_SkillCasted(ActionDisplay actionDisplay, IMap map, Entity source, Entity target)
        {
            var drawableMap = map as IDrawableMap;

            // Play the sound
            PlaySoundSimple(actionDisplay, source);

            // Check if we can properly display the effect
            if (drawableMap != null && source != null)
            {
                if (actionDisplay.GrhIndex != GrhIndex.Invalid)
                {
                    if (target != null && target != source)
                    {
                        // Show the graphic going from the source to target
                        var gd = GrhInfo.GetData(actionDisplay.GrhIndex);
                        if (gd != null)
                        {
                            var grh = new Grh(gd, AnimType.Loop, TickCount.Now);
                            var effect = new MapGrhEffectSeekPosition(grh, source.Center, target.Center, 750f) { MapRenderLayer = MapRenderLayer.SpriteForeground };
                            drawableMap.AddTemporaryMapEffect(effect);
                        }
                    }
                    else
                    {
                        // Show the graphic at the source
                        var gd = GrhInfo.GetData(actionDisplay.GrhIndex);
                        if (gd != null)
                        {
                            var grh = new Grh(gd, AnimType.Loop, TickCount.Now);
                            var effect = new MapGrhEffectLoopOnce(grh, source.Center) { MapRenderLayer = MapRenderLayer.SpriteForeground };
                            drawableMap.AddTemporaryMapEffect(effect);
                        }
                    }
                }

                // Show the particle effect
                var pe = ParticleEffectManager.Instance.TryCreateEffect(actionDisplay.ParticleEffect);
                if (pe != null)
                {
                    pe.Position = source.Center;
                    ITemporaryMapEffect effect;

                    if (target != null && target != source)
                    {
                        // Effect that seeks out the position of the target
                        effect = new TemporaryMapParticleEffectSeekPosition(pe, target.Center, 250f) { MapRenderLayer = MapRenderLayer.SpriteForeground };
                    }
                    else
                    {
                        // Effect that takes place at the source
                        effect = new TemporaryMapParticleEffect(pe) { MapRenderLayer = MapRenderLayer.SpriteForeground };
                    }

                    // Add the effect to the map
                    if (effect != null)
                        drawableMap.AddTemporaryMapEffect(effect);
                }
            }
        }
Ejemplo n.º 2
0
        public static void AD_CastingSkill(ActionDisplay actionDisplay, IMap map, Entity source, Entity target)
        {
            // The maximum life the effects will have. This way, if the entity gets stuck with IsCastingSkill set to true,
            // the effects will at least go away eventually. Make sure that this is not greater than the longest possible
            // time to cast a skill.
            const int maxEffectLife = 1000 * 20;

            var drawableMap = map as IDrawableMap;
            var sourceAsCharacter = source as Character;

            var castingEffects = new List<ITemporaryMapEffect>();

            // Make sure we have a valid source
            if (sourceAsCharacter == null)
            {
                const string errmsg = "AD_CastingSkill requires a Character as the source, but the source ({0}) is type `{1}`.";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, source, source.GetType());
                Debug.Fail(string.Format(errmsg, source, source.GetType()));
                return;
            }

            // Play the sound
            PlaySoundSimple(actionDisplay, source);

            // Check if we can properly display the effect
            if (drawableMap != null)
            {
                // Show the graphic going from the source to target
                if (actionDisplay.GrhIndex != GrhIndex.Invalid)
                {
                    var gd = GrhInfo.GetData(actionDisplay.GrhIndex);
                    if (gd != null)
                    {
                        // Make the effect loop indefinitely
                        var grh = new Grh(gd, AnimType.Loop, TickCount.Now);
                        var effect = new MapGrhEffectTimed(grh, source.Center, maxEffectLife) { MapRenderLayer = MapRenderLayer.SpriteForeground };
                        drawableMap.AddTemporaryMapEffect(effect);
                        castingEffects.Add(effect);
                    }
                }

                // Show the particle effect
                var pe = ParticleEffectManager.Instance.TryCreateEffect(actionDisplay.ParticleEffect);
                if (pe != null)
                {
                    // Effect that just takes place on the caster
                    pe.Position = source.Center;
                    pe.Life = maxEffectLife;
                    var effect = new TemporaryMapParticleEffect(pe) { MapRenderLayer = MapRenderLayer.SpriteForeground };
                    drawableMap.AddTemporaryMapEffect(effect);
                    castingEffects.Add(effect);
                }
            }

            // Make sure we have at least one valid effect. If not, there is nothing more to do.
            if (castingEffects.Count <= 0)
                return;

            // Add the list of effects to our local dictionary
            lock (_activeCastingSkillEffectsSync)
            {
                // Make sure they don't already have effects in the dictionary
                RemoveFromActiveCastingSkillEffects(sourceAsCharacter);

                // Add to the dictionary
                _activeCastingSkillEffects.Add(sourceAsCharacter, castingEffects);
            }

            // Attach the listener for the IsCastingSkill
            sourceAsCharacter.IsCastingSkillChanged += AD_CastingSkill_Character_IsCastingSkillChanged;

            // If the source already finished casting the skill, destroy them now since we probably missed the event
            if (!sourceAsCharacter.IsCastingSkill)
                RemoveFromActiveCastingSkillEffects(sourceAsCharacter);
        }
Ejemplo n.º 3
0
        public static void AD_Projectile(ActionDisplay actionDisplay, IMap map, Entity source, Entity target)
        {
            var drawableMap = map as IDrawableMap;
            var sourceAsCharacter = source as Character;

            // Play the sound
            PlaySoundSimple(actionDisplay, source);

            // Show the attack animation on the attacker
            if (sourceAsCharacter != null)
                sourceAsCharacter.Attack();

            // Check if we can properly display the effect
            if (drawableMap != null && target != null && source != target)
            {
                // Show the graphic going from the attacker to attacked
                if (actionDisplay.GrhIndex != GrhIndex.Invalid)
                {
                    var gd = GrhInfo.GetData(actionDisplay.GrhIndex);
                    if (gd != null)
                    {
                        var grh = new Grh(gd, AnimType.Loop, TickCount.Now);
                        var effect = new MapGrhEffectSeekPosition(grh, source.Center, target.Center, 750f) { MapRenderLayer = MapRenderLayer.SpriteForeground };
                        drawableMap.AddTemporaryMapEffect(effect);
                    }
                }

                // Show the particle effect
                var pe = ParticleEffectManager.Instance.TryCreateEffect(actionDisplay.ParticleEffect);
                if (pe != null)
                {
                    // Effect that just takes place on the target and dies very quickly
                    pe.Position = target.Center;
                    pe.Life = 100;
                    var effect = new TemporaryMapParticleEffect(pe) { MapRenderLayer = MapRenderLayer.SpriteForeground };
                    drawableMap.AddTemporaryMapEffect(effect);
                }
            }
        }