mirror of
https://github.com/chaoticbackup/chaoticbackup.github.io.git
synced 2026-08-21 08:04:18 -05:00
[fix] one move per turn
This commit is contained in:
@@ -40,6 +40,33 @@ export default class Board extends React.Component {
|
||||
this.loadcards();
|
||||
}
|
||||
|
||||
// TODO
|
||||
loadcards() {
|
||||
this.spaces[4].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Maxxor", 'i')}});
|
||||
this.spaces[4].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Maxxor's Torch", 'i')}});
|
||||
this.spaces[1].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Staluk", 'i')}});
|
||||
this.spaces[1].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Vlaric Shard", 'i')}});
|
||||
for (let i = 0; i < 6; i++) {
|
||||
this.spaces[i].creatures[0].controlled = true;
|
||||
this.spaces[i].battlegear[0].controlled = true;
|
||||
}
|
||||
this.spaces[7].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Chaor", 'i')}});
|
||||
this.spaces[7].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Whepcrack", 'i')}});
|
||||
}
|
||||
|
||||
empty_card(type) {
|
||||
let card = {
|
||||
'data': null,
|
||||
'selected': false,
|
||||
'selectable': true,
|
||||
'controlled': false
|
||||
}
|
||||
if (type == "creatures") {
|
||||
card.moveable = true;
|
||||
}
|
||||
return card;
|
||||
}
|
||||
|
||||
// This is a wraper function for preforming changes to game state
|
||||
// It preforms the change locally and propegates it higher
|
||||
// So that a network listener can reflect the change on the other client
|
||||
@@ -54,14 +81,13 @@ export default class Board extends React.Component {
|
||||
makeChange = (change) => {
|
||||
// seriously calling without a change?
|
||||
if (!change) return;
|
||||
console.log(change.event, change.action);
|
||||
console.log(change); // TODO remove
|
||||
let action = change.action;
|
||||
|
||||
// change the game's phase
|
||||
if (change.event == "phase") {
|
||||
// action: "string"
|
||||
this.phase = action;
|
||||
console.log(this.phase);
|
||||
}
|
||||
|
||||
// add a card to a space
|
||||
@@ -88,32 +114,6 @@ export default class Board extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
empty_card(type) {
|
||||
let card = {
|
||||
'data': null,
|
||||
'selected': false,
|
||||
'selectable': true,
|
||||
'controlled': false
|
||||
}
|
||||
if (type == "creatures") {
|
||||
card.moveable = true;
|
||||
}
|
||||
return card;
|
||||
}
|
||||
|
||||
// TODO
|
||||
loadcards() {
|
||||
this.spaces[5].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Maxxor", 'i')}});
|
||||
this.spaces[5].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Maxxor's Torch", 'i')}});
|
||||
this.spaces[2].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Staluk", 'i')}});
|
||||
this.spaces[2].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Vlaric Shard", 'i')}});
|
||||
for (let i = 0; i < 6; i++) {
|
||||
this.spaces[i].creatures[0].controlled = true;
|
||||
this.spaces[i].battlegear[0].controlled = true;
|
||||
}
|
||||
this.spaces[8].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Chaor", 'i')}});
|
||||
this.spaces[8].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Whepcrack", 'i')}});
|
||||
}
|
||||
|
||||
resetCardSelection() {
|
||||
this.spaces.forEach((space) => {
|
||||
@@ -134,36 +134,6 @@ export default class Board extends React.Component {
|
||||
return false;
|
||||
}
|
||||
|
||||
moveSelection(source, destination, movement) {
|
||||
if (source == destination) return false;
|
||||
|
||||
let src_card = this.spaces[source].creatures[0];
|
||||
if (!src_card.moveable) return false; // If already moved, no valid movement
|
||||
|
||||
let des_card = this.spaces[destination].creatures[0];
|
||||
|
||||
let valid = adjacency_6[source];
|
||||
// for each level of swift, increase moveable range
|
||||
// TODO account for range
|
||||
for (let i = 0; i < movement; i++) {
|
||||
if (valid.includes(destination)) {
|
||||
// Check if space occupied
|
||||
if (des_card.data != null) {
|
||||
// Can't move into occupied space of own tribe
|
||||
if (des_card.controlled) return false;
|
||||
// Check if can start combat
|
||||
else return this.canAttack();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
valid.forEach((i) => {
|
||||
valid = [].concat(valid, adjacency_6[i]);
|
||||
});
|
||||
}
|
||||
|
||||
return false; // if all else its probably not moveable
|
||||
}
|
||||
|
||||
selectCard(e) {
|
||||
let id = e.target.id.substr(1);
|
||||
let type = (() => {
|
||||
@@ -174,7 +144,7 @@ export default class Board extends React.Component {
|
||||
}
|
||||
})();
|
||||
|
||||
// Reset selection
|
||||
// When clicking a non-valid target, reset selection
|
||||
if (this.spaces[id][type][0].selectable == false) {
|
||||
return this.resetCardSelection();
|
||||
}
|
||||
@@ -188,7 +158,8 @@ export default class Board extends React.Component {
|
||||
// moving into a space
|
||||
if (this.source > 0) {
|
||||
this.submitChange({event: "movement", action: {src: this.source, dest: id}});
|
||||
this.spaces[id].moveable = false;
|
||||
// Only one move per turn
|
||||
this.spaces[id].creatures[0].moveable = false;
|
||||
return this.resetCardSelection();
|
||||
}
|
||||
|
||||
@@ -197,7 +168,9 @@ export default class Board extends React.Component {
|
||||
|
||||
// select a card
|
||||
this.source = id;
|
||||
let src_card = this.spaces[this.source].creatures[0];
|
||||
|
||||
// Calculate range of spaces based on swift
|
||||
let mv = ((data) => {
|
||||
let swift = (new RegExp(/swift ([0-9]+)/gi).exec(data.gsx$ability));
|
||||
if (swift) return parseInt(swift[1]) + 1;
|
||||
@@ -210,7 +183,34 @@ export default class Board extends React.Component {
|
||||
card.selectable = false;
|
||||
});
|
||||
space.creatures.forEach((card) => {
|
||||
card.selectable = this.moveSelection(id, i, mv);
|
||||
let des_card = this.spaces[i].creatures[0];
|
||||
card.selectable = ((src_id, dest_id, movement) => {
|
||||
// If already moved, no valid movement
|
||||
if (!src_card.moveable) return false;
|
||||
// No self space movement
|
||||
if (src_id == dest_id) return false;
|
||||
|
||||
// for each level of swift, increase moveable range
|
||||
// TODO account for range
|
||||
let valid = adjacency_6[parseInt(src_id) + 1]; // fix offset
|
||||
for (let i = 0; i < movement; i++) {
|
||||
if (valid.includes(parseInt(dest_id) + 1)) { // fix offset
|
||||
// Check if space occupied
|
||||
if (des_card.data != null) {
|
||||
// Can't move into occupied space of own tribe
|
||||
if (des_card.controlled) return false;
|
||||
// Check if can start combat
|
||||
else return this.canAttack();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
valid.forEach((i) => {
|
||||
valid = [].concat(valid, adjacency_6[i]);
|
||||
});
|
||||
}
|
||||
|
||||
return false; // if all else its probably not moveable
|
||||
})(id, i, mv);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -225,21 +225,25 @@ export default class Board extends React.Component {
|
||||
<div className="battleboard">
|
||||
<div className="r1">
|
||||
<div className="space">
|
||||
<Space id={"c1"} cards={this.spaces[1].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b1"} cards={this.spaces[1].battlegear} selectCard={this.selectCard} />
|
||||
<Space id={"c0"} cards={this.spaces[0].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b0"} cards={this.spaces[0].battlegear} selectCard={this.selectCard} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="r2">
|
||||
<div className="space">
|
||||
<Space id={"c1"} cards={this.spaces[1].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b1"} cards={this.spaces[1].battlegear} selectCard={this.selectCard} />
|
||||
</div>
|
||||
<div className="space">
|
||||
<Space id={"c2"} cards={this.spaces[2].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b2"} cards={this.spaces[2].battlegear} selectCard={this.selectCard} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="r3">
|
||||
<div className="space">
|
||||
<Space id={"c3"} cards={this.spaces[3].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b3"} cards={this.spaces[3].battlegear} selectCard={this.selectCard} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="r3">
|
||||
<div className="space">
|
||||
<Space id={"c4"} cards={this.spaces[4].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b4"} cards={this.spaces[4].battlegear} selectCard={this.selectCard} />
|
||||
@@ -248,12 +252,12 @@ export default class Board extends React.Component {
|
||||
<Space id={"c5"} cards={this.spaces[5].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b5"} cards={this.spaces[5].battlegear} selectCard={this.selectCard} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="r4">
|
||||
<div className="space">
|
||||
<Space id={"c6"} cards={this.spaces[6].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b6"} cards={this.spaces[6].battlegear} selectCard={this.selectCard} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="r4">
|
||||
<div className="space">
|
||||
<Space id={"c7"} cards={this.spaces[7].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b7"} cards={this.spaces[7].battlegear} selectCard={this.selectCard} />
|
||||
@@ -262,10 +266,22 @@ export default class Board extends React.Component {
|
||||
<Space id={"c8"} cards={this.spaces[8].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b8"} cards={this.spaces[8].battlegear} selectCard={this.selectCard} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="r5">
|
||||
<div className="space">
|
||||
<Space id={"c9"} cards={this.spaces[9].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b9"} cards={this.spaces[9].battlegear} selectCard={this.selectCard} />
|
||||
</div>
|
||||
<div className="space">
|
||||
<Space id={"c10"} cards={this.spaces[10].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b10"} cards={this.spaces[10].battlegear} selectCard={this.selectCard} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="r6">
|
||||
<div className="space">
|
||||
<Space id={"c11"} cards={this.spaces[11].creatures} selectCard={this.selectCard} />
|
||||
<Space id={"b11"} cards={this.spaces[11].battlegear} selectCard={this.selectCard} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -19,7 +19,7 @@ export default class Play extends React.Component {
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
this.makeChange();
|
||||
// this.makeChange();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
Reference in New Issue
Block a user