Counting the “in game time” works already pretty well. What I am struggling with is scheduling actions.
Let’s say I am having 20 NPC. They have their own day and week schedules. They walk to different places and perform different actions.
I thought about building a solution around observer pattern using delegates in dictionary.
So the plan would be to have a dictionary<string, action> and the string would be unique time identifier (e.g. 10:53 WED). All the NPC would subscribe to the potential events at certain time. When the time changes, I would “grab” from the dictionary actions for particular time (if they exist) and execute the methods.
Do you think solution like that has sense?
Is there any better/cleaner way to design and implement something like that?
Is there a way to achieve something like that and store it in files?
There are two suggestions here.
I think the use of dictionaries is usually done during the optimization phase. use class is better
public class Mission{
public float time;
public System.Action action;
}
This is more scalable , because the requirements may change at any time during development, He might become like this
public class Mission{
public float plannedTime;
public System.Action action;
public MissionType missionType;
public MissionName missionName;
public float progress // 0-1
}
If the behavior of the NPC is close to that of humans, then the NPC actually has two plans, one for what to do every day, the other for what to do every Monday, and what to do every Tuesday.
The mission is placed in the LIst missionList; this field belongs to NPC.
The mission is placed in the LIst missionList; this field belongs to NPC.
Traverse the time of each mission, if the mission time is equal to the current time, do action
Of course, you can arrange the mission in chronological order, so that each frame you only judge whether the time is equal to the time of the next mission
Yes, Mission are an attribute of NPC, and time is managed by Time class.