Trigger.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // The Command & Conquer Map Editor and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // The Command & Conquer Map Editor and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. using MobiusEditor.Interface;
  15. using System;
  16. namespace MobiusEditor.Model
  17. {
  18. public enum TriggerPersistantType
  19. {
  20. Volatile = 0,
  21. SemiPersistant = 1,
  22. Persistant = 2
  23. }
  24. public enum TriggerMultiStyleType
  25. {
  26. Only = 0,
  27. And = 1,
  28. Or = 2,
  29. Linked = 3
  30. }
  31. public class TriggerEvent : ICloneable
  32. {
  33. public static readonly string None = "None";
  34. public string EventType { get; set; }
  35. public string Team { get; set; }
  36. public long Data { get; set; }
  37. public TriggerEvent Clone()
  38. {
  39. return new TriggerEvent()
  40. {
  41. EventType = EventType,
  42. Team = Team,
  43. Data = Data
  44. };
  45. }
  46. object ICloneable.Clone()
  47. {
  48. return Clone();
  49. }
  50. }
  51. public class TriggerAction : ICloneable
  52. {
  53. public static readonly string None = "None";
  54. public string ActionType { get; set; }
  55. public string Trigger { get; set; }
  56. public string Team { get; set; }
  57. public long Data { get; set; }
  58. public TriggerAction Clone()
  59. {
  60. return new TriggerAction()
  61. {
  62. ActionType = ActionType,
  63. Trigger = Trigger,
  64. Team = Team,
  65. Data = Data
  66. };
  67. }
  68. object ICloneable.Clone()
  69. {
  70. return Clone();
  71. }
  72. }
  73. public class Trigger : INamedType, ICloneable
  74. {
  75. public static readonly string None = "None";
  76. public string Name { get; set; }
  77. public TriggerPersistantType PersistantType { get; set; } = TriggerPersistantType.Volatile;
  78. public string House { get; set; }
  79. public TriggerMultiStyleType EventControl { get; set; } = TriggerMultiStyleType.Only;
  80. public TriggerEvent Event1 { get; private set; } = new TriggerEvent { EventType = TriggerEvent.None };
  81. public TriggerEvent Event2 { get; private set; } = new TriggerEvent { EventType = TriggerEvent.None };
  82. public TriggerAction Action1 { get; private set; } = new TriggerAction { ActionType = TriggerEvent.None };
  83. public TriggerAction Action2 { get; private set; } = new TriggerAction { ActionType = TriggerEvent.None };
  84. public Trigger Clone()
  85. {
  86. return new Trigger()
  87. {
  88. Name = Name,
  89. PersistantType = PersistantType,
  90. House = House,
  91. EventControl = EventControl,
  92. Event1 = Event1.Clone(),
  93. Event2 = Event2.Clone(),
  94. Action1 = Action1.Clone(),
  95. Action2 = Action2.Clone()
  96. };
  97. }
  98. public override bool Equals(object obj)
  99. {
  100. if (obj is Trigger)
  101. {
  102. return this == obj;
  103. }
  104. else if (obj is string)
  105. {
  106. return string.Equals(Name, obj as string, StringComparison.OrdinalIgnoreCase);
  107. }
  108. return base.Equals(obj);
  109. }
  110. public override int GetHashCode()
  111. {
  112. return Name.GetHashCode();
  113. }
  114. public override string ToString()
  115. {
  116. return Name;
  117. }
  118. object ICloneable.Clone()
  119. {
  120. return Clone();
  121. }
  122. }
  123. }