class CaveEffects(EnvironmentEffects.EnvironmentEffects):
    WaterCaves = [LocationIds.ANVIL_CAVE_BARBOSA]
    LavaCaves = []

    def __init__(self, parent, modelPath):
        EnvironmentEffects.EnvironmentEffects.__init__(self, parent, modelPath)
        self.modelPath = modelPath
        self.modelPrefix = ''
        self.animActor = None
        self.water = None
        self.reflection = None
        self.supports_sky_only = False
        self.startEffects()

    def delete(self):
        del self.animActor
        self.stopEffects()
        EnvironmentEffects.EnvironmentEffects.delete(self)

    def startEffects(self):
        reflection = Reflection.getGlobalReflection()
        non_shader_water_color = Vec4(0.0, 1.0 / 255.0, 4.0 / 255.0, 1.0)
        shader_water_color = Vec4(0.0, 1.0, 4.0, 255.0)
        if self.parent.uniqueId in self.WaterCaves:
            if base.config.GetBool(
                    'want-shaders',
                    1) and base.win and base.win.getGsg() and base.win.getGsg(
                    ).getShaderModel() >= GraphicsStateGuardian.SM20:
                self.water = Swamp('models/caves/cave_a_water', self.parent,
                                   reflection, None, None, shader_water_color)
                self.water.reflection_factor = 0.29999999999999999
                self.water.set_reflection_parameters_np()
            else:
                water = loader.loadModel('models/caves/cave_a_water')
                water.reparentTo(self.parent)
                color = non_shader_water_color
                water.setColorScale(color)
                water.setTextureOff(1)
                mask = 0xFFFFFFFFL
                stencil = StencilAttrib.make(1, StencilAttrib.SCFAlways,
                                             StencilAttrib.SOKeep,
                                             StencilAttrib.SOKeep,
                                             StencilAttrib.SOReplace, 1, mask,
                                             mask)
                water.setAttrib(stencil)
                water.setBin('water', 0)
                self.reflection = reflection
                taskMgr.add(self.camTask,
                            'caveEffectsCamTask-' + str(id(self)),
                            priority=49)
                water.setFogOff()
        elif self.parent.uniqueId in self.LavaCaves:
            if base.config.GetBool(
                    'want-shaders',
                    1) and base.win and base.win.getGsg() and base.win.getGsg(
                    ).getShaderModel() >= GraphicsStateGuardian.SM20:
                self.water = Swamp(self.modelPrefix + 'lava', self.parent,
                                   reflection, None, None, shader_water_color)
                l1 = LerpScaleInterval(self.water.seamodel,
                                       2,
                                       Vec3(1.006, 1.006, 1.0),
                                       Vec3(1.0, 1.0, 1.0),
                                       blendType='easeInOut')
                l2 = LerpScaleInterval(self.water.seamodel,
                                       2,
                                       Vec3(1.0, 1.0, 1.0),
                                       Vec3(1.006, 1.006, 1.0),
                                       blendType='easeInOut')
                seq = Sequence(l1, l2)
                seq.loop()
                self.water.reflection_factor = 0.29999999999999999
                self.water.set_reflection_parameters_np()
            else:
                water = loader.loadModel(self.modelPrefix + 'lava')
                water.reparentTo(self.parent)
                water.setFogOff()

        base.ambientMgr.requestFadeIn(
            SoundGlobals.AMBIENT_CAVE,
            duration=10,
            finalVolume=PiratesGlobals.DEFAULT_AMBIENT_VOLUME,
            priority=1)
        if self.water:
            self.water.supports_sky_only = self.supports_sky_only

        if reflection:
            if base.options.reflection >= 1:
                reflection.reflectShowThroughOnly(False)
                reflection.enable(True)

    def camTask(self, task):
        if self.reflection:
            self.reflection.update_reflection(base.camLens, base.cam)

        return Task.cont

    def stopEffects(self):
        if hasattr(base, 'cr') and not hasattr(base.cr, 'isFake'):
            if base.options.reflection == 0:
                Water.all_reflections_off()
            elif base.options.reflection == 1:
                Water.all_reflections_show_through_only()
            elif base.options.reflection == 2:
                Water.all_reflections_on()

        if self.water:
            self.water.delete()
            self.water = None

        taskMgr.remove('caveEffectsCamTask-' + str(id(self)))
        base.ambientMgr.requestFadeOut(SoundGlobals.AMBIENT_CAVE,
                                       duration=5,
                                       priority=1)
