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


C# Actor.TraitOrDefault方法代码示例

本文整理汇总了C#中Actor.TraitOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Actor.TraitOrDefault方法的具体用法?C# Actor.TraitOrDefault怎么用?C# Actor.TraitOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Actor的用法示例。


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

示例1: Tick

        public override Activity Tick(Actor self)
        {
            if (IsCanceled || !target.IsValidFor(self))
                return NextActivity;

            var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
            var reloads = self.TraitOrDefault<Reloads>();
            if (limitedAmmo != null && !limitedAmmo.HasAmmo() && reloads == null)
                return Util.SequenceActivities(new HeliReturn(), NextActivity);

            var helicopter = self.Trait<Helicopter>();
            var attack = self.Trait<AttackHeli>();
            var dist = target.CenterPosition - self.CenterPosition;

            // Can rotate facing while ascending
            var desiredFacing = Util.GetFacing(dist, helicopter.Facing);
            helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.ROT);

            if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude))
                return this;

            // Fly towards the target
            if (!target.IsInRange(self.CenterPosition, attack.GetMaximumRange()))
                helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(desiredFacing));

            attack.DoAttack(self, target);

            return this;
        }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:29,代码来源:HeliAttack.cs

示例2: Killed

        public void Killed(Actor self, AttackInfo e)
        {
            self.World.AddFrameEndTask(w =>
            {
                var td = new TypeDictionary()
                {
                    new LocationInit( self.Location ),
                    new CenterLocationInit(self.CenterLocation),
                    new OwnerInit( self.Owner ),
                    new SkipMakeAnimsInit()
                };

                // Allows the husk to drag to its final position
                var mobile = self.TraitOrDefault<Mobile>();
                if (mobile != null)
                {
                    if (!mobile.CanEnterCell(self.Location, self, false)) return;
                    td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location)));
                }

                var facing = self.TraitOrDefault<IFacing>();
                if (facing != null)
                    td.Add(new FacingInit( facing.Facing ));

                var turreted = self.TraitOrDefault<Turreted>();
                if (turreted != null)
                    td.Add( new TurretFacingInit(turreted.turretFacing) );

                var huskActor = self.TraitsImplementing<IHuskModifier>()
                    .Select(ihm => ihm.HuskActor(self))
                    .FirstOrDefault(a => a != null);

                w.CreateActor(huskActor ?? Info.HuskActor, td);
            });
        }
开发者ID:Iran,项目名称:ClassicRA,代码行数:35,代码来源:LeavesHusk.cs

示例3: Tick

        public override Activity Tick(Actor self)
        {
            var capturing = self.TraitOrDefault<Capturable>();
            if (capturing != null && capturing.CaptureInProgress) return NextActivity;

            var h = self.TraitOrDefault<Health>();
            var si = self.Info.Traits.Get<SellableInfo>();
            var pr = self.Owner.PlayerActor.Trait<PlayerResources>();

            var cost = self.GetSellValue();

            var refund = (cost * si.RefundPercent * (h == null ? 1 : h.HP)) / (100 * (h == null ? 1 : h.MaxHP));
            pr.GiveCash(refund);

            foreach (var ns in self.TraitsImplementing<INotifySold>())
                ns.Sold(self);

            if (refund > 0 && self.World.LocalPlayer != null && self.Owner.Stances[self.World.LocalPlayer] == Stance.Ally)
                self.World.AddFrameEndTask(
                    w => w.Add(new CashTick(refund, 30, 2,
                        self.CenterLocation,
                        self.Owner.ColorRamp.GetColor(0))));

            self.Destroy();
            return this;
        }
开发者ID:sonygod,项目名称:OpenRA-Dedicated-20120504,代码行数:26,代码来源:Sell.cs

