mirror of
https://github.com/exane/not-gwent-online
synced 2026-02-03 04:25:00 +00:00
add some abilities
This commit is contained in:
@@ -39,7 +39,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)*/
|
||||
|
||||
|
||||
this.channel = this.socket.subscribe(this._id);
|
||||
@@ -56,13 +57,20 @@ 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("dun_banner_medic"));
|
||||
this.p2.hand.add(Card("dun_banner_medic"));
|
||||
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.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.p2.hand.add(Card("impenetrable_fog"));*/
|
||||
|
||||
this.update();
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
var io = global.io;
|
||||
var DeckData = require("../assets/data/deck");
|
||||
var Deck = require("./Deck");
|
||||
var Hand = require("./Hand");
|
||||
var Card = require("./Card");
|
||||
var Field = require("./Field");
|
||||
var _ = require("underscore");
|
||||
|
||||
|
||||
var Battleside;
|
||||
@@ -16,6 +16,7 @@ Battleside = (function(){
|
||||
* constructor here
|
||||
*/
|
||||
|
||||
var deck = user.getDeck();
|
||||
var self = this;
|
||||
this._isWaiting = true;
|
||||
this.socket = user.socket;
|
||||
@@ -28,7 +29,7 @@ Battleside = (function(){
|
||||
this._name = name;
|
||||
this.battle = battle;
|
||||
this.hand = Hand();
|
||||
this.deck = Deck(DeckData["test"]);
|
||||
this.deck = Deck(DeckData[deck]);
|
||||
this._discard = [];
|
||||
|
||||
this.runEvent = this.battle.runEvent.bind(this.battle);
|
||||
@@ -74,6 +75,20 @@ Battleside = (function(){
|
||||
self.update();
|
||||
self.runEvent("NextTurn", null, [self.foe]);
|
||||
})
|
||||
this.receive("medic:chooseCardFromDiscard", function(data){
|
||||
if(!data){
|
||||
self.runEvent("NextTurn", null, [self.foe]);
|
||||
return;
|
||||
}
|
||||
var cardID = data.cardID;
|
||||
var card = self.getCardFromDiscard(cardID);
|
||||
if(card === -1) throw new Error("medic:chooseCardFromDiscard | unknown card: ", card);
|
||||
|
||||
self.removeFromDiscard(card);
|
||||
|
||||
self.playCard(card);
|
||||
})
|
||||
|
||||
|
||||
this.on("Turn" + this.getID(), this.onTurnStart, this);
|
||||
};
|
||||
@@ -115,6 +130,19 @@ Battleside = (function(){
|
||||
var card = field.getCard(id);
|
||||
if(card !== -1) return card;
|
||||
}
|
||||
/*
|
||||
for(var i = 0; i < this._discard.length; i++) {
|
||||
var c = this._discard[i];
|
||||
if(c.getID() === id) return c;
|
||||
}*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
r.getCardFromDiscard = function(id){
|
||||
for(var i = 0; i < this._discard.length; i++) {
|
||||
var c = this._discard[i];
|
||||
if(c.getID() === id) return c;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -237,8 +265,8 @@ Battleside = (function(){
|
||||
this.runEvent("NextTurn", null, [this.foe]);
|
||||
}
|
||||
|
||||
r.placeCard = function(card){
|
||||
var obj = {};
|
||||
r.placeCard = function(card, obj){
|
||||
obj = _.extend({}, obj);
|
||||
|
||||
this.checkAbilities(card, obj);
|
||||
if(obj._canclePlacement) return 0;
|
||||
@@ -246,13 +274,21 @@ Battleside = (function(){
|
||||
var field = obj.targetSide.field[card.getType()];
|
||||
field.add(card);
|
||||
|
||||
//PubSub.publish("onEachCardPlace");
|
||||
this.runEvent("OnEachCardPlace");
|
||||
|
||||
this.checkAbilityOnAfterPlace(card);
|
||||
this.runEvent("EachCardPlace");
|
||||
|
||||
this.checkAbilityOnAfterPlace(card, obj);
|
||||
/*
|
||||
this.runEvent("AfterPlace", this, [card, obj]);*/
|
||||
|
||||
this.update();
|
||||
|
||||
if(obj._waitResponse){
|
||||
this.hand.remove(card);
|
||||
this.update();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -260,6 +296,7 @@ Battleside = (function(){
|
||||
var self = this;
|
||||
obj.targetSide = this;
|
||||
var ability = Array.isArray(__flag) || card.getAbility();
|
||||
|
||||
if(Array.isArray(ability) && ability.length){
|
||||
var ret = ability.slice();
|
||||
ret = ret.splice(0, 1);
|
||||
@@ -267,8 +304,14 @@ Battleside = (function(){
|
||||
ability = ability[0];
|
||||
}
|
||||
|
||||
if(ability && !Array.isArray(ability)){/*
|
||||
var ability = card.getAbility();*/
|
||||
if(ability && ability.name === obj.suppress){
|
||||
this.update();
|
||||
}
|
||||
|
||||
if(ability && !Array.isArray(ability)){
|
||||
if(ability.waitResponse){
|
||||
obj._waitResponse = true;
|
||||
}
|
||||
if(ability.changeSide){
|
||||
obj.targetSide = this.foe;
|
||||
}
|
||||
@@ -307,9 +350,13 @@ Battleside = (function(){
|
||||
}
|
||||
}
|
||||
|
||||
r.checkAbilityOnAfterPlace = function(card){
|
||||
r.checkAbilityOnAfterPlace = function(card, obj){
|
||||
var ability = card.getAbility();
|
||||
if(ability){
|
||||
if(ability.name && ability.name === obj.suppress){
|
||||
this.update();
|
||||
return;
|
||||
}
|
||||
if(ability.onAfterPlace){
|
||||
ability.onAfterPlace.call(this, card)
|
||||
}
|
||||
@@ -332,6 +379,17 @@ Battleside = (function(){
|
||||
});
|
||||
}
|
||||
|
||||
r.removeFromDiscard = function(card){
|
||||
for(var i = 0; i < this._discard.length; i++) {
|
||||
var c = this._discard[i];
|
||||
if(c.getID() === card.getID()){
|
||||
|
||||
this._discard.splice(i, 1);
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.getDiscard = function(json){
|
||||
if(json){
|
||||
return JSON.stringify(this._discard);
|
||||
@@ -344,6 +402,38 @@ Battleside = (function(){
|
||||
this.setPassing(false);
|
||||
}
|
||||
|
||||
r.filter = function(arrCards, opt){
|
||||
var arr = arrCards.slice();
|
||||
|
||||
for(var key in opt) {
|
||||
var res = [];
|
||||
var prop = key, val = opt[key];
|
||||
|
||||
|
||||
arrCards.forEach(function(card){
|
||||
var property = card.getProperty(prop);
|
||||
if(_.isArray(property)){
|
||||
var _f = false;
|
||||
for(var i = 0; i < property.length; i++) {
|
||||
if(property[i] === val) {
|
||||
_f = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!_f){
|
||||
res.push(card);
|
||||
}
|
||||
}
|
||||
else if(card.getProperty(prop) !== val){
|
||||
res.push(card);
|
||||
}
|
||||
})
|
||||
arr = _.intersection(arr, res);
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
return Battleside;
|
||||
})();
|
||||
|
||||
|
||||
@@ -91,6 +91,9 @@ var Card = (function(){
|
||||
r.getFaction = function(){
|
||||
return this._data.faction;
|
||||
}
|
||||
r.getMusterType = function() {
|
||||
return this._data.musterType || null;
|
||||
}
|
||||
r.getType = function(){
|
||||
return this._data.type;
|
||||
}
|
||||
@@ -116,9 +119,14 @@ var Card = (function(){
|
||||
}
|
||||
|
||||
r.getProperty = function(prop){
|
||||
if(!this._data[prop]) return {};
|
||||
return this._data[prop];
|
||||
}
|
||||
|
||||
r.resetBoost = function() {
|
||||
this._boost = 0;
|
||||
}
|
||||
|
||||
return Card;
|
||||
})();
|
||||
|
||||
|
||||
@@ -78,11 +78,6 @@ var Deck = (function(){
|
||||
var n = this.length();
|
||||
|
||||
for(var i = 0; i < n; i++) {
|
||||
/*var cardID = this.getDeck()[i];
|
||||
if(id == cardID){
|
||||
this.getDeck().splice(i, 1);
|
||||
return id;
|
||||
}*/
|
||||
var c = this.getDeck()[i];
|
||||
if(c.getID() === card.getID()){
|
||||
return this.getDeck().splice(i, 1)[0];
|
||||
|
||||
@@ -51,6 +51,7 @@ var Field = (function(){
|
||||
r.replaceWith = function(oldCard, newCard){
|
||||
var index = this.getPosition(oldCard);
|
||||
this._cards[index] = newCard;
|
||||
oldCard.resetBoost();
|
||||
return oldCard;
|
||||
}
|
||||
|
||||
@@ -64,6 +65,9 @@ var Field = (function(){
|
||||
|
||||
r.removeAll = function() {
|
||||
var tmp = this._cards.slice();
|
||||
tmp.forEach(function(card) {
|
||||
card.resetBoost();
|
||||
})
|
||||
this._cards = [];
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ var Hand = (function(){
|
||||
if(this._hand[i].getID() != id) continue;
|
||||
return this._hand.splice(i, 1);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -65,6 +66,16 @@ var Hand = (function(){
|
||||
return this._hand.length;
|
||||
}
|
||||
|
||||
r.find = function(key, val) {
|
||||
var res = [];
|
||||
this._hand.forEach(function(card){
|
||||
if(card.getProperty(key) == val){
|
||||
res.push(card);
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
return Hand;
|
||||
})();
|
||||
|
||||
@@ -74,6 +74,15 @@ var User = (function(){
|
||||
return this._rooms[0];
|
||||
}
|
||||
|
||||
r.setDeck = function(deck) {
|
||||
console.log("set deck: ", deck);
|
||||
this._deck = deck;
|
||||
}
|
||||
|
||||
r.getDeck = function() {
|
||||
return this._deck || "northern_realm";
|
||||
}
|
||||
|
||||
r.addRoom = function(room) {
|
||||
this._rooms.push(room);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,13 @@ module.exports.run = function(worker){
|
||||
socket.emit("response:name", {name: user.getName()});
|
||||
})
|
||||
|
||||
socket.on("set:deck", function(data) {
|
||||
console.log(data);
|
||||
if(data && data.deck){
|
||||
user.setDeck(data.deck);
|
||||
}
|
||||
})
|
||||
|
||||
socket.on("request:gameLoaded", function(data){
|
||||
console.log(data);
|
||||
connections.roomCollection[data._roomID].setReady(user);
|
||||
|
||||
Reference in New Issue
Block a user