示例#1
0
    protected override void Update(Entity entity, CharBehaviour charAbility, AbilityControl abilityCtrl,
                                   Ability_AutoRifle.PredictedState predictedState, Ability_AutoRifle.Settings settings)
    {
        if (abilityCtrl.behaviorState == AbilityControl.State.Active || abilityCtrl.behaviorState == AbilityControl.State.Cooldown)
        {
            return;
        }

        var command = EntityManager.GetComponentData <UserCommandComponentData>(charAbility.character).command;
        var request = Ability_AutoRifle.GetPreferredState(ref predictedState, ref settings, ref command);

        abilityCtrl.behaviorState = request != Ability_AutoRifle.State.Idle ?  AbilityControl.State.RequestActive : AbilityControl.State.Idle;


        EntityManager.SetComponentData(entity, abilityCtrl);
    }
示例#2
0
    protected override void Update(Entity abilityEntity, CharBehaviour charAbility, AbilityControl abilityCtrl,
                                   Ability_AutoRifle.PredictedState predictedState, Ability_AutoRifle.Settings settings)
    {
        // Decrease cone
        if (predictedState.action != Ability_AutoRifle.State.Fire)
        {
            predictedState.COF -= settings.COFDecreaseVel * m_world.worldTime.tickDuration;
            if (predictedState.COF < settings.minCOF)
            {
                predictedState.COF = settings.minCOF;
            }
        }
        EntityManager.SetComponentData(abilityEntity, predictedState);

        if (abilityCtrl.active == 0)
        {
            return;
        }

        var command = EntityManager.GetComponentData <UserCommandComponentData>(charAbility.character).command;

        switch (predictedState.action)
        {
        case Ability_AutoRifle.State.Idle:
        {
            var request = Ability_AutoRifle.GetPreferredState(ref predictedState, ref settings, ref command);
            if (request == Ability_AutoRifle.State.Reload)
            {
                EnterReloadingPhase(abilityEntity, ref abilityCtrl, ref predictedState, m_world.worldTime.tick);
                break;
            }

            if (request == Ability_AutoRifle.State.Fire)
            {
                EnterFiringPhase(abilityEntity, ref abilityCtrl, ref predictedState, m_world.worldTime.tick);
                break;
            }

            break;
        }

        case Ability_AutoRifle.State.Fire:
        {
            var fireDuration  = 1.0f / settings.roundsPerSecond;
            var phaseDuration = m_world.worldTime.DurationSinceTick(predictedState.phaseStartTick);
            if (phaseDuration > fireDuration)
            {
                var request = Ability_AutoRifle.GetPreferredState(ref predictedState, ref settings, ref command);
                if (request == Ability_AutoRifle.State.Fire && predictedState.ammoInClip > 0)
                {
                    EnterFiringPhase(abilityEntity, ref abilityCtrl, ref predictedState, m_world.worldTime.tick);
                }
                else
                {
                    EnterIdlePhase(abilityEntity, ref abilityCtrl, ref predictedState, m_world.worldTime.tick);
                }
            }

            break;
        }

        case Ability_AutoRifle.State.Reload:
        {
            var phaseDuration = m_world.worldTime.DurationSinceTick(predictedState.phaseStartTick);
            if (phaseDuration > settings.reloadDuration)
            {
                var neededInClip = settings.clipSize - predictedState.ammoInClip;
                predictedState.ammoInClip += neededInClip;

                EnterIdlePhase(abilityEntity, ref abilityCtrl, ref predictedState, m_world.worldTime.tick);
            }

            break;
        }
        }
    }