public void SetTargetFocus(TargetMelee target) { if (target == null) { return; } var direction = CharacterLocomotion.OVERRIDE_FACE_DIRECTION.Target; var position = new TargetPosition(TargetPosition.Target.Transform) { targetTransform = target.transform }; this.Character.characterLocomotion.overrideFaceDirection = direction; this.Character.characterLocomotion.overrideFaceDirectionTarget = position; target.SetTracker(this); this.HasFocusTarget = true; if (this.EventFocus != null) { this.EventFocus.Invoke(true); } }
} //42-46 public void Serialize(LittleEndianWriter writer2) { byte[] buffer; using (var stream = new MemoryStream()) { using (var writer = new LittleEndianWriter(stream)) { writer.WriteUInt(SpellHash); writer.WriteUInt(SpellNetID); writer.WriteByte(SpellLevel); writer.WriteFloat(AttackSpeedModifier); writer.WriteUInt(CasterNetID); writer.WriteUInt(SpellChainOwnerNetID); writer.WriteUInt(PackageHash); writer.WriteUInt(MissileNetID); TargetPosition.Serialize(writer); TargetPositionEnd.Serialize(writer); int targetCount = Targets.Count; if (targetCount > 32) { throw new IOException("CastInfo targets > 32!!!"); } writer.WriteByte((byte)targetCount); foreach (var target in Targets) { writer.WriteUInt(target.Item1); writer.WriteByte((byte)target.Item2); } writer.WriteFloat(DesignerCastTime); writer.WriteFloat(ExtraCastTime); writer.WriteFloat(DesignerTotalTime); writer.WriteFloat(Cooldown); writer.WriteFloat(StartCastTime); byte bitfield = 0; if (IsAutoAttack) { bitfield |= 1; } if (IsSecondAutoAttack) { bitfield |= 2; } if (IsForceCastingOrChannel) { bitfield |= 4; } if (IsOverrideCastPosition) { bitfield |= 8; } if (IsClickCasted) { bitfield |= 16; } writer.WriteByte(bitfield); writer.WriteByte(SpellSlot); writer.WriteFloat(ManaCost); SpellCastLaunchPosition.Serialize(writer); writer.WriteInt(AmmoUsed); writer.WriteFloat(AmmoRechargeTime); } buffer = new byte[stream.Length]; var data = stream.GetBuffer(); Buffer.BlockCopy(data, 0, buffer, 0, buffer.Length); } writer2.WriteUShort((ushort)(buffer.Length + 2)); writer2.WriteBytes(buffer); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="source"></param> /// <param name="position"></param> /// <param name="target"></param> public TargetLocation(XObject source, TargetPosition position, XObject target) : this(source, position) { Contract.Requires<ArgumentNullException>(source != null); Contract.Requires<ArgumentNullException>(target != null); this.target = target; }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="source"></param> /// <param name="position"></param> public TargetLocation(XObject source, TargetPosition position) : this() { Contract.Requires<ArgumentNullException>(source != null); this.source = source; this.position = position; }
protected override void OnUpdate() { // This determines the number of players we have and allocates a NativeArray of Translations // It then schedules a job to be run which will fill that array // We pass the output job handle of this function as a dependency of the ForEach below to guarantee it completes before we need the player position var playerPosition = m_PlayerQuery.ToComponentDataArrayAsync <Translation>(Allocator.TempJob, out JobHandle getPositionHandle); // ECB which will run at the end of the simulation group. If the player is seen, will change the Guard's state to chasing var ecb = m_EndSimECBSystem.CreateCommandBuffer().AsParallelWriter(); // Update the target position (must pass isReadOnly=false) var targetPositionFromEntity = GetComponentDataFromEntity <TargetPosition>(false); var lookHandle = Entities .WithName("LookForPlayer") // ForEach name is helpful for debugging .WithReadOnly(playerPosition) // Marked read only (We don't mutate the player position) .WithNativeDisableParallelForRestriction(targetPositionFromEntity) // Since ComponentDataFromEntity allows us to access *any* entity, // we need to disable the safety system (since we know we're writing // to the player and not another guard) .WithDisposeOnCompletion(playerPosition) // Prevent a memory leak by deallocating our position array at the end of the job .ForEach(( Entity guardEntity, // Refers to the current guard entity. Used by the ECB when changing states int entityInQueryIndex, // Index of the guard entity in the query. Used for Concurrent ECB writing in Translation guardPosition, // "in" keyword makes the parameter ReadOnly in Rotation guardRotation, in VisionCone guardVisionCone ) => { // If there are no players, we can safely skip this work if (playerPosition.Length <= 0) { return; } // Get a normalized vector from the guard to the player var forwardVector = math.forward(guardRotation.Value); var vectorToPlayer = playerPosition[0].Value - guardPosition.Value; var unitVecToPlayer = math.normalize(vectorToPlayer); // Use the dot product to determine if the player is within our vision cone var dot = math.dot(forwardVector, unitVecToPlayer); var canSeePlayer = dot > 0.0f && // player is in front of us math.abs(math.acos(dot)) < guardVisionCone.AngleRadians && // player is within the cone angle bounds math.lengthsq(vectorToPlayer) < guardVisionCone.ViewDistanceSq; // player is within vision distance (we use Squared Distance to avoid sqrt calculation) // Here we grab the tag of the guardEntity var isCurrentlyChasing = HasComponent <IsChasingTag>(guardEntity); if (canSeePlayer) { if (isCurrentlyChasing) { // Update the target position of the guard to the player the guard is chasing // Here we use ComponentDataFromEntity because idle guards will not have a TargetPosition // If the guard is already chasing, then we know they have a TargetPosition already and can set its value targetPositionFromEntity[guardEntity] = new TargetPosition { Value = playerPosition[0].Value }; } else { GuardAIUtility.TransitionToChasing(ecb, guardEntity, entityInQueryIndex, playerPosition[0].Value); } // If the guard has an idle timer, we want to leave the idle state // Therefore, we remove the timer from the guard if (HasComponent <IdleTimer>(guardEntity)) { GuardAIUtility.TransitionFromIdle(ecb, guardEntity, entityInQueryIndex); } } else if (isCurrentlyChasing) // If we don't see the player anymore, stop chasing { GuardAIUtility.TransitionFromChasing(ecb, guardEntity, entityInQueryIndex); GuardAIUtility.TransitionToIdle(ecb, guardEntity, entityInQueryIndex); } }).ScheduleParallel(getPositionHandle); // Schedule the ForEach with the job system to run
public ConstructAction(TargetPosition targetPosition, ConstructionObject constructionObject) { _constructionObject = constructionObject; _targetPosition = targetPosition; }
public override string ToString() { return(string.Format("Move {0} to {1}", CurrentShip.ToString(), TargetPosition.ToString())); }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { // enemyEntities = GridJobStatics.enemyEntities; //Get chunks to process //Fails BURST var chunkFriend = chunk.GetNativeArray(friendlySoldier); var chunkTargetPos = chunk.GetNativeArray(friendlyTarget); //_friendNum used to be firstEntityIndex. Only worked for first chunk. Purpose of var? /// Loop through all friendlies for (int _friendNum = 0; _friendNum < chunkFriend.Length; _friendNum++) { var _ourPos = chunkFriend[_friendNum].soldierData.position; //Get initial enemy int _cellX = math.min((int)(_ourPos.x / Grid.instance.data.cellSize), Grid.instance.numberOfCells - 1); int _cellY = math.min((int)(_ourPos.y / Grid.instance.data.cellSize), Grid.instance.numberOfCells - 1); int _cellZ = math.min((int)(_ourPos.z / Grid.instance.data.cellSize), Grid.instance.numberOfCells - 1); //Bounds checks should be moved to the Grid's getter Soldier enemy = Grid.instance.data.cells[_cellX, _cellY, _cellZ]; Soldier closestSoldier = new Soldier { }; float bestDistSqr = Mathf.Infinity; float3 _frPos = chunkFriend[_friendNum].soldierData.position; int _maxIter = 150; int _iter = 0; #region linked while (enemy.nextSoldier > 0 && (_iter < _maxIter)) { float3 _enPos = enemy.position; float3 _dist = _enPos - _frPos; float distSqr = _dist.x * _dist.x + _dist.y * _dist.y + _dist.z * _dist.z; if (distSqr < bestDistSqr) { bestDistSqr = distSqr; closestSoldier = enemy; } // Debug.LogFormat ("Checking {0}", enemy.nextSoldier); enemy = enemies[new Entity { Index = enemy.nextSoldier, Version = 1 }].soldierData; _iter++; } #endregion linked //Find the closest enemy (not Linked-Listed) #region non-linked // foreach (Soldier soldier in Grid.instance.data.cells) // { // float3 _enPos = soldier.position; // float3 _dist = _enPos - _frPos; // float distSqr = _dist.x * _dist.x + _dist.y * _dist.y + _dist.z * _dist.z; // if (distSqr < bestDistSqr) // { // bestDistSqr = distSqr; // closestEntity = enemyEntities[soldier.nextSoldier]; // // var _enmy = enemies[_ent]; // closestSoldier = enemies[enemyEntities[soldier.nextSoldier]].soldierData; // // if(chunkFriend[_friendNum].soldierData.entityId > 210) // { // // Debug.LogFormat("Found enemy {0} setting target to {1} with us {2}", _ent.Index, _enmy.soldierData.position, chunkFriend[_friendNum].soldierData.entityId); // // Debug.LogFormat("Zero'd target while our ID: {0}", chunkFriend[_friendNum].soldierData.entityId); // } // } // } /// TD: check discrepancy between actual enemy pos and reported, lads still don't go where they should /// Correct, but they still bunch up @ center // Debug.LogFormat("Found best Sqr of {0} on enemy {1}", bestDistSqr, closestSoldier.id); #endregion non-linked // Debug.LogFormat ("Looking towards enmat on ID {0}", enemy.entityId); if (enemy.entityId > 0) { enMat[new Entity { Index = enemy.entityId, Version = 1 }] = new EnemyMaterialColor { Value = new float4(0, 1, 0, 1) }; } chunkTargetPos[_friendNum] = new TargetPosition { Value = closestSoldier.position }; } }
public static List <Fighter> GetTargettableFighters(Fighter originator, TargetCount targetCount, TargetSelection targetSelection, bool excludeSelf, TargetStatus targetStatus, ActionAttribute attackAttribute, TargetPosition targetPosition, TargetElevation targetElevation) { List <Fighter> targettableFighters = new List <Fighter>(); if (targetCount == TargetCount.AllFighters) { // Allys first targettableFighters.AddRange(originator.FighterTeam.TeamMembers); // Reverse ally order for navigation targettableFighters.Reverse(); if (excludeSelf) { targettableFighters.Remove(originator); } targettableFighters.AddRange(originator.FighterTeam.opposingTeam.TeamMembers); } else { switch (targetSelection) { case TargetSelection.Ally: targettableFighters.AddRange(originator.FighterTeam.TeamMembers); if (excludeSelf) { targettableFighters.Remove(originator); } break; case TargetSelection.Enemy: targettableFighters.AddRange(originator.FighterTeam.opposingTeam.TeamMembers); break; case TargetSelection.Self: targettableFighters.Add(originator); break; } } for (int i = targettableFighters.Count - 1; i >= 0; i--) { if (!FighterIsOnTargetableElevation(targettableFighters[i], targetElevation)) { targettableFighters.RemoveAt(i); continue; } // Positional actions will never focus on all teams, so lets do this conditionally switch (targetPosition) { case TargetPosition.Front: if (i > 0) { targettableFighters.RemoveAt(i); continue; } break; case TargetPosition.Rear: if (i < targettableFighters.Count - 1) { targettableFighters.RemoveAt(i); } break; } if (!FighterHasTargetableStatuses(targettableFighters[0], targetStatus)) { targettableFighters.RemoveAt(i); } if (!FighterHasTargetableAttributes(targettableFighters[0], attackAttribute)) { targettableFighters.RemoveAt(i); } } return(targettableFighters); }
public override void Update() { Camera camera = HookCamera.Instance.Get <Camera>(); Ray cursorFromCameraRay = camera.ScreenPointToRay(Input.mousePosition); Transform shooterPosition = this.shooter.transform; Plane plane = default(Plane); float rayDistance; WeaponMuzzle muzzle = this.GetMuzzle(); this.pointShootingRaycast = muzzle.GetPosition(); this.pointShootingWeapon = muzzle.GetPosition(); switch (this.coordinates) { case Coordinates.XY: plane = new Plane(Vector3.forward, shooterPosition.position); this.pointShootingRaycast = new Vector3( this.pointShootingRaycast.x, this.pointShootingRaycast.y, shooterPosition.position.z ); break; case Coordinates.YZ: plane = new Plane(Vector3.right, shooterPosition.position); this.pointShootingRaycast = new Vector3( shooterPosition.position.x, this.pointShootingRaycast.y, this.pointShootingRaycast.z ); break; } Vector3 aimDirection = muzzle.GetDirection(); if (plane.Raycast(cursorFromCameraRay, out rayDistance)) { Vector3 cursor = cursorFromCameraRay.GetPoint(rayDistance); aimDirection = cursor - this.pointShootingRaycast; } float angle = this.GetPitch(aimDirection); this.shooter.SetPitch(angle); this.aimToVector = aimDirection.normalized * this.shooter.currentAmmo.distance; if (this.character) { this.character.characterLocomotion.overrideFaceDirection = ( CharacterLocomotion.OVERRIDE_FACE_DIRECTION.Target ); switch (this.coordinates) { case Coordinates.XY: Vector3 targetPositionXY = ( this.shooter.transform.position + (aimDirection.x > 0f ? Vector3.right : Vector3.left) ); TargetPosition xyFace = new TargetPosition(TargetPosition.Target.Position); xyFace.targetPosition = targetPositionXY; this.character.characterLocomotion.overrideFaceDirectionTarget = xyFace; break; case Coordinates.YZ: Vector3 targetPositionYZ = ( this.character.transform.position + (aimDirection.z > 0f ? Vector3.forward : Vector3.back) ); TargetPosition yzFace = new TargetPosition(TargetPosition.Target.Position); yzFace.targetPosition = targetPositionYZ; this.character.characterLocomotion.overrideFaceDirection = ( CharacterLocomotion.OVERRIDE_FACE_DIRECTION.Target ); this.character.characterLocomotion.overrideFaceDirectionTarget = yzFace; break; } } }
private void button25_Click(object sender, EventArgs e) { _rack.SetSpeed(defaultTestSpeed); Task.Run(() => { //Todo complete condition. TargetPosition target = _rack._motion.HomePosition; switch (_selectedTargetPosition) { case TeachPos.Home: break; case TeachPos.Pick: target = _rack._motion.PickPosition; break; case TeachPos.Bin: break; case TeachPos.ConveyorLeft: break; case TeachPos.ConveyorRight: break; case TeachPos.Holder1: target = _rack._motion.Holder1; break; case TeachPos.Holder2: target = _rack._motion.Holder2; break; case TeachPos.Holder3: target = _rack._motion.Holder3; break; case TeachPos.Holder4: target = _rack._motion.Holder4; break; case TeachPos.Holder5: target = _rack._motion.Holder5; break; case TeachPos.Holder6: target = _rack._motion.Holder6; break; case TeachPos.Gold1: break; case TeachPos.Gold2: break; case TeachPos.Gold3: break; case TeachPos.Gold4: break; case TeachPos.Gold5: break; } try { _rack.Unload(_selectedGripper, target); } catch (Exception ex) { MessageBox.Show(ex.Message); } }); }
void Click() { if (timerStarted && Input.GetMouseButtonDown(0)) { timerStarted = false; inputTimer = 0; TargetPosition.SelectTile(); PlayerPosition.GetPlayerTile(); PlayerPhasing.PlayerPhase(); AudioManager.Instance.PlayFX(phaseSound); if (tileIsPhasable && PlayerPosition.player.transform.position.x == PlayerPosition.playerTile.transform.position.x && PlayerPosition.player.transform.position.z == PlayerPosition.playerTile.transform.position.z) { PlayerPhasing.isPhasing = true; hasClicked = true; } } if (Input.GetMouseButtonDown(0)) { TargetPosition.SelectTile(); PlayerPosition.GetPlayerTile(); PlayerPhasing.PlayerPhase(); if (!tileIsPhasable) { inputTimer = 1; } if (tileIsPhasable) { timerStarted = true; } } if (hasClicked && !PlayerPhasing.isPhasing) { hasClicked = false; timerStarted = false; inputTimer = 0; } if (inputTimer > doubleClickTimingWindow && !hasClicked) { timerStarted = false; tileIsPhasable = false; inputTimer = 0; TargetPosition.SelectTile(); if (PathfindingManager.Instance.tilePath.Count == 0) { PlayerPosition.GetPlayerTile(); } else if (PathfindingManager.Instance.tilePath.Count != 0) { PlayerPosition.playerTile = PathfindingManager.Instance.tilePath[0]; } //If the player tile and target tile cords have both been found, the A* pathfinding begins. PathfindingManager.Instance.FindAstarPath(); } }
public new void Debug() { Player.print("Buster " + EntityId + " / state : " + State + " / position : " + Position.ToString() + " / target : " + TargetPosition.ToString() + " / can capture : " + CanCapture().ToString() + " / is holding : " + IsHoldingAGhost().ToString() + " / can release : " + CanRelease().ToString() + " / can attack : " + CanAttack().ToString() + " / can stun : " + CanStun + " / last turn stun : " + LastTurnStun.ToString() + " / ghost chased : " + ((GhostChased != null) ? GhostChased.EntityId : -1) + " / ghost in range : " + ((GhostInRange != null) ? GhostInRange.EntityId : -1) + " / enemy chased : " + ((EnemyChased != null) ? EnemyChased.EntityId : -1) + " / enemy in range : " + ((EnemyInRange != null) ? EnemyInRange.EntityId : -1) + " / stunned : " + IsStunned + " / busy : " + IsBusy()); }
public override string ToString() { return(GetType().Name + " " + Performer + " -> " + (TargetEntity != null ? TargetEntity.ToString() : TargetPosition.ToString()) + " (" + Math.Ceiling(duractionAcc) + "s left)"); }
public DirectionData(CharacterLocomotion.FACE_DIRECTION direction, TargetPosition target) { this.direction = direction; this.target = target; }
protected override void DecideOnNextAction() { if (CanDoAction() && Owner.CurrentRegion != null) { PatrolRoute ??= Owner.CurrentRegion.GetNodesInRegion().SelectMany(node => node).ToList().FindAll(node => node.Walkable).Select(node => node.Position).OrderBy(node => Guid.NewGuid()).ToList(); if (CanSeePlayerInUnobstructedLine || (CanSeeActivityInUnobstructedLine && Owner.CurrentRegion.HasDestructibleActivity)) { NextAction = KeyActionType.Shoot; } else { if (CurrentPatrolRoute is null || CurrentPatrolRoute.Count == 0) { CurrentPatrolRoute = new Stack <Vector2i>(PatrolRoute); } if (Path != null && !Path.Any()) { Path = null; } if (CurrentPatrolRoute != null && CurrentPatrolRoute.Any() && (Path == null || TargetPosition.IsInvalid() || TargetPosition.Equals(Owner.CurrentRegion.ConvertMapCoordsToRegionFieldCoords(Owner.Coords)))) { SetCooldown(0.05); TargetPosition = CurrentPatrolRoute.Pop(); Path ??= GeneratePath(Owner.CurrentRegion.GetNodesInRegion(), Owner.CurrentRegion.ConvertMapCoordsToRegionFieldCoords(Owner.Coords), TargetPosition); } NextAction = Path == null ? null : GetActionFromNextCoords(Path.Pop().Position + Owner.CurrentRegion.Coords * Owner.CurrentRegion.FieldsInLine); } } else { NextAction = null; } }
public override bool InstantExecute(GameObject target, IAction[] actions, int index) { CharacterShooter charShooter = this.shooter.GetComponent <CharacterShooter>(target); if (charShooter == null) { Debug.LogError("Target Game Object does not have a CharacterShooter component"); return(true); } Transform targetTransform = this.target.GetTransform(target); TargetPosition targetPosition = new TargetPosition(TargetPosition.Target.Transform); targetPosition.targetTransform = targetTransform; switch (this.aim) { case AimDirection.StopAiming: charShooter.StopAiming(); break; case AimDirection.AimCameraDirection: charShooter.StartAiming(new AimingCameraDirection(charShooter)); break; case AimDirection.AimAtTarget: AimingAtTarget aimingTarget = new AimingAtTarget(charShooter); aimingTarget.Setup(this.target); charShooter.StartAiming(aimingTarget); break; case AimDirection.AimAtPosition: AimingAtPosition aimingPosition = new AimingAtPosition(charShooter); aimingPosition.Setup(this.target); charShooter.StartAiming(aimingPosition); break; case AimDirection.AimMuzzleForward: AimingMuzzleForward aimingForward = new AimingMuzzleForward(charShooter); charShooter.StartAiming(aimingForward); break; case AimDirection.AimTopDownPlane: AimingGroundPlane aimingGround = new AimingGroundPlane(charShooter); charShooter.StartAiming(aimingGround); break; case AimDirection.AimTopDownFloor: AimingGroundFloor aimingFloor = new AimingGroundFloor(charShooter); charShooter.StartAiming(aimingFloor); break; case AimDirection.AimSideScroll: AimingSideScrollPlane aimingSidescroll = new AimingSideScrollPlane(charShooter); aimingSidescroll.Setup(this.axis); charShooter.StartAiming(aimingSidescroll); break; } return(true); }
private void Update(float elapsedTime, ref TargetPosition target, ref PositionFloat position, in Speed speed)