コード例 #1
0
    public static Vector3 GetNewPositon(int EntityID, bool Random = false)
    {
        EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive;

        if (myEntity == null)
        {
            return(Vector3.zero);
        }


        Vector3        result = Vector3.zero;
        List <Vector3> Paths  = SphereCache.GetPaths(EntityID);

        if (Paths == null || Paths.Count == 0)
        {
            //  Grab a list of blocks that are configured for this class.
            //    <property name="PathingBlocks" value="PathingCube" />
            List <string> Blocks = EntityUtilities.ConfigureEntityClass(EntityID, "PathingBlocks");
            if (Blocks.Count == 0)
            {
                Blocks.Add("PathingCube");
            }

            //Scan for the blocks in the area
            List <Vector3> PathingVectors = ModGeneralUtilities.ScanForTileEntityInChunksListHelper(myEntity.position, Blocks, EntityID);
            if (PathingVectors == null || PathingVectors.Count == 0)
            {
                return(result);
            }

            //Add to the cache
            SphereCache.AddPaths(EntityID, PathingVectors);
        }

        // Finds the closet block we matched with.
        Vector3 tMin = new Vector3();

        if (Random)
        {
            tMin = SphereCache.GetRandomPath(EntityID);
        }
        else
        {
            tMin = ModGeneralUtilities.FindNearestBlock(myEntity.position, SphereCache.GetPaths(EntityID));
            if (tMin == Vector3.zero)
            {
                return(tMin);
            }
        }
        // Remove it from the cache.
        SphereCache.RemovePath(EntityID, tMin);

        result = GameManager.Instance.World.FindSupportingBlockPos(tMin);
        // Center the pathing position.
        result.x = (float)Utils.Fastfloor(result.x) + 0.5f;
        result.y = (float)Utils.Fastfloor(result.y) + 0.5f;
        result.z = (float)Utils.Fastfloor(result.z) + 0.5f;
        return(result);
    }
コード例 #2
0
    public void SetupAutoPathingBlocks()
    {
        if (this.Buffs.HasCustomVar("PathingCode"))
        {
            return;
        }

        // Check if pathing blocks are defined.
        List <string> Blocks = EntityUtilities.ConfigureEntityClass(this.entityId, "PathingBlocks");

        if (Blocks.Count == 0)
        {
            Blocks = new List <string>()
            {
                "PathingCube"
            }
        }
        ;

        //Scan for the blocks in the area
        List <Vector3> PathingVectors = ModGeneralUtilities.ScanForTileEntityInChunksListHelper(this.position, Blocks, this.entityId);

        if (PathingVectors == null || PathingVectors.Count == 0)
        {
            return;
        }

        // Find the nearest block, and if its a sign, read its code.
        Vector3        target         = ModGeneralUtilities.FindNearestBlock(this.position, PathingVectors);
        TileEntitySign tileEntitySign = GameManager.Instance.World.GetTileEntity(0, new Vector3i(target)) as TileEntitySign;

        if (tileEntitySign == null)
        {
            return;
        }

        // Since signs can have multiple codes, splite with a ,, parse each one.
        String text = tileEntitySign.GetText();
        float  code = 0f; // Defined here as DMT compiler doesn't like inlining it.

        foreach (String temp in text.Split(','))
        {
            if (StringParsers.TryParseFloat(temp, out code))
            {
                this.Buffs.AddCustomVar("PathingCode", code);
                return;
            }
        }
    }