init
This commit is contained in:
57
game_server/game/items/relic_manager.py
Normal file
57
game_server/game/items/relic_manager.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import random
|
||||
from pydantic import BaseModel
|
||||
from game_server.resource import ResourceManager
|
||||
from game_server.resource.configdb.relic_config import RelicConfigData
|
||||
from game_server.resource.configdb.relic_main_affix_config import RelicMainAffixConfigData
|
||||
from game_server.resource.configdb.relic_sub_affix_config import RelicSubAffixConfigData
|
||||
|
||||
|
||||
class SubAffix(BaseModel):
|
||||
id: int
|
||||
count: int
|
||||
step: int
|
||||
|
||||
class MainAffix(BaseModel):
|
||||
AffixID: int
|
||||
Property: str
|
||||
|
||||
class RelicManager(BaseModel):
|
||||
def GetRandomRelicMainAffix(self, itemid) -> MainAffix:
|
||||
config = ResourceManager.instance().find_by_index(RelicConfigData, itemid)
|
||||
if not config:
|
||||
return MainAffix(AffixID=0, Property=None)
|
||||
|
||||
affixes = [
|
||||
affix
|
||||
for affix in ResourceManager.instance().values(RelicMainAffixConfigData)
|
||||
if config.MainAffixGroup == affix.GroupID
|
||||
]
|
||||
|
||||
if not affixes:
|
||||
return MainAffix(AffixID=0, Property=None)
|
||||
|
||||
selected_affix = random.choice(affixes)
|
||||
return MainAffix(AffixID=selected_affix.AffixID, Property=selected_affix.Property)
|
||||
|
||||
def GetRandomRelicSubAffix(self, itemid: int, property: str, loop: int, affix_list: list[SubAffix] = []) -> list[SubAffix]:
|
||||
config = ResourceManager.instance().find_by_index(RelicConfigData, itemid)
|
||||
if not config:
|
||||
return []
|
||||
|
||||
affix_ids_in_list = {affix.id for affix in affix_list}
|
||||
affixes = [
|
||||
affix
|
||||
for affix in ResourceManager.instance().values(RelicSubAffixConfigData)
|
||||
if config.SubAffixGroup == affix.GroupID and affix.Property != property and affix.AffixID not in affix_ids_in_list
|
||||
]
|
||||
|
||||
selected_affixes = random.sample(affixes, 4 - len(affix_ids_in_list))
|
||||
|
||||
sub_affix_list = []
|
||||
for affix in selected_affixes:
|
||||
count = random.randint(1, loop)
|
||||
step = count * 2
|
||||
sub_affix_list.append(SubAffix(id=affix.AffixID, count=count, step=step))
|
||||
|
||||
return sub_affix_list
|
||||
|
||||
Reference in New Issue
Block a user