Example #1
0
 private void GetVectorPosition(_Vector3 vOrig, _Vector3 vDest, float fDis, ref _Vector3 vResult)
 {
     vResult = vDest - vOrig;
     vResult.Magnitude();
     vResult.Normalize();
     vResult *= fDis;
     vResult += vOrig;
 }
Example #2
0
 private float GetDistance(_Vector3 vStart, _Vector3 vEnd) => (vStart - vEnd).Magnitude();
Example #3
0
        private bool RandomMove()
        {
            m_fSecForMetor = m_sSpeed1;

            //if (GetMap() == null
            //    || m_bySearchRange == 0
            //    || m_byMoveType == 0)
            //    //|| !GetUserInView()
            //    // 4 means non-moving.
            //   // || m_byMoveType == 4)
            //    return false;
            m_byMoveType = 1;
            float fDestX = -1.0f, fDestZ = -1.0f;
            int   max_xx = GetMap().GetMapSize();
            int   max_zz = GetMap().GetMapSize();
            int   x = 0, y = 0;

            _Vector3 vStart = new _Vector3(), vEnd = new _Vector3(), vNewPos = new _Vector3();
            float    fDis = 0.0f;
            int      nPathCount = 0;
            int      random_x = 0, random_z = 0;

            if (m_byMoveType == 1 || m_byMoveType == 2 || m_byMoveType == 5)
            {
                random_x = myrand((int)-m_sSpeed1, (int)m_sSpeed1);
                random_z = myrand((int)-m_sSpeed1, (int)m_sSpeed1);

                switch (m_iPattenFrame)
                {
                case -4:
                    fDestX         = GetX() + m_pPattenPos.x - (float)random_x;
                    fDestZ         = GetZ() + m_pPattenPos.z - (float)random_z;
                    m_iPattenFrame = 0;
                    break;

                case -3:
                    fDestX = GetX() + m_pPattenPos.x - (float)random_x;
                    fDestZ = GetZ() + m_pPattenPos.z - (float)random_z;
                    m_iPattenFrame--;
                    break;

                case -2:
                    fDestX = GetX() + m_pPattenPos.x + (float)random_x;
                    fDestZ = GetZ() + m_pPattenPos.z + (float)random_z;
                    m_iPattenFrame--;
                    break;

                case -1:
                    fDestX = GetX() + m_pPattenPos.x + (float)random_x;
                    fDestZ = GetZ() + m_pPattenPos.z + (float)random_z;
                    m_iPattenFrame--;
                    break;

                case 0:
                {
                    switch (m_byMoveType)
                    {
                    case 1:
                        fDestX         = (short)m_nInitX;
                        fDestZ         = (short)m_nInitZ;
                        m_iPattenFrame = myrand(-1, 1);
                        break;

                    case 2:
                        // fDestX = (float)m_PathList.pPattenPos[m_sPathCount].x + m_fBattlePos_x;
                        // fDestZ = (float)m_PathList.pPattenPos[m_sPathCount].z + m_fBattlePos_z;

                        if (m_sPathCount++ >= m_sMaxPathCount)
                        {
                            m_sPathCount = 0;
                        }
                        break;
                    }
                }
                break;

                case 1:
                    fDestX = GetX() + m_pPattenPos.x + (float)random_x;
                    fDestZ = GetZ() + m_pPattenPos.z + (float)random_z;
                    m_iPattenFrame++;
                    break;

                case 2:
                    fDestX = GetX() + m_pPattenPos.x + (float)random_x;
                    fDestZ = GetZ() + m_pPattenPos.z + (float)random_z;
                    m_iPattenFrame++;
                    break;

                case 3:
                    fDestX = GetX() + m_pPattenPos.x - (float)random_x;
                    fDestZ = GetZ() + m_pPattenPos.z - (float)random_z;
                    m_iPattenFrame++;
                    break;

                case 4:
                    fDestX         = GetX() + m_pPattenPos.x - (float)random_x;
                    fDestZ         = GetZ() + m_pPattenPos.z - (float)random_z;
                    m_iPattenFrame = 0;
                    break;
                }

                vStart = new _Vector3(GetX(), GetY(), GetZ());
                vEnd   = new _Vector3(fDestX, 0, fDestZ);
                fDis   = GetDistance(vStart, vEnd);
                GetVectorPosition(vStart, vEnd, m_fSecForMetor, ref vNewPos);
            }

            /*else if (m_byMoveType == 3)
             *      {
             *              if (m_sPathCount == m_sMaxPathCount)
             *              {
             *                      m_byMoveType = 0;
             *                      m_sPathCount = 0;
             *                      return false;
             *              }
             *
             *              if (m_sPathCount != 0 && IsInPathRange() == false)
             *              {
             *                      m_sPathCount--;
             *                      nPathCount = GetNearPathPoint();
             *                      if (nPathCount  == -1)
             *                      {
             *                              TRACE("##### RandomMove Fail : [nid = %d, sid=%d], path = %d/%d, À̵¿ÇÒ ¼ö ÀÖ´Â °Å¸®¿¡¼­ ³Ê¹« ¸Ö¾îÁ³´ç,, ¾îÄÉÇØ #####\n", GetID(), GetProtoID(), m_sPathCount, m_sMaxPathCount);
             *                              vStart.Set(GetX(), GetY(), GetZ());
             *                              fDestX = (float)m_PathList.pPattenPos[0].x + m_fBattlePos_x;
             *                              fDestZ = (float)m_PathList.pPattenPos[0].z + m_fBattlePos_z;
             *                              vEnd.Set(fDestX, 0, fDestZ);
             *                              GetVectorPosition(vStart, vEnd, m_fSecForMetor, &vNewPos);
             *                              fDestX = vNewPos.x;
             *                              fDestZ = vNewPos.z;
             *                      }
             *                      else
             *                      {
             *                              if (nPathCount < 0)
             *                                      return false;
             *
             *                              fDestX = (float)m_PathList.pPattenPos[nPathCount].x + m_fBattlePos_x;
             *                              fDestZ = (float)m_PathList.pPattenPos[nPathCount].z + m_fBattlePos_x;
             *                              m_sPathCount = nPathCount;
             *                      }
             *              }
             *              else
             *              {
             *                      if (m_sPathCount < 0)
             *                              return false;
             *
             *                      fDestX = (float)m_PathList.pPattenPos[m_sPathCount].x + m_fBattlePos_x;
             *                      fDestZ = (float)m_PathList.pPattenPos[m_sPathCount].z + m_fBattlePos_x;
             *              }
             *
             *              m_sPathCount++;
             *      }*/

            vStart.Set(GetX(), 0.0f, GetZ());
            vEnd.Set(fDestX, 0.0f, fDestZ);
            if (GetX() < 0 || GetZ() < 0 || fDestX < 0 || fDestZ < 0)
            {
                return(false);
            }

            int mapWidth = 2048;// (int)(max_xx * GetMap().GetUnitDistance());

            if (GetX() >= mapWidth || GetZ() >= mapWidth || fDestX >= mapWidth || fDestZ >= mapWidth)
            {
                return(false);
            }

            fDis = GetDistance(vStart, vEnd);
            if (fDis > 200)
            {
                if (m_byMoveType == 2 || m_byMoveType == 3)
                {
                    if (--m_sPathCount <= 0)
                    {
                        m_sPathCount = 0;
                    }
                }

                //TRACE("##### RandomMove Fail : NPC_MAX_MOVE_RANGE overflow  .. [nid = %d, name=%s], cur_x=%.2f, z=%.2f, dest_x=%.2f, dest_z=%.2f, fDis=%.2f#####\n", GetID(), GetName().c_str(), GetX(), GetZ(), fDestX, fDestZ, fDis);
                return(false);
            }

            if (fDis <= m_fSecForMetor)
            {
                // ClearPathFindData();
                m_fStartPoint_X = GetX();
                m_fStartPoint_Y = GetZ();
                m_fEndPoint_X   = fDestX;
                m_fEndPoint_Y   = fDestZ;
                //    m_bPathFlag = true;
                //    m_iAniFrameIndex = 1;
                //    m_pPoint[0].fXPos = m_fEndPoint_X;
                //    m_pPoint[0].fZPos = m_fEndPoint_Y;
                return(true);
            }

            float fTempRange = (float)fDis + 2;
            int   min_x      = (int)(GetX() - fTempRange) / TILE_SIZE; if (min_x < 0)
            {
                min_x = 0;
            }
            int min_z = (int)(GetZ() - fTempRange) / TILE_SIZE; if (min_z < 0)
            {
                min_z = 0;
            }
            int max_x = (int)(GetX() + fTempRange) / TILE_SIZE; if (max_x >= max_xx)
            {
                max_x = max_xx - 1;
            }
            int max_z = (int)(GetZ() + fTempRange) / TILE_SIZE; if (min_z >= max_zz)
            {
                min_z = max_zz - 1;
            }

            CPoint start = new CPoint(), end = new CPoint();

            start.x = (int)(GetX() / TILE_SIZE) - min_x;
            start.y = (int)(GetZ() / TILE_SIZE) - min_z;
            end.x   = (int)(fDestX / TILE_SIZE) - min_x;
            end.y   = (int)(fDestZ / TILE_SIZE) - min_z;

            if (start.x < 0 || start.y < 0 || end.x < 0 || end.y < 0)
            {
                return(false);
            }

            m_fStartPoint_X = GetX();
            m_fStartPoint_Y = GetZ();
            m_fEndPoint_X   = fDestX;
            m_fEndPoint_Y   = fDestZ;

            m_min_x = min_x;
            m_min_y = min_z;
            m_max_x = max_x;
            m_max_y = max_z;

            return(PathFind(start, end, m_fSecForMetor) == 1);;
        }
Example #4
0
        public static _Vector3 operator /(_Vector3 value1, float value2)
        {
            _Vector3 SumVector = new _Vector3(value1.x / value2, value1.y / value2, value1.z / value2);

            return(SumVector);
        }
Example #5
0
        public static _Vector3 operator /(_Vector3 left, _Vector3 right)
        {
            _Vector3 SumVector = new _Vector3(left.x / right.x, left.y / right.y, left.z / right.z);

            return(SumVector);
        }
Example #6
0
        public static _Vector3 operator *(_Vector3 left, float right)
        {
            _Vector3 SumVector = new _Vector3(left.x * right, left.y * right, left.z * right);

            return(SumVector);
        }
Example #7
0
        public static _Vector3 operator *(float left, _Vector3 right)
        {
            _Vector3 SumVector = new _Vector3(left * right.x, left * right.y, left * right.z);

            return(SumVector);
        }