Esempio n. 1
0
    public void AssignMission(ResourceRequest r)
    {
        target  = null;
        loading = true;
        Collections.Available.Remove(this);
        mission = r;
        List <IResources> Source = new List <IResources> ();

        Source.AddRange(Collections.ResourceSources);
        Source.OrderBy(
            targ => Vector3.Distance(this.transform.position, targ.GetGameObject().transform.position)).ToList();
        target = null;
        int i = 0;

        try{
            while (target == null)
            {
                if (Source[i] != mission.patron && Source [i].HasResource(mission.resource, mission.amount))
                {
                    target = Source [i];
                }
                i++;
            }
        }
        catch {
            Debug.Log("No valid sources.");
            EndMission();
            return;
        }
        agent.SetDestination(target.GetGameObject().transform.position);
        Debug.Log(gameObject.name + " is enroute to " + target.GetGameObject().name);
    }