コード例 #1
0
        /// <summary>
        /// Called to update the entity's position/logic.
        /// </summary>
        public override void OnUpdate()
        {
            base.OnUpdate();

            if (LightningState == 2)
            {
                WorldObj.PlaySoundEffect(PosX, PosY, PosZ, "ambient.weather.thunder", 10000F, 0.8F + Rand.NextFloat() * 0.2F);
                WorldObj.PlaySoundEffect(PosX, PosY, PosZ, "random.explode", 2.0F, 0.5F + Rand.NextFloat() * 0.2F);
            }

            LightningState--;

            if (LightningState < 0)
            {
                if (BoltLivingTime == 0)
                {
                    SetDead();
                }
                else if (LightningState < -Rand.Next(10))
                {
                    BoltLivingTime--;
                    LightningState = 1;
                    BoltVertex     = Rand.Next();

                    if (WorldObj.DoChunksNearChunkExist(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY), MathHelper2.Floor_double(PosZ), 10))
                    {
                        int i = MathHelper2.Floor_double(PosX);
                        int j = MathHelper2.Floor_double(PosY);
                        int k = MathHelper2.Floor_double(PosZ);

                        if (WorldObj.GetBlockId(i, j, k) == 0 && Block.Fire.CanPlaceBlockAt(WorldObj, i, j, k))
                        {
                            WorldObj.SetBlockWithNotify(i, j, k, Block.Fire.BlockID);
                        }
                    }
                }
            }

            if (LightningState >= 0)
            {
                float         d    = 3;
                List <Entity> list = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, AxisAlignedBB.GetBoundingBoxFromPool(PosX - d, PosY - d, PosZ - d, PosX + d, PosY + 6 + d, PosZ + d));

                for (int l = 0; l < list.Count; l++)
                {
                    Entity entity = list[l];
                    entity.OnStruckByLightning(this);
                }

                WorldObj.LightningFlash = 2;
            }
        }