@@ -1495,6 +1495,8 @@ void Cellapp::reqTeleportOtherAck(Mercury::Channel* pChannel, MemoryStream& s)
1495
1495
// -------------------------------------------------------------------------------------
1496
1496
void Cellapp::reqTeleportOther (Mercury::Channel* pChannel, MemoryStream& s)
1497
1497
{
1498
+ size_t rpos = s.rpos ();
1499
+
1498
1500
ENTITY_ID nearbyMBRefID = 0 , teleportEntityID = 0 ;
1499
1501
Position3D pos;
1500
1502
Direction3D dir;
@@ -1505,10 +1507,22 @@ void Cellapp::reqTeleportOther(Mercury::Channel* pChannel, MemoryStream& s)
1505
1507
s >> entityType;
1506
1508
s >> pos.x >> pos.y >> pos.z ;
1507
1509
s >> dir.dir .x >> dir.dir .y >> dir.dir .z ;
1510
+
1511
+ bool success = false ;
1508
1512
1509
1513
Space* space = Spaces::findSpace (spaceID);
1510
1514
if (space == NULL )
1511
1515
{
1516
+ s.rpos (rpos);
1517
+
1518
+ Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool ().createObject ();
1519
+ (*pBundle).newMessage (CellappInterface::reqTeleportOtherCB);
1520
+ (*pBundle) << teleportEntityID;
1521
+ (*pBundle) << success;
1522
+ (*pBundle).append (&s);
1523
+ pBundle->send (this ->getNetworkInterface (), pChannel);
1524
+ Mercury::Bundle::ObjPool ().reclaimObject (pBundle);
1525
+
1512
1526
ERROR_MSG (boost::format (" Cellapp::reqTeleportOther: not found space(%1%), reqTeleportEntity(%2%)!\n " ) % spaceID % teleportEntityID);
1513
1527
s.opfini ();
1514
1528
return ;
@@ -1518,6 +1532,16 @@ void Cellapp::reqTeleportOther(Mercury::Channel* pChannel, MemoryStream& s)
1518
1532
Entity* e = createEntityCommon (EntityDef::findScriptModule (entityType)->getName (), NULL , false , teleportEntityID, false );
1519
1533
if (e == NULL )
1520
1534
{
1535
+ s.rpos (rpos);
1536
+
1537
+ Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool ().createObject ();
1538
+ (*pBundle).newMessage (CellappInterface::reqTeleportOtherCB);
1539
+ (*pBundle) << teleportEntityID;
1540
+ (*pBundle) << success;
1541
+ (*pBundle).append (&s);
1542
+ pBundle->send (this ->getNetworkInterface (), pChannel);
1543
+ Mercury::Bundle::ObjPool ().reclaimObject (pBundle);
1544
+
1521
1545
ERROR_MSG (boost::format (" Cellapp::reqTeleportOther: create reqTeleportEntity(%1%) is error!\n " ) % teleportEntityID);
1522
1546
s.opfini ();
1523
1547
return ;
@@ -1536,6 +1560,61 @@ void Cellapp::reqTeleportOther(Mercury::Channel* pChannel, MemoryStream& s)
1536
1560
1537
1561
Entity* nearbyMBRef = Cellapp::getSingleton ().findEntity (nearbyMBRefID);
1538
1562
e->onTeleportSuccess (nearbyMBRef, lastSpaceID);
1563
+
1564
+ success = true ;
1565
+
1566
+ {
1567
+ Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool ().createObject ();
1568
+ (*pBundle).newMessage (CellappInterface::reqTeleportOtherCB);
1569
+ (*pBundle) << teleportEntityID;
1570
+ (*pBundle) << success;
1571
+ pBundle->send (this ->getNetworkInterface (), pChannel);
1572
+ Mercury::Bundle::ObjPool ().reclaimObject (pBundle);
1573
+ }
1574
+ }
1575
+
1576
+ // -------------------------------------------------------------------------------------
1577
+ void Cellapp::reqTeleportOtherCB (Mercury::Channel* pChannel, MemoryStream& s)
1578
+ {
1579
+ ENTITY_ID nearbyMBRefID = 0 , teleportEntityID = 0 ;
1580
+ bool success;
1581
+
1582
+ s >> teleportEntityID >> success;
1583
+
1584
+ Entity* entity = Cellapp::getSingleton ().findEntity (teleportEntityID);
1585
+
1586
+ if (entity == NULL )
1587
+ {
1588
+ if (!success)
1589
+ {
1590
+ ERROR_MSG (boost::format (" Cellapp::reqTeleportOtherCB: not found reqTeleportEntity(%1%), lose entity!\n " ) % teleportEntityID);
1591
+ s.opfini ();
1592
+ return ;
1593
+ }
1594
+
1595
+ s.opfini ();
1596
+ }
1597
+
1598
+ // 传送成功, 我们销毁这个entity。
1599
+ if (success)
1600
+ {
1601
+ destroyEntity (teleportEntityID, false );
1602
+ return ;
1603
+ }
1604
+
1605
+ // 传送失败了, 我们需要重恢复entity
1606
+ Position3D pos;
1607
+ Direction3D dir;
1608
+ ENTITY_SCRIPT_UID entityType;
1609
+ SPACE_ID spaceID = 0 , lastSpaceID = 0 ;
1610
+
1611
+ s >> teleportEntityID >> nearbyMBRefID >> lastSpaceID >> spaceID;
1612
+ s >> entityType;
1613
+ s >> pos.x >> pos.y >> pos.z ;
1614
+ s >> dir.dir .x >> dir.dir .y >> dir.dir .z ;
1615
+
1616
+ entity->changeToReal (0 , s);
1617
+ entity->onTeleportFailure ();
1539
1618
}
1540
1619
1541
1620
// -------------------------------------------------------------------------------------
0 commit comments