Ejemplo n.º 1
0
        private void ExplodeOnLand()
        {
            SpawnExplosionParticles();

            if (sidedAPI.Side == EnumAppSide.Server)
            {
                this.entity.World.PlaySoundAt(new AssetLocation("meteoricexpansion", "sounds/effect/land_meteor_explosion_layered"), this.entity, null, true, 512, 1.0f);

                Vec3d previousPos = this.entity.PreviousServerPos.XYZ;
                Vec3d currentPos  = this.entity.ServerPos.XYZ;

                Vec3d meteorDirection   = (currentPos - previousPos).Normalize();
                Vec3d shrapnelDirection = MeteoricExpansionHelpers.InvertVector(meteorDirection);


                if (MeteoricExpansionHelpers.GetConfigDestructive() == true)
                {
                    CreateCrater(meteorDirection, shrapnelDirection);
                    InjureEntities(currentPos);
                }

                //-- The meteor has a chance to 'break apart' on impact and throw out its own drops on impact, amount based on its size --//
                foreach (BlockDropItemStack itemStack in entity.Properties.Drops)
                {
                    for (int i = 0; i < (int)(entity.Properties.Client.Size * explosionRand.Next(minMeteorDrops, maxMeteorDrops)); i++)
                    {
                        entity.World.SpawnItemEntity(itemStack.GetNextItemStack(), entity.ServerPos.XYZ, GetNewItemStackVector(shrapnelDirection, itemStackVelocityModifier));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void ExplodeOnLand()
        {
            if (sidedAPI.Side == EnumAppSide.Server)
            {
                this.entity.World.PlaySoundAt(new AssetLocation("meteoricexpansion", "sounds/effect/land_meteor_explosion_layered"), this.entity, null, true, 512, 1.0f);

                //-- entity.PreviousServerPos is never set in VS 1.17 for some reason! Therefore, the direction vector is stored in an attribute on the entity and used instead of calculating it from currentPos - previousPos --//

                Vec3d currentPos = this.entity.ServerPos.XYZ;

                Vec3i meteorDirectionInt = entity.Attributes.GetVec3i("direction", Vec3i.Zero);
                Vec3d meteorDirection    = new Vec3d(meteorDirectionInt.X, meteorDirectionInt.Y, meteorDirectionInt.Z).Normalize();

                Vec3d shrapnelDirection = MeteoricExpansionHelpers.InvertVector(meteorDirection);

                if (serverAPI.World.Config.GetBool("Destructive") == true)
                {
                    CreateCrater(meteorDirection, shrapnelDirection);
                    InjureEntities(currentPos);
                }

                //-- The meteor has a chance to 'break apart' on impact and throw out its own drops on impact, amount based on its size --//
                foreach (BlockDropItemStack itemStack in entity.Properties.Drops)
                {
                    for (int i = 0; i < (int)(entity.Properties.Client.Size * explosionRand.Next(minMeteorDrops, maxMeteorDrops)); i++)
                    {
                        entity.World.SpawnItemEntity(itemStack.GetNextItemStack(), entity.ServerPos.XYZ, GetNewItemStackVector(shrapnelDirection, itemStackVelocityModifier));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void InitializeSpawner()
        {
            spawnerRand    = new Random(serverAPI.World.Seed);
            timeSinceSpawn = serverAPI.World.ElapsedMilliseconds;

            minMeteorSpawnTime = MeteoricExpansionHelpers.GetMinSpawnTime();
            maxMeteorSpawnTime = MeteoricExpansionHelpers.GetMaxSpawnTime();

            nextMeteorSpawn = spawnerRand.Next(minMeteorSpawnTime, maxMeteorSpawnTime) + spawnerRand.NextDouble();
            nextMeteorSpawn = MeteoricExpansionHelpers.ConvertMinutesToMilliseconds(nextMeteorSpawn);
        }
Ejemplo n.º 4
0
        public override void StartServerSide(ICoreServerAPI api)
        {
            base.StartServerSide(api);
            serverAPI = api;

            MeteoricExpansionHelpers.ReadConfig(api);
            InitializeSpawner();

            api.Event.RegisterGameTickListener(onSpawnerTick, spawnerTickIntervalInMilliseconds);
            firstTickListener = api.Event.RegisterGameTickListener(onFirstTick, 1);
        }
Ejemplo n.º 5
0
        private void ExplodeInAir()
        {
            SpawnExplosionParticles();

            if (sidedAPI.Side == EnumAppSide.Server)
            {
                this.entity.World.PlaySoundAt(new AssetLocation("meteoricexpansion", "sounds/effect/air_meteor_explosion_layered"), this.entity, null, true, 512, 1.0f);

                if (MeteoricExpansionHelpers.GetConfigDestructive() == true)
                {
                    InjureEntities(this.entity.ServerPos.XYZ);
                }
            }
        }
Ejemplo n.º 6
0
        //-- Offsets meteor spawn position so that it does not spawn directly above the player --//
        private double GetSpawnOffset()
        {
            int minSpawnOffset = MeteoricExpansionHelpers.GetMinSpawnDistance();
            int maxSpawnOffset = MeteoricExpansionHelpers.GetMaxSpawnDistance();

            int    negativeRand = spawnerRand.Next(0, 1);
            double spawnOffset  = spawnerRand.Next(this.serverAPI.WorldManager.ChunkSize * minSpawnOffset, this.serverAPI.WorldManager.ChunkSize * maxSpawnOffset) + spawnerRand.NextDouble();

            if (negativeRand == 0)
            {
                return(-spawnOffset);
            }

            return(spawnOffset);
        }
Ejemplo n.º 7
0
        //-- Spawn a meteor made with random rock and metals above the first online player every number of seconds as determined by tickIntervalInSeconds --//
        //-- Eventually spawns will happen between the minMeteorSpawnTime and maxMeteorSpawnTime --//
        private void onSpawnerTick(float deltaTime)
        {
            if (this.serverAPI.World.ElapsedMilliseconds - timeSinceSpawn > nextMeteorSpawn)
            {
                if (serverAPI.World.AllOnlinePlayers.Length > 0)
                {
                    int playerToSpawnAt = GetSinglePlayer(serverAPI.World.AllOnlinePlayers);

                    serverAPI.World.SpawnEntity(InitEntity(MeteoricExpansionHelpers.SelectRandomMeteor(), playerToSpawnAt));
                }

                nextMeteorSpawn = spawnerRand.Next(minMeteorSpawnTime, maxMeteorSpawnTime) + spawnerRand.NextDouble();
                nextMeteorSpawn = MeteoricExpansionHelpers.ConvertMinutesToMilliseconds(nextMeteorSpawn);

                timeSinceSpawn = this.serverAPI.World.ElapsedMilliseconds;
            }
        }
Ejemplo n.º 8
0
        public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)
        {
            base.Initialize(properties, api, InChunkIndex3d);

            rand = new Random((int)this.EntityId);

            currentScale = (float)rand.NextDouble() + rand.Next(minMeteorScale, maxMeteorScale);

            properties.Client.Size      *= currentScale;
            properties.CollisionBoxSize *= currentScale;

            if (api.Side == EnumAppSide.Server)
            {
                minMeteorLifespan = MeteoricExpansionHelpers.GetMinLifespan();
                maxMeteorLifespan = MeteoricExpansionHelpers.GetMaxLifespan();

                spawnTimeInMilliseconds = api.World.ElapsedMilliseconds;
                currentLifespan         = (float)(rand.Next(minMeteorLifespan, maxMeteorLifespan) * currentScale + rand.NextDouble()) * 1000;

                properties.Attributes["lightHsv"].AsObject <byte[]>(new byte[] { 4, 4, 31 });
            }
        }
Ejemplo n.º 9
0
        private void onFirstTick(float deltaTime)
        {
            MeteoricExpansionHelpers.InitializeHelpers(serverAPI.World.Seed, EntityCodeArray());

            serverAPI.Event.UnregisterGameTickListener(firstTickListener);
        }