push better version of prototype that actually runs

This commit is contained in:
RabbyDevs 2025-05-17 20:46:07 +03:00
parent ce265b89ca
commit af681c8f15
3 changed files with 329 additions and 213 deletions

View file

@ -1,12 +1,21 @@
use std::collections::HashMap;
use wicked_waifus_data::pb_components::action::{CollectParams, UnlockTeleportTrigger};
use wicked_waifus_protocol::{ItemRewardNotify, NormalItemUpdateNotify, RewardItemInfo, WR};
use crate::logic::{
player::{ItemUsage, Player},
use wicked_waifus_protocol::{
CommonTagData, EntityCommonTagNotify, EntityStateReadyNotify, ItemRewardNotify,
NormalItemUpdateNotify, RewardItemInfo, WR,
};
use wicked_waifus_data::pb_components::action::{
ChangeSelfEntityState, CollectParams, UnlockTeleportTrigger
};
use wicked_waifus_data::pb_components::entity_state::EntityStateComponent;
use crate::logic::ecs::component::ComponentContainer;
use crate::logic::handler::handle_action;
use crate::logic::player::{ItemUsage, Player};
use crate::logic::utils::tag_utils;
use crate::query_components;
pub fn collect_action(
player: &mut Player,
_entity_id: i64,
@ -69,7 +78,7 @@ pub fn collect_action(
}
#[inline(always)]
fn unlock_teleport_trigger_action(
pub fn unlock_teleport_trigger_action(
player: &mut Player,
_entity_id: i64,
_level_entity_data: &wicked_waifus_data::LevelEntityConfigData,
@ -78,3 +87,79 @@ fn unlock_teleport_trigger_action(
) {
player.unlock_teleport(action.teleport_id)
}
pub fn change_self_entity_state_action(
player: &mut Player,
entity_id: i64,
level_entity_data: &wicked_waifus_data::LevelEntityConfigData,
template_config: &wicked_waifus_data::TemplateConfigData,
action: ChangeSelfEntityState,
) {
let state = tag_utils::get_tag_id_by_name(action.entity_state.as_str());
// TODO: update Tag::CommonEntityTags too??
let old_state = {
let world_ref = player.world.borrow();
let world = world_ref.get_world_entity();
let mut state_tag = query_components!(world, entity_id, StateTag).0.unwrap();
let old_state = state_tag.state_tag_id;
tracing::debug!("ChangeSelfEntityState: old state {old_state} -> new state: {state}");
state_tag.state_tag_id = state;
old_state
};
if let Some(entity_state_component) = level_entity_data
.components_data
.entity_state_component
.as_ref()
.or(template_config
.components_data
.entity_state_component
.as_ref())
.cloned()
{
let entity_state_component: EntityStateComponent = entity_state_component; // TODO: Remove this line, used for casting only
// TODO: implement rest of cases
if let Some(state_change_behaviors) = entity_state_component.state_change_behaviors {
for state_change_behavior in state_change_behaviors {
// TODO: implement rest of cases
let expected = tag_utils::get_tag_id_by_name(state_change_behavior.state.as_str());
if expected == state {
if let Some(actions) = state_change_behavior.action {
for sub in actions {
handle_action(
player,
entity_id,
level_entity_data,
template_config,
sub,
);
}
}
}
}
}
}
player.notify(EntityCommonTagNotify {
id: entity_id,
tags: vec![
CommonTagData {
tag_id: old_state,
remove_tag_ids: false,
}, // Remove
CommonTagData {
tag_id: state,
remove_tag_ids: true,
}, // Add
],
});
player.notify(EntityStateReadyNotify {
entity_id,
tag_id: state,
ready: true, // TODO: Always true? or shall we compare it to something??
});
}

View file

@ -115,7 +115,7 @@ macro_rules! handle_push {
}
macro_rules! handle_action {
($($variant:ident),*) => {
($($variant:ident),* $(,)?) => {
use wicked_waifus_data::pb_components::action::Action;
use crate::logic::player::Player;
@ -124,18 +124,24 @@ macro_rules! handle_action {
entity_id: i64,
level_entity_data: &wicked_waifus_data::LevelEntityConfigData,
template_config: &wicked_waifus_data::TemplateConfigData,
element: Action
action: Action
) {
::paste::paste! {
match element {
match action {
$(
Action::$variant(inner) => {
paste::paste! {
[<$variant:snake _action>](player, entity_id, level_entity_data, template_config, inner.params)
}
[<$variant:snake _action>](
player,
entity_id,
level_entity_data,
template_config,
inner.params
)
},
_ => tracing::debug!("hi"),
)*
_ => {
::tracing::warn!("Action not implemented for: {:?}", action);
}
}
}
}
@ -320,190 +326,190 @@ handle_push! {
}
handle_action! {
ExecBattleAction,
WaitBattleCondition,
SetBattleState,
PlayFlow,
// ExecBattleAction,
// WaitBattleCondition,
// SetBattleState,
// PlayFlow,
Collect,
LeisureInteract,
// LeisureInteract,
UnlockTeleportTrigger,
EnableTemporaryTeleport,
OpenSystemBoard,
OpenSystemFunction,
// EnableTemporaryTeleport,
// OpenSystemBoard,
// OpenSystemFunction,
ChangeSelfEntityState,
SetPlayerOperationRestriction,
Wait,
ChangeEntityState,
Log,
EnableNearbyTracking,
TeleportDungeon,
DestroySelf,
CameraLookAt,
StopCameraLookAt,
EnterOrbitalCamera,
ExitOrbitalCamera,
SendAiEvent,
SetInteractionLockState,
AwakeEntity,
ChangeLiftTarget,
CalculateVar,
AddBuffToPlayer,
RemoveBuffFromPlayer,
AddBuffToEntity,
RemoveBuffFromEntity,
Prompt,
SetEntityVisible,
DestroyEntity,
GuideTrigger,
TriggerCameraShake,
SetVar,
VehicleEnter,
VehicleExitPlayer,
LockEntity,
UnlockEntity,
CommonTip,
CommonTip2,
PostAkEvent,
VehicleEnterNpc,
VehicleExitNpc,
PlayerLookAt,
PlayBubble,
AddPlayBubble,
ClearPlayBubble,
ExecRiskHarvestEffect,
EnableLevelPlay,
ClaimLevelPlayReward,
SettlementDungeon,
ExitDungeon,
FinishDungeon,
RecordDungeonEvent,
RecoverDurability,
FadeInScreen,
FadeOutScreen,
ChangeNpcPerformState,
EntityTurnTo,
EntityLookAt,
ToggleMapMarkState,
RandomVar,
ModifySceneItemAttributeTag,
VehicleWaterfallClimbing,
VehicleTeleport,
RogueGotoNextFloor,
RogueReceiveReward,
RogueSelectRoom,
RogueActivatePortal,
MowingTowerGotoNextFloor,
SlashAndTowerGotoNextFloor,
PlayMontage,
OpenSystemBoardWithReturn,
UnlockSystemItem,
SetSportsState,
OpenSimpleGameplay,
PlayEffect,
PlayEffect2,
RestorePlayerCameraAdjustment,
AdjustPlayerCamera,
SetPlayerPos,
MoveWithSpline,
EnableSplineMoveModel,
ToggleScanSplineEffect,
MoveSceneItem,
StopSceneItemMove,
FireBullet,
ClearFishingCabinInSaleItems,
AcceptFishingEntrust,
DestroyFishingBoat,
SetJigsawItem,
SetJigsawFoundation,
SetTeleControl,
SetEntityClientVisible,
ToggleHighlightExploreUi,
ExecAlertSystemAction,
AddFlowInteractOption,
RemoveFlowInteractOption,
EnableHostility,
ChangePhantomFormation,
RestorePhantomFormation,
ChangeTimer,
ToggleTimerPauseState,
ChangeFightTeam,
AddTrialFollowShooter,
RemoveTrialFollowShooter,
AddTrialCharacter,
RemoveTrialCharacter,
SetAreaState,
SwitchSubLevels,
ChangeTeamPosition,
GetItem,
CreatePrefab,
DestroyPrefab,
CompleteGuide,
PlayDynamicSettlement,
UsePhantomSkill,
HideTargetRange,
ChangeOtherState,
SetRegionConfig,
SetReviveRegion,
ExecResurrection,
ShowTargetRange,
SetTime,
SetTimeLockState,
EnableSystem,
EnableAoiNotify,
SetForceLock,
PlayRegisteredMontage,
SetAudioState,
HideGroup,
ShowHidedGroup,
HideSpecificEntities,
ShowSpecificEntities,
RemovePreloadResource,
Preload,
EnableAI,
SwitchDataLayers,
DestroyQuest,
DestroyQuestItem,
PromptQuestChapterUI,
TakePlotPhoto,
SetWuYinQuState,
RunActions,
ManualOccupations,
SetWeather,
SendNpcMail,
EnableFunction,
FocusOnMapMark,
CharacterLookAt,
AddGuestCharacter,
RemoveGuestCharacter,
TeleportToAndEnterVehicle,
SetAreaTimeState,
ResetPlayerCameraFocus,
ResetLevelPlay,
VehicleSprint,
VehicleMoveWithPathLine,
ClientPreEnableSubLevels,
GuestOperateUiAnimation,
ChangeEntityCamp,
NewMoveWithSpline,
DangoAbyssActivatePortal,
DangoAbyssCreateRewardTreasureBox,
DangoAbyssGotoNextFloor,
DangoAbyssReceiveReward,
SummonEntity,
GetRewardByInteract,
OpenQte,
ActiveAntiGravitySafePoint,
BvbPlayDialog,
BvbSendSystemEvent,
BvbSendAiEvent,
BvbPlayerOperationConstraint,
ExecClientBattleAction,
TriggerSpecificScanEffect,
SetActorVar,
RunActorCustomEvent,
StopUiScreenEffect,
StopNewMoveWithSpline,
RequestSystemFunction
// SetPlayerOperationRestriction,
// Wait,
// ChangeEntityState,
// Log,
// EnableNearbyTracking,
// TeleportDungeon,
// DestroySelf,
// CameraLookAt,
// StopCameraLookAt,
// EnterOrbitalCamera,
// ExitOrbitalCamera,
// SendAiEvent,
// SetInteractionLockState,
// AwakeEntity,
// ChangeLiftTarget,
// CalculateVar,
// AddBuffToPlayer,
// RemoveBuffFromPlayer,
// AddBuffToEntity,
// RemoveBuffFromEntity,
// Prompt,
// SetEntityVisible,
// DestroyEntity,
// GuideTrigger,
// TriggerCameraShake,
// SetVar,
// VehicleEnter,
// VehicleExitPlayer,
// LockEntity,
// UnlockEntity,
// CommonTip,
// CommonTip2,
// PostAkEvent,
// VehicleEnterNpc,
// VehicleExitNpc,
// PlayerLookAt,
// PlayBubble,
// AddPlayBubble,
// ClearPlayBubble,
// ExecRiskHarvestEffect,
// EnableLevelPlay,
// ClaimLevelPlayReward,
// SettlementDungeon,
// ExitDungeon,
// FinishDungeon,
// RecordDungeonEvent,
// RecoverDurability,
// FadeInScreen,
// FadeOutScreen,
// ChangeNpcPerformState,
// EntityTurnTo,
// EntityLookAt,
// ToggleMapMarkState,
// RandomVar,
// ModifySceneItemAttributeTag,
// VehicleWaterfallClimbing,
// VehicleTeleport,
// RogueGotoNextFloor,
// RogueReceiveReward,
// RogueSelectRoom,
// RogueActivatePortal,
// MowingTowerGotoNextFloor,
// SlashAndTowerGotoNextFloor,
// PlayMontage,
// OpenSystemBoardWithReturn,
// UnlockSystemItem,
// SetSportsState,
// OpenSimpleGameplay,
// PlayEffect,
// PlayEffect2,
// RestorePlayerCameraAdjustment,
// AdjustPlayerCamera,
// SetPlayerPos,
// MoveWithSpline,
// EnableSplineMoveModel,
// ToggleScanSplineEffect,
// MoveSceneItem,
// StopSceneItemMove,
// FireBullet,
// ClearFishingCabinInSaleItems,
// AcceptFishingEntrust,
// DestroyFishingBoat,
// SetJigsawItem,
// SetJigsawFoundation,
// SetTeleControl,
// SetEntityClientVisible,
// ToggleHighlightExploreUi,
// ExecAlertSystemAction,
// AddFlowInteractOption,
// RemoveFlowInteractOption,
// EnableHostility,
// ChangePhantomFormation,
// RestorePhantomFormation,
// ChangeTimer,
// ToggleTimerPauseState,
// ChangeFightTeam,
// AddTrialFollowShooter,
// RemoveTrialFollowShooter,
// AddTrialCharacter,
// RemoveTrialCharacter,
// SetAreaState,
// SwitchSubLevels,
// ChangeTeamPosition,
// GetItem,
// CreatePrefab,
// DestroyPrefab,
// CompleteGuide,
// PlayDynamicSettlement,
// UsePhantomSkill,
// HideTargetRange,
// ChangeOtherState,
// SetRegionConfig,
// SetReviveRegion,
// ExecResurrection,
// ShowTargetRange,
// SetTime,
// SetTimeLockState,
// EnableSystem,
// EnableAoiNotify,
// SetForceLock,
// PlayRegisteredMontage,
// SetAudioState,
// HideGroup,
// ShowHidedGroup,
// HideSpecificEntities,
// ShowSpecificEntities,
// RemovePreloadResource,
// Preload,
// EnableAI,
// SwitchDataLayers,
// DestroyQuest,
// DestroyQuestItem,
// PromptQuestChapterUI,
// TakePlotPhoto,
// SetWuYinQuState,
// RunActions,
// ManualOccupations,
// SetWeather,
// SendNpcMail,
// EnableFunction,
// FocusOnMapMark,
// CharacterLookAt,
// AddGuestCharacter,
// RemoveGuestCharacter,
// TeleportToAndEnterVehicle,
// SetAreaTimeState,
// ResetPlayerCameraFocus,
// ResetLevelPlay,
// VehicleSprint,
// VehicleMoveWithPathLine,
// ClientPreEnableSubLevels,
// GuestOperateUiAnimation,
// ChangeEntityCamp,
// NewMoveWithSpline,
// DangoAbyssActivatePortal,
// DangoAbyssCreateRewardTreasureBox,
// DangoAbyssGotoNextFloor,
// DangoAbyssReceiveReward,
// SummonEntity,
// GetRewardByInteract,
// OpenQte,
// ActiveAntiGravitySafePoint,
// BvbPlayDialog,
// BvbSendSystemEvent,
// BvbSendAiEvent,
// BvbPlayerOperationConstraint,
// ExecClientBattleAction,
// TriggerSpecificScanEffect,
// SetActorVar,
// RunActorCustomEvent,
// StopUiScreenEffect,
// StopNewMoveWithSpline,
// RequestSystemFunction
}
pub fn handle_logic_message(player: &mut super::player::Player, msg: Message) {

View file

@ -1,8 +1,13 @@
use std::collections::HashMap;
use wicked_waifus_protocol::{CommonTagData, EntityCommonTagNotify, EntityStateReadyNotify, ItemRewardNotify, NormalItemUpdateNotify, RewardItemInfo, WR};
use wicked_waifus_protocol::{
CommonTagData, EntityCommonTagNotify, EntityStateReadyNotify, ItemRewardNotify,
NormalItemUpdateNotify, RewardItemInfo, WR,
};
use wicked_waifus_data::pb_components::action::{Action, ChangeSelfEntityState, UnlockTeleportTrigger};
use wicked_waifus_data::pb_components::action::{
Action, ChangeSelfEntityState, UnlockTeleportTrigger,
};
use wicked_waifus_data::pb_components::entity_state::EntityStateComponent;
use crate::logic::ecs::component::ComponentContainer;
@ -12,11 +17,9 @@ use crate::logic::utils::tag_utils;
use crate::query_components;
macro_rules! unimplemented_action {
($action:ident) => {
{
tracing::warn!("Action not implemented for: {:?}", $action);
}
}
($action:ident) => {{
tracing::warn!("Action not implemented for: {:?}", $action);
}};
}
// pub fn perform_action(player: &mut Player,
@ -212,11 +215,13 @@ macro_rules! unimplemented_action {
// }
// }
fn change_self_entity_state_action(player: &mut Player,
entity_id: i64,
level_entity_data: &wicked_waifus_data::LevelEntityConfigData,
template_config: &wicked_waifus_data::TemplateConfigData,
action: ChangeSelfEntityState) {
pub fn change_self_entity_state_action(
player: &mut Player,
entity_id: i64,
level_entity_data: &wicked_waifus_data::LevelEntityConfigData,
template_config: &wicked_waifus_data::TemplateConfigData,
action: ChangeSelfEntityState,
) {
let state = tag_utils::get_tag_id_by_name(action.entity_state.as_str());
// TODO: update Tag::CommonEntityTags too??
@ -230,9 +235,17 @@ fn change_self_entity_state_action(player: &mut Player,
old_state
};
if let Some(entity_state_component) = level_entity_data.components_data.entity_state_component.as_ref()
.or(template_config.components_data.entity_state_component.as_ref()).cloned() {
let entity_state_component: EntityStateComponent = entity_state_component; // TODO: Remove this line, used for casting only
if let Some(entity_state_component) = level_entity_data
.components_data
.entity_state_component
.as_ref()
.or(template_config
.components_data
.entity_state_component
.as_ref())
.cloned()
{
let entity_state_component: EntityStateComponent = entity_state_component; // TODO: Remove this line, used for casting only
// TODO: implement rest of cases
if let Some(state_change_behaviors) = entity_state_component.state_change_behaviors {
@ -243,7 +256,13 @@ fn change_self_entity_state_action(player: &mut Player,
if expected == state {
if let Some(actions) = state_change_behavior.action {
for sub in actions {
handle_action(player, entity_id, level_entity_data, template_config, sub);
handle_action(
player,
entity_id,
level_entity_data,
template_config,
sub,
);
}
}
}
@ -254,8 +273,14 @@ fn change_self_entity_state_action(player: &mut Player,
player.notify(EntityCommonTagNotify {
id: entity_id,
tags: vec![
CommonTagData { tag_id: old_state, remove_tag_ids: false }, // Remove
CommonTagData { tag_id: state, remove_tag_ids: true }, // Add
CommonTagData {
tag_id: old_state,
remove_tag_ids: false,
}, // Remove
CommonTagData {
tag_id: state,
remove_tag_ids: true,
}, // Add
],
});
@ -264,4 +289,4 @@ fn change_self_entity_state_action(player: &mut Player,
tag_id: state,
ready: true, // TODO: Always true? or shall we compare it to something??
});
}
}