SM: 0.4.2 percent goals fix (#2183)

fixed percent items goals that can fail generation (reported here https://discord.com/channels/731205301247803413/1147318124383850516/1147318124383850516 and here https://discord.com/channels/731205301247803413/1138137515505750108/1138137515505750108)
This commit is contained in:
lordlou 2023-09-19 19:26:42 -04:00 committed by GitHub
parent 6e02a4ca3c
commit 0012584e51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -150,7 +150,6 @@ class GraphBuilder(object):
# update item% objectives
accessibleItems = [il.Item for il in allItemLocs if ilCheck(il)]
majorUpgrades = [item.Type for item in accessibleItems if item.BeamBits != 0 or item.ItemBits != 0]
sm.objectives.setItemPercentFuncs(len(accessibleItems), majorUpgrades)
if split == "Scavenger":
# update escape access for scav with last scav loc
lastScavItemLoc = progItemLocs[-1]
@ -163,6 +162,7 @@ class GraphBuilder(object):
if ilCheck(itemLoc) and (split.startswith("Full") or itemLoc.Location.isClass(split)):
availLocsByArea[itemLoc.Location.GraphArea].append(itemLoc.Location.Name)
self.log.debug("escapeTrigger. availLocsByArea="+str(availLocsByArea))
sm.objectives.setItemPercentFuncs(len(accessibleItems), majorUpgrades, container)
sm.objectives.setAreaFuncs({area:lambda sm,ap:SMBool(len(container.getLocs(lambda loc: loc.Name in availLocsByArea[area]))==0) for area in availLocsByArea})
self.log.debug("escapeTrigger. collect locs until G4 access")
# collect all item/locations up until we can pass G4 (the escape triggers)

View File

@ -511,16 +511,18 @@ class Objectives(object):
def setScavengerHuntFunc(self, scavClearFunc):
self.goals["finish scavenger hunt"].clearFunc = scavClearFunc
def setItemPercentFuncs(self, totalItemsCount=None, allUpgradeTypes=None):
def getPctFunc(pct, totalItemsCount):
def setItemPercentFuncs(self, totalItemsCount=None, allUpgradeTypes=None, container=None):
def getPctFunc(total_needed, container):
def f(sm, ap):
nonlocal pct, totalItemsCount
return sm.hasItemsPercent(pct, totalItemsCount)
nonlocal total_needed, container
locs_checked = len(container.getUsedLocs(lambda loc: True))
return SMBool(locs_checked >= total_needed)
return f
# AP: now based on location checks instead of local item
for pct in [25,50,75,100]:
goal = 'collect %d%% items' % pct
self.goals[goal].clearFunc = getPctFunc(pct, totalItemsCount)
self.goals[goal].clearFunc = getPctFunc(totalItemsCount * pct / 100, container)
if allUpgradeTypes is not None:
self.goals["collect all upgrades"].clearFunc = lambda sm, ap: sm.haveItems(allUpgradeTypes)