mirror of
https://github.com/chaoticbackup/chaoticbackup.github.io.git
synced 2026-04-25 15:58:11 -05:00
range and swift work
This commit is contained in:
parent
be6c94ad05
commit
481d7526df
|
|
@ -6,18 +6,18 @@ import '../../scss/play/battleboard.scss';
|
||||||
|
|
||||||
// array of array of accesible spaces per swift
|
// array of array of accesible spaces per swift
|
||||||
const adjacency_6 = {
|
const adjacency_6 = {
|
||||||
1: [2, 3],
|
0: [1, 2],
|
||||||
2: [1, 3, 4, 5],
|
1: [0, 2, 3, 4],
|
||||||
3: [1, 2, 5, 6],
|
2: [0, 1, 4, 5],
|
||||||
4: [2, 5, 7, 8],
|
3: [1, 4, 6, 7],
|
||||||
5: [2, 3, 4, 6, 7, 8, 9],
|
4: [1, 2, 3, 5, 6, 7, 8],
|
||||||
6: [3, 5, 8, 9],
|
5: [2, 4, 7, 8],
|
||||||
7: [4, 5, 8, 10],
|
6: [3, 4, 7, 9],
|
||||||
8: [4, 5, 6, 7, 9, 10, 11],
|
7: [3, 4, 5, 6, 8, 9, 10],
|
||||||
9: [5, 6, 8, 11],
|
8: [4, 5, 7, 10],
|
||||||
10: [7, 8, 11, 12],
|
9: [6, 7, 10, 11],
|
||||||
11: [8, 9, 10, 12],
|
10: [7, 8, 9, 11],
|
||||||
12: [10, 11]
|
11: [9, 10]
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
|
|
@ -185,7 +185,7 @@ export default class Board extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
selectCard(e) {
|
selectCard(e) {
|
||||||
let id = e.target.id.substr(1);
|
let id = parseInt(e.target.id.substr(1));
|
||||||
let type = (() => {
|
let type = (() => {
|
||||||
switch (e.target.id.charAt(0)) {
|
switch (e.target.id.charAt(0)) {
|
||||||
case 'b': return 'battlegear';
|
case 'b': return 'battlegear';
|
||||||
|
|
@ -221,47 +221,76 @@ export default class Board extends React.Component {
|
||||||
let src_card = this.spaces[this.source].creatures[0];
|
let src_card = this.spaces[this.source].creatures[0];
|
||||||
|
|
||||||
// Calculate range of spaces based on swift
|
// Calculate range of spaces based on swift
|
||||||
let mv = ((data) => {
|
let swift = ((data) => {
|
||||||
let swift = (new RegExp(/swift ([0-9]+)/gi).exec(data.gsx$ability));
|
let s = (new RegExp(/swift ([0-9]+)/gi).exec(data.gsx$ability));
|
||||||
if (swift) return parseInt(swift[1]) + 1;
|
// TODO brainwashed
|
||||||
return 1;
|
if (s) return parseInt(s[1]);
|
||||||
|
return 0;
|
||||||
})(this.spaces[id].creatures[0].data);
|
})(this.spaces[id].creatures[0].data);
|
||||||
|
|
||||||
|
let range = ((data) => {
|
||||||
|
let r = (new RegExp(/^range/mi).exec(data.gsx$ability));
|
||||||
|
// TODO brainwashed
|
||||||
|
if (r) return true;
|
||||||
|
return false;
|
||||||
|
})(this.spaces[id].creatures[0].data);
|
||||||
|
|
||||||
|
// Start with adjacent spaces
|
||||||
|
let valid = adjacency_6[id];
|
||||||
|
let invalid = [];
|
||||||
|
let attackable = [];
|
||||||
|
let last_inx = 0;
|
||||||
|
|
||||||
|
// determine a list of valid spaces to move into
|
||||||
|
// for each level of swift, increase moveable range
|
||||||
|
for (let mv = 0; mv <= swift; mv++) {
|
||||||
|
let lvl = valid;
|
||||||
|
for (let i = last_inx; i < valid.length; i++) {
|
||||||
|
// if (invalid.includes(valid[i])) continue;
|
||||||
|
let des_card = this.spaces[valid[i]].creatures[0];
|
||||||
|
// Ocupied spaces are invalid, but can be used to start combat
|
||||||
|
if (des_card.data != null) {
|
||||||
|
invalid.push(valid[i]);
|
||||||
|
// Can't move into space of own creatures
|
||||||
|
// Otherwise check if can start combat
|
||||||
|
if (!des_card.controlled && this.canAttack()) {
|
||||||
|
attackable.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (swift == 0) continue;
|
||||||
|
// Can't move through without range
|
||||||
|
if (des_card.data == null || range) {
|
||||||
|
lvl = [].concat(lvl, adjacency_6[valid[i]])
|
||||||
|
.filter(function(item, pos, self) {
|
||||||
|
return self.indexOf(item) == pos;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mv + 1 > swift) break; // ignore last set
|
||||||
|
last_inx = valid.length; // don't reiterate same spaces
|
||||||
|
valid = lvl;
|
||||||
|
}
|
||||||
|
// remove invalid spaces
|
||||||
|
valid = valid.filter(x => !invalid.includes(x));
|
||||||
|
|
||||||
// set selectable options
|
// set selectable options
|
||||||
this.spaces.forEach((space, i) => {
|
this.spaces.forEach((space, i) => {
|
||||||
space.battlegear.forEach((card) => {
|
space.battlegear.forEach((card) => {
|
||||||
card.selectable = false;
|
card.selectable = false;
|
||||||
});
|
});
|
||||||
space.creatures.forEach((card) => {
|
let des_card = space.creatures[0];
|
||||||
let des_card = this.spaces[i].creatures[0];
|
des_card.selectable = ((src_id, dest_id) => {
|
||||||
card.selectable = ((src_id, dest_id, movement) => {
|
// If already moved, no valid movement
|
||||||
// If already moved, no valid movement
|
if (!src_card.moveable) return false;
|
||||||
if (!src_card.moveable) return false;
|
// No self space movement
|
||||||
// No self space movement
|
else if (src_id == dest_id) return false;
|
||||||
if (src_id == dest_id) return false;
|
// If its a valid spot
|
||||||
|
else if (valid.includes(dest_id)) return true;
|
||||||
// for each level of swift, increase moveable range
|
// TODO different effect for attackable?
|
||||||
// TODO account for range
|
else if (attackable.includes(dest_id)) return true;
|
||||||
let valid = adjacency_6[parseInt(src_id) + 1]; // fix offset
|
// if all else its probably not moveable
|
||||||
for (let i = 0; i < movement; i++) {
|
else return false;
|
||||||
if (valid.includes(parseInt(dest_id) + 1)) { // fix offset
|
})(id, i);
|
||||||
// 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);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// creature is now selected
|
// creature is now selected
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user