当前位置: 首页>>代码示例>>C#>>正文


C# Ruleset类代码示例

本文整理汇总了C#中Ruleset的典型用法代码示例。如果您正苦于以下问题:C# Ruleset类的具体用法?C# Ruleset怎么用?C# Ruleset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Ruleset类属于命名空间,在下文中一共展示了Ruleset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckUpgradesValidity

        static void CheckUpgradesValidity(Action<string> emitError, Ruleset rules)
        {
            var upgradesGranted = GetAllGrantedUpgrades(emitError, rules).ToHashSet();

            foreach (var actorInfo in rules.Actors)
            {
                if (actorInfo.Key.StartsWith("^"))
                    continue;

                foreach (var trait in actorInfo.Value.TraitInfos<ITraitInfo>())
                {
                    var fields = trait.GetType().GetFields();
                    foreach (var field in fields.Where(x => x.HasAttribute<UpgradeUsedReferenceAttribute>()))
                    {
                        var values = LintExts.GetFieldValues(trait, field, emitError);
                        foreach (var value in values)
                        {
                            if (!upgradesGranted.Contains(value))
                                emitError("Actor type `{0}` uses upgrade `{1}` that is not granted by anything!".F(actorInfo.Key, value));

                            if (actorInfo.Value.TraitInfoOrDefault<UpgradeManagerInfo>() == null)
                                emitError("Actor type `{0}` uses upgrade `{1}`, but doesn't have the UpgradeManager trait.".F(actorInfo.Key, value));
                        }
                    }
                }
            }
        }
开发者ID:OpenRA,项目名称:OpenRA,代码行数:27,代码来源:CheckUpgrades.cs

