예제 #1
0
        /**
         * <summary>Generates a new event based on the headline template</summary>
         * <remarks>
         *  This method doesn't apply the event; it just generates it.
         * </remarks>
         *
         * <param name="rand">The RNG to use to generate this event. (Default: a brand new one)</param>
         * <returns>An event based on this template.</returns>
         */
        public EconEvent GenerateNewEvent(IHeadlineContentProvider rng)
        {
            StringBuilder builder      = new StringBuilder();
            int           affectedItem = -1;
            int           oldPrice     = 0;

            foreach (HeadlineToken token in this.headlineTemplate)
            {
                // Get the subtype:
                var subtype = HeadlineTemplate.GetSubType(token, rng);
                switch (token.type)
                {
                case HeadlineTokenType.Item:
                {
                    // Generate an item, whatever kind.
                    // If we haven't yet generated an item, select that to
                    // be the item affected by this event.
                    int item     = GenerateItem(subtype, rng);
                    var itemInfo = rng.GetItemInformation(item);
                    if (affectedItem == -1)
                    {
                        affectedItem = item;
                        oldPrice     = itemInfo.price;
                    }

                    builder.Append(itemInfo.name);
                    break;
                }

                case HeadlineTokenType.Other:
                {
                    builder.Append(GenerateOther(subtype, rng));
                    break;
                }

                case HeadlineTokenType.String:
                {
                    builder.Append(token.str);
                    break;
                }
                }
            }

            int percent = GeneratePercentChange(affectedItem, rng.GetRNG());

            return(new EconEvent(builder.ToString(), affectedItem, percent, oldPrice));
        }
예제 #2
0
 /**
  * <summary>Returns the subtype of the token, randomly selecting one if necessary.</summary>
  *
  * <param name="token">The token whose subtype to get.</param>
  * <param name="rng">The RNG provider to use if necessary.</param>
  *
  * <returns>The subtype of the token.</returns>
  */
 private static HeadlineTokenSubtype GetSubType(HeadlineToken token, IHeadlineContentProvider rng)
 {
     if (token.subtypes == null || token.subtypes.Count == 0)
     {
         return(default(HeadlineTokenSubtype));
     }
     else if (token.subtypes.Count == 1)
     {
         return(token.subtypes[0]);
     }
     else
     {
         var rand  = rng.GetRNG();
         var index = rand.Next(token.subtypes.Count);
         return(token.subtypes[index]);
     }
 }