public void CheckSurroundingEntities(EntityAliveSDX questNPC, EntityPlayer player)
    {
        List <Entity> NearbyEntities = new List <Entity>();
        Bounds        bb             = new Bounds(questNPC.position, new Vector3(questNPC.GetSeeDistance(), 20f, questNPC.GetSeeDistance()));

        questNPC.world.GetEntitiesInBounds(typeof(EntityAliveSDX), bb, NearbyEntities);
        for (int i = NearbyEntities.Count - 1; i >= 0; i--)
        {
            EntityAliveSDX x = (EntityAliveSDX)NearbyEntities[i];
            if (x != questNPC && x.IsAlive())
            {
                if (x.Buffs.HasCustomVar("Leader") && x.Buffs.GetCustomVar("Leader") == (float)questNPC.entityId)
                {
                    EntityUtilities.SetOwner(x.entityId, player.entityId);
                }
            }
        }
    }
Example #2
0
    public static bool CheckForBin(int EntityID, String StatType)
    {
        EntityAliveSDX myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAliveSDX;

        if (!myEntity)
        {
            return(false);
        }


        DisplayLog(myEntity.entityId + " CheckForBin() " + StatType);
        // There is too many values that we need to read in from the entity, so we'll read them directly from the entityclass
        EntityClass entityClass = EntityClass.list[myEntity.entityClass];

        List <String> lstContainers = new List <String>();
        List <String> lstItems      = new List <String>();

        switch (StatType)
        {
        case "Food":
            // If it isn't hungry, don't look for food.
            if (!EntityUtilities.isEntityHungry(EntityID))
            {
                return(false);
            }

            lstContainers = ConfigureEntityClass("FoodBins", entityClass);
            lstItems      = ConfigureEntityClass("FoodItems", entityClass);
            break;

        case "Water":

            if (!EntityUtilities.isEntityThirsty(EntityID))
            {
                return(false);
            }

            lstContainers = ConfigureEntityClass("WaterBins", entityClass);
            lstItems      = ConfigureEntityClass("WaterItems", entityClass);
            break;

        case "Health":
            if (!EntityUtilities.isEntityHurt(EntityID))
            {
                return(false);
            }

            DisplayLog("CheckForBin(): Health Items not implemented");
            return(false);

        default:
            DisplayLog("CheckForBin(): Default is not implemented");
            return(false);
        }
        ;

        // Checks the Entity's backpack to see if it can meet its needs there.
        ItemValue item   = CheckContents(myEntity.lootContainer, lstItems, StatType);
        bool      result = ConsumeProduct(EntityID, item);

        if (result)
        {
            DisplayLog("CheckForBin(): Found Item in my Back pack: " + item.ItemClass.GetItemName());
            return(false);  // If we found something to consume, don't bother looking further.
        }
        // If the entity already has an investigative position, check to see if we are close enough for it.
        if (myEntity.HasInvestigatePosition)
        {
            DisplayLog(" CheckForBin(): Has Investigative position. Checking distance to bin");
            float sqrMagnitude2 = (myEntity.InvestigatePosition - myEntity.position).sqrMagnitude;
            if (sqrMagnitude2 <= 4f)
            {
                DisplayLog(" CheckForBin(): I am close to a bin.");
                Vector3i   blockLocation = new Vector3i(myEntity.InvestigatePosition.x, myEntity.InvestigatePosition.y, myEntity.InvestigatePosition.z);
                BlockValue checkBlock    = myEntity.world.GetBlock(blockLocation);
                DisplayLog(" CheckForBin(): Target Block is: " + checkBlock);
                TileEntityLootContainer myTile = myEntity.world.GetTileEntity(0, blockLocation) as TileEntityLootContainer;
                if (myTile != null)
                {
                    item = CheckContents(myTile, lstItems, StatType);
                    if (item != null)
                    {
                        DisplayLog("CheckForBin() I retrieved: " + item.ItemClass.GetItemName());
                    }
                    result = ConsumeProduct(EntityID, item);
                    DisplayLog(" Did I consume? " + result);
                    return(result);
                }
            }
            return(false);
        }

        DisplayLog(" Scanning For " + StatType);
        Vector3 TargetBlock = ScanForBlockInList(myEntity.position, lstContainers, Utils.Fastfloor(myEntity.GetSeeDistance()));

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

        DisplayLog(" Setting Target:" + GameManager.Instance.World.GetBlock(new Vector3i(TargetBlock)).Block.GetBlockName());
        myEntity.SetInvestigatePosition(TargetBlock, 120);
        return(true);
    }