private static CharacterRoutineTypeName GetRandomRoutineType(Character character)
    {
        List <CharacterRoutineType> availableCharacterRoutineTypes = new List <CharacterRoutineType>();

        // filter out available routines that are not suitable for the character's role
        for (int i = 0; i < RoutineManager.AvailableRoutineTypes.Count; i++)
        {
            CharacterRoutineType characterRoutineType = RoutineManager.AvailableRoutineTypes.ElementAt(i).Value;
            if (characterRoutineType.CharacterRoles.Count == 0 || characterRoutineType.CharacterRoles.Contains(character.Role))
            {
                availableCharacterRoutineTypes.Add(characterRoutineType);
            }
        }

        // weight chances for routines based on the time of day
        float[] weightedIndeces = availableCharacterRoutineTypes.Select(routine => {
            float originalWeight = routine.ProbabilityWeight;
            float adjustedWeight = routine.ApplyTimeProbabilityMultiplier(originalWeight);
            return(adjustedWeight);
        }).ToArray();
        //for (int p = 0; p < weightedIndeces.Length; p++)
        //{
        //    Logger.Log("adjusted weightedIndex {0} is {1}", p, weightedIndeces[p]);
        //}
        //for (int q = 0; q < availableCharacterRoutineTypes.Count; q++)
        //{
        //    Logger.Log("availableCharacterRoutineTypes name{0} is {1}", q, availableCharacterRoutineTypes[q].Name);
        //}
        int randomWeightIndex = Util.GetRandomWeightedIndex(weightedIndeces);

        CharacterRoutineTypeName randomCharacterRoutineType = availableCharacterRoutineTypes[randomWeightIndex].Name;

        return(randomCharacterRoutineType);
    }
    private List <RoomObjectName> GetRoomObjectsForTask(CharacterRoutineTypeName routineTypeName)
    {
        if (!RoutineManager.AvailableRoutineTypes.ContainsKey(routineTypeName))
        {
            Logger.Error("Could not find routine {0} among the available routine tasks", routineTypeName);
        }
        CharacterRoutineType characterRoutineType = RoutineManager.AvailableRoutineTypes[routineTypeName];

        return(characterRoutineType.RoomObjects);
    }
Example #3
0
    private static RoomObjectBlueprint ControlRoomMicrophoneBlueprint()
    {
        RoomObjectBlueprint blueprint = new RoomObjectBlueprint(RoomObjectName.ControlRoomMicrophone)
                                        .WithName("Microphone")
                                        .WithMenuDescription("Test one, two")
                                        .WithObjectInteractions(new ObjectInteraction[]
        {
            ObjectInteraction.Create(ObjectInteractionType.Perform, "Speak", ObjectInteractionCharacterRole.CharacterAtRoomObject)
            .AddInteractionStep(InteractionStep.Create().WithSequenceLine("Everyone is listening to the instructions"))
        })
                                        .WithCharacterRoutines(new CharacterRoutineType[]
        {
            CharacterRoutineType.Create(CharacterRoutineTypeName.Sing)
        });

        return(blueprint);
    }
Example #4
0
    public void RegisterRoomObjectGO(RoomObjectGO roomObjectGO)
    {
        bool exists = RoomObjectGOs.Any(go => go.RoomObjectBlueprint.RoomObjectName == roomObjectGO.RoomObjectBlueprint.RoomObjectName);

        //Logger.Log("Registered a {0} object in {1}", roomObjectGO.RoomObject.RoomObjectName, roomObjectGO.ParentRoom.RoomBlueprint.RoomName);
        RoomObjectGOs.Add(roomObjectGO);

        // if first of its kind, check if we should register a new routine
        if (!exists)
        {
            for (int i = 0; i < roomObjectGO.RoomObjectBlueprint.CharacterRoutines.Length; i++)
            {
                CharacterRoutineType routineType = roomObjectGO.RoomObjectBlueprint.CharacterRoutines[i];
                if (!RoutineManager.AvailableRoutineTypes.ContainsKey(routineType.Name))
                {
                    RoutineManager.EnableRoutineType(routineType);
                }
            }
        }
    }
