SHARE
TWEET

Untitled

a guest Aug 12th, 2017 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void MotionMaster::MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ)
  2. {
  3.     //this function may make players fall below map
  4.     /*if (i_owner->GetTypeId() == TYPEID_PLAYER)
  5.         return;*/
  6.  
  7.     float x, y, z;
  8.     float dist = speedXY * speedZ * 0.1f;
  9.     i_owner->GetNearPoint(i_owner, x, y, z, i_owner->GetObjectSize(), dist, i_owner->GetAngle(srcX, srcY) + M_PI);
  10.     MoveJump(x, y, z, speedXY, speedZ);
  11. }
  12.  
  13.  
  14. void WorldObject::GetNearPoint(WorldObject const* searcher, float &x, float &y, float &z, float searcher_size, float distance2d, float absAngle) const
  15. {
  16.     Position* pos = NULL;
  17.     // get coords before any operations
  18.     if (searcher && searcher->GetTypeId() == TYPEID_PLAYER)
  19.         searcher->GetPosition(pos);
  20.     GetNearPoint2D(x, y, distance2d + searcher_size, absAngle);
  21.     z = GetPositionZ();
  22.     UpdateGroundPositionZ(x, y, z);
  23.    
  24.     // Use additional calculations for players
  25.     // based on SPELL_EFFECT_LEAP code
  26.     // IsWithinLOS(x, y, z) isn't ideal
  27.     if (searcher && searcher->GetTypeId() == TYPEID_PLAYER && !IsWithinLOS(x, y, z))
  28.     {
  29.         //sLog->outError("WorldObject::GetNearPoint(start): x %f y %f z %f", x, y, z);      
  30.         float destx, desty, destz, ground, floor;
  31.         float dist = distance2d/* + searcher_size*/;
  32.         float orientation = absAngle, step = dist/10.0f;
  33.         Map const* map = searcher->GetMap();
  34.  
  35.         destx = x;
  36.         desty = y;
  37.         destz = z;
  38.  
  39.         // if enable this - floor detection will be broken
  40.         /*bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(searcher->GetMapId(), x1, y1, z1 + 0.5f, x, y, z + 0.5f, destx, desty, destz, -0.5f);
  41.  
  42.         if (col) // We had a collision!
  43.         {
  44.             destx -= 0.6 * cos(orientation);
  45.             desty -= 0.6 * sin(orientation);
  46.             dist = sqrt((x1-destx)*(x1-destx) + (y1-desty)*(y1-desty));
  47.             sLog->outError("WorldObject::GetNearPoint(collision): x %f y %f dist %f", destx, desty, dist);
  48.         }*/
  49.  
  50.         //sLog->outError("WorldObject::GetNearPoint(before cycle): x %f y %f z %f", destx, desty, destz);
  51.         for (int j = 0; j < 10; j++)
  52.         {
  53.             if (!IsWithinLOS(destx, desty, destz))
  54.             {
  55.                 destx -= step * cos(orientation);
  56.                 desty -= step * sin(orientation);
  57.                 ground = map->GetHeight(destx, desty, MAX_HEIGHT, true);
  58.                 floor = map->GetHeight(destx, desty, z, true);
  59.                 //sLog->outError("WorldObject::GetNearPoint(cycle floor z): %f", floor);
  60.                 destz = fabs(ground - z) <= fabs(floor - z) ? ground : floor;
  61.             } else break;
  62.             //sLog->outError("WorldObject::GetNearPoint(cycle): x %f y %f z %f", destx, desty, destz);
  63.         }
  64.  
  65.         x = destx;
  66.         y = desty;
  67.         z = destz/* + 0.15f*/;
  68.  
  69.         //sLog->outError("WorldObject::GetNearPoint(new): x %f y %f z %f", x, y, z);
  70.  
  71.         if (IsWithinLOS(x, y, z))
  72.         {
  73.             //sLog->outError("WorldObject::GetNearPoint: new coord are in LOS!");
  74.            
  75.             // In fake LOS (thin wall or not high ground), collision detector sucks
  76.             /*float x1, y1, z1;
  77.             searcher->GetPosition(x1, y1, z1);
  78.             bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(searcher->GetMapId(), x1, y1, z1 + 0.5f, x, y, z + 0.5f, x, y, z, -0.5f);
  79.  
  80.             if (col) // We had a collision!
  81.             {
  82.  
  83.                 //sLog->outError("WorldObject::GetNearPoint(before collision): x %f y %f z %f", x, y, z);
  84.                 x -= 0.6 * cos(orientation);
  85.                 y -= 0.6 * sin(orientation);
  86.                 z = map->GetHeight(x, y, z, true);
  87.                 //sLog->outError("WorldObject::GetNearPoint(collision): x %f y %f z %f", x, y, z);
  88.             }*/
  89.             return;
  90.         } else
  91.         {
  92.             // Fail at get good coords, don't move
  93.             x = searcher->GetPositionX();
  94.             y = searcher->GetPositionY();
  95.             z = searcher->GetPositionZ();          
  96.             //sLog->outError("WorldObject::GetNearPoint: new coords NOT are in LOS!");
  97.         }
  98.     }
  99. }
RAW Paste Data
Top