예제 #1
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 value2 = randomized_element.Values[selected_index].Value;
                        if (value2.StartsWith("PICK_ITEM"))
                        {
                            value2 = value2.Substring("PICK_ITEM".Length);
                            string[]   array          = value2.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)
                                {
                                    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 objective2     = null;
                    Type           objective_type = Type.GetType("StardewValley." + objective_data.Type.Trim() + "Objective");
                    if (!(objective_type == null) && objective_type.IsSubclassOf(typeof(OrderObjective)))
                    {
                        objective2 = (OrderObjective)Activator.CreateInstance(objective_type);
                        if (objective2 != null)
                        {
                            objective2.description.Value = order.Parse(objective_data.Text);
                            objective2.maxCount.Value    = int.Parse(order.Parse(objective_data.RequiredCount));
                            objective2.Load(order, objective_data.Data);
                            order.objectives.Add(objective2);
                        }
                    }
                }
                {
                    foreach (SpecialOrderRewardData reward_data in data.Rewards)
                    {
                        OrderReward reward2     = null;
                        Type        reward_type = Type.GetType("StardewValley." + reward_data.Type.Trim() + "Reward");
                        if (!(reward_type == null) && reward_type.IsSubclassOf(typeof(OrderReward)))
                        {
                            reward2 = (OrderReward)Activator.CreateInstance(reward_type);
                            if (reward2 != null)
                            {
                                reward2.Load(order, reward_data.Data);
                                order.rewards.Add(reward2);
                            }
                        }
                    }
                    return(order);
                }
            }
            return(null);
        }