public static bool PreTimeTravel1(InteractionInstance ths) { if (!UIUtils.IsOkayToStartModalDialog()) { return(false); } Sim actor = ths.InstanceActor as Sim; TravelUtil.PlayerMadeTravelRequest = true; OpportunityNames guid = CheckOpportunities(actor); string prompt; if (GameUtils.IsFutureWorld()) { prompt = TimePortal.LocalizeString("ConfirmReturn", new object[0x0]); } else if (guid != OpportunityNames.Undefined) { prompt = TimePortal.LocalizeString("ConfirmWarningTravel", new object[0x0]); } else { prompt = TimePortal.LocalizeString("ConfirmTravel", new object[0x0]); } if (!TwoButtonDialog.Show(prompt, Localization.LocalizeString("Ui/Caption/Global:Accept", new object[0x0]), Localization.LocalizeString("Ui/Caption/Global:Cancel", new object[0x0]))) { TravelUtil.PlayerMadeTravelRequest = false; return(false); } //Sims3.Gameplay.Gameflow.Singleton.DisableSave(this, "Ui/Caption/HUD/DisasterSaveError:Traveling"); ths.CancellableByPlayer = false; if ((guid != OpportunityNames.Undefined) && (actor.OpportunityManager != null)) { actor.OpportunityManager.CancelOpportunity(guid); } if (actor.OpportunityManager != null) { if (actor.OpportunityManager.HasOpportunity(OpportunityNames.EP11_HelpingTheTimeTraveler01)) { actor.OpportunityManager.CancelOpportunity(OpportunityNames.EP11_HelpingTheTimeTraveler01); } if (actor.OpportunityManager.HasOpportunity(OpportunityNames.EP11_HelpingTheTimeTraveler02)) { actor.OpportunityManager.CancelOpportunity(OpportunityNames.EP11_HelpingTheTimeTraveler02); } if (GameUtils.IsFutureWorld() && actor.OpportunityManager.HasOpportunity(OpportunityNames.EP11_RecalibrateDefenseGrid)) { actor.OpportunityManager.CancelOpportunity(OpportunityNames.EP11_RecalibrateDefenseGrid); } } return(true); }
public override void OnCompletion(out OpportunityNames triggerOpportunity) { bool opportunityWin = RewardsManager.CheckForWin(mSharedData.mCompletionWinChance, mSharedData.mModifierList, Actor); ArrayList rewardsList = opportunityWin ? mSharedData.mWinRewardsList : mSharedData.mLossRewardsList; RewardInfoEx.GiveRewards(Actor, TargetObject, rewardsList); base.OnCompletion(out triggerOpportunity); }
public static bool Perform(SimDescription me, OpportunityNames guid) { Opportunity opportunity = null; GenericManager <OpportunityNames, Opportunity, Opportunity> .sDictionary.TryGetValue((ulong)guid, out opportunity); Repeatability origRepeatability = Repeatability.Undefined; if (opportunity != null) { origRepeatability = opportunity.RepeatLevel; opportunity.mSharedData.mRepeatLevel = Repeatability.Always; } try { me.Household.mCompletedHouseholdOpportunities.Remove((ulong)guid); if (opportunity.IsLocationBased) { List <Lot> alreadyChosenLots = new List <Lot>(); foreach (ulong lotId in OpportunityManager.sLocationBasedOpportunities.Values) { Lot lot = LotManager.GetLot(lotId); if (lot == null) { continue; } alreadyChosenLots.Add(lot); } Lot lotTarget = OpportunityManager.GetLotTarget(opportunity, alreadyChosenLots); if (lotTarget != null) { lotTarget.AddLocationBasedOpportunity(opportunity.EventDay, opportunity.EventStartTime, opportunity.EventEndTime, opportunity.Guid); alreadyChosenLots.Add(lotTarget); } } return(me.CreatedSim.OpportunityManager.AddOpportunityNow(guid, true, false)); } finally { if (opportunity != null) { opportunity.mSharedData.mRepeatLevel = origRepeatability; } } }
private static bool CheckAllRequirements(Sim s, Opportunity op, OpportunityNames lastOpName, ref string msg) { Opportunity.OpportunitySharedData sharedData = op.SharedData; WorldName mTargetWorldRequired = sharedData.mTargetWorldRequired; WorldName currentWorld = GameUtils.GetCurrentWorld(); if (mTargetWorldRequired == WorldName.SunsetValley) { mTargetWorldRequired = s.SimDescription.HomeWorld; } if ((mTargetWorldRequired == currentWorld) || (mTargetWorldRequired == WorldName.Undefined)) { foreach (Opportunity.OpportunitySharedData.RequirementInfo info in sharedData.mRequirementList) { if (info.mType == RequirementType.OpportunityComplete) { OpportunityNames mGuid = (OpportunityNames)info.mGuid; if (lastOpName == mGuid) { continue; } } if (!op.CheckRequirement(info, s, sharedData)) { msg += Common.NewLine + " Failure: " + info.mType; return(false); } } } OpportunityNames mCompletionTriggerOpportunity = sharedData.mCompletionTriggerOpportunity; if (mCompletionTriggerOpportunity != OpportunityNames.Undefined) { Opportunity staticOpportunity = OpportunityManager.GetStaticOpportunity(mCompletionTriggerOpportunity); if ((staticOpportunity != null) && !op.CheckAllRequirements(s, staticOpportunity, sharedData.mGuid)) { msg += Common.NewLine + " Failure: B"; return(false); } } return(true); }
private static bool CheckAllRequirements(Sim s, Opportunity op, OpportunityNames lastOpName, ref string msg) { Opportunity.OpportunitySharedData sharedData = op.SharedData; WorldName mTargetWorldRequired = sharedData.mTargetWorldRequired; WorldName currentWorld = GameUtils.GetCurrentWorld(); if (mTargetWorldRequired == WorldName.SunsetValley) { mTargetWorldRequired = s.SimDescription.HomeWorld; } if ((mTargetWorldRequired == currentWorld) || (mTargetWorldRequired == WorldName.Undefined)) { foreach (Opportunity.OpportunitySharedData.RequirementInfo info in sharedData.mRequirementList) { if (info.mType == RequirementType.OpportunityComplete) { OpportunityNames mGuid = (OpportunityNames)info.mGuid; if (lastOpName == mGuid) { continue; } } if (!op.CheckRequirement(info, s, sharedData)) { msg += Common.NewLine + " Failure: " + info.mType; return false; } } } OpportunityNames mCompletionTriggerOpportunity = sharedData.mCompletionTriggerOpportunity; if (mCompletionTriggerOpportunity != OpportunityNames.Undefined) { Opportunity staticOpportunity = OpportunityManager.GetStaticOpportunity(mCompletionTriggerOpportunity); if ((staticOpportunity != null) && !op.CheckAllRequirements(s, staticOpportunity, sharedData.mGuid)) { msg += Common.NewLine + " Failure: B"; return false; } } return true; }
private static ArrayList ParseRequirements(XmlDbRow dr, OpportunityNames opportunityKey) { ArrayList list = new ArrayList(); for (int i = 1; i <= 8; i++) { List<string> entry = dr.GetStringList("Requirement" + i, ',', false); if (entry.Count > 0) { RequirementType type; ParserFunctions.TryParseEnum<RequirementType>(entry[0], out type, RequirementType.Undefined); Opportunity.OpportunitySharedData.RequirementInfo info = null; if (type == RequirementType.Undefined) { info = new Opportunity.OpportunitySharedData.RequirementInfo(); info.mData = dr.GetString("Requirement" + i); info.mType = RequirementType.Undefined; } else { switch (type) { case RequirementType.Career: info = ParseCareerRequirements(entry); break; case RequirementType.Skill: info = ParseSkillRequirements(entry); break; case RequirementType.Trait: info = OpportunityManager.ParseTraitRequirements(entry); break; case RequirementType.WorldHasRabbitHoleType: info = OpportunityManager.ParseWorldHasRabbitHoleRequirement(entry); break; case RequirementType.LearnableRecipeExists: case RequirementType.HasAcquaintanceOrHigher: case RequirementType.HasYAAcquaintanceOrHigher: case RequirementType.HasNonFriendCoworker: case RequirementType.WorldHasPregnantSim: case RequirementType.HasChildOrTeenAcquaintanceOrHigher: case RequirementType.IsElder: case RequirementType.WorldHasCommunityLot: case RequirementType.HasHighRelationshipWithDeadSim: case RequirementType.Unemployed: case RequirementType.HasSingleSim: info = new Opportunity.OpportunitySharedData.RequirementInfo(); info.mType = type; break; case RequirementType.HasObjectOnHomeLot: case RequirementType.WorldHasLotWith: info = OpportunityManager.ParseObjectRequirement(entry); info.mType = type; break; case RequirementType.KnowsRecipe: info = OpportunityManager.ParseKnowsRecipeRequirement(entry); break; case RequirementType.HasStrangers: info = OpportunityManager.ParseHasStrangersRequirement(entry); break; case RequirementType.HasNonHouseholdAdultSims: info = OpportunityManager.ParseHasNonHouseholdAdultSimsRequirement(entry); break; case RequirementType.WorldHasInvitableSimInCareer: case RequirementType.WorldHasSimInCareer: case RequirementType.WorldHasSkillTutorableSimInCareer: info = OpportunityManager.ParseWorldHasSimInCareerRequirement(entry); info.mType = type; break; case RequirementType.HasInvitableCoworker: info = OpportunityManager.ParseHasInvitableCoworkerRequirement(entry); break; case RequirementType.HasGrade: info = OpportunityManager.ParseHasGradeRequirement(entry); break; case RequirementType.HasPlanted: info = OpportunityManager.ParseHasPlantedRequirement(entry); break; case RequirementType.HasWrittenXBooksOfGenre: info = OpportunityManager.ParseHasWrittenXBooksOfGenreRequirement(entry); break; case RequirementType.OpportunityNotComplete: info = ParseOpportunityNotCompleteRequirement(entry); break; case RequirementType.OpportunityComplete: info = ParseOpportunityCompleteRequirement(entry); break; case RequirementType.CanWriteGenre: info = OpportunityManager.ParseCanWriteGenreRequirement(entry); break; case RequirementType.WorldHasSpecificSim: info = OpportunityManager.ParseWorldHasSpecificSimRequirement(entry); break; case RequirementType.WorldHasCommunityLotType: info = OpportunityManager.ParseWorldHasCommunityLotTypeRequirement(entry, type); break; case RequirementType.NotInCareer: info = ParseNotInCareerRequirement(entry); break; case RequirementType.HasVacationLocal: info = OpportunityManager.ParseHasVacationLocalRequirement(entry); break; case RequirementType.WorldHasSimInRole: info = OpportunityManager.WorldHasSimInRoleRequirement(entry); break; case RequirementType.WorldHasSimOnSpecificLot: info = OpportunityManager.WorldHasSimOnSpecificLot(entry); break; case RequirementType.WorldHasEmptyTreasureSpawner: info = OpportunityManager.WorldHasEmptyTreasureSpawner(entry); break; case RequirementType.VisaLevel: info = OpportunityManager.ParseVisaLevelRequirements(entry, opportunityKey); break; case RequirementType.HasBuff: info = OpportunityManager.ParseBuffRequirements(entry); break; case RequirementType.KnowsInvention: info = OpportunityManager.ParseKnownInventionRequirement(entry); break; case RequirementType.KnowsSculpture: info = OpportunityManager.ParseKnownSculptureRequirement(entry); break; case RequirementType.Celebrity: info = OpportunityManager.ParseCelebrityRequirements(entry); break; case RequirementType.HasCompletedNGigs: info = OpportunityManager.ParseHasCompletedNGigsRequirements(entry); break; case RequirementType.HasPet: info = OpportunityManager.ParseHasPetRequirement(entry); break; } } if (info != null) { list.Add(info); } } } return list; }
public static bool Perform(SimDescription me, OpportunityNames guid) { Opportunity opportunity = null; GenericManager<OpportunityNames, Opportunity, Opportunity>.sDictionary.TryGetValue((ulong)guid, out opportunity); Repeatability origRepeatability = Repeatability.Undefined; if (opportunity != null) { origRepeatability = opportunity.RepeatLevel; opportunity.mSharedData.mRepeatLevel = Repeatability.Always; } try { me.Household.mCompletedHouseholdOpportunities.Remove((ulong)guid); if (opportunity.IsLocationBased) { List<Lot> alreadyChosenLots = new List<Lot>(); foreach (ulong lotId in OpportunityManager.sLocationBasedOpportunities.Values) { Lot lot = LotManager.GetLot(lotId); if (lot == null) continue; alreadyChosenLots.Add(lot); } Lot lotTarget = OpportunityManager.GetLotTarget(opportunity, alreadyChosenLots); if (lotTarget != null) { lotTarget.AddLocationBasedOpportunity(opportunity.EventDay, opportunity.EventStartTime, opportunity.EventEndTime, opportunity.Guid); alreadyChosenLots.Add(lotTarget); } } return me.CreatedSim.OpportunityManager.AddOpportunityNow(guid, true, false); } finally { if (opportunity != null) { opportunity.mSharedData.mRepeatLevel = origRepeatability; } } }
public override bool Run() { try { if (!Target.RouteToCone(Actor)) { return(false); } StandardEntry(); try { BeginCommodityUpdates(); if (((Target.mJobSelectionDay.Ticks == 0x0L) || (SimClock.CurrentDayOfWeek != Target.mJobSelectionDay.DayOfWeek)) || (SimClock.ElapsedTime(TimeUnit.Days, Target.mJobSelectionDay) >= 1f)) { Target.mAvailableJobs.Clear(); Target.mTakenJobs.Clear(); Target.mJobSelectionDay = SimClock.CurrentTime(); Target.StartTimer(); } if (GameUtils.IsUniversityWorld()) { EnterStateMachine("JobBoard", "Enter", "x"); SetActor("jobBoard", Target); AnimateSim("Exit"); } else { Actor.PlaySoloAnimation("a2o_postBoxJobBoard_checkBoard_x", true); } EndCommodityUpdates(true); Definition definition = InteractionDefinition as Definition; Tutorialette.TriggerLesson(Lessons.QuestTracker, Actor); if (Autonomous || !UIUtils.IsOkayToStartModalDialog()) { Actor.Wander(kMinWanderDistance, kMaxWanderDistance, false, RouteDistancePreference.NoPreference, false); } else { OpportunityNames choice = OpportunityNames.Undefined; if (Target.mTakenJobs.Count >= kOpportunitiesPerDay) { string msg = "JobBoardEmptyTNS"; if (GameUtils.IsUniversityWorld()) { msg = "JobBoardEmptyTNSEP9"; } Actor.ShowTNSIfSelectable(LocalizeString(Actor.IsFemale, msg, new object[0x0]), StyledNotification.NotificationStyle.kSimTalking); } else { if ((Target.mAvailableJobs.Count + Target.mTakenJobs.Count) < kOpportunitiesPerDay) { List <Opportunity> opportunities = OpportunityEx.GetAllOpportunities(Actor, definition.mOppName); List <float> weights = new List <float>(); foreach (Opportunity opp in opportunities) { float num = Actor.SimDescription.OpportunityHistory.HasRejectedOpportunity(opp.Guid) ? OpportunityHistory.kUserRejectedOpportunityWeightMultiplier : 1f; weights.Add(opp.ChanceToGetOnPhone * num); } Opportunity opportunity = null; while (opportunities.Count > 0) { int index = RandomUtil.GetWeightedIndex(weights.ToArray()); opportunity = opportunities[index]; weights.RemoveAt(index); opportunities.RemoveAt(index); if (!Target.mAvailableJobs.Contains(opportunity.Guid)) { Target.mAvailableJobs.Add(opportunity.Guid); Target.mIndexOfLastChosen = Target.mAvailableJobs.Count - 0x1; if (!OpportunityEx.Perform(Actor.SimDescription, opportunity.Guid)) { return(false); } choice = opportunity.Guid; break; } } if (choice == OpportunityNames.Undefined) { Actor.ShowTNSIfSelectable(LocalizeString(Actor.IsFemale, "NoValidOppsTNS", new object[] { Actor }), StyledNotification.NotificationStyle.kGameMessagePositive, Target.ObjectId, Actor.ObjectId); return(false); } } else { choice = OpportunityNames.Undefined; int count = Target.mAvailableJobs.Count; if (count > 0x0) { int num2 = (Target.mIndexOfLastChosen + 0x1) % count; for (int i = 0x0; i < Target.mAvailableJobs.Count; i++) { int num4 = (i + num2) % count; OpportunityNames names3 = Target.mAvailableJobs[num4]; if ((Actor.OpportunityManager.IsOpportunityAvailable(names3)) && (Actor.OpportunityManager.IsOpportunityCategory(names3, definition.mOppName))) { choice = names3; Target.mIndexOfLastChosen = num4; break; } } } if (choice != OpportunityNames.Undefined) { if (!OpportunityEx.Perform(Actor.SimDescription, choice)) { return(false); } } else { Actor.ShowTNSIfSelectable(LocalizeString(Actor.IsFemale, "NoValidOppsTNS", new object[] { Actor }), StyledNotification.NotificationStyle.kGameMessagePositive, Target.ObjectId, Actor.ObjectId); } } if (choice != OpportunityNames.Undefined) { Target.mIndexOfLastChosen = 0x0; Target.mAvailableJobs.Remove(choice); Target.mTakenJobs.Add(choice); if (Target.mTakenJobs.Count >= kOpportunitiesPerDay) { Target.StopHelperEffect(); } } } } } finally { StandardExit(); } return(true); } catch (ResetException) { throw; } catch (Exception e) { Common.Exception(Actor, Target, e); return(false); } }
protected static List <Opportunity> GetAllOpportunities(Sim sim, bool singleCategory, Dictionary <OpportunityNames, Opportunity> opportunityList) { //Common.StringBuilder msg = new Common.StringBuilder("GetAllOpportunities"); List <Opportunity> allOpportunities = new List <Opportunity>(); if (!GameStates.IsOnVacation) { CareerManager manager = sim.CareerManager; if (manager != null) { for (int i = 0; i < 2; i++) { Sims3.Gameplay.Careers.Career career = manager.Occupation as Sims3.Gameplay.Careers.Career; if (i == 1) { career = manager.School; } if (career == null) { continue; } foreach (Sims3.Gameplay.Careers.Career.EventDaily daily in career.CareerEventList) { Sims3.Gameplay.Careers.Career.EventOpportunity oppEvent = daily as Sims3.Gameplay.Careers.Career.EventOpportunity; if (oppEvent == null) { continue; } if (opportunityList.ContainsKey(oppEvent.mOpportunity)) { continue; } Opportunity opportunity = OpportunityManager.GetStaticOpportunity(oppEvent.mOpportunity); if (opportunity == null) { continue; } opportunityList.Add(opportunity.Guid, opportunity); } } } } foreach (Opportunity opportunity in opportunityList.Values) { //msg += Common.NewLine + "A: " + opportunity.Guid; Repeatability origRepeatability = opportunity.RepeatLevel; OpportunityNames origTriggerOpp = opportunity.SharedData.mCompletionTriggerOpportunity; WorldName targetWorldRequired = opportunity.SharedData.mTargetWorldRequired; try { if (!singleCategory) { opportunity.mSharedData.mRepeatLevel = Repeatability.Always; opportunity.mSharedData.mCompletionTriggerOpportunity = OpportunityNames.Undefined; } if (opportunity.TargetWorldRequired == WorldName.SunsetValley) { if ((singleCategory) && (Common.IsOnTrueVacation())) { if (sim.SimDescription.HomeWorld != GameUtils.GetCurrentWorld()) { continue; } } else { opportunity.SharedData.mTargetWorldRequired = WorldName.Undefined; } } else if (opportunity.TargetWorldRequired != WorldName.Undefined) { if (opportunity.TargetWorldRequired != GameUtils.GetCurrentWorld()) { continue; } } if (GameStates.IsOnVacation) { bool career = false; foreach (Opportunity.OpportunitySharedData.RequirementInfo info in opportunity.SharedData.mRequirementList) { if (info.mType == RequirementType.Career) { career = true; break; } } if (career) { continue; } } //if (IsAvailable(opportunity, sim, ref msg)) if (opportunity.IsAvailable(sim)) { allOpportunities.Add(opportunity); } } catch (Exception e) { Common.DebugException(opportunity.Guid + Common.NewLine + opportunity.Name, e); } finally { opportunity.mSharedData.mRepeatLevel = origRepeatability; opportunity.mSharedData.mCompletionTriggerOpportunity = origTriggerOpp; opportunity.SharedData.mTargetWorldRequired = targetWorldRequired; } } List <Opportunity> allPotentials = new List <Opportunity>(); foreach (Opportunity opportunity in allOpportunities) { string name = null; //msg += Common.NewLine + "B: " + opportunity.Guid; try { if (sim.OpportunityManager.HasOpportunity(opportunity.OpportunityCategory)) { continue; } Opportunity toAdd = opportunity.Clone(); toAdd.Actor = sim; // EA has coding to spawn the Time Traveler in SetupTargets(), don't do it in that case if ((toAdd.SharedData.mTargetType != OpportunityTargetTypes.Sim) || (toAdd.SharedData.mTargetData != "TimeTraveler")) { if (!sim.OpportunityManager.SetupTargets(toAdd)) { continue; } } toAdd.SetLocalizationIndex(); name = toAdd.Name; allPotentials.Add(toAdd); } catch (Exception e) { Common.DebugException(opportunity.Guid + Common.NewLine + name, e); } } //Common.DebugWriteLog(msg); return(allPotentials); }