public ServerObjectAvailabilityChanged(RoutingMetaPacket internalMetaPacket) : base(internalMetaPacket)
        {
            InternalMetaPacket.PacketId = AEPacketId.ServerNewObjectAvailable;

            RoutingObject = InternalPacket.ReadRoutingComponent();
            Available     = InternalPacket.ReadBoolean();
        }
Beispiel #2
0
        public static void PostPlanRouteCallback(Route r, string routeType, string result)
        {
            try
            {
                if ((r.Follower != null) && (r.Follower.Target is Sim))
                {
                    if (((r.GetOption(Route.RouteOption.EnableSubwayPlanning)) || (r.GetOption2(Route.RouteOption2.EnableHoverTrainPlanning))) && !r.GetOption(Route.RouteOption.EnableUFOPlanning))
                    {
                        CheckAndUpdateRouteForPortals(r);
                    }

                    if (((routeType == "Replan") || (routeType == "ReplanFromPoint")) && r.GetOption(Route.RouteOption.PlanUsingStroller))
                    {
                        r.SetOption(Route.RouteOption.ReplanUsingStroller, false);
                    }

                    if (RoutingComponent.sPostPlanProfileCallback != null)
                    {
                        RoutingComponent.sPostPlanProfileCallback(r, routeType, result);
                    }
                }
            }
            catch (Exception e)
            {
                Common.Exception("PostPlanRouteCallback", e);
            }
        }
Beispiel #3
0
        public ClientHandshakeBeginPacket(RoutingMetaPacket metaPacket) : base(metaPacket)
        {
            InternalMetaPacket.PacketId = AEPacketId.ClientHandshakeBegin;

            Protocol  = InternalPacket.ReadUInt32();
            Password  = InternalPacket.ReadShortString();
            Component = InternalPacket.ReadRoutingComponent();
        }
        internal FeatureConfigurationContext(ReadOnlySettings settings, IConfigureComponents container, PipelineSettings pipelineSettings, RoutingComponent routing)
        {
            Settings  = settings;
            Container = container;
            Pipeline  = pipelineSettings;
            Routing   = routing;

            TaskControllers = new List <FeatureStartupTaskController>();
        }
    private static RouterService WalkAncestorsForRouterService(DependencyObject dependencyObject)
    {
        var routerService = from ancestor in dependencyObject.AncestorsAndSelf()
                            let service = RoutingComponent.GetRouterService(ancestor)
                                          where service != null
                                          select service;

        return(routerService.LastOrDefault());
    }
        public ServerHandshakeResultPacket(RoutingMetaPacket metaPacket) : base(metaPacket)
        {
            InternalMetaPacket.PacketId = AEPacketId.ServerHandshakeResult;

            Result = ReadSHRPResult();

            if (Result == SHRPResult.Success)
            {
                OurComponent             = InternalPacket.ReadRoutingComponent();
                OtherAvailableComponents = InternalPacket.ReadList(PacketExtensions.ReadRoutingComponent);
            }
        }
    private static void RegisterViewportWithService(RouterService service, FrameworkElement control)
    {
        var viewportName          = RoutingComponent.GetViewportName(control);
        var viewportAdapterOption = ControlViewportAdapterFactory.GetControlViewportAdapter(control);

        viewportAdapterOption.Match(
            some: viewportAdapter =>
        {
            RoutingComponentsHelperLogHelper.LogRegisteringViewportMessage(service, control, viewportName);

            service.RegisterViewport(viewportName, viewportAdapter);

            RoutingComponentsHelperLogHelper.LogViewportRegisteredMessage(service, control, viewportName);
        },
            none: () =>
        {
            RoutingComponentsHelperLogHelper.LogViewportAdapterNotFoundMessage(service, control);
        });
    }
Beispiel #8
0
        public FeaturesReport SetupFeatures(IConfigureComponents container, PipelineSettings pipelineSettings, RoutingComponent routing)
        {
            // featuresToActivate is enumerated twice because after setting defaults some new features might got activated.
            var sourceFeatures = Sort(features);

            var enabledFeatures = new List <FeatureInfo>();

            while (true)
            {
                var featureToActivate = sourceFeatures.FirstOrDefault(x => settings.IsFeatureEnabled(x.Feature.GetType()));
                if (featureToActivate == null)
                {
                    break;
                }
                sourceFeatures.Remove(featureToActivate);
                enabledFeatures.Add(featureToActivate);
                featureToActivate.Feature.ConfigureDefaults(settings);
            }

            foreach (var feature in enabledFeatures)
            {
                ActivateFeature(feature, enabledFeatures, container, pipelineSettings, routing);
            }

            settings.PreventChanges();

            return(new FeaturesReport(features.Select(t => t.Diagnostics).ToList()));
        }
