1
0
mirror of https://github.com/exane/not-gwent-online synced 2024-11-23 19:36:53 +00:00

add some abilities

This commit is contained in:
exane 2015-06-19 14:14:37 +02:00
parent b2aa796aad
commit 21a92f69f3
19 changed files with 3772 additions and 81 deletions

View File

@ -4,7 +4,19 @@ module.exports = {
}, },
"medic": { "medic": {
waitResponse: true,
onAfterPlace: function(card) {
var discard = this.getDiscard();
discard = this.filter(discard, {
"ability": "hero",
"type": card.constructor.TYPE.SPECIAL
})
this.send("played:medic", {
cards: JSON.stringify(discard)
}, true);
}
}, },
"morale_boost": { "morale_boost": {
onAfterPlace: function(card) { onAfterPlace: function(card) {
@ -19,14 +31,25 @@ module.exports = {
} }
}, },
"muster": { "muster": {
name: "muster",
onAfterPlace: function(card){ onAfterPlace: function(card){
var name = card.getName(); var musterType = card.getMusterType();
var self = this; var self = this;
var cards = this.deck.find("name", name); var cardsDeck = this.deck.find("musterType", musterType);
cards.forEach(function(_card) { var cardsHand = this.hand.find("musterType", musterType);
cardsDeck.forEach(function(_card) {
self.deck.removeFromDeck(_card); self.deck.removeFromDeck(_card);
this.placeCard(_card); self.placeCard(_card, {
suppress: "muster"
});
})
cardsHand.forEach(function(_card) {
self.hand.remove(_card);
self.placeCard(_card, {
suppress: "muster"
});
}) })
} }
}, },
@ -128,5 +151,32 @@ module.exports = {
var card = this.deck.removeFromDeck(cards[0]); var card = this.deck.removeFromDeck(cards[0]);
this.placeCard(card); this.placeCard(card);
} }
},
"francesca_leader1": {
},
"francesca_leader2": {
},
"francesca_leader3": {
},
"francesca_leader4": {
},
"eredin_leader1": {
},
"eredin_leader2": {
},
"eredin_leader3": {
},
"eredin_leader4": {
},
"hero": {
} }
} }

View File

