Trigger.cs (4258B)
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 9 // The Command & Conquer Map Editor and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 using MobiusEditor.Interface; 16 using System; 17 18 namespace MobiusEditor.Model 19 { 20 public enum TriggerPersistantType 21 { 22 Volatile = 0, 23 SemiPersistant = 1, 24 Persistant = 2 25 } 26 27 public enum TriggerMultiStyleType 28 { 29 Only = 0, 30 And = 1, 31 Or = 2, 32 Linked = 3 33 } 34 35 public class TriggerEvent : ICloneable 36 { 37 public static readonly string None = "None"; 38 39 public string EventType { get; set; } 40 41 public string Team { get; set; } 42 43 public long Data { get; set; } 44 45 public TriggerEvent Clone() 46 { 47 return new TriggerEvent() 48 { 49 EventType = EventType, 50 Team = Team, 51 Data = Data 52 }; 53 } 54 55 object ICloneable.Clone() 56 { 57 return Clone(); 58 } 59 } 60 61 public class TriggerAction : ICloneable 62 { 63 public static readonly string None = "None"; 64 65 public string ActionType { get; set; } 66 67 public string Trigger { get; set; } 68 69 public string Team { get; set; } 70 71 public long Data { get; set; } 72 73 public TriggerAction Clone() 74 { 75 return new TriggerAction() 76 { 77 ActionType = ActionType, 78 Trigger = Trigger, 79 Team = Team, 80 Data = Data 81 }; 82 } 83 84 object ICloneable.Clone() 85 { 86 return Clone(); 87 } 88 } 89 90 public class Trigger : INamedType, ICloneable 91 { 92 public static readonly string None = "None"; 93 94 public string Name { get; set; } 95 96 public TriggerPersistantType PersistantType { get; set; } = TriggerPersistantType.Volatile; 97 98 public string House { get; set; } 99 100 public TriggerMultiStyleType EventControl { get; set; } = TriggerMultiStyleType.Only; 101 102 public TriggerEvent Event1 { get; private set; } = new TriggerEvent { EventType = TriggerEvent.None }; 103 104 public TriggerEvent Event2 { get; private set; } = new TriggerEvent { EventType = TriggerEvent.None }; 105 106 public TriggerAction Action1 { get; private set; } = new TriggerAction { ActionType = TriggerEvent.None }; 107 108 public TriggerAction Action2 { get; private set; } = new TriggerAction { ActionType = TriggerEvent.None }; 109 110 public Trigger Clone() 111 { 112 return new Trigger() 113 { 114 Name = Name, 115 PersistantType = PersistantType, 116 House = House, 117 EventControl = EventControl, 118 Event1 = Event1.Clone(), 119 Event2 = Event2.Clone(), 120 Action1 = Action1.Clone(), 121 Action2 = Action2.Clone() 122 }; 123 } 124 125 public override bool Equals(object obj) 126 { 127 if (obj is Trigger) 128 { 129 return this == obj; 130 } 131 else if (obj is string) 132 { 133 return string.Equals(Name, obj as string, StringComparison.OrdinalIgnoreCase); 134 } 135 136 return base.Equals(obj); 137 } 138 139 public override int GetHashCode() 140 { 141 return Name.GetHashCode(); 142 } 143 144 public override string ToString() 145 { 146 return Name; 147 } 148 149 object ICloneable.Clone() 150 { 151 return Clone(); 152 } 153 } 154 }