Exemple #1
0
        //Performe the random interaction


        private static void PerformeInteractionOnSelf(Sim sim, InteractionDefinition definition)
        {
            InteractionPriority priority = sim.CurrentInteraction.GetPriority();

            InteractionInstance instance3 = definition.CreateInstance(sim, sim, priority, false, true);

            sim.InteractionQueue.Add(instance3);

            if (AddMenuItem.ReturnShowNotification())
            {
                StyledNotification.Show(new StyledNotification.Format(sim.Name + "\r" + instance3.GetInteractionName(), StyledNotification.NotificationStyle.kGameMessagePositive));
            }
        }
Exemple #2
0
        public static void DoInteractionToOthers(Sim sim)
        {
            try
            {
                Random r = new Random();

                //Get Sims on lot
                List <Sim> sims = ReturnSimsOnLot(sim);

                if (sims.Count > 0)
                {
                    int  tries    = 0;
                    int  maxTries = 20;
                    bool success  = false;
                    while (!success)
                    {
                        //Get random sim
                        int randomSim = r.Next(sims.Count);
                        Sim targetSim = sims[randomSim];

                        //Increment tries
                        tries++;

                        if (sim != null && sim.SocialComponent != null && targetSim != null)
                        {
                            List <InteractionObjectPair> pairs = new List <InteractionObjectPair>();
                            foreach (var item in sim.SocialComponent.GetAllInteractionsForAutonomy(targetSim))
                            {
                                if (item.CheckIfInteractionValid())
                                {
                                    pairs.Add(item);
                                }
                            }

                            InteractionPriority priority = new InteractionPriority(InteractionPriorityLevel.UserDirected);
                            if (sim.CurrentInteraction != null)
                            {
                                priority = sim.CurrentInteraction.GetPriority();
                            }

                            //IF the sim is not in the active household, raise the priority
                            if (sim.Household != null && !sim.Household.IsActive)
                            {
                                priority = new InteractionPriority(InteractionPriorityLevel.UserDirected);
                            }

                            InteractionInstance instance = pairs[r.Next(pairs.Count)].InteractionDefinition.CreateInstance(targetSim, sim, priority, false, true);
                            if (instance != null)
                            {
                                try
                                {
                                    success = sim.InteractionQueue.Add(instance);

                                    if (success && AddMenuItem.ReturnShowNotification())
                                    {
                                        StyledNotification.Show(new StyledNotification.Format(sim.Name + "\r" + instance.GetInteractionName() + "\r" + targetSim.Name, StyledNotification.NotificationStyle.kGameMessagePositive));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    StyledNotification.Show(new StyledNotification.Format(sim.Name + "\r" + ex.ToString(), StyledNotification.NotificationStyle.kGameMessagePositive));
                                }
                            }
                        }

                        //Break off if the interaction is not sticking
                        if (tries == maxTries && !success)
                        {
                            success = true;
                            DoInteractionToSelf(sim);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                sim.ShowTNSIfSelectable(ex.ToString(), StyledNotification.NotificationStyle.kGameMessagePositive, ObjectGuid.InvalidObjectGuid, sim.ObjectId);
            }
        }