Exemple #1
0
 protected virtual void _UpdateObjectiveRegistration()
 {
     for (int i = 0; i < _registeredObjectives.Count; i++)
     {
         OrderObjective objective = _registeredObjectives[i];
         if (!objectives.Contains(objective))
         {
             objective.Unregister();
         }
     }
     foreach (OrderObjective objective2 in objectives)
     {
         if (!_registeredObjectives.Contains(objective2))
         {
             objective2.Register(this);
             _registeredObjectives.Add(objective2);
         }
     }
 }
Exemple #2
0
        public static SpecialOrder GetSpecialOrder(string key, int?generation_seed)
        {
            Dictionary <string, SpecialOrderData> order_data = Game1.content.Load <Dictionary <string, SpecialOrderData> >("Data\\SpecialOrders");

            if (!generation_seed.HasValue)
            {
                generation_seed = Game1.random.Next();
            }
            if (order_data.ContainsKey(key))
            {
                Random           r     = new Random(generation_seed.Value);
                SpecialOrderData data  = order_data[key];
                SpecialOrder     order = new SpecialOrder();
                order.generationSeed.Value = generation_seed.Value;
                order._orderData           = data;
                order.questKey.Value       = key;
                order.questName.Value      = data.Name;
                order.requester.Value      = data.Requester;
                order.orderType.Value      = data.OrderType.Trim();
                order.specialRule.Value    = data.SpecialRule.Trim();
                if (data.ItemToRemoveOnEnd != null)
                {
                    int item_to_remove = -1;
                    if (int.TryParse(data.ItemToRemoveOnEnd, out item_to_remove))
                    {
                        order.itemToRemoveOnEnd.Value = item_to_remove;
                    }
                }
                if (data.MailToRemoveOnEnd != null)
                {
                    order.mailToRemoveOnEnd.Value = data.MailToRemoveOnEnd;
                }
                order.selectedRandomElements.Clear();
                if (data.RandomizedElements != null)
                {
                    foreach (RandomizedElement randomized_element in data.RandomizedElements)
                    {
                        List <int> valid_indices = new List <int>();
                        for (int i = 0; i < randomized_element.Values.Count; i++)
                        {
                            if (CheckTags(randomized_element.Values[i].RequiredTags))
                            {
                                valid_indices.Add(i);
                            }
                        }
                        int selected_index = Utility.GetRandom(valid_indices, r);
                        order.selectedRandomElements[randomized_element.Name] = selected_index;
                        string value = randomized_element.Values[selected_index].Value;
                        if (!value.StartsWith("PICK_ITEM"))
                        {
                            continue;
                        }
                        value = value.Substring("PICK_ITEM".Length);
                        string[]   array          = value.Split(',');
                        List <int> valid_item_ids = new List <int>();
                        string[]   array2         = array;
                        for (int j = 0; j < array2.Length; j++)
                        {
                            string valid_item_name = array2[j].Trim();
                            if (valid_item_name.Length == 0)
                            {
                                continue;
                            }
                            if (char.IsDigit(valid_item_name[0]))
                            {
                                int item_id = -1;
                                if (int.TryParse(valid_item_name, out item_id))
                                {
                                    valid_item_ids.Add(item_id);
                                }
                            }
                            else
                            {
                                Item item = Utility.fuzzyItemSearch(valid_item_name);
                                if (Utility.IsNormalObjectAtParentSheetIndex(item, item.ParentSheetIndex))
                                {
                                    valid_item_ids.Add(item.ParentSheetIndex);
                                }
                            }
                        }
                        order.preSelectedItems[randomized_element.Name] = Utility.GetRandom(valid_item_ids, r);
                    }
                }
                if (data.Duration == "Month")
                {
                    order.SetDuration(QuestDuration.Month);
                }
                else if (data.Duration == "TwoWeeks")
                {
                    order.SetDuration(QuestDuration.TwoWeeks);
                }
                else if (data.Duration == "TwoDays")
                {
                    order.SetDuration(QuestDuration.TwoDays);
                }
                else if (data.Duration == "ThreeDays")
                {
                    order.SetDuration(QuestDuration.ThreeDays);
                }
                else
                {
                    order.SetDuration(QuestDuration.Week);
                }
                order.questDescription.Value = data.Text;
                foreach (SpecialOrderObjectiveData objective_data in data.Objectives)
                {
                    OrderObjective objective      = null;
                    Type           objective_type = Type.GetType("StardewValley." + objective_data.Type.Trim() + "Objective");
                    if (!(objective_type == null) && objective_type.IsSubclassOf(typeof(OrderObjective)))
                    {
                        objective = (OrderObjective)Activator.CreateInstance(objective_type);
                        if (objective != null)
                        {
                            objective.description.Value = order.Parse(objective_data.Text);
                            objective.maxCount.Value    = int.Parse(order.Parse(objective_data.RequiredCount));
                            objective.Load(order, objective_data.Data);
                            order.objectives.Add(objective);
                        }
                    }
                }
                {
                    foreach (SpecialOrderRewardData reward_data in data.Rewards)
                    {
                        OrderReward reward      = null;
                        Type        reward_type = Type.GetType("StardewValley." + reward_data.Type.Trim() + "Reward");
                        if (!(reward_type == null) && reward_type.IsSubclassOf(typeof(OrderReward)))
                        {
                            reward = (OrderReward)Activator.CreateInstance(reward_type);
                            if (reward != null)
                            {
                                reward.Load(order, reward_data.Data);
                                order.rewards.Add(reward);
                            }
                        }
                    }
                    return(order);
                }
            }
            return(null);
        }
Exemple #3
0
 public virtual void AddObjective(OrderObjective objective)
 {
     objectives.Add(objective);
 }