Commit c29d67fe authored by Matthew Odle's avatar Matthew Odle

add tool consumption

parent 88fb60ff
......@@ -26,10 +26,10 @@ export class Building extends React.Component {
<div className={building.producing ? "active" : "inactive"}>Active: {building.producing ? "Yes" : "No" }</div>
<div className="progress" style={progressStyle}>Progress: {building.progress}</div>
{ building.assignedVillagers ? <AssignedVillagers building={building} /> : null }
<button type="button" id="addAVillager" onClick={() => this.props.manageVillagers(building, 1, 'assign')}>+</button>
<button type="button" id="removeAVillger" onClick={() => this.props.manageVillagers(building, 1, 'unassign')}>-</button>
<button type="button" id="addManyVillagers" onClick={() => this.props.manageVillagers(building, 10, 'assign')}>++</button>
<button type="button" id="removeManyVillagers" onClick={() => this.props.manageVillagers(building, 10, 'unassign')}>--</button>
<button type="button" id="addAVillager" onClick={() => this.props.manageVillagerAssignments(building, 1, 'assign')}>+</button>
<button type="button" id="removeAVillger" onClick={() => this.props.manageVillagerAssignments(building, 1, 'unassign')}>-</button>
<button type="button" id="addManyVillagers" onClick={() => this.props.manageVillagerAssignments(building, 10, 'assign')}>++</button>
<button type="button" id="removeManyVillagers" onClick={() => this.props.manageVillagerAssignments(building, 10, 'unassign')}>--</button>
</div>
);
}
......
......@@ -89,7 +89,7 @@ export class Village extends React.Component {
}
}
manageVillagers = (building, amount, operation) => {
manageVillagerAssignments = (building, amount, operation) => {
if (operation === 'assign' && this.getUnassignedVillagers().length > 0) {
this.assignVillagers(building, amount);
}
......@@ -253,9 +253,37 @@ export class Village extends React.Component {
});
};
getTool = (villager) => {
const villageStore = this.state.villageStore.slice();
let tools = villageStore.find( material => material.name === 'tool')
if (tools.count > 0) {
villager.toolDurability = 100;
villager.hasTool = true;
tools.count -= 1;
}
}
checkVillagerTool = (villagers) => {
// only equip tools to villagers that are assigned to a building
villagers.map( villager => villager.toolDurability <= 0 && villager.assignment !== "none" ? villager = this.getTool(villager) : null);
}
updateAllVillagers = (villagers) => {
this.setState({
villagers: villagers,
});
}
manageVillagerConditions = () => {
const villagers = this.state.villagers.slice();
this.checkVillagerTool(villagers);
this.updateAllVillagers(villagers);
}
tick = () => {
const buildings = this.props.buildings.slice();
this.manageProductionBuildings(buildings);
this.manageVillagerConditions();
this.setState({
elapsed: new Date() - this.props.start,
buildings: buildings,
......@@ -289,7 +317,7 @@ export class Village extends React.Component {
<Building
key={building.id}
building={building}
manageVillagers={this.manageVillagers}
manageVillagerAssignments={this.manageVillagerAssignments}
increasePriority={this.increasePriority}
decreasePriority={this.decreasePriority}
/>
......
......@@ -20,7 +20,7 @@ const knobsAndLevers = {
const villageStore = [
{name: 'wood', count: 0, source: 'FORESTER_HUT'},
{name: 'tool', count: 0, source: 'SMITHY'},
{name: 'tool', count: 5, source: 'SMITHY'},
{name: 'iron', count: 0, source: 'MINE'},
{name: 'firewood', count: 0, source: 'WOODCUTTER_HUT'},
];
......@@ -50,7 +50,7 @@ buildings.push({type: 'production',
goods: ['tool'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
progress: 0,
progress: 2,
baseProductionRate: knobsAndLevers.defaultProductionRate,
producing: false
});
......@@ -59,7 +59,7 @@ buildings.push({type: 'extraction',
name: 'FORESTER_HUT',
label: "Forester's Hut",
description: "it's big, it's heavy, it's wood",
priority: 2,
priority: 0,
goods: ['wood'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
......@@ -72,7 +72,7 @@ buildings.push({type: 'extraction',
name: 'MINE',
label: "Mine",
description: "the strength of the earth to forge the tools",
priority: 4,
priority: 1,
goods: ['iron'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
......@@ -85,7 +85,7 @@ buildings.push({type: 'production',
name: 'WOODCUTTER',
label: 'Woodcutter',
description: "it's big, it's heavy, it's wood",
priority: 0,
priority: 3,
materials: ['wood'],
goods: ['firewood'],
assignedVillagers: [],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment