Example #1
0
    private StoneComponent getNearestStoneComponent(Vector3 currentPosition)
    {
        StoneComponent[] stoneComponents = (StoneComponent[])UnityEngine.GameObject.FindObjectsOfType(typeof(StoneComponent));
        StoneComponent   closest         = null;
        float            closestDist     = 0;

        foreach (StoneComponent stoneComponent in stoneComponents)
        {
            if (stoneComponent.PiecesAvailable == 0)
            {
                continue;
            }

            if (closest == null)
            {
                closest     = stoneComponent;
                closestDist = (stoneComponent.gameObject.transform.position - currentPosition).magnitude;
            }
            else
            {
                float dist = (stoneComponent.gameObject.transform.position - currentPosition).magnitude;
                if (dist < closestDist)
                {
                    closest     = stoneComponent;
                    closestDist = dist;
                }
            }
        }

        return(closest);
    }
        public int ValidStone(int companyId, StoneComponent sc)
        {
            if (sc.State != SVMStateEnum.Unadded && sc.State != SVMStateEnum.Deleted)
            {
                // Make sure a stone was selected in the dropdown
                if (sc.Id == 0)
                {
                    throw new OjMissingStoneException("You must select a stone!");
                }

                return(sc.Id.Value);
            }
            return(0);
        }
Example #3
0
    private SequenceBehaviour createActionSequence()
    {
        SequenceBehaviour actionSequence        = new SequenceBehaviour(Agent);
        Rigidbody         rigidbody             = gameObject.GetComponent(typeof(Rigidbody)) as Rigidbody;
        StoneComponent    nearestStoneComponent = getNearestStoneComponent(rigidbody.transform.position);

        if (nearestStoneComponent == null)
        {
            Stop();
            notifyFinished();
            return(null);
        }
        StorageComponent storageComponent = getNearestStorageComponent(nearestStoneComponent.transform.position);

        if (storageComponent == null)
        {
            Stop();
            notifyFinished();
            return(null);
        }
        BackpackComponent backpackComponent = gameObject.GetComponent(typeof(BackpackComponent)) as BackpackComponent;

        if (backpackComponent == null)
        {
            Stop();
            notifyFinished();
            return(null);
        }
        MoveTowardsBehaviour             moveTowardsStoneBehaviour        = new MoveTowardsBehaviour(Agent, rigidbody, speed, nearestStoneComponent.transform.position);
        GatherStoneBehaviour             gatherStoneBehaviour             = new GatherStoneBehaviour(Agent, backpackComponent, nearestStoneComponent);
        MoveTowardsBehaviour             moveTowardsStorageBehaviour      = new MoveTowardsBehaviour(Agent, rigidbody, speed, storageComponent.transform.position);
        PutMaterialsIntoStorageBehaviour putMaterialsIntoStorageBehaviour = new PutMaterialsIntoStorageBehaviour(Agent, storageComponent, backpackComponent);

        if (!backpackComponent.hasStone)
        {
            actionSequence.AddSequentialBehaviour(moveTowardsStoneBehaviour);
            actionSequence.AddSequentialBehaviour(gatherStoneBehaviour);
        }
        actionSequence.AddSequentialBehaviour(moveTowardsStorageBehaviour);
        actionSequence.AddSequentialBehaviour(putMaterialsIntoStorageBehaviour);
        return(actionSequence);
    }
 public float workDuration = 2; // seconds
 public GatherStoneBehaviour(Agent agent, BackpackComponent backpackComponent, StoneComponent stoneComponent) : base(agent)
 {
     this.stoneComponent    = stoneComponent;
     this.backpackComponent = backpackComponent;
 }