hds.npc.generatePathTable C# (CSharp) Method

generatePathTable() public method

public generatePathTable ( ) : int
return int
        public int generatePathTable()
        {
            // We firs test this with just one moove from point x to y
            // To calc this we need to know the time the object needs to reach this point,
            // the new point and the rotation to calc pretty to sync client and server position is right
            // to get a smooth walking :)
            Maths math = new Maths();

            // First choose a new pos in the range
            LtVector3f newPos = math.RandomPointOnCircle((float)xBase,(float)yBase, (float)zBase, 5.0f * 100);
            Output.WriteDebugLog("Mob Goes from X: " + this.getXPos() + " , Z: " + this.getZPos() + " to X: " + newPos.a + ", Z: " + newPos.c);

            double xNew = (double)newPos.a;
            double zNew = (double)newPos.c;

            this.destination = newPos;
            // Try to calculate rotation

            // Oh this seems to match ...needs more testing later when we fixed random pos

            double yaw = Math.Atan((double)(xNew - getXPos()) / (zNew - getZPos()))*128/Math.PI;

            double calcRotation = Math.Atan2(Math.Cos(xNew), Math.Sin(zNew) * Math.Sin(zNew)) * 128/Math.PI;

            double testRot = Math.Atan2(xNew, zNew) * 180 / Math.PI;
            double testRot2 = Math.Atan2(xNew, zNew) * 128 / Math.PI;

            Output.WriteDebugLog("Test Rot with 360 : " + testRot.ToString() + "| 255 : " + testRot2.ToString() + " AND THE YAW: " + yaw.ToString() + " (Cast to uint16 : " + Convert.ToInt16(yaw).ToString() + " )");

            int yawVal = (int)Convert.ToInt16(yaw);

            if (zNew < this.getZPos() || xNew < this.getXPos())
            {
                Output.WriteDebugLog("Need to adjust YAW + 128 from :" + yawVal.ToString() + " to: " + (yawVal + 128).ToString());
                yawVal = yawVal + 128;
            }
            else
            {
                Output.WriteDebugLog("Need to adjust YAW - 128 from :" + yawVal.ToString() + " to: " + (yawVal - 128).ToString());
                yawVal = yawVal - 128;
            }

            Output.WriteDebugLog("YAW VAL :" + yawVal.ToString() );

            this.rotation = (ushort)yawVal;
            Output.WriteDebugLog("Calc Rotation : " + calcRotation.ToString() + " and to UINT : " + (uint)calcRotation);

            // Calculate the distance for seconds to move
            int requiredSeconds = (int)(((math.distance2Coords((float)xPos, (float)xNew, (float)zPos, (float)zNew) / 0.176) / 500) * 0.9586);
            return requiredSeconds;
        }