Skip to content

Commit

Permalink
Some new changes to use the mounts and fix to detect better fight out…
Browse files Browse the repository at this point in the history
…comes
  • Loading branch information
Hexalgo committed Nov 15, 2024
1 parent ae7bc88 commit 8f41ac3
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 42 deletions.
4 changes: 4 additions & 0 deletions pydofus2/com/ankamagames/berilia/managers/KernelEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@


class KernelEvent(Enum):
PetsMounting = auto()
ObjectObtainedInFarm = auto()
ItemSold = auto()
KamasSpentOnSellTax = auto()
FarmPathStart = auto()
Paused = auto()
MarketOfflineSales = auto()
BankInventoryContent = auto()
FightOutcomeForPlayer = auto()
PlayerDied = auto()

# Market
MarketPriceChanged = auto()
Expand Down
4 changes: 4 additions & 0 deletions pydofus2/com/ankamagames/dofus/internalDatacenter/DataEnum.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,7 @@ class DataEnum:
LOCATION_CLUB_CUSTOM_EFFECT_ID: int = 14

ACHIEVEMENT_CAT_MODSTERS_HIDDEN: int = 149

RAPPEL_POTION_GUID = 548

CHEST_TYPE_ID = 172
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self):
self._market_mapId = None
self._market_gfx = None
self._search_item_listener = None
self._market_ie_id = None

@property
def priority(self) -> int:
Expand All @@ -99,6 +100,9 @@ def pushed(self) -> bool:
"""Called when frame is pushed to stack"""
self._bids_manager = MarketBidsManager()
self._market_type_open = None
self._market_gfx = None
self._market_ie_id = None
self._current_searched_item_gid = None
self._state = "INIT"
return True

Expand All @@ -108,6 +112,7 @@ def reset_state(self):
self._bids_manager.allowed_types = None
self._bids_manager.npc_id = None
self._market_gfx = None
self._market_ie_id = None
self._market_type_open = None
self._current_mode = None
self._current_searched_item_gid = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def __init__(self):
self._sourceInformations: GameRolePlayNamedActorInformations
self._targetInformations: GameRolePlayNamedActorInformations
self._success: bool
self._current_exchange_type = None

@property
def priority(self) -> int:
Expand All @@ -139,6 +140,7 @@ def pushed(self) -> bool:
return True

def pulled(self) -> bool:
self._current_exchange_type = None
if Kernel().commonExchangeManagementFrame:
Kernel().worker.removeFrameByName("CommonExchangeManagementFrame")
if self._success is not None:
Expand Down Expand Up @@ -300,6 +302,7 @@ def process(self, msg: Message) -> bool:
if commonExchangeFrame:
commonExchangeFrame.resetExchangeSequence()
pods = int(msg.storageMaxSlot)
self._current_exchange_type = msg.exchangeType
KernelEventsManager().send(KernelEvent.ExchangeBankStartedWithStorage, msg.exchangeType, pods)
return False

Expand Down Expand Up @@ -365,6 +368,8 @@ def process(self, msg: Message) -> bool:
InventoryManager().bankInventory.kamas = msg.kamas
InventoryManager().bankInventory.initializeFromObjectItems(msg.objects)
KernelEventsManager().send(KernelEvent.InventoryContent, msg.objects, msg.kamas)
if self._current_exchange_type == ExchangeTypeEnum.BANK:
KernelEventsManager().send(KernelEvent.BankInventoryContent, msg.objects, msg.kamas)
return True

elif isinstance(msg, StorageObjectUpdateMessage):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def process(self, msg: Message) -> bool:
PlayedCharacterManager().petsMount = equipmentView.content[
CharacterInventoryPositionEnum.ACCESSORY_POSITION_PETS
]
Logger().info(f"Player is pet mounting: {PlayedCharacterManager().petsMount.name}")
if equipmentView.content[CharacterInventoryPositionEnum.INVENTORY_POSITION_ENTITY]:
PlayedCharacterManager().hasCompanion = True
playerCharacterManager = PlayedCharacterManager()
Expand Down Expand Up @@ -230,12 +231,12 @@ def onAcceptDrop(self) -> None:
def onRefuseDrop(self) -> None:
self._dropPopup = None

