Skip to content

Commit

Permalink
Added an option in Event Generation that will make it so that after g…
Browse files Browse the repository at this point in the history
…etting the Progressive Tech, you'll still have to research its relevant technologies. Will later add a prerequisite to all vanilla techs.
  • Loading branch information
DestinyPlayer committed Oct 7, 2024
1 parent 6d60fff commit 6e454a5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 35 deletions.
44 changes: 30 additions & 14 deletions worlds/stellaris/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from pymem import Pymem, pattern, process
import sys

from worlds.dlcquest.test.TestItemShuffle import items
from NetUtils import add_json_item, add_json_text, add_json_location, JSONTypes
from .Generate import generateMod
from . import DataTest

logger = logging.getLogger("Client")
Expand Down Expand Up @@ -54,14 +55,14 @@ def findBaseRes(patternMatch):
try:
logger.info("Reference resource "+str(patternMatch)+" found at address "+str(hex(referenceResourceAddress)))
except:
logger.error("ERROR: Reference Resource could not be found. Aborting.")
logger.error("ERROR: Reference Resource could not be found.")
return referenceResourceAddress

def checkBaseRes(res):
try:
logger.info("Reference resource value is: "+str(pm.read_longlong(res)))
except:
logger.error("ERROR: Reference Resource cannot be read. Aborting.")
logger.error("ERROR: Reference Resource cannot be read.")

async def connectToStellaris():
logger.info("Trying to connect to Stellaris")
Expand All @@ -88,7 +89,7 @@ async def connectToStellaris():
checkBaseRes(emerRes)
if pm.read_longlong(baseRes + 0x8) != referenceNumber2 or pm.read_longlong(
emerRes - 0x8) != referenceNumber1:
logger.error("ERROR: Wrong reference addresses found. Aborting.")
logger.error("ERROR: Wrong reference addresses found.")
commResIn = [baseRes - 0x10, 0] # Items going into Stellaris
commResOut = [baseRes - 0x8, 0] # Items going out of Stellaris
grabResources()
Expand Down Expand Up @@ -118,14 +119,25 @@ def _cmd_reconnect_stellaris(self):
"""Try to reconnect to Stellaris if the connection failed"""
stellaris_game_task = asyncio.create_task(connectToStellaris(), name="StellarisConnection")

def _cmd_generate_test_mod(self):
"""Generates a test mod in the world's folder"""
logger.info("Generating a test mod")
generateMod()

class StellarisContext(CommonContext):
command_processor = StellarisCommandProcessor
# Text Mode to use !hint and such with games that have no text entry
tags = CommonContext.tags | {"TextOnly"}
game = "Stellaris" # empty matches any game since 0.3.2
game = "Risk of Rain 2" # empty matches any game since 0.3.2
items_handling = 0b111 # receive all items for /received
want_slot_data = False # Can't use game specific slot_data

async def get_username(self):
if not self.auth:
self.auth = self.username
if not self.auth:
logger.info('Picked default player name - DestinyPlayer_1')
self.auth = "DestinyPlayer_1"

async def server_auth(self, password_requested: bool = False):
if password_requested and not self.password:
await super(StellarisContext, self).server_auth(password_requested)
Expand All @@ -135,10 +147,21 @@ async def server_auth(self, password_requested: bool = False):
def on_package(self, cmd: str, args: dict):
if cmd == "Connected":
self.game = self.slot_info[self.slot].game
elif cmd == 'ReceivedItems':
start_index = args["index"]
logger.info("Listing previously received items:")
for index, item in enumerate(self.items_received, 1):
parts = []
add_json_text(parts, " ")
add_json_item(parts, item.item, self.slot, item.flags)
add_json_text(parts, " from ")
add_json_location(parts, item.location, item.player)
add_json_text(parts, " by ")
add_json_text(parts, item.player, type=JSONTypes.player_id)
self.on_print_json({"data": parts, "cmd": "PrintJSON"})


async def disconnect(self, allow_autoreconnect: bool = False):
self.game = ""
await super().disconnect(allow_autoreconnect)

async def main(args):
Expand Down Expand Up @@ -187,17 +210,10 @@ async def main(args):

colorama.deinit()