Beispiel #9
0
        bool ActivateFeature(FeatureInfo featureInfo, List <FeatureInfo> featuresToActivate, IConfigureComponents container, PipelineSettings pipelineSettings, RoutingComponent routing)
        {
            if (featureInfo.Feature.IsActive)
            {
                return(true);
            }

            Func <List <string>, bool> dependencyActivator = dependencies =>
            {
                var dependantFeaturesToActivate = new List <FeatureInfo>();

                foreach (var dependency in dependencies.Select(dependencyName => featuresToActivate
                                                               .SingleOrDefault(f => f.Feature.Name == dependencyName))
                         .Where(dependency => dependency != null))
                {
                    dependantFeaturesToActivate.Add(dependency);
                }
                return(dependantFeaturesToActivate.Aggregate(false, (current, f) => current | ActivateFeature(f, featuresToActivate, container, pipelineSettings, routing)));
            };
            var featureType = featureInfo.Feature.GetType();

            if (featureInfo.Feature.Dependencies.All(dependencyActivator))
            {
                featureInfo.Diagnostics.DependenciesAreMet = true;

                var context = new FeatureConfigurationContext(settings, container, pipelineSettings, routing);
                if (!HasAllPrerequisitesSatisfied(featureInfo.Feature, featureInfo.Diagnostics, context))
                {
                    settings.MarkFeatureAsDeactivated(featureType);
                    return(false);
                }
                settings.MarkFeatureAsActive(featureType);
                featureInfo.Feature.SetupFeature(context);
                featureInfo.TaskControllers          = context.TaskControllers;
                featureInfo.Diagnostics.StartupTasks = context.TaskControllers.Select(d => d.Name).ToList();
                featureInfo.Diagnostics.Active       = true;
                return(true);
            }
            settings.MarkFeatureAsDeactivated(featureType);
            featureInfo.Diagnostics.DependenciesAreMet = false;
            return(false);
        }