def useItem(self, iw: ItemWrapper, quantity=0, useOnCell=False):
def useItem(self, iw: ItemWrapper, quantity=0, useOnCell=False, use_multiple=True):
if useOnCell and iw.targetable:
if Kernel().battleFrame:
return
else:
if quantity > 1:
if quantity > 1 and use_multiple:
oumsg = ObjectUseMultipleMessage()
oumsg.init(quantity, iw.objectUID)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ def process(self, msg: Message) -> bool:

if isinstance(msg, GameRolePlayPlayerLifeStatusMessage):
state = PlayerLifeStatusEnum(msg.state)
if state != PlayerLifeStatusEnum.STATUS_ALIVE:
if (
pcm.PlayedCharacterManager().player_life_status != state
and state == PlayerLifeStatusEnum.STATUS_TOMBSTONE
):
KernelEventsManager().send(KernelEvent.PlayerDied)
Logger().warning(f"Player died!")
else:
Logger().warning(f"Player is dead")
pcm.PlayedCharacterManager().player_life_status = state
self._phenixMapId = msg.phenixMapId
KernelEventsManager().send(KernelEvent.PlayerStateChanged, state, msg.phenixMapId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __init__(self):
self.player_life_status = PlayerLifeStatusEnum.STATUS_ALIVE
self.publicMode = False
self.isPetsMounting = False
self.petsMount = None
self.petsMount: "ItemWrapper" = None
self.hasCompanion = False
self.mount: MountData = None
self.teamId = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Tuple

import pydofus2.com.ankamagames.dofus.logic.game.common.managers.StorageOptionManager as storageoptmgr
from pydofus2.com.ankamagames.berilia.managers.KernelEventsManager import KernelEvent, KernelEventsManager
from pydofus2.com.ankamagames.dofus.internalDatacenter.DataEnum import DataEnum
from pydofus2.com.ankamagames.dofus.internalDatacenter.items.ItemWrapper import ItemWrapper
from pydofus2.com.ankamagames.dofus.logic.game.common.managers.PlayedCharacterManager import PlayedCharacterManager
Expand Down Expand Up @@ -138,6 +139,8 @@ def modifyItemPosition(self, itemUID: int, position: int) -> None:
if position == CharacterInventoryPositionEnum.ACCESSORY_POSITION_PETS:
PlayedCharacterManager().isPetsMounting = True
PlayedCharacterManager().petsMount = itemSet.item
KernelEventsManager().send(KernelEvent.PetsMounting, itemSet.item)
Logger().info(f"Player is pet mounting: {itemSet.item.name}")
else:
PlayedCharacterManager().isPetsMounting = False
PlayedCharacterManager().petsMount = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ def process(self, msg: Message) -> bool:
return True

elif isinstance(msg, GameFightEndMessage):
gfemsg = msg
maxEndRescue = 5
maxEndRescue -= 1
while self._currentSequenceFrame and maxEndRescue > 0:
Expand All @@ -293,9 +292,9 @@ def process(self, msg: Message) -> bool:
if self._executingSequence:
Logger().error("Delaying fight end because we're still in a sequence.")
self._endBattle = True
self._battleResults = gfemsg
self._battleResults = msg
else:
self.endBattle(gfemsg)
self.endBattle(msg)
FightersStateManager().endFight()
CurrentPlayedFighterManager().endFight()
return False
Expand Down Expand Up @@ -467,8 +466,7 @@ def endBattle(self, fightEnd: GameFightEndMessage) -> None:
self._holder.reset()
self._synchroniseFighters = None
Kernel().worker.removeFrame(self)
fightContextFrame = Kernel().fightContextFrame
fightContextFrame.process(fightEnd)
Kernel().fightContextFrame.process(fightEnd)

def onSkipTurnTimeOut(self, event) -> None:
self._skipTurnTimer.cancel()
Expand Down Expand Up @@ -509,8 +507,7 @@ def gameFightSynchronize(self, fighters: list[GameFightFighterInformations]) ->
self._neverSynchronizedBefore = False

def removeSavedPosition(self, pEntityId: float) -> None:
fightContextFrame = Kernel().fightContextFrame
savedPositions: list = fightContextFrame.fightersPositionsHistory.get(pEntityId)
savedPositions: list = Kernel().fightContextFrame.fightersPositionsHistory.get(pEntityId)
if savedPositions:
nbPos = len(savedPositions)
i = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,15 +760,15 @@ def getFighterInfos(self, fighterId: float) -> GameFightFighterInformations:
def stopReconnection(self, *args) -> None:
Kernel().beingInReconnection = False

def buildFighResul(self, gfemsg: GameFightEndMessage) -> None:
def buildFightResults(self, msg: GameFightEndMessage) -> None:
fightEnding = FightEndingMessage()
fightEnding.init()
Kernel().worker.process(fightEnding)
results = list[FightResultEntryWrapper](len(gfemsg.results) * [None])
results = list[FightResultEntryWrapper](len(msg.results) * [None])
resultIndex = 0
winners = list[FightResultEntryWrapper]()
temp = []
for resultEntry in gfemsg.results:
for resultEntry in msg.results:
temp.append(resultEntry)
isSpectator = True
for i in range(len(temp)):
Expand Down Expand Up @@ -804,10 +804,10 @@ def buildFighResul(self, gfemsg: GameFightEndMessage) -> None:
and temp[i + 1].wave != resultEntry.wave
):
frew.isLastOfHisWave = True
if resultEntry.outcome == FightOutcomeEnum.RESULT_DEFENDER_GROUP:
if resultEntry.outcome == FightOutcomeEnum.RESULT_DEFENDER_GROUP.value:
hardcoreLoots = frew
else:
if resultEntry.outcome == FightOutcomeEnum.RESULT_VICTORY:
if resultEntry.outcome == FightOutcomeEnum.RESULT_VICTORY.value:
winners.append(frew)
results[resultIndex] = frew
resultIndex += 1
Expand All @@ -832,24 +832,24 @@ def buildFighResul(self, gfemsg: GameFightEndMessage) -> None:
kamas -= winner.rewards.kamas
winnersName = ""
losersName = ""
for namedTeamWO in gfemsg.namedPartyTeamsOutcomes:
for namedTeamWO in msg.namedPartyTeamsOutcomes:
if namedTeamWO.team.partyName and namedTeamWO.team.partyName != "":
if namedTeamWO.outcome == FightOutcomeEnum.RESULT_VICTORY:
if namedTeamWO.outcome == FightOutcomeEnum.RESULT_VICTORY.value:
winnersName = namedTeamWO.team.partyName
elif namedTeamWO.outcome == FightOutcomeEnum.RESULT_LOST:
elif namedTeamWO.outcome == FightOutcomeEnum.RESULT_LOST.value:
losersName = namedTeamWO.team.partyName
resultsRecap = {
"results": results,
"rewardRate": gfemsg.rewardRate,
"sizeMalus": gfemsg.lootShareLimitMalus,
"duration": gfemsg.duration,
"rewardRate": msg.rewardRate,
"sizeMalus": msg.lootShareLimitMalus,
"duration": msg.duration,
"challenges": self.challengesList,
"turns": self._battleFrame.turnsCount,
"fightType": self._fightType,
"winnersName": winnersName,
"losersName": losersName,
"isSpectator": isSpectator,
}
if isinstance(gfemsg, BreachGameFightEndMessage):
resultsRecap["budget"] = gfemsg.budget
if isinstance(msg, BreachGameFightEndMessage):
resultsRecap["budget"] = msg.budget
return resultsRecap
15 changes: 9 additions & 6 deletions pydofus2/com/ankamagames/dofus/network/enums/FightOutcomeEnum.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
class FightOutcomeEnum:
from enum import Enum