Example #5
0
    public void DeregisterRoomObjectGO(RoomObjectGO roomObjectGO)
    {
        RoomObjectGOs.Remove(roomObjectGO);

        // if room object last of its kind, check if we should deregister a routine
        bool exists = RoomObjectGOs.Any(go => go.RoomObjectBlueprint.RoomObjectName == roomObjectGO.RoomObjectBlueprint.RoomObjectName);

        List <CharacterRoutineType> noLongerAvailableRoutines = new List <CharacterRoutineType>();

        if (!exists)
        {
            for (int i = 0; i < RoutineManager.AvailableRoutineTypes.Count; i++)
            {
                CharacterRoutineType characterRoutineType = RoutineManager.AvailableRoutineTypes.ElementAt(i).Value;
                bool containsRoomObject = characterRoutineType.RoomObjects.Contains(roomObjectGO.RoomObjectBlueprint.RoomObjectName);
                bool isStillAvailable   = false;

                if (containsRoomObject)
                {
                    for (int j = 0; j < characterRoutineType.RoomObjects.Count; j++)
                    {
                        RoomObjectName roomObjectInRoutine = characterRoutineType.RoomObjects[j];
                        if (RoomObjectGOs.Any(go => go.RoomObjectBlueprint.RoomObjectName == roomObjectInRoutine))
                        {
                            isStillAvailable = true;
                            break;
                        }
                    }
                }
                if (isStillAvailable)
                {
                    noLongerAvailableRoutines.Add(characterRoutineType);
                }
            }

            for (int k = 0; k < noLongerAvailableRoutines.Count; k++)
            {
                RoutineManager.DisableRoutineType(noLongerAvailableRoutines[k]);
            }
        }
    }
Example #6
0
    private static RoomObjectBlueprint TelephoneBlueprint()
    {
        RoomObjectBlueprint blueprint = new RoomObjectBlueprint(RoomObjectName.Telephone)
                                        .WithName("Telephone")
                                        .WithMenuDescription("A classic black telephone")
                                        .WithObjectInteractions(new ObjectInteraction[]
        {
            ObjectInteraction.Create(ObjectInteractionType.Contact, "Call the police")
            .AddInteractionStep(InteractionStep.Create().WithSequenceLine("You asked the police to removed the loud, beared hippies from your studio")),
            ObjectInteraction.Create(ObjectInteractionType.Contact, "Order a pizza")
            .AddInteractionStep(InteractionStep.Create().WithSequenceLine("You ordered a pizza for the whole band")),
            ObjectInteraction.Create(ObjectInteractionType.Contact, "Organise a tour")
            .AddInteractionStep(InteractionStep.Create().WithSequenceLine("The band is going on tour again!"))
        })
                                        .WithCharacterRoutines(new CharacterRoutineType[]
        {
            CharacterRoutineType.Create(CharacterRoutineTypeName.MakePhoneCall)
        });

        return(blueprint);
    }
Example #7
0
    public static CharacterRoutineType Create(CharacterRoutineTypeName name)
    {
        CharacterRoutineType characterRoutineType = new CharacterRoutineType(name);

        switch (name)
        {
        case CharacterRoutineTypeName.Idle1:
            return(characterRoutineType.Idle());

        case CharacterRoutineTypeName.MakePhoneCall:
            return(characterRoutineType.MakePhoneCall());

        case CharacterRoutineTypeName.Sing:
            return(characterRoutineType.Sing());

        case CharacterRoutineTypeName.Sleep:
            return(characterRoutineType.Sleep());

        default:
            Logger.Error("Cannot find a creation function for character routine name {0}", name);
            return(null);
        }
    }
 public static void DisableRoutineType(CharacterRoutineType routineType)
 {
     //Logger.Log("Disabled routine {0}", routineType.Name);
     AvailableRoutineTypes.Remove(routineType.Name);
 }
 public static void EnableRoutineType(CharacterRoutineType routineType)
 {
     //Logger.Log("Enabled routine {0}", routineType.Name);
     AvailableRoutineTypes.Add(routineType.Name, routineType);
 }