Skip to content

Commit

Permalink
Messages fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ToxicFrog committed Jul 21, 2022
1 parent d180462 commit 1a1f60b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions indestructable/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Fix: removed some stray debug logging
- Fix: mod would sometimes stop working entirely on level transition
- Fix: messages from the mod now properly display in the HUD
- Fix: the "you have X lives" message on level entry is no longer overwritten by the autosave message

# 0.1.0

Expand Down
31 changes: 24 additions & 7 deletions indestructable/ca.ancilla.indestructable/Indestructable.zs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class ::IndestructableEventHandler : StaticEventHandler {
if (!force) return; // PANIC
MoveToTail(pawn, force);
force.lives = max(force.lives, GetInt("indestructable_lives_after_level"));
console.printf("You have \c[GOLD]%d\c- extra %s!",
force.lives, force.lives == 1 ? "life" : "lives");
force.SetStateLabel("LevelStartMessage");
}

override void WorldThingDied(WorldEvent evt) {
Expand All @@ -69,8 +68,9 @@ class ::IndestructableEventHandler : StaticEventHandler {
let force = ::IndestructableForce(pawn.FindInventory("::IndestructableForce"));
if (!force) return; // PANIC
force.lives += lives;
console.printf("Absorbed the boss's power! You now have \c[CYAN]%d\c- extra %s!",
force.lives, force.lives == 1 ? "life" : "lives");
force.Message(string.format(
"Absorbed the boss's power! You now have \c[CYAN]%d\c- extra %s!",
force.lives, force.lives == 1 ? "life" : "lives"));
}
}

Expand All @@ -94,6 +94,14 @@ class ::IndestructableForce : Inventory {
// take damage, big hits like standing in a room of exploding barrels can
// still drop them down below the intended restore target.
TNT1 A 0 RestorePlayerHealth();
GOTO Idle;
LevelStartMessage:
// Used to display the "you have X extra lives" message at the start of a
// level. A brief delay is added so that it shows up after start-of-level
// debug logging, the autosave message, etc.
TNT1 A 3;
TNT1 A 0 ShowLevelStartMessage();
GOTO Idle;
Idle:
TNT1 A -1;
STOP;
Expand All @@ -107,6 +115,15 @@ class ::IndestructableForce : Inventory {
return ::IndestructableEventHandler.GetBool(name);
}

void Message(string msg) {
owner.A_Log(msg, true);
}

void ShowLevelStartMessage() {
self.Message(string.format("You have \c[GOLD]%d\c- extra %s!",
self.lives, self.lives == 1 ? "life" : "lives"));
}

override void AbsorbDamage(
int damage, Name damageType, out int newdamage,
Actor inflictor, Actor source, int flags) {
Expand All @@ -131,7 +148,7 @@ class ::IndestructableForce : Inventory {

void ActivateIndestructability() {
--lives;
console.printf("\c+INDESTRUCTABLE!");
Message("\c[RED]INDESTRUCTABLE!");
self.SetStateLabel("RestoreHealth");

GivePowerup("::IndestructableScreenEffect");
Expand All @@ -142,8 +159,8 @@ class ::IndestructableForce : Inventory {
if (GetBool("indestructable_damage_bonus"))
GivePowerup("::IndestructableDamage");

console.printf("You have \c[RED]%d\c- extra %s left!",
lives, lives == 1 ? "life" : "lives");
Message(string.format("You have \c[RED]%d\c- extra %s left!",
lives, lives == 1 ? "life" : "lives"));
}

void RestorePlayerHealth() {
Expand Down

0 comments on commit 1a1f60b

Please sign in to comment.