#INTERRUPT FOR TESTING
if __name__ == '__main__':
logging.getLogger().setLevel(logging.INFO) # force log-level to work around log level resetting to WARNING
runStellarisClient(*sys.argv[1:]) # default value for parse_args

#[VARIABLES]############################################################################

connectionAddress = "localhost"
connectionPort = "38281"

connectionFullAddress = "ws://"+connectionAddress+":"+connectionPort
'''
#[GAME FUNCTIONS]########################################################################
#This function finds an address in Process memory based on the provided pattern
Expand Down
9 changes: 6 additions & 3 deletions worlds/stellaris/CreateEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from .templates.TemplateLocalisation import localisationStart, localisationEventTemplate
from .Utility import writeToFile, languages

test = True

#This function looks through the tech dictionary for technology with the specified name
def findTech(search):
for tech in DataTech.techs:
Expand All @@ -21,9 +23,10 @@ def constructTechAction(tech):
conditions = conditions + eventIfTech.format(has = name + str(i))
else:
elseif = "if"
vanilla = DataTechVanilla.vanillaTechs[tech["name"]]
for split in vanilla[i].split(" "):
result = result + eventGiveTech.format(name = split)
if test is True:
vanilla = DataTechVanilla.vanillaTechs[tech["name"]]
for split in vanilla[i].split(" "):
result = result + eventGiveTech.format(name = split)
conditions = conditions + eventNotIfTech.format(hasnot = name + str(i+1))
action = action + eventAction.format(elseif = elseif, conditions = conditions, result = result)
return action
Expand Down
2 changes: 1 addition & 1 deletion worlds/stellaris/CreateTechs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def createTechLocalisations():

#This function assigns the default icon to every added Technology
def createTechIcons():
path = "mod/archipelago-stellaris-mod/gfx/interface/icons/technologies/"
path = "worlds/stellaris/mod/archipelago-stellaris-mod/gfx/interface/icons/technologies/"
iconTempName = "tech_progressive"
iconFinName = iconTempName+"_{type}_{num}"
format = ".dds"
Expand Down
13 changes: 7 additions & 6 deletions worlds/stellaris/Generate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from . import CreateEvents, CreateTechs, Utility

CreateTechs.createTech()
CreateTechs.createTechLocalisations()
CreateTechs.createTechIcons()
def generateMod():
CreateTechs.createTech()
CreateTechs.createTechLocalisations()
CreateTechs.createTechIcons()

CreateEvents.createEvents()
CreateEvents.createEventLocalisations()
CreateEvents.createEvents()
CreateEvents.createEventLocalisations()

Utility.copyOtherLocalisationFiles("archipelago_events_l_english.yml")
Utility.copyOtherLocalisationFiles("archipelago_events_l_english.yml")
4 changes: 2 additions & 2 deletions worlds/stellaris/Utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#This function writes files to the mod folder
def writeToFile(path,text,encoding=None):
path = "mod/archipelago-stellaris-mod/"+path
path = "worlds/stellaris/mod/archipelago-stellaris-mod/"+path
if encoding is not None:
f = open(path, "w", encoding=encoding)
else:
Expand All @@ -19,5 +19,5 @@ def copyOtherLocalisationFiles(file):
for lang in languages:
if lang == "english":
continue
path = "mod/archipelago-stellaris-mod/localisation/"
path = "worlds/stellaris/mod/archipelago-stellaris-mod/localisation/"
shutil.copyfile(path + "english/"+file, path + lang + "/" + file)
8 changes: 4 additions & 4 deletions worlds/stellaris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class StellarisWorld(World):
"Nowhere": 76000
}

def create_item(self, name: str) -> Item:
if name == "Test":
return Item(name, ItemClassification.filler, -1, self.player)
raise KeyError(name)
def create_items(self) -> None:
# shortcut for starting_inventory... The start_with_revive option lets you start with a Dio's Best Friend
if self.options.testing:
self.multiworld.push_precollected(self.multiworld.create_item("Dio's Best Friend", self.player))
6 changes: 1 addition & 5 deletions worlds/stellaris/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
requests~=2.32.3
Pymem~=1.13.1
pip~=23.2.1
MarkupSafe~=2.1.5
docutils~=0.21.2
Pymem>=1.13.1

0 comments on commit 6e454a5

Please sign in to comment.