Requiring certain heroes for certain levels, and showing the choose hero view when they go to play a level where the hero has changed.

This commit is contained in:
Nick Winter 2014-11-26 08:53:06 -08:00
parent 3f9aa1ba79
commit 2c0bf2fef1
7 changed files with 46 additions and 7 deletions

View file

@ -81,3 +81,6 @@ module.exports = class CocoClass
stopListeningToShortcuts: ->
return unless key?
key.deleteScope(@scope)
playSound: (trigger, volume=1) ->
Backbone.Mediator.publish 'audio-player:play-sound', trigger: trigger, volume: volume

View file

@ -249,9 +249,11 @@ module.exports = LevelOptions =
'swift-dagger':
requiredGear: {waist: 'leather-belt', 'programming-book': 'programmaticon-ii', eyes: 'wooden-glasses', 'right-hand': 'crude-crossbow', 'left-hand': 'crude-dagger', wrists: 'sundial-wristwatch'}
restrictedGear: {eyes: 'crude-glasses'}
allowedHeroes: ['ninja', 'trapper', 'forest-archer']
'shrapnel':
requiredGear: {waist: 'leather-belt', 'programming-book': 'programmaticon-ii', eyes: 'wooden-glasses', 'right-hand': 'crude-crossbow', 'left-hand': 'weak-charge', wrists: 'sundial-wristwatch'}
restrictedGear: {eyes: 'crude-glasses', 'left-hand': 'crude-dagger'}
allowedHeroes: ['ninja', 'trapper', 'forest-archer']
# Wizard branch
'arcane-ally':
@ -260,10 +262,12 @@ module.exports = LevelOptions =
'touch-of-death':
requiredGear: {waist: 'leather-belt', 'programming-book': 'programmaticon-ii', eyes: 'wooden-glasses', 'right-hand': 'enchanted-stick', 'left-hand': 'unholy-tome-i', wrists: 'sundial-wristwatch'}
restrictedGear: {}
allowedHeroes: ['librarian', 'potion-master', 'sorcerer']
'bonemender':
requiredGear: {waist: 'leather-belt', 'programming-book': 'programmaticon-ii', eyes: 'wooden-glasses', 'right-hand': 'enchanted-stick', 'left-hand': 'book-of-life-i', wrists: 'sundial-wristwatch'}
restrictedGear: {'left-hand': 'unholy-tome-i'}
requiredCode: ['canCast']
allowedHeroes: ['librarian', 'potion-master', 'sorcerer']
'coinucopia':
requiredGear: {'programming-book': 'programmaticon-i', feet: 'leather-boots', 'programming-book': 'programmaticon-ii', flag: 'basic-flags'}

View file

@ -3,6 +3,12 @@ PlayHeroesModal = require 'views/play/modal/PlayHeroesModal'
InventoryModal = require 'views/game-menu/InventoryModal'
LevelSession = require 'models/LevelSession'
SuperModel = require 'models/SuperModel'
ThangType = require 'models/ThangType'
LevelOptions = require 'lib/LevelOptions'
lastHeroesEarned = me.get('earned')?.heroes ? []
lastHeroesPurchased = me.get('purchased')?.heroes ? []
module.exports = class LevelSetupManager extends CocoClass
@ -46,9 +52,19 @@ module.exports = class LevelSetupManager extends CocoClass
open: ->
firstModal = if @options.hadEverChosenHero then @inventoryModal else @heroesModal
if (not _.isEqual(lastHeroesEarned, me.get('earned')?.heroes ? []) or
not _.isEqual(lastHeroesPurchased, me.get('purchased')?.heroes ? []))
console.log 'Showing hero picker because heroes earned/purchased has changed.'
firstModal = @heroesModal
else if allowedHeroSlugs = LevelOptions[@options.levelID]?.allowedHeroes
unless _.find(allowedHeroSlugs, (slug) -> ThangType.heroes[slug] is me.get('heroConfig')?.thangType)
firstModal = @heroesModal
lastHeroesEarned = me.get('earned')?.heroes ? []
lastHeroesPurchased = me.get('purchased')?.heroes ? []
@options.parent.openModalView(firstModal)
# @inventoryModal.onShown() # replace?
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'game-menu-open', volume: 1
@playSound 'game-menu-open'
#- Modal events

View file

