Files
cultivation-world-simulator/src/classes/magic_stone.py
2025-10-31 00:35:05 +08:00

43 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from typing import Union
class MagicStone(int):
"""
灵石实际上是一个int类代表持有的灵石的数量。
"""
def __init__(self, value: int):
self.value = value
def __str__(self) -> str:
return f"{self.value}灵石"
def get_info(self) -> str:
return str(self)
def get_detailed_info(self) -> str:
return str(self)
def __add__(self, other: Union['MagicStone', int]) -> 'MagicStone':
if isinstance(other, int):
return MagicStone(self.value + other)
return MagicStone(self.value + other.value)
def __iadd__(self, other: Union['MagicStone', int]) -> 'MagicStone':
if isinstance(other, int):
self.value += other
else:
self.value += other.value
return self
def __sub__(self, other: Union['MagicStone', int]) -> 'MagicStone':
if isinstance(other, int):
return MagicStone(self.value - other)
return MagicStone(self.value - other.value)
def __isub__(self, other: Union['MagicStone', int]) -> 'MagicStone':
if isinstance(other, int):
self.value -= other
else:
self.value -= other.value
return self