-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorders.js
156 lines (122 loc) · 4.35 KB
/
orders.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
function Order(name, issuer) {
//how the starred orders will be played?
this.name = name;
this.issuer = issuer; //todo should I store the player or the house?
}
function OrderCollection(board, gameStats) { //todo more verifications on the order placement
this.board = board;
this.gameStats = gameStats;
this.orders = new Array(this.board.areaCount);
this.revealOrders = false;
//returns true if it replaced a previously placed order
this.placeOrder = function(area, order) {
if (!board.hasController(area) && !board.isOccupied(area)) {
throw 'A player can only place orders on units he controls. ' + area.name + ' has no controller or is not occupied.';
}
if (board.getController(area).name != order.issuer.name) {
throw 'A player can only place orders on the units he controls. Those units are controlled by the house ' + board.getController(area).name;
}
//todo other checks?
//todo check if a player placed more orders than he's able to. Consider his King's Court track.
var returnValue = false;
if (this.orders[area.id] != null) {
returnValue = true;
}
this.orders[area.id] = order;
return returnValue;
};
this.removeOrder = function(area) {
this.orders[area.id] = null;
};
//supposed to be a private method
this.getOrdersOfType = function(orderName) {
var orderClass = window[orderName];
var ordersOfType = new Array();
for (var i = 0; i < this.orders.length; i++) {
if (this.orders[i] === null || typeof(this.orders[i]) === 'undefined') {
continue;
}
if (this.orders[i] instanceof orderClass) {
ordersOfType.push(this.orders[i]);
}
}
return ordersOfType;
};
//supposed to be a private method
this.sortOrdersByIronThroneInfluence = function(someOrders) { //todo it seems this will be reused a lot. Should this method really be here?
var rank = this.gameStats.ironThrone.getRank();
var hashRank = new Object(); //todo consider applying this technique in the SingleRankTracker.getRank() method
for (var i = 0; i < rank.length; i++) {
hashRank[rank[i].name] = i;
}
var sortFunction = function(orderA, orderB) {
return hashRank[orderA.issuer.name] - hashRank[orderB.issuer.name];
};
someOrders.sort(sortFunction);
return someOrders;
};
this.getRaidOrders = function() {
return this.sortOrdersByIronThroneInfluence(this.getOrdersOfType('RaidOrder'));
};
this.getMarchOrders = function() {
return this.sortOrdersByIronThroneInfluence(this.getOrdersOfType('MarchOrder'));
};
this.getDefendOrders = function() {
return this.getOrdersOfType('DefendOrder');
};
this.getSupportOrders = function() {
return this.getOrdersOfType('SupportOrder');
};
this.getConsolidatePowerOrders = function() {
return this.sortOrdersByIronThroneInfluence(this.getOrdersOfType('ConsolidatePowerOrder'));
};
}
RaidOrder.prototype = new Order();
RaidOrder.prototype.constructor = RaidOrder;
function RaidOrder(issuer) {
Order.call(this, 'Raid', issuer);
this.execute = function() {
//todo this.game.board.getAdjacents(this.area);
//check for adjacent orders to see if they can be raided
//show options to player
//ask him to choose what he wants to raid, or if he wants to ignore those orders
};
};
MarchOrder.prototype = new Order();
MarchOrder.prototype.constructor = MarchOrder;
function MarchOrder(issuer, strength) {
Order.call(this, 'March', issuer);
this.strength = strength;
this.execute = function() {
//player will split army?
//what units and where will you move them to?
//will you leave a power token?
//combat, if needed (support + defend) orders + kills + retreat and route
};
};
SupportOrder.prototype = new Order();
SupportOrder.prototype.constructor = SupportOrder;
function SupportOrder(issuer) {
Order.call(this, 'Support', issuer);
this.execute = function() {
//autodetect suportable units
//allow the player to declare support (before cards are shown)
};
};
DefendOrder.prototype = new Order();
DefendOrder.prototype.constructor = DefendOrder;
function DefendOrder(issuer) {
Order.call(this, 'Defend', issuer);
this.execute = function() {
};
};
ConsolidatePowerOrder.prototype = new Order();
ConsolidatePowerOrder.prototype.constructor = ConsolidatePowerOrder;
function ConsolidatePowerOrder(issuer) {
Order.call(this, 'Consolidate Power', issuer);
this.execute = function() {
};
this.cancel = function() {
throw 'Cannot cancel a consolidate power order.';
};
};