Skip to content

Instantly share code, notes, and snippets.

@Suor
Created January 21, 2021 18:45
Show Gist options
  • Save Suor/6fa891dd2e635e440f6bb967ae1ee6d0 to your computer and use it in GitHub Desktop.
Save Suor/6fa891dd2e635e440f6bb967ae1ee6d0 to your computer and use it in GitHub Desktop.
Battle Brothers: debug ambitions not happening
::mods_registerMod("mod_fix_ambitions", 0.1, "Fix ambitions not fullfilling");
::mods_queue("mod_fix_ambitions", "mod_hooks(>=19)", function() {
this.logInfo("fa: loading");
::mods_hookNewObject("ambitions/ambition_manager", function(obj) {
this.logInfo("fa: hook ambition manager");
local update = obj.update;
obj.update = function() {
this.logInfo("fa: ambitions.update available=" + this.isAvailable() + " ambition=" + this.m.ActiveAmbition);
if (this.m.ActiveAmbition != null) {
this.logInfo("fa: active ambition " + this.m.ActiveAmbition.m.ID + " success=" + this.m.ActiveAmbition.isSuccess())
this.logInfo("fa: canFireEvent " + this.World.Events.canFireEvent());
}
update();
}
});
::mods_hookNewObject("events/event_manager", function(obj) {
this.logInfo("fa: hook event manager");
obj.canFireEvent = function( _ignoreEvaluating = false, _ignorePreviousBattle = false ) {
this.logInfo("fa: canFireEvent 0")
if (this.World.State.getMenuStack().hasBacksteps() || this.LoadingScreen != null && (this.LoadingScreen.isAnimating() || this.LoadingScreen.isVisible()) || this.World.State.m.EventScreen.isVisible() || this.World.State.m.EventScreen.isAnimating())
{
return false;
}
this.logInfo("fa: canFireEvent 1")
if (("State" in this.Tactical) && this.Tactical.State != null)
{
return false;
}
this.logInfo("fa: canFireEvent 2")
if (this.m.ActiveEvent != null)
{
return false;
}
this.logInfo("fa: canFireEvent 3 " + this.m.Thread)
if (!_ignoreEvaluating && this.m.Thread != null)
{
return false;
}
this.logInfo("fa: canFireEvent 4")
if (!_ignorePreviousBattle && this.Time.getVirtualTimeF() - this.m.LastBattleTime < 2.0)
{
return false;
}
this.logInfo("fa: canFireEvent 5")
local parties = this.World.getAllEntitiesAtPos(this.World.State.getPlayer().getPos(), 400.0);
foreach( party in parties )
{
if (!party.isAlliedWithPlayer())
{
return false;
}
}
this.logInfo("fa: canFireEvent 6")
return true;
}
obj.selectEvent = function() {
// Function is a generator.
local score = 0;
local eventToFire;
this.logInfo("fa: selectEvent 0, len="+this.m.Events.len())
for( local i = 0; i < this.m.Events.len(); i = ++i )
{
this.logInfo("fa: selectEvent 1, i=" + i + " eventID=" + this.m.Events[i].getID());
if (this.m.LastEventID == this.m.Events[i].getID() && !this.m.Events[i].isSpecial())
{
this.m.Events[i].clear();
}
else
{
this.m.Events[i].update();
}
this.logInfo("fa: selectEvent 1")
if (i % 2 == 0)
{
this.logInfo("fa: selectEvent 1a")
yield false;
}
this.logInfo("fa: selectEvent 2")
if (this.m.Events[i].getScore() <= 0 || this.World.Statistics.isNewsReady() && this.m.Events[i].getScore() < 2000 || this.Time.getVirtualTimeF() - this.m.LastBattleTime < 5.0 && this.m.Events[i].getScore() < 500)
{
}
else
{
score = score + this.m.Events[i].getScore();
}
}
local pick = this.Math.rand(1, score);
this.logInfo("fa: selectEvent 3, pick=" + pick)
yield false;
this.logInfo("fa: selectEvent 4")
for( local i = 0; i < this.m.Events.len(); i = ++i )
{
// this.logInfo("fa: selectEvent 5, i="+i+" eventID=" + this.m.Events[i].getID())
if (this.m.Events[i].getScore() <= 0 || this.World.Statistics.isNewsReady() && this.m.Events[i].getScore() < 2000 || this.Time.getVirtualTimeF() - this.m.LastBattleTime < 5.0 && this.m.Events[i].getScore() < 500)
{
}
else
{
if (pick <= this.m.Events[i].getScore())
{
eventToFire = this.m.Events[i];
break;
}
pick = pick - this.m.Events[i].getScore();
}
}
this.logInfo("fa: selectEvent 6, eventToFire=" + eventToFire ? eventToFire.getID() : "none")
if (eventToFire == null)
{
this.logDebug("no event????");
return true;
}
this.logInfo("fa: selectEvent 7")
yield false;
this.m.ActiveEvent = eventToFire;
this.m.ActiveEvent.clear();
this.m.ActiveEvent.update();
this.logInfo("fa: selectEvent 8, score=" + this.m.ActiveEvent.getScore())
if (this.m.ActiveEvent.getScore() == 0)
{
this.m.ActiveEvent.clear();
this.m.ActiveEvent = null;
return true;
}
this.logInfo("fa: selectEvent 9")
if (this.m.ActiveEvent.getScore() < 500)
{
local parties = this.World.getAllEntitiesAtPos(this.World.State.getPlayer().getPos(), 400.0);
foreach( party in parties )
{
if (!party.isAlliedWithPlayer())
{
this.m.ActiveEvent.clear();
this.m.ActiveEvent = null;
return true;
}
}
}
this.logInfo("fa: selectEvent 10")
if (this.m.ActiveEvent.getScore() < 2000)
{
this.m.LastEventTime = this.Time.getVirtualTimeF();
}
this.logInfo("fa: selectEvent 11")
this.m.ActiveEvent.fire();
this.m.IsEventShown = this.World.State.showEventScreen(this.m.ActiveEvent);
return true;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment