diff --git a/client/js/client.js b/client/js/client.js index 23c265d..45ff32e 100644 --- a/client/js/client.js +++ b/client/js/client.js @@ -458,6 +458,10 @@ let BattleView = Backbone.View.extend({ let modal = new MedicModal({model: this.user}); this.$el.prepend(modal.render().el); } + if(this.user.get("emreis_leader4")){ + let modal = new LeaderEmreis4Modal({model: this.user}); + this.$el.prepend(modal.render().el); + } if(this.user.get("setAgile")){ let id = this.user.get("setAgile"); this.$el.find("[data-id='" + id + "']").addClass("activeCard"); @@ -608,6 +612,24 @@ let MedicModal = Modal.extend({ } }); +let LeaderEmreis4Modal = Modal.extend({ + template: require("../templates/modal.emreis_leader4.handlebars"), + events: { + "click .card": "onCardClick" + }, + onCardClick: function(e){ + let id = $(e.target).closest(".card").data().id; + this.model.get("app").send("emreis_leader4:chooseCardFromDiscard", { + cardID: id + }) + this.model.set("emreis_leader4", false); + }, + cancel: function(){ + this.model.get("app").send("emreis_leader4:chooseCardFromDiscard") + this.model.set("emreis_leader4", false); + } +}); + let ReDrawModal = Modal.extend({ template: require("../templates/modal.redraw.handlebars"), initialize: function(){ @@ -708,12 +730,18 @@ let User = Backbone.Model.extend({ app.receive("played:medic", function(data){ let cards = JSON.parse(data.cards); - //console.log("played medic"); self.set("medicDiscard", { cards: cards }); }) + app.receive("played:emreis_leader4", function(data){ + let cards = JSON.parse(data.cards); + self.set("emreis_leader4", { + cards: cards + }); + }) + app.receive("played:agile", function(data){ //console.log("played agile"); self.set("setAgile", data.cardID); diff --git a/client/templates/modal.emreis_leader4.handlebars b/client/templates/modal.emreis_leader4.handlebars new file mode 100644 index 0000000..f7aebf8 --- /dev/null +++ b/client/templates/modal.emreis_leader4.handlebars @@ -0,0 +1,11 @@ +
+

Choose one card from your foes discard pile

+
+
+ {{#each emreis_leader4.cards as |val key|}} + {{>card val}} + {{/each}} +
+
+
close
+
\ No newline at end of file diff --git a/client/templates/modal.medic.handlebars b/client/templates/modal.medic.handlebars index d644364..3f2f18f 100644 --- a/client/templates/modal.medic.handlebars +++ b/client/templates/modal.medic.handlebars @@ -1,5 +1,5 @@
-

Choose one card from your discard

+

Choose one card from your discard pile

{{#each medicDiscard.cards as |val key|}} diff --git a/server/Battleside.js b/server/Battleside.js index 2205258..0cbe1e0 100644 --- a/server/Battleside.js +++ b/server/Battleside.js @@ -54,7 +54,7 @@ Battleside = (function(){ var ability = leaderCard.getAbility(); - ability.onActivate.apply(self); + ability.onActivate.apply(self, [leaderCard]); leaderCard.setDisabled(true); self.battle.sendNotification(self.getName() + " activated " + leaderCard.getName() + "! (leadercard)"); self.update(); @@ -96,6 +96,19 @@ Battleside = (function(){ self.playCard(card); }) + this.receive("emreis_leader4:chooseCardFromDiscard", function(data){ + if(!data){ + //self.runEvent("NextTurn", null, [self.foe]); + return; + } + var cardID = data.cardID; + var card = self.foe.getCardFromDiscard(cardID); + if(card === -1) throw new Error("emreis_leader4:chooseCardFromDiscard | unknown card: ", card); + + self.foe.removeFromDiscard(card); + + self.placeCard(card); + }) this.receive("agile:field", function(data){ var fieldType = data.field; if(!(fieldType in [0, 1])) throw new Error("set field agile: false fieldtype " + fieldType); @@ -413,8 +426,9 @@ Battleside = (function(){ if(!field.isOnField(card)){ field.get().forEach(function(_card){ - if(_card.getID() == id) return; - if(_card.getType() != card.getType()) return; + if(_card.getID() === id) return; + if(_card.getID() === card.getID()) return; + if(_card.getType() !== card.getType()) return; if(_card.hasAbility("hero")) return; _card.setBoost(id, 0); }) @@ -423,7 +437,8 @@ Battleside = (function(){ } field.get().forEach(function(_card){ - if(_card.getID() == id) return; + if(_card.getID() === id) return; + if(_card.getID() === card.getID()) return; if(_card.getType() != card.getType()) return; if(_card.hasAbility("hero")) return; _card.setBoost(id, 0); @@ -524,9 +539,18 @@ Battleside = (function(){ } } - r.checkAbilityOnAfterPlace = function(card, obj){ - var ability = card.getAbility(); - if(ability){ + r.checkAbilityOnAfterPlace = function(card, obj, __flag){ + //var ability = card.getAbility(); + var ability = Array.isArray(__flag) ? __flag : card.getAbility(); + + if(Array.isArray(ability) && ability.length){ + var ret = ability.slice(); + ret.splice(0, 1); + this.checkAbilityOnAfterPlace(card, obj, ret); + ability = ability[0]; + } + + if(ability && !Array.isArray(ability)){ if(ability.name && ability.name === obj.suppress){ //this.update(); return; @@ -582,13 +606,12 @@ Battleside = (function(){ _card.setForcedPower(forcedPower); }); this.runEvent("WeatherChange"); - //this.update(); } r.scorch = function(card){ var side = this.foe; var field = side.field[Card.TYPE.CLOSE_COMBAT]; - var cards = field.getHighestCards(); + var cards = field.getHighestCards(true); var removeCards = field.removeCard(cards); @@ -603,9 +626,6 @@ Battleside = (function(){ this.battle.sendNotification(txt); side.addToDiscard(removeCards); - /* - this.hand.remove(card); - this.addToDiscard(card);*/ } r.clearMainFields = function(){ @@ -745,6 +765,10 @@ Battleside = (function(){ } + r.sendNotification = function(msg) { + this.battle.sendNotification(msg); + } + return Battleside; })();