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