Esempio n. 2
0
class ForestEffects(EnvironmentEffects.EnvironmentEffects):
    FIREFLIES_Z = 6.0
    RANDOM_SOUND_PERIOD = 6
    RANDOM_SOUND_CHANCE = 12

    def __init__(self, parent, modelPath):
        EnvironmentEffects.EnvironmentEffects.__init__(self, parent, modelPath)
        self.fireflies = None
        self.modelPrefix = modelPath[:-4]
        self.animActor = self.setupAnimActor()
        self.water = None
        self.randomAnimalSoundFiles = [
            SoundGlobals.SFX_FX_JUNGLE_BIRDS_01,
            SoundGlobals.SFX_FX_JUNGLE_BIRDS_02
        ]
        self.randomSfx = []
        self.startEffects()
        return

    def delete(self):
        del self.animActor
        self.stopEffects()
        EnvironmentEffects.EnvironmentEffects.delete(self)

    def startEffects(self):
        if not self.fireflies:
            self.fireflies = Fireflies()
        if self.fireflies and hasattr(base, 'cr'):
            self.fireflies.reparentTo(base.localAvatar)
            self.fireflies.startLoop()
        base.ambientMgr.requestFadeIn(
            SoundGlobals.AMBIENT_JUNGLE,
            duration=10,
            finalVolume=PiratesGlobals.DEFAULT_AMBIENT_VOLUME,
            priority=1)
        self.swamp_water = None
        reflection = Reflection.getGlobalReflection()
        if 'jungle_a' in self.modelPrefix:
            if base.config.GetBool(
                    'want-shaders',
                    1) and base.win and base.win.getGsg() and base.win.getGsg(
                    ).getShaderModel() >= GraphicsStateGuardian.SM20:
                water_color = Vec4(13, 15, 21, 255.0)
                self.water = Swamp(self.modelPrefix + 'water', self.parent,
                                   reflection, None, None, water_color)
                self.water.reflection_factor = 0.3
                self.water.set_reflection_parameters_np()
            else:
                water = loader.loadModel(self.modelPrefix + 'water')
                water.reparentTo(self.parent)
                color = Vec4(0)
                water.setColorScale(color)
                mask = 4294967295L
                stencil = StencilAttrib.make(1, StencilAttrib.SCFAlways,
                                             StencilAttrib.SOKeep,
                                             StencilAttrib.SOKeep,
                                             StencilAttrib.SOReplace, 1, mask,
                                             mask)
                water.setAttrib(stencil)
                water.setBin('water', 0)
                self.reflection = reflection
                taskMgr.add(self.camTask,
                            'jungleEffectsCamTask-' + str(id(self)),
                            priority=49)
                water.setFogOff()
        for file in self.randomAnimalSoundFiles:
            sfx = loadSfx(file)
            self.randomSfx.append(sfx)

        taskMgr.doMethodLater(self.RANDOM_SOUND_PERIOD,
                              self.checkForRandomSound,
                              name='checkForRandomSound-' + str(id(self)))
        return

    def stopEffects(self):
        if hasattr(base, 'cr') and not hasattr(base.cr, 'isFake'):
            taskMgr.remove(self.parent.uniqueName('groundFogZTask'))
        if self.water:
            self.water.delete()
            self.water = None
        if self.fireflies:
            self.fireflies.destroy()
            self.fireflies = None
        taskMgr.remove('jungleEffectsCamTask-' + str(id(self)))
        taskMgr.remove('checkForRandomSound-' + str(id(self)))
        for sfx in self.randomSfx:
            sfx.stop()

        base.ambientMgr.requestFadeOut(SoundGlobals.AMBIENT_JUNGLE,
                                       duration=5,
                                       priority=1)
        return

    def checkForRandomSound(self, task):
        randomSoundPlaying = False
        for sfx in self.randomSfx:
            if sfx.status() == 2:
                randomSoundPlaying = True
                break

        if not randomSoundPlaying:
            roll = random.randint(0, 100)
            if roll < self.RANDOM_SOUND_CHANCE:
                sfxToPlay = random.choice(self.randomSfx)
                sfxToPlay.play()
        taskMgr.doMethodLater(self.RANDOM_SOUND_PERIOD,
                              self.checkForRandomSound,
                              name='checkForRandomSound-' + str(id(self)))
        return Task.done

    def camTask(self, task):
        if self.reflection:
            self.reflection.update_reflection(base.camLens, base.cam)
        return Task.cont

    def adjustGroundFogZ(self, task):
        if self.fireflies:
            self.fireflies.setZ(render, self.FIREFLIES_Z)
        if self.fireflies:
            return Task.cont
        return Task.done
