Skip to content

Commit 02c0f37

Browse files
committed
完善teleport功能。
1 parent 1fd96a4 commit 02c0f37

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

kbe/src/server/cellapp/entity.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2845,6 +2845,10 @@ void Entity::createFromStream(KBEngine::MemoryStream& s)
28452845
s >> scriptUType >> spaceID_ >> isDestroyed_ >> isOnGround_ >> topSpeed_ >>
28462846
topSpeedY_ >> layer_ >> baseMailboxComponentID;
28472847

2848+
// 此时强制设置为不在地面,无法判定其是否在地面,角色需要客户端上报是否在地面
2849+
// 而服务端的NPC则与移动后是否在地面来判定。
2850+
isOnGround_ = false;
2851+
28482852
this->scriptModule_ = EntityDef::findScriptModule(scriptUType);
28492853

28502854
// 设置entity的baseMailbox
@@ -2950,7 +2954,10 @@ void Entity::createWitnessFromStream(KBEngine::MemoryStream& s)
29502954
EntityMailbox* client = static_cast<EntityMailbox*>(clientMB);
29512955
clientMailbox(client);
29522956

2953-
setWitness(Witness::ObjPool().createObject());
2957+
// 不要使用setWitness,因为此时不需要走onAttach流程,客户端不需要重新enterworld。
2958+
// setWitness(Witness::ObjPool().createObject());
2959+
pWitness_ = Witness::ObjPool().createObject();
2960+
pWitness_->pEntity(this);
29542961
pWitness_->createFromStream(s);
29552962
}
29562963
}

kbe/src/server/cellapp/move_controller.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
2121
#include "cellapp.hpp"
2222
#include "entity.hpp"
2323
#include "move_controller.hpp"
24+
#include "moveto_point_handler.hpp"
25+
#include "moveto_entity_handler.hpp"
26+
#include "navigate_handler.hpp"
2427

2528
namespace KBEngine{
2629

@@ -45,13 +48,29 @@ void MoveController::addToStream(KBEngine::MemoryStream& s)
4548
{
4649
Controller::addToStream(s);
4750

51+
uint8 utype = pMoveToPointHandler_->type();
52+
s << utype;
53+
4854
pMoveToPointHandler_->addToStream(s);
4955
}
5056

5157
//-------------------------------------------------------------------------------------
5258
void MoveController::createFromStream(KBEngine::MemoryStream& s)
5359
{
5460
Controller::createFromStream(s);
61+
KBE_ASSERT(pMoveToPointHandler_ == NULL);
62+
63+
uint8 utype;
64+
s >> utype;
65+
66+
if(utype == MoveToPointHandler::MOVE_TYPE_NAV)
67+
pMoveToPointHandler_ = new NavigateHandler();
68+
else if(utype == MoveToPointHandler::MOVE_TYPE_ENTITY)
69+
pMoveToPointHandler_ = new MoveToEntityHandler();
70+
else if(utype == MoveToPointHandler::MOVE_TYPE_POINT)
71+
pMoveToPointHandler_ = new MoveToPointHandler();
72+
else
73+
KBE_ASSERT(false);
5574

5675
pMoveToPointHandler_->createFromStream(s);
5776
}

kbe/src/server/cellapp/moveto_point_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void MoveToPointHandler::addToStream(KBEngine::MemoryStream& s)
7373
{
7474
uint8 utype = type();
7575

76-
s << utype << destPos_.x << destPos_.y << destPos_.z << velocity_ << faceMovement_ << moveVertically_ <<
76+
s << /*utype <<*/ destPos_.x << destPos_.y << destPos_.z << velocity_ << faceMovement_ << moveVertically_ <<
7777
range_ << layer_;
7878

7979
s.appendBlob(script::Pickler::pickle(pyuserarg_));

kbe/src/server/cellapp/witness.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ void Witness::createFromStream(KBEngine::MemoryStream& s)
113113
}
114114

115115
lastBasePos.z = -FLT_MAX;
116+
Cellapp::getSingleton().addUpdatable(this);
116117
}
117118

118119
//-------------------------------------------------------------------------------------

kbe/src/server/cellapp/witness.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class Witness : public PoolObject, public Updatable
103103
return bytes;
104104
}
105105

106+
INLINE void pEntity(Entity* pEntity);
106107
INLINE Entity* pEntity();
107108

108109
void attach(Entity* pEntity);

kbe/src/server/cellapp/witness.ipp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ INLINE Entity* Witness::pEntity()
2727
return pEntity_;
2828
}
2929

30+
//-------------------------------------------------------------------------------------
31+
INLINE void Witness::pEntity(Entity* pEntity)
32+
{
33+
pEntity_ = pEntity;
34+
}
35+
3036
//-------------------------------------------------------------------------------------
3137
INLINE float Witness::aoiRadius()const
3238
{

0 commit comments

Comments
 (0)