@ -357,6 +357,7 @@
skills: "Skills"
available_for_purchase: "Available for Purchase"
level_to_unlock: "Level to unlock:"
restricted_to_certain_heroes: "Only certain heroes can play this level."
skill_docs:
writable: "writable" # Hover over "attack" in Your Skills while playing a level to see most of this

View file

@ -107,6 +107,11 @@ $heroCanvasHeight: 265px
.hero-avatar
background-color: goldenrod
&.restricted
@include opacity(0.25)
.hero-avatar
background-color: black
//- Small transformations to jumble the hero icons a little
@ -147,7 +152,7 @@ $heroCanvasHeight: 265px
#hero-carousel
.hero-item
&.locked:not(.purchasable)
&.locked:not(.purchasable), &.restricted
@include opacity(0.6)
canvas, .hero-feature-image
@ -255,7 +260,7 @@ $heroCanvasHeight: 265px
color: #333
text-align: center
#locked-hero-explanation
#locked-hero-explanation, #restricted-hero-explanation
position: absolute
left: 32px
top: 527px

View file

@ -12,13 +12,13 @@
.carousel-indicator-container
ol.carousel-indicators
for hero, index in heroes
li(data-hero-id=hero.get('original'), title=hero.name, data-slide-to=index, data-target="#hero-carousel", class="hero-indicator hero-index-" + index + (hero.locked ? " locked" : "") + (hero.purchasable ? " purchasable" : ""))
li(data-hero-id=hero.get('original'), title=hero.name, data-slide-to=index, data-target="#hero-carousel", class="hero-indicator hero-index-" + index + (hero.locked ? " locked" : "") + (hero.purchasable ? " purchasable" : "") + (hero.restricted ? " restricted" : ""))
.hero-avatar
if hero.locked && !hero.purchasable
img.lock-indicator(src="/images/pages/game-menu/lock.png", draggable="false")
.carousel-inner
for hero in heroes
div(class="item hero-item" + (hero.locked ? " locked" : "") + (hero.purchasable ? " purchasable" : ""), data-hero-id=hero.get('original'))
div(class="item hero-item" + (hero.locked ? " locked" : "") + (hero.purchasable ? " purchasable" : "") + (hero.restricted ? " restricted" : ""), data-hero-id=hero.get('original'))
canvas.hero-canvas
.hero-feature-image
img(draggable="false")
@ -28,7 +28,7 @@
.hero-stat-row
.stat-label(data-i18n='choose_hero.status')
.stat-value.hero-status-value(data-i18n=hero.purchasable ? 'play.purchasable' : (hero.locked ? 'play.locked' : 'play.available'))
.stat-value.hero-status-value(data-i18n=hero.restricted ? 'inventory.restricted_title' : (hero.purchasable ? 'play.purchasable' : (hero.locked ? 'play.locked' : 'play.available')))
.hero-stat-row
.stat-label(data-i18n='choose_hero.weapons')
@ -53,7 +53,14 @@
#hero-footer
if visibleHero
if visibleHero.purchasable
if visibleHero.restricted
#restricted-hero-explanation
h2
span= visibleHero.name
span.spl(data-i18n="inventory.restricted_title") Restricted
span.spr(data-i18n="choose_hero.restricted_to_certain_heroes") Only certain heroes can play this level.
else if visibleHero.purchasable
#purchasable-hero-explanation
h2(data-i18n="choose_hero.available_for_purchase") Available for Purchase
button.btn.unlock-button#purchase-hero-button

View file

@ -8,6 +8,7 @@ AudioPlayer = require 'lib/AudioPlayer'
utils = require 'lib/utils'
BuyGemsModal = require 'views/play/modal/BuyGemsModal'
Purchase = require 'models/Purchase'
LevelOptions = require 'lib/LevelOptions'
module.exports = class PlayHeroesModal extends ModalView
className: 'modal fade play-modal'
@ -54,6 +55,8 @@ module.exports = class PlayHeroesModal extends ModalView
original = hero.get('original')
hero.locked = not me.ownsHero(original)
hero.purchasable = hero.locked and (original in (me.get('earned')?.heroes ? []))
if @options.levelID and allowedHeroSlugs = LevelOptions[@options.levelID]?.allowedHeroes
hero.restricted = not (hero.get('slug') in allowedHeroSlugs)
hero.class = (hero.get('heroClass') or 'warrior').toLowerCase()
hero.stats = hero.getHeroStats()