示例2: ShowSlotDropDown

		public static void ShowSlotDropDown(Ruleset rules, DropDownButtonWidget dropdown, Session.Slot slot,
			Session.Client client, OrderManager orderManager)
		{
			var options = new Dictionary<string, IEnumerable<SlotDropDownOption>>() {{"Slot", new List<SlotDropDownOption>()
			{
				new SlotDropDownOption("Open", "slot_open "+slot.PlayerReference, () => (!slot.Closed && client == null)),
				new SlotDropDownOption("Closed", "slot_close "+slot.PlayerReference, () => slot.Closed)
			}}};

			var bots = new List<SlotDropDownOption>();
			if (slot.AllowBots)
			{
				foreach (var b in rules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
				{
					var bot = b;
					var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
					bots.Add(new SlotDropDownOption(bot,
						"slot_bot {0} {1} {2}".F(slot.PlayerReference, botController.Index, bot),
						() => client != null && client.Bot == bot));
				}
			}
			options.Add(bots.Any() ? "Bots" : "Bots Disabled", bots);

			Func<SlotDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
			{
				var item = ScrollItemWidget.Setup(itemTemplate,
					o.Selected,
					() => orderManager.IssueOrder(Order.Command(o.Order)));
				item.Get<LabelWidget>("LABEL").GetText = () => o.Title;
				return item;
			};

			dropdown.ShowDropDown<SlotDropDownOption>("LABEL_DROPDOWN_TEMPLATE", 167, options, setupItem);
		}
开发者ID:JackKucan,项目名称:OpenRA,代码行数:34,代码来源:LobbyUtils.cs

示例3: CncInstallMusicLogic

        public CncInstallMusicLogic(Widget widget, Ruleset modRules, Action onExit)
        {
            var installButton = widget.GetOrNull<ButtonWidget>("INSTALL_BUTTON");
            if (installButton != null)
            {
                Action afterInstall = () =>
                {
                    try
                    {
                        var path = new string[] { Platform.SupportDir, "Content", Game.modData.Manifest.Mod.Id }.Aggregate(Path.Combine);
                        GlobalFileSystem.Mount(Path.Combine(path, "scores.mix"));
                        GlobalFileSystem.Mount(Path.Combine(path, "transit.mix"));

                        modRules.Music.Do(m => m.Value.Reload());

                        var musicPlayerLogic = (MusicPlayerLogic)installButton.Parent.LogicObject;
                        musicPlayerLogic.BuildMusicTable();
                    }
                    catch (Exception e)
                    {
                        Log.Write("debug", "Mounting the new mixfile and rebuild of scores list failed:\n{0}", e);
                    }
                };

                installButton.OnClick = () =>
                    Ui.OpenWindow("INSTALL_MUSIC_PANEL", new WidgetArgs() {
                        { "afterInstall", afterInstall },
                        { "filesToCopy", new[] { "SCORES.MIX" } },
                        { "filesToExtract", new[] { "transit.mix" } },
                    });
                installButton.IsVisible = () => modRules.InstalledMusic.ToArray().Length < 3; // HACK around music being split between transit.mix and scores.mix
            }
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:33,代码来源:CncInstallMusicLogic.cs

示例4: TileSelectorLogic

		public TileSelectorLogic(Widget widget, WorldRenderer worldRenderer, Ruleset modRules)
		{
			var tileset = modRules.TileSets[worldRenderer.World.Map.Tileset];

			editor = widget.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
			panel = widget.Get<ScrollPanelWidget>("TILETEMPLATE_LIST");
			itemTemplate = panel.Get<ScrollItemWidget>("TILEPREVIEW_TEMPLATE");
			panel.Layout = new GridLayout(panel);

			var tileCategorySelector = widget.Get<DropDownButtonWidget>("TILE_CATEGORY");
			var categories = tileset.EditorTemplateOrder;
			Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
			{
				var item = ScrollItemWidget.Setup(template,
					() => tileCategorySelector.Text == option,
					() => { tileCategorySelector.Text = option; IntializeTilePreview(widget, worldRenderer, tileset, option); });

				item.Get<LabelWidget>("LABEL").GetText = () => option;
				return item;
			};

			tileCategorySelector.OnClick = () =>
				tileCategorySelector.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, categories, setupItem);

			tileCategorySelector.Text = categories.First();
			IntializeTilePreview(widget, worldRenderer, tileset, categories.First());
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:27,代码来源:TileSelectorLogic.cs

示例5: Run

		public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
		{
			foreach (var actorInfo in rules.Actors)
			{
				var healthTraits = actorInfo.Value.TraitInfos<HealthInfo>().ToList();
				if (!healthTraits.Any())
					continue;

				var targetable = actorInfo.Value.TraitInfos<ITargetableInfo>().SelectMany(x => x.GetTargetTypes()).ToList();
				if (!targetable.Any())
					continue;

				foreach (var weaponInfo in rules.Weapons)
				{
					var warheads = weaponInfo.Value.Warheads.OfType<SpreadDamageWarhead>().Where(dw => dw.Damage > 0);

					foreach (var warhead in warheads)
					{
						// This is a special warhead, like the one on `weathering` in D2k.
						if (!warhead.DamageTypes.Any())
							continue;

						// This warhead cannot affect this actor.
						if (!warhead.ValidTargets.Overlaps(targetable))
							continue;

						if (healthTraits.Where(x => x.Radius.Length > warhead.TargetExtraSearchRadius.Length).Any())
							emitError("Actor type `{0}` has a health radius exceeding the victim scan radius of a warhead on `{1}`!"
								.F(actorInfo.Key, weaponInfo.Key));
					}
				}
			}
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:33,代码来源:CheckTargetHealthRadius.cs

示例6: Run

		public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
		{
			foreach (var actorInfo in rules.Actors)
			{
				if (actorInfo.Key.StartsWith("^"))
					continue;

				var count = actorInfo.Value.TraitInfos<IDefaultVisibilityInfo>().Count();

				if (count == 0)
					emitError("Actor type `{0}` does not define a default visibility type!".F(actorInfo.Key));
				else if (count > 1)
					emitError("Actor type `{0}` defines multiple default visibility types!".F(actorInfo.Key));
				else
				{
					var vis = actorInfo.Value.TraitInfoOrDefault<HiddenUnderShroudInfo>();
					if (vis != null && vis.Type == VisibilityType.Footprint)
					{
						var ios = actorInfo.Value.TraitInfoOrDefault<IOccupySpaceInfo>();
						if (ios == null)
							emitError("Actor type `{0}` defines VisibilityType.Footprint in `{1}` but has no IOccupySpace traits!".F(actorInfo.Key, vis.GetType()));
						else if (!ios.OccupiedCells(actorInfo.Value, CPos.Zero).Any())
							emitError("Actor type `{0}` defines VisibilityType.Footprint in `{1}` but does not have any footprint cells!".F(actorInfo.Key, vis.GetType()));
					}
				}
			}
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:27,代码来源:CheckDefaultVisibility.cs

示例7: LoadMapSettings

        public static void LoadMapSettings(Session.Global gs, Ruleset rules)
        {
            var devMode = rules.Actors["player"].TraitInfo<DeveloperModeInfo>();
            gs.AllowCheats = devMode.Enabled;

            var crateSpawner = rules.Actors["world"].TraitInfoOrDefault<CrateSpawnerInfo>();
            gs.Crates = crateSpawner != null && crateSpawner.Enabled;

            var shroud = rules.Actors["player"].TraitInfo<ShroudInfo>();
            gs.Fog = shroud.FogEnabled;
            gs.Shroud = !shroud.ExploredMapEnabled;

            var resources = rules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
            gs.StartingCash = resources.DefaultCash;

            var startingUnits = rules.Actors["world"].TraitInfoOrDefault<SpawnMPUnitsInfo>();
            gs.StartingUnitsClass = startingUnits == null ? "none" : startingUnits.StartingUnitsClass;

            var mapBuildRadius = rules.Actors["world"].TraitInfoOrDefault<MapBuildRadiusInfo>();
            gs.AllyBuildRadius = mapBuildRadius != null && mapBuildRadius.AllyBuildRadiusEnabled;

            var mapCreeps = rules.Actors["world"].TraitInfoOrDefault<MapCreepsInfo>();
            gs.Creeps = mapCreeps != null && mapCreeps.Enabled;

            var mapOptions = rules.Actors["world"].TraitInfo<MapOptionsInfo>();
            gs.ShortGame = mapOptions.ShortGameEnabled;
            gs.TechLevel = mapOptions.TechLevel;
            gs.Difficulty = mapOptions.Difficulty ?? mapOptions.Difficulties.FirstOrDefault();
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:29,代码来源:LobbyCommands.cs

示例8: CheckUpgradesUsage

        static void CheckUpgradesUsage(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
        {
            var upgradesUsed = GetAllUsedUpgrades(emitError, rules).ToHashSet();

            // Check all upgrades granted by traits.
            foreach (var actorInfo in rules.Actors)
            {
                foreach (var trait in actorInfo.Value.TraitInfos<ITraitInfo>())
                {
                    var fields = trait.GetType().GetFields();
                    foreach (var field in fields.Where(x => x.HasAttribute<UpgradeGrantedReferenceAttribute>()))
                    {
                        var values = LintExts.GetFieldValues(trait, field, emitError);
                        foreach (var value in values.Where(x => !upgradesUsed.Contains(x)))
                            emitWarning("Actor type `{0}` grants upgrade `{1}` that is not used by anything!".F(actorInfo.Key, value));
                    }
                }
            }

            // Check all upgrades granted by warheads.
            foreach (var weapon in rules.Weapons)
            {
                foreach (var warhead in weapon.Value.Warheads)
                {
                    var fields = warhead.GetType().GetFields();
                    foreach (var field in fields.Where(x => x.HasAttribute<UpgradeGrantedReferenceAttribute>()))
                    {
                        var values = LintExts.GetFieldValues(warhead, field, emitError);
                        foreach (var value in values.Where(x => !upgradesUsed.Contains(x)))
                            emitWarning("Weapon type `{0}` grants upgrade `{1}` that is not used by anything!".F(weapon.Key, value));
                    }
                }
            }
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:34,代码来源:CheckUpgrades.cs

示例9: Run

        public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
        {
            foreach (var weaponInfo in rules.Weapons)
            {
                var missile = weaponInfo.Value.Projectile as MissileInfo;
                if (missile != null)
                {
                    var minAngle = missile.MinimumLaunchAngle.Angle;
                    var maxAngle = missile.MaximumLaunchAngle.Angle;

                    // If both angles are identical, we only need to test one of them
                    var testMaxAngle = minAngle != maxAngle;
                    CheckLaunchAngles(weaponInfo.Key, minAngle, testMaxAngle, maxAngle, emitError);
                }

                var bullet = weaponInfo.Value.Projectile as BulletInfo;
                if (bullet != null)
                {
                    var minAngle = bullet.LaunchAngle[0].Angle;
                    var maxAngle = bullet.LaunchAngle.Length > 1 ? bullet.LaunchAngle[1].Angle : minAngle;

                    // If both angles are identical, we only need to test one of them
                    var testMaxAngle = minAngle != maxAngle;
                    CheckLaunchAngles(weaponInfo.Key, minAngle, testMaxAngle, maxAngle, emitError);
                }
            }
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:27,代码来源:CheckAngle.cs

示例10: story_data_is_observed_during_invocation

        public void story_data_is_observed_during_invocation()
        {
            var data = new List<KeyValuePair<string, object>>()
            {
                new KeyValuePair<string, object>("bool_value", true),
                new KeyValuePair<string, object>("int_value", 123),
                new KeyValuePair<string, object>("string_value", "test!"),
            };

            var handlerRules = new Ruleset<IStory, IStoryHandler>()
            {
                Rules = {
                    new PredicateRule(
                        _ => true,                                                              // always run for story
                        _ => new ActionHandler(
                            (story) => Assert.AreEqual(0, story.Data.Count()),                  // make sure OnStart() is invoked with zero data items.
                            (story, task) => Assert.IsTrue(data.SequenceEqual(story.Data)))     // make sure OnStop() is invoked with 3 data items.
                    ),
                },
            };

            new Story("testStory", handlerRules).Run(story =>
            {
                foreach (var kvp in data)
                {
                    story.Data[kvp.Key] = kvp.Value;
                }
            });
        }
开发者ID:amitapl,项目名称:logmetry,代码行数:29,代码来源:CoreTests.cs

示例11: Run

		public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
		{
			foreach (var weaponInfo in rules.Weapons)
			{
				var warheads = weaponInfo.Value.Warheads.OfType<SpawnActorWarhead>().ToList();

				foreach (var warhead in warheads)
				{
					foreach (var a in warhead.Actors)
					{
						if (!rules.Actors.ContainsKey(a.ToLowerInvariant()))
						{
							emitError("Warhead type {0} tries to spawn invalid actor {1}!"
							.F(weaponInfo.Key, a));
							break;
						}

						if (!rules.Actors[a.ToLowerInvariant()].HasTraitInfo<IPositionableInfo>())
							emitError("Warhead type {0} tries to spawn unpositionable actor {1}!"
							.F(weaponInfo.Key, a));

						if (!rules.Actors[a.ToLowerInvariant()].HasTraitInfo<ParachutableInfo>() && warhead.Paradrop == true)
							emitError("Warhead type {0} tries to paradrop actor {1} which doesn't have the Parachutable trait!"
							.F(weaponInfo.Key, a));
					}
				}
			}
		}
开发者ID:GraionDilach,项目名称:OpenRA.Mods.AS,代码行数:28,代码来源:CheckSpawnActorWarheads.cs

示例12: ScrollItemWidget

 public ScrollItemWidget(Ruleset modRules)
     : base(modRules)
 {
     IsVisible = () => false;
     VisualHeight = 0;
     IgnoreChildMouseOver = true;
 }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:7,代码来源:ScrollItemWidget.cs

示例13: Run

		public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
		{
			foreach (var actorInfo in rules.Actors)
			{
				var healthTraits = actorInfo.Value.TraitInfos<HealthInfo>().ToList();
				if (!healthTraits.Any())
					continue;

				var targetable = actorInfo.Value.TraitInfos<ITargetableInfo>().SelectMany(x => x.GetTargetTypes()).ToList();
				if (!targetable.Any())
					continue;

				foreach (var weaponInfo in rules.Weapons)
				{
					var warheadAS = weaponInfo.Value.Warheads.OfType<WarheadAS>();

					foreach (var wh in warheadAS)
					{
						// This warhead cannot affect this actor.
						if (!wh.ValidTargets.Overlaps(targetable))
							continue;

						if (healthTraits.Any(x => x.Shape.OuterRadius.Length > wh.TargetSearchRadius.Length))
							emitError("Actor type `{0}` has a health radius exceeding the victim scan radius of an AS warhead on `{1}`!"
								.F(actorInfo.Key, weaponInfo.Key));
					}
				}
			}
		}
开发者ID:GraionDilach,项目名称:OpenRA.Mods.AS,代码行数:29,代码来源:CheckTargetHealthRadiusAS.cs

示例14: Run

 public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
 {
     foreach (var actorData in D2kMapImporter.ActorDataByActorCode.Values)
     {
         if (!rules.Actors.ContainsKey(actorData.First))
             emitError("Undefined actor {0} in map import code.".F(actorData.First));
     }
 }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:8,代码来源:CheckImportActors.cs

示例15: story_exception_thrown_is_propagated

        public void story_exception_thrown_is_propagated()
        {
            var handlerRules = new Ruleset<IStory, IStoryHandler>();

            new Story("testStory", handlerRules).Run(story =>
            {
                throw new InvalidOperationException("oh oh");
            });
        }
开发者ID:amitapl,项目名称:logmetry,代码行数:9,代码来源:CoreTests.cs


注:本文中的Ruleset类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。