-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing Prefabs so FusedBombs can spawn lit #157
Conversation
@@ -194,7 +194,7 @@ public void tickEquipped(Player player, Level level, float delta, String equipLo | |||
chargeEffect.tex = 0; | |||
|
|||
chargeTime = 0f; | |||
level.addEntity(chargeEffect); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, the Level class has a SpawnEntity method that does this same thing
@@ -49,7 +49,7 @@ public void SpawnEntity(Level level, Entity e) { | |||
if (e instanceof Monster) { | |||
((Monster)e).Init(level, Game.instance.player.level); | |||
} | |||
level.addEntity(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the Prefab behavior is potentially scary, could this be wired up by overriding the tossItem
function like the Potion does?
public void tossItem(Level level, float attackPower) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for when you break a pot and bomb drops. Instead of changing how prefabs spawn things, I could change the guard inside of FusedBomb
Reverted the changes to Previous: if(source == Level.Source.SPAWNED && !wasSpawned) {
isLit = Game.rand.nextFloat() < this.chanceIsLit;
isDud = Game.rand.nextFloat() < this.chanceIsDud;
}
else if(source == Level.Source.LEVEL_START) {
isLit = false;
isDud = Game.rand.nextFloat() < this.chanceIsDud;
}
wasSpawned = true; New: isLit = Game.rand.nextFloat() < chanceIsLit;
isDud = Game.rand.nextFloat() < chanceIsDud;
wasSpawned = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as expected.
isLit = false; | ||
isDud = Game.rand.nextFloat() < this.chanceIsDud; | ||
} | ||
isLit = Game.rand.nextFloat() < chanceIsLit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this now cause the bomb logic to reset on save loads, now that it isn't guarding on wasSpawned
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, yes you are correct. I've reworked the init
method:
// Don't set any fields if this was placed in the editor.
if (wasJustPlacedInEditor(source)) { // source == Level.Source.EDITOR
return;
}
// Guard against relighting on loading of a save.
if (wasSpawned) {
return;
}
isLit |= Game.rand.nextFloat() < chanceIsLit;
isDud |= Game.rand.nextFloat() < chanceIsDud;
wasSpawned = true;
Summary
Fixes bombs never spawning lit. This was because
Level.addEntity
always set source toSource.LEVEL_START
and the FusedBomb class has a guard against that case.I added a
Level.addEntity(Entity e, Source source)
so prefabs can set the source correctly.