Update to assignTarget

This commit is contained in:
Antoine H 2021-01-12 10:20:30 +01:00
parent 2dbb5e4dfe
commit 1696694db5
2 changed files with 26 additions and 15 deletions

View file

@ -82,13 +82,13 @@ public class Client_controller : MonoBehaviour, IUsable
} }
else else
{ {
Debug.Log(gameObject.name+" doesn't want that"); Debug.Log(gameObject.name+" doesn't want that "+object_used.name);
return false; return false;
} }
} }
else else
{ {
Debug.Log(gameObject.name+" doesn't want that"); Debug.Log(gameObject.name+" doesn't want that "+object_used.name);
return false; return false;
} }
} }
@ -146,7 +146,7 @@ public class Client_controller : MonoBehaviour, IUsable
{ {
//Leave tavern //Leave tavern
status = "leaving"; status = "leaving";
agent.SetDestination(ClientManager.Instance.assignTarget(agent.destination)); //Request next target agent.SetDestination(ClientManager.Instance.assignTarget(agent.destination, true)); //Request next target
} }
else if(UIWaitingTimer != null) //Update UI Waiting timer else if(UIWaitingTimer != null) //Update UI Waiting timer
UIWaitingTimer.SetValue(waitTimer/waitingTime); UIWaitingTimer.SetValue(waitTimer/waitingTime);
@ -173,7 +173,7 @@ public class Client_controller : MonoBehaviour, IUsable
//Leave tavern //Leave tavern
status = "leaving"; status = "leaving";
agent.SetDestination(ClientManager.Instance.assignTarget(agent.destination)); //Request next target agent.SetDestination(ClientManager.Instance.assignTarget(agent.destination, true)); //Request next target
} }
} }

View file

@ -55,14 +55,18 @@ public sealed class ClientManager : MonoBehaviour
} }
//Assign a random available target. //Return a random available target. Or the Exit if Exit=True.
public Vector2 assignTarget(Vector2? prevTarget=null) //prevTarget : Previous target of the client which will be available for other clients.
public Vector2 assignTarget(Vector2? prevTarget=null, bool exit=false)
{ {
if(prevTarget != null) if(prevTarget != null)
{ {
targets_dict[(Vector2)prevTarget]=false; //Free prevTarget targets_dict[(Vector2)prevTarget]=false; //Free prevTarget
return spawnPoint;
} }
if(exit) //Assign Exit target
return spawnPoint;
else
{
List<Vector2> avail_tgt = new List<Vector2>(); List<Vector2> avail_tgt = new List<Vector2>();
foreach(KeyValuePair<Vector2, bool> tgt in targets_dict) foreach(KeyValuePair<Vector2, bool> tgt in targets_dict)
if(tgt.Value is false) if(tgt.Value is false)
@ -72,6 +76,13 @@ public sealed class ClientManager : MonoBehaviour
targets_dict[target]=true; targets_dict[target]=true;
return target; return target;
} }
}
//Return a random order from available consummable
public string assignOrder()
{
return "beer";
}
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()