#include "CharacterObject.h" #include "Asset/Squirrel/SquirrelManager.h" #include "Actor/Map/GameMap.h" #include "Actor/Map/GameWorld.h" CharacterObject::~CharacterObject() { } void CharacterObject::Construction(int job) { m_objecttype = ObjectType::CHARACTER; this->Job = job; // 创建装备管理器 _EquipmentManager = new Chr_Equipment(); _EquipmentManager->Init(this); // 创建动画管理器(一定要先创建装备管理器再创建动画管理器 因为需要读取身上的装备) _AnimationManager = new Chr_Animation(); _AnimationManager->Init(this); // 创建状态机 _StateMachine = new Chr_StateMachine(); _StateMachine->Init(this); // 开启控制器 EnableController(); } void CharacterObject::EnableController() { this->_Controller = new Chr_Controller(); _Controller->Init(this); AddChild(_Controller); } void CharacterObject::DisableController() { this->RemoveChild(_Controller); this->_Controller = nullptr; } void CharacterObject::ControllerMsg(CONTROLLER_MSG_TYPE msgType, void *msgData) { // 摇杆移动 if (msgType == CONTROLLER_MSG_TYPE::CONTROLLER_MSG_TYPE_LEFT_JOYSTICK_MOVE) { Vec2 *pos = (Vec2 *)msgData; std::vector movedata = {pos->x, pos->y}; this->GetObjectVars().SetArray("_move_data_", movedata); this->_StateMachine->ChangeState(BASE_STATE::MOVE); } } void CharacterObject::SetPosition(VecFPos3 pos) { BaseObject::SetPosition(pos); } void CharacterObject::SetDirection(int dir) { BaseObject::SetDirection(dir); } void CharacterObject::OnUpdate(float deltaTime) { ActiveObject::OnUpdate(deltaTime); // 判断是否要进行区域移动 if (!IsTeleportArea) { GameMap::MapMoveArea Info = this->_AffMap->CheckIsItMoveArea(this->GetPosition()); if (Info.town != -2 && Info.area != -2) { IsTeleportArea = true; // 调用世界类移动自己 GameWorld::GetWorld()->MoveCharacter(this, Info.town, Info.area); } } else { GameMap::MapMoveArea Info = this->_AffMap->CheckIsItMoveArea(this->GetPosition()); if (Info.town == -2 && Info.area == -2) IsTeleportArea = false; } }