Exemplo n.º 1
0
        public void OnEntityDied(EntityDied message)
        {
            var entity = message.KilledEntity;

            // Play explosion effect at point of death.
            var particleSystem =
                (CameraCenteredParticleEffectSystem)Manager.GetSystem(ParticleEffectSystem.TypeId);

            if (particleSystem != null)
            {
                particleSystem.Play("Effects/BasicExplosion", entity);
            }
            var soundSystem = (CameraCenteredSoundSystem)Manager.GetSystem(SoundSystem.TypeId);

            if (soundSystem != null)
            {
                soundSystem.Play("Explosion", entity);
            }

            // See if the entity respawns.
            var respawn = ((Respawn)Manager.GetComponent(entity, Respawn.TypeId));

            if (respawn == null)
            {
                // Entity does not respawn, remove it. This can be triggered from
                // a parallel system (e.g. collisions), so we remember to remove it.
                lock (_entitiesToRemove)
                {
                    _entitiesToRemove.Add(entity);
                }
            }
        }
Exemplo n.º 2
0
        public void OnEntityDied(EntityDied message)
        {
            var entity = message.KilledEntity;

            // See if the entity respawns.
            var respawn = ((Respawn)Manager.GetComponent(entity, Respawn.TypeId));

            if (respawn == null)
            {
                return;
            }

            // Entity does respawn, disable components and wait.
            foreach (var componentType in respawn.ComponentsToDisable)
            {
                Manager.GetComponent(entity, componentType).Enabled = false;
            }
            respawn.TimeToRespawn = respawn.Delay;

            // Remove any remaining damage debuffs.
            foreach (var dot in Manager.GetComponents(entity, DamagingStatusEffect.TypeId).ToList())
            {
                Manager.RemoveComponent(dot);
            }

            // Stop the entity, to avoid zooming off to nowhere when
            // killed by a sun, e.g.
            var velocity = ((Velocity)Manager.GetComponent(entity, Velocity.TypeId));

            if (velocity != null)
            {
                velocity.LinearVelocity = Vector2.Zero;
            }
        }
Exemplo n.º 3
0
 public void OnEntityDied(EntityDied message)
 {
     foreach (var ai in Components)
     {
         ai.OnEntityInvalidated(message.KilledEntity);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Invokes the EntityDied event
        /// </summary>
        /// <param name="args">The event args</param>
        protected virtual void OnDeath(CacheObjectEventArgs args)
        {
            var handler = EntityDied;

            if (handler != null)
            {
                EntityDied.Invoke(this, args);
            }
        }
Exemplo n.º 5
0
        public void OnEntityDied(EntityDied message)
        {
            var entity = message.KilledEntity;

            var drops = ((Drops)Manager.GetComponent(entity, Drops.TypeId));

            if (drops != null)
            {
                var translation = ((ITransform)Manager.GetComponent(entity, TransformTypeId)).Position;
                Drop(drops.ItemPool, ref translation);
            }
        }
Exemplo n.º 6
0
 public void TriggerEntityDied(DeathEventData data)
 {
     EntityDied?.Invoke(data);
 }
Exemplo n.º 7
0
        public void OnEntityDied(EntityDied message)
        {
            // See if the entity that died gives XP.
            var xp = (ExperiencePoints)Manager.GetComponent(message.KilledEntity, ExperiencePoints.TypeId);

            if (xp == null)
            {
                return;
            }

            // Get number of players in the game to scale the received XP.
            var avatars = (AvatarSystem)Manager.GetSystem(AvatarSystem.TypeId);

            Debug.Assert(avatars != null);
            var actualXp = (int)(xp.Value * (1f + (avatars.Count - 1) * 0.05f));

            // Figure out whom to attribute the main share of the experience to.
            var        killer     = message.KillingEntity;
            Experience experience = null;

            while (killer > 0)
            {
                // Try to get experience tracking component.
                experience = (Experience)Manager.GetComponent(killer, Experience.TypeId);
                if (experience != null)
                {
                    // Got it, stop right here. Attribute the full XP.
                    experience.Value += actualXp;
                    break;
                }

                // Try to get parent.
                var owner = (Owner)Manager.GetComponent(killer, Owner.TypeId);
                if (owner != null)
                {
                    // Got a parent, try that one.
                    killer = owner.Value;
                }
                else
                {
                    // No parent, give up.
                    break;
                }
            }

            // Get position of the killed entity.
            var killedPosition = (ITransform)Manager.GetComponent(message.KilledEntity, TransformTypeId);

            Debug.Assert(killedPosition != null);

            // 50% of XP for others, if object died via environment or was
            // killed by some NPC, 90% if killed by other player.
            actualXp = (int)(actualXp * ((experience != null) ? 0.9f : 0.5f));

            // Cell size for player caused deaths, much lower for environment
            // kills (so player won't level up all the time just because two factions
            // battle it out!)
            var range = (experience != null) ? (CellSystem.CellSize / 2) : 1500f;

            // Give XP to all other players in the game.
            foreach (var avatar in avatars.Avatars)
            {
                // Skip the killer as he already got his xp.
                if (avatar == killer)
                {
                    continue;
                }

                // See how far away the player is.
                var transform = (ITransform)Manager.GetComponent(avatar, TransformTypeId);
                if (transform == null)
                {
                    // Skip him if we cannot determine his position.
                    continue;
                }

                // Limit to one system size (radius: cell size / 2).
                var distance = FarPosition.Distance(transform.Position, killedPosition.Position);
                if (distance > range)
                {
                    // Too far away, this one gets nothing.
                    continue;
                }

                // Looking good, attribute slightly reduced amount of XP.
                var otherExperience = (Experience)Manager.GetComponent(avatar, Experience.TypeId);
                if (otherExperience != null)
                {
                    otherExperience.Value += actualXp;
                }
            }
        }