Add mobreport.py
This commit is contained in:
@@ -5,7 +5,7 @@ class Group:
|
||||
How many individuals are commonly present when encountering a creature.
|
||||
"""
|
||||
|
||||
def __init__(self, name, smallest, largest):
|
||||
def __init__(self, name:str, smallest:int, largest:int):
|
||||
self.name = name
|
||||
self.smallest = smallest
|
||||
self.largest = largest
|
||||
@@ -42,9 +42,19 @@ ALL = [SOLO, PAIR, FAMILY, TROUP, HERD]
|
||||
def merge(*groups):
|
||||
if not groups: return SOLO
|
||||
|
||||
result = Group(f"", HERD.largest, SOLO.smallest)
|
||||
for group in groups:
|
||||
result.smallest = min(result.smallest, group.smallest)
|
||||
result.largest = max(result.largest, group.largest)
|
||||
smallest = ALL[-1].largest
|
||||
smallestGroup = None
|
||||
|
||||
return result
|
||||
largest = ALL[0].smallest
|
||||
largestGroup = None
|
||||
|
||||
for group in groups:
|
||||
if group.smallest < smallest:
|
||||
smallest = group.smallest
|
||||
smallestGroup = group
|
||||
|
||||
if group.largest > largest:
|
||||
largest = group.largest
|
||||
largestGroup = group
|
||||
|
||||
return Group(f"{smallestGroup.name}-{largestGroup.name}", smallest, largest)
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
from tungston.core.fauna.mob import Mob
|
||||
from collections.abc import Iterator
|
||||
from tungston.core.fauna.mobplacement import MobPlacement
|
||||
|
||||
|
||||
# Class ############################################################################################
|
||||
|
||||
class MobCatalog:
|
||||
|
||||
def __init__(self, mobs):
|
||||
self.mobs = mobs
|
||||
def __init__(self, mobs:tuple[MobPlacement]):
|
||||
self._mobs = {}
|
||||
|
||||
def findByName(self, name):
|
||||
for mob in self.mobs:
|
||||
if mob.name == name:
|
||||
return mob
|
||||
for mob in mobs:
|
||||
self.add(mob)
|
||||
|
||||
return None
|
||||
def add(self, placement:MobPlacement) -> "MobCatalog":
|
||||
if placement.mob.name in self._mobs:
|
||||
raise Exception("Catalog already has an entry for {mob.name}")
|
||||
|
||||
self._mobs[placement.mob.name] = placement
|
||||
|
||||
def all(self) -> Iterator[MobPlacement]:
|
||||
for placement in self._mobs.values():
|
||||
yield placement
|
||||
|
||||
def get(self, name:str) -> MobPlacement:
|
||||
return self._mobs.get(name, None)
|
||||
|
||||
@@ -30,7 +30,7 @@ def test_cowsInFields(placement):
|
||||
"Placement{" +
|
||||
"habitats: [" +
|
||||
"Habitat{" +
|
||||
"altitude: [anywhere <-64 to 320>], " +
|
||||
"altitude: anywhere <-64 to 320>, " +
|
||||
"biomeFilter: BiomeFilter([[Flora<field>, Heat<temperate>]], [[]]), " +
|
||||
"seasons: [Season<spring>, Season<summer>, Season<autumn>, Season<winter>], " +
|
||||
"group: solo<1 to 1>, " +
|
||||
|
||||
Reference in New Issue
Block a user