Esempio n. 1
0
    private void RoomPreparer_Update(On.RoomPreparer.orig_Update orig, RoomPreparer self)
    {
        bool lastDone = self.done;

        orig.Invoke(self);
        bool needsFinalization = false;

        if (self.done && !lastDone)
        {
            // Terrain destruction must be applied each time a room is realized
            foreach (AbstractWorldEntity entity in self.room.abstractRoom.entities)
            {
                if (entity is AbstractDestruction ad)
                {
                    ad.ApplyTerrain(false);
                    if (ad.affectTerrain)
                    {
                        needsFinalization = true;
                    }
                }
            }
        }
        if (needsFinalization)
        {
            AbstractDestruction.FinalizeTerrainDestruction(self.room);
        }
    }
Esempio n. 2
0
    private void DestructiveExplosion(Room room, Vector2 pos, float rad, bool affectTerrain = true)
    {
        AbstractDestruction ad = new AbstractDestruction(room.world, room.GetWorldCoordinate(pos), pos, rad, room.game.GetNewID(), affectTerrain);

        room.abstractRoom.AddEntity(ad);
        ad.ApplyTerrain();
        ad.ApplyVisual();

        // All affected screens must have their caches cleared
        {
            Texture2D currentLevelTex = room.game.rainWorld.persistentData.cameraTextures[0, 0];
            for (int i = 0, len = room.cameraPositions.Length; i < len; i++)
            {
                Vector2    testCamPos   = room.cameraPositions[i];
                IntVector2 testLocalPos = new IntVector2(Mathf.FloorToInt(ad.realPos.x - testCamPos.x), Mathf.FloorToInt(ad.realPos.y - testCamPos.y));
                if ((testLocalPos.x < -rad) || (testLocalPos.y < -rad) || (testLocalPos.x > currentLevelTex.width + rad) || (testLocalPos.y > currentLevelTex.height + rad))
                {
                    continue;
                }
                DestructionCache.ClearCachedTexture(i);
                DestructionCache.SetScreenDirty(i);
            }
        }
    }