Skip to content

Commit

Permalink
Reimplemented achievement checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevadroz committed Jul 13, 2023
1 parent 96f073b commit 1dddc21
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 852 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.luarc.json
.vscode/launch.json
devDir/
437 changes: 0 additions & 437 deletions content/itempools.xml

This file was deleted.

172 changes: 0 additions & 172 deletions content/items.xml

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions devScripts/exportEnum.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,12 @@ local function export_table(table, path)
file:close()
end

function exports.collectibles()
export_table(CollectibleType, "collectibles")
end

function exports.players()
export_table(PlayerType, "players")
end

function exports.trinkets()
export_table(TrinketType, "trinkets")
end

function exports.cards()
export_table(Card, "cards")
end

function exports.pills()
export_table(PillEffect, "pills")
end

function exports.all()
exports.collectibles()
exports.players()
exports.trinkets()
exports.cards()
exports.pills()
end

exports.table = export_table
Expand Down
104 changes: 18 additions & 86 deletions devScripts/genStatic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!python
# WARNING! THIS FILE IS NOT CLEANED OR ORGANIZED.
import sys
import xml.etree.ElementTree as ET
import json
Expand All @@ -8,64 +9,41 @@
unlockList = [None] * 637
genItemList = []
modItemUnlockList = [None] * 637
ignoreList = {327, 328, 293, 105, 126, 214, 609, 313, 349}
#ignoreList = {327, 328, 293, 105, 126, 214, 609, 313, 349}

extractedPath = sys.argv[1]

items = ET.parse(extractedPath + "resources-dlc3/items.xml")
players = ET.parse(extractedPath + "resources-dlc3/players.xml")
cards = ET.parse(extractedPath + "resources-dlc3/pocketitems.xml")

itempools = ET.parse(extractedPath + "resources-dlc3/itempools.xml")
#itempools = ET.parse(extractedPath + "resources-dlc3/itempools.xml")

def fill_tables():
collect_enum = json.loads(open("enums/collectibles.json", "r").read())
collect_file = create_static_file("../static/collectibles.lua")
collect_file_comma = False
players_enum = json.loads(open("enums/players.json", "r").read())
players_file = create_static_file("../static/players.lua")
players_file_comma = False
trinkets_enum = json.loads(open("enums/trinkets.json", "r").read())
trinket_file = create_static_file("../static/trinkets.lua")
trinket_file_comma = False
cards_enum = json.loads(open("enums/cards.json", "r").read())
cards_file = create_static_file("../static/cards.lua")
cards_file_comma = False
pills_enum = json.loads(open("enums/pills.json", "r").read())
pills_file = create_static_file("../static/pills.lua")
pills_file_comma = False
for item in items.getroot():
if item.tag == "passive" or item.tag == "active" or item.tag == "familiar":
append_file(collect_file, get_entry(item, collect_enum, "CollectibleType"), collect_file_comma)
collect_file_comma = True
add_unlocks(item, collect_enum)
add_unlocks(item, collect_enum, "CollectibleType", 1)
elif item.tag == "trinket":
append_file(trinket_file, get_entry(item, trinkets_enum, "TrinketType"), trinket_file_comma)
trinket_file_comma = True
add_unlocks(item, trinkets_enum, "TrinketType", 2)
for item in players.getroot():
append_file(players_file, get_entry(item, players_enum, "PlayerType"), players_file_comma)
players_file_comma = True
add_to_ignore(item)
for item in cards.getroot():
if item.tag == "card" or item.tag == "rune":
append_file(cards_file, get_entry(item, cards_enum, "Card"), cards_file_comma)
cards_file_comma = True
add_unlocks(item, cards_enum, "Card", 3)
elif item.tag == "pilleffect":
append_file(pills_file, get_entry(item, pills_enum, "PillEffect"), pills_file_comma)
pills_file_comma = True
collect_file.write("}")
trinket_file.write("}")
add_unlocks(item, pills_enum, "PillEffect", 4)
players_file.write("}")
cards_file.write("}")
pills_file.write("}")
collect_file.close()
trinket_file.close()
players_file.close()
cards_file.close()
pills_file.close()

