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