It focuses on , modularity , and extensibility , allowing you to work with game data in Python objects instead of raw text files. 📦 metin2lib – Python Library for Metin 2 """ metin2lib - A Python library for working with Metin 2 game data files. Supports proto files (item, mob, skill, etc.), quest scripts, and more. """ import re from pathlib import Path from typing import List, Dict, Any, Optional, Union
def get_block(self, state: str) -> Optional[str]: """Get a specific state block.""" return self.blocks.get(f"state state") python library for metin 2
def add(self, entry: ProtoEntry) -> None: """Add or replace an entry.""" self.entries[entry.vnum] = entry It focuses on , modularity , and extensibility
def get(self, vnum: int) -> Optional[ProtoEntry]: """Get entry by vnum.""" return self.entries.get(vnum) """ import re from pathlib import Path from
def _extract_blocks(self) -> Dict[str, str]: """Extract state/block sections.""" blocks = {} pattern = re.compile(r'(state\s+\w+)(.*?)(?=state\s+\w+|$)', re.DOTALL) for match in pattern.finditer(self.content): block_name = match.group(1).strip() block_content = match.group(2).strip() blocks[block_name] = block_content return blocks
def is_usable(self, vnum: int) -> bool: """Check if item is usable (type=USE).""" entry = self.proto.get(vnum) if not entry: return False return entry.get("type") == "USE"