Ejemplo n.º 1
0
        public void setDamageDirection(GameBase sourceObject, TransformF damagePos)
        {
            if (sourceObject.isObject())
            {
                damagePos = console.isField(sourceObject, "initialPosition") ? new TransformF(sourceObject["initialPosition"]) : sourceObject.getTransform();
            }

            TransformF dp  = damagePos;
            Point3F    wbc = getWorldBoxCenter();

            TransformF damagevec = dp - new TransformF(wbc);

            damagevec = damagevec.normalizeSafe();

            GameConnection client = this["client"];

            if (!client.isObject())
            {
                return;
            }

            ShapeBase cameraobject = client.getCameraObject();

            TransformF inverseTransform = cameraobject.getInverseTransform();

            damagevec = math.MatrixMulVector(inverseTransform, damagevec.GetPosition());

            float[]  components = new float[6];
            string[] directions = new string[6];
            directions[0] = "Left";
            directions[1] = "Right";
            directions[2] = "Bottom";
            directions[3] = "Front";
            directions[4] = "Bottom";
            directions[5] = "Top";

            components[0] = -damagevec.mPositionX;
            components[1] = damagevec.mPositionX;
            components[2] = -damagevec.mPositionY;
            components[3] = damagevec.mPositionY;
            components[4] = -damagevec.mPositionZ;
            components[5] = damagevec.mPositionZ;
            string damagedirection = string.Empty;
            float  max             = 0;

            for (int i = 0; i < 6; i++)
            {
                if (components[i] <= max)
                {
                    continue;
                }
                damagedirection = directions[i];
                max             = components[i];
            }

            if (console.isObject(client))
            {
                // Util._commandToClient(client, console.addTaggedString("setDamageDirection"), damagedirection);
                console.commandToClient(client, console.addTaggedString("setDamageDirection"), new[] { damagedirection });
            }
        }