@ -204,7 +204,6 @@ module.exports = {
}, },
"francesca_pureblood_elf": { "francesca_pureblood_elf": {
name: "Francesca, Pureblood Elf", name: "Francesca, Pureblood Elf",
power: -1, power: -1,
@ -273,7 +272,7 @@ module.exports = {
name: "Havekar Healer", name: "Havekar Healer",
power: 0, power: 0,
ability: "morale_boost", ability: "morale_boost",
img: "healerr", img: "healer",
faction: "Scoia'tael", faction: "Scoia'tael",
type: 1 type: 1
}, },
@ -297,6 +296,7 @@ module.exports = {
name: "Elven Skirmisher", name: "Elven Skirmisher",
power: 2, power: 2,
ability: "muster", ability: "muster",
musterType: "skirmisher",
img: "elven_skirmisher2", img: "elven_skirmisher2",
faction: "Scoia'tael", faction: "Scoia'tael",
type: 1 type: 1
@ -305,6 +305,7 @@ module.exports = {
name: "Dwarven Skirmisher", name: "Dwarven Skirmisher",
power: 3, power: 3,
ability: "muster", ability: "muster",
musterType: "skirmisher",
img: "skirmisher2", img: "skirmisher2",
faction: "Scoia'tael", faction: "Scoia'tael",
type: 0 type: 0
@ -353,6 +354,7 @@ module.exports = {
name: "Mahakaman Defender", name: "Mahakaman Defender",
power: 5, power: 5,
ability: "muster", ability: "muster",
musterType: "defender",
img: "defender2", img: "defender2",
faction: "Scoia'tael", faction: "Scoia'tael",
type: 0 type: 0
@ -423,13 +425,12 @@ module.exports = {
}, },
"eredin_commander_of_the_red_riders": { "eredin_commander_of_the_red_riders": {
name: "Eredin, Commander of the Red Riders", name: "Eredin, Commander of the Red Riders",
power: -1, power: -1,
ability: "eredin_leader1", ability: "eredin_leader1",
img: "eredin_commander", img: "eredin_commander",
faction: "Monster", faction: "monster",
type: 3 type: 3
}, },
"eredin_bringer_of_death": { "eredin_bringer_of_death": {
@ -437,7 +438,7 @@ module.exports = {
power: -1, power: -1,
ability: "eredin_leader2", ability: "eredin_leader2",
img: "eredin_bringer", img: "eredin_bringer",
faction: "Monster", faction: "monster",
type: 3 type: 3
}, },
"eredin_destroyer_of_worlds": { "eredin_destroyer_of_worlds": {
@ -445,7 +446,7 @@ module.exports = {
power: -1, power: -1,
ability: "eredin_leader3", ability: "eredin_leader3",
img: "eredin_destroyer", img: "eredin_destroyer",
faction: "Monster", faction: "monster",
type: 3 type: 3
}, },
"eredin_king_of_the_wild_hunt": { "eredin_king_of_the_wild_hunt": {
@ -453,7 +454,7 @@ module.exports = {
power: -1, power: -1,
ability: "eredin_leader4", ability: "eredin_leader4",
img: "eredin_king", img: "eredin_king",
faction: "Monster", faction: "monster",
type: 3 type: 3
}, },
"kayran": { "kayran": {
@ -461,7 +462,7 @@ module.exports = {
power: 8, power: 8,
ability: ["hero", "morale_boost"], ability: ["hero", "morale_boost"],
img: "kayran", img: "kayran",
faction: "Monster", faction: "monster",
type: 1 type: 1
}, },
"leshen": { "leshen": {
@ -469,7 +470,7 @@ module.exports = {
power: 10, power: 10,
ability: "hero", ability: "hero",
img: "leshen", img: "leshen",
faction: "Monster", faction: "monster",
type: 1 type: 1
}, },
"imlerith": { "imlerith": {
@ -477,7 +478,7 @@ module.exports = {
power: 10, power: 10,
ability: "hero", ability: "hero",
img: "imlerith", img: "imlerith",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"draug": { "draug": {
@ -485,23 +486,25 @@ module.exports = {
power: 10, power: 10,
ability: "hero", ability: "hero",
img: "draug", img: "draug",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"ghoul": { "ghoul": {
name: "Ghoul", name: "Ghoul",
power: 1, power: 1,
ability: "muster", ability: "muster",
musterType: "ghoul",
img: "ghoul1", img: "ghoul1",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"nekker": { "nekker": {
name: "Nekker", name: "Nekker",
power: 2, power: 2,
ability: "muster", ability: "muster",
musterType: "nekker",
img: "nekker", img: "nekker",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"wyvern": { "wyvern": {
@ -509,7 +512,7 @@ module.exports = {
power: 2, power: 2,
ability: null, ability: null,
img: "wyvern", img: "wyvern",
faction: "Monster", faction: "monster",
type: 1 type: 1
}, },
"foglet": { "foglet": {
@ -517,7 +520,7 @@ module.exports = {
power: 2, power: 2,
ability: null, ability: null,
img: "foglet", img: "foglet",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"celaeno_harpy": { "celaeno_harpy": {
@ -525,7 +528,7 @@ module.exports = {
power: 2, power: 2,
ability: null, ability: null,
img: "celaeno_harpy", img: "celaeno_harpy",
faction: "Monster", faction: "monster",
type: 1 type: 1
}, },
"gargoyle": { "gargoyle": {
@ -533,7 +536,7 @@ module.exports = {
power: 2, power: 2,
ability: null, ability: null,
img: "gargoyle", img: "gargoyle",
faction: "Monster", faction: "monster",
type: 1 type: 1
}, },
"cockatrice": { "cockatrice": {
@ -541,7 +544,7 @@ module.exports = {
power: 2, power: 2,
ability: null, ability: null,
img: "cockatrice", img: "cockatrice",
faction: "Monster", faction: "monster",
type: 1 type: 1
}, },
"harpy": { "harpy": {
@ -549,7 +552,7 @@ module.exports = {
power: 2, power: 2,
ability: "agile", ability: "agile",
img: "harpy", img: "harpy",
faction: "Monster", faction: "monster",
type: 1 type: 1
}, },
"endrega": { "endrega": {
@ -557,47 +560,52 @@ module.exports = {
power: 2, power: 2,
ability: null, ability: null,
img: "endrega", img: "endrega",
faction: "Monster", faction: "monster",
type: 1 type: 1
}, },
"vampire_bruxa": { "vampire_bruxa": {
name: "Vampire: Bruxa", name: "Vampire: Bruxa",
power: 4, power: 4,
ability: "muster", ability: "muster",
musterType: "vampire",
img: "vampire_bruxa", img: "vampire_bruxa",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"vampire_fleder": { "vampire_fleder": {
name: "Vampire: Fleder", name: "Vampire: Fleder",
power: 4, power: 4,
ability: "muster", ability: "muster",
musterType: "vampire",
img: "vampire_fleder", img: "vampire_fleder",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"vampire_garkain": { "vampire_garkain": {
name: "Vampire: Garkain", name: "Vampire: Garkain",
power: 4, power: 4,
ability: "muster", ability: "muster",
musterType: "vampire",
img: "vampire_garkain", img: "vampire_garkain",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"vampire_ekimmara": { "vampire_ekimmara": {
name: "Vampire: Ekimmara", name: "Vampire: Ekimmara",
power: 4, power: 4,
ability: "muster", ability: "muster",
musterType: "vampire",
img: "vampire_ekimmara", img: "vampire_ekimmara",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"arachas": { "arachas": {
name: "Arachas", name: "Arachas",
power: 4, power: 4,
ability: "muster", ability: "muster",
musterType: "arachas",
img: "arachas1", img: "arachas1",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"botchling": { "botchling": {
@ -605,7 +613,7 @@ module.exports = {
power: 4, power: 4,
ability: null, ability: null,
img: "botchling", img: "botchling",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"forktail": { "forktail": {
@ -613,7 +621,7 @@ module.exports = {
power: 5, power: 5,
ability: null, ability: null,
img: "forktail", img: "forktail",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"plague_maiden": { "plague_maiden": {
@ -621,7 +629,7 @@ module.exports = {
power: 5, power: 5,
ability: null, ability: null,
img: "forktail", img: "forktail",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"griffin": { "griffin": {
@ -629,7 +637,7 @@ module.exports = {
power: 5, power: 5,
ability: null, ability: null,
img: "griffin", img: "griffin",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"werewolf": { "werewolf": {
@ -637,7 +645,7 @@ module.exports = {
power: 5, power: 5,
ability: null, ability: null,
img: "werewolf", img: "werewolf",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"frightener": { "frightener": {
@ -645,7 +653,7 @@ module.exports = {
power: 5, power: 5,
ability: null, ability: null,
img: "frightener", img: "frightener",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"ice_giant": { "ice_giant": {
@ -653,7 +661,7 @@ module.exports = {
power: 5, power: 5,
ability: null, ability: null,
img: "ice_giant", img: "ice_giant",
faction: "Monster", faction: "monster",
type: 2 type: 2
}, },
"grave_hag": { "grave_hag": {
@ -661,47 +669,52 @@ module.exports = {
power: 5, power: 5,
ability: null, ability: null,
img: "grave_hag", img: "grave_hag",
faction: "Monster", faction: "monster",
type: 1 type: 1
}, },
/*"vampire_katakan": { /*"vampire_katakan": {
name: "Vampire: Katakan", name: "Vampire: Katakan",
power: 5, power: 5,
ability: "muster", ability: "muster",
musterType: "vampire",
img: "vampire_katakan", img: "vampire_katakan",
faction: "Monster", faction: "monster",
type: 0 type: 0
},*/ },*/
"crone_whispess": { "crone_whispess": {
name: "Crone: Whispess", name: "Crone: Whispess",
power: 6, power: 6,
ability: "muster", ability: "muster",
musterType: "crone",
img: "crone_whispess", img: "crone_whispess",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"crone_brewess": { "crone_brewess": {
name: "Crone: Brewess", name: "Crone: Brewess",
power: 6, power: 6,
ability: "muster", ability: "muster",
musterType: "crone",
img: "crone_brewess", img: "crone_brewess",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"crone_weavess": { "crone_weavess": {
name: "Crone: Weavess", name: "Crone: Weavess",
power: 6, power: 6,
ability: "muster", ability: "muster",
musterType: "crone",
img: "crone_weavess", img: "crone_weavess",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"arachas_behemoth": { "arachas_behemoth": {
name: "Arachas Behemoth", name: "Arachas Behemoth",
power: 6, power: 6,
ability: "muster", ability: "muster",
musterType: "arachas",
img: "arachas_behemoth", img: "arachas_behemoth",
faction: "Monster", faction: "monster",
type: 2 type: 2
}, },
"fire_elemental": { "fire_elemental": {
@ -709,7 +722,7 @@ module.exports = {
power: 6, power: 6,
ability: null, ability: null,
img: "fire_elemental", img: "fire_elemental",
faction: "Monster", faction: "monster",
type: 2 type: 2
}, },
"fiend": { "fiend": {
@ -717,7 +730,7 @@ module.exports = {
power: 6, power: 6,
ability: null, ability: null,
img: "fiend", img: "fiend",
faction: "Monster", faction: "monster",
type: 0 type: 0
}, },
"earth_elemental": { "earth_elemental": {
@ -725,7 +738,7 @@ module.exports = {
power: 6, power: 6,
ability: null, ability: null,
img: "earth_elemental", img: "earth_elemental",
faction: "Monster", faction: "monster",
type: 2 type: 2
} }
} }

View File

@ -1,6 +1,6 @@
module.exports = { module.exports = {
"test": [ "northern_realm": [
"redanian_foot_soldier", "redanian_foot_soldier",
"poor_fucking_infantry", "poor_fucking_infantry",
"redanian_foot_soldier", "redanian_foot_soldier",
@ -29,11 +29,8 @@ module.exports = {
"impenetrable_fog" "impenetrable_fog"
], ],
"Scoia'tael": [ "scoiatael": [
"francesca_pureblood_elf",
"francesca_the_beautiful",
"francesca_daisy_of_the_valley", "francesca_daisy_of_the_valley",
"francesca_queen_of_dol_blathanna",
"saesenthessis", "saesenthessis",
"iorveth", "iorveth",
"isengrim_faoiltiarnah", "isengrim_faoiltiarnah",
@ -41,17 +38,22 @@ module.exports = {
"havekar_healer", "havekar_healer",
"riordain", "riordain",
"toruviel", "toruviel",
"decoy",
"decoy",
"impenetrable_fog",
"elven_skirmisher", "elven_skirmisher",
"elven_skirmisher",
"dwarven_skirmisher",
"dwarven_skirmisher", "dwarven_skirmisher",
"ciaran_aep_easnillien", "ciaran_aep_easnillien",
"vrihedd_brigade_recruit", "vrihedd_brigade_recruit",
"dol_blathanna_archer", "dol_blathanna_archer",
//"hav_caaren_medic",
"havekar_smuggler", "havekar_smuggler",
"mahakaman_defender", "mahakaman_defender",
"vrihedd_brigade_veteran", "vrihedd_brigade_veteran",
"dennis_cranmer", "dennis_cranmer",
"filavandrel_aen_fidhail", "filavandrel_aen_fidhail",
"filavandrel_aen_fidhail",
"ida_emean_aep_sivney", "ida_emean_aep_sivney",
"yaevinn", "yaevinn",
"barclay_els", "barclay_els",
@ -60,15 +62,15 @@ module.exports = {
], ],
"monster": [ "monster": [
"eredin_commander_of_the_red_riders",
"eredin_bringer_of_death",
"eredin_destroyer_of_worlds",
"eredin_king_of_the_wild_hunt", "eredin_king_of_the_wild_hunt",
"kayran", "kayran",
"leshen", "leshen",
"imlerith", "imlerith",
"draug", "draug",
"ghoul", "ghoul",
"decoy",
"decoy",
"nekker",
"nekker", "nekker",
"wyvern", "wyvern",
"foglet", "foglet",
@ -76,10 +78,15 @@ module.exports = {
"gargoyle", "gargoyle",
"cockatrice", "cockatrice",
"harpy", "harpy",
"impenetrable_fog",
"endrega", "endrega",
"vampire_bruxa", "vampire_bruxa",
"vampire_bruxa",
"vampire_fleder",
"vampire_fleder", "vampire_fleder",
"vampire_garkain", "vampire_garkain",
"vampire_garkain",
"vampire_ekimmara",
"vampire_ekimmara", "vampire_ekimmara",
"arachas", "arachas",
"botchling", "botchling",
@ -92,7 +99,10 @@ module.exports = {
"grave_hag", "grave_hag",
//"vampire_katakan", //"vampire_katakan",
"crone_whispess", "crone_whispess",
"crone_whispess",
"crone_brewess", "crone_brewess",
"crone_brewess",
"crone_weavess",
"crone_weavess", "crone_weavess",
"arachas_behemoth", "arachas_behemoth",
"fire_elemental", "fire_elemental",

View File

@ -40,9 +40,24 @@ gulp.task('sass', function(){
})); }));
}); });
gulp.task("unit tests", function(){
browserify('./test/spec/mainSpec.js', {standalone: "app", debug: true})
.transform(babelify)
.bundle().on("error", function(err){
console.log(err);
})
.pipe(source('spec.js').on("error", function(err){
console.log(err);
}))
.pipe(gulp.dest('./test/spec/').on("error", function(err){
console.log(err);
}));
})
gulp.task("watch", function(){ gulp.task("watch", function(){
gulp.watch("./public/js/*", ["browserify"]); gulp.watch("./public/js/*", ["browserify"]);
gulp.watch("./public/scss/*", ["sass"]); gulp.watch("./public/scss/*", ["sass"]);
gulp.watch("./test/spec/*", ["unit tests"]);
}) })
gulp.task("default", ["watch", "browserify", "sass"]); gulp.task("default", ["watch", "browserify", "sass", "unit tests"]);

View File

@ -160,6 +160,11 @@
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<input type="text" class="name-input" value="{{name}}"> <input type="text" class="name-input" value="{{name}}">
<select id="deckChoice">
<option value="northern_realm">Deck: Northern Realms</option>
<option value="scoiatael">Deck: Scoia'tael</option>
<option value="monster">Deck: Monster</option>
</select>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
@ -213,6 +218,21 @@
<div class="bbm-button bbm-close">close</div> <div class="bbm-button bbm-close">close</div>
</div> </div>
</script> </script>
<script type="text/template" id="modal-medic-template">
<div class="bbm-modal__topbar">
<h3 class="bbm-modal__title">Choose one card from your discard</h3>
</div>
<div class="bbm-modal__section">
{{#each medicDiscard.cards}}
<div class="card" data-key="{{_key}}" data-id="{{_id}}">
<img src="../assets/cards/{{_data.img}}.png">
</div>
{{/each}}
</div>
<div class="bbm-modal__bottombar">
<div class="bbm-button bbm-close">close</div>
</div>
</script>
<script type="text/template" id="preview-template"> <script type="text/template" id="preview-template">
<img src="{{src}}"> <img src="{{src}}">
</script> </script>

View File

@ -18,10 +18,12 @@ var Lobby = Backbone.View.extend({
events: { events: {
"click .create-room": "createRoom", "click .create-room": "createRoom",
"click .join-room": "joinRoom", "click .join-room": "joinRoom",
"blur .name-input": "changeName" "blur .name-input": "changeName",
"change #deckChoice": "setDeck"
}, },
render: function(){ render: function(){
this.$el.html(this.template(this.app.user.attributes)); this.$el.html(this.template(this.app.user.attributes));
//this.$el.find("#deckChoice option[value='" + this.app.user.get("setDeck") + "']").attr("selected", "selected")
return this; return this;
}, },
createRoom: function(){ createRoom: function(){
@ -30,6 +32,10 @@ var Lobby = Backbone.View.extend({
joinRoom: function(){ joinRoom: function(){
this.app.send("request:joinRoom"); this.app.send("request:joinRoom");
}, },
setDeck: function(e){
var val = $(e.target).val();
this.app.user.setDeck(val);
},
changeName: function(e){ changeName: function(e){
var name = $(e.target).val(); var name = $(e.target).val();
this.app.user.setName(name); this.app.user.setName(name);

View File

@ -304,7 +304,8 @@ var BattleView = Backbone.View.extend({
var side; var side;
if($discard.parent().hasClass("player")){ if($discard.parent().hasClass("player")){
side = this.yourSide; side = this.yourSide;
} else { }
else {
side = this.otherSide; side = this.otherSide;
} }
this.user.set("openDiscard", { this.user.set("openDiscard", {
@ -327,6 +328,10 @@ var BattleView = Backbone.View.extend({
var modal = new Modal({model: this.user}); var modal = new Modal({model: this.user});
this.$el.prepend(modal.render().el); this.$el.prepend(modal.render().el);
} }
if(this.user.get("medicDiscard")){
var modal = new MedicModal({model: this.user});
this.$el.prepend(modal.render().el);
}
if(this.user.get("waitForDecoy")){ if(this.user.get("waitForDecoy")){
var id = this.user.get("waitForDecoy"); var id = this.user.get("waitForDecoy");
@ -402,9 +407,29 @@ var Modal = Backbone.Modal.extend({
} }
}); });
var MedicModal = Modal.extend({
template: Handlebars.compile($("#modal-medic-template").html()),
events: {
"click .card": "onCardClick"
},
onCardClick: function(e){
console.log($(e.target).closest(".card"));
var id = $(e.target).closest(".card").data().id;
this.model.get("app").send("medic:chooseCardFromDiscard", {
cardID: id
})
this.model.set("medicDiscard", false);
},
cancel: function(){
this.model.get("app").send("medic:chooseCardFromDiscard")
this.model.set("medicDiscard", false);
}
});
var User = Backbone.Model.extend({ var User = Backbone.Model.extend({
defaults: { defaults: {
name: "" name: "",
deckKey: "northern_realm"
}, },
initialize: function(){ initialize: function(){
var self = this; var self = this;
@ -449,10 +474,19 @@ var User = Backbone.Model.extend({
$(".container").prepend('<div class="alert alert-danger">Your foe left the battle!</div>') $(".container").prepend('<div class="alert alert-danger">Your foe left the battle!</div>')
}) })
app.receive("played:medic", function(data){
var cards = JSON.parse(data.cards);
console.log("played medic");
self.set("medicDiscard", {
cards: cards
});
})
app.on("createRoom", this.createRoom, this); app.on("createRoom", this.createRoom, this);
app.on("joinRoom", this.joinRoom, this); app.on("joinRoom", this.joinRoom, this);
app.on("setName", this.setName, this); app.on("setName", this.setName, this);
app.on("setDeck", this.setDeck, this);
app.send("request:name", this.get("name") == "unnamed" ? null : {name: this.get("name")}); app.send("request:name", this.get("name") == "unnamed" ? null : {name: this.get("name")});
@ -470,6 +504,11 @@ var User = Backbone.Model.extend({
}, },
setName: function(name){ setName: function(name){
this.get("app").send("request:name", {name: name}); this.get("app").send("request:name", {name: name});
},
setDeck: function(deckKey){
console.log("deck: ", deckKey);
this.set("deckKey", deckKey);
this.get("app").send("set:deck", {deck: deckKey});
} }
}); });
@ -490,10 +529,12 @@ var Lobby = Backbone.View.extend({
events: { events: {
"click .create-room": "createRoom", "click .create-room": "createRoom",
"click .join-room": "joinRoom", "click .join-room": "joinRoom",
"blur .name-input": "changeName" "blur .name-input": "changeName",
"change #deckChoice": "setDeck"
}, },
render: function(){ render: function(){
this.$el.html(this.template(this.user.attributes)); this.$el.html(this.template(this.user.attributes));
/*this.$el.find("#deckChoice option[value='" + this.app.user.get("setDeck") + "']").attr("selected", "selected")*/
return this; return this;
}, },
createRoom: function(){ createRoom: function(){
@ -502,6 +543,11 @@ var Lobby = Backbone.View.extend({
joinRoom: function(){ joinRoom: function(){
this.app.trigger("joinRoom"); this.app.trigger("joinRoom");
}, },
setDeck: function(e){
var val = $(e.target).val();
this.app.trigger("setDeck", val);
this.$el.find("#deckChoice option[value='" + val + "']").attr("selected", "selected")
},
changeName: function(e){ changeName: function(e){
var name = $(e.target).val(); var name = $(e.target).val();
this.app.trigger("setName", name); this.app.trigger("setName", name);

View File

@ -39,7 +39,8 @@ var Battle = (function(){
r.init = function(){ r.init = function(){
/*PubSub.subscribe("update", this.update.bind(this));*/ /*PubSub.subscribe("update", this.update.bind(this));*/
this.on("Update", this.update); this.on("Update", this.update);/*
this.on("AfterPlace", this.checkAbilityOnAfterPlace)*/
this.channel = this.socket.subscribe(this._id); this.channel = this.socket.subscribe(this._id);
@ -56,13 +57,20 @@ var Battle = (function(){
r.start = function(){ r.start = function(){
this.p1.setLeadercard(); this.p1.setLeadercard();
this.p2.setLeadercard(); this.p2.setLeadercard();
this.p1.draw(10); this.p1.draw(5);
this.p2.draw(10); this.p2.draw(5);
this.p1.hand.add(Card("dun_banner_medic"));
this.p2.hand.add(Card("dun_banner_medic"));
this.p1.hand.add(Card("isengrim_faoiltiarnah"));
this.p2.hand.add(Card("isengrim_faoiltiarnah"));
this.p1.addToDiscard([Card("kaedweni_siege_expert")]);
this.p2.addToDiscard([Card("kaedweni_siege_expert")]);
/*
this.p1.hand.add(Card("decoy")); this.p1.hand.add(Card("decoy"));
this.p1.hand.add(Card("impenetrable_fog")); this.p1.hand.add(Card("impenetrable_fog"));
this.p2.hand.add(Card("decoy")); this.p2.hand.add(Card("decoy"));
this.p2.hand.add(Card("impenetrable_fog")); this.p2.hand.add(Card("impenetrable_fog"));*/
this.update(); this.update();

View File

@ -1,9 +1,9 @@
var io = global.io;
var DeckData = require("../assets/data/deck"); var DeckData = require("../assets/data/deck");
var Deck = require("./Deck"); var Deck = require("./Deck");
var Hand = require("./Hand"); var Hand = require("./Hand");
var Card = require("./Card"); var Card = require("./Card");
var Field = require("./Field"); var Field = require("./Field");
var _ = require("underscore");
var Battleside; var Battleside;
@ -16,6 +16,7 @@ Battleside = (function(){
* constructor here * constructor here
*/ */
var deck = user.getDeck();
var self = this; var self = this;
this._isWaiting = true; this._isWaiting = true;
this.socket = user.socket; this.socket = user.socket;
@ -28,7 +29,7 @@ Battleside = (function(){
this._name = name; this._name = name;
this.battle = battle; this.battle = battle;
this.hand = Hand(); this.hand = Hand();
this.deck = Deck(DeckData["test"]); this.deck = Deck(DeckData[deck]);
this._discard = []; this._discard = [];
this.runEvent = this.battle.runEvent.bind(this.battle); this.runEvent = this.battle.runEvent.bind(this.battle);
@ -74,6 +75,20 @@ Battleside = (function(){
self.update(); self.update();
self.runEvent("NextTurn", null, [self.foe]); self.runEvent("NextTurn", null, [self.foe]);
}) })
this.receive("medic:chooseCardFromDiscard", function(data){
if(!data){
self.runEvent("NextTurn", null, [self.foe]);
return;
}
var cardID = data.cardID;
var card = self.getCardFromDiscard(cardID);
if(card === -1) throw new Error("medic:chooseCardFromDiscard | unknown card: ", card);
self.removeFromDiscard(card);
self.playCard(card);
})
this.on("Turn" + this.getID(), this.onTurnStart, this); this.on("Turn" + this.getID(), this.onTurnStart, this);
}; };
@ -115,6 +130,19 @@ Battleside = (function(){
var card = field.getCard(id); var card = field.getCard(id);
if(card !== -1) return card; if(card !== -1) return card;
} }
/*
for(var i = 0; i < this._discard.length; i++) {
var c = this._discard[i];
if(c.getID() === id) return c;
}*/
return -1;
}
r.getCardFromDiscard = function(id){
for(var i = 0; i < this._discard.length; i++) {
var c = this._discard[i];
if(c.getID() === id) return c;
}
return -1; return -1;
} }
@ -237,8 +265,8 @@ Battleside = (function(){
this.runEvent("NextTurn", null, [this.foe]); this.runEvent("NextTurn", null, [this.foe]);
} }
r.placeCard = function(card){ r.placeCard = function(card, obj){
var obj = {}; obj = _.extend({}, obj);
this.checkAbilities(card, obj); this.checkAbilities(card, obj);
if(obj._canclePlacement) return 0; if(obj._canclePlacement) return 0;
@ -246,13 +274,21 @@ Battleside = (function(){
var field = obj.targetSide.field[card.getType()]; var field = obj.targetSide.field[card.getType()];
field.add(card); field.add(card);
//PubSub.publish("onEachCardPlace");
this.runEvent("OnEachCardPlace");
this.checkAbilityOnAfterPlace(card); this.runEvent("EachCardPlace");
this.checkAbilityOnAfterPlace(card, obj);
/*
this.runEvent("AfterPlace", this, [card, obj]);*/
this.update(); this.update();
if(obj._waitResponse){
this.hand.remove(card);
this.update();
return 0;
}
return 1; return 1;
} }
@ -260,6 +296,7 @@ Battleside = (function(){
var self = this; var self = this;
obj.targetSide = this; obj.targetSide = this;
var ability = Array.isArray(__flag) || card.getAbility(); var ability = Array.isArray(__flag) || card.getAbility();
if(Array.isArray(ability) && ability.length){ if(Array.isArray(ability) && ability.length){
var ret = ability.slice(); var ret = ability.slice();
ret = ret.splice(0, 1); ret = ret.splice(0, 1);
@ -267,8 +304,14 @@ Battleside = (function(){
ability = ability[0]; ability = ability[0];
} }
if(ability && !Array.isArray(ability)){/* if(ability && ability.name === obj.suppress){
var ability = card.getAbility();*/ this.update();
}
if(ability && !Array.isArray(ability)){
if(ability.waitResponse){
obj._waitResponse = true;
}
if(ability.changeSide){ if(ability.changeSide){
obj.targetSide = this.foe; obj.targetSide = this.foe;
} }
@ -307,9 +350,13 @@ Battleside = (function(){
} }
} }
r.checkAbilityOnAfterPlace = function(card){ r.checkAbilityOnAfterPlace = function(card, obj){
var ability = card.getAbility(); var ability = card.getAbility();
if(ability){ if(ability){
if(ability.name && ability.name === obj.suppress){
this.update();
return;
}
if(ability.onAfterPlace){ if(ability.onAfterPlace){
ability.onAfterPlace.call(this, card) ability.onAfterPlace.call(this, card)
} }
@ -332,6 +379,17 @@ Battleside = (function(){
}); });
} }
r.removeFromDiscard = function(card){
for(var i = 0; i < this._discard.length; i++) {
var c = this._discard[i];
if(c.getID() === card.getID()){
this._discard.splice(i, 1);
return
}
}
}
r.getDiscard = function(json){ r.getDiscard = function(json){
if(json){ if(json){
return JSON.stringify(this._discard); return JSON.stringify(this._discard);
@ -344,6 +402,38 @@ Battleside = (function(){
this.setPassing(false); this.setPassing(false);
} }
r.filter = function(arrCards, opt){
var arr = arrCards.slice();
for(var key in opt) {
var res = [];
var prop = key, val = opt[key];
arrCards.forEach(function(card){
var property = card.getProperty(prop);
if(_.isArray(property)){
var _f = false;
for(var i = 0; i < property.length; i++) {
if(property[i] === val) {
_f = true;
break;
}
}
if(!_f){
res.push(card);
}
}
else if(card.getProperty(prop) !== val){
res.push(card);
}
})
arr = _.intersection(arr, res);
}
return arr;
}
return Battleside; return Battleside;
})(); })();

View File

@ -91,6 +91,9 @@ var Card = (function(){
r.getFaction = function(){ r.getFaction = function(){
return this._data.faction; return this._data.faction;
} }
r.getMusterType = function() {
return this._data.musterType || null;
}
r.getType = function(){ r.getType = function(){
return this._data.type; return this._data.type;
} }
@ -116,9 +119,14 @@ var Card = (function(){
} }
r.getProperty = function(prop){ r.getProperty = function(prop){
if(!this._data[prop]) return {};
return this._data[prop]; return this._data[prop];
} }
r.resetBoost = function() {
this._boost = 0;
}
return Card; return Card;
})(); })();

View File

@ -78,11 +78,6 @@ var Deck = (function(){
var n = this.length(); var n = this.length();
for(var i = 0; i < n; i++) { for(var i = 0; i < n; i++) {
/*var cardID = this.getDeck()[i];
if(id == cardID){
this.getDeck().splice(i, 1);
return id;
}*/
var c = this.getDeck()[i]; var c = this.getDeck()[i];
if(c.getID() === card.getID()){ if(c.getID() === card.getID()){
return this.getDeck().splice(i, 1)[0]; return this.getDeck().splice(i, 1)[0];

View File

@ -51,6 +51,7 @@ var Field = (function(){
r.replaceWith = function(oldCard, newCard){ r.replaceWith = function(oldCard, newCard){
var index = this.getPosition(oldCard); var index = this.getPosition(oldCard);
this._cards[index] = newCard; this._cards[index] = newCard;
oldCard.resetBoost();
return oldCard; return oldCard;
} }
@ -64,6 +65,9 @@ var Field = (function(){
r.removeAll = function() { r.removeAll = function() {
var tmp = this._cards.slice(); var tmp = this._cards.slice();
tmp.forEach(function(card) {
card.resetBoost();
})
this._cards = []; this._cards = [];
return tmp; return tmp;
} }

View File

@ -49,6 +49,7 @@ var Hand = (function(){
if(this._hand[i].getID() != id) continue; if(this._hand[i].getID() != id) continue;
return this._hand.splice(i, 1); return this._hand.splice(i, 1);
} }
return -1; return -1;
} }
@ -65,6 +66,16 @@ var Hand = (function(){
return this._hand.length; return this._hand.length;
} }
r.find = function(key, val) {
var res = [];
this._hand.forEach(function(card){
if(card.getProperty(key) == val){
res.push(card);
}
});
return res;
}
return Hand; return Hand;
})(); })();

View File

@ -74,6 +74,15 @@ var User = (function(){
return this._rooms[0]; return this._rooms[0];
} }
r.setDeck = function(deck) {
console.log("set deck: ", deck);
this._deck = deck;
}
r.getDeck = function() {
return this._deck || "northern_realm";
}
r.addRoom = function(room) { r.addRoom = function(room) {
this._rooms.push(room); this._rooms.push(room);
} }

View File

@ -35,6 +35,13 @@ module.exports.run = function(worker){
socket.emit("response:name", {name: user.getName()}); socket.emit("response:name", {name: user.getName()});
}) })
socket.on("set:deck", function(data) {
console.log(data);
if(data && data.deck){
user.setDeck(data.deck);
}
})
socket.on("request:gameLoaded", function(data){ socket.on("request:gameLoaded", function(data){
console.log(data); console.log(data);
connections.roomCollection[data._roomID].setReady(user); connections.roomCollection[data._roomID].setReady(user);

View File

@ -17,6 +17,7 @@
<!-- include spec files here... --> <!-- include spec files here... -->
<script src="spec/SpecHelper.js"></script> <script src="spec/SpecHelper.js"></script>
<script src="spec/PubSubSpec.js"></script> <script src="spec/PubSubSpec.js"></script>
<script src="spec/spec.js"></script>
</head> </head>

33
test/spec/filterSpec.js Normal file
View File

@ -0,0 +1,33 @@
var Card = require("../../server/Card");
var Battleside = require("../../server/Battleside");
var data = require("../../assets/data/abilities");
describe("filter", function(){
var card, side, filter, cards;
beforeEach(function(){
filter = Battleside.prototype.filter;
cards = [];
cards.push(Card("iorveth"));
cards.push(Card("toruviel"));
cards.push(Card("isengrim_faoiltiarnah"));
cards.push(Card("decoy"));
})
it("it should filter heroes out", function(){
var res = filter(cards, {
"ability": "hero"
})
expect(res.length).toBe(2);
})
it("it should filter hero and special cards out", function(){
var res = filter(cards, {
"ability": "hero",
"type": Card.TYPE.SPECIAL
})
expect(res.length).toBe(1);
})
})

5
test/spec/mainSpec.js Normal file
View File

@ -0,0 +1,5 @@
require("./filterSpec");
(function main(){
})();

3360
test/spec/spec.js Normal file

File diff suppressed because one or more lines are too long