public void SetupOptionButton(EventOption eventOption) { Description.text = eventOption.OptionDescription; Button.onClick.AddListener(() => UiEventHandler.FireOptionSelectedEvent(eventOption)); }
protected override string ActionName(EventOption eventOption) { return action; }
protected override string ActionName(EventOption eventOption) { return CachedMethodName; }
protected override string ActionName(EventOption eventOption) { return eventOption.BulkText ? BulkTextAction : TextAction; }
private EventOption GetBirthDeathEvent( int year, string eventName ) { int month = m_options.Random.Next( 1, 12 ); int day = m_options.Random.Next( 1, 28 ); EventOption ev = new EventOption( new DateTime(year, month, day) ); ev.SubOptions.Add( new StringOption( eventName, "yes", OptionType.ID ) ); return ev; }
protected override string ActionName(EventOption eventOption) { return exception.ToString(); }
protected override string ActionName(EventOption eventOption) { string lookupNode = "Node(" + PathTo(clickedNode) + ")."; return isExpanded ? lookupNode + ExpandEventName : lookupNode + CollapseEventName; }
protected List<Character> CreateRandomCharacter( CharacterOption charOptions, Dictionary<int, Dynasty> availDynasties, bool outputLaws ) { List<Character> retList = new List<Character>(); #region This Character #region Culture, Religion, Dynasty Culture curCul; if( charOptions.SpecifiedCulture ) curCul = charOptions.Culture; else curCul = charOptions.CultureList.RandomItem( m_options.Random ); Religion curRel; if( charOptions.SpecifiedReligion ) curRel = charOptions.Religion; else curRel = charOptions.ReligionList.RandomItem( m_options.Random ); Dynasty dyn; if( charOptions.SpecifiedDynasty ) { dyn = charOptions.Dynasty; } else { dyn = m_options.Data.GetDynastyByCulture( availDynasties, curCul, m_options.Random ); while( dyn == null ) { if( availDynasties.Count == 0 ) availDynasties = new Dictionary<int, Dynasty>( m_options.Data.Dynasties ); dyn = m_options.Data.GetDynastyByCulture( availDynasties, m_options.Data.GetRandomCulture( m_options.Random ).Value, m_options.Random ); } availDynasties.Remove( dyn.ID ); } #endregion Character curChar = new Character(); retList.Add( curChar ); int age; if( !charOptions.IsSpouse ) age = m_options.Random.Normal( 17, 40 ); else age = m_options.Random.Normal( charOptions.PartnerAge, 3.0 ).Clamp( 17, 99 ); curChar.CustomFlags["age"] = age; int birthYear = m_options.StartDate - 1 - age; curChar.Events.Add( GetBirthDeathEvent( birthYear, "birth" ) ); int deathYear = m_options.StartDate + m_options.Random.Normal( 5, 40 ); curChar.Events.Add( GetBirthDeathEvent( deathYear, "death" ) ); curChar.ID = charOptions.ID != 0 ? charOptions.ID : m_options.CharID++; curChar.Culture = curCul.Name; curChar.Religion = curRel.Name; curChar.Dynasty = dyn.ID; // Check rule set restrictions. if( charOptions.Gender == RuleSet.Gender.Random ) charOptions.Gender = m_options.RuleSet.GetGender( curCul, curRel ); if( charOptions.Gender == RuleSet.Gender.Random ) curChar.IsFemale = ( m_options.Random.Next( 101 ) <= m_options.RuleSet.FemaleRulerChance ); else curChar.IsFemale = charOptions.Gender == RuleSet.Gender.Female; curChar.Name = curCul.GetRandomName( curChar.IsFemale, m_options.Random ); #endregion #region Spouse if( !charOptions.IsSpouse && age > 20 && m_options.Random.Next( 0, 101 ) < m_options.RuleSet.RulerSpouseChance ) { CharacterOption spouseOptions = charOptions; spouseOptions.Gender = curChar.IsFemale ? RuleSet.Gender.Male : RuleSet.Gender.Female; spouseOptions.IsSpouse = true; spouseOptions.PartnerAge = age; spouseOptions.SpecifiedDynasty = false; spouseOptions.ID = 0; List<Character> posSpouse = CreateRandomCharacter( spouseOptions, availDynasties, false ); curChar.CurrentSpouse = posSpouse[0]; posSpouse[0].CurrentSpouse = curChar; int youngestAge = (int)curChar.CurrentSpouse.CustomFlags["age"]; if( age < youngestAge ) youngestAge = age; int marriageYear = m_options.Random.Next( 1, youngestAge - 16 ); int month = m_options.Random.Next( 1, 12 ); int day = m_options.Random.Next( 1, 28 ); EventOption spouseEvent = new EventOption( new DateTime( m_options.StartDate - marriageYear, month, day ) ); spouseEvent.SubOptions.Add( new IntegerOption( "add_spouse", curChar.ID ) ); curChar.CurrentSpouse.Events.Add( spouseEvent ); EventOption curCharEvent = new EventOption( new DateTime( m_options.StartDate - marriageYear, month, day ) ); curCharEvent.SubOptions.Add( new IntegerOption( "add_spouse", posSpouse[0].ID ) ); curChar.Events.Add( curCharEvent ); retList.Add( posSpouse[0] ); } #endregion #region Law Generation if( !charOptions.IsSpouse ) { LawSet laws = m_options.RuleSet.LawRules.GetLawSet( curCul, curRel, m_options.Random ); if( outputLaws ) { Log( " --Fetched realm laws: " + "\n Succession: " + laws.Succession + "\n Gender: " + laws.Gender + "\n Crown: " + laws.CrownAuthority + "\n Feudal Levy: " + laws.FeudalLevy + "\n Feudal Tax: " + laws.FeudalTax + "\n City Levy: " + laws.CityLevy + "\n City Tax: " + laws.CityTax + "\n Church Levy: " + laws.ChurchLevy + "\n Church Tax: " + laws.ChurchTax + "\n Iqta Levy: " + laws.IqtaLevy + "\n Iqta Tax:" + laws.IqtaTax ); } curChar.CustomFlags["laws"] = laws; } #endregion return retList; }
protected abstract string ActionName(EventOption eventOption);
protected override string ActionName(EventOption eventOption) { return "Node( " + PathTo(selectedNode) + ")." + SelectEventName; }
public virtual void WriteTo(EventWriter eventWriter, EventOption eventOption) { eventWriter.Write(UIItemType, ActionName(eventOption), uiItem.PrimaryIdentification, ActionParameters); }
/// <summary> /// Generates the content of the events based on the condition /// </summary> /// <param name="conType">Type of conditions, 0 for required, 1 for basic, 2 for advanced</param> /// <param name="numCon">Number of conditions</param> /// <param name="eventtype">The type of event, gathering, diplomacy, research</param> /// <returns></returns> private EventOption generateEvent(int conType, int numCon, string eventtype, int location) { // test vars //int conType = 0; //int numCon = 1; //int numOut = 1; //string eventtype = "gathering"; //string eventLevel = "basic"; XmlDocument xmlDoc = new XmlDocument(); TextAsset textAsset = Resources.Load("XML/EventStructure", typeof(TextAsset)) as TextAsset; xmlDoc.LoadXml(textAsset.text); // xmlDoc.Load(eventstructurepath); XmlNodeList conditionList = xmlDoc.SelectNodes(eventconditions); //Event options EventOption evOpt = new EventOption(); // add crew member condition for (int i = 0; i < conditionList.Count; i++) { XmlNode xn = conditionList[i]; if (int.Parse(xn.SelectSingleNode("type").InnerText) <= 0) { Piece basPiece = DataManager.instance.BoardPieces[xn.SelectSingleNode("piece").InnerText]; if (evOpt.Conditions.ContainsKey(basPiece)) { evOpt.Conditions[basPiece] += int.Parse(xn.SelectSingleNode("amount").InnerText); } else { evOpt.Conditions.Add(basPiece, int.Parse(xn.SelectSingleNode("amount").InnerText)); } break; } } bool roomAdded = false; // Select event conditions for (int j = 0; j < numCon-1; j++) { int[] conSelect = DataManager.randomArray(conditionList.Count); for (int i = 0; i < conditionList.Count; i++) { bool roomExist = false; XmlNode xn = conditionList[conSelect[i]]; //Select a condition which is limited by the condition type parameter if (int.Parse(xn.SelectSingleNode("type").InnerText) <= conType) { Piece basPiece = DataManager.instance.BoardPieces[xn.SelectSingleNode("piece").InnerText]; if( !roomAdded && conType == 2 && basPiece.Type != BoardType.ROOM ) { continue; } roomAdded = true; // ensures there is only one room. if(basPiece.Type == BoardType.ROOM) { foreach(KeyValuePair<Piece, int> pieceNum in evOpt.Conditions) { if(pieceNum.Key.Type == BoardType.ROOM) { roomExist = true; } } if (roomExist) { continue; } } if (evOpt.Conditions.ContainsKey(basPiece)) { evOpt.Conditions[basPiece] += int.Parse(xn.SelectSingleNode("amount").InnerText); } else { evOpt.Conditions.Add(basPiece, int.Parse(xn.SelectSingleNode("amount").InnerText)); } break; } } } int conSelectnum = numCon; int addedCons = 0; Dictionary<Piece, int> usedConds = new Dictionary<Piece, int>(); //Select outcomes while (addedCons < numCon ) { //numRuns++; string numberString = ""; switch (conSelectnum) { case 2: numberString = "/two"; break; case 1: numberString = "/one"; break; case 3: numberString = "/three"; break; } //numberString = "/one"; XmlNodeList Outcome = xmlDoc.SelectNodes("eventstructure/" + eventtype + numberString + "/outcome"); int[] outSelect = DataManager.randomArray(Outcome.Count); for (int i = 0; i < outSelect.Length; i++) { XmlNode xn = Outcome[outSelect[i]]; XmlNodeList xnConlist = xn.SelectNodes("conditions/condition"); bool found = true; for (int j = 0; j < xnConlist.Count; j++) { XmlNode xnCon = xnConlist[j]; Piece conPiece = DataManager.instance.BoardPieces[xnCon.SelectSingleNode("piece").InnerText]; if (!evOpt.Conditions.ContainsKey(conPiece) || evOpt.Conditions[conPiece] < int.Parse(xnCon.SelectSingleNode("amount").InnerText)) { found = false; break; } if(usedConds.ContainsKey(conPiece) && !(evOpt.Conditions[conPiece]-usedConds[conPiece] >= int.Parse(xnCon.SelectSingleNode("amount").InnerText))) { found = false; break; } } if (found) { for(int j = 0; j<xnConlist.Count; j++) { XmlNode xnCon = xnConlist[j]; addedCons = addedCons + int.Parse(xnCon.SelectSingleNode("amount").InnerText); Piece conPiece = DataManager.instance.BoardPieces[xnCon.SelectSingleNode("piece").InnerText]; if (usedConds.ContainsKey(conPiece)) { usedConds[conPiece] += int.Parse(xnCon.SelectSingleNode("amount").InnerText); } else { usedConds.Add(conPiece, int.Parse(xnCon.SelectSingleNode("amount").InnerText)); } } string critString = "/normal"; if ((Random.Range(0, 100) + 1) > crit) { critString = "/critical"; } EventOutcomeGroup evgroup = new EventOutcomeGroup(); evgroup.Outcomes.Add(generateOutcome(xn, "success", critString, EventOutcomeType.SUCCESS)); evgroup.Outcomes.Add(generateOutcome(xn, "neutral", critString, EventOutcomeType.NEUTRAL)); evgroup.Outcomes.Add(generateOutcome(xn, "failure", critString, EventOutcomeType.FAILURE)); evOpt.Results.Add(evgroup); break; } } //Debug.Log("Selected part " + conSelectnum); //Debug.Log("Added conditions " +addedCons); if( conSelectnum != 1) { conSelectnum--; } } //Set flavors switch (eventtype) { case "gathering": switch (location) { case 0: locationXmlString = "mine"; evOpt.locType = Location.MINE; break; case 1: locationXmlString = "quarry"; evOpt.locType = Location.QUARRY; break; case 2: locationXmlString = "wreckage"; evOpt.locType = Location.WRECKAGE; break; case 3: locationXmlString = "factory"; evOpt.locType = Location.FACTORY; break; case 4: locationXmlString = "village"; evOpt.locType = Location.VILLAGE; break; } break; case "research": switch (location) { case 0: locationXmlString = "forest"; evOpt.locType = Location.FOREST; break; case 1: locationXmlString = "rockformation"; evOpt.locType = Location.ROCKFORMATION; break; case 2: locationXmlString = "magicsite"; evOpt.locType = Location.MAGICSITE; break; case 3: locationXmlString = "lake"; evOpt.locType = Location.LAKE; break; case 4: locationXmlString = "ruins"; evOpt.locType = Location.RUINS; break; } break; } evOpt.locationXmlString = locationXmlString; XmlNodeList entryflavs = xmlDoc.SelectNodes("eventstructure/introflavor/" + eventtype + "/"+ locationXmlString + "/flavor"); int[] flSel = DataManager.randomArray(entryflavs.Count); entryFlavor = entryflavs[flSel[0]].InnerText; return evOpt; }
protected override string ActionName(EventOption eventOption) { CodePath.New<RadioButton>().Select(); return CodePath.Last; }
protected override string ActionName(EventOption eventOption) { return MethodNameResolver.NameFor<RadioButton>(r=>r.Select()); }
void ParseDatabaseText(string str) { currentDatabase.Clear(); var eventRegex = new Regex("\\[[\\s\\S]+?(?=;)", RegexOptions.Multiline); var keyAndTextRegex = new Regex("\\[(?<key>.+?)\\] ?(?<flags>{[\\w, !]+})?(\\r\\n)?(?<text>[\\s\\S]+?)(?=<)", RegexOptions.Multiline); var optionRegex = new Regex("(?<flags><[!,\\w ]*>) ?(?<text>[\\s\\S]+?\\]) *(?:\n|\r|\r\n)", RegexOptions.Multiline); var targetRegex = new Regex("\\[(?<target>.+?)\\]", RegexOptions.Multiline); var choiceTextRegex = new Regex("^([\\s\\S]+?(?=\\[))", RegexOptions.Multiline); var flagsRegex = new Regex("!?\\w+"); //var optionFlagsRegex = new Regex("<(?:!?\\w+,?)+>"); var eventMatches = eventRegex.Matches(str); foreach (Match em in eventMatches) { var e = new GameEvent(); var km = keyAndTextRegex.Match(em.Value); e.Key = km.Groups["key"].Value; e.Text = km.Groups["text"].Value; string flags = km.Groups["flags"].Value; var flagMatches = flagsRegex.Matches(flags); foreach (Match fm in flagMatches) { var flag = fm.Value.TrimStart('!'); if (fm.Value.StartsWith("!")) e.Flags.RemoveAll(s=>s == flag); else e.Flags.Add(flag); } var optionMatches = optionRegex.Matches(em.Value); foreach (Match om in optionMatches) { var eo = new EventOption(); var omText = om.Groups["text"]; eo.Text = choiceTextRegex.Match(omText.Value).Value; var flagMatches2 = flagsRegex.Matches(om.Groups["flags"].Value); foreach (Match fm in flagMatches2) { var flag = fm.Value.TrimStart('!'); if (fm.Value.StartsWith("!")) eo.NotAllowedFlags.Add(flag); else eo.RequiredFlags.Add(flag); } var targetMatches = targetRegex.Matches(omText.Value); foreach (Match tm in targetMatches) { eo.Targets.Add(tm.Groups["target"].Value); } e.Options.Add(eo); } currentDatabase.Add(e); } EditorUtility.SetDirty(currentDatabase); }