public static void ServerExplode(
            [CanBeNull] ICharacter character,
            [CanBeNull] IProtoObjectExplosive protoObjectExplosive,
            ExplosionPreset explosionPreset,
            Vector2D epicenterPosition,
            DamageDescription damageDescriptionCharacters,
            IPhysicsSpace physicsSpace,
            ExecuteExplosionDelegate executeExplosionCallback)
        {
            ValidateIsServer();

            // schedule explosion charred ground spawning
            ServerTimersSystem.AddAction(
                // the delay is quite small and just needed to ensure
                // that the charred ground spawned some time after this object is destroyed
                delaySeconds: explosionPreset.SpriteAnimationDuration * 0.5,
                () =>
            {
                var tilePosition = (Vector2Ushort)epicenterPosition;
                if (!Server.World.GetTile(tilePosition)
                    .StaticObjects
                    .Any(so => so.ProtoStaticWorldObject is ObjectCharredGround))
                {
                    // spawn charred ground
                    var objectCharredGround =
                        Server.World.CreateStaticWorldObject <ObjectCharredGround>(tilePosition);
                    var objectCharredGroundOffset = epicenterPosition - tilePosition.ToVector2D();
                    if (objectCharredGroundOffset != Vector2D.Zero)
                    {
                        ObjectCharredGround.ServerSetWorldOffset(objectCharredGround,
                                                                 objectCharredGroundOffset.ToVector2F());
                    }
                }
            });

            // schedule explosion damage
            ServerTimersSystem.AddAction(
                delaySeconds: explosionPreset.ServerDamageApplyDelay,
                () =>
            {
                // prepare weapon caches
                var characterFinalStatsCache = character != null
                                                       ? character.SharedGetFinalStatsCache()
                                                       : FinalStatsCache.Empty;

                var weaponFinalCache = new WeaponFinalCache(character,
                                                            characterFinalStatsCache,
                                                            weapon: null,
                                                            protoWeapon: null,
                                                            protoObjectExplosive: protoObjectExplosive,
                                                            damageDescription: damageDescriptionCharacters);

                // execute explosion
                executeExplosionCallback(
                    positionEpicenter: epicenterPosition,
                    physicsSpace: physicsSpace,
                    weaponFinalCache: weaponFinalCache);
            });
        }
Esempio n. 2
0
        public static void ServerExplode(
            [CanBeNull] ICharacter character,
            [CanBeNull] IProtoObjectExplosive protoObjectExplosive,
            ExplosionPreset explosionPreset,
            Vector2D epicenterPosition,
            DamageDescription damageDescriptionCharacters,
            IPhysicsSpace physicsSpace,
            ExecuteExplosionDelegate executeExplosionCallback)
        {
            ValidateIsServer();

            // schedule explosion charred ground spawning
            ServerTimersSystem.AddAction(
                delaySeconds: explosionPreset.SpriteAnimationDuration * 0.5,
                () =>
            {
                var tilePosition = (Vector2Ushort)epicenterPosition;

                // remove existing charred ground objects at the same tile
                foreach (var staticWorldObject in Shared.WrapInTempList(
                             Server.World.GetTile(tilePosition).StaticObjects))
                {
                    if (staticWorldObject.ProtoStaticWorldObject is ObjectCharredGround)
                    {
                        Server.World.DestroyObject(staticWorldObject);
                    }
                }

                // spawn charred ground
                var objectCharredGround = Server.World
                                          .CreateStaticWorldObject <ObjectCharredGround>(tilePosition);
                var objectCharredGroundOffset = epicenterPosition - tilePosition.ToVector2D();
                if (objectCharredGroundOffset != Vector2D.Zero)
                {
                    ObjectCharredGround.ServerSetWorldOffset(objectCharredGround,
                                                             (Vector2F)objectCharredGroundOffset);
                }
            });

            // schedule explosion damage
            ServerTimersSystem.AddAction(
                delaySeconds: explosionPreset.ServerDamageApplyDelay,
                () =>
            {
                // prepare weapon caches
                var characterFinalStatsCache = character?.SharedGetFinalStatsCache()
                                               ?? FinalStatsCache.Empty;

                var weaponFinalCache = new WeaponFinalCache(character,
                                                            characterFinalStatsCache,
                                                            weapon: null,
                                                            protoWeapon: null,
                                                            protoObjectExplosive: protoObjectExplosive,
                                                            damageDescription: damageDescriptionCharacters);

                // execute explosion
                executeExplosionCallback(
                    positionEpicenter: epicenterPosition,
                    physicsSpace: physicsSpace,
                    weaponFinalCache: weaponFinalCache);
            });
        }