// Reads the buff and quest information
    public override void Read(byte _version, BinaryReader _br)
    {
        base.Read(_version, _br);
        strMyName    = _br.ReadString();
        QuestJournal = new QuestJournal();
        QuestJournal.Read(_br);
        PatrolCoordinates.Clear();
        String strPatrol = _br.ReadString();

        foreach (String strPatrolPoint in strPatrol.Split(';'))
        {
            Vector3 temp = ModGeneralUtilities.StringToVector3(strPatrolPoint);
            if (temp != Vector3.zero)
            {
                PatrolCoordinates.Add(temp);
            }
        }

        String strGuardPosition = _br.ReadString();

        GuardPosition     = ModGeneralUtilities.StringToVector3(strGuardPosition);
        factionId         = _br.ReadByte();
        GuardLookPosition = ModGeneralUtilities.StringToVector3(_br.ReadString());
        try
        {
            this.Buffs.Read(_br);
        }
        catch (Exception ex)
        {
            // fail safe to protect game saves
        }
    }
Beispiel #2
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);
    }
Beispiel #3
0
    public static Vector3 GetNewPositon(int EntityID, int maxBlocks = 30)
    {
        EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive;

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

        if (!EntityUtilities.CheckProperty(EntityID, "PathingBlocks"))
        {
            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)
            {
                // DisplayLog("No Blocks configured. Setting Default", __instance.theEntity);
                // Blocks.Add("PathingCube");
                return(result);
            }

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

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

        Vector3 newposition = SphereCache.GetRandomPath(EntityID);

        if (newposition == Vector3.zero)
        {
            return(result);
        }

        // Remove it from the cache.
        SphereCache.RemovePath(EntityID, newposition);

        result = GameManager.Instance.World.FindSupportingBlockPos(newposition);
        //Debug.Log("Position: " + result);
        // 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);
    }
    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;
            }
        }
    }
    public virtual bool CheckForProductionBuff()
    {
        if (!CheckIncentive(lstProductionBuffs))
        {
            return(false);
        }

        // If it's an egg producing entity, scan for a bed to hatch.
        if (theEntity.Buffs.HasBuff(strProductionFinishedBuff))
        {
            Vector3 TargetBlock = ModGeneralUtilities.ScanForBlockInList(this.theEntity.position, lstBeds, 20);
            if (TargetBlock != Vector3.zero)
            {
                theEntity.SetInvestigatePosition(TargetBlock, 120);
                return(true);
            }
        }
        return(false);
    }
    public virtual bool CheckForSanitation()
    {
        if (!CheckIncentive(lstSanitationBuffs))
        {
            return(false);
        }

        if (lstSanitation.Count > 0)
        {
            Vector3 TargetBlock = ModGeneralUtilities.ScanForBlockInList(this.theEntity.position, lstSanitation, 20);
            if (TargetBlock == Vector3.zero)
            {
                return(false);
            }

            theEntity.SetInvestigatePosition(TargetBlock, 120);
        }
        return(true);
    }
    // Scans for the water block in the area.
    public virtual bool CheckForHomeBlock()
    {
        if (lstHomeBlocks.Count == 0)
        {
            return(false);
        }

        Vector3 TargetBlock = ModGeneralUtilities.ScanForBlockInList(this.theEntity.position, lstHomeBlocks, 20);

        if (TargetBlock == Vector3.zero)
        {
            return(false);
        }

        Vector3i position;

        position.x = Utils.Fastfloor(TargetBlock.x);
        position.z = Utils.Fastfloor(TargetBlock.z);
        position.y = Utils.Fastfloor(TargetBlock.y);
        theEntity.setHomeArea(position, MaxDistance);
        return(true);
    }
    // Determines if this AI task can even start. This is based on the thirsty and hunger buffs
    public override bool CanExecute()
    {
        bool result = false;

        if (theEntity.IsSleeping)
        {
            return(false);
        }

        if (!CanContinue())
        {
            theEntity.SetInvestigatePosition(Vector3.zero, 0);
            return(false);
        }

        if (!theEntity.HasInvestigatePosition)
        {
            if (EntityUtilities.isEntityHungry(this.theEntity.entityId) &&
                ModGeneralUtilities.CheckForBin(this.theEntity.entityId, "Food"))
            {
                result = true;
            }

            if (EntityUtilities.isEntityThirsty(this.theEntity.entityId) &&
                ModGeneralUtilities.CheckForBin(this.theEntity.entityId, "Water"))
            {
                result = true;
            }

            if (EntityUtilities.isEntityHurt(this.theEntity.entityId) &&
                ModGeneralUtilities.CheckForBin(this.theEntity.entityId, "Health"))
            {
                result = true;
            }

            else if (CheckForProductionBuff())
            {
                result = true;
            }
            else if (CheckForShelter()) // Check for shelder.
            {
                result = true;
            }
            else
            {
                // check and see if you have a home block.
                CheckForHomeBlock();
                theEntity.SetInvestigatePosition(Vector3.zero, 0);
                result = false;
            }
        }

        // If We can continue, that means we've triggered the hunger or thirst buff. Investigate Position are set int he CheckFor.. methods
        // If we still don't have a position, then there's no food or water near by that satisfies our needs.
        if (result && theEntity.HasInvestigatePosition)
        {
            DisplayLog(" Investigate Pos: " + investigatePos + " Current Seek Time: " + investigateTicks + " Max Seek Time: " + theEntity.GetInvestigatePositionTicks() + " Seek Position: " + seekPos + " Target Block: " + theEntity.world.GetBlock(new Vector3i(investigatePos)).Block.GetBlockName());
            investigatePos = theEntity.InvestigatePosition;
            seekPos        = theEntity.world.FindSupportingBlockPos(investigatePos);
            return(true);
        }
        return(false);
    }