Example #1
0
    // This will search for a mother entity to see it can satisfy its thirst from its mother, rather than a traditional water block.
    public static float GetEntityWater(int EntityID)
    {
        EntityAliveSDX myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAliveSDX;

        if (myEntity)
        {
            if (myEntity.Buffs.HasCustomVar("Mother"))
            {
                float          MotherID     = myEntity.Buffs.GetCustomVar("Mother");
                EntityAliveSDX MotherEntity = myEntity.world.GetEntity((int)MotherID) as EntityAliveSDX;
                if (MotherEntity)
                {
                    DisplayLog(" My Mother is: " + MotherEntity.EntityName);
                    if (MotherEntity.Buffs.HasCustomVar("MilkLevel"))
                    {
                        DisplayLog("Heading to mommy");
                        float MilkLevel = MotherEntity.Buffs.GetCustomVar("MilkLevel");
                        myEntity.SetInvestigatePosition(myEntity.world.GetEntity((int)MotherID).position, 60);
                        return(MilkLevel);
                    }
                }
            }
        }
        return(0f);
    }
Example #2
0
    public static bool ConsumeProduct(int EntityID, ItemValue item)
    {
        bool result = false;

        EntityAliveSDX myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAliveSDX;

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

        // No Item, no consumption
        if (item == null)
        {
            return(false);
        }


        DisplayLog(" ConsumeProduct() " + item.ItemClass.GetItemName());
        ItemClass original = myEntity.inventory.holdingItem;

        myEntity.inventory.SetBareHandItem(item);
        ItemAction itemAction = myEntity.inventory.holdingItem.Actions[0];

        if (itemAction != null)
        {
            myEntity.Attack(true);
            DisplayLog("ConsumeProduct(): Hold Item has Action0. Executing..");
            itemAction.ExecuteAction(myEntity.inventory.holdingItemData.actionData[0], true);

            //// We want to consume the food, but the consumption of food isn't supported on the non-players, so just fire off the buff
            ///
            DisplayLog("ConsumeProduct(): Trigger Events");
            myEntity.FireEvent(MinEventTypes.onSelfPrimaryActionEnd);
            myEntity.FireEvent(MinEventTypes.onSelfHealedSelf);


            myEntity.SetInvestigatePosition(Vector3.zero, 0);
        }

        DisplayLog(" ConsumeProduct(): Restoring hand item");
        myEntity.inventory.SetBareHandItem(ItemClass.GetItem(original.Name, false));

        return(result);
    }
Example #3
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);
    }