void Start() { // Retrieve references character = GetComponent<Character>(); // Set initial stance stance = Stance.Walking; }
public Infiltrate(Actor self, Actor target, EnterBehaviour enterBehaviour, Stance validStances, string notification) : base(self, target, enterBehaviour) { this.target = target; this.validStances = validStances; this.notification = notification; cloak = self.TraitOrDefault<Cloak>(); }
public void initWeaponConfig(ContentManager content, String weaponConfigFile) { XDocument weaponDoc = XDocument.Load(weaponConfigFile); List<XElement> weapons = weaponDoc.Element("Weapons").Elements("Weapon").ToList(); List<XElement> animations; List<XElement> stances; Dictionary<String, String> weaponAnimations; Dictionary<String, Stance> weaponStances; String weaponName; Texture2D weaponTex; String animationName; String animationType; int weaponDamage; String stanceName; Vector2 gripPoint; Rectangle drawBox; foreach (XElement weapon in weapons) { weaponAnimations = new Dictionary<string,string>(); weaponStances = new Dictionary<string,Stance>(); weaponName = weapon.Attribute("name").Value; weaponTex = content.Load<Texture2D>(weapon.Attribute("texture").Value); weaponDamage = int.Parse(weapon.Attribute("damage").Value); animations = weapon.Elements("Animation").ToList(); foreach(XElement animation in animations){ animationName = animation.Attribute("name").Value; animationType = animation.Attribute("type").Value; weaponAnimations[animationType] = animationName; } stances = weapon.Elements("Stance").ToList(); foreach(XElement stance in stances){ stanceName = stance.Attribute("name").Value; gripPoint = new Vector2(); gripPoint.X = float.Parse(stance.Attribute("gripX").Value); gripPoint.Y = float.Parse(stance.Attribute("gripY").Value); drawBox = new Rectangle(); drawBox.X = int.Parse(stance.Attribute("texX").Value); drawBox.Y = int.Parse(stance.Attribute("texY").Value); drawBox.Width = int.Parse(stance.Attribute("texWidth").Value); drawBox.Height = int.Parse(stance.Attribute("texHeight").Value); weaponStances[stanceName] = new Stance { name = stanceName, gripPoint = gripPoint, drawBox = drawBox }; } weaponPrototypes[weaponName] = new Weapon(weaponName, weaponTex, weaponDamage, weaponAnimations, weaponStances); } }
Stance GetNextStance(Stance s) { switch (s) { case Stance.Ally: return Stance.Enemy; case Stance.Enemy: return Stance.Neutral; case Stance.Neutral: return Stance.Ally; default: throw new ArgumentException(); } }
public YourPositionPacketOut(double delta, long tID, Location pos, Location vel, Location avel, Stance stance, bool pup) { UsageType = NetUsageType.PLAYERS; ID = ServerToClientPacket.YOUR_POSITION; Data = new byte[8 + 24 + 24 + 1 + 8]; Utilities.LongToBytes(tID).CopyTo(Data, 0); pos.ToDoubleBytes().CopyTo(Data, 8); vel.ToDoubleBytes().CopyTo(Data, 8 + 24); Data[8 + 24 + 24] = (byte)((stance == Stance.Standing ? 0 : 1) | (pup ? 2: 0)); Utilities.DoubleToBytes(delta).CopyTo(Data, 8 + 24 + 24 + 1); }
public void WalkOrig(int direction) { _direction = direction; Stance = Stance.Walking; _texture = new FRM(_repo + _prefix + TextureName + "AB.frm", MovementHelper.HexX(HexPosition), MovementHelper.HexY(HexPosition)); _texture.CurrentDirection = direction; _steps = _texture._directions[direction]._frames.Length; _steps = 4; }
void SetStance(ButtonWidget bw, Player p, Stance ss) { if (!p.World.LobbyInfo.GlobalSettings.FragileAlliances) return; // stance changes are banned // HACK: Abuse of the type system here with `CPos` world.IssueOrder(new Order("SetStance", world.LocalPlayer.PlayerActor, false) { TargetLocation = new CPos((int)ss, 0), TargetString = p.InternalName }); bw.Text = ss.ToString(); }
public string TooltipForPlayerStance(Stance stance) { if (stance == Stance.None || !GenericVisibility.HasStance(stance)) return Name; if (GenericStancePrefix && stance == Stance.Ally) return "Allied " + GenericName; if (GenericStancePrefix && stance == Stance.Enemy) return "Enemy " + GenericName; return GenericName; }
void SetStance(ButtonWidget bw, Player p, Stance ss) { if (!p.World.LobbyInfo.GlobalSettings.FragileAlliances) return; // stance changes are banned world.IssueOrder(new Order("SetStance", world.LocalPlayer.PlayerActor, false) { ExtraData = (uint)ss, TargetString = p.InternalName, }); bw.Text = ss.ToString(); }
/// <summary> /// Switches from walking/crouching to crawl, from crawl to walking /// </summary> private void PressToggleStance() { switch (stance) { case Stance.Walking: case Stance.Crouch: stance = Stance.Crawl; break; case Stance.Crawl: stance = Stance.Walking; break; } }
//change stance and set the function pointer to the mode it should be using now public void change_stance(Stance given_stance){ //set the stance this.stance = given_stance; //set the delegate if(this.stance == Stance.Attack){ this.stance_delegate = new Ability_Delegate (attack); } else if(this.stance == Stance.Defend){ this.stance_delegate = new Ability_Delegate (defend); } else if(this.stance == Stance.Support){ this.stance_delegate = new Ability_Delegate (support); } }
public void Walk(int[] directionsPath) { if (directionsPath.Length == 0) return; _direction = directionsPath[0]; _directionsPath = directionsPath; _hexesOnPath = directionsPath.Length; _hexesOnPathCount = 0; Stance = Stance.Walking; _texture = new FRM(_repo + _prefix + TextureName + "AB.frm", MovementHelper.HexX(HexPosition), MovementHelper.HexY(HexPosition)); _texture.CurrentDirection = _direction; _steps = _texture._directions[_direction]._frames.Length; _twoSteps = SetNumberOfSteps(); _steps = 4 * (directionsPath.Length); }
public Tech(bool Spawned, bool Selected, Vector3 CurrentCoord, bool IsArrested, bool IsDead, bool IsVisible, int TimesSpawned, Stance stance, MoveSpeed moveSpeed, bool IsinDark, State state, Type type) { // Use methods to randomly generate these values. this.Spawned = Spawned; this.Selected = Selected; this.CurrentCoord = CurrentCoord; this.IsArrested = IsArrested; this.IsDead = IsDead; this.IsVisible = IsVisible; this.TimesSpawned = TimesSpawned; this.stance = stance; this.moveSpeed = moveSpeed; this.IsinDark = IsinDark; this.state = state; this.type = type; //GuardRoute = new List(); }
/// <summary> /// Constructor. /// </summary> public Unit(byte ownerid, BodyType body, WeaponType weapon, Stance stance, byte iHP, byte cHP, byte expertise, byte iAP, byte cAP, short x, short y, string name, params StatusEffect[] effects ) { OwnerID = ownerid; ID = _nextID; _nextID++; Body = body; Weapon = weapon; InitialHitPoints = iHP; CurrentHitPoints = cHP; InitialActionPoints = iAP; CurrentActionPoints = cAP; Stance = stance; Expertise = expertise; X = x; Y = y; Name = name; Effects = new List<StatusEffect>(); foreach(var se in effects) { Effects.Add(se); } }
protected override void MovementUpdate() { isHidden = false; isOnLadder = false; previousFlip = flip; previousPosition = position; previousStance = stance; position += speed; speed.Y += PhysicsHelper.Gravity; if (position.X < standingOrigin.X) position.X = standingOrigin.X; Vector2 goal = Game1.level.goalPos; if (Bounds.Contains((int)goal.X, (int)goal.Y)) { Game1.saver.LoadLevel("level" + ++Game1.currentLevel); position = Game1.level.startPos; speed = Vector2.Zero; return; } foreach (Sprite sprite in Game1.level.Sprites) { if (sprite.layer > layer && sprite.Bounds.Contains(hideRectangle)) { isHidden = true; } Platform platform = sprite as Platform; if (platform != null) { if (PerPixelHits(platform)) { if (platform.IsLadder) { if (Input.Key_Down(Keys.W) || stance == Stance.Climbing) { isOnLadder = true; if (Math.Abs(speed.Y) > 0) speed.Y = 0; speed.X *= (1 - friction); } } if (platform.layer == Level.BaineLayer) { jumpModifier = platform.material.jumpStrenghtModifier; friction = platform.material.friction; #region Multisample Vector2 diff = position - previousPosition; int iterations = (int)speed.Length() + 5; bool done = false; for (int i = 0; i < iterations; i++) { position -= diff / iterations; if (done) break; if (!PerPixelHits(platform)) done = true; } speed.X *= (1 - friction); speed.Y = 0; #endregion if (stance != Stance.Idle) stance = Stance.Standing; ////Rubber //if (platform.material.ToString() == Material.Preset.Rubber.ToString()) //{ // speed.Y = -baseJumpStrength * jumpModifier * Math.Sign(speed.Y); // speed.X += friction * Math.Sign(speed.X); // hasDoubleJumped = false; // Library.sounds["Jump"].Play(1, (float)Game1.random.NextDouble(), 0); // touchesGround = false; // stance = Stance.Jumping; //} #region Unstuck if (PerPixelHits(platform)) // If still hitting then stuck so move out { Console.WriteLine("Stuck!"); diff = position - platform.Position; float pixelsToCenterOfObject = diff.Length(); diff.Normalize(); diff *= 2; // Move max 2 pixels per frame iterations = 5; done = false; for (int i = 0; i < iterations; i++) { position += diff / iterations; if (done) break; if (!PerPixelHits(platform)) done = true; } speed = Vector2.Zero; } #endregion Trap trap = platform as Trap; if (trap != null) { health -= trap.damage; needsRedraw = true; } } } } if (sprite is HealthPotion && PerPixelHits(sprite)) { DrinkPotion(sprite); } previousSpeed = speed; if ((speed.Y == 0 && previousSpeed.Y == 0)) { touchesGround = true; } if (Math.Abs(speed.Y) > 2) { if (isOnLadder) { stance = Stance.Jumping; touchesGround = false; } } } hideRectangle = new Rectangle((int)position.X - (int)(origin.X), (int)position.Y - 15, (int)origin.X * 2, 8); if (!isHidden) { foreach (MovingSprite movingSprite in Game1.level.MovingSprites) { Enemy2 enemy = movingSprite as Enemy2; if (enemy != null && PerPixelHits(enemy)) { health -= enemy.Damage; needsRedraw = true; } } } if (position.Y + origin.Y > Game1.graphics.PreferredBackBufferHeight || health <= 0) { if (LivesLeft > 0) { Game1.ReloadLevel(); position = Game1.level.startPos; LivesLeft -= 1; health = 100; speed = Vector2.Zero; } else { Game1.currentState = Game1.GameState.GameOver; Game1.gameIsStarted = false; } return; } }
static void SetPlayerStance(World w, Player p, Player target, Stance s) { var oldStance = p.Stances[target]; p.Stances[target] = s; target.Shroud.UpdatePlayerStance(w, p, oldStance, s); p.Shroud.UpdatePlayerStance(w, target, oldStance, s); foreach (var nsc in w.ActorsWithTrait<INotifyStanceChanged>()) nsc.Trait.StanceChanged(nsc.Actor, p, target, oldStance, s); }
public void setStance(Stance newStance) { this.stance = newStance; }
private void Walking(double gameTime) { _counter += gameTime; if (_counter > 150) { _texture.Update(gameTime); _counter = 0; _steps--; _hexsteps--; } if(_hexsteps == 0 && _steps != 0) { _texture._directions[_direction]._anumationIndex = 0; if (_twoSteps) { var nextHex = MovementHelper.GetAdjecentHex(_direction, HexPosition); nextHex = MovementHelper.GetAdjecentHex(_direction, nextHex); HexPosition = nextHex; _texture._posX = MovementHelper.HexX(nextHex); _texture._posY = MovementHelper.HexY(nextHex); _hexesOnPathCount++; } else { var nextHex = MovementHelper.GetAdjecentHex(_direction, HexPosition); HexPosition = nextHex; _texture._posX = MovementHelper.HexX(nextHex); _texture._posY = MovementHelper.HexY(nextHex); } _direction = _directionsPath[++_hexesOnPathCount]; _twoSteps = SetNumberOfSteps(); _texture.CurrentDirection = _direction; } if (_steps == 0) { Stance = Stance.Standing; var nextHex = MovementHelper.GetAdjecentHex(_direction, HexPosition); HexPosition = nextHex; _texture = new FRM(_repo + _prefix + TextureName + "AA.frm", MovementHelper.HexX(HexPosition), MovementHelper.HexY(HexPosition)); _texture.CurrentDirection = _direction; } }
public RepairBuilding(Actor self, Actor target, EnterBehaviour enterBehaviour, Stance validStances) : base(self, target, enterBehaviour) { this.target = target; this.validStances = validStances; health = target.Trait <Health>(); }
public void UpdatePlayerStance(World w, Player player, Stance oldStance, Stance newStance) { if (oldStance == newStance) return; foreach (var a in w.Actors.Where(a => a.Owner == player)) { UpdateVisibility(a); UpdateShroudGeneration(a); } }
static void SetPlayerStance(World w, Player a, Player b, Stance s) { var oldStance = a.Stances[b]; a.Stances[b] = s; if (b == w.LocalPlayer) w.WorldActor.Trait<Shroud>().UpdatePlayerStance(w, b, oldStance, s); }
//Allow user of this method to optionally pass in a stance for a more detailed lookup. public FacialAnimationData GetFacialAnimation(string type, string actionID, InteractionAnimationType interactionType, Stance stance) { try { if (this.databases.ContainsKey(type)) { actionID = actionID.ToLower(); List <FacialAnimationData> list = this.databases[type]; FacialAnimationData item = null; //Track how many recursive runs we have done, so we dont run into stack overflows. this.searchDepth += 1; for (int i = 0; i < list.Count; i++) { FacialAnimationData currentItem = list[i]; if (string.Compare(currentItem.ID, actionID, true) == 0 && currentItem.Stance == (int)stance && currentItem.InteractionType == interactionType) { item = currentItem; break; } } //We did not find a excakt match for the facial animation we where looking for, try to find an approximate hit. if (item == null && this.searchDepth <= MaxSearchDepth) { //If first iteration fails we use lookup based on stance. if (searchDepth == 1) { if ((stance & Stance.UseStanding) != 0) { item = GetFacialAnimation(type, actionID, interactionType, Stance.StandingNormal); } if ((stance & Stance.UseSitting) != 0) { item = GetFacialAnimation(type, actionID, interactionType, Stance.SittingNormal); } } //Else we default to standing stance. else { item = GetFacialAnimation(type, actionID, interactionType, Stance.StandingNormal); } } //Reset for the next caller. this.searchDepth = 0; return(item); } } catch (Exception e) { //CrashHelp.Report("AnimationMetaDatabase", e.Message, e); } return(null); }
/// <summary> /// Checks if a transition from the current stance to the target stance is possible given the current environment. /// </summary> /// <param name="targetStance">Stance to check for transition safety.</param> /// <param name="newHeight">If the transition is safe, the new height of the character. Zero otherwise.</param> /// <param name="newPosition">If the transition is safe, the new location of the character body if the transition occurred. Zero vector otherwise.</param> /// <returns>True if the target stance is different than the current stance and the transition is valid, false otherwise.</returns> public bool CheckTransition(Stance targetStance, out float newHeight, out Vector3 newPosition) { var currentPosition = characterBody.position; var down = characterBody.orientationMatrix.Down; newPosition = new Vector3(); newHeight = 0; if (CurrentStance != targetStance) { float currentHeight; switch (CurrentStance) { case Stance.Prone: currentHeight = proneHeight; break; case Stance.Crouching: currentHeight = crouchingHeight; break; default: currentHeight = standingHeight; break; } float targetHeight; switch (targetStance) { case Stance.Prone: targetHeight = proneHeight; break; case Stance.Crouching: targetHeight = crouchingHeight; break; default: targetHeight = standingHeight; break; } if (currentHeight >= targetHeight) { //The character is getting smaller, so no validation queries are required. if (SupportFinder.HasSupport) { //On the ground, so need to move the position down. newPosition = currentPosition + down * ((currentHeight - targetHeight) * 0.5f); } else { //We're in the air, so we don't have to change the position at all- just change the height. newPosition = currentPosition; } newHeight = targetHeight; return(true); } //The character is getting bigger, so validation is required. ConvexCollidable <CylinderShape> queryObject; switch (targetStance) { case Stance.Prone: queryObject = proneQueryObject; break; case Stance.Crouching: queryObject = crouchingQueryObject; break; default: queryObject = standingQueryObject; break; } var tractionContacts = new QuickList <CharacterContact>(BufferPools <CharacterContact> .Thread); var supportContacts = new QuickList <CharacterContact>(BufferPools <CharacterContact> .Thread); var sideContacts = new QuickList <CharacterContact>(BufferPools <CharacterContact> .Thread); var headContacts = new QuickList <CharacterContact>(BufferPools <CharacterContact> .Thread); try { if (SupportFinder.HasSupport) { //Increasing in size requires a query to verify that the new state is safe. //TODO: State queries can be expensive if the character is crouching beneath something really detailed. //There are some situations where you may want to do an upwards-pointing ray cast first. If it hits something, //there's no need to do the full query. newPosition = currentPosition - down * ((targetHeight - currentHeight) * .5f); PrepareQueryObject(queryObject, ref newPosition); QueryManager.QueryContacts(queryObject, ref tractionContacts, ref supportContacts, ref sideContacts, ref headContacts); if (IsObstructed(ref sideContacts, ref headContacts)) { //Can't stand up if something is in the way! return(false); } newHeight = targetHeight; return(true); } else { //This is a complicated case. We must perform a semi-downstep query. //It's different than a downstep because the head may be obstructed as well. float highestBound = 0; float lowestBound = (targetHeight - currentHeight) * .5f; float currentOffset = lowestBound; float maximum = lowestBound; int attempts = 0; //Don't keep querying indefinitely. If we fail to reach it in a few informed steps, it's probably not worth continuing. //The bound size check prevents the system from continuing to search a meaninglessly tiny interval. while (attempts++ < 5 && lowestBound - highestBound > Toolbox.BigEpsilon) { Vector3 candidatePosition = currentPosition + currentOffset * down; float hintOffset; switch (TrySupportLocation(queryObject, ref candidatePosition, out hintOffset, ref tractionContacts, ref supportContacts, ref sideContacts, ref headContacts)) { case CharacterContactPositionState.Accepted: currentOffset += hintOffset; //Only use the new position location if the movement distance was the right size. if (currentOffset > 0 && currentOffset < maximum) { newPosition = currentPosition + currentOffset * down; newHeight = targetHeight; return(true); } else { return(false); } case CharacterContactPositionState.NoHit: highestBound = currentOffset + hintOffset; currentOffset = (lowestBound + highestBound) * .5f; break; case CharacterContactPositionState.Obstructed: lowestBound = currentOffset; currentOffset = (highestBound + lowestBound) * .5f; break; case CharacterContactPositionState.TooDeep: currentOffset += hintOffset; lowestBound = currentOffset; break; } } //Couldn't find a hit. Go ahead and get bigger! newPosition = currentPosition; newHeight = targetHeight; return(true); } } finally { tractionContacts.Dispose(); supportContacts.Dispose(); sideContacts.Dispose(); headContacts.Dispose(); } } return(false); }
//Stance 1 = Red, Stance 2 = Green, Stance 3 = Blue //Attack 1 moves forward, attack 2 moves backwards IEnumerator Stance1Attack1() { currentStance = Stance.STANCE2; SetColor(); yield return(null); }
IEnumerator Stance2Attack2() { currentStance = Stance.STANCE1; SetColor(); yield return(null); }
Target ChooseTarget(Actor self, AttackBase ab, Stance attackStances, WDist scanRange, bool allowMove, bool allowTurn) { var chosenTarget = Target.Invalid; var chosenTargetPriority = int.MinValue; int chosenTargetRange = 0; var activePriorities = activeTargetPriorities.ToList(); if (activePriorities.Count == 0) { return(chosenTarget); } var targetsInRange = self.World.FindActorsInCircle(self.CenterPosition, scanRange) .Select(Target.FromActor) .Concat(self.Owner.FrozenActorLayer.FrozenActorsInCircle(self.World, self.CenterPosition, scanRange) .Select(Target.FromFrozenActor)); foreach (var target in targetsInRange) { BitSet <TargetableType> targetTypes; Player owner; if (target.Type == TargetType.Actor) { // PERF: Most units can only attack enemy units. If this is the case but the target is not an enemy, we // can bail early and avoid the more expensive targeting checks and armament selection. For groups of // allied units, this helps significantly reduce the cost of auto target scans. This is important as // these groups will continuously rescan their allies until an enemy finally comes into range. if (attackStances == OpenRA.Traits.Stance.Enemy && !target.Actor.AppearsHostileTo(self)) { continue; } // Check whether we can auto-target this actor targetTypes = target.Actor.GetEnabledTargetTypes(); if (PreventsAutoTarget(self, target.Actor) || !target.Actor.CanBeViewedByPlayer(self.Owner)) { continue; } owner = target.Actor.Owner; } else if (target.Type == TargetType.FrozenActor) { if (attackStances == OpenRA.Traits.Stance.Enemy && self.Owner.Stances[target.FrozenActor.Owner] == OpenRA.Traits.Stance.Ally) { continue; } targetTypes = target.FrozenActor.TargetTypes; owner = target.FrozenActor.Owner; } else { continue; } var validPriorities = activePriorities.Where(ati => { // Already have a higher priority target if (ati.Priority < chosenTargetPriority) { return(false); } // Incompatible stances if (!ati.ValidStances.HasStance(self.Owner.Stances[owner])) { return(false); } // Incompatible target types if (!ati.ValidTargets.Overlaps(targetTypes) || ati.InvalidTargets.Overlaps(targetTypes)) { return(false); } return(true); }).ToList(); if (validPriorities.Count == 0) { continue; } // Make sure that we can actually fire on the actor var armaments = ab.ChooseArmamentsForTarget(target, false); if (!allowMove) { armaments = armaments.Where(arm => target.IsInRange(self.CenterPosition, arm.MaxRange()) && !target.IsInRange(self.CenterPosition, arm.Weapon.MinRange)); } if (!armaments.Any()) { continue; } if (!allowTurn && !ab.TargetInFiringArc(self, target, 4 * ab.Info.FacingTolerance)) { continue; } // Evaluate whether we want to target this actor var targetRange = (target.CenterPosition - self.CenterPosition).Length; foreach (var ati in validPriorities) { if (chosenTarget.Type == TargetType.Invalid || chosenTargetPriority < ati.Priority || (chosenTargetPriority == ati.Priority && targetRange < chosenTargetRange)) { chosenTarget = target; chosenTargetPriority = ati.Priority; chosenTargetRange = targetRange; } } } return(chosenTarget); }
public static bool Pawn_StanceTracker_SetStance(Stance newStance) { return(!(newStance is Stance_Busy busy && busy.verb?.caster is IFakeCaster)); }
public RevealShroudEffect(WPos pos, WDist radius, Shroud.SourceType type, Player forPlayer, Stance stances, int delay = 0, int duration = 50) { this.pos = pos; player = forPlayer; revealRadius = radius; validStances = stances; sourceType = type; this.duration = duration; ticks = -delay; }
public Baine(System.IO.BinaryReader r) : base(r) { // Get Baine-data hasDoubleJumped = r.ReadBoolean(); isOnLadder = r.ReadBoolean(); health = r.ReadSingle(); stance = (Stance)r.ReadByte(); isHidden = r.ReadBoolean(); LivesLeft = r.ReadInt32(); // Other idle = Library.textures["BaineIdle"]; idleOrigin = new Vector2(idle.Width / 2, idle.Height / 2); standing = Library.textures["BaineStanding"]; standingOrigin = new Vector2(standing.Width / 2, standing.Height / 2); crouching = Library.textures["BaineCrouching"]; crouchOrigin = new Vector2(crouching.Width / 2, crouching.Height / 2); jumping = Library.textures["BaineJumping"]; jumpingOrigin = new Vector2(jumping.Width / 2, jumping.Height / 2); climbing = Library.textures["BaineClimbing"]; climbingOrigin = new Vector2(climbing.Width / 2, climbing.Height / 2); identifier = SaveFileManager.SaveTypeIdentifier.Baine; this.layer = Level.BaineLayer; }
/// <summary>Evaluates a single actor according to the rules defined in this consideration</summary> public int GetAttractiveness(Actor a, Stance stance, Player firedBy) { if (stance != Against) return 0; if (a == null) return 0; var targetable = a.TraitOrDefault<ITargetable>(); if (targetable == null) return 0; if (!targetable.TargetableBy(a, firedBy.PlayerActor)) return 0; if (Types.Intersect(targetable.TargetTypes).Any()) { switch (TargetMetric) { case DecisionMetric.Value: var valueInfo = a.Info.Traits.GetOrDefault<ValuedInfo>(); return (valueInfo != null) ? valueInfo.Cost * Attractiveness : 0; case DecisionMetric.Health: var health = a.TraitOrDefault<Health>(); return (health != null) ? (health.HP / health.MaxHP) * Attractiveness : 0; default: return Attractiveness; } } return 0; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Set Current Stance //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public void SetCurrentStance(Stance stance) { m_eCurrentStance = stance; }
public override void _Ready() { this.level = GetParent() as Level; this.nodeAnimateSprite = GetNode <PlayerAnimation>("animate_sprite"); this.nodeCollision = GetNode <CollisionShape2D>("collision"); this.nodeSparks = GetNode <Particles2D>("animate_sprite/sparks"); this.nodeOverlayTrack = GetNode <PlayerOverlay>("animate_sprite/overlay_track"); this.nodeOverlayNoTrack = GetNode <PlayerOverlay>("overlay_notrack"); this.nodeSfx = GetNode <AudioStreamPlayer2D>("sfx"); this.nodeSfx.Connect("finished", this, nameof(_OnSfxFinished)); //Load stances STANCE_LAX = new Stance("lax", LAX_SPRITE); //Creates attacks if they exist STANCE_LOW = new Stance("low", LOW_SPRITE); STANCE_HIGH = new Stance("high", HIGH_SPRITE); this.ChangeState(State.LAX); this.SCALEFACTOR = new Vector2((this.DIRECTION == Direction.RIGHT) ? 1 : -1, 1); //Set up actions if (Lobby.role == Lobby.MultiplayerRole.OFFLINE) { if (this.controls == ControlMethod.PLAYER1) { this.inputPrefix = "p1_"; } else { this.inputPrefix = "p2_"; } } else //Is multiplayer { if (this.controls == ControlMethod.PLAYER1) //Master { this.inputPrefix = "p1_"; RsetConfig("position", MultiplayerAPI.RPCMode.Puppetsync); RpcConfig(nameof(this.ActionStart), MultiplayerAPI.RPCMode.Puppetsync); } else // Puppet { this.inputPrefix = "remote_"; RsetConfig("position", MultiplayerAPI.RPCMode.Puppet); RpcConfig(nameof(this.ActionStart), MultiplayerAPI.RPCMode.Puppet); } RsetConfig(nameof(this.velocity), MultiplayerAPI.RPCMode.Puppet); RpcConfig(nameof(this.ChangeState), MultiplayerAPI.RPCMode.Puppet); RpcConfig(nameof(this.Hurt_), MultiplayerAPI.RPCMode.Remotesync); RpcConfig(nameof(this.ChangeHP_), MultiplayerAPI.RPCMode.Remotesync); RpcConfig(nameof(this.Parried_ByIndex_), MultiplayerAPI.RPCMode.Remotesync); } this.ACTION_UP = this.inputPrefix + "up"; this.ACTION_DOWN = this.inputPrefix + "down"; this.ACTION_LEFT = this.inputPrefix + "left"; this.ACTION_RIGHT = this.inputPrefix + "right"; //Flip if necessary if (this.DIRECTION == Direction.LEFT) { this.Flip(); } }
public static bool HasStance(this Stance s, Stance stance) { // PERF: Enum.HasFlag is slower and requires allocations. return((s & stance) == stance); }
public void SetStance(Player target, Stance s) { var oldStance = Stances[target]; Stances[target] = s; target.Shroud.UpdatePlayerStance(World, this, oldStance, s); Shroud.UpdatePlayerStance(World, target, oldStance, s); foreach (var nsc in World.ActorsWithTrait<INotifyStanceChanged>()) nsc.Trait.StanceChanged(nsc.Actor, this, target, oldStance, s); }
public void StanceChanged(Actor self, Player a, Player b, Stance oldStance, Stance newStance) { owner.RefreshGps(self); }
/// <summary> /// Checks if a transition from the current stance to the target stance is possible given the current environment. /// </summary> /// <param name="targetStance">Stance to check for transition safety.</param> /// <param name="newHeight">If the transition is safe, the new height of the character. Zero otherwise.</param> /// <param name="newPosition">If the transition is safe, the new location of the character body if the transition occurred. Zero vector otherwise.</param> /// <returns>True if the target stance is different than the current stance and the transition is valid, false otherwise.</returns> public bool CheckTransition(Stance targetStance, out float newHeight, out Vector3 newPosition) { var currentPosition = characterBody.position; var down = characterBody.orientationMatrix.Down; newPosition = new Vector3(); newHeight = 0; if (CurrentStance != targetStance) { float currentHeight; switch (CurrentStance) { case Stance.Prone: currentHeight = proneHeight; break; case Stance.Crouching: currentHeight = crouchingHeight; break; default: currentHeight = standingHeight; break; } float targetHeight; switch (targetStance) { case Stance.Prone: targetHeight = proneHeight; break; case Stance.Crouching: targetHeight = crouchingHeight; break; default: targetHeight = standingHeight; break; } if (currentHeight >= targetHeight) { //The character is getting smaller, so no validation queries are required. if (SupportFinder.HasSupport) { //On the ground, so need to move the position down. newPosition = currentPosition + down * ((currentHeight - targetHeight) * 0.5f); } else { //We're in the air, so we don't have to change the position at all- just change the height. newPosition = currentPosition; } newHeight = targetHeight; return true; } //The character is getting bigger, so validation is required. ConvexCollidable<CylinderShape> queryObject; switch (targetStance) { case Stance.Prone: queryObject = proneQueryObject; break; case Stance.Crouching: queryObject = crouchingQueryObject; break; default: queryObject = standingQueryObject; break; } var tractionContacts = new QuickList<CharacterContact>(BufferPools<CharacterContact>.Thread); var supportContacts = new QuickList<CharacterContact>(BufferPools<CharacterContact>.Thread); var sideContacts = new QuickList<CharacterContact>(BufferPools<CharacterContact>.Thread); var headContacts = new QuickList<CharacterContact>(BufferPools<CharacterContact>.Thread); try { if (SupportFinder.HasSupport) { //Increasing in size requires a query to verify that the new state is safe. //TODO: State queries can be expensive if the character is crouching beneath something really detailed. //There are some situations where you may want to do an upwards-pointing ray cast first. If it hits something, //there's no need to do the full query. newPosition = currentPosition - down * ((targetHeight - currentHeight) * .5f); PrepareQueryObject(queryObject, ref newPosition); QueryManager.QueryContacts(queryObject, ref tractionContacts, ref supportContacts, ref sideContacts, ref headContacts); if (IsObstructed(ref sideContacts, ref headContacts)) { //Can't stand up if something is in the way! return false; } newHeight = targetHeight; return true; } else { //This is a complicated case. We must perform a semi-downstep query. //It's different than a downstep because the head may be obstructed as well. float highestBound = 0; float lowestBound = (targetHeight - currentHeight) * .5f; float currentOffset = lowestBound; float maximum = lowestBound; int attempts = 0; //Don't keep querying indefinitely. If we fail to reach it in a few informed steps, it's probably not worth continuing. //The bound size check prevents the system from continuing to search a meaninglessly tiny interval. while (attempts++ < 5 && lowestBound - highestBound > Toolbox.BigEpsilon) { Vector3 candidatePosition = currentPosition + currentOffset * down; float hintOffset; switch (TrySupportLocation(queryObject, ref candidatePosition, out hintOffset, ref tractionContacts, ref supportContacts, ref sideContacts, ref headContacts)) { case CharacterContactPositionState.Accepted: currentOffset += hintOffset; //Only use the new position location if the movement distance was the right size. if (currentOffset > 0 && currentOffset < maximum) { newPosition = currentPosition + currentOffset * down; newHeight = targetHeight; return true; } else { return false; } case CharacterContactPositionState.NoHit: highestBound = currentOffset + hintOffset; currentOffset = (lowestBound + highestBound) * .5f; break; case CharacterContactPositionState.Obstructed: lowestBound = currentOffset; currentOffset = (highestBound + lowestBound) * .5f; break; case CharacterContactPositionState.TooDeep: currentOffset += hintOffset; lowestBound = currentOffset; break; } } //Couldn't find a hit. Go ahead and get bigger! newPosition = currentPosition; newHeight = targetHeight; return true; } } finally { tractionContacts.Dispose(); supportContacts.Dispose(); sideContacts.Dispose(); headContacts.Dispose(); } } return false; }
private void WalkingOrig(double gameTime) { _counter += gameTime; if (_counter > 150) { _texture.Update(gameTime); _counter = 0; _steps--; } if (_steps == 0) { Stance = Stance.Standing; HexPosition = MovementHelper.GetAdjecentHex(_direction, HexPosition); _texture = new FRM(_repo + _prefix + TextureName + "AA.frm", MovementHelper.HexX(HexPosition), MovementHelper.HexY(HexPosition)); _texture.CurrentDirection = _direction; } }
public void Idle(Vector3 position, Vector3 forward) { StopCoroutine(); stance = stepManager.Idle(position, forward, Stance.Foot.Left); }
/// <summary> /// Tests a collision object with the dimensions matching the desired stance shape at the given position for contacts. /// Output data is stored in the query manager's supporting lists. /// </summary> /// <param name="stance">Character stance to use in the query.</param> /// <param name="position">Position to use for the query.</param> public void QueryContacts(Vector3 position, Stance stance) { QueryContacts(position, stance == Stance.Standing ? standingQueryObject : crouchingQueryObject); }
protected override void InputUpdate() { if (touchesGround) { if (Input.Key_Down(leftKey)) // Ground control left { if (speed.X >= -maxHorizontalSpeed) speed.X -= ((movementSpeed / 2) + (movementSpeed * friction)); stance = Stance.Walking; flip = SpriteEffects.FlipHorizontally; } if (Input.Key_Down(rightKey)) // Ground control right { if (speed.X <= maxHorizontalSpeed) speed.X += ((movementSpeed / 2) + (movementSpeed * friction)); stance = Stance.Walking; flip = SpriteEffects.None; } if (Input.Key_Down(crouchKey)) { if (isOnLadder) // Climb down { speed.Y = 4; } else // Crouch { stance = Stance.Crouching; if (previousStance != Stance.Crouching) position.Y += (standingOrigin.Y - crouchOrigin.Y) - 1; } } if (Input.Key_Down(Keys.W)) { if (isOnLadder) // Climb up { speed.Y = -4f; } } if (Input.Key_NewDown(jumpKey)) { if (stance == Stance.Crouching) // Crouch jump { speed.Y = -baseJumpStrength * 1.8f * jumpModifier; hasDoubleJumped = true; } else // Normal jump { speed.Y = -baseJumpStrength * jumpModifier; hasDoubleJumped = false; } speed.X += friction * Math.Sign(speed.X); Library.sounds["Jump"].Play(1,(float)Game1.random.NextDouble(),0); touchesGround = false; stance = Stance.Jumping; } } else { stance = Stance.Jumping; if (Input.Key_Down(leftKey)) // Air control left { if (speed.X >= -maxHorizontalSpeed) speed.X -= movementSpeed / 2; flip = SpriteEffects.FlipHorizontally; } if (Input.Key_Down(rightKey)) // Air control right { if (speed.X <= maxHorizontalSpeed) speed.X += movementSpeed / 2; flip = SpriteEffects.None; } if (Input.Key_NewDown(jumpKey) && !hasDoubleJumped) // Double jump { speed.Y = -baseJumpStrength; hasDoubleJumped = true; } } if (isOnLadder) { movementSpeed = standardMovementSpeed; stance = Stance.Climbing; } }
public int MoveLength() { Stance stance = ModelController.inModelMode ? GetComponent <ModelBehavior>().Stance() : Stance(); return(Mathf.RoundToInt(stance.NegotiateMoveLength(moveBase * MoveModifier()))); }
// returns a given stance (these are premade) public static Stance Get(tentacleStance s) { /* TODO: Add stances */ Stance st; BoneSet b = new BoneSet(); Bone t6; Bone t5; Bone t4; Bone t3; Bone t2; Bone t1; switch (s) { case tentacleStance.Idle: t6 = new Bone(null, Vector2.Zero, new Vector2(42, 12), 89, 105, "tentacle_base", 0.06f, (float)Math.PI * 1.5f, Color.White, 1.0f); t5 = new Bone(t6, new Vector2(40, 30), new Vector2(0, 55), 68, 69, "tentacle_5", 0.05f, (float)Math.PI * 1.77f, Color.White, 1.0f); t4 = new Bone(t5, new Vector2(68, 40), new Vector2(2, 25), 64, 50, "tentacle_4", 0.04f, (float)Math.PI * 1.93f, Color.White, 1.0f); t3 = new Bone(t4, new Vector2(44, 22), new Vector2(12, 22), 54, 53, "tentacle_3", 0.03f, (float)Math.PI * 1.75f, Color.White, 1.0f); t2 = new Bone(t3, new Vector2(44, 21), new Vector2(4, 15), 35, 33, "tentacle_2", 0.02f, (float)Math.PI * 1.70f, Color.White, 1.0f); t1 = new Bone(t2, new Vector2(30, 20), new Vector2(2, 15), 34, 37, "tentacle_tip_1", 0.01f, (float)Math.PI * 1.75f, Color.White, 1.0f); b.AddBone(t6); b.AddBone(t5); b.AddBone(t4); b.AddBone(t3); b.AddBone(t2); b.AddBone(t1); st = new Stance(b); st.Type = (int)tentacleStance.Idle; return(st); case tentacleStance.Walk1: t6 = new Bone(null, Vector2.Zero, new Vector2(12, 42), 105, 89, "tentacle_base", 0.06f, (float)Math.PI * 1.25f, Color.White, 1.0f); t5 = new Bone(t6, new Vector2(40, 75), new Vector2(0, 60), 69, 68, "tentacle_5", 0.05f, (float)Math.PI * 1.35f, Color.White, 1.0f); t4 = new Bone(t5, new Vector2(68, 35), new Vector2(2, 25), 64, 50, "tentacle_4", 0.04f, (float)Math.PI * 1.25f, Color.White, 1.0f); t3 = new Bone(t4, new Vector2(44, 22), new Vector2(12, 22), 54, 53, "tentacle_3", 0.03f, (float)Math.PI * 1.1f, Color.White, 1.0f); t2 = new Bone(t3, new Vector2(44, 21), new Vector2(4, 15), 35, 33, "tentacle_2", 0.02f, (float)Math.PI * 1.0f, Color.White, 1.0f); t1 = new Bone(t2, new Vector2(30, 15), new Vector2(2, 15), 34, 37, "tentacle_tip_1", 0.01f, (float)Math.PI * 1.0f, Color.White, 1.0f); b.AddBone(t6); b.AddBone(t5); b.AddBone(t4); b.AddBone(t3); b.AddBone(t2); b.AddBone(t1); st = new Stance(b); st.Type = (int)tentacleStance.Walk1; return(st); case tentacleStance.Walk2: t6 = new Bone(null, Vector2.Zero, new Vector2(12, 42), 105, 89, "tentacle_base", 0.06f, (float)Math.PI * 1.55f, Color.White, 1.0f); t5 = new Bone(t6, new Vector2(40, 75), new Vector2(0, 60), 69, 68, "tentacle_5", 0.05f, (float)Math.PI * 1.69f, Color.White, 1.0f); t4 = new Bone(t5, new Vector2(68, 35), new Vector2(2, 25), 64, 50, "tentacle_4", 0.04f, (float)Math.PI * 1.58f, Color.White, 1.0f); t3 = new Bone(t4, new Vector2(44, 22), new Vector2(12, 22), 54, 53, "tentacle_3", 0.03f, (float)Math.PI * 1.34f, Color.White, 1.0f); t2 = new Bone(t3, new Vector2(44, 21), new Vector2(4, 15), 35, 33, "tentacle_2", 0.02f, (float)Math.PI * 1.33f, Color.White, 1.0f); t1 = new Bone(t2, new Vector2(30, 15), new Vector2(2, 15), 34, 37, "tentacle_tip_1", 0.01f, (float)Math.PI * 1.35f, Color.White, 1.0f); b.AddBone(t6); b.AddBone(t5); b.AddBone(t4); b.AddBone(t3); b.AddBone(t2); b.AddBone(t1); st = new Stance(b); st.Type = (int)tentacleStance.Walk2; return(st); case tentacleStance.Walk3: t6 = new Bone(null, Vector2.Zero, new Vector2(12, 42), 105, 89, "tentacle_base", 0.06f, (float)Math.PI * (1.25f - .75f), Color.White, 1.0f); t5 = new Bone(t6, new Vector2(40, 75), new Vector2(0, 60), 69, 68, "tentacle_5", 0.05f, (float)Math.PI * (1.35f - .69f), Color.White, 1.0f); t4 = new Bone(t5, new Vector2(68, 35), new Vector2(2, 25), 64, 50, "tentacle_4", 0.04f, (float)Math.PI * (1.25f - .78f), Color.White, 1.0f); t3 = new Bone(t4, new Vector2(44, 22), new Vector2(12, 22), 54, 53, "tentacle_3", 0.03f, (float)Math.PI * (1.1f - .77f), Color.White, 1.0f); t2 = new Bone(t3, new Vector2(44, 21), new Vector2(4, 15), 35, 33, "tentacle_2", 0.02f, (float)Math.PI * (1.0f - .72f), Color.White, 1.0f); t1 = new Bone(t2, new Vector2(30, 15), new Vector2(2, 15), 34, 37, "tentacle_tip_1", 0.01f, (float)Math.PI * (1.0f - .75f), Color.White, 1.0f); b.AddBone(t6); b.AddBone(t5); b.AddBone(t4); b.AddBone(t3); b.AddBone(t2); b.AddBone(t1); st = new Stance(b); st.Type = (int)tentacleStance.Walk1; return(st); case tentacleStance.Walk4: t6 = new Bone(null, Vector2.Zero, new Vector2(12, 42), 105, 89, "tentacle_base", 0.06f, (float)Math.PI * (1.25f - 1.75f), Color.White, 1.0f); t5 = new Bone(t6, new Vector2(40, 75), new Vector2(0, 60), 69, 68, "tentacle_5", 0.05f, (float)Math.PI * (1.35f - 1.69f), Color.White, 1.0f); t4 = new Bone(t5, new Vector2(68, 35), new Vector2(2, 25), 64, 50, "tentacle_4", 0.04f, (float)Math.PI * (1.25f - 1.78f), Color.White, 1.0f); t3 = new Bone(t4, new Vector2(44, 22), new Vector2(12, 22), 54, 53, "tentacle_3", 0.03f, (float)Math.PI * (1.1f - 1.77f), Color.White, 1.0f); t2 = new Bone(t3, new Vector2(44, 21), new Vector2(4, 15), 35, 33, "tentacle_2", 0.02f, (float)Math.PI * (1.0f - 1.72f), Color.White, 1.0f); t1 = new Bone(t2, new Vector2(30, 15), new Vector2(2, 15), 34, 37, "tentacle_tip_1", 0.01f, (float)Math.PI * (1.0f - 1.75f), Color.White, 1.0f); b.AddBone(t6); b.AddBone(t5); b.AddBone(t4); b.AddBone(t3); b.AddBone(t2); b.AddBone(t1); st = new Stance(b); st.Type = (int)tentacleStance.Walk1; return(st); case tentacleStance.Walk5: t6 = new Bone(null, Vector2.Zero, new Vector2(12, 42), 105, 89, "tentacle_base", 0.06f, (float)Math.PI * (1.25f + .84f), Color.White, 1.0f); t5 = new Bone(t6, new Vector2(40, 75), new Vector2(0, 60), 69, 68, "tentacle_5", 0.05f, (float)Math.PI * (1.35f + .8f), Color.White, 1.0f); t4 = new Bone(t5, new Vector2(68, 35), new Vector2(2, 25), 64, 50, "tentacle_4", 0.04f, (float)Math.PI * (1.25f + .89f), Color.White, 1.0f); t3 = new Bone(t4, new Vector2(44, 22), new Vector2(12, 22), 54, 53, "tentacle_3", 0.03f, (float)Math.PI * (1.1f + .78f), Color.White, 1.0f); t2 = new Bone(t3, new Vector2(44, 21), new Vector2(4, 15), 35, 33, "tentacle_2", 0.02f, (float)Math.PI * (1.0f + .88f), Color.White, 1.0f); t1 = new Bone(t2, new Vector2(30, 15), new Vector2(2, 15), 34, 37, "tentacle_tip_1", 0.01f, (float)Math.PI * (1.0f + .9f), Color.White, 1.0f); b.AddBone(t6); b.AddBone(t5); b.AddBone(t4); b.AddBone(t3); b.AddBone(t2); b.AddBone(t1); st = new Stance(b); st.Type = (int)tentacleStance.Walk1; return(st); case tentacleStance.Walk6: t6 = new Bone(null, Vector2.Zero, new Vector2(12, 42), 105, 89, "tentacle_base", 0.06f, (float)Math.PI * (1.25f + .41f), Color.White, 1.0f); t5 = new Bone(t6, new Vector2(40, 75), new Vector2(0, 60), 69, 68, "tentacle_5", 0.05f, (float)Math.PI * (1.35f + .49f), Color.White, 1.0f); t4 = new Bone(t5, new Vector2(68, 35), new Vector2(2, 25), 64, 50, "tentacle_4", 0.04f, (float)Math.PI * (1.25f + .42f), Color.White, 1.0f); t3 = new Bone(t4, new Vector2(44, 22), new Vector2(12, 22), 54, 53, "tentacle_3", 0.03f, (float)Math.PI * (1.1f + .37f), Color.White, 1.0f); t2 = new Bone(t3, new Vector2(44, 21), new Vector2(4, 15), 35, 33, "tentacle_2", 0.02f, (float)Math.PI * (1.0f + .46f), Color.White, 1.0f); t1 = new Bone(t2, new Vector2(30, 15), new Vector2(2, 15), 34, 37, "tentacle_tip_1", 0.01f, (float)Math.PI * (1.0f + .5f), Color.White, 1.0f); b.AddBone(t6); b.AddBone(t5); b.AddBone(t4); b.AddBone(t3); b.AddBone(t2); b.AddBone(t1); st = new Stance(b); st.Type = (int)tentacleStance.Walk1; return(st); case tentacleStance.Walk7: t6 = new Bone(null, Vector2.Zero, new Vector2(12, 42), 105, 89, "tentacle_base", 0.06f, (float)Math.PI * (1.25f - 1.0f), Color.White, 1.0f); t5 = new Bone(t6, new Vector2(40, 75), new Vector2(0, 60), 69, 68, "tentacle_5", 0.05f, (float)Math.PI * (1.35f - .96f), Color.White, 1.0f); t4 = new Bone(t5, new Vector2(68, 35), new Vector2(2, 25), 64, 50, "tentacle_4", 0.04f, (float)Math.PI * (1.25f - 1.08f), Color.White, 1.0f); t3 = new Bone(t4, new Vector2(44, 22), new Vector2(12, 22), 54, 53, "tentacle_3", 0.03f, (float)Math.PI * (1.1f - 1.03f), Color.White, 1.0f); t2 = new Bone(t3, new Vector2(44, 21), new Vector2(4, 15), 35, 33, "tentacle_2", 0.02f, (float)Math.PI * (1.0f - 1.06f), Color.White, 1.0f); t1 = new Bone(t2, new Vector2(30, 15), new Vector2(2, 15), 34, 37, "tentacle_tip_1", 0.01f, (float)Math.PI * (1.0f - 1.1f), Color.White, 1.0f); b.AddBone(t6); b.AddBone(t5); b.AddBone(t4); b.AddBone(t3); b.AddBone(t2); b.AddBone(t1); st = new Stance(b); st.Type = (int)tentacleStance.Walk1; return(st); default: return(null); } }
public void UpdatePlayerStance(World w, Player player, Stance oldStance, Stance newStance) { if (oldStance == newStance) return; // No longer our ally; remove unit vis if (oldStance == Stance.Ally) { var toRemove = w.Actors.Where(a => a.Owner == player).ToList(); foreach (var a in toRemove) RemoveActor(a); } // Is now our ally; add unit vis if (newStance == Stance.Ally) foreach (var a in w.Actors.Where( a => a.Owner == player )) AddActor(a); }
/// <summary>Evaluates a single actor according to the rules defined in this consideration</summary> public int GetAttractiveness(Actor a, Stance stance, Player firedBy) { if (stance != Against) return 0; if (a == null) return 0; var targetable = a.TraitsImplementing<ITargetable>().Where(Exts.IsTraitEnabled); if (!targetable.Any(t => t.TargetableBy(a, firedBy.PlayerActor))) return 0; if (Types.Overlaps(targetable.SelectMany(t => t.TargetTypes))) { switch (TargetMetric) { case DecisionMetric.Value: var valueInfo = a.Info.TraitInfoOrDefault<ValuedInfo>(); return (valueInfo != null) ? valueInfo.Cost * Attractiveness : 0; case DecisionMetric.Health: var health = a.TraitOrDefault<Health>(); return (health != null) ? (health.HP / health.MaxHP) * Attractiveness : 0; default: return Attractiveness; } } return 0; }
protected override void AnimationUpdate(GameTime gameTime) { // Animation switch (stance) { case Stance.Idle: baseTexture = idle; origin = idleOrigin; // Turn around twice if (turnCountdown > 0) { turnCountdown -= gameTime.ElapsedGameTime.Milliseconds; } if (turnCountdown <= 0) { if (!hasTurned) { if (flip == SpriteEffects.None) flip = SpriteEffects.FlipHorizontally; else flip = SpriteEffects.None; turnCountdown = 500; hasTurned = true; } else if (!hasTurnedTwice) { if (flip == SpriteEffects.None) flip = SpriteEffects.FlipHorizontally; else flip = SpriteEffects.None; hasTurnedTwice = true; } } break; case Stance.Standing: baseTexture = standing; origin = standingOrigin; movementSpeed = standardMovementSpeed; idleCountdown -= gameTime.ElapsedGameTime.Milliseconds; if (idleCountdown <= 0) { hasTurned = false; hasTurnedTwice = false; turnCountdown = milliSecondsTilTurn; stance = Stance.Idle; } break; case Stance.Walking: baseTexture = standing; origin = standingOrigin; movementSpeed = standardMovementSpeed; break; case Stance.Crouching: baseTexture = crouching; origin = crouchOrigin; movementSpeed = crouchingMovementSpeed; break; case Stance.Jumping: baseTexture = jumping; origin = jumpingOrigin; break; case Stance.Climbing: baseTexture = climbing; origin = climbingOrigin; break; } if (stance != Stance.Idle && stance != Stance.Standing) { idleCountdown = milliSecondsTilIdle; } if (stance != Stance.Crouching && previousStance == Stance.Crouching) { position.Y -= (standingOrigin.Y - crouchOrigin.Y); } if (stance != previousStance) { Console.WriteLine(ToString() + " changed stance to " + stance.ToString()); needsRedraw = true; } if (previousFlip != flip) { Console.WriteLine(ToString() + " flipped direction to " + (flip.ToString() == "None" ? "right" : "left")); needsRedraw = true; } color = Color.Multiply(Color.White, (health / 100)); }
Actor ChooseTarget(Actor self, Stance attackStances, WDist range, bool allowMove) { var actorsByArmament = new Dictionary <Armament, List <Actor> >(); var actorsInRange = self.World.FindActorsInCircle(self.CenterPosition, range); foreach (var actor in actorsInRange) { // PERF: Most units can only attack enemy units. If this is the case but the target is not an enemy, we // can bail early and avoid the more expensive targeting checks and armament selection. For groups of // allied units, this helps significantly reduce the cost of auto target scans. This is important as // these groups will continuously rescan their allies until an enemy finally comes into range. if (attackStances == OpenRA.Traits.Stance.Enemy && !actor.AppearsHostileTo(self)) { continue; } if (PreventsAutoTarget(self, actor) || !self.Owner.CanTargetActor(actor)) { continue; } // Select only the first compatible armament for each actor: if this actor is selected // it will be thanks to the first armament anyways, since that is the first selection // criterion var target = Target.FromActor(actor); var armaments = attack.ChooseArmamentsForTarget(target, false); if (!allowMove) { armaments = armaments.Where(arm => target.IsInRange(self.CenterPosition, arm.MaxRange()) && !target.IsInRange(self.CenterPosition, arm.Weapon.MinRange)); } var armament = armaments.FirstOrDefault(); if (armament == null) { continue; } List <Actor> actors; if (actorsByArmament.TryGetValue(armament, out actors)) { actors.Add(actor); } else { actorsByArmament.Add(armament, new List <Actor> { actor }); } } // Armaments are enumerated in attack.Armaments in construct order // When autotargeting, first choose targets according to the used armament construct order // And then according to distance from actor // This enables preferential treatment of certain armaments // (e.g. tesla trooper's tesla zap should have precedence over tesla charge) foreach (var arm in attack.Armaments) { List <Actor> actors; if (actorsByArmament.TryGetValue(arm, out actors)) { return(actors.ClosestTo(self)); } } return(null); }