1
0
mirror of https://github.com/exane/not-gwent-online synced 2025-11-08 09:08:40 +00:00

fix morale boost + improved events

This commit is contained in:
exane
2015-06-19 21:53:48 +02:00
parent 2c307a4fb8
commit 730e8f714a
9 changed files with 957 additions and 196 deletions

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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;