Skip to content

Commit

Permalink
Paris Mulligan
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Jan 12, 2014
1 parent 9c1e202 commit 012701b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 24 deletions.
3 changes: 1 addition & 2 deletions classes.js
Expand Up @@ -77,8 +77,7 @@ function Player(game){
this.precognition = false;
this.gpull = null;
this.nova = 0;
this.maxhp = 100;
this.hp = 100;
this.maxhp = this.hp = 100;
this.hand = [];
this.deck = [];
this.creatures = new Array(23);
Expand Down
37 changes: 24 additions & 13 deletions etg.js
Expand Up @@ -17,6 +17,10 @@ var ShieldEnum = 2;
var PermanentEnum = 3;
var SpellEnum = 4;
var CreatureEnum = 5;
var MulliganPhase1 = 0;
var MulliganPhase2 = 1;
var PlayPhase = 2;
var EndPhase = 3;
var TrueMarks = ["8pi", "8pj", "8pk", "8pl", "8pm", "8pn", "8po", "8pp", "8pq", "8pr", "8ps", "8pt", "8pu"];
var NymphList = [undefined, undefined,
"500", "6ug",
Expand Down Expand Up @@ -45,7 +49,7 @@ var ShardList = [undefined, undefined,
"5vi", "7u2",
"62m", "816"];
function mkGame(first, seed){
var game = { rng: new MersenneTwister(seed) };
var game = { rng: new MersenneTwister(seed), phase: MulliganPhase1, ply: 0 };
game.player1 = new Player(game);
game.player2 = new Player(game);
game.player1.foe = game.player2;
Expand Down Expand Up @@ -276,6 +280,7 @@ Player.prototype.spend = function(qtype, x) {
return true;
}
Player.prototype.endturn = function(discard) {
this.game.ply++;
if (discard != undefined){
var card=this.hand[discard].card;
this.hand.splice(discard, 1);
Expand Down Expand Up @@ -400,20 +405,15 @@ Player.prototype.drawcard = function() {
}
}
}
Player.prototype.drawhand = function() {
this.shuffle(this.deck);
var mulligan = true;
for(var i=0; i<7; i++){
if (this.deck[i].cost == 0){
mulligan=false;
break;
Player.prototype.drawhand = function(x) {
if (x > 0){
while (this.hand.length > 0){
this.deck.push(this.hand.pop().card);
}
}
if (mulligan){
this.shuffle(this.deck);
}
for(var i=0; i<7; i++){
this.hand.push(new CardInstance(this.deck.pop(), this));
for(var i=0; i<x; i++){
this.hand.push(new CardInstance(this.deck.pop(), this));
}
}
}
Player.prototype.masscc = function(caster, func){
Expand Down Expand Up @@ -838,6 +838,17 @@ Player.prototype.randomcard = function(upped, filter){
var keys = filtercards(upped, filter);
return CardCodes[keys[this.upto(keys.length)]];
}
function progressMulligan(game){
if (game.phase == MulliganPhase1){
game.phase = MulliganPhase2;
}else if(game.phase == MulliganPhase2){
game.phase = PlayPhase;
}else{
console.log("Not mulligan phase: " + game.phase);
return;
}
game.turn = game.turn.foe;
}
function activename(active){
return active?active.activename:"";
}
Expand Down
52 changes: 43 additions & 9 deletions index.html
Expand Up @@ -50,7 +50,8 @@
}
function setWinner(play){
game.winner=play;
endturn.setText(play==game.player1?"Won":"Lost");
game.phase=EndPhase;
endturn.setText((play==game.player1?"Won ":"Lost ")+game.ply);
}
function player2summon(handindex, tgt){
var card = game.player2.hand[handindex].card;
Expand Down Expand Up @@ -237,18 +238,19 @@
}
}
if (game.turn == game.player1){
game.player1.drawhand();
game.player2.drawhand();
game.player1.drawhand(7);
game.player2.drawhand(7);
}else{
game.player2.drawhand();
game.player1.drawhand();
game.player2.drawhand(7);
game.player1.drawhand(7);
}
if (ai){
game.player2.ai = ai;
if(game.turn == game.player2){
game.player2.ai();
progressMulligan(game);
}
}
cancel.setText("Mulligan");
endturn.setText("End Turn");
mainStage = gameui;
}
Expand Down Expand Up @@ -462,7 +464,18 @@
game = undefined;
mainStage = menuui;
}else if (game.turn == game.player1){
if (discard == undefined && game.player1.hand.length == 8){
if (game.phase == MulliganPhase1 || game.phase == MulliganPhase2){
if(!game.player2.ai){
socket.emit("mulligan", true);
}
progressMulligan(game);
if (game.phase == MulliganPhase2 && game.player2.ai){
progressMulligan(game);
}
if (game.phase == PlayPhase){
cancel.setText("Cancel");
}
}else if (discard == undefined && game.player1.hand.length == 8){
discarding = true;
}else{
discarding = false;
Expand All @@ -482,12 +495,15 @@
}
}
gameui.addChild(endturn);
var cancel = new PIXI.Text("Cancel", {font: "16px Arial bold"});
var cancel = new PIXI.Text("", {font: "16px Arial bold"});
cancel.position.x = 800;
cancel.position.y = 500;
cancel.interactive = true;
cancel.click = function() {
if (game.turn == game.player1){
if ((game.phase == MulliganPhase1 || game.phase == MulliganPhase2) && game.turn == game.player1 && game.player1.hand.length>0){
game.player1.drawhand(game.player1.hand.length-1);
socket.emit("mulligan");
}else if (game.turn == game.player1){
if (targetingMode){
targetingMode = null;
targetingModeCb = null;
Expand Down Expand Up @@ -558,6 +574,7 @@
cardart.setTexture(getArt(game.player1.hand[_i].card.code));
}
handsprite[0][i].click = function(){
if (game.phase != PlayPhase)return;
var cardinst = game.player1.hand[_i];
if (cardinst){
if (discarding){
Expand Down Expand Up @@ -597,6 +614,7 @@
}
}
handsprite[1][i].click = function(){
if (game.phase != PlayPhase)return;
if (targetingMode){
var cardinst = game.player2.hand[_i];
if (cardinst && targetingMode(cardinst)){
Expand Down Expand Up @@ -633,6 +651,7 @@
setInfo(game.players[_j].creatures[_i]);
}
creasprite[j][i].click = function(){
if (game.phase != PlayPhase)return;
var crea = game.players[_j].creatures[_i];
if (!crea)return;
if (targetingMode && targetingMode(crea)){
Expand Down Expand Up @@ -663,6 +682,7 @@
setInfo(game.players[_j].permanents[_i]);
}
permsprite[j][i].click = function(){
if (game.phase != PlayPhase)return;
var perm = game.players[_j].permanents[_i];
if (!perm)return;
if (targetingMode && targetingMode(perm)){
Expand Down Expand Up @@ -705,6 +725,7 @@
setInfo(game.players[_j].shield);
}
weapsprite[j].click = function(){
if (game.phase != PlayPhase)return;
var weap = game.players[_j].weapon;
if (!weap)return
if (targetingMode && targetingMode(weap)){
Expand All @@ -719,6 +740,7 @@
}
}
shiesprite[j].click = function(){
if (game.phase != PlayPhase)return;
var shie = game.players[_j].shield;
if (!shie)return
if (targetingMode && targetingMode(shie)){
Expand Down Expand Up @@ -772,6 +794,7 @@
setInfo(game.players[_j]);
}
hptext[j].click = function(){
if (game.phase != PlayPhase)return;
if (targetingMode && targetingMode(game.players[_j])){
targetingMode = undefined;
targetingModeCb(game.players[_j]);
Expand Down Expand Up @@ -810,6 +833,17 @@
socket.on("chat", function(data) {
document.getElementById("chatArea").value = data;
});
socket.on("mulligan", function(data) {
if (data === true){
progressMulligan(game);
if (game.phase == PlayPhase){
cancel.setText("Cancel");
}
}else{
game.player2.drawhand(game.player2.hand.length-1);
}
document.getElementById("chatArea").value = data;
});
function maybeSendChat(e) {
e.cancelBubble = true;
if (e.keyCode != 13)return;
Expand Down
1 change: 1 addition & 0 deletions server.js
Expand Up @@ -55,4 +55,5 @@ io.sockets.on("connection", function(socket) {
foeEcho(socket, "summon");
foeEcho(socket, "active");
foeEcho(socket, "chat");
foeEcho(socket, "mulligan");
});

0 comments on commit 012701b

Please sign in to comment.