示例4: Tick

        public override Activity Tick(Actor self)
        {
            if (IsCanceled) return NextActivity;
            if (!target.IsValid) return NextActivity;

            var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
            var reloads = self.TraitOrDefault<Reloads>();
            if (limitedAmmo != null && !limitedAmmo.HasAmmo() && reloads == null)
                return Util.SequenceActivities( new HeliReturn(), NextActivity );

            var aircraft = self.Trait<Aircraft>();
            var info = self.Info.Traits.Get<HelicopterInfo>();
            if (aircraft.Altitude != info.CruiseAltitude)
            {
                aircraft.Altitude += Math.Sign(info.CruiseAltitude - aircraft.Altitude);
                return this;
            }

            var attack = self.Trait<AttackHeli>();
            var range = attack.GetMaximumRange() * 0.625f;
            var dist = target.CenterLocation - self.CenterLocation;

            var desiredFacing = Util.GetFacing(dist, aircraft.Facing);
            aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);

            if( !float2.WithinEpsilon( float2.Zero, dist, range * Game.CellSize ) )
                aircraft.TickMove( 1024 * aircraft.MovementSpeed, desiredFacing );

            attack.DoAttack( self, target );

            return this;
        }
开发者ID:sonygod,项目名称:OpenRA-Dedicated-20120504,代码行数:32,代码来源:HeliAttack.cs

