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
@ -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);
|
||||
})
|
||||
}
|
||||
},
|
||||
@ -164,31 +174,13 @@ module.exports = {
|
||||
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,7 +40,8 @@ var Battle = (function(){
|
||||
|
||||
r.init = function(){
|
||||
/*PubSub.subscribe("update", this.update.bind(this));*/
|
||||
this.on("Update", this.update);/*
|
||||
this.on("Update", this.update);
|
||||
/*
|
||||
this.on("AfterPlace", this.checkAbilityOnAfterPlace)*/
|
||||
|
||||
|
||||
@ -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"));
|
||||
@ -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;
|
||||
|
||||
return uid_event;
|
||||
}
|
||||
|
||||
else {
|
||||
this.events[event].push(obj);
|
||||
}
|
||||
}
|
||||
|
||||
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(){
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
@ -66,7 +70,7 @@ var Field = (function(){
|
||||
r.removeAll = function(){
|
||||
var tmp = this._cards.slice();
|
||||
tmp.forEach(function(card){
|
||||
card.resetBoost();
|
||||
card.reset();
|
||||
})
|
||||
this._cards = [];
|
||||
return tmp;
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,59 +1,48 @@
|
||||
var Battle = require("../../server/Battle");
|
||||
var Card = require("../../server/Card");
|
||||
var data = require("../../assets/data/abilities");
|
||||
|
||||
describe("pubsub", function(){
|
||||
var battle;
|
||||
var battle, card1, card2;
|
||||
|
||||
beforeEach(function(){
|
||||
battle = Battle();
|
||||
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(){
|
||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
||||
var CARD = {
|
||||
_id: 1,
|
||||
_name: "cardy"
|
||||
}
|
||||
|
||||
battle.on("EachTurn", function(card){
|
||||
expect(card).toEqual(CARD);
|
||||
}, this, [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);
|
||||
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(){
|
||||
//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");
|
||||
|
||||
battle.on("EachTurn", function(card){
|
||||
expect(card.id).toEqual(card1.id);
|
||||
@ -62,13 +51,6 @@ describe("pubsub", function() {
|
||||
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");
|
||||
|
||||
battle.on("EachTurn", function(card){
|
||||
expect(card.id).toEqual(card1.id);
|
||||
@ -77,13 +59,6 @@ describe("pubsub", function() {
|
||||
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");
|
||||
|
||||
battle.on("EachTurn", function(card){
|
||||
expect(card.id).toEqual(card1.id);
|
||||
@ -92,5 +67,32 @@ describe("pubsub", function() {
|
||||
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