Example #1
0
        public void Load(Dictionary data)
        {
            var    valueExtractor = GlobalConstants.GameManager.ItemDatabase.ValueExtractor;
            string guidString     = valueExtractor.GetValueFromDictionary <string>(data, "Guid");

            this.ID = guidString is null ? Guid.Empty : new Guid(guidString);

            guidString   = valueExtractor.GetValueFromDictionary <string>(data, "Questor");
            this.Questor = guidString is null ? Guid.Empty : new Guid(guidString);

            guidString      = valueExtractor.GetValueFromDictionary <string>(data, "Instigator");
            this.Instigator = guidString is null ? Guid.Empty : new Guid(guidString);

            this.CurrentStep = valueExtractor.GetValueFromDictionary <int>(data, "CurrentStep");

            var rewardDicts = valueExtractor.GetArrayValuesCollectionFromDictionary <Dictionary>(data, "Rewards");

            List <IItemInstance> rewards = new List <IItemInstance>();

            foreach (Dictionary dict in rewardDicts)
            {
                IItemInstance item = new ItemInstance();
                item.Load(dict);
                rewards.Add(item);
            }
            GlobalConstants.GameManager.ItemHandler.AddQuestRewards(this.ID, rewards);

            this.RewardGUIDs = rewards.Select(instance => instance.Guid).ToList();

            this.Actions = new List <IQuestAction>();
            var actionDicts = valueExtractor.GetArrayValuesCollectionFromDictionary <Dictionary>(data, "Actions");

            foreach (Dictionary actionDict in actionDicts)
            {
                string type = valueExtractor.GetValueFromDictionary <string>(actionDict, "Type");
                if (type.IsNullOrEmpty())
                {
                    continue;
                }

                IQuestAction action = QuestActionFactory.Create(type);
                if (action is null)
                {
                    continue;
                }

                action.Load(actionDict);
                this.Actions.Add(action);
            }
        }