mirror of
https://github.com/exane/not-gwent-online
synced 2024-10-31 10:36:53 +00:00
fix morale boost + improved events
This commit is contained in:
parent
2c307a4fb8
commit
730e8f714a
@ -2,10 +2,10 @@ module.exports = {
|
|||||||
|
|
||||||
"agile": {
|
"agile": {
|
||||||
cancelPlacement: true,
|
cancelPlacement: true,
|
||||||
onBeforePlace: function(card) {
|
onBeforePlace: function(card){
|
||||||
var self = this;
|
var self = this;
|
||||||
this.send("played:agile", {cardID: card.getID()}, true);
|
this.send("played:agile", {cardID: card.getID()}, true);
|
||||||
this.on("agile:setField", function(type) {
|
this.on("agile:setField", function(type){
|
||||||
self.off("agile:setField");
|
self.off("agile:setField");
|
||||||
card.changeType(type)
|
card.changeType(type)
|
||||||
self.placeCard(card, {
|
self.placeCard(card, {
|
||||||
@ -17,7 +17,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
"medic": {
|
"medic": {
|
||||||
waitResponse: true,
|
waitResponse: true,
|
||||||
onAfterPlace: function(card) {
|
onAfterPlace: function(card){
|
||||||
var discard = this.getDiscard();
|
var discard = this.getDiscard();
|
||||||
|
|
||||||
discard = this.filter(discard, {
|
discard = this.filter(discard, {
|
||||||
@ -31,14 +31,24 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"morale_boost": {
|
"morale_boost": {
|
||||||
onAfterPlace: function(card) {
|
|
||||||
var field = this.field[card.getType()];
|
|
||||||
var cards = field.get();
|
|
||||||
|
|
||||||
cards.forEach(function(_card) {
|
onEachCardPlace: function(card){
|
||||||
if(_card.getID() == card.getID()) return;
|
var field = this.field[card.getType()];
|
||||||
if(_card.getRawPower() === -1) return;
|
var id = card.getID();
|
||||||
_card.boost(1);
|
if(!field.isOnField(card)){
|
||||||
|
field.get().forEach(function(_card){
|
||||||
|
if(_card.getID() == id) return;
|
||||||
|
if(_card.getType() != card.getType()) return;
|
||||||
|
_card.setBoost(id, 0);
|
||||||
|
})
|
||||||
|
this.off("EachCardPlace", card.getUidEvents("EachCardPlace"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
field.get().forEach(function(_card){
|
||||||
|
if(_card.getID() == id) return;
|
||||||
|
if(_card.getType() != card.getType()) return;
|
||||||
|
_card.setBoost(id, 1);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -51,13 +61,13 @@ module.exports = {
|
|||||||
var cardsDeck = this.deck.find("musterType", musterType);
|
var cardsDeck = this.deck.find("musterType", musterType);
|
||||||
var cardsHand = this.hand.find("musterType", musterType);
|
var cardsHand = this.hand.find("musterType", musterType);
|
||||||
|
|
||||||
cardsDeck.forEach(function(_card) {
|
cardsDeck.forEach(function(_card){
|
||||||
self.deck.removeFromDeck(_card);
|
self.deck.removeFromDeck(_card);
|
||||||
self.placeCard(_card, {
|
self.placeCard(_card, {
|
||||||
suppress: "muster"
|
suppress: "muster"
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
cardsHand.forEach(function(_card) {
|
cardsHand.forEach(function(_card){
|
||||||
self.hand.remove(_card);
|
self.hand.remove(_card);
|
||||||
self.placeCard(_card, {
|
self.placeCard(_card, {
|
||||||
suppress: "muster"
|
suppress: "muster"
|
||||||
@ -86,7 +96,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"weather_fog": {
|
"weather_fog": {
|
||||||
onEachTurn: function(card) {
|
onEachTurn: function(card){
|
||||||
var targetRow = card.constructor.TYPE.RANGED;
|
var targetRow = card.constructor.TYPE.RANGED;
|
||||||
var forcedPower = 1;
|
var forcedPower = 1;
|
||||||
var field1 = this.field[targetRow].get();
|
var field1 = this.field[targetRow].get();
|
||||||
@ -94,12 +104,12 @@ module.exports = {
|
|||||||
|
|
||||||
var field = field1.concat(field2);
|
var field = field1.concat(field2);
|
||||||
|
|
||||||
field.forEach(function(_card) {
|
field.forEach(function(_card){
|
||||||
if(_card.getRawAbility() == "hero") return;
|
if(_card.getRawAbility() == "hero") return;
|
||||||
_card.setForcedPower(forcedPower);
|
_card.setForcedPower(forcedPower);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onEachCardPlace: function(card) {
|
onEachCardPlace: function(card){
|
||||||
var targetRow = card.constructor.TYPE.RANGED;
|
var targetRow = card.constructor.TYPE.RANGED;
|
||||||
var forcedPower = 1;
|
var forcedPower = 1;
|
||||||
var field1 = this.field[targetRow].get();
|
var field1 = this.field[targetRow].get();
|
||||||
@ -107,14 +117,14 @@ module.exports = {
|
|||||||
|
|
||||||
var field = field1.concat(field2);
|
var field = field1.concat(field2);
|
||||||
|
|
||||||
field.forEach(function(_card) {
|
field.forEach(function(_card){
|
||||||
if(_card.getRawAbility() == "hero") return;
|
if(_card.getRawAbility() == "hero") return;
|
||||||
_card.setForcedPower(forcedPower);
|
_card.setForcedPower(forcedPower);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"weather_rain": {
|
"weather_rain": {
|
||||||
onEachTurn: function(card) {
|
onEachTurn: function(card){
|
||||||
var targetRow = card.constructor.TYPE.SIEGE;
|
var targetRow = card.constructor.TYPE.SIEGE;
|
||||||
var forcedPower = 1;
|
var forcedPower = 1;
|
||||||
var field1 = this.field[targetRow].get();
|
var field1 = this.field[targetRow].get();
|
||||||
@ -122,7 +132,7 @@ module.exports = {
|
|||||||
|
|
||||||
var field = field1.concat(field2);
|
var field = field1.concat(field2);
|
||||||
|
|
||||||
field.forEach(function(_card) {
|
field.forEach(function(_card){
|
||||||
if(_card.getRawAbility() == "hero") return;
|
if(_card.getRawAbility() == "hero") return;
|
||||||
_card.setForcedPower(forcedPower);
|
_card.setForcedPower(forcedPower);
|
||||||
});
|
});
|
||||||
@ -130,7 +140,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"weather_frost": {
|
"weather_frost": {
|
||||||
onEachTurn: function(card) {
|
onEachTurn: function(card){
|
||||||
var targetRow = card.constructor.TYPE.CLOSE_COMBAT;
|
var targetRow = card.constructor.TYPE.CLOSE_COMBAT;
|
||||||
var forcedPower = 1;
|
var forcedPower = 1;
|
||||||
var field1 = this.field[targetRow].get();
|
var field1 = this.field[targetRow].get();
|
||||||
@ -138,7 +148,7 @@ module.exports = {
|
|||||||
|
|
||||||
var field = field1.concat(field2);
|
var field = field1.concat(field2);
|
||||||
|
|
||||||
field.forEach(function(_card) {
|
field.forEach(function(_card){
|
||||||
if(_card.getRawAbility() == "hero") return;
|
if(_card.getRawAbility() == "hero") return;
|
||||||
_card.setForcedPower(forcedPower);
|
_card.setForcedPower(forcedPower);
|
||||||
});
|
});
|
||||||
@ -146,7 +156,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"clear_weather": {
|
"clear_weather": {
|
||||||
onAfterPlace: function(card) {
|
onAfterPlace: function(card){
|
||||||
var targetRow = card.constructor.TYPE.WEATHER;
|
var targetRow = card.constructor.TYPE.WEATHER;
|
||||||
var field = this.field[targetRow].get();
|
var field = this.field[targetRow].get();
|
||||||
|
|
||||||
@ -157,38 +167,20 @@ module.exports = {
|
|||||||
replaceWith: true
|
replaceWith: true
|
||||||
},
|
},
|
||||||
"foltest_leader1": {
|
"foltest_leader1": {
|
||||||
onActivate: function() {
|
onActivate: function(){
|
||||||
var cards = this.deck.find("key", "impenetrable_fog")
|
var cards = this.deck.find("key", "impenetrable_fog")
|
||||||
if(!cards.length) return;
|
if(!cards.length) return;
|
||||||
var card = this.deck.removeFromDeck(cards[0]);
|
var card = this.deck.removeFromDeck(cards[0]);
|
||||||
this.placeCard(card);
|
this.placeCard(card);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"francesca_leader1": {
|
"francesca_leader1": {},
|
||||||
|
"francesca_leader2": {},
|
||||||
},
|
"francesca_leader3": {},
|
||||||
"francesca_leader2": {
|
"francesca_leader4": {},
|
||||||
|
"eredin_leader1": {},
|
||||||
},
|
"eredin_leader2": {},
|
||||||
"francesca_leader3": {
|
"eredin_leader3": {},
|
||||||
|
"eredin_leader4": {},
|
||||||
},
|
"hero": {}
|
||||||
"francesca_leader4": {
|
|
||||||
|
|
||||||
},
|
|
||||||
"eredin_leader1": {
|
|
||||||
|
|
||||||
},
|
|
||||||
"eredin_leader2": {
|
|
||||||
|
|
||||||
},
|
|
||||||
"eredin_leader3": {
|
|
||||||
|
|
||||||
},
|
|
||||||
"eredin_leader4": {
|
|
||||||
|
|
||||||
},
|
|
||||||
"hero": {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -105,7 +105,7 @@ var SideView = Backbone.View.extend({
|
|||||||
'</div>'),
|
'</div>'),
|
||||||
templateCards: Handlebars.compile('{{#each this}}' +
|
templateCards: Handlebars.compile('{{#each this}}' +
|
||||||
'<div class="card{{#if _disabled}} disabled{{/if}}" data-key="{{_key}}" data-id="{{_id}}">' +
|
'<div class="card{{#if _disabled}} disabled{{/if}}" data-key="{{_key}}" data-id="{{_id}}">' +
|
||||||
'{{#if _boost}}<span>+{{_boost}}</span>{{/if}}' +
|
'{{#if boost}}<span>+{{boost}}</span>{{/if}}' +
|
||||||
'<img src="../assets/cards/{{_data.img}}.png">' +
|
'<img src="../assets/cards/{{_data.img}}.png">' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'{{/each}}'),
|
'{{/each}}'),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
var Battleside = require("./Battleside");
|
var Battleside = require("./Battleside");
|
||||||
var Card = require("./Card");
|
var Card = require("./Card");
|
||||||
|
var shortid = require("shortid");
|
||||||
|
|
||||||
|
|
||||||
var Battle = (function(){
|
var Battle = (function(){
|
||||||
@ -39,7 +40,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.on("AfterPlace", this.checkAbilityOnAfterPlace)*/
|
||||||
|
|
||||||
|
|
||||||
@ -57,11 +59,23 @@ 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("kaedweni_siege_expert"));
|
this.p1.hand.add(Card("kaedweni_siege_expert"));
|
||||||
this.p2.hand.add(Card("kaedweni_siege_expert"));
|
this.p2.hand.add(Card("kaedweni_siege_expert"));
|
||||||
|
this.p1.hand.add(Card("ballista"));
|
||||||
|
this.p2.hand.add(Card("ballista"));
|
||||||
|
this.p1.hand.add(Card("ballista"));
|
||||||
|
this.p2.hand.add(Card("ballista"));
|
||||||
|
this.p1.hand.add(Card("ballista"));
|
||||||
|
this.p2.hand.add(Card("ballista"));
|
||||||
|
this.p1.hand.add(Card("ballista"));
|
||||||
|
this.p2.hand.add(Card("ballista"));
|
||||||
|
this.p1.hand.add(Card("ballista"));
|
||||||
|
this.p2.hand.add(Card("ballista"));
|
||||||
|
this.p1.hand.add(Card("decoy"));
|
||||||
|
this.p2.hand.add(Card("decoy"));
|
||||||
/*
|
/*
|
||||||
this.p1.hand.add(Card("dun_banner_medic"));
|
this.p1.hand.add(Card("dun_banner_medic"));
|
||||||
this.p2.hand.add(Card("dun_banner_medic"));
|
this.p2.hand.add(Card("dun_banner_medic"));
|
||||||
@ -70,7 +84,7 @@ var Battle = (function(){
|
|||||||
|
|
||||||
/*this.p1.addToDiscard([Card("kaedweni_siege_expert")]);
|
/*this.p1.addToDiscard([Card("kaedweni_siege_expert")]);
|
||||||
this.p2.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"));
|
||||||
@ -151,19 +165,28 @@ var Battle = (function(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
r.runEvent = function(eventid, ctx, args){
|
r.runEvent = function(eventid, ctx, args, uid){
|
||||||
ctx = ctx || this;
|
ctx = ctx || this;
|
||||||
|
uid = uid || null;
|
||||||
args = args || [];
|
args = args || [];
|
||||||
var event = "on" + eventid;
|
var event = "on" + eventid;
|
||||||
|
|
||||||
if(!this.events[event]){
|
if(!this.events[event]){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.events[event].forEach(function(e){
|
|
||||||
var obj = e;
|
if(uid){
|
||||||
|
var obj = this.events[event][uid];
|
||||||
obj.cb = obj.cb.bind(ctx)
|
obj.cb = obj.cb.bind(ctx)
|
||||||
obj.cb.apply(ctx, obj.onArgs.concat(args));
|
obj.cb.apply(ctx, obj.onArgs.concat(args));
|
||||||
});
|
}
|
||||||
|
else {
|
||||||
|
for(var _uid in this.events[event]) {
|
||||||
|
var obj = this.events[event][_uid];
|
||||||
|
obj.cb = obj.cb.bind(ctx)
|
||||||
|
obj.cb.apply(ctx, obj.onArgs.concat(args));
|
||||||
|
}
|
||||||
|
}
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +194,7 @@ var Battle = (function(){
|
|||||||
ctx = ctx || null;
|
ctx = ctx || null;
|
||||||
args = args || [];
|
args = args || [];
|
||||||
var event = "on" + eventid;
|
var event = "on" + eventid;
|
||||||
|
var uid_event = shortid.generate();
|
||||||
|
|
||||||
var obj = {};
|
var obj = {};
|
||||||
if(!ctx){
|
if(!ctx){
|
||||||
@ -182,29 +206,32 @@ var Battle = (function(){
|
|||||||
obj.onArgs = args;
|
obj.onArgs = args;
|
||||||
|
|
||||||
if(!(event in this.events)){
|
if(!(event in this.events)){
|
||||||
this.events[event] = [];
|
/*this.events[event] = [];*/
|
||||||
|
this.events[event] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof cb !== "function"){
|
if(typeof cb !== "function"){
|
||||||
throw new Error("cb not a function");
|
throw new Error("cb not a function");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(args){
|
this.events[event][uid_event] = obj;
|
||||||
this.events[event].push(obj);
|
|
||||||
|
return uid_event;
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
r.off = function(eventid, uid){
|
||||||
this.events[event].push(obj);
|
uid = uid || null;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
r.off = function(eventid){
|
|
||||||
var event = "on" + eventid;
|
var event = "on" + eventid;
|
||||||
if(!this.events[event]) return;
|
if(!this.events[event]) return;
|
||||||
this.events[event].forEach(function(e){
|
if(uid){
|
||||||
e = null;
|
this.events[event][uid] = null;
|
||||||
});
|
delete this.events[event][uid];
|
||||||
delete this.events[event];
|
return;
|
||||||
|
}
|
||||||
|
for(var _uid in this.events[event]){
|
||||||
|
this.events[event][_uid] = null;
|
||||||
|
delete this.events[event][_uid];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r.checkIfIsOver = function(){
|
r.checkIfIsOver = function(){
|
||||||
@ -230,14 +257,14 @@ var Battle = (function(){
|
|||||||
return Math.random() > 0.5 ? this.p1 : this.p2;
|
return Math.random() > 0.5 ? this.p1 : this.p2;
|
||||||
}
|
}
|
||||||
|
|
||||||
r.userLeft = function(sideName) {
|
r.userLeft = function(sideName){
|
||||||
var side = this[sideName];
|
var side = this[sideName];
|
||||||
|
|
||||||
side.foe.send("foe:left", null, true);
|
side.foe.send("foe:left", null, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r.shutDown = function() {
|
r.shutDown = function(){
|
||||||
this.channel = null;
|
this.channel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,9 +330,11 @@ Battleside = (function(){
|
|||||||
if(ability.changeSide){
|
if(ability.changeSide){
|
||||||
obj.targetSide = this.foe;
|
obj.targetSide = this.foe;
|
||||||
}
|
}
|
||||||
|
if(ability.onReset){
|
||||||
|
this.on("Reset", ability.onReset, this, [card])
|
||||||
|
}
|
||||||
if(ability.replaceWith){
|
if(ability.replaceWith){
|
||||||
obj._cancelPlacement = true;
|
obj._cancelPlacement = true;
|
||||||
|
|
||||||
this.on("Decoy:replaceWith", function(replaceCard){
|
this.on("Decoy:replaceWith", function(replaceCard){
|
||||||
if(replaceCard.getType() == Card.TYPE.LEADER ||
|
if(replaceCard.getType() == Card.TYPE.LEADER ||
|
||||||
replaceCard.getType() == Card.TYPE.WEATHER ||
|
replaceCard.getType() == Card.TYPE.WEATHER ||
|
||||||
@ -345,6 +347,7 @@ Battleside = (function(){
|
|||||||
|
|
||||||
|
|
||||||
field.replaceWith(replaceCard, card);
|
field.replaceWith(replaceCard, card);
|
||||||
|
self.runEvent("EachCardPlace");
|
||||||
|
|
||||||
self.hand.add(replaceCard);
|
self.hand.add(replaceCard);
|
||||||
self.hand.remove(card);
|
self.hand.remove(card);
|
||||||
@ -354,11 +357,12 @@ Battleside = (function(){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if(ability.onEachTurn){
|
if(ability.onEachTurn){
|
||||||
this.on("EachTurn", ability.onEachTurn, this, [card])
|
var uid = this.on("EachTurn", ability.onEachTurn, this, [card])
|
||||||
|
card._uidEvents["EachTurn"] = uid;
|
||||||
}
|
}
|
||||||
if(ability.onEachCardPlace){
|
if(ability.onEachCardPlace){
|
||||||
//PubSub.subscribe("onEachCardPlace", ability.onEachCardPlace.bind(this, card));
|
var uid = this.on("EachCardPlace", ability.onEachCardPlace, this, [card]);
|
||||||
this.on("EachCardPlace", ability.onEachCardPlace, this, [card]);
|
card._uidEvents["EachCardPlace"] = uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.update();
|
this.update();
|
||||||
|
@ -9,16 +9,15 @@ var Card = (function(){
|
|||||||
/**
|
/**
|
||||||
* constructor here
|
* constructor here
|
||||||
*/
|
*/
|
||||||
|
this._uidEvents = {};
|
||||||
this.setDisabled(false);
|
this.setDisabled(false);
|
||||||
this.channel = {};
|
|
||||||
this._key = key;
|
this._key = key;
|
||||||
this._data = CardData[key];
|
this._data = CardData[key];
|
||||||
this._data.key = key;
|
this._data.key = key;
|
||||||
this._boost = 0;
|
this._boost = {};
|
||||||
this._forcedPower = -1;
|
this._forcedPower = -1;
|
||||||
this._init();
|
this._init();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
var r = Card.prototype;
|
var r = Card.prototype;
|
||||||
/**
|
/**
|
||||||
@ -44,8 +43,11 @@ var Card = (function(){
|
|||||||
WEATHER: 5
|
WEATHER: 5
|
||||||
};
|
};
|
||||||
|
|
||||||
r.channel = null
|
r._uidEvents = null;
|
||||||
|
|
||||||
|
r.getUidEvents = function(key) {
|
||||||
|
return this._uidEvents[key];
|
||||||
|
}
|
||||||
|
|
||||||
r._init = function(){
|
r._init = function(){
|
||||||
this._id = ++Card.__id;
|
this._id = ++Card.__id;
|
||||||
@ -57,20 +59,20 @@ var Card = (function(){
|
|||||||
r.getPower = function(){
|
r.getPower = function(){
|
||||||
if(this._data.power === -1) return 0;
|
if(this._data.power === -1) return 0;
|
||||||
if(this._forcedPower > -1){
|
if(this._forcedPower > -1){
|
||||||
return (this._forcedPower > this._data.power ? this._data.power : this._forcedPower) + this._boost;
|
return (this._forcedPower > this._data.power ? this._data.power : this._forcedPower) + this.getBoost();
|
||||||
}
|
}
|
||||||
return this._data.power + this._boost;
|
return this._data.power + this.getBoost();
|
||||||
}
|
}
|
||||||
r.getRawPower = function(){
|
r.getRawPower = function(){
|
||||||
return this._data.power;
|
return this._data.power;
|
||||||
}
|
}
|
||||||
r.calculateBoost = function(){
|
/*r.calculateBoost = function(){
|
||||||
this._boost = 0;
|
this._boost = 0;
|
||||||
for(var key in this._boosts) {
|
for(var key in this._boosts) {
|
||||||
var boost = this._boosts[key];
|
var boost = this._boosts[key];
|
||||||
this.boost(boost.getPower());
|
this.boost(boost.getPower());
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
r.setForcedPower = function(nr){
|
r.setForcedPower = function(nr){
|
||||||
this._forcedPower = nr;
|
this._forcedPower = nr;
|
||||||
}
|
}
|
||||||
@ -110,9 +112,23 @@ var Card = (function(){
|
|||||||
return this._id;
|
return this._id;
|
||||||
}
|
}
|
||||||
|
|
||||||
r.boost = function(nr){
|
/*r.boost = function(nr){
|
||||||
/*this.getPower(); //to recalculate this._power;*/
|
this.getPower(); //to recalculate this._power;
|
||||||
this._boost += nr;
|
this._boost += nr;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
r.getBoost = function() {
|
||||||
|
var res = 0;
|
||||||
|
for(var key in this._boost) {
|
||||||
|
res += this._boost[key];
|
||||||
|
}
|
||||||
|
this.boost = res;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
r.setBoost = function(key, val) {
|
||||||
|
this._boost[key] = val;
|
||||||
|
this.getBoost(); //to recalculate this.boost
|
||||||
}
|
}
|
||||||
|
|
||||||
r.isDisabled = function(){
|
r.isDisabled = function(){
|
||||||
@ -128,9 +144,10 @@ var Card = (function(){
|
|||||||
return this._data[prop];
|
return this._data[prop];
|
||||||
}
|
}
|
||||||
|
|
||||||
r.resetBoost = function(){
|
r.reset = function(){
|
||||||
this._changedType = null;
|
this._changedType = null;
|
||||||
this._boost = 0;
|
this._boost = {};
|
||||||
|
this.boost = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Card;
|
return Card;
|
||||||
|
@ -48,10 +48,14 @@ var Field = (function(){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.isOnField = function(card){
|
||||||
|
return this.getPosition(card) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
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();
|
oldCard.reset();
|
||||||
return oldCard;
|
return oldCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,10 +67,10 @@ var Field = (function(){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
r.removeAll = function() {
|
r.removeAll = function(){
|
||||||
var tmp = this._cards.slice();
|
var tmp = this._cards.slice();
|
||||||
tmp.forEach(function(card) {
|
tmp.forEach(function(card){
|
||||||
card.resetBoost();
|
card.reset();
|
||||||
})
|
})
|
||||||
this._cards = [];
|
this._cards = [];
|
||||||
return tmp;
|
return tmp;
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,96 +1,98 @@
|
|||||||
describe("pubsub", function() {
|
var Battle = require("../../server/Battle");
|
||||||
var battle;
|
var Card = require("../../server/Card");
|
||||||
|
var data = require("../../assets/data/abilities");
|
||||||
|
|
||||||
beforeEach(function() {
|
describe("pubsub", function(){
|
||||||
battle = Battle();
|
var battle, card1, card2;
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
battle = {};
|
||||||
|
battle.runEvent = Battle.prototype.runEvent;
|
||||||
|
battle.on = Battle.prototype.on;
|
||||||
|
battle.off = Battle.prototype.off;
|
||||||
|
battle.events = {};
|
||||||
|
battle.update = function() {};
|
||||||
|
|
||||||
|
card1 = Card("kaedweni_siege_expert");
|
||||||
|
card2 = Card("dun_banner_medic");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("on: has correct arguments", function() {
|
it("on: has correct arguments", function(){
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
||||||
var CARD = {
|
|
||||||
_id: 1,
|
|
||||||
_name: "cardy"
|
|
||||||
}
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card) {
|
battle.on("EachTurn", function(card){
|
||||||
expect(card).toEqual(CARD);
|
expect(card).toEqual(card1);
|
||||||
}, this, [CARD]);
|
}, this, [card1]);
|
||||||
battle.runEvent("EachTurn");
|
battle.runEvent("EachTurn");
|
||||||
})
|
|
||||||
it("runEvent: has correct arguments", function() {
|
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
|
||||||
var CARD = {
|
|
||||||
_id: 1,
|
|
||||||
_name: "cardy"
|
|
||||||
}
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card) {
|
|
||||||
expect(card).toEqual(CARD);
|
})
|
||||||
|
it("runEvent: has correct arguments", function(){
|
||||||
|
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
||||||
|
battle.on("EachTurn", function(c){
|
||||||
|
expect(c).toEqual(card1);
|
||||||
});
|
});
|
||||||
battle.runEvent("EachTurn", null, [CARD]);
|
battle.runEvent("EachTurn", null, [card1]);
|
||||||
})
|
})
|
||||||
it("on + runEvent: has correct arguments", function() {
|
it("on + runEvent: has correct arguments", function(){
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
||||||
var CARD = {
|
battle.on("EachTurn", function(c1, c2){
|
||||||
_id: 1,
|
expect(c1).toEqual(card1);
|
||||||
_name: "cardy"
|
expect(c2).toEqual(card2);
|
||||||
}
|
}, null, [card1]);
|
||||||
var CARD2 = {
|
battle.runEvent("EachTurn", null, [card2]);
|
||||||
_id: 2,
|
|
||||||
_name: "cardooo"
|
|
||||||
}
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card1, card2) {
|
|
||||||
expect(card1).toEqual(CARD);
|
|
||||||
expect(card2).toEqual(CARD2);
|
|
||||||
}, null, [CARD]);
|
|
||||||
battle.runEvent("EachTurn", null, [CARD2]);
|
|
||||||
})
|
})
|
||||||
it("test context", function() {
|
it("test context", function(){
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
|
||||||
var Card = function(id, name){
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
var card1 = new Card(1, "cardy");
|
|
||||||
var card2 = new Card(2, "cardoo");
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card) {
|
battle.on("EachTurn", function(card){
|
||||||
expect(card.id).toEqual(card1.id);
|
expect(card.id).toEqual(card1.id);
|
||||||
expect(this.id).toEqual(card2.id);
|
expect(this.id).toEqual(card2.id);
|
||||||
}, card2, [card1]);
|
}, card2, [card1]);
|
||||||
battle.runEvent("EachTurn");
|
battle.runEvent("EachTurn");
|
||||||
})
|
})
|
||||||
it("test context", function() {
|
it("test context", function(){
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
|
||||||
var Card = function(id, name){
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
var card1 = new Card(1, "cardy");
|
|
||||||
var card2 = new Card(2, "cardoo");
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card) {
|
battle.on("EachTurn", function(card){
|
||||||
expect(card.id).toEqual(card1.id);
|
expect(card.id).toEqual(card1.id);
|
||||||
expect(this.id).toEqual(card2.id);
|
expect(this.id).toEqual(card2.id);
|
||||||
}, null, [card1]);
|
}, null, [card1]);
|
||||||
battle.runEvent("EachTurn", card2);
|
battle.runEvent("EachTurn", card2);
|
||||||
})
|
})
|
||||||
it("test context", function() {
|
it("test context", function(){
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
|
||||||
var Card = function(id, name){
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
var card1 = new Card(1, "cardy");
|
|
||||||
var card2 = new Card(2, "cardoo");
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card) {
|
battle.on("EachTurn", function(card){
|
||||||
expect(card.id).toEqual(card1.id);
|
expect(card.id).toEqual(card1.id);
|
||||||
expect(this.id).toEqual(card1.id);
|
expect(this.id).toEqual(card1.id);
|
||||||
}, card1, [card1]);
|
}, card1, [card1]);
|
||||||
battle.runEvent("EachTurn", card2);
|
battle.runEvent("EachTurn", card2);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should handle off correctly", function() {
|
||||||
|
var cb1 = function(){}, cb2 = function() {};
|
||||||
|
var obj = {
|
||||||
|
cb1: cb1,
|
||||||
|
cb2: cb2
|
||||||
|
}
|
||||||
|
|
||||||
|
spyOn(obj, "cb1");
|
||||||
|
spyOn(obj, "cb2");
|
||||||
|
|
||||||
|
|
||||||
|
var uid1 = battle.on("EachCardPlace", obj.cb1, battle, [card1]);
|
||||||
|
var uid2 = battle.on("EachCardPlace", obj.cb2, battle, [card2]);
|
||||||
|
|
||||||
|
|
||||||
|
battle.off("EachCardPlace", uid2);
|
||||||
|
battle.runEvent("EachCardPlace");
|
||||||
|
|
||||||
|
|
||||||
|
expect(obj.cb1).toHaveBeenCalled();
|
||||||
|
expect(obj.cb2).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
/*battle.off("EachCardPlace", uid1);
|
||||||
|
|
||||||
|
expect(battle.events).toEqual({});*/
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require("./filterSpec");
|
require("./filterSpec");
|
||||||
|
require("./PubSubSpec");
|
||||||
|
|
||||||
(function main(){
|
(function main(){
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user