mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-28 15:17:46 +00:00
move itemaction to own class, perchbird's effect command
This commit is contained in:
parent
86517c53ea
commit
ccb83bec5d
6 changed files with 150 additions and 42 deletions
|
@ -38,8 +38,7 @@ Action::Action( Entity::CharaPtr caster, uint32_t actionId, FrameworkPtr fw ) :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Action::Action( Entity::CharaPtr caster, uint32_t actionId,
|
Action::Action( Entity::CharaPtr caster, uint32_t actionId, Data::ActionPtr actionData, FrameworkPtr fw ) :
|
||||||
Data::ActionPtr actionData, FrameworkPtr fw ) :
|
|
||||||
m_pSource( std::move( caster ) ),
|
m_pSource( std::move( caster ) ),
|
||||||
m_pFw( std::move( fw ) ),
|
m_pFw( std::move( fw ) ),
|
||||||
m_actionData( std::move( actionData ) ),
|
m_actionData( std::move( actionData ) ),
|
||||||
|
|
73
src/world/Action/ItemAction.cpp
Normal file
73
src/world/Action/ItemAction.cpp
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
#include "ItemAction.h"
|
||||||
|
|
||||||
|
#include <Exd/ExdDataGenerated.h>
|
||||||
|
|
||||||
|
#include <Actor/Player.h>
|
||||||
|
#include <Network/PacketWrappers/EffectPacket.h>
|
||||||
|
|
||||||
|
using namespace Sapphire;
|
||||||
|
using namespace Sapphire::World::Action;
|
||||||
|
|
||||||
|
ItemAction::ItemAction( Sapphire::Entity::CharaPtr source, uint32_t itemId,
|
||||||
|
Sapphire::Data::ItemActionPtr itemActionData, uint16_t itemSourceSlot,
|
||||||
|
uint16_t itemSourceContainer, Sapphire::FrameworkPtr fw ) :
|
||||||
|
m_itemAction( std::move( itemActionData ) ),
|
||||||
|
m_itemSourceSlot( itemSourceSlot ),
|
||||||
|
m_itemSourceContainer( itemSourceContainer )
|
||||||
|
{
|
||||||
|
m_id = itemId;
|
||||||
|
m_pSource = std::move( source );
|
||||||
|
m_pFw = std::move( fw );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemAction::start()
|
||||||
|
{
|
||||||
|
if( !m_pSource->isPlayer() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// todo: check inv slot for item
|
||||||
|
|
||||||
|
// todo: can we just do this?
|
||||||
|
execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemAction::execute()
|
||||||
|
{
|
||||||
|
switch( m_itemAction->type )
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
getSourceChara()->getAsPlayer()->sendDebug( "ItemAction type {0} not supported.", m_itemAction->type );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Common::ItemActionType::ItemActionVFX:
|
||||||
|
case Common::ItemActionType::ItemActionVFX2:
|
||||||
|
{
|
||||||
|
handleVFXItem();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemAction::interrupt()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemAction::handleVFXItem()
|
||||||
|
{
|
||||||
|
Common::EffectEntry effect{};
|
||||||
|
effect.effectType = Common::ActionEffectType::VFX;
|
||||||
|
effect.value = m_itemAction->data[ 0 ];
|
||||||
|
|
||||||
|
auto effectPacket = std::make_shared< Network::Packets::Server::EffectPacket >( getSourceChara()->getId(),
|
||||||
|
getSourceChara()->getId(), getId() );
|
||||||
|
effectPacket->setTargetActor( getSourceChara()->getId() );
|
||||||
|
effectPacket->setAnimationId( Common::ItemActionType::ItemActionVFX );
|
||||||
|
effectPacket->setDisplayType( Common::ActionEffectDisplayType::ShowItemName );
|
||||||
|
effectPacket->addEffect( effect );
|
||||||
|
|
||||||
|
m_pSource->sendToInRangeSet( effectPacket, true );
|
||||||
|
}
|
38
src/world/Action/ItemAction.h
Normal file
38
src/world/Action/ItemAction.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#ifndef SAPPHIRE_ITEMACTION_H
|
||||||
|
#define SAPPHIRE_ITEMACTION_H
|
||||||
|
|
||||||
|
#include "Action.h"
|
||||||
|
|
||||||
|
namespace Sapphire::Data
|
||||||
|
{
|
||||||
|
struct ItemAction;
|
||||||
|
using ItemActionPtr = std::shared_ptr< ItemAction >;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Sapphire::World::Action
|
||||||
|
{
|
||||||
|
class ItemAction : public Action
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ItemAction( Entity::CharaPtr source, uint32_t itemId, Data::ItemActionPtr itemActionData,
|
||||||
|
uint16_t itemSourceSlot, uint16_t itemSourceContainer, FrameworkPtr fw );
|
||||||
|
virtual ~ItemAction() = default;
|
||||||
|
|
||||||
|
void start() override;
|
||||||
|
|
||||||
|
void execute() override;
|
||||||
|
|
||||||
|
void interrupt() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void handleVFXItem();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Sapphire::Data::ItemActionPtr m_itemAction;
|
||||||
|
|
||||||
|
uint16_t m_itemSourceSlot;
|
||||||
|
uint16_t m_itemSourceContainer;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //SAPPHIRE_ITEMACTION_H
|
|
@ -86,6 +86,7 @@ namespace World::Action
|
||||||
{
|
{
|
||||||
TYPE_FORWARD( Action );
|
TYPE_FORWARD( Action );
|
||||||
TYPE_FORWARD( EventAction );
|
TYPE_FORWARD( EventAction );
|
||||||
|
TYPE_FORWARD( ItemAction );
|
||||||
|
|
||||||
using ActionCallback = std::function< void( Entity::Player&, uint32_t, uint64_t ) >;
|
using ActionCallback = std::function< void( Entity::Player&, uint32_t, uint64_t ) >;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "ActionMgr.h"
|
#include "ActionMgr.h"
|
||||||
|
|
||||||
#include "Action/Action.h"
|
#include "Action/Action.h"
|
||||||
|
#include "Action/ItemAction.h"
|
||||||
#include "Script/ScriptMgr.h"
|
#include "Script/ScriptMgr.h"
|
||||||
#include "Actor/Player.h"
|
#include "Actor/Player.h"
|
||||||
|
|
||||||
|
@ -66,24 +67,11 @@ void World::Manager::ActionMgr::handleItemAction( Sapphire::Entity::Player& play
|
||||||
{
|
{
|
||||||
player.sendDebug( "got item act: {0}, slot: {1}, container: {2}", itemId, itemSourceSlot, itemSourceContainer );
|
player.sendDebug( "got item act: {0}, slot: {1}, container: {2}", itemId, itemSourceSlot, itemSourceContainer );
|
||||||
|
|
||||||
// todo: check we have item & remove item from inventory
|
auto action = Action::make_ItemAction( player.getAsChara(), itemId, itemActionData,
|
||||||
|
itemSourceSlot, itemSourceContainer, framework() );
|
||||||
|
|
||||||
switch( itemActionData->type )
|
// todo: item actions don't have cast times? if so we can just start it and we're good
|
||||||
{
|
action->start();
|
||||||
default:
|
|
||||||
{
|
|
||||||
player.sendDebug( "ItemAction type {0} not supported.", itemActionData->type );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Common::ItemActionType::ItemActionVFX:
|
|
||||||
case Common::ItemActionType::ItemActionVFX2:
|
|
||||||
{
|
|
||||||
handleItemActionVFX( player, itemId, itemActionData->data[ 0 ] );
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::Manager::ActionMgr::bootstrapAction( Entity::Player& player,
|
void World::Manager::ActionMgr::bootstrapAction( Entity::Player& player,
|
||||||
|
@ -106,18 +94,3 @@ void World::Manager::ActionMgr::bootstrapAction( Entity::Player& player,
|
||||||
// todo: what do in cases of swiftcast/etc? script callback?
|
// todo: what do in cases of swiftcast/etc? script callback?
|
||||||
currentAction->start();
|
currentAction->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::Manager::ActionMgr::handleItemActionVFX( Sapphire::Entity::Player& player, uint32_t itemId, uint16_t vfxId )
|
|
||||||
{
|
|
||||||
Common::EffectEntry effect{};
|
|
||||||
effect.effectType = Common::ActionEffectType::VFX;
|
|
||||||
effect.value = vfxId;
|
|
||||||
|
|
||||||
auto effectPacket = std::make_shared< Network::Packets::Server::EffectPacket >( player.getId(), player.getId(), itemId );
|
|
||||||
effectPacket->setTargetActor( player.getId() );
|
|
||||||
effectPacket->setAnimationId( Common::ItemActionType::ItemActionVFX );
|
|
||||||
effectPacket->setDisplayType( Common::ActionEffectDisplayType::ShowItemName );
|
|
||||||
effectPacket->addEffect( effect );
|
|
||||||
|
|
||||||
player.sendToInRangeSet( effectPacket, true );
|
|
||||||
}
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Exd/ExdDataGenerated.h>
|
#include <Exd/ExdDataGenerated.h>
|
||||||
#include <Database/DatabaseDef.h>
|
#include <Database/DatabaseDef.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <Network/PacketWrappers/EffectPacket.h>
|
||||||
|
|
||||||
#include "DebugCommand/DebugCommand.h"
|
#include "DebugCommand/DebugCommand.h"
|
||||||
#include "DebugCommandMgr.h"
|
#include "DebugCommandMgr.h"
|
||||||
|
@ -522,6 +523,29 @@ void Sapphire::World::Manager::DebugCommandMgr::add( char* data, Entity::Player&
|
||||||
sscanf( params.c_str(), "%d", &id );
|
sscanf( params.c_str(), "%d", &id );
|
||||||
player.learnAction( id );
|
player.learnAction( id );
|
||||||
}
|
}
|
||||||
|
else if ( subCommand == "effect")
|
||||||
|
{
|
||||||
|
uint16_t param1;
|
||||||
|
sscanf( params.c_str(), "%hu", ¶m1 );
|
||||||
|
|
||||||
|
auto effectPacket = std::make_shared< Server::EffectPacket >( player.getId(), player.getTargetId(), param1 );
|
||||||
|
effectPacket->setRotation( Common::Util::floatToUInt16Rot( player.getRot() ) );
|
||||||
|
|
||||||
|
Common::EffectEntry entry{};
|
||||||
|
entry.value = param1;
|
||||||
|
entry.effectType = Common::ActionEffectType::Damage;
|
||||||
|
entry.hitSeverity = Common::ActionHitSeverityType::NormalDamage;
|
||||||
|
|
||||||
|
effectPacket->addEffect( entry );
|
||||||
|
|
||||||
|
auto sequence = player.getCurrentZone()->getNextEffectSequence();
|
||||||
|
effectPacket->setSequence( sequence );
|
||||||
|
|
||||||
|
// effectPacket->setAnimationId( param1 );
|
||||||
|
// effectPacket->setEffectFlags( 0 );
|
||||||
|
|
||||||
|
player.queuePacket( effectPacket );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
player.sendUrgent( "{0} is not a valid ADD command.", subCommand );
|
player.sendUrgent( "{0} is not a valid ADD command.", subCommand );
|
||||||
|
|
Loading…
Add table
Reference in a new issue