Esempio n. 3
0
class ForestEffects(EnvironmentEffects.EnvironmentEffects):
    FIREFLIES_Z = 6.0
    RANDOM_SOUND_PERIOD = 6
    RANDOM_SOUND_CHANCE = 12
    
    def __init__(self, parent, modelPath):
        EnvironmentEffects.EnvironmentEffects.__init__(self, parent, modelPath)
        self.fireflies = None
        self.modelPrefix = modelPath[:-4]
        self.animActor = self.setupAnimActor()
        self.water = None
        self.randomAnimalSoundFiles = [
            SoundGlobals.SFX_FX_JUNGLE_BIRDS_01,
            SoundGlobals.SFX_FX_JUNGLE_BIRDS_02]
        self.randomSfx = []
        self.startEffects()

    
    def delete(self):
        del self.animActor
        self.stopEffects()
        EnvironmentEffects.EnvironmentEffects.delete(self)

    
    def startEffects(self):
        if not self.fireflies:
            self.fireflies = Fireflies()
        
        if self.fireflies and hasattr(base, 'cr'):
            self.fireflies.reparentTo(base.localAvatar)
            self.fireflies.startLoop()
        
        base.ambientMgr.requestFadeIn(SoundGlobals.AMBIENT_JUNGLE, duration = 10, finalVolume = PiratesGlobals.DEFAULT_AMBIENT_VOLUME, priority = 1)
        self.swamp_water = None
        reflection = Reflection.getGlobalReflection()
        if 'jungle_a' in self.modelPrefix:
            if base.config.GetBool('want-shaders', 1) and base.win and base.win.getGsg() and base.win.getGsg().getShaderModel() >= GraphicsStateGuardian.SM20:
                water_color = Vec4(13, 15, 21, 255.0)
                self.water = Swamp(self.modelPrefix + 'water', self.parent, reflection, None, None, water_color)
                self.water.reflection_factor = 0.29999999999999999
                self.water.set_reflection_parameters_np()
            else:
                water = loader.loadModel(self.modelPrefix + 'water')
                water.reparentTo(self.parent)
                color = Vec4(0)
                water.setColorScale(color)
                mask = 0xFFFFFFFFL
                stencil = StencilAttrib.make(1, StencilAttrib.SCFAlways, StencilAttrib.SOKeep, StencilAttrib.SOKeep, StencilAttrib.SOReplace, 1, mask, mask)
                water.setAttrib(stencil)
                water.setBin('water', 0)
                self.reflection = reflection
                taskMgr.add(self.camTask, 'jungleEffectsCamTask-' + str(id(self)), priority = 49)
                water.setFogOff()
        
        for file in self.randomAnimalSoundFiles:
            sfx = loadSfx(file)
            self.randomSfx.append(sfx)
        
        taskMgr.doMethodLater(self.RANDOM_SOUND_PERIOD, self.checkForRandomSound, name = 'checkForRandomSound-' + str(id(self)))

    
    def stopEffects(self):
        if hasattr(base, 'cr') and not hasattr(base.cr, 'isFake'):
            taskMgr.remove(self.parent.uniqueName('groundFogZTask'))
        
        if self.water:
            self.water.delete()
            self.water = None
        
        if self.fireflies:
            self.fireflies.destroy()
            self.fireflies = None
        
        taskMgr.remove('jungleEffectsCamTask-' + str(id(self)))
        taskMgr.remove('checkForRandomSound-' + str(id(self)))
        for sfx in self.randomSfx:
            sfx.stop()
        
        base.ambientMgr.requestFadeOut(SoundGlobals.AMBIENT_JUNGLE, duration = 5, priority = 1)

    
    def checkForRandomSound(self, task):
        randomSoundPlaying = False
        for sfx in self.randomSfx:
            if sfx.status() == 2:
                randomSoundPlaying = True
                break
                continue
        
        if not randomSoundPlaying:
            roll = random.randint(0, 100)
            if roll < self.RANDOM_SOUND_CHANCE:
                sfxToPlay = random.choice(self.randomSfx)
                sfxToPlay.play()
            
        
        taskMgr.doMethodLater(self.RANDOM_SOUND_PERIOD, self.checkForRandomSound, name = 'checkForRandomSound-' + str(id(self)))
        return Task.done

    
    def camTask(self, task):
        if self.reflection:
            self.reflection.update_reflection(base.camLens, base.cam)
        
        return Task.cont

    
    def adjustGroundFogZ(self, task):
        if self.fireflies:
            self.fireflies.setZ(render, self.FIREFLIES_Z)
        
        if self.fireflies:
            return Task.cont
        
        return Task.done
