Skip to content
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

Merged
merged 7 commits into from
Nov 4, 2020

Conversation

joshuaskelly
Copy link
Collaborator

Summary

Fixes bombs never spawning lit. This was because Level.addEntity always set source to Source.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.

@@ -194,7 +194,7 @@ public void tickEquipped(Player player, Level level, float delta, String equipLo
chargeEffect.tex = 0;

chargeTime = 0f;
level.addEntity(chargeEffect);
Copy link
Owner

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);
Copy link
Owner

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) {

Copy link
Collaborator Author

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

@joshuaskelly
Copy link
Collaborator Author

Reverted the changes to Level and Prefab. I just removed the guard in FusedBomb.init()

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;

Copy link
Contributor

@PythooonUser PythooonUser left a 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;
Copy link
Owner

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?

Copy link
Collaborator Author

@joshuaskelly joshuaskelly Nov 3, 2020

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;

@joshuaskelly joshuaskelly merged commit c82ea6b into master Nov 4, 2020
@joshuaskelly joshuaskelly deleted the fixes/fused-bomb-not-spawning-lit branch November 4, 2020 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants