Esempio n. 1
0
        private void UpdateUnitAbilityActivations(List <UnitAbilityActivationMessage> receivedUnitAbilityMessagesSinceLastFrame)
        {
            // sort by oldest frame to newest frame
            receivedUnitAbilityMessagesSinceLastFrame.Sort((message1, message2) =>
            {
                return(message1.StartFrame == message2.StartFrame ? 0 : MatchSimulationUnit.IsFrameInFuture(message1.StartFrame, message2.StartFrame) ? 1 : -1);
            });

            for (int i = 0; i < receivedUnitAbilityMessagesSinceLastFrame.Count; i++)
            {
                UnitAbilityActivationMessage unitAbilityActivationMessage = receivedUnitAbilityMessagesSinceLastFrame[i];

                MatchSimulationUnit unitToUpdate;
                if (simulationUnits.TryGetValue(unitAbilityActivationMessage.UnitId, out unitToUpdate))
                {
                    unitToUpdate.AbilityActivationSubject.OnNext(new AbilityActivation
                    {
                        Rotation        = UnitValueConverter.ToUnityRotation(unitAbilityActivationMessage.Rotation),
                        StartFrame      = unitAbilityActivationMessage.StartFrame,
                        ActivationFrame = unitAbilityActivationMessage.ActivationFrame
                    });
                }
            }
        }
Esempio n. 2
0
 public Vector3 GetUnityPosition()
 {
     return(new Vector3(UnitValueConverter.ToUnityPosition(XPosition), 0f, UnitValueConverter.ToUnityPosition(YPosition)));
 }
Esempio n. 3
0
 public Quaternion GetUnityRotation()
 {
     return(Quaternion.Euler(0f, UnitValueConverter.ToUnityRotation(Rotation), 0f));
 }
Esempio n. 4
0
    protected virtual void UpdateToNextState(byte currentFrame)
    {
        int   speedPartToModify = 390 / 6;
        float queueCount        = interpolationQueue.Count;
        float frameDelay        = FrameDelay;

        // quick decrease, slow increase
        float maxSpeedThisFrame = Mathf.Min(1f, lastMovementSpeedModifier + 0.05f);
        float minSpeedThisFrame = Mathf.Max(0f, lastMovementSpeedModifier - 0.3f);

        float movementSpeedModifier       = Mathf.Clamp01(Mathf.Clamp(queueCount / frameDelay, minSpeedThisFrame, maxSpeedThisFrame));
        int   movementSpeedForFrame       = (int)(390 - speedPartToModify + (speedPartToModify * movementSpeedModifier));
        float movevementDistanceAvailable = UnitValueConverter.ToUnityPosition(movementSpeedForFrame);

        lastMovementSpeedModifier = movementSpeedModifier;

        /*DIContainer.Logger.Debug(string.Format("Movement speed for frame: {0} Modifier: {1} QueueCount: {2} Delay: {3}",
         *                                     movementSpeedForFrame, movementSpeedModifier, interpolationQueue.Count, PositionFrameDelay));*/

        if (CurrentStateToLerpTo != null)
        {
            AdvanceLerpToPositionState(CurrentStateToLerpTo, ref movevementDistanceAvailable);

            if (CurrentStateToLerpTo == null)
            {
                // to ensure next lerp is started so wait frame that results in a stutter is generated.
                StartLerpingIfValid(currentFrame, ref movevementDistanceAvailable);
            }
        }
        else if (!StartLerpingIfValid(currentFrame, ref movevementDistanceAvailable))
        {
            /*StringBuilder stringBuilder = new StringBuilder();
             * InterpolationState[] stateArray = interpolationQueue.ToArray();
             * for (int i = 0; i < stateArray.Length; i++)
             * {
             *  stringBuilder.Append(stateArray[i].TargetFrame);
             *  stringBuilder.Append(" ");
             * }
             *
             * DIContainer.Logger.Warn(string.Format("No state to update to at frame: {0} existing frames: {1}", currentFrame, stringBuilder));*/

            movementChangedCounter++;

            if (movementChangedCounter > 2 && animator != null)
            {
                animator.SetBool("Running", false);
            }
        }

        if (currentAbilityActivation != null &&
            (MatchSimulationUnit.IsFrameInFuture(currentFrame, currentAbilityActivation.StartFrame) ||
             currentFrame == currentAbilityActivation.StartFrame))
        {
            modelRoot.transform.rotation     = Quaternion.Euler(0f, currentAbilityActivation.Rotation, 0f);
            telegraphRoot.transform.rotation = Quaternion.Euler(0f, currentAbilityActivation.Rotation, 0f);

            if (!currentAbilityActivation.Started)
            {
                telegraphRoot.gameObject.SetActive(true);
                telegraphFillRoot.gameObject.SetActive(true);

                if (animator != null)
                {
                    animator.SetTrigger("Attack");
                }

                currentAbilityActivation.Started = true;
            }

            if (MatchSimulationUnit.IsFrameInFuture(currentFrame, currentAbilityActivation.ActivationFrame) || currentFrame == currentAbilityActivation.ActivationFrame)
            {
                currentAbilityActivation = null;
                telegraphRoot.gameObject.SetActive(false);
                telegraphFillRoot.gameObject.SetActive(true);
                telegraphFillRoot.transform.localScale = new Vector3(0f, 1f, 0f);
            }
            else
            {
                UpdateTelegraphFillState(currentFrame);
            }
        }
    }