Exemple #1
0
        /**
         * <summary>Updates the state of an Objective</summary>
         * <param name = "objectiveID">The ID of the Objective to update</param>
         * <param name = "newStateID">The ID of the Objective's new state</param>
         * <param name = "playerID">The ID of the Player whose Objectives to update, if the Objective is set per-Player</param>
         */
        public void SetObjectiveState(int objectiveID, int newStateID, int playerID)
        {
            if (!KickStarter.inventoryManager.ObjectiveIsPerPlayer(objectiveID))
            {
                SetObjectiveState(objectiveID, newStateID);
                return;
            }

            if (playerID < 0 || (KickStarter.player && KickStarter.player.ID == playerID))
            {
                SetObjectiveState(objectiveID, newStateID);
                return;
            }

            // Inactive player
            PlayerData playerData = KickStarter.saveSystem.GetPlayerData(playerID);

            if (playerData != null)
            {
                ObjectiveInstance[] extractedObjectives = ExtractPlayerObjectiveData(playerData).ToArray();
                foreach (ObjectiveInstance objectiveInstance in extractedObjectives)
                {
                    if (objectiveInstance.Objective.ID == objectiveID)
                    {
                        objectiveInstance.CurrentStateID = newStateID;
                        string dataString = RecordPlayerObjectiveData(extractedObjectives);
                        KickStarter.saveSystem.AssignObjectivesToPlayer(dataString, playerID);
                        return;
                    }
                }
            }

            // No data found
            List <ObjectiveInstance> tempObjectives       = new List <ObjectiveInstance>();
            ObjectiveInstance        newObjectiveInstance = new ObjectiveInstance(objectiveID, newStateID);

            if (newObjectiveInstance.Objective != null)
            {
                tempObjectives.Add(newObjectiveInstance);
                string dataString = RecordPlayerObjectiveData(tempObjectives.ToArray());
                KickStarter.saveSystem.AssignObjectivesToPlayer(dataString, playerID);
            }
        }
Exemple #2
0
        /**
         * <summary>Restores saved data from a MainData class</summary>
         * <param name = "playerData">The MainData class to load from</param>
         */
        public void AssignGlobalObjectives(MainData mainData)
        {
            globalObjectiveInstances.Clear();
            SelectedObjective = null;

            if (!string.IsNullOrEmpty(mainData.globalObjectivesData))
            {
                string[] globalObjectivesArray = mainData.globalObjectivesData.Split(SaveSystem.pipe[0]);

                foreach (string chunk in globalObjectivesArray)
                {
                    ObjectiveInstance objectiveInstance = new ObjectiveInstance(chunk);
                    if (objectiveInstance.Objective != null)
                    {
                        globalObjectiveInstances.Add(objectiveInstance);
                    }
                }
            }
        }
        private List <ObjectiveInstance> ExtractPlayerObjectiveData(PlayerData playerData)
        {
            List <ObjectiveInstance> objectiveInstances = new List <ObjectiveInstance>();

            if (!string.IsNullOrEmpty(playerData.playerObjectivesData))
            {
                string[] playerObjectivesArray = playerData.playerObjectivesData.Split(SaveSystem.pipe[0]);

                foreach (string chunk in playerObjectivesArray)
                {
                    ObjectiveInstance objectiveInstance = new ObjectiveInstance(chunk);
                    if (objectiveInstance.Objective != null)
                    {
                        objectiveInstances.Add(objectiveInstance);
                    }
                }
            }

            return(objectiveInstances);
        }
        /**
         * <summary>Updates the state of an Objective</summary>
         * <param name = "objectiveID">The ID of the Objective to update</param>
         * <param name = "newStateType">The ObjectiveStateType of the Objective's new state. If not states of this type are found, no change will be made.  If multiple states of this type are found, the first will be set.</param>
         * <param name = "selectAfter">If True, the Objective will be considered 'selected' upon being updated</param>
         */
        public void SetObjectiveState(int objectiveID, ObjectiveStateType newStateType, bool selectAfter = false)
        {
            int       newStateID = -1;
            Objective objective  = KickStarter.inventoryManager.GetObjective(objectiveID);

            if (objective == null)
            {
                return;
            }

            foreach (ObjectiveState state in objective.states)
            {
                if (state.stateType == newStateType)
                {
                    newStateID = state.ID;
                }
            }

            if (newStateID < 0)
            {
                return;
            }

            foreach (ObjectiveInstance objectiveInstance in playerObjectiveInstances)
            {
                if (objectiveInstance.Objective.ID == objectiveID)
                {
                    objectiveInstance.CurrentStateID = newStateID;
                    if (selectAfter)
                    {
                        SelectedObjective = objectiveInstance;
                    }
                    return;
                }
            }

            foreach (ObjectiveInstance objectiveInstance in globalObjectiveInstances)
            {
                if (objectiveInstance.Objective.ID == objectiveID)
                {
                    objectiveInstance.CurrentStateID = newStateID;
                    if (selectAfter)
                    {
                        SelectedObjective = objectiveInstance;
                    }
                    return;
                }
            }

            ObjectiveInstance newObjectiveInstance = new ObjectiveInstance(objectiveID, newStateID);

            if (newObjectiveInstance.Objective != null)
            {
                if (newObjectiveInstance.Objective.perPlayer && KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow)
                {
                    playerObjectiveInstances.Add(newObjectiveInstance);
                }
                else
                {
                    globalObjectiveInstances.Add(newObjectiveInstance);
                }
                if (selectAfter)
                {
                    SelectedObjective = newObjectiveInstance;
                }
                KickStarter.eventManager.Call_OnObjectiveUpdate(newObjectiveInstance);
            }
            else
            {
                ACDebug.LogWarning("Cannot set the state of objective " + objectiveID + " because that ID does not exist!");
            }
        }