コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,EventId,isFavorite")] EventOption eventOption)
        {
            if (id != eventOption.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(eventOption);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EventOptionExists(eventOption.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EventId"] = new SelectList(_context.Event, "Id", "Name", eventOption.EventId);
            return(View(eventOption));
        }
コード例 #2
0
ファイル: EventService.cs プロジェクト: VismaLietuva/simoona
        private void MapNewOptions(CreateEventDto newEventDto, Event newEvent)
        {
            if (newEventDto.NewOptions == null)
            {
                return;
            }

            foreach (var option in newEventDto.NewOptions)
            {
                if (option == null)
                {
                    continue;
                }

                var newOption = new EventOption
                {
                    Created    = DateTime.UtcNow,
                    CreatedBy  = newEventDto.UserId,
                    Modified   = DateTime.UtcNow,
                    ModifiedBy = newEventDto.UserId,
                    Option     = option.Option,
                    Rule       = option.Rule,
                    Event      = newEvent
                };

                _eventOptionsDbSet.Add(newOption);
            }
        }
コード例 #3
0
        // GET: InviteeTables/Create
        public async Task <int> RunAlgo()
        {
            if (!isDataValid())
            {
                throw new Exception(" ");
            }

            result = algo.RunAlgo(AlgoDbCreation()).getGens().ToList();

            EventOption eventOption = new EventOption(GetEventByID(MyGlobals.GlobalEventID));

            foreach (var item in result)
            {
                InviteeTable inviteeTable = new InviteeTable(item.invitee, item.table, eventOption, GetEventByID(MyGlobals.GlobalEventID));
                var          result       = _context.Add(inviteeTable);
            }

            var result2 = await _context.SaveChangesAsync();

            ViewData["EventId"]       = new SelectList(_context.Event, "Id", "Name");
            ViewData["EventOptionId"] = new SelectList(_context.EventOption, "Id", "Id");
            ViewData["InviteeId"]     = new SelectList(_context.Invitee, "Id", "FirstName");
            ViewData["TableId"]       = new SelectList(_context.Table, "Id", "Id");
            ViewData["CurrentEvent"]  = MyGlobals.GlobalEventName;

            return(eventOption.Id);
        }
コード例 #4
0
        public ActionResult Create(EventOption evOption)
        {
            if (ModelState.IsValid)
            {
                try {
                    evOption.EmailOption = true;
                    if (fsWebService.CreateEventOption(evOption) != null)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        this.AddModelError(string.Format(Errors.ERROR_EVENTOPTION_CREATE_UNEXPECTED, evOption.EventOptionName), _logger);
                    }
                }
                catch (Exception ex) {
                    this.AddModelError(ex.Message, _logger, ex);
                }
            }
            else
            {
                this.AddModelError(ModelState.Values.SelectMany(v => v.Errors).ToList(), _logger);
            }

            return(View("Modify", evOption));
        }
コード例 #5
0
ファイル: EventService.cs プロジェクト: VismaLietuva/simoona
        private void UpdateEventOptions(EditEventDto editedEvent, Event @event)
        {
            foreach (var editedOption in editedEvent.EditedOptions)
            {
                var option = @event.EventOptions.Single(o => o.Id == editedOption.Id);
                option.Option = editedOption.Option;
            }

            var removedOptions = @event.EventOptions.Where(o => !editedEvent.EditedOptions.Select(x => x.Id).Contains(o.Id)).ToList();

            foreach (var option in removedOptions)
            {
                _eventOptionsDbSet.Remove(option);
            }

            foreach (var newOption in editedEvent.NewOptions)
            {
                var option = new EventOption
                {
                    Option     = newOption.Option,
                    Rule       = newOption.Rule,
                    EventId    = editedEvent.Id,
                    Created    = DateTime.UtcNow,
                    CreatedBy  = editedEvent.UserId,
                    Modified   = DateTime.UtcNow,
                    ModifiedBy = editedEvent.UserId
                };

                _eventOptionsDbSet.Add(option);
            }
        }
コード例 #6
0
        public void combatAction()
        {
            EventOptionAction action = new StartCombatAction();

            EventOption e = new EventOption(action);

            e.choose();
            LogAssert.Expect(LogType.Log, "combat started");
        }
コード例 #7
0
 private ActionResult Modify(int id)
 {
     try {
         EventOption evOption = (id != 0) ? fsWebService.GetEventOption(id) : null;
         return((evOption != null) ? View("Modify", evOption) : View("Modify"));
     }
     catch (Exception ex) {
         FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
         return(HttpNotFound(ex.Message));
     }
 }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("Id,EventId,isFavorite")] EventOption eventOption)
        {
            if (ModelState.IsValid)
            {
                _context.Add(eventOption);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EventId"] = new SelectList(_context.Event, "Id", "Name", eventOption.EventId);
            return(View(eventOption));
        }
コード例 #9
0
        public void choosenEvent()
        {
            EventOptionAction action = new StartCombatAction();

            EventOption e       = new EventOption(action);
            bool        choosen = false;

            e.choosen += (sender, args) => choosen = true;

            e.choose();

            Assert.IsTrue(choosen);
        }
コード例 #10
0
 protected override string ActionName(EventOption eventOption)
 {
     return "Node( " + PathTo(selectedNode) + ")." + SelectEventName;
 }
コード例 #11
0
ファイル: UserEvent.cs プロジェクト: tmandersson/FastGTD
 protected abstract string ActionName(EventOption eventOption);
コード例 #12
0
ファイル: UserEvent.cs プロジェクト: tmandersson/FastGTD
 public virtual void WriteTo(EventWriter eventWriter, EventOption eventOption)
 {
     eventWriter.Write(UIItemType, ActionName(eventOption), uiItem.PrimaryIdentification, ActionParameters);
 }
コード例 #13
0
 public void SetupOptionButton(EventOption eventOption)
 {
     Description.text = eventOption.OptionDescription;
     Button.onClick.AddListener(() => UiEventHandler.FireOptionSelectedEvent(eventOption));
 }
コード例 #14
0
 protected override string ActionName(EventOption eventOption)
 {
     return CachedMethodName;
 }
コード例 #15
0
		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;
		}
コード例 #16
0
 protected override string ActionName(EventOption eventOption)
 {
     string lookupNode = "Node(" + PathTo(clickedNode) + ").";
     return isExpanded ? lookupNode + ExpandEventName : lookupNode + CollapseEventName;
 }
コード例 #17
0
		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;
		}
コード例 #18
0
	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);
	}
コード例 #19
0
ファイル: ExceptionEvent.cs プロジェクト: tmandersson/FastGTD
 protected override string ActionName(EventOption eventOption)
 {
     return exception.ToString();
 }
コード例 #20
0
ファイル: RadioButtonEvent.cs プロジェクト: EricBlack/White
 protected override string ActionName(EventOption eventOption)
 {
     return MethodNameResolver.NameFor<RadioButton>(r=>r.Select());
 }
コード例 #21
0
ファイル: TextBoxEvent.cs プロジェクト: huangzhichong/White
 protected override string ActionName(EventOption eventOption)
 {
     return eventOption.BulkText ? BulkTextAction : TextAction;
 }
コード例 #22
0
 protected override string ActionName(EventOption eventOption)
 {
     CodePath.New<RadioButton>().Select();
     return CodePath.Last;
 }
コード例 #23
0
ファイル: TabEvent.cs プロジェクト: tmandersson/FastGTD
 protected override string ActionName(EventOption eventOption)
 {
     return action;
 }
コード例 #24
0
ファイル: Event.cs プロジェクト: theorclord/ThesisApp
    /// <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;
    }