Beispiel #1
0
    protected override void UpdateToNextState(byte currentFrame)
    {
        if (currentAbilityActivation != null)
        {
            telegraphRoot.transform.rotation = Quaternion.Euler(0f, currentAbilityActivation.Rotation, 0f);
            UpdateTelegraphFillState(currentFrame);
            if (MatchSimulationUnit.IsFrameInFuture(currentFrame, currentAbilityActivation.ActivationFrame) || currentFrame == currentAbilityActivation.ActivationFrame)
            {
                //TODO: Show telegraph 'timer'
                telegraphRoot.gameObject.SetActive(false);
                telegraphFillRoot.gameObject.SetActive(false);
                currentAbilityActivation = null;
            }

            return;
        }

        if (receivedLocalAimingUpdate)
        {
            receivedLocalAimingUpdate = false;
        }
        else
        {
            telegraphRoot.gameObject.SetActive(false);
        }
    }
Beispiel #2
0
 public void Initialize(MatchSimulationUnit unitState)
 {
     unitState.HealthPercent
     .Select(healthPercent => Mathf.InverseLerp(0, 100, healthPercent))
     .Subscribe(UpdateHealthFill)
     .AddTo(this);
 }
Beispiel #3
0
    public override void OnSpawn(MatchSimulationUnit unitState, MatchSimulation matchSimulation)
    {
        base.OnSpawn(unitState, matchSimulation);

        MatchSimulationLocalPlayer localPlayer = unitState as MatchSimulationLocalPlayer;

        if (localPlayer != null)
        {
            localPlayer.LocalAimingSubject
            .Subscribe(OnLocalAimingUpdate);
        }
    }
Beispiel #4
0
    private bool ShouldLerpToState(InterpolationState state, byte currentFrame)
    {
        // is state in past or current frame? Should never happen.
        if (MatchSimulationUnit.IsFrameInFuture(currentFrame, state.TargetFrame) || currentFrame == state.TargetFrame)
        {
            return(true);
        }

        Vector3 positionDiff = state.TargetPosition - this.transform.position;
        byte    frameDiff    = MathHelper.GetFrameDiff(currentFrame, state.TargetFrame);
        byte    maxFramesForPositionChange = MathHelper.GetRoundedMaxFramesForPositionChange(positionDiff);
        bool    shouldLerp = (frameDiff - maxFramesForPositionChange) <= 1 || frameDiff == 0;

        /*DIContainer.Logger.Debug(string.Format("ShouldLerp: {0} PositionDiff: {1} FrameDiff: {2} FramesForPositionChange: {3} CurrentFrame: {4} TargetFrame: {5}",
         *                                     shouldLerp, positionDiff, frameDiff, maxFramesForPositionChange, currentFrame, state.TargetFrame));*/

        return(shouldLerp);
    }
Beispiel #5
0
    public virtual void OnSpawn(MatchSimulationUnit unitState, MatchSimulation matchSimulation)
    {
        InitializeChildComponents();
        transform.position = unitState.MovementState.Value.GetUnityPosition();
        transform.rotation = unitState.MovementState.Value.GetUnityRotation();

        unitState.MovementState
        .Subscribe(OnPositionRotationUpdate)
        .AddTo(this);

        healthbar.Initialize(unitState);

        matchSimulation.SimulationFrameSubject
        .Subscribe(UpdateToNextState)
        .AddTo(this);

        unitState.AbilityActivationSubject
        .Subscribe(abilityActivation => OnAbilityActivation(abilityActivation.Rotation, abilityActivation.StartFrame, abilityActivation.ActivationFrame));
    }
Beispiel #6
0
        public void OnUnitSpawn(byte unitId, byte unitType, MatchSimulationUnit unitState, MatchSimulation matchSimulation, bool isLocalPlayer = false)
        {
            GameObject unitGameobject;

            if (viewUnitPrefabs.TryGetValue(unitType, out unitGameobject))
            {
                // TODO: get from pool instead
                GameObject spawnedGameObject = MonoBehaviour.Instantiate(unitGameobject);
                MatchSimulationViewUnit matchSimulationViewUnit;

                if (isLocalPlayer)
                {
                    matchSimulationViewUnit = spawnedGameObject.AddComponent <MatchSimulationLocalPlayerViewUnit>();
                    CameraRoot.transform.SetParent(spawnedGameObject.transform);
                }
                else
                {
                    matchSimulationViewUnit = spawnedGameObject.AddComponent <MatchSimulationViewUnit>();
                }

                spawnedGameObject.SetActive(true);
                matchSimulationViewUnit.OnSpawn(unitState, matchSimulation);
            }
        }
Beispiel #7
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);
            }
        }
    }