mirror of
https://github.com/Steffo99/lihzahrd.git
synced 2024-11-25 01:24:21 +00:00
...I kinda forgot to do separate commits...
This commit is contained in:
parent
82ae0089ca
commit
d115938a11
28 changed files with 87 additions and 67 deletions
|
@ -1,5 +1,5 @@
|
||||||
from .world import World
|
from .world import World
|
||||||
from . import bestiary, chests, fileutils, header, journeypowers, npcs, pressureplates, signs, tileentities, tiles, townmanager
|
|
||||||
|
|
||||||
__all__ = ["World", "bestiary", "chests", "fileutils", "header", "journeypowers", "npcs", "pressureplates", "signs", "tileentities", "tiles",
|
__all__ = [
|
||||||
"townmanager"]
|
"World",
|
||||||
|
]
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
class Bestiary:
|
class Bestiary:
|
||||||
"""A bestiary entry."""
|
"""A bestiary entry."""
|
||||||
|
|
||||||
__slots__ = "npc_chats_count", "npc_chats_data", "npc_kill_count","npc_kill_data", "npc_sighting_count", "npc_sighting_data"
|
__slots__ = "npc_chats_count", "npc_chats_data", "npc_kill_count", "npc_kill_data", "npc_sighting_count", "npc_sighting_data"
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
npc_chats_count: int,
|
npc_chats_count: int,
|
||||||
|
@ -11,7 +12,7 @@ class Bestiary:
|
||||||
npc_kill_count: int,
|
npc_kill_count: int,
|
||||||
npc_kill_data: typing.List[str],
|
npc_kill_data: typing.List[str],
|
||||||
npc_sighting_count: int,
|
npc_sighting_count: int,
|
||||||
npc_sighting_data: typing.List[str],):
|
npc_sighting_data: typing.List[str], ):
|
||||||
self.npc_chats_count: int = npc_chats_count
|
self.npc_chats_count: int = npc_chats_count
|
||||||
self.npc_chats_data: typing.Dict[str, int] = npc_chats_data
|
self.npc_chats_data: typing.Dict[str, int] = npc_chats_data
|
||||||
self.npc_kill_count: int = npc_kill_count
|
self.npc_kill_count: int = npc_kill_count
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
import typing
|
import typing
|
||||||
from ..items.itemstack import ItemStack
|
from ..items import ItemStack
|
||||||
from ..fileutils import Coordinates
|
from ..fileutils import Coordinates
|
||||||
|
|
||||||
|
|
||||||
class Chest:
|
class Chest:
|
||||||
"""A chest with its contents."""
|
"""A chest with its contents."""
|
||||||
|
|
||||||
def __init__(self, position: Coordinates, name: str, contents: typing.List[ItemStack]):
|
def __init__(self, position: Coordinates, name: str, contents: typing.List[ItemStack]):
|
||||||
self.position: Coordinates = position
|
self.position: Coordinates = position
|
||||||
self.name: str = name
|
self.name: str = name
|
||||||
self.contents: typing.List[ItemStack] = contents
|
self.contents: typing.List[ItemStack] = contents
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Chest '{self.name}' at {self.position}>"
|
if self.name:
|
||||||
|
return f'<Chest "{self.name}" at {self.position} with {len(self.contents)} items>'
|
||||||
|
return f"<Chest at {self.position} with {len(self.contents)} items>"
|
||||||
|
|
13
lihzahrd/enums/__init__.py
Normal file
13
lihzahrd/enums/__init__.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
from .blocktype import BlockType
|
||||||
|
from .entitytype import EntityType
|
||||||
|
from .itemtype import ItemType
|
||||||
|
from .liquidtype import LiquidType
|
||||||
|
from .walltype import WallType
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"BlockType",
|
||||||
|
"EntityType",
|
||||||
|
"ItemType",
|
||||||
|
"LiquidType",
|
||||||
|
"WallType",
|
||||||
|
]
|
|
@ -2,12 +2,13 @@ import typing
|
||||||
import struct
|
import struct
|
||||||
import uuid
|
import uuid
|
||||||
import datetime
|
import datetime
|
||||||
|
import functools
|
||||||
from .rect import Rect
|
from .rect import Rect
|
||||||
|
|
||||||
|
|
||||||
class FileReader:
|
class FileReader:
|
||||||
def __init__(self, file):
|
def __init__(self, file: typing.IO):
|
||||||
self.file = file
|
self.file: typing.IO = file
|
||||||
|
|
||||||
def bool(self) -> bool:
|
def bool(self) -> bool:
|
||||||
return struct.unpack("?", self.file.read(1))[0]
|
return struct.unpack("?", self.file.read(1))[0]
|
||||||
|
@ -42,8 +43,9 @@ class FileReader:
|
||||||
def double(self) -> float:
|
def double(self) -> float:
|
||||||
return struct.unpack("d", self.file.read(8))[0]
|
return struct.unpack("d", self.file.read(8))[0]
|
||||||
|
|
||||||
def bits(self) -> typing.Tuple[bool, bool, bool, bool, bool, bool, bool, bool]:
|
@staticmethod
|
||||||
data = struct.unpack("B", self.file.read(1))[0]
|
@functools.lru_cache(256)
|
||||||
|
def _bitify(data) -> typing.Tuple[bool, bool, bool, bool, bool, bool, bool, bool]:
|
||||||
return (bool(data & 0b0000_0001),
|
return (bool(data & 0b0000_0001),
|
||||||
bool(data & 0b0000_0010),
|
bool(data & 0b0000_0010),
|
||||||
bool(data & 0b0000_0100),
|
bool(data & 0b0000_0100),
|
||||||
|
@ -53,6 +55,10 @@ class FileReader:
|
||||||
bool(data & 0b0100_0000),
|
bool(data & 0b0100_0000),
|
||||||
bool(data & 0b1000_0000))
|
bool(data & 0b1000_0000))
|
||||||
|
|
||||||
|
def bits(self) -> typing.Tuple[bool, bool, bool, bool, bool, bool, bool, bool]:
|
||||||
|
data = struct.unpack("B", self.file.read(1))[0]
|
||||||
|
return self._bitify(data)
|
||||||
|
|
||||||
def rect(self) -> Rect:
|
def rect(self) -> Rect:
|
||||||
left, right, top, bottom = struct.unpack("iiii", self.file.read(16))
|
left, right, top, bottom = struct.unpack("iiii", self.file.read(16))
|
||||||
return Rect(left, right, top, bottom)
|
return Rect(left, right, top, bottom)
|
||||||
|
|
|
@ -9,7 +9,7 @@ from .fourpartsplit import FourPartSplit
|
||||||
from .generatorinfo import GeneratorInfo
|
from .generatorinfo import GeneratorInfo
|
||||||
from .invasion import Invasion
|
from .invasion import Invasion
|
||||||
from .invasiontype import InvasionType
|
from .invasiontype import InvasionType
|
||||||
from .lanternevent import LanternEvent
|
from .lanternnight import LanternNight
|
||||||
from .lunarevents import LunarEvents
|
from .lunarevents import LunarEvents
|
||||||
from .moonphase import MoonPhase
|
from .moonphase import MoonPhase
|
||||||
from .moonstyle import MoonStyle
|
from .moonstyle import MoonStyle
|
||||||
|
@ -40,7 +40,7 @@ __all__ = [
|
||||||
"GeneratorInfo",
|
"GeneratorInfo",
|
||||||
"Invasion",
|
"Invasion",
|
||||||
"InvasionType",
|
"InvasionType",
|
||||||
"LanternEvent",
|
"LanternNight",
|
||||||
"LunarEvents",
|
"LunarEvents",
|
||||||
"MoonPhase",
|
"MoonPhase",
|
||||||
"MoonStyle",
|
"MoonStyle",
|
||||||
|
|
|
@ -3,7 +3,7 @@ from .rain import Rain
|
||||||
from .party import Party
|
from .party import Party
|
||||||
from .sandstorm import Sandstorm
|
from .sandstorm import Sandstorm
|
||||||
from .lunarevents import LunarEvents
|
from .lunarevents import LunarEvents
|
||||||
from .lanternevent import LanternEvent
|
from .lanternnight import LanternNight
|
||||||
|
|
||||||
class Events:
|
class Events:
|
||||||
"""Information about the ongoing world events."""
|
"""Information about the ongoing world events."""
|
||||||
|
@ -16,7 +16,7 @@ class Events:
|
||||||
party: Party,
|
party: Party,
|
||||||
sandstorm: Sandstorm,
|
sandstorm: Sandstorm,
|
||||||
lunar_events: LunarEvents,
|
lunar_events: LunarEvents,
|
||||||
lantern_night: LanternEvent):
|
lantern_night: LanternNight):
|
||||||
self.blood_moon: bool = blood_moon
|
self.blood_moon: bool = blood_moon
|
||||||
"""If the current moon is a Blood Moon."""
|
"""If the current moon is a Blood Moon."""
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class Events:
|
||||||
self.lunar_events: LunarEvents = lunar_events
|
self.lunar_events: LunarEvents = lunar_events
|
||||||
"""Information about the currently ongoing Lunar Events."""
|
"""Information about the currently ongoing Lunar Events."""
|
||||||
|
|
||||||
self.lantern_night: LanternEvent = lantern_night
|
self.lantern_night: LanternNight = lantern_night
|
||||||
"""Information about the currently ongoing lantern night."""
|
"""Information about the currently ongoing lantern night."""
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
6
lihzahrd/header/lanternevent.py → lihzahrd/header/lanternnight.py
Executable file → Normal file
6
lihzahrd/header/lanternevent.py → lihzahrd/header/lanternnight.py
Executable file → Normal file
|
@ -1,7 +1,7 @@
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
class LanternEvent:
|
class LanternNight:
|
||||||
"""Lantern Night event related information."""
|
"""Lantern Night event related information."""
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
nights_on_cooldown: int,
|
nights_on_cooldown: int,
|
||||||
|
@ -17,8 +17,8 @@ class LanternEvent:
|
||||||
self.manual: bool = manual
|
self.manual: bool = manual
|
||||||
"""Was this night started by the player?"""
|
"""Was this night started by the player?"""
|
||||||
|
|
||||||
self.next_night_is_lantern_night:bool = next_night_is_lantern_night
|
self.next_night_is_lantern_night: bool = next_night_is_lantern_night
|
||||||
"""Is the next night a lantern night?"""
|
"""Was a boss just defeated, making the next night a Lantern Night?"""
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"WorldLanternNight(nights_on_cooldown={self.nights_on_cooldown}," \
|
return f"WorldLanternNight(nights_on_cooldown={self.nights_on_cooldown}," \
|
|
@ -1,19 +1,21 @@
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
class Pets:
|
class Pets:
|
||||||
"""Pet related information"""
|
"""Pet related information"""
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
cat: bool,
|
cat: bool,
|
||||||
dog: bool,
|
dog: bool,
|
||||||
bunny: bool):
|
bunny: bool):
|
||||||
|
|
||||||
self.cat: bool = cat
|
self.cat: bool = cat
|
||||||
"""Has the cat been bought."""
|
"""Was the `Cat License <https://terraria.gamepedia.com/Cat_License>`_ ever activated?"""
|
||||||
|
|
||||||
self.dog: int = dog
|
self.dog: int = dog
|
||||||
"""Has the cat been bought."""
|
"""Was the `Dog License <https://terraria.gamepedia.com/Dog_License>`_ ever activated?"""
|
||||||
|
|
||||||
self.bunny: float = bunny
|
self.bunny: float = bunny
|
||||||
"""Has the bunny been bought."""
|
"""Was the `Bunny License <https://terraria.gamepedia.com/Bunny_License>`_ ever activated?"""
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"WorldPets(cat={self.cat}, dog={self.dog}, bunny={self.bunny})"
|
return f"{self.__class__.__qualname__}(cat={self.cat}, dog={self.dog}, bunny={self.bunny})"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from typing import *
|
from typing import *
|
||||||
from ..tiles import BlockType
|
from ..enums import BlockType
|
||||||
|
|
||||||
|
|
||||||
class SavedOreTiers:
|
class SavedOreTiers:
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from .itemstack import ItemStack
|
from .itemstack import ItemStack
|
||||||
from .itemtype import ItemType
|
|
||||||
|
|
||||||
__all__ = ["ItemStack", "ItemType"]
|
__all__ = ["ItemStack"]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from .itemtype import ItemType
|
from ..enums import ItemType
|
||||||
|
|
||||||
|
|
||||||
class ItemStack:
|
class ItemStack:
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from .npc import NPC
|
from .npc import NPC
|
||||||
from .mob import Mob
|
from .mob import Mob
|
||||||
from .npctype import EntityType
|
|
||||||
|
|
||||||
__all__ = ["NPC", "Mob", "EntityType"]
|
__all__ = ["NPC", "Mob"]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import typing
|
import typing
|
||||||
from .npctype import EntityType
|
from ..enums import EntityType
|
||||||
from ..fileutils import Coordinates
|
from ..fileutils import Coordinates
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@ class Mob:
|
||||||
__slots__ = "type", "position"
|
__slots__ = "type", "position"
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
type_: int,
|
type_: EntityType,
|
||||||
position: Coordinates, ):
|
position: Coordinates, ):
|
||||||
self.type: int = type_
|
self.type: EntityType = type_
|
||||||
"""The type of mob this object represents."""
|
"""The type of entity this object represents."""
|
||||||
|
|
||||||
self.position: Coordinates = position
|
self.position: Coordinates = position
|
||||||
"""The position of the mob in the game world."""
|
"""The position of the mob in the game world."""
|
||||||
|
|
|
@ -1,33 +1,31 @@
|
||||||
import typing
|
from typing import Optional
|
||||||
from .npctype import EntityType
|
from ..enums import EntityType
|
||||||
from ..fileutils import Coordinates
|
from ..fileutils import Coordinates
|
||||||
|
from .mob import Mob
|
||||||
|
|
||||||
|
|
||||||
class NPC:
|
class NPC(Mob):
|
||||||
"""A NPC somewhere in the world."""
|
"""A NPC somewhere in the world."""
|
||||||
|
|
||||||
__slots__ = "type", "name", "position", "home", "variation_index"
|
__slots__ = "type", "name", "position", "home", "variation_index"
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
type_: EntityType,
|
type_: EntityType,
|
||||||
name: str,
|
|
||||||
position: Coordinates,
|
position: Coordinates,
|
||||||
|
name: str,
|
||||||
variation_index: int,
|
variation_index: int,
|
||||||
home: typing.Optional[Coordinates] = None,):
|
home: Optional[Coordinates] = None):
|
||||||
self.type: EntityType = type_
|
|
||||||
"""The NPC this object represents."""
|
super().__init__(type_, position)
|
||||||
|
|
||||||
self.name: str = name
|
self.name: str = name
|
||||||
"""The name of this NPC."""
|
"""The name of this NPC."""
|
||||||
|
|
||||||
self.position: Coordinates = position
|
self.home: Optional[Coordinates] = home
|
||||||
"""The position of the mob in the game world."""
|
"""The coordinates of the home of this NPC, or ``None`` if the NPC is homeless."""
|
||||||
|
|
||||||
self.home: typing.Optional[Coordinates] = home
|
|
||||||
"""The coordinates of the home of this NPC, or None if the NPC is homeless."""
|
|
||||||
|
|
||||||
self.variation_index: int = variation_index
|
self.variation_index: int = variation_index
|
||||||
"""Unsure, but seems to be an index to different possible NPC variations."""
|
"""(Unknown) Possibly the current `Zoologist <https://terraria.gamepedia.com/Zoologist>`_ form?"""
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<NPC {repr(self.type)} at {self.position}>"
|
return f"<NPC {repr(self.type)} at {self.position}>"
|
||||||
|
|
|
@ -2,6 +2,7 @@ class TargetDummy:
|
||||||
"""Data pertaining to a Target Dummy (https://terraria.gamepedia.com/Target_Dummy)"""
|
"""Data pertaining to a Target Dummy (https://terraria.gamepedia.com/Target_Dummy)"""
|
||||||
|
|
||||||
def __init__(self, npc: int):
|
def __init__(self, npc: int):
|
||||||
|
# TODO: what's this?
|
||||||
self.npc: int = npc
|
self.npc: int = npc
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
from .liquidtype import LiquidType
|
|
||||||
from .rleencoding import RLEEncoding
|
from .rleencoding import RLEEncoding
|
||||||
from .shape import Shape
|
from .shape import Shape
|
||||||
from .wiring import Wiring
|
from .wiring import Wiring
|
||||||
from .blocktype import BlockType
|
|
||||||
from .frameimportantdata import FrameImportantData
|
from .frameimportantdata import FrameImportantData
|
||||||
from .walltype import WallType
|
|
||||||
from .block import Block
|
from .block import Block
|
||||||
from .wall import Wall
|
from .wall import Wall
|
||||||
from .liquid import Liquid
|
from .liquid import Liquid
|
||||||
from .tile import Tile
|
from .tile import Tile
|
||||||
from .tilematrix import TileMatrix
|
from .tilematrix import TileMatrix
|
||||||
|
|
||||||
__all__ = ["LiquidType", "RLEEncoding", "Shape", "Wiring", "BlockType", "FrameImportantData", "WallType", "Block",
|
__all__ = ["RLEEncoding", "Shape", "Wiring", "FrameImportantData", "Block",
|
||||||
"Wall", "Liquid", "Tile", "TileMatrix"]
|
"Wall", "Liquid", "Tile", "TileMatrix"]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import typing
|
import typing
|
||||||
from .blocktype import BlockType
|
from ..enums import BlockType
|
||||||
from .frameimportantdata import FrameImportantData
|
from .frameimportantdata import FrameImportantData
|
||||||
from .shape import Shape
|
from .shape import Shape
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from .liquidtype import LiquidType
|
from ..enums import LiquidType
|
||||||
|
|
||||||
|
|
||||||
class Liquid:
|
class Liquid:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import typing
|
import typing
|
||||||
from .tile import Tile
|
from .tile import Tile
|
||||||
from ..fileutils import FileReader, Coordinates
|
from ..fileutils import Coordinates
|
||||||
|
|
||||||
|
|
||||||
class TileMatrix:
|
class TileMatrix:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import typing
|
import typing
|
||||||
from .walltype import WallType
|
from ..enums import WallType
|
||||||
|
|
||||||
|
|
||||||
class Wall:
|
class Wall:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from ..fileutils import Coordinates
|
from ..fileutils import Coordinates
|
||||||
from ..npcs import EntityType
|
from ..enums import EntityType
|
||||||
|
|
||||||
|
|
||||||
class Room:
|
class Room:
|
||||||
|
|
|
@ -2,6 +2,7 @@ import uuid
|
||||||
import math
|
import math
|
||||||
from typing import *
|
from typing import *
|
||||||
from .fileutils import *
|
from .fileutils import *
|
||||||
|
from .enums import *
|
||||||
from .items import *
|
from .items import *
|
||||||
from .header import *
|
from .header import *
|
||||||
from .tiles import *
|
from .tiles import *
|
||||||
|
@ -610,7 +611,7 @@ class World:
|
||||||
advanced_combat=combat_book_used
|
advanced_combat=combat_book_used
|
||||||
)
|
)
|
||||||
|
|
||||||
lantern_night = LanternEvent(f.int4(), f.bool(), f.bool(), f.bool())
|
lantern_night = LanternNight(f.int4(), f.bool(), f.bool(), f.bool())
|
||||||
|
|
||||||
events = Events(blood_moon=blood_moon,
|
events = Events(blood_moon=blood_moon,
|
||||||
solar_eclipse=eclipse,
|
solar_eclipse=eclipse,
|
||||||
|
|
Loading…
Reference in a new issue