QuestGigs.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using UnityEngine;
  2. using DataTools;
  3. using WebTools.Phone;
  4. public class QuestGigs : RandomGigs
  5. {
  6. protected override void Start()
  7. {
  8. base.Start();
  9. GameGlobal.Instance.OnGigChanged += OnGigChanged;
  10. OnGigChanged(GameGlobal.Instance.GigID);
  11. }
  12. private void OnGigChanged(string id)
  13. {
  14. if (id == string.Empty)
  15. {
  16. return;
  17. }
  18. currentGig = data.GameData.GetGigById(id, GameGlobal.Instance.CurrentChapter);
  19. if (dataUser.UserData.ActualGigId != currentGig.Id)
  20. {
  21. if (dataUser.UserData.StarsEarned > 0)
  22. {
  23. Debug.LogWarning("Something weird happens and StarsEarned value not 0 at the start of gig");
  24. dataUser.UserData.StarsEarned = 0;//To prevent starting gig with filled completion bar
  25. }
  26. dataUser.UserData.ActualGigId = currentGig.Id;
  27. dataUser.OnGigTimestampReceived += OnTimeReceived;
  28. dataUser.UpdateGigStartTime();
  29. SaveDataUser();
  30. }
  31. else
  32. {
  33. OnTimeReceived();
  34. }
  35. if((currentGig.StarsNeeded - dataUser.UserData.StarsEarned) > 0)
  36. {
  37. RandomizeGigs(currentGig.StarsNeeded, currentGig.Type, currentGig.Location);
  38. }
  39. else
  40. {
  41. Invoke("OnFinishTask", 2f);
  42. }
  43. }
  44. private void SaveDataUser()
  45. {
  46. dataUser.UpdateDataUser();
  47. }
  48. protected override void OnLocationChanged(Location location)
  49. {
  50. base.OnLocationChanged(location);
  51. if(currentGig != null)
  52. {
  53. SetLocationButtons(currentGig.Location);
  54. }
  55. }
  56. protected override void OnFinishTask()
  57. {
  58. DataTools.Gig gig = currentGig;
  59. dataUser.UserData.ActualGigId = string.Empty;
  60. FinishGig();
  61. base.OnFinishTask();
  62. if (gig.Type != DataTools.GigType.Practice)
  63. {
  64. AddTweetReward(gig);
  65. }
  66. }
  67. protected override void Update()
  68. {
  69. base.Update();
  70. }
  71. private void AddTweetReward()
  72. {
  73. ChirpTimerAndFollowers chirpTimerAndFollow = gigsGigActionsData.GetChirpTimerAndFollowers(currentGig.Type, currentGig.Duration);
  74. TweetBehaviour.Instance.GigTweet(currentGig, chirpTimerAndFollow, pointsBar);
  75. return;
  76. }
  77. private void AddTweetReward(DataTools.Gig gig)
  78. {
  79. if(gig.Id == "Your First Gig")//This is stupid. Need to find another way to not showing tweet after first gig in game.
  80. {
  81. return;
  82. }
  83. ChirpTimerAndFollowers chirpTimerAndFollow = gigsGigActionsData.GetChirpTimerAndFollowers(gig.Type, gig.Duration);
  84. TweetBehaviour.Instance.GigTweet(gig, chirpTimerAndFollow, pointsBar);
  85. return;
  86. }
  87. protected override void ShowTweetOnGigFinish()
  88. {
  89. AddTweetReward();
  90. dataUser.UserData.ActualGigId = string.Empty;
  91. }
  92. }