genItems()
genPools()

def get_entry_info(entry, enum, enum_name):
item_id = int(entry.get("id"))
Expand All @@ -92,22 +70,11 @@ def append_file(file, entry, comma):
else:
file.write(entry)

def add_to_ignore(player):
items = player.get("items")
pocket = player.get("pocketActive")
if items != None:
items = map(int, items.split(','))
for item in items:
ignoreList.add(item)
if pocket != None:
pocket = int(pocket)
ignoreList.add(pocket)

def add_unlocks(item, enum):
def add_unlocks(entry, enum, enum_name, entry_type):
if use_vanilla_items:
item_id, achievement = get_entry_info(item, enum, "CollectibleType")
if achievement != 0 and not (int(item.get("id")) in ignoreList):
unlockList[achievement - 1] = item_id
item_id, achievement = get_entry_info(entry, enum, enum_name)
if achievement != 0: #and not (int(item.get("id")) in ignoreList):
unlockList[achievement - 1] = entry_type, item_id

def genItems():
modCollectibles_file = open("../content/items.xml", "w")
Expand All @@ -124,56 +91,21 @@ def genItems():
achievements_file = create_static_file("../static/achievements.lua")
achievements_file_comma = False
for achievement, entry in enumerate(unlockList):
unlock_item = entry
unlock_type = None
unlock_item = None
if entry == None:
unlock_type = 0
unlock_item = '"KZAchievementCheckerID' + str(modItemUnlockList[achievement]) + '"'
else:
unlock_type = entry[0]
unlock_item = entry[1]
prefix = '['
if achievements_file_comma:
prefix = ',['
achievements_file.write(prefix + str(unlock_item) + ']=' + str(achievement + 1))
achievements_file.write(prefix + str(achievement + 1) + ']={' + str(unlock_type) + ',' + str(unlock_item) + '}')
achievements_file_comma = True
achievements_file.write("}")
achievements_file.close()

def genPools():
total_length = 0
items_by_pool = {}
sorted_pools = sorted(itempools.getroot(), key=len, reverse=True)
for pool in sorted_pools:
total_length += len(pool)
for pool in sorted_pools:
items_by_pool[pool.get("Name")] = len(pool) / total_length * len(genItemList)
total_by_pool = 0
for pool in items_by_pool.items():
rounded = round(pool[1])
total_by_pool += rounded
#print(str(pool[1]) + " | " + str(rounded) + " | " + pool[0])
items_by_pool[pool[0]] = rounded
#print(str(total_by_pool) + " / " + str(len(genItemList)))
genLength = len(genItemList)
if total_by_pool > genLength:
i = 0
while total_by_pool != genLength:
items_by_pool[sorted_pools[i].get("Name")] -= 1
total_by_pool -= 1
i += 1
elif total_by_pool < genLength:
i = 0
while total_by_pool != genLength:
items_by_pool[sorted_pools[i].get("Name")] += 1
total_by_pool += 1
i += 1
mod_itempools = open("../content/itempools.xml", "w")
mod_itempools.write("<ItemPools>\n")
used_modItems = 0
for pool in itempools.getroot():
mod_itempools.write(" <" + pool.tag + ' Name="' + pool.get("Name") + '">\n')
amount = items_by_pool[pool.get("Name")]
for i in range(amount):
mod_itempools.write(' <Item Name="KZAchievementCheckerID' + str(genItemList[used_modItems + i]) + '" Weight="0.00001" DecreaseBy="0" RemoveOn="0"/>\n')
used_modItems = used_modItems + amount
mod_itempools.write(" </Pool>\n")
mod_itempools.write("</ItemPools>")


fill_tables()
2 changes: 1 addition & 1 deletion devScripts/launch_genLuaTables.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

python ./genStatic.py ~/Escritorio/ISAAC/
python ./genStatic.py ../../IsaacResources
Loading

0 comments on commit 1dddc21

Please sign in to comment.