private void onMissionStarted(Player player, MissionInstance mission) { if (mission.MissionType == MissionType.Adventure) { base.refresh(); } }
public MissionListItem(MissionInstance mission) { //this.missionInfo = missionInfo; this.mission = mission; this.isAnimatingLeft = true; this.isClickedInside = false; }
private void onMissionEnded(Player player, MissionInstance mission, bool success) { if (mission.MissionType == MissionType.Adventure) { base.refresh(); } }
public async Task LoadAsync() { await using var ctx = new UchuContext(); var missions = await ctx.Missions.Where( m => m.CharacterId == GameObject.Id ).ToArrayAsync(); MissionInstances = new List <MissionInstance>(); Player player = GameObject as Player; foreach (var mission in missions) { var instance = new MissionInstance(player, mission.MissionId); MissionInstances.Add(instance); await instance.LoadAsync(); } Listen(player.OnRespondToMission, async(MissionID, Reciever, RewardLOT) => { await RespondToMissionAsync(MissionID, Reciever, RewardLOT); }); }
public async Task CompleteMissionAsync(int missionId) { // // Get the mission the player is responding to. // var mission = MissionInstances.FirstOrDefault(m => m.MissionId == missionId); // // Check if the player is accepting a mission or responding to one. // if (mission == default) { var instance = new MissionInstance(GameObject as Player, missionId); MissionInstances.Add(instance); await instance.LoadAsync(); await instance.CompleteAsync(); return; } await mission.CompleteAsync(); }
/// <summary> /// Loads all player missions, combining the cd client and uchu database into mission instances /// </summary> private async Task LoadAsync() { if (GameObject is Player player) { await using var uchuContext = new UchuContext(); // On load, load all the missions from database and store them in memory var missions = await uchuContext.Missions.Where( m => m.CharacterId == GameObject.Id ).ToArrayAsync(); foreach (var mission in missions) { var instance = new MissionInstance(mission.MissionId, player); await instance.LoadAsync(uchuContext); lock (Missions) { Missions.Add(instance); } } this._loaded = true; Listen(player.OnRespondToMission, async(missionId, receiver, rewardLot) => { await RespondToMissionAsync(missionId, receiver, rewardLot); }); } }
protected override void onRefresh() { Player player = GameLogic.Binder.GameState.Player; base.m_contentMenu.refreshTitle(StringExtensions.ToUpperLoca(_.L(ConfigLoca.DHUD_BUTTON_MISSIONS, null, false)), string.Empty, string.Empty); bool flag = player.Missions.hasMissionOnCooldown(); this.m_sortedMissionInstanceList.Clear(); for (int i = 0; i < player.Missions.Instances.Count; i++) { this.m_sortedMissionInstanceList.Add(player.Missions.Instances[i]); } this.m_sortedMissionInstanceList.Sort(new Comparison <MissionInstance>(MissionInstance.CompareByCooldown)); for (int j = 0; j < this.m_missionCells.Count; j++) { MissionCell cell = this.m_missionCells[j]; if (j < this.m_sortedMissionInstanceList.Count) { MissionInstance mission = this.m_sortedMissionInstanceList[j]; bool flag2 = mission.getRemainingCooldownSeconds() > 0L; cell.gameObject.SetActive(!flag2); if (!flag2) { if (App.Binder.ConfigMeta.NOTIFY_NEW_MISSIONS_DURING_WELCOME_BACK) { CmdInspectMission.ExecuteStatic(player, mission); } cell.refresh(player, mission, (j < player.Missions.Instances.Count) || flag, null, null); if (!App.Binder.ConfigMeta.NOTIFY_NEW_MISSIONS_DURING_WELCOME_BACK) { CmdInspectMission.ExecuteStatic(player, mission); } } } else { cell.gameObject.SetActive(false); } } if (flag) { this.MasterCooldownRootTm.gameObject.SetActive(true); this.MasterCooldownText.text = MenuHelpers.SecondsToStringHoursMinutes(player.Missions.getMinRemainingCooldownSeconds()); this.MasterCooldownRootTm.SetAsLastSibling(); } else { this.MasterCooldownRootTm.gameObject.SetActive(false); } int amount = player.Missions.getNumCompletedMissionsRequiredForBigPrize(); int num4 = amount - Mathf.Max(amount - player.Missions.NumUnclaimedMissionCompletions, 0); this.MasterDescription.text = _.L(ConfigLoca.MISSIONS_BIG_PRIZE, new < > __AnonType9 <int>(amount), false); this.MasterProgressBar.setNormalizedValue(Mathf.Clamp01(((float)num4) / ((float)amount))); this.MasterProgressBarText.text = num4 + " / " + amount; }
/// <summary> /// Creates and loads a new mission securely into the mission inventory /// </summary> /// <param name="missionId">The missionId to create a mission for</param> /// <param name="gameObject">The game object to assign the mission to</param> /// <returns>The newly created mission instance</returns> public async Task <MissionInstance> AddMissionAsync(int missionId, GameObject gameObject) { var mission = new MissionInstance(missionId, (Player)GameObject); await mission.LoadAsync(); lock (Missions) { Missions.Add(mission); } return(mission); }
public static Sprite GetMissionRewardIcon(MissionInstance mission) { if (!string.IsNullOrEmpty(mission.RewardShopEntryId)) { return(PlayerView.Binder.SpriteResources.getSprite(ConfigUi.GetFloaterSpriteForShopEntry(mission.RewardShopEntryId))); } if (mission.RewardDiamonds > 0.0) { return(PlayerView.Binder.SpriteResources.getSprite(ConfigUi.RESOURCE_TYPE_SPRITES[ResourceType.Diamond])); } return(null); }
public static string GetMissionRewardTitle(MissionInstance mission) { if (!string.IsNullOrEmpty(mission.RewardShopEntryId)) { string shopEntryDropTitle = MenuTreasureChest.GetShopEntryDropTitle(ConfigShops.GetShopEntry(mission.RewardShopEntryId), null); return(string.IsNullOrEmpty(shopEntryDropTitle) ? "1" : shopEntryDropTitle.Replace("+", string.Empty)); } if (mission.RewardDiamonds > 0.0) { return(mission.RewardDiamonds.ToString()); } return(null); }
/// <summary> /// Takes a saved mission and updates its values, tasks and progress according to a mission instance /// </summary> /// <param name="savedMission">The saved mission to save the information to</param> /// <param name="mission">The mission information to save to the saved mission</param> private static void UpdateMissionFromMissionInstance(Mission savedMission, MissionInstance mission) { // Update an existing mission savedMission.State = (int)mission.State; savedMission.CompletionCount = mission.CompletionCount; savedMission.LastCompletion = mission.LastCompletion; foreach (var task in mission.Tasks) { var savedTask = savedMission.Tasks.FirstOrDefault(t => t.TaskId == task.TaskId); if (savedTask == default) { continue; } savedTask.Values = CreateMissionTaskValuesFromProgress(task.Progress); } }
void OnMissionStarted(MissionInstance _mission) { UIWindow window; if (UIWindowManager.Instance().CreateWindow("Mission Progress", out window)) { RectTransform content = Instantiate(UIManager.Instance().missionProgressWindowContentPrefab); window.SetContent(content); MissionProgress missionProgress = content.GetComponent <MissionProgress>(); window.OnWindowClosed += (UIWindow w) => { m_company.EndCurrentMission(); }; missionProgress.SetMissionInstance(_mission); } }
public async Task LoadAsync() { await using var ctx = new UchuContext(); var missions = await ctx.Missions.Where( m => m.CharacterId == GameObject.ObjectId ).ToArrayAsync(); MissionInstances = new List <MissionInstance>(); foreach (var mission in missions) { var instance = new MissionInstance(GameObject as Player, mission.MissionId); MissionInstances.Add(instance); await instance.LoadAsync(); } }
/// <summary> /// Creates a database mission from a mission instance /// </summary> /// <param name="character">The character to create the mission for</param> /// <param name="mission">The mission instance information to use for the mission</param> /// <returns>The mission with information from the mission instance</returns> private static Mission CreateMissionFromMissionInstance(Character character, MissionInstance mission) => new Mission { Character = character, MissionId = mission.MissionId, State = (int)mission.State, CompletionCount = mission.CompletionCount, LastCompletion = mission.LastCompletion, Tasks = mission.Tasks.Select(task => new MissionTask { TaskId = task.TaskId, Values = task.Progress .GroupBy(value => value) .Select(value => new MissionTaskValue { Value = value.Key, Count = value.Count() }).ToList() }).ToList() };
public void StartMission(Mission _mission, List <Monster> _monsters) { if (m_currentMission != null) { Debug.LogError("Can't start two missions at the same time."); return; } m_currentMission = new MissionInstance(); m_currentMission.Start(_mission, _monsters); if (OnMissionStarted != null) { OnMissionStarted(m_currentMission); } SetPause(true); Logger.Log("Started mission."); }
public void refresh(Player player, MissionInstance mission, bool doShowDivider, [Optional, DefaultParameterValue(null)] string titleOverride, [Optional, DefaultParameterValue(null)] string descriptionOverride) { double num; float v = mission.getMissionProgress(player, out num); num = (num <= mission.Requirement) ? num : mission.Requirement; ConfigMissions.Mission missionData = ConfigMissions.GetMissionData(mission.MissionId); long totalSeconds = mission.getRemainingCooldownSeconds(); bool flag = ((mission.MissionType == MissionType.PromotionEvent) && (v == 1.0)) && !mission.OnCooldown; bool flag2 = (mission.MissionType == MissionType.PromotionEvent) && mission.OnCooldown; Image image = (mission.MissionType != MissionType.PromotionEvent) ? this.RewardIconBig : this.RewardIconSmall; this.IconBgGolden.gameObject.SetActive(flag); this.ProgressBarFgGolden.gameObject.SetActive(flag); this.ProgressBarText.gameObject.SetActive(!flag); this.CooldownRoot.SetActive(flag2); this.Title.gameObject.SetActive(!flag2); this.Description.gameObject.SetActive(!flag2); this.ProgressBar.gameObject.SetActive(!flag2); this.RewardText.gameObject.SetActive(!(flag2 || flag)); this.RewardIconSmall.gameObject.SetActive(false); this.RewardIconBig.gameObject.SetActive(false); image.gameObject.SetActive(!(flag2 || flag)); this.Divider.SetActive(doShowDivider); if (mission.MissionType == MissionType.PromotionEvent) { this.CooldownSubtitle.text = _.L(ConfigLoca.PROMOTION_EVENT_MISSION_AVAILABLE_IN, null, false); } this.CooldownTime.text = MenuHelpers.SecondsToStringDaysHoursMinutes(totalSeconds, true); this.Icon.sprite = (mission.MissionType != MissionType.PromotionEvent) ? PlayerView.Binder.SpriteResources.getSprite(missionData.Icon) : PlayerView.Binder.SpriteResources.getSprite(ConfigMissions.PROMOTION_EVENT_MISSION_ICON); this.Icon.material = !flag2 ? null : PlayerView.Binder.DisabledUiMaterial; this.IconBg.material = !flag2 ? null : PlayerView.Binder.DisabledUiMaterial; this.Notifier.SetActive(!mission.Inspected); this.Title.text = StringExtensions.ToUpperLoca((titleOverride == null) ? _.L(missionData.Title, null, false) : titleOverride); this.Description.text = !flag?missionData.getFormattedMissionDescription(mission.Requirement, true, descriptionOverride) : _.L(ConfigLoca.MISSION_COMPLETED, null, false); this.ProgressBarText.text = num + " / " + mission.Requirement; this.ProgressBar.setNormalizedValue(v); image.sprite = ConfigMissions.GetMissionRewardIcon(mission); this.RewardText.text = ConfigMissions.GetMissionRewardTitle(mission); }
private void sendMissionEvent(string state, Player player, MissionInstance mission) { TrackingEvent e = new TrackingEvent("bounty_quest"); e.Payload.Add("quest_state", state); e.Payload.Add("quest_code", mission.MissionId); e.Payload.Add("quest_goal", mission.Requirement); if (mission.MissionType == MissionType.PromotionEvent) { foreach (KeyValuePair <string, PromotionEventInstance> pair in player.PromotionEvents.Instances) { string key = pair.Key; if (pair.Value.Missions.Instances.Contains(mission)) { e.Payload.Add("quest_event_id", key); break; } } } this.injectStandardPayload(player, e); Service.Binder.TrackingService.AddEvent(e); }
// TODO: Improve private async Task SearchForNewAchievementsAsync <T>(MissionTaskType type, Lot lot, Func <T, Task> progress = null) where T : MissionTaskBase { await using var cdClient = new CdClientContext(); // // Collect tasks which fits the requirements of this action. // var otherTasks = new List <MissionTasks>(); // ReSharper disable once LoopCanBeConvertedToQuery foreach (var missionTask in cdClient.MissionTasksTable) { if (MissionParser.GetTargets(missionTask).Contains(lot)) { otherTasks.Add(missionTask); } } foreach (var task in otherTasks) { var mission = await cdClient.MissionsTable.FirstOrDefaultAsync(m => m.Id == task.Id); if (mission == default) { continue; } // // Check if mission is an achievement and has a task of the correct type. // if (mission.OfferobjectID != -1 || mission.TargetobjectID != -1 || (mission.IsMission ?? true) || task.TaskType != (int)type) { continue; } // // Get the mission on the character. If present. // var characterMission = MissionInstances.FirstOrDefault(m => m.MissionId == mission.Id); // // Check if the player could passably start this achievement. // if (characterMission != default) { continue; } // // Check if player has the Prerequisites to start this achievement. // var hasPrerequisites = MissionParser.CheckPrerequiredMissions( mission.PrereqMissionID, GetCompletedMissions() ); if (!hasPrerequisites) { continue; } // // Player can start achievement. // // Get Mission Id of new achievement. if (mission.Id == default) { continue; } var missionId = mission.Id.Value; // // Setup new achievement. // var instance = new MissionInstance(GameObject as Player, missionId); MissionInstances.Add(instance); await instance.LoadAsync(); // TODO: Silent? await instance.StartAsync(); var activeTask = instance.Tasks.First(t => t.TaskId == task.Uid); if (progress != null) { Detach(async() => { await progress(activeTask as T); }); } } }
private void onMissionStarted(Player player, MissionInstance mission) { this.refreshMissionCount(player); }
private void onMissionEnded(Player player, MissionInstance mission, bool success) { this.refreshMissionCount(player); }
void OnMissionEnded(MissionInstance _mission) { UIWindowManager.Instance().DestroyWindow("Mission Progress"); }
/// <summary> /// Checks if the player can accept a mission based on whether it's repeatable, already started and if the /// requirements are met. /// </summary> /// <param name="mission"></param> /// <returns><c>true</c> if the player can accept this mission, <c>false</c> otherwise</returns> public bool CanAccept(MissionInstance mission) => (mission.CanRepeat || !HasMission(mission.MissionId)) && MissionParser.CheckPrerequiredMissions(mission.PrerequisiteMissions, AllMissions);
/// <summary> /// Adds a mission for unit testing. /// </summary> /// <param name="mission">The test mission to add.</param> public void AddTestMission(MissionInstance mission) { lock (Missions) { Missions.Add(mission); } }
private void onMissionEnded(Player player, MissionInstance mission, bool success) { this.sendMissionEvent("completed", player, mission); }
private void onMissionStarted(Player player, MissionInstance mission) { this.sendMissionEvent("started", player, mission); }
public async Task RespondToMissionAsync(int missionId, GameObject missionGiver, Lot rewardItem) { // // The player has clicked on the accept or complete button. // await using var ctx = new UchuContext(); await using var cdClient = new CdClientContext(); // // Get the mission the player is responding to. // var mission = MissionInstances.FirstOrDefault(m => m.MissionId == missionId); // // Check if the player is accepting a mission or responding to one. // if (mission == default) { var instance = new MissionInstance(GameObject as Player, missionId); MissionInstances.Add(instance); await instance.LoadAsync(); await instance.StartAsync(); return; } // // Player is responding to an active mission. // var isComplete = await mission.IsCompleteAsync(); if (!isComplete) { // // Mission is not complete. // var currentState = await mission.GetMissionStateAsync(); await mission.UpdateMissionStateAsync(currentState); MessageOfferMission(missionId, missionGiver); return; } // // Complete mission. // await mission.CompleteAsync(rewardItem); missionGiver?.GetComponent <MissionGiverComponent>().OfferMission(GameObject as Player); }
public void SetMissionInstance(MissionInstance _mission) { m_mission = _mission; }