Commit 7d73ab35 authored by Craig S. Cottingham's avatar Craig S. Cottingham

Finish adding rice as a distillable ingredient

parent 175831c4
......@@ -30,6 +30,13 @@ class Still extends EntityItem {
POTATO = 'potato',
RICE = 'rice';
static final Map<String, int> FERMENTABILITY = {
CORN: 4,
GRAIN: 1,
POTATO: 8,
RICE: 2
};
static final Action ACTION_ADD = new Action()
..timeRequired = 500
..multiEnabled = true
......@@ -57,8 +64,6 @@ class Still extends EntityItem {
int pending = 0;
int processed = 0;
Map<String, int> itemsAdded = {};
bool collecting = false;
Still(String id, num x, num y, num z, num rotation, bool h_flip, String streetName) : super(id, x, y, z, rotation, h_flip, streetName) {
......@@ -72,6 +77,7 @@ class Still extends EntityItem {
..add(ACTION_ADD_CORN)
..add(ACTION_ADD_GRAIN)
..add(ACTION_ADD_POTATO)
..add(ACTION_ADD_RICE)
..add(ACTION_COLLECT);
}
......@@ -105,17 +111,13 @@ class Still extends EntityItem {
@override
Map<String, String> getPersistMetadata() => super.getPersistMetadata()
..['pending'] = pending.toString()
..['processed'] = processed.toString()
..['itemsAdded'] = JSON.encode(itemsAdded);
..['processed'] = processed.toString();
@override
void restoreState(Map<String, String> metadata) {
super.restoreState(metadata);
pending = int.parse((metadata['pending'] ?? 0).toString());
processed = int.parse((metadata['processed'] ?? 0).toString());
if (metadata.containsKey('itemsAdded')) {
itemsAdded = JSON.decode(metadata['itemsAdded']);
}
}
@override
......@@ -123,26 +125,15 @@ class Still extends EntityItem {
if (pending >= INPUT_PER_HOOCH) {
toast('Wait for me to finish!', userSocket);
return false;
} else if (pending > 0) {
await Future.forEach(itemsAdded.keys, (String itemType) async {
await InventoryV2.addItemToUser(email, itemType, itemsAdded[itemType]);
});
itemsAdded = {};
return await super.pickUp(userSocket: userSocket, email: email);
} else {
return await super.pickUp(userSocket: userSocket, email: email);
}
}
Future<bool> addHops(String itemType, String email, [int count = 1]) async {
Future<bool> addFermentables(String itemType, String email, [int count = 1]) async {
try {
int taken = await InventoryV2.takeAnyItemsFromUser(email, itemType, count);
pending += taken;
if (itemsAdded.containsKey(itemType)) {
itemsAdded[itemType] += taken;
} else {
itemsAdded[itemType] = taken;
}
pending += taken * FERMENTABILITY[itemType];
SkillManager.learn(SKILL, email, (count / 3).ceil());
return true;
......@@ -152,18 +143,14 @@ class Still extends EntityItem {
}
}
Future<bool> addCorn({WebSocket userSocket, String email, int count: 1}) async => addHops(CORN, email, count);
Future<bool> addGrain({WebSocket userSocket, String email, int count: 1}) async => addHops(GRAIN, email, count);
Future<bool> addPotato({WebSocket userSocket, String email, int count: 1}) async => addHops(POTATO, email, count);
Future<bool> addRice({WebSocket userSocket, String email, int count: 1}) async => addHops(RICE, email, count);
Future<bool> addCorn({WebSocket userSocket, String email, int count: 1}) async => addFermentables(CORN, email, count);
Future<bool> addGrain({WebSocket userSocket, String email, int count: 1}) async => addFermentables(GRAIN, email, count);
Future<bool> addPotato({WebSocket userSocket, String email, int count: 1}) async => addFermentables(POTATO, email, count);
Future<bool> addRice({WebSocket userSocket, String email, int count: 1}) async => addFermentables(RICE, email, count);
Future<bool> collect({WebSocket userSocket, String email}) async {
if (processed == 0) {
if (pending == 0) {
toast("There's nothing to collect!", userSocket);
} else {
toast("There's not enough in here to make any hooch worth collecting!", userSocket);
}
toast("There's nothing to collect!", userSocket);
return false;
} else {
int collected = 0;
......@@ -187,7 +174,6 @@ class Still extends EntityItem {
// Done
collecting = false;
itemsAdded = {};
SkillManager.learn(SKILL, email, (collected / 4).ceil());
return true;
......
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