RESULT_LOST: int = 0

RESULT_DRAW: int = 1
class FightOutcomeEnum(Enum):

RESULT_VICTORY: int = 2
RESULT_LOST = 0

RESULT_TAX: int = 5
RESULT_DRAW = 1

RESULT_DEFENDER_GROUP: int = 6
RESULT_VICTORY = 2

RESULT_TAX = 5

RESULT_DEFENDER_GROUP = 6
15 changes: 10 additions & 5 deletions pydofus2/com/ankamagames/jerakine/network/messages/Worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ def terminate(self) -> None:
self._terminating.set()
self._queue.put(TerminateWorkerMessage())

def _clear_queue(self, queue: queue.Queue):
while queue.qsize() != 0:
try:
queue.get_nowait()
except queue.Empty:
break

def reset(self) -> None:
for f in self._framesList:
f.pulled()
Expand All @@ -166,11 +173,9 @@ def reset(self) -> None:
self._framesToRemove.clear()
self._currentFrameTypesCache.clear()
self._processingMessage.clear()
while self._queue.qsize() != 0:
try:
self._queue.get_nowait()
except self._queue.Empty:
break
self._clear_queue(self._before_callbacks)
self._clear_queue(self._queue)
self._clear_queue(self._after_callbacks)

def pushFrame(self, frame: Frame) -> None:
if str(frame) in [str(f) for f in self._framesList]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MovementPath:

