using System; using UnityEngine; using UnityEngine.UI; public class WeeklyQuestItem : MonoBehaviour { public int uid; public int indexOfPlayerQuest; public float maxProgress; public float currentProgress; public int PointsCost = 5; public Sprite WeeklyQuestShowSprite; private Animator WeeklyQuestShowCardAnim; private AudioSource audiosource; public AudioClip[] audios; public Text PointsText; public Text QuestTypeText; public Text RewardText; public Text QuestDescriptionText; public Text ProgressText; public Text InProgressText; public Button RewardButton; public Image ProgressBorderImage; public Image ProgressBarImage; public GameObject OtwartaKartaItems; private Image BackgroundCardImage; private QuestManager questManager; public static event Action OnUnlockCardQuestErrorGlobal; public static event Action OnUnlockCardQuestGlobal; private void Start() { audiosource = GetComponent(); questManager = UnityEngine.Object.FindObjectOfType(); WeeklyQuestShowCardAnim = GetComponent(); PointsText.text = PointsCost.ToString(); BackgroundCardImage = GetComponent(); if (isShowed()) { GetComponent().sprite = WeeklyQuestShowSprite; PointsText.gameObject.SetActive(value: false); QuestTypeText.gameObject.SetActive(value: false); OtwartaKartaItems.SetActive(value: true); } } public bool isShowed() { for (int i = 0; i < Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest.Count; i++) { if (Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[i].uid == uid) { return Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[i].isShowed; } } return false; } public void ShowCardButton() { if (isShowed()) { return; } if (Singleton.Instance.GetCurrentPlayerData().QuestPoints < PointsCost) { WeeklyQuestItem.OnUnlockCardQuestErrorGlobal?.Invoke(); WeeklyQuestShowCardAnim.SetTrigger("InsufficientPoints"); return; } Singleton.Instance.GetCurrentPlayerData().QuestPoints -= PointsCost; WeeklyQuestItem.OnUnlockCardQuestGlobal?.Invoke(); WeeklyQuestShowCardAnim.SetTrigger("Show"); for (int i = 0; i < Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest.Count; i++) { if (Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[i].uid == uid) { Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[i].isShowed = true; } } } public void ShowWeeklyQuest() { GetComponent().sprite = WeeklyQuestShowSprite; PointsText.gameObject.SetActive(value: false); QuestTypeText.gameObject.SetActive(value: false); OtwartaKartaItems.SetActive(value: true); } public void SetProgress(float progress, float fullprogress) { currentProgress = progress; maxProgress = fullprogress; ProgressText.text = SetProgressTextValue(currentProgress, maxProgress); float fillAmount = SetProgressValue(progress, maxProgress); ProgressBarImage.fillAmount = fillAmount; } private float SetProgressValue(float progress, float fullprogress) { GameManager.GameQuest.QuestObjectiveType questObjectiveType = GameManager.GameQuest.QuestObjectiveType.Catch_fish; for (int i = 0; i < Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest.Count; i++) { Debug.Log(uid); if (Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[i].uid == uid) { questObjectiveType = Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[i].gameQuest.questObjectiveType; } } switch (questObjectiveType) { case GameManager.GameQuest.QuestObjectiveType.Catch_fish_by_weight: if (progress >= fullprogress) { return progress; } return 0f; case GameManager.GameQuest.QuestObjectiveType.Catch_fish: case GameManager.GameQuest.QuestObjectiveType.Spend_time: case GameManager.GameQuest.QuestObjectiveType.Catch_fish_total_weight: case GameManager.GameQuest.QuestObjectiveType.Catch_fish_by_species: return progress / maxProgress; default: return progress / maxProgress; } } private string SetProgressTextValue(float progress, float fullprogress) { GameManager.GameQuest.QuestObjectiveType questObjectiveType = GameManager.GameQuest.QuestObjectiveType.Catch_fish; for (int i = 0; i < Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest.Count; i++) { Debug.Log(uid); if (Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[i].uid == uid) { questObjectiveType = Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[i].gameQuest.questObjectiveType; } } Debug.Log(questObjectiveType); switch (questObjectiveType) { case GameManager.GameQuest.QuestObjectiveType.Catch_fish_by_weight: if (progress >= fullprogress) { return GameManager.Instance.ConvertWeightWithoutUnit(fullprogress) + "/" + GameManager.Instance.ConvertWeightWithoutUnit(fullprogress).ToString("F1"); } return GameManager.Instance.ConvertWeightWithoutUnit(0f).ToString("F1") + "/" + GameManager.Instance.ConvertWeightWithoutUnit(fullprogress).ToString("F1"); case GameManager.GameQuest.QuestObjectiveType.Catch_fish_total_weight: case GameManager.GameQuest.QuestObjectiveType.Catch_fish_by_species: return GameManager.Instance.ConvertWeightWithoutUnit(progress).ToString("F2") + "/" + GameManager.Instance.ConvertWeightWithoutUnit(fullprogress).ToString("F2"); case GameManager.GameQuest.QuestObjectiveType.Catch_fish: case GameManager.GameQuest.QuestObjectiveType.Spend_time: return Mathf.Clamp(progress, 0f, fullprogress).ToString("F0") + "/" + fullprogress; default: return GameManager.Instance.ConvertWeightWithoutUnit(progress).ToString("F2") + "/" + GameManager.Instance.ConvertWeightWithoutUnit(fullprogress).ToString("F2"); } } public void GetRewardButton() { for (int i = 0; i < Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest.Count; i++) { if (Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[i].uid == uid) { questManager.RewardAudioSource.Play(); RewardPopUpItem component = UnityEngine.Object.Instantiate(questManager.RewardPopUpPrefab, questManager.transform).GetComponent(); component.id = uid; component.rewardText.text = "$" + Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[i].gameQuest.reward; component.type = Singleton.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[i].gameQuest.type; UnityEngine.Object.Destroy(base.gameObject); } } } private void ButtonController() { if (currentProgress >= maxProgress && maxProgress > 0f) { RewardButton.gameObject.SetActive(value: true); ProgressBorderImage.gameObject.SetActive(value: false); InProgressText.gameObject.SetActive(value: false); ProgressText.gameObject.SetActive(value: false); ProgressBarImage.gameObject.SetActive(value: false); } } private void Update() { ButtonController(); } }