1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2026-04-16 06:51:23 +00:00

ru:: guarded items

This commit is contained in:
Zeno Rogue
2026-03-29 14:43:32 +02:00
parent 35dd49a00d
commit 68ba2e1ca4
4 changed files with 52 additions and 0 deletions

View File

@@ -841,6 +841,23 @@ struct shopitem : public item {
virtual void hs(stater& s) override { item::hs(s); s.act("bought", bought, false).act("last_intersect", last_intersect, 0); }
};
struct non_spatial_entity : public entity {
virtual xy siz() { return {0,0}; }
virtual string glyph() { return "?"; }
virtual color_t color() { return 0xC04040FF; }
virtual void draw() override {}
virtual void act() override {}
virtual bool hidden() override { return true; }
};
struct guard_event : non_spatial_entity {
entity *item, *monster;
string monster_name;
bool active;
virtual void act() override;
virtual void hs(stater& s) override { entity::hs(s); s.act("active", active, false); }
};
struct loot : public item {
entity *owner;
bool dropped;

View File

@@ -936,4 +936,27 @@ void icicle::act() {
}
}
void guard_event::act() {
if(monster == nullptr) {
if(!entity_by_id.count(monster_name)) {
println(hlog, "Guard event not connected correctly: ", monster_name);
existing = false;
return;
}
monster = entity_by_id[monster_name];
println(hlog, "guard event connected");
}
if(item->existing && monster->existing) {
active = true;
monster->existing = false;
println(hlog, "guard event activated");
}
if(active && !item->existing && !monster->existing) {
monster->existing = true;
monster->invinc_end = max(monster->invinc_end, gframeid + 100);
active = false;
println(hlog, "guard event deactivated");
}
}
}

View File

@@ -194,4 +194,5 @@ extern vector<unique_ptr<struct entity>> new_entities;
string unspace(const string& s);
string respace(const string& s);
extern map<string, entity*> entity_by_id;
}

View File

@@ -185,6 +185,17 @@ void load_room(fhstream& f, cell *c) {
b->id = unspace(b->pickup_message = scanline_noblank(f));
r.entities.emplace_back(std::move(b));
}
else if(cap == "GUARD") {
auto loot = &*r.entities.back();
println(hlog, "loot is ", loot->id);
auto b = std::make_unique<guard_event>();
b->item = loot;
b->monster = nullptr;
b->monster_name = cutoff("NOTHING");
b->id = b->monster_name + "-GUARD";
println(hlog, "guard ", b->id, " added on ", b->item->id);
r.entities.emplace_back(std::move(b));
}
else if(cap == "SHOPITEM") {
auto b = std::make_unique<shopitem>();
b->respawn = get_xy();