Пример #1
0
        public static StatEffect Create(string fieldText, Sprite image)
        {
            if (string.IsNullOrEmpty(fieldText))
            {
                return(null);
            }
            StatEffect retval     = new StatEffect();
            int        splitIndex = fieldText.IndexOf('\n');

            foreach (string scText in fieldText.Substring(0, splitIndex).Split(RLConstants.STRING_SPLIT_AND))
            {
                retval.statChanges.Add(new StatChange(scText.Trim()));
            }

            retval.effectTexts = new List <string>(fieldText.Substring(splitIndex + 1).Split(RLConstants.STRING_SPLIT_OR, System.StringSplitOptions.RemoveEmptyEntries));
            for (int e = 0; e < retval.effectTexts.Count; e++)
            {
                retval.effectTexts[e] = RLUtilities.ApplyBoldItalic(retval.effectTexts[e]);
            }

            retval.EffectImage = image;
            return(retval);
        }
Пример #2
0
    public DecisionHolder(TextAsset decisionsFile)
    {
        alwaysAvailable = new List <Decision>();
        unavailable     = new List <Decision>();
        decisionQueue   = new List <Decision>();
        string[][] allDecisions = RLUtilities.ReadSheet(decisionsFile.text);
        int        decisionFieldIndex = -1, fieldsPerButton = 0, fieldsBeforeButtons = 0, numResults = 0;

        for (int d = 0; d < allDecisions.Length; d++)
        {
            if (d == 0)                  // Column names
            {
                string curButtonName = string.Empty;

                for (int i = 0; i < allDecisions[d].Length; i++)
                {
                    string curField = allDecisions[d][i];
                    if (decisionFieldIndex < 0)
                    {
                        if (curField == "Decision")
                        {
                            decisionFieldIndex = i;
                        }
                        continue;
                    }
                    if (curField.StartsWith("Button:"))
                    {
                        if (!string.IsNullOrEmpty(curButtonName))
                        {
                            break;
                        }
                        curButtonName       = curField.Replace("Button:", "").Trim();
                        fieldsBeforeButtons = i;
                    }
                    else if (i >= fieldsBeforeButtons + BUTTON_INFO_FIELDS)
                    {
                        numResults++;
                    }
                }
                fieldsPerButton = BUTTON_INFO_FIELDS + numResults;
                continue;                   // That's all we want from the first row
            }

            if (allDecisions[d].Length < 1 || string.IsNullOrEmpty(allDecisions[d][decisionFieldIndex]))
            {
                continue;                                                                                                      // Invalid row. REJECTED
            }
            Decision curDec = new Decision()
            {
                decisionText = RLUtilities.ApplyBoldItalic(allDecisions[d][decisionFieldIndex]),
                decisionID   = allDecisions[d][0].Substring(0, allDecisions[d][0].IndexOf('\n')),
            };

            ImagesHolder.DecisionImages curImages = ImagesHolder.GetImages(curDec.decisionID);
            if (curImages != null)
            {
                curDec.decisionImage = curImages.decisionImage;
            }

            for (int b = 0; b < BUTTON_COUNT; b++)
            {
                int           i = fieldsBeforeButtons + (b * fieldsPerButton);          // Button info start index
                List <string> curStatEffects = new List <string>();

                for (int s = 0; s < numResults; s++)
                {
                    // Stat effects
                    string curEffect = allDecisions[d][i + BUTTON_INFO_FIELDS + s];
                    if (!string.IsNullOrEmpty(curEffect))
                    {
                        curStatEffects.Add(curEffect);
                    }
                }
                curDec.buttonResults.Add(new Decision.ButtonResult(allDecisions[d][i], allDecisions[d][i + 1], curStatEffects, curImages == null ? null : curImages.resultImages[b]));
            }

            int reqIndex      = fieldsBeforeButtons + (BUTTON_COUNT * fieldsPerButton),
                freeTurnIndex = reqIndex + 1;
            curDec.SetRequirements(allDecisions[d][reqIndex]);
            curDec.turnCost = allDecisions[d][freeTurnIndex] == "TRUE" ? 0 : 1;

            (string.IsNullOrEmpty(allDecisions[d][reqIndex]) ? alwaysAvailable : unavailable).Add(curDec);
        }

        // Set up decision queue
        decisionQueue.Clear();
        decisionQueue.InsertRange(0, alwaysAvailable);
        decisionQueue.Sort((d1, d2) => {         // Shuffle
            return(Random.value > 0.5f ? 1 : -1);
        });
        UpdateAvailableDecisions();

        GameManager.Instance.OnDecisionTaken += UpdateAvailableDecisions;
    }