public void Execute() { DynamicBuffer <PathPosition> pathPositionBuffer = pathPositionBufferFromEntity[entity]; pathPositionBuffer.Clear(); DestinationComponent destination = destinationComponentDataFromEntity[entity]; int endNodeIndex = CalculateIndex(destination.endPosition.x, destination.endPosition.y, gridSize.x); PathNode endNode = pathNodeArray[endNodeIndex]; if (endNode.cameFromNodeIndex == -1) { //Debug.Log("Didn't find a path!"); pathFollowComponentDataFromEntity[entity] = new PathFollow { pathIndex = -1 }; } else { // Found a path CalculatePath(pathNodeArray, endNode, pathPositionBuffer); pathFollowComponentDataFromEntity[entity] = new PathFollow { pathIndex = pathPositionBuffer.Length - 1 }; } }
protected override void OnUpdate() { var group = World.GetExistingSystem <ServerSimulationSystemGroup>(); var tick = group.ServerTick; var deltaTime = Time.DeltaTime; Entities.ForEach((ref Dash dash, ref Usable usable, ref OwningPlayer player, ref Cooldown cooldown) => { if (usable.inuse) { if (cooldown.timer == cooldown.duration) { // just used ability DestinationComponent dest = EntityManager.GetComponentData <DestinationComponent>(player.Value); CanMove canmove = EntityManager.GetComponentData <CanMove>(player.Value); dest.Valid = false; canmove.Value = false; EntityManager.SetComponentData <DestinationComponent>(player.Value, dest); EntityManager.SetComponentData <CanMove>(player.Value, canmove); } Debug.Log("DashSystem inuse is true"); GamePosition pos = EntityManager.GetComponentData <GamePosition>(player.Value); Rotation rot = EntityManager.GetComponentData <Rotation>(player.Value); float3 direction = math.rotate(rot.Value, dash.dir); pos.Value += direction.xz * dash.speed * deltaTime; dash.distance_traveled += dash.speed * deltaTime; EntityManager.SetComponentData <GamePosition>(player.Value, pos); if (dash.distance_traveled >= dash.max_distance) { usable.inuse = false; EntityManager.SetComponentData <CanMove>(player.Value, new CanMove { Value = true }); if (cooldown.timer < 0) { usable.canuse = true; } dash.distance_traveled = 0; } } }); }
protected override void OnUpdate() { var group = World.GetExistingSystem <ServerSimulationSystemGroup>(); var tick = group.ServerTick; var deltaTime = Time.DeltaTime; Entities.ForEach((ref Shield shield, ref Usable usable, ref OwningPlayer player, ref AngleInput angle, ref Releasable releasable) => { if (releasable.released) { usable.inuse = false; releasable.released = false; } if (usable.inuse) { usable.canuse = true; // keep this true always DestinationComponent dest = EntityManager.GetComponentData <DestinationComponent>(player.Value); dest.Valid = false; EntityManager.SetComponentData <DestinationComponent>(player.Value, dest); } else { // pass } }); Entities.ForEach((ref ShieldHitbox hitbox, ref AssociatedEntity shield, ref Rotation rot, ref OwningPlayer player) => { AngleInput angle = EntityManager.GetComponentData <AngleInput>(shield.Value); // just hack to make it match the animation float clampedAngle = Mathf.Clamp(angle.Value, -90, 0) + 15; Rotation playerRot = EntityManager.GetComponentData <Rotation>(player.Value); rot.Value = playerRot.Value * Quaternion.AngleAxis(clampedAngle, Vector3.up); }); }
protected override void OnUpdate() { var group = World.GetExistingSystem <ServerSimulationSystemGroup>(); var tick = group.ServerTick; var deltaTime = Time.DeltaTime; Entities.ForEach((ref Sword sword, ref Usable usable, ref OwningPlayer player, ref Cooldown cooldown) => { //GameObject animatingBody = EntityManager.GetComponentObject<GameObject>(player.Value); //Animator anim = animatingBody.GetComponent<Animator>(); //float speed = anim.GetFloat("StabSpeed"); //float stabTime = Utility.AnimationLength("CharArmature|Stab", animatingBody) / speed; float stabTime = 0.25f; // TODO the order of operations matters here probably? if (usable.inuse) { BusyTimer busyTimer = EntityManager.GetComponentData <BusyTimer>(player.Value); if (cooldown.timer == cooldown.duration) { // make agent unable to move, unset destination, start animation DestinationComponent dest = EntityManager.GetComponentData <DestinationComponent>(player.Value); dest.Valid = false; busyTimer.Value = stabTime; EntityManager.SetComponentData <DestinationComponent>(player.Value, dest); EntityManager.SetComponentData <BusyTimer>(player.Value, busyTimer); //anim.SetBool("Idle", true); //anim.SetBool("Stabbing", true); } if (cooldown.timer > 0 && cooldown.timer < cooldown.duration - stabTime) { usable.inuse = false; //anim.SetBool("Stabbing", false); //anim.SetBool("Idle", true); } } }); Entities.ForEach((Entity ent, DynamicBuffer <Hit> hitBuffer, ref StabHitbox stab, ref Rotation rot, ref Damage damage) => { List <Hit> hitList = new List <Hit>(); for (int i = 0; i < hitBuffer.Length; i++) { var hit = hitBuffer[i]; hit.knockback = math.rotate(rot.Value, Utility.v3tof3(Vector3.forward)); hit.damage = damage.Value; hitBuffer[i] = hit; hitList.Add(hit); } for (int i = 0; i < hitList.Count; i++) { var hit = hitList[i]; var hurtboxBuffer = EntityManager.GetBuffer <Hit>(hit.ent); hit.ent = ent; hurtboxBuffer.Add(hit); } hitBuffer.Clear(); }); }