Exemple #1
0
        public bool GetFormationFrame(
            out WorldPosition formationPosition,
            out Vec2 formationDirection,
            out float speedLimit,
            out bool isSettingDestinationSpeed,
            out bool limitIsMultiplier,
            bool finalDestination = false)
        {
            Formation formation = this.Agent.Formation;

            isSettingDestinationSpeed = false;
            limitIsMultiplier         = false;
            bool flag = false;

            if (formation != null)
            {
                formationPosition  = formation.GetOrderPositionOfUnit(this.Agent);
                formationDirection = formation.GetDirectionOfUnit(this.Agent);
            }
            else
            {
                formationPosition  = WorldPosition.Invalid;
                formationDirection = Vec2.Invalid;
            }
            if (FormationCohesionComponent.FormationSpeedAdjustmentEnabled && this.Agent.IsMount)
            {
                formationPosition  = WorldPosition.Invalid;
                formationDirection = Vec2.Invalid;
                if (this.Agent.RiderAgent == null || this.Agent.RiderAgent != null && (!this.Agent.RiderAgent.IsActive() || this.Agent.RiderAgent.Formation == null))
                {
                    speedLimit = -1f;
                }
                else
                {
                    limitIsMultiplier = true;
                    speedLimit        = this.Agent.RiderAgent.GetComponent <FormationMovementComponent>().CohesionComponent.GetDesiredSpeedInFormation(formation.MovementOrder.MovementState == MovementOrder.MovementStateEnum.Charge);
                }
            }
            else if (formation == null)
            {
                speedLimit = -1f;
            }
            else if (formation.IsUnitDetached(this.Agent))
            {
                speedLimit = -1f;
                WorldFrame?nullable = new WorldFrame?();
                if (formation.MovementOrder.MovementState != MovementOrder.MovementStateEnum.Charge || this.Agent.Detachment != null && !this.Agent.Detachment.IsLoose)
                {
                    nullable = formation.GetDetachmentFrame(this.Agent);
                }
                if (nullable.HasValue)
                {
                    formationDirection = nullable.Value.Rotation.f.AsVec2.Normalized();
                    flag = true;
                }
                else
                {
                    formationDirection = Vec2.Invalid;
                }
            }
            else
            {
                switch (formation.MovementOrder.MovementState)
                {
                case MovementOrder.MovementStateEnum.Charge:
                    limitIsMultiplier = true;
                    speedLimit        = FormationCohesionComponent.FormationSpeedAdjustmentEnabled ? this.CohesionComponent.GetDesiredSpeedInFormation(true) : -1f;
                    break;

                case MovementOrder.MovementStateEnum.Hold:
                    isSettingDestinationSpeed = true;
                    if (FormationCohesionComponent.FormationSpeedAdjustmentEnabled && this.CohesionComponent.ShouldCatchUpWithFormation)
                    {
                        limitIsMultiplier = true;
                        speedLimit        = this.CohesionComponent.GetDesiredSpeedInFormation(false);
                    }
                    else
                    {
                        speedLimit = -1f;
                    }
                    flag = true;
                    break;

                case MovementOrder.MovementStateEnum.Retreat:
                    speedLimit = -1f;
                    break;

                case MovementOrder.MovementStateEnum.StandGround:
                    formationDirection = this.Agent.Frame.rotation.f.AsVec2;
                    speedLimit         = -1f;
                    flag = true;
                    break;

                default:
                    speedLimit = -1f;
                    break;
                }
            }
            return(flag);
        }