コード例 #1
0
 /// <summary>
 /// Chooses the task for this entity based on this job.
 /// </summary>
 /// <param name="npc"></param>
 private void ChooseWorkTask(NPC npc)
 {
     if (CurrentlyWorkingAt != null)
     {
         CurrentlyWorkingAt.CurrentUser = null;
     }
     if (WorkEquiptment.Count == 0)
     {
         throw new System.Exception("No work equiptment");
     }
     CurrentlyWorkingAt = GameManager.RNG.RandomFromList(WorkEquiptment);
     for (int i = 0; i < 10; i++)
     {
         if (CurrentlyWorkingAt.CurrentUser != null)
         {
             CurrentlyWorkingAt = GameManager.RNG.RandomFromList(WorkEquiptment);
         }
         else
         {
             CurrentlyWorkingAt.CurrentUser = npc;
         }
     }
     CurrentWorkTime = Time.time;
     //Choose work time limit of 25-45 seconds
     WorkTimeLimit = GameManager.RNG.RandomInt(25, 45);
 }
コード例 #2
0
    public static Vector3 WorkPosition(this IWorkEquiptmentObject obj)
    {
        WorldObjectData objDat = obj as WorldObjectData;
        float           x      = obj.DeltaPosition.x * Mathf.Cos(objDat.Rotation * Mathf.Deg2Rad)
                                 + obj.DeltaPosition.z * Mathf.Sin(objDat.Rotation * Mathf.Deg2Rad);

        float z = -obj.DeltaPosition.x * Mathf.Sin(objDat.Rotation * Mathf.Deg2Rad)
                  + obj.DeltaPosition.z * Mathf.Cos(objDat.Rotation * Mathf.Deg2Rad);

        return(objDat.Position + new Vector3(x, obj.DeltaPosition.y, z));
    }
コード例 #3
0
 private void ChooseWorkEquiptment(NPC npc)
 {
     CurrentTargetEquiptment = GameManager.RNG.RandomFromList(WorkEquiptment);
     for (int i = 0; i < 10; i++)
     {
         if (CurrentTargetEquiptment.CurrentUser != null)
         {
             CurrentTargetEquiptment = GameManager.RNG.RandomFromList(WorkEquiptment);
         }
         else
         {
             CurrentTargetEquiptment.CurrentUser = npc;
         }
     }
 }
コード例 #4
0
 public override void JobTick(NPC npc)
 {
     //If we currently have no task
     if (SubTask == CurrentSubTask.None)
     {
         if (!HasEquiptment)
         {
             SetSubTask(npc, CurrentSubTask.GettingEquiptment);
         }
     }
     else if (SubTask == CurrentSubTask.GettingEquiptment)
     {
         //if we have sucesfully got our equiptment
         if (HasEquiptment)
         {
             if (GameManager.RNG.RandomBool())
             {
                 //TODO - uncomment this
                 //SetSubTask(npc, CurrentSubTask.Patrolling);
                 SetSubTask(npc, CurrentSubTask.Training);
             }
             else
             {
                 SetSubTask(npc, CurrentSubTask.Training);
             }
         }
     }
     else if (SubTask == CurrentSubTask.Patrolling)
     {
         if (CurrentTargetPosition.WithinDistance(npc.Position, 3))
         {
             Settlement set = npc.NPCKingdomData.GetSettlement();
             CurrentTargetPosition = set.RandomPathPoint().AsVector3();
             npc.GetLoadedEntity().LEPathFinder.SetTarget(CurrentTargetPosition);
             npc.GetLoadedEntity().SpeechBubble.PushMessage("Choosing new patrol target " + CurrentTargetPosition);
         }
     }
     else if (SubTask == CurrentSubTask.Training)
     {
         if (CurrentTargetEquiptment == null)
         {
             CurrentTargetEquiptment = GameManager.RNG.RandomFromList(WorkEquiptment);
             for (int i = 0; i < 10; i++)
             {
                 if (CurrentTargetEquiptment.CurrentUser != null)
                 {
                     CurrentTargetEquiptment = GameManager.RNG.RandomFromList(WorkEquiptment);
                 }
                 else
                 {
                     CurrentTargetEquiptment.CurrentUser = npc;
                 }
             }
             //If no valid equiptment is found, we patrol
             if (CurrentTargetEquiptment == null)
             {
                 SetSubTask(npc, CurrentSubTask.Patrolling);
             }
             else
             {
                 //if the equiptment is non null, we target and travel to it
                 CurrentTargetPosition = CurrentTargetEquiptment.WorkPosition();
                 npc.GetLoadedEntity().LEPathFinder.SetTarget(CurrentTargetPosition);
                 npc.GetLoadedEntity().SpeechBubble.PushMessage("Training on object " + CurrentTargetPosition);
             }
         }
     }
 }
コード例 #5
0
    private void SetSubTask(NPC npc, CurrentSubTask task)
    {
        SubTask = task;

        if (task == CurrentSubTask.GettingEquiptment)
        {
            npc.GetLoadedEntity().SpeechBubble.PushMessage("Walking to go get equiptment");

            //Choose random spot at work building.
            //TODO - add specific parts to each building (perhaps, we define rooms)
            CurrentTargetPosition = GameManager.RNG.RandomFromList(WorkLocation.WorkBuilding.GetSpawnableTiles()).AsVector3();
            npc.GetLoadedEntity().LEPathFinder.SetTarget(CurrentTargetPosition);
            CurrentTaskTime = -1;
            //Ensure this task does not time out till completed
            CurrentTaskTimeout = float.MaxValue;
        }
        else if (task == CurrentSubTask.Patrolling)
        {
            npc.GetLoadedEntity().SpeechBubble.PushMessage("Starting patrol");

            Settlement set = npc.NPCKingdomData.GetSettlement();
            CurrentTargetPosition = set.RandomPathPoint().AsVector3();
            npc.GetLoadedEntity().LEPathFinder.SetTarget(CurrentTargetPosition);
            npc.GetLoadedEntity().SpeechBubble.PushMessage("Patrol target: " + CurrentTargetPosition);
        }
        else if (task == CurrentSubTask.Training)
        {
            npc.GetLoadedEntity().SpeechBubble.PushMessage("Starting to train");
            //Choose equiptment to work at
            CurrentTargetEquiptment = GameManager.RNG.RandomFromList(WorkEquiptment);
            for (int i = 0; i < 10; i++)
            {
                if (CurrentTargetEquiptment.CurrentUser != null)
                {
                    CurrentTargetEquiptment = GameManager.RNG.RandomFromList(WorkEquiptment);
                }
                else
                {
                    CurrentTargetEquiptment.CurrentUser = npc;
                }
            }
            //If no valid equiptment is found, we patrol
            if (CurrentTargetEquiptment == null)
            {
                SetSubTask(npc, CurrentSubTask.Patrolling);
            }
            else
            {
                //if the equiptment is non null, we target and travel to it
                CurrentTargetPosition = CurrentTargetEquiptment.WorkPosition();
                npc.GetLoadedEntity().LEPathFinder.SetTarget(CurrentTargetPosition);
                npc.GetLoadedEntity().SpeechBubble.PushMessage("Training on object " + CurrentTargetPosition);
            }


            if (npc.Position.WithinDistance(CurrentTargetPosition, 0.5f))
            {
                EquiptmentAssociatedTask(npc);
            }
        }
    }