本文整理汇总了C#中World.ActorsWithTrait方法的典型用法代码示例。如果您正苦于以下问题:C# World.ActorsWithTrait方法的具体用法?C# World.ActorsWithTrait怎么用?C# World.ActorsWithTrait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World.ActorsWithTrait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SupportPowerTimerWidget
public SupportPowerTimerWidget(World world)
{
powers = world.ActorsWithTrait<SupportPowerManager>()
.Where(p => !p.Actor.IsDead() && !p.Actor.Owner.NonCombatant)
.SelectMany(s => s.Trait.Powers.Values)
.Where(p => p.Instances.Any() && p.Info.DisplayTimer && !p.Disabled);
}
示例2: ActorsBitmap
public static Bitmap ActorsBitmap(World world)
{
var map = world.Map;
var b = map.Bounds;
var size = Exts.NextPowerOf2(Math.Max(b.Width, b.Height));
var bitmap = new Bitmap(size, size);
var bitmapData = bitmap.LockBits(bitmap.Bounds(),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe
{
var colors = (int*)bitmapData.Scan0;
var stride = bitmapData.Stride / 4;
foreach (var t in world.ActorsWithTrait<IRadarSignature>())
{
if (world.FogObscures(t.Actor))
continue;
var color = t.Trait.RadarSignatureColor(t.Actor);
foreach (var cell in t.Trait.RadarSignatureCells(t.Actor))
{
var uv = Map.CellToMap(map.TileShape, cell);
if (b.Contains(uv.X, uv.Y))
colors[(uv.Y - b.Top) * stride + uv.X - b.Left] = color.ToArgb();
}
}
}
bitmap.UnlockBits(bitmapData);
return bitmap;
}
示例3: ActorsBitmap
public static Bitmap ActorsBitmap(World world)
{
var map = world.Map;
var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
var bitmap = new Bitmap(size, size);
var bitmapData = bitmap.LockBits(bitmap.Bounds(),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe
{
int* c = (int*)bitmapData.Scan0;
foreach (var t in world.ActorsWithTrait<IRadarSignature>())
{
if (world.FogObscures(t.Actor))
continue;
var color = t.Trait.RadarSignatureColor(t.Actor);
foreach (var cell in t.Trait.RadarSignatureCells(t.Actor))
if (world.Map.IsInMap(cell))
*(c + ((cell.Y - world.Map.Bounds.Top) * bitmapData.Stride >> 2) + cell.X - world.Map.Bounds.Left) = color.ToArgb();
}
}
bitmap.UnlockBits(bitmapData);
return bitmap;
}
示例4: IngameRadarDisplayLogic
public IngameRadarDisplayLogic(Widget widget, World world)
{
var radarEnabled = false;
var cachedRadarEnabled = false;
var blockColor = Color.Transparent;
var radar = widget.Get<RadarWidget>("RADAR_MINIMAP");
radar.IsEnabled = () => radarEnabled;
var devMode = world.LocalPlayer.PlayerActor.Trait<DeveloperMode>();
var ticker = widget.Get<LogicTickerWidget>("RADAR_TICKER");
ticker.OnTick = () =>
{
radarEnabled = devMode.DisableShroud || world.ActorsWithTrait<ProvidesRadar>()
.Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
if (radarEnabled != cachedRadarEnabled)
Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", radarEnabled ? "RadarUp" : "RadarDown", null);
cachedRadarEnabled = radarEnabled;
};
var block = widget.GetOrNull<ColorBlockWidget>("RADAR_FADETOBLACK");
if (block != null)
{
radar.Animating = x => blockColor = Color.FromArgb((int)(255 * x), Color.Black);
block.IsVisible = () => blockColor.A != 0;
block.GetColor = () => blockColor;
}
}
示例5: Render
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
{
var jamsMissiles = ai.TraitInfoOrDefault<JamsMissilesInfo>();
if (jamsMissiles != null)
{
yield return new RangeCircleRenderable(
centerPosition,
jamsMissiles.Range,
0,
Color.FromArgb(128, Color.Red),
Color.FromArgb(96, Color.Black));
}
var jamsRadar = ai.TraitInfoOrDefault<JamsRadarInfo>();
if (jamsRadar != null)
{
yield return new RangeCircleRenderable(
centerPosition,
jamsRadar.Range,
0,
Color.FromArgb(128, Color.Blue),
Color.FromArgb(96, Color.Black));
}
foreach (var a in w.ActorsWithTrait<RenderJammerCircle>())
if (a.Actor.Owner.IsAlliedWith(w.RenderPlayer))
foreach (var r in a.Trait.RenderAfterWorld(wr))
yield return r;
}
示例6: Explode
void Explode(World world)
{
world.AddFrameEndTask(w => w.Remove(this));
Combat.DoExplosion(firedBy.PlayerActor, weapon, pos);
world.WorldActor.Trait<ScreenShaker>().AddEffect(20, pos, 5);
foreach (var a in world.ActorsWithTrait<NukePaletteEffect>())
a.Trait.Enable();
}
示例7: Render
public void Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
{
wr.DrawRangeCircleWithContrast(
Color.FromArgb(128, Color.Cyan),
wr.ScreenPxPosition(centerPosition),
ai.Traits.Get<CreatesShroudInfo>().Range,
Color.FromArgb(96, Color.Black));
foreach (var a in w.ActorsWithTrait<RenderShroudCircle>())
if (a.Actor.Owner == a.Actor.World.LocalPlayer)
a.Trait.RenderAfterWorld(wr);
}
示例8: Render
public void Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
{
var jamsMissiles = ai.Traits.GetOrDefault<JamsMissilesInfo>();
if (jamsMissiles != null)
RenderJammerCircle.DrawRangeCircle(wr, centerPosition, jamsMissiles.Range, Color.Red);
var jamsRadar = ai.Traits.GetOrDefault<JamsRadarInfo>();
if (jamsRadar != null)
RenderJammerCircle.DrawRangeCircle(wr, centerPosition, jamsRadar.Range, Color.Blue);
foreach (var a in w.ActorsWithTrait<RenderJammerCircle>())
if (a.Actor.Owner == a.Actor.World.LocalPlayer)
a.Trait.RenderAfterWorld(wr);
}
示例9: Render
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
{
yield return new RangeCircleRenderable(
centerPosition,
Range,
0,
Color,
Color.FromArgb(96, Color.Black));
foreach (var a in w.ActorsWithTrait<WithRangeCircle>())
if (a.Actor.Owner.IsAlliedWith(w.RenderPlayer) && a.Trait.Info.Type == Type)
foreach (var r in a.Trait.RenderAfterWorld(wr))
yield return r;
}
示例10: Render
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
{
yield return new RangeCircleRenderable(
centerPosition,
ai.TraitInfo<CreatesShroudInfo>().Range,
0,
Color.FromArgb(128, Color.Cyan),
Color.FromArgb(96, Color.Black));
foreach (var a in w.ActorsWithTrait<RenderShroudCircle>())
if (a.Actor.Owner.IsAlliedWith(w.RenderPlayer))
foreach (var r in a.Trait.RenderAfterWorld(wr))
yield return r;
}
示例11: SupportPowerTimerWidget
public SupportPowerTimerWidget(World world)
{
powers = world.ActorsWithTrait<SupportPowerManager>()
.Where(p => !p.Actor.IsDead && !p.Actor.Owner.NonCombatant)
.SelectMany(s => s.Trait.Powers.Values)
.Where(p => p.Instances.Any() && p.Info.DisplayTimerStances != Stance.None && !p.Disabled);
// Timers in replays should be synced to the effective game time, not the playback time.
timestep = world.Timestep;
if (world.IsReplay)
timestep = world.WorldActor.Trait<MapOptions>().GameSpeed.Timestep;
bgDark = ChromeMetrics.Get<Color>("TextContrastColorDark");
bgLight = ChromeMetrics.Get<Color>("TextContrastColorLight");
}
示例12: SupportPowerTimerWidget
public SupportPowerTimerWidget(World world)
{
powers = world.ActorsWithTrait<SupportPowerManager>()
.Where(p => !p.Actor.IsDead && !p.Actor.Owner.NonCombatant)
.SelectMany(s => s.Trait.Powers.Values)
.Where(p => p.Instances.Any() && p.Info.DisplayTimer && !p.Disabled);
// Timers in replays should be synced to the effective game time, not the playback time.
timestep = world.Timestep;
if (world.IsReplay)
{
GameSpeed speed;
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>();
if (gameSpeeds.Speeds.TryGetValue(world.LobbyInfo.GlobalSettings.GameSpeedType, out speed))
timestep = speed.Timestep;
}
}
示例13: WorldLoaded
public void WorldLoaded(World w, WorldRenderer wr)
{
bridges = new CellLayer<Bridge>(w.Map);
// Build a list of templates that should be overlayed with bridges
foreach (var bridge in info.Bridges)
{
var bi = w.Map.Rules.Actors[bridge].TraitInfo<BridgeInfo>();
foreach (var template in bi.Templates)
bridgeTypes.Add(template.First, Pair.New(bridge, template.Second));
}
// Take all templates to overlay from the map
foreach (var cell in w.Map.AllCells.Where(cell => bridgeTypes.ContainsKey(w.Map.MapTiles.Value[cell].Type)))
ConvertBridgeToActor(w, cell);
// Link adjacent (long)-bridges so that artwork is updated correctly
foreach (var p in w.ActorsWithTrait<Bridge>())
p.Trait.LinkNeighbouringBridges(w, this);
}
示例14: Chronoshift
public static void Chronoshift(World world, List<Pair<Actor, int2>>units, Actor chronosphere, int duration, bool killCargo)
{
if (chronosphere != null)
chronosphere.Trait<RenderBuilding>().PlayCustomAnim(chronosphere, "active");
// Trigger screen desaturate effect
foreach (var a in world.ActorsWithTrait<ChronoshiftPaletteEffect>())
a.Trait.Enable();
Sound.Play("chrono2.aud", units.First().First.CenterLocation);
foreach (var kv in units)
{
var target = kv.First;
var targetCell = kv.Second;
var cs = target.Trait<Chronoshiftable>();
if (cs.CanChronoshiftTo(target, targetCell, true))
cs.Teleport(target, targetCell, duration, killCargo,chronosphere);
}
}
示例15: GetLineBuildCells
public static IEnumerable<CPos> GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi)
{
var lbi = world.Map.Rules.Actors[name].Traits.Get<LineBuildInfo>();
var topLeft = location; // 1x1 assumption!
if (world.IsCellBuildable(topLeft, bi))
yield return topLeft;
// Start at place location, search outwards
// TODO: First make it work, then make it nice
var vecs = new[] { new CVec(1, 0), new CVec(0, 1), new CVec(-1, 0), new CVec(0, -1) };
int[] dirs = { 0, 0, 0, 0 };
for (int d = 0; d < 4; d++)
{
for (int i = 1; i < lbi.Range; i++)
{
if (dirs[d] != 0)
continue;
var cell = topLeft + i * vecs[d];
if (world.IsCellBuildable(cell, bi))
continue; // Cell is empty; continue search
// Cell contains an actor. Is it the type we want?
if (world.ActorsWithTrait<LineBuildNode>().Any(a =>
(
a.Actor.Location == cell &&
a.Actor.Info.Traits.Get<LineBuildNodeInfo>().Types.Intersect(lbi.NodeTypes).Any()
)))
dirs[d] = i; // Cell contains actor of correct type
else
dirs[d] = -1; // Cell is blocked by another actor type
}
// Place intermediate-line sections
if (dirs[d] > 0)
for (int i = 1; i < dirs[d]; i++)
yield return topLeft + i * vecs[d];
}
}