@property
def walkHorizontalDiagDuration(self):
if PlayedCharacterManager().isRiding:
if PlayedCharacterManager().isRiding or PlayedCharacterManager().isPetsMounting:
return random.gauss(
self.MOUNT_WALK_HORIZONTAL_DIAG_DURATION_MEAN, self.MOUNT_WALK_HORIZONTAL_DIAG_DURATION_VAR
)
Expand All @@ -58,7 +58,7 @@ def walkHorizontalDiagDuration(self):

@property
def walkVerticalDiagDuration(self):
if PlayedCharacterManager().isRiding:
if PlayedCharacterManager().isRiding or PlayedCharacterManager().isPetsMounting:
return random.gauss(
self.MOUNT_WALK_VERTICAL_DIAG_DURATION_MEAN, self.MOUNT_WALK_VERTICAL_DIAG_DURATION_VAR
)
Expand All @@ -67,14 +67,14 @@ def walkVerticalDiagDuration(self):

@property
def walkLinearDuration(self):
if PlayedCharacterManager().isRiding:
if PlayedCharacterManager().isRiding or PlayedCharacterManager().isPetsMounting:
return random.gauss(self.MOUNT_WALK_LINEAR_DURATION_MEAN, self.MOUNT_WALK_LINEAR_DURATION_VAR)
else:
return random.gauss(self.WALK_LINEAR_DURATION_MEAN, self.WALK_LINEAR_DURATION_VAR)

@property
def runHorizontalDiagDuration(self):
if PlayedCharacterManager().isRiding:
if PlayedCharacterManager().isRiding or PlayedCharacterManager().isPetsMounting:
return random.gauss(
self.MOUNT_RUN_HORIZONTAL_DIAG_DURATION_MEAN, self.MOUNT_RUN_HORIZONTAL_DIAG_DURATION_VAR
)
Expand All @@ -83,17 +83,17 @@ def runHorizontalDiagDuration(self):

@property
def runVerticalDiagDuration(self):
if PlayedCharacterManager().isRiding:
if PlayedCharacterManager().isRiding or PlayedCharacterManager().isPetsMounting:
return random.gauss(self.MOUNT_RUN_VERTICAL_DIAG_DURATION_MEAN, self.MOUNT_RUN_VERTICAL_DIAG_DURATION_VAR)
else:
return random.gauss(self.RUN_VERTICAL_DIAG_DURATION_MEAN, self.RUN_VERTICAL_DIAG_DURATION_VAR)

@property
def runLinearDuration(self):
if PlayedCharacterManager().isRiding:
return self.RUN_LINEAR_DURATION_MEAN + abs(random.gauss(0, self.RUN_LINEAR_DURATION_VAR))
if PlayedCharacterManager().isRiding or PlayedCharacterManager().isPetsMounting:
return random.gauss(self.MOUNT_RUN_LINEAR_DURATION_MEAN, self.MOUNT_RUN_LINEAR_DURATION_VAR)
else:
return self.MOUNT_RUN_LINEAR_DURATION_MEAN + abs(random.gauss(0, self.MOUNT_RUN_LINEAR_DURATION_VAR))
return random.gauss(self.RUN_LINEAR_DURATION_MEAN, self.RUN_LINEAR_DURATION_VAR)

def getStepDuration(self, orientation) -> float:
from pydofus2.com.ankamagames.dofus.logic.game.common.managers.PlayedCharacterManager import (
Expand Down

0 comments on commit 8f41ac3

Please sign in to comment.