示例5: Tick

        public override Activity Tick(Actor self)
        {
            if (!target.IsValidFor(self))
                Cancel(self);

            var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
            if (limitedAmmo != null && !limitedAmmo.HasAmmo())
                Cancel(self);

            var attack = self.TraitOrDefault<AttackPlane>();
            if (attack != null)
                attack.DoAttack(self, target);

            if (inner == null)
            {
                if (IsCanceled)
                    return NextActivity;

                inner = Util.SequenceActivities(new Fly(self, target), new FlyTimed(50));
            }

            inner = Util.RunActivity(self, inner);

            return this;
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:25,代码来源:FlyAttack.cs

示例6: Refuel

 public Refuel(Actor self, Actor host)
 {
     move = self.TraitOrDefault<IMove>();
     this.host = host;
     target = Target.FromActor(host);
     refuels = host.TraitOrDefault<RefuelsUnits>();
     fueltank = self.TraitOrDefault<Fueltank>();
 }
开发者ID:obrakmann,项目名称:oramod-wargame,代码行数:8,代码来源:Refuel.cs

示例7: RepairBridge

 public RepairBridge(Actor self, Actor target, EnterBehaviour enterBehaviour, string notification)
     : base(self, target, enterBehaviour)
 {
     this.target = target;
     legacyHut = target.TraitOrDefault<LegacyBridgeHut>();
     hut = target.TraitOrDefault<BridgeHut>();
     this.notification = notification;
 }
开发者ID:pchote,项目名称:OpenRA,代码行数:8,代码来源:RepairBridge.cs

示例8: Tick

		public override Activity Tick(Actor self)
		{
			if (IsCanceled)
				return NextActivity;

			self.World.AddFrameEndTask(w =>
			{
				if (self.IsDead)
					return;

				foreach (var nt in self.TraitsImplementing<INotifyTransform>())
					nt.OnTransform(self);

				var selected = w.Selection.Contains(self);
				var controlgroup = w.Selection.GetControlGroupForActor(self);

				self.Dispose();
				foreach (var s in Sounds)
					Game.Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);

				Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", Notification, self.Owner.Faction.InternalName);

				var init = new TypeDictionary
				{
					new LocationInit(self.Location + Offset),
					new OwnerInit(self.Owner),
					new FacingInit(Facing),
				};

				if (SkipMakeAnims)
					init.Add(new SkipMakeAnimsInit());

				if (Faction != null)
					init.Add(new FactionInit(Faction));

				var health = self.TraitOrDefault<Health>();
				if (health != null)
				{
					var newHP = ForceHealthPercentage > 0 ? ForceHealthPercentage : (health.HP * 100) / health.MaxHP;
					init.Add(new HealthInit(newHP));
				}

				var cargo = self.TraitOrDefault<Cargo>();
				if (cargo != null)
					init.Add(new RuntimeCargoInit(cargo.Passengers.ToArray()));

				var a = w.CreateActor(ToActor, init);
				foreach (var nt in self.TraitsImplementing<INotifyTransform>())
					nt.AfterTransform(a);

				if (selected)
					w.Selection.Add(w, a);
				if (controlgroup.HasValue)
					w.Selection.AddToControlGroup(a, controlgroup.Value);
			});

			return this;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:58,代码来源:Transform.cs

示例9: Infiltrate

		public Infiltrate(Actor self, Actor target)
			: base(self, target)
		{
			this.target = target;

			cloak = self.TraitOrDefault<Cloak>();

			infiltrates = self.TraitOrDefault<Infiltrates>();
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:9,代码来源:Infiltrate.cs

示例10: CombatDebugOverlay

        public CombatDebugOverlay(Actor self)
        {
            attack = Exts.Lazy(() => self.TraitOrDefault<AttackBase>());
            coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
            health = Exts.Lazy(() => self.TraitOrDefault<Health>());

            var localPlayer = self.World.LocalPlayer;
            devMode = localPlayer != null ? localPlayer.PlayerActor.Trait<DeveloperMode>() : null;
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:9,代码来源:CombatDebugOverlay.cs

示例11: Tick

		public override Activity Tick(Actor self)
		{
			if (IsCanceled)
				return NextActivity;

			self.World.AddFrameEndTask(w =>
			{
				if (self.IsDead())
					return;

				foreach (var nt in self.TraitsImplementing<INotifyTransform>())
					nt.OnTransform(self);

				var selected = w.Selection.Contains(self);

				self.Destroy();
				foreach (var s in Sounds)
					Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);

				var init = new TypeDictionary
				{
					new LocationInit(self.Location + Offset),
					new OwnerInit(self.Owner),
					new FacingInit(Facing),
				};

				if (SkipMakeAnims)
					init.Add(new SkipMakeAnimsInit());

				if (Race != null)
					init.Add(new RaceInit(Race));

				var health = self.TraitOrDefault<Health>();
				if (health != null)
				{
					var newHP = (ForceHealthPercentage > 0)
						? ForceHealthPercentage / 100f
						: (float)health.HP / health.MaxHP;

					init.Add(new HealthInit(newHP));
				}

				var cargo = self.TraitOrDefault<Cargo>();
				if (cargo != null)
					init.Add(new RuntimeCargoInit(cargo.Passengers.ToArray()));

				var a = w.CreateActor(ToActor, init);
				foreach (var nt in self.TraitsImplementing<INotifyTransform>())
					nt.AfterTransform(a);

				if (selected)
					w.Selection.Add(w, a);
			});

			return this;
		}
开发者ID:Berzeger,项目名称:OpenRA,代码行数:56,代码来源:Transform.cs

示例12: Tick

		public override Activity Tick(Actor self)
		{
			var pc = self.TraitOrDefault<PortableChrono>();
			if (teleporter == self && pc != null && !pc.CanTeleport)
				return NextActivity;

			foreach (var condition in self.TraitsImplementing<IPreventsTeleport>())
				if (condition.PreventsTeleport(self))
					return NextActivity;

			var bestCell = ChooseBestDestinationCell(self, destination);
			if (bestCell == null)
				return NextActivity;

			destination = bestCell.Value;

			Game.Sound.Play(sound, self.CenterPosition);
			Game.Sound.Play(sound, self.World.Map.CenterOfCell(destination));

			self.Trait<IPositionable>().SetPosition(self, destination);
			self.Generation++;

			if (killCargo)
			{
				var cargo = self.TraitOrDefault<Cargo>();
				if (cargo != null && teleporter != null)
				{
					while (!cargo.IsEmpty(self))
					{
						var a = cargo.Unload(self);

						// Kill all the units that are unloaded into the void
						// Kill() handles kill and death statistics
						a.Kill(teleporter);
					}
				}
			}

			// Consume teleport charges if this wasn't triggered via chronosphere
			if (teleporter == self && pc != null)
				pc.ResetChargeTime();

			// Trigger screen desaturate effect
			if (screenFlash)
				foreach (var a in self.World.ActorsWithTrait<ChronoshiftPaletteEffect>())
					a.Trait.Enable();

			if (teleporter != null && self != teleporter && !teleporter.Disposed)
			{
				var building = teleporter.TraitOrDefault<WithSpriteBody>();
				if (building != null && building.DefaultAnimation.HasSequence("active"))
					building.PlayCustomAnimation(teleporter, "active");
			}

			return NextActivity;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:56,代码来源:Teleport.cs

示例13: Parachute

        public Parachute(Actor self, WPos dropPosition)
        {
            um = self.TraitOrDefault<UpgradeManager>();
            pos = self.TraitOrDefault<IPositionable>();

            // Parachutable trait is a prerequisite for running this activity
            para = self.Info.Traits.Get<ParachutableInfo>();
            fallVector = new WVec(0, 0, para.FallRate);
            this.dropPosition = dropPosition;
        }
开发者ID:rhamilton1415,项目名称:OpenRA,代码行数:10,代码来源:Parachute.cs

示例14: DoAttack

        public void DoAttack(Actor self)
        {
            if( !CanAttack( self ) ) return;

            var move = self.TraitOrDefault<IMove>();
            var facing = self.TraitOrDefault<IFacing>();
            foreach (var w in Weapons)
                if (CheckFire(self, move, facing, w))
                    w.FiredShot();
        }
开发者ID:mgatland,项目名称:OpenRA,代码行数:10,代码来源:AttackBase.cs

示例15: Tick

        public override Activity Tick(Actor self)
        {
            if (IsCanceled) return NextActivity;

            // if we're a thing that can turn, turn to the
            // right facing for the unload animation
            var facing = self.TraitOrDefault<IFacing>();
            var unloadFacing = self.Info.Traits.Get<CargoInfo>().UnloadFacing;
            if (facing != null && facing.Facing != unloadFacing)
                return Util.SequenceActivities( new Turn(unloadFacing), this );

            // TODO: handle the BS of open/close sequences, which are inconsistent,
            //		for reasons that probably make good sense to the westwood guys.

            var cargo = self.Trait<Cargo>();
            if (cargo.IsEmpty(self))
                return NextActivity;

            var ru = self.TraitOrDefault<RenderUnit>();
            if (ru != null)
                ru.PlayCustomAnimation(self, "unload", null);

            var exitTile = ChooseExitTile(self, cargo.Peek(self));
            if (exitTile == null)
                return this;

            var actor = cargo.Unload(self);
            var exit = exitTile.Value.CenterPosition;
            var current = self.Location.CenterPosition;

            self.World.AddFrameEndTask(w =>
            {
                if (actor.Destroyed)
                    return;

                var mobile = actor.Trait<Mobile>();
                mobile.Facing = Util.GetFacing(exit - current, mobile.Facing );
                mobile.SetPosition(actor, exitTile.Value);
                mobile.SetVisualPosition(actor, current);
                var speed = mobile.MovementSpeedForCell(actor, exitTile.Value);
                var length = speed > 0 ? (exit - current).Length / speed : 0;

                w.Add(actor);
                actor.CancelActivity();
                actor.QueueActivity(new Drag(current, exit, length));
                actor.QueueActivity(mobile.MoveTo(exitTile.Value, 0));

                var rallyPoint = ChooseRallyPoint(actor).Value;
                actor.QueueActivity(mobile.MoveTo(rallyPoint, 0));
                actor.SetTargetLine(Target.FromCell(rallyPoint), Color.Green, false);
            });

            return unloadAll ? this : NextActivity;
        }
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:54,代码来源:UnloadCargo.cs


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