Advertisement
dimon-torchila

Untitled

Mar 5th, 2023
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. using UnityEditor.MPE;
  7. using UnityEngine;
  8.  
  9.  
  10. public class LevelProcessor : MonoBehaviour
  11. {
  12. private GameController _controller;
  13. private JObject _levelInfo;
  14. public int to_deliver;
  15. public int score;
  16. private Dictionary<string, Type> req_to_type;
  17.  
  18. private void Awake()
  19. {
  20. Dictionary<string, Type> req_to_type = new Dictionary<string, Type>(){
  21. {"deliver_object", typeof(DeliveryRequirement)},
  22. {"score", typeof(ScoreRequirement)},
  23. };
  24. _controller = GameObject.FindObjectOfType<GameController>();
  25. }
  26.  
  27. private void Start()
  28. {
  29. foreach (JObject requirement in _levelInfo["requirements"])
  30. {
  31. var parsedRequirement = requirement.ToObject(req_to_type[requirement["req_type"].ToString()]);
  32. _controller.AddNewEventProcessor(parsedRequirement.event_type);
  33. }
  34. }
  35. }
  36.  
  37. class DeliveryRequirement : IEventProcessor
  38. {
  39. public EventType event_type = EventType.object_delivered;
  40. private string req_type;
  41. private string object_type;
  42. private int min_condition;
  43. private int delivery_count = 0;
  44.  
  45. public DeliveryRequirement() { }
  46. public DeliveryRequirement(string req_type, string object_type, int min_condition, int _deliveryCount)
  47. {
  48. this.req_type = req_type;
  49. this.object_type = object_type;
  50. this.min_condition = min_condition;
  51. this.delivery_count = _deliveryCount;
  52. }
  53. public void ProcessEvent(GameEvent game_event)
  54. {
  55. if (game_event.type == EventType.object_delivered && (bool)game_event.data["delivery_is_ok"])
  56. {
  57. this.delivery_count -= 1;
  58. }
  59. }
  60. }
  61. class ScoreRequirement : IEventProcessor
  62. {
  63. public EventType eventType = EventType.score_changed;
  64. private string object_type;
  65. private int total_score;
  66.  
  67. public ScoreRequirement()
  68. { }
  69.  
  70. public ScoreRequirement(string object_type, int _totalScore)
  71. {
  72. this.object_type = object_type;
  73. this.total_score = _totalScore;
  74. }
  75. public void ProcessEvent(GameEvent game_event)
  76. {
  77. if (game_event.type == EventType.object_delivered && (bool)game_event.data["delivery_is_ok"])
  78. {
  79. this.total_score += (int)game_event.data["delivery_data"]["score"];
  80. }
  81.  
  82. if (game_event.type == EventType.score_changed)
  83. {
  84. total_score += (int)game_event.data["change_count"];
  85. }
  86. }
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement