Example #1
0
    public override bool checkProceduralPrecondition(GameObject agent, BlackBoard bb)
    {
        // find the nearest rock that we can mine
        IronRockComponent[] rocks   = bb.GetData("ironRock") as IronRockComponent[];
        IronRockComponent   closest = null;
        float closestDist           = 0;

        foreach (IronRockComponent rock in rocks)
        {
            if (closest == null)
            {
                // first one, so choose it for now
                closest     = rock;
                closestDist = (rock.gameObject.transform.position - agent.transform.position).magnitude;
            }
            else
            {
                // is this one closer than the last?
                float dist = (rock.gameObject.transform.position - agent.transform.position).magnitude;
                if (dist < closestDist)
                {
                    // we found a closer one, use it
                    closest     = rock;
                    closestDist = dist;
                }
            }
        }
        targetRock = closest;
        target     = targetRock.gameObject;

        return(closest != null);
    }
Example #2
0
    /// <summary>
    /// 执行
    /// 如果操作成功执行则返回True,否则返回false,
    /// 如果发生了什么事,它就再也无法执行了。 在这种情况下
    /// 行动队列应清除,无法达到目标。</summary>
    /// <param name="agent"></param>
    /// <param name="bb"></param>
    /// <returns></returns>
    /// <exception cref="System.NotImplementedException"></exception>
    public override bool Perform(GameObject agent, BlackBoard bb)
    {
        if (startTime == 0)
        {
            startTime = Time.time;
        }

        if (Time.time - startTime > workDuration)
        {
            //
            Backpack backpack = (Backpack)bb.GetData("backpack");
            //增加背包中的数量
            backpack.stoneNum += 5;
            //完成
            isComplete = true;
            ToolComponent tool = backpack.tool.GetComponent <ToolComponent>();
            //减少工具耐久度
            tool.use(0.34f);
            //耐久度小于等于0销毁当前工具
            if (tool.destroyed())
            {
                Destroy(backpack.tool);
                backpack.tool = null;
            }
        }
        return(true);
    }
Example #3
0
 public override bool checkProceduralPrecondition(GameObject agent, BlackBoard bb)
 {
     CampComponent[] c = bb.GetData("camp") as CampComponent[];
     if (c == null || c.Length <= 0)
     {
         return(false);
     }
     camp   = c[0];
     target = camp.gameObject;
     return(camp != null);
 }
Example #4
0
    public override bool perform(GameObject agent, BlackBoard bb)
    {
        if (startTime == 0)
        {
            startTime = Time.time;
        }

        if (Time.time - startTime > workDuration)
        {
            // finished chopping
            Brain brain = bb.GetData("brain") as Brain;
            brain.Mind += 50;
            sleeped     = true;
        }
        return(true);
    }
Example #5
0
    /// <summary>
    /// 检查程序前提条件
    /// </summary>
    /// <param name="agent"></param>
    /// <param name="bb"></param>
    /// <returns></returns>
    public override bool CheckProceduralPrecondition(GameObject agent, BlackBoard bb)
    {
        Warehouse[] warehouse        = (Warehouse[])bb.GetData("Warehouse");
        Warehouse   closestWarehouse = null;
        //最近的距离
        float closestDist = 0;

        foreach (Warehouse item in warehouse)
        {
            if (item.toolNum > 0)
            {
                //
                if (closestWarehouse == null)
                {
                    closestWarehouse = item;
                    //计算到达当前仓库的距离
                    closestDist = (item.gameObject.transform.position - agent.transform.position).magnitude;
                }
                else
                {
                    //计算到达当前仓库的距离
                    float dist = (item.gameObject.transform.position - agent.transform.position).magnitude;
                    //如果当前仓库的距离小于上一个仓库的距离 就说明当前仓库更近
                    if (dist < closestDist)
                    {
                        closestWarehouse = item;
                        closestDist      = dist;
                    }
                }
            }
        }
        if (closestWarehouse == null)
        {
            return(false);
        }

        targetWarehouse = closestWarehouse;
        //设置目标
        target = closestWarehouse.gameObject;

        return(closestWarehouse != null);
    }
Example #6
0
    /// <summary>
    /// 检查程序前提条件
    /// </summary>
    /// <param name="agent"></param>
    /// <param name="bb"></param>
    /// <returns></returns>
    public override bool CheckProceduralPrecondition(GameObject agent, BlackBoard bb)
    {
        // find the nearest supply pile that has spare tools
        //找到最近的有备用工具的供应堆
        SupplyPileComponent[] supplyPiles = (SupplyPileComponent[])bb.GetData("supplyPiles");
        SupplyPileComponent   closest     = null;
        float closestDist = 0;

        foreach (SupplyPileComponent supply in supplyPiles)
        {
            if (closest == null)
            {
                // first one, so choose it for now
                //第一个,所以现在选择它
                closest     = supply;
                closestDist = (supply.gameObject.transform.position - agent.transform.position).magnitude;
            }
            else
            {
                // is this one closer than the last?
                //这个比最后一个更近吗?
                float dist = (supply.gameObject.transform.position - agent.transform.position).magnitude;
                if (dist < closestDist)
                {
                    // we found a closer one, use it
                    //我们找到了一个更近的,使用它
                    closest     = supply;
                    closestDist = dist;
                }
            }
        }
        if (closest == null)
        {
            return(false);
        }

        targetSupplyPile = closest;
        target           = targetSupplyPile.gameObject;

        return(closest != null);
    }
Example #7
0
    /// <summary>
    /// 检查程序前提条件
    /// </summary>
    /// <param name="agent"></param>
    /// <param name="bb"></param>
    /// <returns></returns>
    public override bool CheckProceduralPrecondition(GameObject agent, BlackBoard bb)
    {
        // find the nearest tree that we can chop
        //找到我们能砍掉的最近的树
        AppleTreeComponet[] trees   = (AppleTreeComponet[])bb.GetData("appleTree");
        AppleTreeComponet   closest = null;
        float closestDist           = 0;

        foreach (AppleTreeComponet tree in trees)
        {
            if (closest == null)
            {
                // first one, so choose it for now
                //第一个,现在就选择它
                closest     = tree;
                closestDist = (tree.gameObject.transform.position - agent.transform.position).magnitude;
            }
            else
            {
                // is this one closer than the last?
                //这个比最后一个更近吗?
                float dist = (tree.gameObject.transform.position - agent.transform.position).magnitude;
                if (dist < closestDist)
                {
                    // we found a closer one, use it
                    //我们找到了一个更近的,用它
                    closest     = tree;
                    closestDist = dist;
                }
            }
        }
        if (closest == null)
        {
            return(false);
        }

        targetAppleTree = closest;
        target          = targetAppleTree.gameObject;

        return(closest != null && closest.AppleNum > 0);
    }
Example #8
0
    public override bool CheckProceduralPrecondition(GameObject agent, BlackBoard bb)
    {
        WolfDen[] dens        = bb.GetData("wolfDen") as WolfDen[];
        WolfDen   closest     = null;
        float     closestDist = 0;

        foreach (WolfDen den in dens)
        {
            if (den.WolfNum <= 0)
            {
                continue;
            }
            if (closest == null)
            {
                // first one, so choose it for now
                closest     = den;
                closestDist = (den.gameObject.transform.position - agent.transform.position).magnitude;
            }
            else
            {
                // is this one closer than the last?
                float dist = (den.gameObject.transform.position - agent.transform.position).magnitude;
                if (dist < closestDist)
                {
                    // we found a closer one, use it
                    closest     = den;
                    closestDist = dist;
                }
            }
        }
        if (closest == null)
        {
            return(false);
        }

        targetWolf = closest;
        target     = targetWolf.gameObject;

        return(closest != null);
    }
Example #9
0
    public override bool CheckProceduralPrecondition(GameObject agent, BlackBoard bb)
    {
        // find the nearest supply pile that has spare ores
        SupplyPileComponent[] supplyPiles = (SupplyPileComponent[])bb.GetData("supplyPiles");
        SupplyPileComponent   closest     = null;
        float closestDist = 0;

        foreach (SupplyPileComponent supply in supplyPiles)
        {
            if (supply.numOre >= 3)               // we need to take 3 ore
            {
                if (closest == null)
                {
                    // first one, so choose it for now
                    closest     = supply;
                    closestDist = (supply.gameObject.transform.position - agent.transform.position).magnitude;
                }
                else
                {
                    // is this one closer than the last?
                    float dist = (supply.gameObject.transform.position - agent.transform.position).magnitude;
                    if (dist < closestDist)
                    {
                        // we found a closer one, use it
                        closest     = supply;
                        closestDist = dist;
                    }
                }
            }
        }
        if (closest == null)
        {
            return(false);
        }

        targetSupplyPile = closest;
        target           = targetSupplyPile.gameObject;

        return(closest != null);
    }
Example #10
0
    /// <summary>
    /// 程序检查此操作是否可以运行。 并非所有行动
    /// 需要这个,但有些可能。
    /// </summary>
    /// <param name="agent"></param>
    /// <param name="bb"></param>
    /// <returns></returns>
    /// <exception cref="System.NotImplementedException"></exception>
    /// <inheritdoc />
    public override bool CheckProceduralPrecondition(GameObject agent, BlackBoard bb)
    {
        //获取任务目标点
        Mining[] taskTargetPoint = (Mining[])bb.GetData("Mining");
        //最近的目标
        Mining closest = null;
        //距离
        float closestDist = 0;

        foreach (Mining target in taskTargetPoint)
        {
            if (closest == null)
            {
                closest = target;
                //计算到达目标的距离
                closestDist = (target.gameObject.transform.position - agent.transform.position).magnitude;
            }
            else
            {
                //计算到达目标的距离
                float dist = (target.gameObject.transform.position - agent.transform.position).magnitude;

                if (dist < closestDist)
                {
                    closest     = target;
                    closestDist = dist;
                }
            }
        }
        if (closest == null)
        {
            return(false);
        }

        currentTaskTarget = closest;
        target            = currentTaskTarget.gameObject;

        return(closest != null);
    }
Example #11
0
    /// <summary>
    /// 检测工作前提
    /// </summary>
    /// <param name="agent"></param>
    /// <param name="bb"></param>
    /// <returns></returns>
    public override bool CheckProceduralPrecondition(GameObject agent, BlackBoard bb)
    {
        //获取所有树木
        Trees[] blocks = (Trees[])bb.GetData("Tree");
        //最近的树木
        Trees closest = null;
        //距离
        float closestDist = 0;

        foreach (Trees block in blocks)
        {
            if (closest == null)
            {
                closest = block;
                //计算距离
                closestDist = (block.gameObject.transform.position - agent.transform.position).magnitude;
            }
            else
            {
                //计算距离
                float dist = (block.gameObject.transform.position - agent.transform.position).magnitude;
                //当前距离小于上一个树木
                if (dist < closestDist)
                {
                    closest     = block;
                    closestDist = dist;
                }
            }
        }
        if (closest == null)
        {
            return(false);
        }

        targetTrees = closest;
        target      = targetTrees.gameObject;

        return(closest != null);
    }
Example #12
0
    public override bool Perform(GameObject agent, BlackBoard bb)
    {
        if (startTime == 0)
        {
            startTime = Time.time;
        }

        if (Time.time - startTime > workDuration)
        {
            // finished chopping
            BackpackComponent backpack = (BackpackComponent)bb.GetData("backpack");
            backpack.numFirewood += 5;
            chopped = true;
            ToolComponent tool = backpack.tool.GetComponent(typeof(ToolComponent)) as ToolComponent;
            tool.use(0.34f);
            if (tool.destroyed())
            {
                Destroy(backpack.tool);
                backpack.tool = null;
            }
        }
        return(true);
    }
Example #13
0
    public override bool CheckProceduralPrecondition(GameObject agent, BlackBoard bb)
    {
        // find the nearest forge
        ForgeComponent[] forges      = (ForgeComponent[])bb.GetData("forge");
        ForgeComponent   closest     = null;
        float            closestDist = 0;

        foreach (ForgeComponent forge in forges)
        {
            if (closest == null)
            {
                // first one, so choose it for now
                closest     = forge;
                closestDist = (forge.gameObject.transform.position - agent.transform.position).magnitude;
            }
            else
            {
                // is this one closer than the last?
                float dist = (forge.gameObject.transform.position - agent.transform.position).magnitude;
                if (dist < closestDist)
                {
                    // we found a closer one, use it
                    closest     = forge;
                    closestDist = dist;
                }
            }
        }
        if (closest == null)
        {
            return(false);
        }

        targetForge = closest;
        target      = targetForge.gameObject;

        return(closest != null);
    }
Example #14
0
    public override bool CheckProceduralPrecondition(GameObject agent, BlackBoard bb)
    {
        // find the nearest chopping block that we can chop our wood at
        ChoppingBlockComponent[] blocks  = (ChoppingBlockComponent[])bb.GetData("choppingBlock");
        ChoppingBlockComponent   closest = null;
        float closestDist = 0;

        foreach (ChoppingBlockComponent block in blocks)
        {
            if (closest == null)
            {
                // first one, so choose it for now
                closest     = block;
                closestDist = (block.gameObject.transform.position - agent.transform.position).magnitude;
            }
            else
            {
                // is this one closer than the last?
                float dist = (block.gameObject.transform.position - agent.transform.position).magnitude;
                if (dist < closestDist)
                {
                    // we found a closer one, use it
                    closest     = block;
                    closestDist = dist;
                }
            }
        }
        if (closest == null)
        {
            return(false);
        }

        targetChoppingBlock = closest;
        target = targetChoppingBlock.gameObject;

        return(closest != null);
    }