void Armor::onEvent(event::Event * const event) { if (event->id() == ChangedInventoryItems::ID) { ChangedInventoryItems* e = static_cast<ChangedInventoryItems*> (event); for (set<unsigned char>::iterator k = e->keys().begin(); k != e->keys().end(); ++k) { if (betterThanCurrent(Inventory::itemAtKey(*k))) _put_on.insert(*k); else _put_on.erase(*k); } } else if (event->id() == ReceivedItems::ID) { ReceivedItems* e = static_cast<ReceivedItems*> (event); for (map<unsigned char, Item>::iterator i = e->items().begin(); i != e->items().end(); ++i) { if (data::Armor::armors().find(i->second.name()) == data::Armor::armors().end()) continue; // not armor if (i->second.beatitude() != BEATITUDE_UNKNOWN) { /* known beatitude, should we wear it? */ if (i->second.beatitude() != CURSED && betterThanCurrent(i->second)) _put_on.insert(i->first); // it's not cursed and (possibly) better than what we're wearing else _put_on.erase(i->first); continue; } Beatify b(i->first, 175); EventBus::broadcast(&b); } } else if (event->id() == WantItems::ID) { WantItems* e = static_cast<WantItems*> (event); if (Saiph::encumbrance() >= BURDENED) { /* burdened and beatifying, (and is on a stash): pick up */ if (World::shortestPath(ALTAR).cost() < UNPASSABLE) { if (Saiph::encumbrance() < STRESSED) { if (e->safeStash()) { for (map<unsigned char, Item>::iterator i = e->items().begin(); i != e->items().end(); ++i) { if (betterThanCurrent(i->second)) i->second.want(i->second.count()); } } } /* burdened and not beatifying: stash */ } else if (e->safeStash()) { loopTimeout = World::turn() + 10; } /* not burdened */ } else { /* and not on safe stash: pick up */ if (!e->safeStash() && loopTimeout <= World::turn()) { /* ^ this also means 'drop at every safe stash if not burdened' */ /* TODO: to avoid this, check whether on upstair, without stashing */ for (map<unsigned char, Item>::iterator i = e->items().begin(); i != e->items().end(); ++i) { if (betterThanCurrent(i->second)) i->second.want(i->second.count()); } } } } }
void Armor::onEvent(event::Event * const event) { if (event->id() == ChangedInventoryItems::ID) { ChangedInventoryItems* e = static_cast<ChangedInventoryItems*> (event); for (set<unsigned char>::iterator k = e->keys().begin(); k != e->keys().end(); ++k) { if (betterThanCurrent(Inventory::itemAtKey(*k))) _put_on.insert(*k); else _put_on.erase(*k); } } else if (event->id() == ReceivedItems::ID) { ReceivedItems* e = static_cast<ReceivedItems*> (event); for (map<unsigned char, Item>::iterator i = e->items().begin(); i != e->items().end(); ++i) { if (data::Armor::armors().find(i->second.name()) == data::Armor::armors().end()) continue; // not armor if (i->second.beatitude() != BEATITUDE_UNKNOWN) { /* known beatitude, should we wear it? */ if (i->second.beatitude() != CURSED && betterThanCurrent(i->second)) _put_on.insert(i->first); // it's not cursed and (possibly) better than what we're wearing else _put_on.erase(i->first); continue; } Beatify b(i->first, 175); EventBus::broadcast(&b); } } else if (event->id() == WantItems::ID) { WantItems* e = static_cast<WantItems*> (event); if (e->safeStash() && World::shortestPath(ALTAR).cost() >= UNPASSABLE) { /* on safe stash and can't path to altar, drop */ } else if (Saiph::encumbrance() < BURDENED && (!e->safeStash() || World::shortestPath(ALTAR).cost() < UNPASSABLE)) { /* we're not burdened and not on a safe stash or we can't reach an altar, loot armor */ /* if we are on a safe stash and can't reach an altar then we will drop armor */ for (map<unsigned char, Item>::iterator i = e->items().begin(); i != e->items().end(); ++i) { if (betterThanCurrent(i->second)) i->second.want(i->second.count()); } } } }