berserkPain :: EntPain
berserkPain =
  GenericEntPain "berserk_pain" $ \selfRef _ _ damage -> do
    self <- readRef selfRef

    when ((self^.eHealth) < (self^.eMaxHealth) `div` 2) $
      modifyRef selfRef (\v -> v & eEntityState.esSkinNum .~ 1)

    levelTime <- use $ gameBaseGlobals.gbLevel.llTime

    unless (levelTime < (self^.ePainDebounceTime)) $ do
      modifyRef selfRef (\v -> v & ePainDebounceTime .~ levelTime + 3)

      sound <- use $ gameBaseGlobals.gbGameImport.giSound
      soundPain <- use $ mBerserkGlobals.mBerserkSoundPain
      sound (Just selfRef) Constants.chanVoice soundPain 1 Constants.attnNorm 0

      skillValue <- liftM (^.cvValue) skillCVar

      unless (skillValue == 3) $ do -- no pain anims in nightmare
        r <- Lib.randomF

        let currentMove = if damage < 20 || r < 0.5
                            then berserkMovePain1
                            else berserkMovePain2

        modifyRef selfRef (\v -> v & eMonsterInfo.miCurrentMove .~ Just currentMove)
berserkPain :: EntPain
berserkPain =
  GenericEntPain "berserk_pain" $ \selfRef _ _ damage -> do
    self <- readRef selfRef

    when ((self^.eHealth) < (self^.eMaxHealth) `div` 2) $
      modifyRef selfRef (\v -> v & eEntityState.esSkinNum .~ 1)

    levelTime <- use $ gameBaseGlobals.gbLevel.llTime

    unless (levelTime < (self^.ePainDebounceTime)) $ do
      modifyRef selfRef (\v -> v & ePainDebounceTime .~ levelTime + 3)

      sound <- use $ gameBaseGlobals.gbGameImport.giSound
      soundPain <- use $ mBerserkGlobals.mBerserkSoundPain
      sound (Just selfRef) Constants.chanVoice soundPain 1 Constants.attnNorm 0

      skillValue <- liftM (^.cvValue) skillCVar

      unless (skillValue == 3) $ do -- no pain anims in nightmare
        r <- Lib.randomF

        let currentMove = if damage < 20 || r < 0.5
                            then berserkMovePain1
                            else berserkMovePain2

        modifyRef selfRef (\v -> v & eMonsterInfo.miCurrentMove .~ Just currentMove)
berserkPain =
  GenericEntPain "berserk_pain" $ \selfRef _ _ damage -> do
    self <- readRef selfRef

    when ((self^.eHealth) < (self^.eMaxHealth) `div` 2) $
      modifyRef selfRef (\v -> v & eEntityState.esSkinNum .~ 1)

    levelTime <- use $ gameBaseGlobals.gbLevel.llTime

    unless (levelTime < (self^.ePainDebounceTime)) $ do
      modifyRef selfRef (\v -> v & ePainDebounceTime .~ levelTime + 3)

      sound <- use $ gameBaseGlobals.gbGameImport.giSound
      soundPain <- use $ mBerserkGlobals.mBerserkSoundPain
      sound (Just selfRef) Constants.chanVoice soundPain 1 Constants.attnNorm 0

      skillValue <- liftM (^.cvValue) skillCVar

      unless (skillValue == 3) $ do -- no pain anims in nightmare
        r <- Lib.randomF

        let currentMove = if damage < 20 || r < 0.5
                            then berserkMovePain1
                            else berserkMovePain2

        modifyRef selfRef (\v -> v & eMonsterInfo.miCurrentMove .~ Just currentMove)