Esempio n. 4
0
class CaveEffects(EnvironmentEffects.EnvironmentEffects):
    WaterCaves = [LocationIds.ANVIL_CAVE_BARBOSA]
    LavaCaves = []

    def __init__(self, parent, modelPath):
        EnvironmentEffects.EnvironmentEffects.__init__(self, parent, modelPath)
        self.modelPath = modelPath
        self.modelPrefix = ""
        self.animActor = None
        self.water = None
        self.reflection = None
        self.supports_sky_only = False
        self.startEffects()

    def delete(self):
        del self.animActor
        self.stopEffects()
        EnvironmentEffects.EnvironmentEffects.delete(self)

    def startEffects(self):
        reflection = Reflection.getGlobalReflection()
        non_shader_water_color = Vec4(0.0, 1.0 / 255.0, 4.0 / 255.0, 1.0)
        shader_water_color = Vec4(0.0, 1.0, 4.0, 255.0)
        if self.parent.uniqueId in self.WaterCaves:
            if (
                base.config.GetBool("want-shaders", 1)
                and base.win
                and base.win.getGsg()
                and base.win.getGsg().getShaderModel() >= GraphicsStateGuardian.SM20
            ):
                self.water = Swamp("models/caves/cave_a_water", self.parent, reflection, None, None, shader_water_color)
                self.water.reflection_factor = 0.29999999999999999
                self.water.set_reflection_parameters_np()
            else:
                water = loader.loadModel("models/caves/cave_a_water")
                water.reparentTo(self.parent)
                color = non_shader_water_color
                water.setColorScale(color)
                water.setTextureOff(1)
                mask = 0xFFFFFFFFL
                stencil = StencilAttrib.make(
                    1,
                    StencilAttrib.SCFAlways,
                    StencilAttrib.SOKeep,
                    StencilAttrib.SOKeep,
                    StencilAttrib.SOReplace,
                    1,
                    mask,
                    mask,
                )
                water.setAttrib(stencil)
                water.setBin("water", 0)
                self.reflection = reflection
                taskMgr.add(self.camTask, "caveEffectsCamTask-" + str(id(self)), priority=49)
                water.setFogOff()
        elif self.parent.uniqueId in self.LavaCaves:
            if (
                base.config.GetBool("want-shaders", 1)
                and base.win
                and base.win.getGsg()
                and base.win.getGsg().getShaderModel() >= GraphicsStateGuardian.SM20
            ):
                self.water = Swamp(self.modelPrefix + "lava", self.parent, reflection, None, None, shader_water_color)
                l1 = LerpScaleInterval(
                    self.water.seamodel, 2, Vec3(1.006, 1.006, 1.0), Vec3(1.0, 1.0, 1.0), blendType="easeInOut"
                )
                l2 = LerpScaleInterval(
                    self.water.seamodel, 2, Vec3(1.0, 1.0, 1.0), Vec3(1.006, 1.006, 1.0), blendType="easeInOut"
                )
                seq = Sequence(l1, l2)
                seq.loop()
                self.water.reflection_factor = 0.29999999999999999
                self.water.set_reflection_parameters_np()
            else:
                water = loader.loadModel(self.modelPrefix + "lava")
                water.reparentTo(self.parent)
                water.setFogOff()

        base.ambientMgr.requestFadeIn(
            SoundGlobals.AMBIENT_CAVE, duration=10, finalVolume=PiratesGlobals.DEFAULT_AMBIENT_VOLUME, priority=1
        )
        if self.water:
            self.water.supports_sky_only = self.supports_sky_only

        if reflection:
            if base.options.reflection >= 1:
                reflection.reflectShowThroughOnly(False)
                reflection.enable(True)

    def camTask(self, task):
        if self.reflection:
            self.reflection.update_reflection(base.camLens, base.cam)

        return Task.cont

    def stopEffects(self):
        if hasattr(base, "cr") and not hasattr(base.cr, "isFake"):
            if base.options.reflection == 0:
                Water.all_reflections_off()
            elif base.options.reflection == 1:
                Water.all_reflections_show_through_only()
            elif base.options.reflection == 2:
                Water.all_reflections_on()

        if self.water:
            self.water.delete()
            self.water = None

        taskMgr.remove("caveEffectsCamTask-" + str(id(self)))
        base.ambientMgr.requestFadeOut(SoundGlobals.AMBIENT_CAVE, duration=5, priority=1)