Пример #1
0
        private static void InsertElement(IElementContainer <ISequentialElement> sequentialContainer, IFileElement newElement, ISequentialElement origElement)
        {
            ISequentialElement seqElement = sequentialContainer.AddElement(newElement);

            seqElement.MaximumRandomStartDelay = origElement.MaximumRandomStartDelay;
            seqElement.FixedStartDelay         = origElement.FixedStartDelay;
        }
Пример #2
0
        private void OneOf(IElementContainer subContainer, params Expression <Action <IRule> >[] actions)
        {
            IAlternatives alternatives = new Alternatives();

            SaveCurrentContainer();
            SetContainer(subContainer ?? alternatives);

            // If there is more than one action, then
            // we need to "alternate" between them
            if (actions.Length > 1 && subContainer != null)
            {
                subContainer.AddElement(alternatives);
                SetContainer(alternatives);
            }

            SaveCurrentSequence();

            foreach (var action in actions)
            {
                ResetSequence();
                action.Compile()(this);
            }

            RestoreSequence();

            RestoreContainer();
            AddElementToContainer(subContainer ?? alternatives);
        }
Пример #3
0
        internal void AddElementToContainer(IElement element)
        {
            // Because we can't tell ahead of time if there will be
            // more than one element added to an element container,
            // we need to check at run-time.
            //
            // If the provided element is the first in the chain, we
            // assume it's the only one, and simply add it to the
            // container (whatever type that may be).
            // If a second element comes along, and it needs to go
            // in that container, then that means there is a
            // "sequence" of elements. Remove the first element
            // that was added earlier, add it and the new element
            // to a new sequence object, and put the sequence
            // into the container.
            //
            // Example of a "chain" (probably not the best term):
            //
            // |-- 0 --|------------ 1 ------------|-- 2 --| // <-- Chain #
            // Say("X").Optionally(r => r.Say("Y")).Say("Z")

            if (_countInChain == 1)
            {
                ISequence sequence = new Sequence();

                sequence.AddElement(_container.Pop());
                sequence.AddElement(element);

                _container.AddElement(sequence);
                _currentSequence = sequence;
            }
            else if (_countInChain > 1)
            {
                _currentSequence.AddElement(element);
            }
            else
            {
                _container.AddElement(element);
            }

            _countInChain++;
        }
Пример #4
0
        public IModeElement GetModeElementDefinition(ITargetDirectoryProvider targetDirectoryProvider)
        {
            IElementContainer <IParallelElement> container = DataModule.ElementFactory.CreateParallelContainer("Test-Szenario");
            IModeElement modeElement = DataModule.ElementFactory.CreateModeElement("Test-Szenario", container);

            IRandomBackgroundMusicList music = DataModule.ElementFactory.CreateRandomBackgroundMusicList("Musik");

            container.AddElement(music);

            IBackgroundSounds sounds = DataModule.ElementFactory.CreateBackgroundSounds("Sounds");

            container.AddElement(sounds);

            IBackgroundSoundChoice soundChoice1 = sounds.AddElement("Auswahl 1");

            music.AddElement(DataModule.ElementFactory.CreateFileElement(targetDirectoryProvider.GetPathWithinLibrary(m_MusicResource), SoundFileType.Music));
            soundChoice1.AddElement(DataModule.ElementFactory.CreateFileElement(targetDirectoryProvider.GetPathWithinLibrary(m_SoundResource), SoundFileType.SoundEffect));

            return(modeElement);
        }
Пример #5
0
		//----------------------------------------------------------------------
		//  Now we recursively decend the Mobile/Item hierarchy, allowing sub
		//  containment (when it makes sense):
		//----------------------------------------------------------------------
		private static void AddRecursiveMobilesAndItems(
			XmlNode parentNode,
			XmlNode childNode,
			IElementContainer elementContainer
			)
		{
			bool reject = false;
			string probability = "1.0";
			string pick = "";
			string n = "1";
			string id = "0";
			string forceAttack = "false";
			string effectStr = "None";

			try { probability = childNode.Attributes["p"].Value; }
			catch { }
			try { n = childNode.Attributes["n"].Value; }
			catch { }
			try { id = childNode.Attributes["id"].Value; }
			catch { }
			try { forceAttack = childNode.Attributes["forceAttack"].Value; }
			catch { }
			try { effectStr = childNode.Attributes["effect"].Value; }
			catch { }

			string[] effectOptions = effectStr.Split( ':' );
			string effect = effectOptions[0];
			string effectHue = "0";
			if( effectOptions.Length > 1 ) effectHue = effectOptions[1];

			try { pick = childNode.Attributes["pick"].Value; }
			catch
			{
				Console.WriteLine( "Attempted to add an element without a pick at {0}. IGNORING.",
					childNode.Attributes["lineNumber"].Value
					);
				return;
			}

			if( parentNode.Name == "Item" && childNode.Name == "Mobile" ) reject = true;

			//------------------------------------------------------------------
			//  I anticpate more rejection reasons; in any case, the message is decoupled 
			//  entirely from the reason...
			//------------------------------------------------------------------

			if( reject )
			{
				Console.WriteLine(
					"RandomEncounters: Tried to add {0} \"{1}\" to {2} at {3}. THIS IS ILLEGAL. IGNORED.",
					childNode.Name,
					pick,
					parentNode.Name,
					childNode.Attributes["lineNumber"].Value
					);
				return;
			}

			string[] tokens = n.Split( new Char[] { ':' } ); // splits to min:max, or just n if no ':'

			EncounterElement newElement =
				new EncounterElement(
					childNode,
					probability,
					pick,
					id,
					tokens[0],
					(tokens.Length > 1 ? tokens[1] : tokens[0]),
					forceAttack,
					effect,
					effectHue
					);

			XmlNodeList subNodes = childNode.SelectNodes( "Mobile | Item | Prop" );

			//----------------------------------------------
			// Now iterate over subelements
			//----------------------------------------------
			foreach( XmlNode subNode in subNodes )
			{
				if( subNode.Name == "Prop" ) AddProp( childNode, subNode, newElement );

				else AddRecursiveMobilesAndItems(
					childNode,
					subNode,
					newElement
					);
			}

			elementContainer.AddElement( newElement );
		}
Пример #6
0
        private static void InsertElement(IElementContainer <IChoiceElement> choiceContainer, IFileElement newElement, IChoiceElement origElement)
        {
            IChoiceElement choiceElement = choiceContainer.AddElement(newElement);

            choiceElement.RandomChance = origElement.RandomChance;
        }