Beispiel #10
0
        public static bool DoRoute(RoutingComponent ths, Route r)
        {
            Sim owner = ths.Owner as Sim;

            if ((!r.ExecutionFromNonSimTaskIsSafe && (owner != null)) && (Simulator.CurrentTask != ths.Owner.ObjectId))
            {
                Simulator.CurrentTask.ObjectFromId <GameObject>();
                return(false);
            }

            IBoat boat = ths.Owner as IBoat;

            if (ths.RoutingParent != null)
            {
                if (!(ths.RoutingParent is IBoat) || (r.GetOption2(Route.RouteOption2.EndAsBoat) && (!r.PlanResult.Succeeded() || !RoutingComponent.PlannedRouteHasNonBoatSubpath(r))))
                {
                    // Custom
                    if (ths.RoutingParent.RoutingComponent is CarRoutingComponent)
                    {
                        return(CarRoutingComponentEx.DoRoute(ths.RoutingParent.RoutingComponent as CarRoutingComponent, r));
                    }
                    else
                    {
                        return(ths.RoutingParent.RoutingComponent.DoRoute(r));
                    }
                }
            }
            else if (((boat != null) && r.PlanResult.Succeeded()) && (!r.GetOption2(Route.RouteOption2.EndAsBoat) || RoutingComponent.PlannedRouteHasNonBoatSubpath(r)))
            {
                Sim driver = boat.GetDriver();
                if (driver != null)
                {
                    return(driver.RoutingComponent.DoRoute(r));
                }
            }

            Common.StringBuilder msg = new Common.StringBuilder("RoutingComponentEx:DoRoute" + Common.NewLine);
            if (owner != null)
            {
                msg += Common.NewLine + owner.FullName + Common.NewLine;
            }

            ths.mRouteActions.Clear();
            bool routeSuccess = true;

            try
            {
                RouteAction.FailureExplanation explanation = RouteAction.FailureExplanation.None;
                RoutingComponent.mnNumDoRouteCalls += (ulong)0x1L;
                if (r.PlanResult.Succeeded())
                {
                    ths.OnAboutToStartFollowingRoute(r);
                    if (r.PlanResult.Succeeded())
                    {
                        ths.PushActionsForRoute(r, r);
                        if (owner != null)
                        {
                            owner.PushBackpackPostureIfNecessary();
                            owner.PushCanePostureIfNecessary();
                            owner.PushJetpackPostureIfNecessary();
                        }
                    }
                    else
                    {
                        routeSuccess = false;
                    }
                }
                else
                {
                    routeSuccess = false;
                }

                msg.Append("A");

                if (!routeSuccess)
                {
                    explanation |= RouteAction.FailureExplanation.InitialPlanFailure;
                    LogFailure(ths.Owner, RouteAction.FailureExplanation.InitialPlanFailure, r.PlanResult, "Initial Path Plan Failure (WILL NOT play route fail)");
                    r.SetRouteActionResult(0x2);
                    return(false);
                }

                msg.Append("B");

                int failures = 0;

                if ((ths.RoutingParent != null) && (ths.RoutingParent is IBoat))
                {
                    ths.UpdateDynamicFootprint(ths.RoutingParent as GameObject, false);
                }
                else
                {
                    ths.UpdateDynamicFootprint(ths.Owner, false);
                }

                Vector3 originalPosition = ths.Owner.Position;
                int     loops            = 0;

                bool  success       = true;
                Route processedPath = r;
                bool  isOutside     = ths.Owner.IsOutside;
                ths.mNumWaterEntriesThisRoute = 0;
                while (ths.mRouteActions.Count != 0x0)
                {
                    // Custom
                    if (ths.Owner.Position == originalPosition)
                    {
                        loops++;
                    }

                    if ((loops > 30) || (ths.mRouteActions.Count > 30))
                    {
                        success = false;
                        ths.mRouteActions.Clear();
                        break;
                    }

                    if (ths.mRouteActions[0] is GetInBoatRouteAction)
                    {
                        ths.mNumWaterEntriesThisRoute++;
                        if (ths.mNumWaterEntriesThisRoute > 10)
                        {
                            if (owner != null)
                            {
                                owner.SetToResetAndSendHome();
                            }
                            else
                            {
                                ths.Owner.SetObjectToReset();
                            }
                            return(false);
                        }
                    }

                    if ((owner != null) && owner.IsOutside)
                    {
                        owner.PushHoverboardPostureIfNecessary();
                    }

                    // Custom
                    RouteAction routeAction = ths.mRouteActions[0x0];

                    msg.Append(Common.NewLine + routeAction.GetType());

                    RouteAction.ActionResult actionResult = RouteAction.ActionResult.Continue;

                    //using (BuffsChangedProxy buffsProxy = new BuffsChangedProxy(owner))
                    {
                        try
                        {
                            if (routeAction is ObstacleEncounteredRouteInterruptAction)
                            {
                                actionResult = ObstacleEncounteredRouteInterruptActionEx.PerformAction(routeAction as ObstacleEncounteredRouteInterruptAction);
                            }
                            else
                            {
                                actionResult = routeAction.PerformAction();
                            }
                        }
                        catch (ResetException)
                        {
                            throw;
                        }
                        catch (SacsErrorException e)
                        {
                            Common.DebugException(owner, null, msg, e);

                            failures++;

                            if (failures > 10)
                            {
                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else
                            {
                                actionResult = RouteAction.ActionResult.ContinueAndPopPathAndReplan;
                            }

                            routeAction.OnReset();
                        }
                        catch (Exception e)
                        {
                            Common.Exception(owner, null, msg.ToString(), e);

                            string stackTrace = e.StackTrace.ToString();

                            if (stackTrace.Contains("OccultManager:DisallowClothesChange"))
                            {
                                OccultTypeHelper.ValidateOccult(owner.SimDescription, null);

                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else if (stackTrace.Contains("CommonDoor:IsAllowedThrough"))
                            {
                                Corrections.CleanupCommonDoors(null);
                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else if (stackTrace.Contains("SimRoutingComponent:RequestWalkStyle"))
                            {
                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else
                            {
                                failures++;

                                if (failures > 10)
                                {
                                    actionResult = RouteAction.ActionResult.Terminate;
                                }
                                else
                                {
                                    actionResult = RouteAction.ActionResult.ContinueAndPopPathAndReplan;
                                }
                            }

                            routeAction.OnReset();
                        }
                    }

                    msg.Append(Common.NewLine + "C");

                    // Custom
                    if ((ths.mRouteActions.Count > 0) && (ths.mRouteActions[0x0].ForciblyReplanned) && (actionResult == RouteAction.ActionResult.ContinueAndPopPath))
                    {
                        actionResult = RouteAction.ActionResult.ContinueAndFollowPath;
                    }

                    msg.Append(Common.NewLine + actionResult + Common.NewLine);

                    if (GoHere.Settings.mDetailedRouting)
                    {
                        if (Sim.ActiveActor == owner)
                        {
                            Common.DebugNotify(msg);
                        }
                    }

                    if (ths.mRouteActions.Count == 0x0)
                    {
                        explanation |= RouteAction.FailureExplanation.InternalPlanFailure;
                        success      = false;
                        break;
                    }

                    msg.Append("D");

                    ths.mPreviousRouteAction = ths.mRouteActions[0x0];
                    switch (actionResult)
                    {
                    case RouteAction.ActionResult.Continue:
                    case RouteAction.ActionResult.ContinueAndPopPath:
                    case RouteAction.ActionResult.ContinueAndPopPathAndReplan:
                    case RouteAction.ActionResult.ContinueAndPopPathAndRestart:
                    case RouteAction.ActionResult.ContinueAndFollowPath:
                        msg.Append("E");

                        ths.mRouteActions.RemoveAt(0x0);
                        bool flag3 = (processedPath.GetNumPaths() > 0x1) || (processedPath.IsLoop());
                        if (((actionResult == RouteAction.ActionResult.ContinueAndPopPath) && flag3) || ((actionResult == RouteAction.ActionResult.ContinueAndPopPathAndRestart) || (actionResult == RouteAction.ActionResult.ContinueAndPopPathAndReplan)))
                        {
                            if (flag3)
                            {
                                processedPath.PopPath();
                            }

                            msg.Append("F");

                            if (actionResult == RouteAction.ActionResult.ContinueAndPopPathAndReplan)
                            {
                                Vector3 outPosition = new Vector3();
                                if ((ths.RoutingParent != null) && (ths.RoutingParent is IBoat))
                                {
                                    outPosition = ths.RoutingParent.PositionOnFloor;
                                }
                                else if (ths.Owner != null)
                                {
                                    if ((owner != null) && (owner.Posture is SwimmingInPool))
                                    {
                                        outPosition = ths.Owner.Position;
                                    }
                                    else
                                    {
                                        outPosition = ths.Owner.PositionOnFloor;
                                    }
                                }
                                else
                                {
                                    processedPath.GetPathStartPoint(0x0, ref outPosition);
                                }
                                processedPath.ReplanFromPoint(outPosition);
                            }

                            msg.Append("G");

                            if (actionResult == RouteAction.ActionResult.ContinueAndPopPathAndRestart)
                            {
                                Vector3 positionOnFloor = new Vector3();
                                if (ths.Owner != null)
                                {
                                    positionOnFloor = ths.Owner.PositionOnFloor;
                                }
                                else
                                {
                                    processedPath.GetPathStartPoint(0x0, ref positionOnFloor);
                                }
                                processedPath.SetOption(Route.RouteOption.EnablePlanningAsCar, false);
                                processedPath.SetOption(Route.RouteOption.EnableSubwayPlanning, false);
                                processedPath.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, false);
                                processedPath.ReplanFromPoint(positionOnFloor);
                                explanation |= RouteAction.FailureExplanation.CancelledByScript;
                                success      = false;
                                ths.mRouteActions.Clear();
                            }
                            else if (processedPath.PlanResult.Succeeded())
                            {
                                ths.PushActionsForRoute(r, processedPath);
                            }
                            else
                            {
                                explanation |= RouteAction.FailureExplanation.ReplanFailure;
                                success      = false;
                                ths.mRouteActions.Clear();
                            }
                        }
                        else if ((actionResult == RouteAction.ActionResult.ContinueAndFollowPath) && (r.GetNumPaths() > 0x0))
                        {
                            msg.Append("H");

                            if (r.PlanResult.Succeeded())
                            {
                                ths.PushActionsForRoute(r, processedPath);
                            }
                            else
                            {
                                explanation |= RouteAction.FailureExplanation.InternalPlanFailure;
                                success      = false;
                                ths.mRouteActions.Clear();
                            }
                        }
                        break;

                    default:
                        msg.Append("I");

                        explanation |= ths.mPreviousRouteAction.FailureExplanations;
                        success      = false;
                        ths.mRouteActions.Clear();
                        break;
                    }
                }

                msg.Append("J");

                ths.mRouteActions.Clear();
                r.SetRouteActionResult((uint)explanation);
                if (!success)
                {
                    if (ths.mPreviousRouteAction == null)
                    {
                        LogFailure(ths.Owner, explanation, r.PlanResult, "(Null mPreviousRouteAction failure)");
                    }
                    else
                    {
                        LogFailure(ths.Owner, explanation, r.PlanResult, "(failure in " + ths.mPreviousRouteAction.ToString() + ")");
                    }
                }

                msg.Append("K");

                if ((ths.RoutingParent != null) && (ths.RoutingParent is IBoat))
                {
                    ths.UpdateDynamicFootprint(ths.RoutingParent as GameObject, true);
                }
                else
                {
                    ths.UpdateDynamicFootprint(ths.Owner, true);
                }

                routeSuccess             = (success && (processedPath == r)) && r.PlanResult.Succeeded();
                ths.mPreviousRouteAction = null;
                if (ths.OnRouteActionsFinished != null)
                {
                    ths.OnRouteActionsFinished(ths.Owner, routeSuccess);
                }

                if (((SeasonsManager.Enabled && routeSuccess) && (isOutside && (owner != null))) && ((owner.IsHuman && owner.SimDescription.ChildOrAbove) && (!owner.IsOutside && (owner.CurrentOutfitCategory == OutfitCategories.Outerwear))))
                {
                    owner.SwitchToOutfitWithSpin(Sim.ClothesChangeReason.RemovingOuterwear);
                }

                if (owner != null)
                {
                    SwimmingInPool posture = owner.Posture as SwimmingInPool;
                    if ((posture != null) && posture.UsedShortEntryAnimation)
                    {
                        posture.UsedShortEntryAnimation = false;
                        if (owner.SimDescription.IsMatureMermaid)
                        {
                            OccultMermaid.PutOnTailWithSpin(owner.SimDescription);
                        }
                    }
                }
            }
            catch (ResetException)
            {
                routeSuccess = false;
                if (ths.mRouteActions.Count > 0x0)
                {
                    RouteAction action = ths.mRouteActions[0x0];
                    if (action != null)
                    {
                        action.OnReset();
                    }
                }
                ths.mRouteActions.Clear();
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(owner, null, msg.ToString(), e);
                routeSuccess = false;

                if (ths.mRouteActions.Count > 0x0)
                {
                    RouteAction action = ths.mRouteActions[0x0];
                    if (action != null)
                    {
                        action.OnReset();
                    }
                }
                ths.mRouteActions.Clear();
            }
            finally
            {
                ths.mRouteActions.Clear();
                if (owner != null)
                {
                    owner.RestoreUsedHoverboard();
                }

                if ((owner != null) && (owner.FirstName == "Roberto"))
                {
                    Common.DebugStackLog(msg);
                }
            }

            return(routeSuccess);
        }
Beispiel #11
0
        public override bool Run()
        {
            try
            {
                Vector3 vector4;
                if (Actor.LotCurrent.IsHouseboatLot())
                {
                    mIsHouseboat = true;
                }
                mSittingInBoatPosture = Actor.Posture as SittingInBoat;

                Vector3 mPoint       = Hit.mPoint;
                Vector3 newTargetPos = mPoint;
                if (mSittingInBoatPosture == null)
                {
                    if (!mIsHouseboat)
                    {
                        if (IsNearHiddenIsland(mPoint))
                        {
                            Vector3 invalid = Vector3.Invalid;
                            World.GetNearestSwimmingPoint(Actor.Position, ref invalid, ref mPoint);
                        }

                        if (!RouteToFishingLocation(mPoint, Actor, Hit.mType, Hit.mId))
                        {
                            Actor.PlayRouteFailure(new ThumbnailKey(ResourceKey.CreatePNGKey("w_fishing_skill", ResourceUtils.ProductVersionToGroupId(ProductVersion.BaseGame)), ThumbnailSize.Medium));
                            return(false);
                        }
                    }
                    else if (!RouteToFishingLocationOnHouseboat(Actor, ref mPoint, Actor, Hit.mType, Hit.mId, ref newTargetPos))
                    {
                        return(false);
                    }
                }
                else
                {
                    Boat container = mSittingInBoatPosture.Container as Boat;
                    if (container != null)
                    {
                        mPoint = container.GetFishingPosition(mSittingInBoatPosture);
                        if (World.GetTerrainType(mPoint.x, mPoint.z, container.Level) != 2)
                        {
                            return(false);
                        }

                        RoutingComponent routingComponent = container.RoutingComponent;
                        if ((routingComponent == null) || routingComponent.IsRouting)
                        {
                            return(false);
                        }
                    }
                }

                if (mIsHouseboat && World.GetHouseboatDisplayToWorldPosition(Actor.LotCurrent.LotId, newTargetPos, out vector4))
                {
                    PrepFishing(mPoint, vector4);
                }
                else
                {
                    PrepFishing(mPoint, mPoint);
                }

                WaterTypes waterType = FishingSpot.GetWaterType(Hit.mType);
                Fishing    fishing   = Actor.SkillManager.AddElement(SkillNames.Fishing) as Fishing;
                fishing.TypesOfWaterFishedIn = waterType | fishing.TypesOfWaterFishedIn;
                if (!BaitSelected)
                {
                    BaitInfoSelected = fishing.mBaitInfo;
                }
                if (BaitInfoSelected != null)
                {
                    BaitInUse = FindProperBait(BaitInfoSelected);
                    Actor.InteractionQueue.FireQueueChanged();
                }
                else if (fishing.SkillLevel > kNoBaitUsedLesson)
                {
                    Tutorialette.TriggerLesson(Lessons.FishingSkill, Actor);
                }

                BeginCommodityUpdates();

                bool succeeded = false;

                MotiveDelta delta = null;

                try
                {
                    StartStages();
                    if (Actor.TraitManager.HasElement(TraitNames.Angler))
                    {
                        mIsAngler = true;
                        delta     = AddMotiveDelta(CommodityKind.Fun, kAnglerFunPerHour);
                    }

                    mLoopLengthForNextFish = mFishingData.GetNextFishTimeLength(mIsAngler, fishing.IsFisherman());
                    mShowTns = mFishingData.ShouldShowFishingTns(Actor, BaitInUse);
                    mCurrentStateMachine.SetParameter("skillLevel", fishing.GetSkillLevelParameterForJazzGraph());
                    if (BaitInUse != null)
                    {
                        fishing.mBaitInfo = new Fishing.BaitInfo(BaitInUse);
                    }
                    else
                    {
                        fishing.mBaitInfo = null;
                    }

                    AnimateSim("Fish");
                    Actor.RegisterGroupTalk();

                    succeeded = DoLoop(~(ExitReason.Replan | ExitReason.MidRoutePushRequested | ExitReason.ObjectStateChanged | ExitReason.PlayIdle | ExitReason.MaxSkillPointsReached), new Interaction <Sim, Terrain> .InsideLoopFunction(LoopFunc), mCurrentStateMachine);

                    Actor.UnregisterGroupTalk();
                    if (BaitInUse != null)
                    {
                        Actor.Inventory.SetNotInUse(BaitInUse);
                    }

                    if (mSittingInBoatPosture == null)
                    {
                        AnimateSim("Exit");
                    }
                    else
                    {
                        AnimateSim("ExitFishing");
                        mSittingInBoatPosture.CurrentStateMachine.RequestState("x", "SimIdle");
                    }
                }
                finally
                {
                    StandardExit(false, false);
                    if (mIsAngler)
                    {
                        RemoveMotiveDelta(delta);
                    }

                    EndCommodityUpdates(succeeded);
                }
                return(succeeded);
            }
            catch (ResetException)
            {
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(Actor, Target, e);
                return(false);
            }
        }
Beispiel #12
0
 public static void WriteRoutingComponent(this Packet packet, RoutingComponent component)
 {
     packet.WriteGuid(component.Guid);
     packet.WriteComponentType(component.Type);
     packet.WriteList(component.OwnedObjects, WriteRoutingComponent);
 }
Beispiel #13
0
    private void ApplyData()
    {
        RoutingComponent routing = base.GetComponent <RoutingComponent>();

        routing.CurrentRoutingOptions = new RoutingComponent.RoutingOptions(this.kEnemyData.kSpeed, RoutingComponent.RouteOrientation.Left, this.kEnemyData.kRouteStyle);
    }
Beispiel #14
0
        public static bool DoRoute(RoutingComponent ths, Route r)
        {
            Sim owner = ths.Owner as Sim;
            if ((!r.ExecutionFromNonSimTaskIsSafe && (owner != null)) && (Simulator.CurrentTask != ths.Owner.ObjectId))
            {
                Simulator.CurrentTask.ObjectFromId<GameObject>();
                return false;
            }

            IBoat boat = ths.Owner as IBoat;
            if (ths.RoutingParent != null)
            {
                if (!(ths.RoutingParent is IBoat) || (r.GetOption2(Route.RouteOption2.EndAsBoat) && (!r.PlanResult.Succeeded() || !RoutingComponent.PlannedRouteHasNonBoatSubpath(r))))
                {
                    // Custom
                    if (ths.RoutingParent.RoutingComponent is CarRoutingComponent)
                    {
                        return CarRoutingComponentEx.DoRoute(ths.RoutingParent.RoutingComponent as CarRoutingComponent, r);
                    }
                    else
                    {
                        return ths.RoutingParent.RoutingComponent.DoRoute(r);
                    }
                }
            }
            else if (((boat != null) && r.PlanResult.Succeeded()) && (!r.GetOption2(Route.RouteOption2.EndAsBoat) || RoutingComponent.PlannedRouteHasNonBoatSubpath(r)))
            {
                Sim driver = boat.GetDriver();
                if (driver != null)
                {
                    return driver.RoutingComponent.DoRoute(r);
                }
            }

            Common.StringBuilder msg = new Common.StringBuilder("RoutingComponentEx:DoRoute" + Common.NewLine);
            if (owner != null)
            {
                msg += Common.NewLine + owner.FullName + Common.NewLine;
            }

            ths.mRouteActions.Clear();
            bool routeSuccess = true;
            try
            {
                RouteAction.FailureExplanation explanation = RouteAction.FailureExplanation.None;
                RoutingComponent.mnNumDoRouteCalls += (ulong)0x1L;
                if (r.PlanResult.Succeeded())
                {
                    ths.OnAboutToStartFollowingRoute(r);
                    if (r.PlanResult.Succeeded())
                    {
                        ths.PushActionsForRoute(r, r);
                        if (owner != null)
                        {
                            owner.PushBackpackPostureIfNecessary();
                            owner.PushCanePostureIfNecessary();
                            owner.PushJetpackPostureIfNecessary();
                        }
                    }
                    else
                    {
                        routeSuccess = false;
                    }
                }
                else
                {
                    routeSuccess = false;
                }

                msg.Append("A");

                if (!routeSuccess)
                {
                    explanation |= RouteAction.FailureExplanation.InitialPlanFailure;
                    LogFailure(ths.Owner, RouteAction.FailureExplanation.InitialPlanFailure, r.PlanResult, "Initial Path Plan Failure (WILL NOT play route fail)");
                    r.SetRouteActionResult(0x2);
                    return false;
                }

                msg.Append("B");

                int failures = 0;

                if ((ths.RoutingParent != null) && (ths.RoutingParent is IBoat))
                {
                    ths.UpdateDynamicFootprint(ths.RoutingParent as GameObject, false);
                }
                else
                {
                    ths.UpdateDynamicFootprint(ths.Owner, false);
                }

                Vector3 originalPosition = ths.Owner.Position;
                int loops = 0;

                bool success = true;
                Route processedPath = r;
                bool isOutside = ths.Owner.IsOutside;
                ths.mNumWaterEntriesThisRoute = 0;
                while (ths.mRouteActions.Count != 0x0)
                {
                    // Custom
                    if (ths.Owner.Position == originalPosition)
                    {
                        loops++;
                    }

                    if ((loops > 30) || (ths.mRouteActions.Count > 30))
                    {
                        success = false;
                        ths.mRouteActions.Clear();
                        break;
                    }

                    if (ths.mRouteActions[0] is GetInBoatRouteAction)
                    {
                        ths.mNumWaterEntriesThisRoute++;
                        if (ths.mNumWaterEntriesThisRoute > 10)
                        {
                            if (owner != null)
                            {
                                owner.SetToResetAndSendHome();
                            }
                            else
                            {
                                ths.Owner.SetObjectToReset();
                            }
                            return false;
                        }
                    }

                    if ((owner != null) && owner.IsOutside)
                    {
                        owner.PushHoverboardPostureIfNecessary();
                    }

                    // Custom
                    RouteAction routeAction = ths.mRouteActions[0x0];

                    msg.Append(Common.NewLine + routeAction.GetType());

                    RouteAction.ActionResult actionResult = RouteAction.ActionResult.Continue;

                    //using (BuffsChangedProxy buffsProxy = new BuffsChangedProxy(owner))
                    {
                        try
                        {
                            if (routeAction is ObstacleEncounteredRouteInterruptAction)
                            {
                                actionResult = ObstacleEncounteredRouteInterruptActionEx.PerformAction(routeAction as ObstacleEncounteredRouteInterruptAction);
                            }
                            else
                            {
                                actionResult = routeAction.PerformAction();
                            }
                        }
                        catch (ResetException)
                        {
                            throw;
                        }
                        catch (SacsErrorException e)
                        {
                            Common.DebugException(owner, null, msg, e);

                            failures++;

                            if (failures > 10)
                            {
                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else
                            {
                                actionResult = RouteAction.ActionResult.ContinueAndPopPathAndReplan;
                            }

                            routeAction.OnReset();
                        }
                        catch (Exception e)
                        {
                            Common.Exception(owner, null, msg.ToString(), e);

                            string stackTrace = e.StackTrace.ToString();

                            if (stackTrace.Contains("OccultManager:DisallowClothesChange"))
                            {
                                OccultTypeHelper.ValidateOccult(owner.SimDescription, null);

                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else if (stackTrace.Contains("CommonDoor:IsAllowedThrough"))
                            {
                                Corrections.CleanupCommonDoors(null);
                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else if (stackTrace.Contains("SimRoutingComponent:RequestWalkStyle"))
                            {
                                actionResult = RouteAction.ActionResult.Terminate;
                            }
                            else
                            {
                                failures++;

                                if (failures > 10)
                                {
                                    actionResult = RouteAction.ActionResult.Terminate;
                                }
                                else
                                {
                                    actionResult = RouteAction.ActionResult.ContinueAndPopPathAndReplan;
                                }
                            }

                            routeAction.OnReset();
                        }
                    }

                    msg.Append(Common.NewLine + "C");

                    // Custom
                    if ((ths.mRouteActions.Count > 0) && (ths.mRouteActions[0x0].ForciblyReplanned) && (actionResult == RouteAction.ActionResult.ContinueAndPopPath))
                    {
                        actionResult = RouteAction.ActionResult.ContinueAndFollowPath;
                    }

                    msg.Append(Common.NewLine + actionResult + Common.NewLine);

                    if (GoHere.Settings.mDetailedRouting)
                    {
                        if (Sim.ActiveActor == owner)
                        {
                            Common.DebugNotify(msg);
                        }
                    }

                    if (ths.mRouteActions.Count == 0x0)
                    {
                        explanation |= RouteAction.FailureExplanation.InternalPlanFailure;
                        success = false;
                        break;
                    }

                    msg.Append("D");

                    ths.mPreviousRouteAction = ths.mRouteActions[0x0];
                    switch(actionResult)
                    {
                        case RouteAction.ActionResult.Continue:
                        case RouteAction.ActionResult.ContinueAndPopPath:
                        case RouteAction.ActionResult.ContinueAndPopPathAndReplan:
                        case RouteAction.ActionResult.ContinueAndPopPathAndRestart:
                        case RouteAction.ActionResult.ContinueAndFollowPath:
                            msg.Append("E");

                            ths.mRouteActions.RemoveAt(0x0);
                            bool flag3 = (processedPath.GetNumPaths() > 0x1) || (processedPath.IsLoop());
                            if (((actionResult == RouteAction.ActionResult.ContinueAndPopPath) && flag3) || ((actionResult == RouteAction.ActionResult.ContinueAndPopPathAndRestart) || (actionResult == RouteAction.ActionResult.ContinueAndPopPathAndReplan)))
                            {
                                if (flag3)
                                {
                                    processedPath.PopPath();
                                }

                                msg.Append("F");

                                if (actionResult == RouteAction.ActionResult.ContinueAndPopPathAndReplan)
                                {
                                    Vector3 outPosition = new Vector3();
                                    if ((ths.RoutingParent != null) && (ths.RoutingParent is IBoat))
                                    {
                                        outPosition = ths.RoutingParent.PositionOnFloor;
                                    }
                                    else if (ths.Owner != null)
                                    {
                                        if ((owner != null) && (owner.Posture is SwimmingInPool))
                                        {
                                            outPosition = ths.Owner.Position;
                                        }
                                        else
                                        {
                                            outPosition = ths.Owner.PositionOnFloor;
                                        }
                                    }
                                    else
                                    {
                                        processedPath.GetPathStartPoint(0x0, ref outPosition);
                                    }
                                    processedPath.ReplanFromPoint(outPosition);
                                }

                                msg.Append("G");

                                if (actionResult == RouteAction.ActionResult.ContinueAndPopPathAndRestart)
                                {
                                    Vector3 positionOnFloor = new Vector3();
                                    if (ths.Owner != null)
                                    {
                                        positionOnFloor = ths.Owner.PositionOnFloor;
                                    }
                                    else
                                    {
                                        processedPath.GetPathStartPoint(0x0, ref positionOnFloor);
                                    }
                                    processedPath.SetOption(Route.RouteOption.EnablePlanningAsCar, false);
                                    processedPath.SetOption(Route.RouteOption.EnableSubwayPlanning, false);
                                    processedPath.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, false);
                                    processedPath.ReplanFromPoint(positionOnFloor);
                                    explanation |= RouteAction.FailureExplanation.CancelledByScript;
                                    success = false;
                                    ths.mRouteActions.Clear();
                                }
                                else if (processedPath.PlanResult.Succeeded())
                                {
                                    ths.PushActionsForRoute(r, processedPath);
                                }
                                else
                                {
                                    explanation |= RouteAction.FailureExplanation.ReplanFailure;
                                    success = false;
                                    ths.mRouteActions.Clear();
                                }
                            }
                            else if ((actionResult == RouteAction.ActionResult.ContinueAndFollowPath) && (r.GetNumPaths() > 0x0))
                            {
                                msg.Append("H");

                                if (r.PlanResult.Succeeded())
                                {
                                    ths.PushActionsForRoute(r, processedPath);
                                }
                                else
                                {
                                    explanation |= RouteAction.FailureExplanation.InternalPlanFailure;
                                    success = false;
                                    ths.mRouteActions.Clear();
                                }
                            }
                            break;
                        default:
                            msg.Append("I");

                            explanation |= ths.mPreviousRouteAction.FailureExplanations;
                            success = false;
                            ths.mRouteActions.Clear();
                            break;
                    }
                }

                msg.Append("J");

                ths.mRouteActions.Clear();
                r.SetRouteActionResult((uint)explanation);
                if (!success)
                {
                    if (ths.mPreviousRouteAction == null)
                    {
                        LogFailure(ths.Owner, explanation, r.PlanResult, "(Null mPreviousRouteAction failure)");
                    }
                    else
                    {
                        LogFailure(ths.Owner, explanation, r.PlanResult, "(failure in " + ths.mPreviousRouteAction.ToString() + ")");
                    }
                }

                msg.Append("K");

                if ((ths.RoutingParent != null) && (ths.RoutingParent is IBoat))
                {
                    ths.UpdateDynamicFootprint(ths.RoutingParent as GameObject, true);
                }
                else
                {
                    ths.UpdateDynamicFootprint(ths.Owner, true);
                }

                routeSuccess = (success && (processedPath == r)) && r.PlanResult.Succeeded();
                ths.mPreviousRouteAction = null;
                if (ths.OnRouteActionsFinished != null)
                {
                    ths.OnRouteActionsFinished(ths.Owner, routeSuccess);
                }

                if (((SeasonsManager.Enabled && routeSuccess) && (isOutside && (owner != null))) && ((owner.IsHuman && owner.SimDescription.ChildOrAbove) && (!owner.IsOutside && (owner.CurrentOutfitCategory == OutfitCategories.Outerwear))))
                {
                    owner.SwitchToOutfitWithSpin(Sim.ClothesChangeReason.RemovingOuterwear);
                }

                if (owner != null)
                {
                    SwimmingInPool posture = owner.Posture as SwimmingInPool;
                    if ((posture != null) && posture.UsedShortEntryAnimation)
                    {
                        posture.UsedShortEntryAnimation = false;
                        if (owner.SimDescription.IsMatureMermaid)
                        {
                            OccultMermaid.PutOnTailWithSpin(owner.SimDescription);
                        }
                    }
                }
            }
            catch (ResetException)
            {
                routeSuccess = false;
                if (ths.mRouteActions.Count > 0x0)
                {
                    RouteAction action = ths.mRouteActions[0x0];
                    if (action != null)
                    {
                        action.OnReset();
                    }
                }
                ths.mRouteActions.Clear();
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(owner, null, msg.ToString(), e);
                routeSuccess = false;

                if (ths.mRouteActions.Count > 0x0)
                {
                    RouteAction action = ths.mRouteActions[0x0];
                    if (action != null)
                    {
                        action.OnReset();
                    }
                }
                ths.mRouteActions.Clear();
            }
            finally
            {
                ths.mRouteActions.Clear();
                if (owner != null)
                {
                    owner.RestoreUsedHoverboard();
                }

                if ((owner != null) && (owner.FirstName == "Roberto"))
                {
                    Common.DebugStackLog(msg);
                }
            }

            return routeSuccess;
        }