1
0
mirror of https://github.com/exane/not-gwent-online synced 2025-08-13 13:07:32 +00:00

lot of stuff

This commit is contained in:
exane
2015-06-21 16:50:50 +02:00
parent 66cc04d36c
commit 753f4e7a9c
19 changed files with 1155 additions and 102 deletions

@@ -61,11 +61,17 @@ var Battle = (function(){
this.p2.setLeadercard();
this.p1.draw(10);
this.p2.draw(10);
this.p1.hand.add(Card("blue_stripes_commando"));
this.p2.hand.add(Card("blue_stripes_commando"));
this.p1.hand.add(Card("blue_stripes_commando"));
this.p2.hand.add(Card("blue_stripes_commando"));
/*
this.p1.hand.add(Card("commanders_horn"));
this.p2.hand.add(Card("commanders_horn"));
this.p1.hand.add(Card("commanders_horn"));
this.p2.hand.add(Card("commanders_horn"));
/*
this.p1.hand.add(Card("biting_frost"));
this.p2.hand.add(Card("biting_frost"));
this.p1.hand.add(Card("torrential_rain"));
this.p2.hand.add(Card("torrential_rain"));
this.p1.hand.add(Card("clear_weather"));
this.p2.hand.add(Card("clear_weather"));*//*
this.p1.hand.add(Card("kaedweni_siege_expert"));
this.p2.hand.add(Card("kaedweni_siege_expert"));
this.p1.hand.add(Card("ballista"));
@@ -77,8 +83,8 @@ var Battle = (function(){
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("ballista"));*/
/*this.p1.hand.add(Card("decoy"));
this.p2.hand.add(Card("decoy"));*/
/*
this.p1.hand.add(Card("dun_banner_medic"));
@@ -86,8 +92,8 @@ var Battle = (function(){
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.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"));
@@ -155,10 +161,10 @@ var Battle = (function(){
cards: JSON.stringify(p.hand.getCards())
});
p.send("update:fields", {
close: p.field[Card.TYPE.CLOSE_COMBAT],
ranged: p.field[Card.TYPE.RANGED],
siege: p.field[Card.TYPE.SIEGE],
weather: p.field[Card.TYPE.WEATHER]
close: p.field[Card.TYPE.CLOSE_COMBAT].getInfo(),
ranged: p.field[Card.TYPE.RANGED].getInfo(),
siege: p.field[Card.TYPE.SIEGE].getInfo(),
weather: p.field[Card.TYPE.WEATHER].getInfo()
})
}

@@ -21,10 +21,15 @@ Battleside = (function(){
this._isWaiting = true;
this.socket = user.socket;
this.field = {};
this.field[Card.TYPE.LEADER] = Field(Card.TYPE.LEADER);
this.field[Card.TYPE.CLOSE_COMBAT] = Field(Card.TYPE.CLOSE_COMBAT);
this.field[Card.TYPE.RANGED] = Field(Card.TYPE.RANGED);
this.field[Card.TYPE.SIEGE] = Field(Card.TYPE.SIEGE);
this.field[Card.TYPE.LEADER] = Field(this);
this.field[Card.TYPE.CLOSE_COMBAT] = Field(this, true);
this.field[Card.TYPE.RANGED] = Field(this, true);
this.field[Card.TYPE.SIEGE] = Field(this, true);
/*this.field[Card.TYPE.HORN] = {
close: Field(this),
range: Field(this),
siege: Field(this)
};*/
this.n = n ? "p2" : "p1";
this._name = name;
this.battle = battle;
@@ -88,14 +93,24 @@ Battleside = (function(){
self.playCard(card);
})
this.receive("agile:field", function(data) {
this.receive("agile:field", function(data){
var fieldType = data.field;
if(!(fieldType in [0, 1])) throw new Error("set field agile: false fieldtype " + fieldType);
self.runEvent("agile:setField", null, [fieldType]);
self.runEvent("NextTurn", null, [self.foe]);
})
this.receive("cancel:agile", function(){
self.off("agile:setField");
})
this.receive("horn:field", function(data){
var fieldType = data.field;
if(!(fieldType in [0, 1, 2])) throw new Error("set field horn: false fieldtype " + fieldType);
self.runEvent("horn:setField", null, [fieldType]);
self.runEvent("NextTurn", null, [self.foe]);
})
this.receive("cancel:horn", function(){
self.off("horn:setField");
})
this.on("Turn" + this.getID(), this.onTurnStart, this);
@@ -129,7 +144,7 @@ Battleside = (function(){
}
r.setUpWeatherFieldWith = function(p2){
this.field[Card.TYPE.WEATHER] = p2.field[Card.TYPE.WEATHER] = Field(Card.TYPE.WEATHER);
this.field[Card.TYPE.WEATHER] = p2.field[Card.TYPE.WEATHER] = Field(this);
}
r.findCardOnFieldByID = function(id){
@@ -279,8 +294,16 @@ Battleside = (function(){
this.checkAbilities(card, obj);
if(obj._cancelPlacement) return 0;
var field = obj.targetSide.field[card.getType()];
field.add(card);
var field;
if(typeof obj.isHorn !== "undefined"){
field = obj.targetSide.field[obj.isHorn];
field.add(card, true);
}
else {
field = obj.targetSide.field[card.getType()];
field.add(card);
}
this.runEvent("EachCardPlace");
@@ -298,6 +321,49 @@ Battleside = (function(){
return 1;
}
r.setHorn = function(card) {
var self = this;
this.send("played:horn", {cardID: card.getID()}, true)
this.on("horn:setField", function(type){
self.off("horn:setField");
card.changeType(type);
self.placeCard(card, {
isHorn: type,
disabled: true
});
self.hand.remove(card);
})
}
r.commanderHornAbility = function(card) {
var field = this.field[card.getType()];
var id = "commanders_horn";
if(typeof field === "undefined") {
//console.log("field unknown | %s", card.getName());
return;
}
if(!field.isOnField(card)){
field.get().forEach(function(_card){
if(_card.getID() == id) return;
if(_card.getType() != card.getType()) return;
if(_card.hasAbility("hero")) 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;
if(_card.hasAbility("hero")) return;
_card.setBoost(id, 0);
_card.setBoost(id, _card.getPower());
})
}
r.checkAbilities = function(card, obj, __flag){
var self = this;
obj.targetSide = this;
@@ -316,10 +382,17 @@ Battleside = (function(){
}
if(ability && !Array.isArray(ability)){
if(ability.onBeforePlace) {
if(ability.onBeforePlace){
ability.onBeforePlace.apply(this, [card]);
}
if(ability.cancelPlacement) {
if(ability.isCommandersHornCard) {
this.setHorn(card);
}
if(ability.commandersHorn) {
ability.onEachCardPlace = this.commanderHornAbility;
ability.onWeatherChange = this.commanderHornAbility;
}
if(ability.cancelPlacement){
obj._cancelPlacement = true;
}
if(ability.waitResponse){
@@ -327,10 +400,11 @@ Battleside = (function(){
}
if(ability.changeSide){
obj.targetSide = this.foe;
}/*
if(ability.onReset){
this.on("Reset", ability.onReset, this, [card])
}*/
}
if(typeof ability.weather !== "undefined"){
ability.onEachTurn = this.setWeather.bind(this, ability.weather);
ability.onEachCardPlace = this.setWeather.bind(this, ability.weather);
}
if(ability.replaceWith){
obj._cancelPlacement = true;
this.on("Decoy:replaceWith", function(replaceCard){
@@ -362,6 +436,10 @@ Battleside = (function(){
var uid = this.on("EachCardPlace", ability.onEachCardPlace, this, [card]);
card._uidEvents["EachCardPlace"] = uid;
}
if(ability.onWeatherChange){
var uid = this.on("WeatherChange", ability.onWeatherChange, this, [card]);
card._uidEvents["WeatherChange"] = uid;
}
this.update();
}
@@ -380,6 +458,49 @@ Battleside = (function(){
}
}
r.setWeather = function(weather){
var targetRow = weather;
var field;
if(typeof targetRow === "undefined") return;
//console.log(this.field[Card.TYPE.WEATHER]);
if(targetRow === Card.TYPE.WEATHER){
field = this.field[targetRow];
field.removeAll();
for(var i = Card.TYPE.CLOSE_COMBAT; i <= Card.TYPE.SIEGE; i++) {
var _field1, _field2, _field;
_field1 = this.field[i].get();
_field2 = this.foe.field[i].get();
_field = _field1.concat(_field2);
_field.forEach(function(_card){
if(_card.hasAbility("hero")) return;
_card.setForcedPower(-1);
});
}
this.runEvent("WeatherChange");
return;
}
var forcedPower = 1;
if(typeof targetRow === "undefined"){
console.trace(this);
}
var field1 = this.field[targetRow].get();
var field2 = this.foe.field[targetRow].get();
field = field1.concat(field2);
field.forEach(function(_card){
if(_card.hasAbility("hero")) return;
_card.setForcedPower(forcedPower);
});
this.runEvent("WeatherChange");
this.update();
}
r.clearMainFields = function(){
var cards1 = this.field[Card.TYPE.CLOSE_COMBAT].removeAll();
var cards2 = this.field[Card.TYPE.RANGED].removeAll();
@@ -432,7 +553,7 @@ Battleside = (function(){
if(_.isArray(property)){
var _f = false;
for(var i = 0; i < property.length; i++) {
if(property[i] === val) {
if(property[i] === val){
_f = true;
break;
}

@@ -17,7 +17,6 @@ var Card = (function(){
this._boost = {};
this._forcedPower = -1;
this._init();
};
var r = Card.prototype;
/**
@@ -68,6 +67,7 @@ var Card = (function(){
}
r.setForcedPower = function(nr){
this._forcedPower = nr;
/*this.getBoost(); *///recalculate
}
r.getRawAbility = function(){
return this._data.ability;
@@ -82,6 +82,16 @@ var Card = (function(){
}
return AbilityData[this._data.ability];
}
r.hasAbility = function(ability) {
var a = this.getRawAbility();
if(Array.isArray(a)) {
for(var i=0; i<a.length; i++) {
var _a = a[i];
if(_a === ability) return true;
}
}
return a === ability;
}
r.getImage = function(){
return "../assets/cards/" + this._data.img + ".png";
}
@@ -105,11 +115,6 @@ var Card = (function(){
return this._id;
}
/*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) {

@@ -1,13 +1,15 @@
var Field = (function(){
var Field = function(){
var Field = function(side, hasHornField){
if(!(this instanceof Field)){
return (new Field());
return (new Field(side, hasHornField));
}
/**
* constructor here
*/
this._hasHornField = hasHornField || false;
this._cards = [];
this.side = side;
};
var r = Field.prototype;
/**
@@ -18,8 +20,19 @@ var Field = (function(){
r._cards = null;
r._score = 0;
r._hasHornField = null;
r._hornCard = null;
r.side = null;
r.add = function(card){
r.add = function(card, isHorn){
/*if(card.hasAbility("commanders_horn")) {
this.setHorn(card);
return;
}*/
if(isHorn && this._hasHornField) {
this.setHorn(card);
return;
}
this._cards.push(card);
this.updateScore();
}
@@ -49,6 +62,9 @@ var Field = (function(){
}
r.isOnField = function(card){
if(this._hasHornField && this.getHorn() && card.getID() === this.getHorn().getID()){
return true;
}
return this.getPosition(card) >= 0;
}
@@ -69,13 +85,45 @@ var Field = (function(){
r.removeAll = function(){
var tmp = this._cards.slice();
var self = this;
tmp.forEach(function(card){
card.reset();
for(var event in card._uidEvents) {
self.side.off(event, card.getUidEvents(event));
}
})
this._cards = [];
if(this.getHorn()) {
var card = this.getHorn();
card.reset();
this.setHorn(null);
for(var event in card._uidEvents) {
self.side.off(event, card.getUidEvents(event));
}
tmp.push(card);
}
return tmp;
}
r.getInfo = function() {
var self = this;
return {
cards: self._cards,
horn: self.getHorn(),
score: self._score
}
}
r.getHorn = function() {
if(!this._hasHornField) return null;
return this._hornCard;
}
r.setHorn = function(card) {
if(!this._hasHornField) return null;
this._hornCard = card;
}
return Field;
})();

@@ -23,7 +23,8 @@ var Hand = (function(){
*/
r._hand = null;
r.add = function(card){
r.add = function(card){/*
console.log(card.getID(), card.getName());*/
this._hand.push(card);
}
@@ -45,6 +46,8 @@ var Hand = (function(){
//console.trace(id);
id = id instanceof Card ? id.getID() : id;
if(!n) return -1;
for(var i = 0; i < n; i++) {
if(!this._hand[i]) {
console.trace(this._hand[i]);
@@ -59,6 +62,7 @@ var Hand = (function(){
r.getRandomCard = function(){
var rnd = (Math.random() * this._hand.length) | 0;
if(!this._hand.length) return -1;
return this._hand[rnd];
}