|
12 | 12 | namespace SessionSeven.Actors
|
13 | 13 | {
|
14 | 14 |
|
15 |
| - [Serializable] |
16 |
| - public class BloodDropEmitter : Component, IContent, IUpdate |
17 |
| - { |
18 |
| - List<RyanBlooddrop> Drops = new List<RyanBlooddrop>(); |
19 |
| - bool SpawnDrops = true; |
20 |
| - int TotalBloodDrops = 0; |
21 |
| - int BloodDropCounter = 0; |
22 |
| - int CommentCounter = -1; |
23 |
| - int Comments = 0; |
24 |
| - [NonSerialized] |
25 |
| - private Texture2D _Texture; |
26 |
| - public Texture2D Texture { get { return _Texture; } } |
27 |
| - |
28 |
| - public BloodDropEmitter() |
29 |
| - { |
30 |
| - Drops = new List<RyanBlooddrop>(); |
31 |
| - Enabled = true; |
32 |
| - } |
33 |
| - |
34 |
| - public void Start() |
35 |
| - { |
36 |
| - SpawnDrops = true; |
37 |
| - Enabled = true; |
38 |
| - } |
39 |
| - |
40 |
| - public void Stop() |
41 |
| - { |
42 |
| - SpawnDrops = false; |
43 |
| - } |
44 |
| - |
45 |
| - Randomizer Randomizer |
46 |
| - { |
47 |
| - get |
48 |
| - { |
49 |
| - return Entity.World.Get<Randomizer>(); |
50 |
| - } |
51 |
| - } |
52 |
| - |
53 |
| - public bool Enabled { get; set; } |
54 |
| - public float UpdateOrder { get; set; } |
55 |
| - |
56 |
| - public void LoadContent(ContentLoader content) |
57 |
| - { |
58 |
| - _Texture = content.Load<Texture2D>(SessionSeven.content.rooms.basement.blooddrops); |
59 |
| - foreach (var Drop in Drops) |
60 |
| - { |
61 |
| - Drop.Get<Sprite>().SetTexture(_Texture, 16, 1); |
62 |
| - } |
63 |
| - } |
64 |
| - |
65 |
| - public void UnloadContent() |
66 |
| - { |
67 |
| - |
68 |
| - } |
69 |
| - |
70 |
| - public void Update() |
71 |
| - { |
72 |
| - OnUpdateDrops(); |
73 |
| - OnUpdateComments(); |
74 |
| - } |
75 |
| - |
76 |
| - public void ResetCommentCounter() |
77 |
| - { |
78 |
| - CommentCounter = Randomizer.CreateInt(1000, 1500); |
79 |
| - } |
80 |
| - |
81 |
| - void OnUpdateComments() |
82 |
| - { |
83 |
| - const string COMMENT_BLOOD_SCRIPT = "commentblood"; |
84 |
| - |
85 |
| - if (-1 == CommentCounter && !Game.Ego.Get<Scripts>().HasScript(COMMENT_BLOOD_SCRIPT)) |
86 |
| - { |
87 |
| - ResetCommentCounter(); |
88 |
| - } |
89 |
| - |
90 |
| - if (0 == CommentCounter) |
91 |
| - { |
92 |
| - if (Entity.World.Interactive && |
93 |
| - Verbs.Walk.Equals(Tree.GUI.Interaction.Scene.SelectedVerb) && |
94 |
| - null == Tree.GUI.Interaction.Scene.SelectedPrimary && |
95 |
| - !Game.Ego.Get<Scripts>().HasScript(COMMENT_BLOOD_SCRIPT)) |
96 |
| - { |
97 |
| - CommentCounter = -1; |
98 |
| - Game.Ego.Stop(); |
99 |
| - Game.Ego.StartScript(CommentScript(), COMMENT_BLOOD_SCRIPT); |
100 |
| - } |
101 |
| - } |
102 |
| - else if (CommentCounter > 0 && Entity.World.Interactive) |
103 |
| - { |
104 |
| - CommentCounter--; |
105 |
| - } |
106 |
| - } |
107 |
| - |
108 |
| - IEnumerator CommentScript() |
109 |
| - { |
110 |
| - Game.Ego.Turn(Directions4.Down); |
111 |
| - Entity.World.Interactive = false; |
112 |
| - var Comment = string.Empty; |
113 |
| - |
114 |
| - switch (Comments) |
115 |
| - { |
116 |
| - case 0: |
117 |
| - Comment = Basement_Res.My_hand_is_wounded; |
118 |
| - break; |
119 |
| - case 1: |
120 |
| - Comment = Basement_Res.My_hand_is_losing_blood; |
121 |
| - break; |
122 |
| - case 2: |
123 |
| - Comment = Basement_Res.My_hand_is_still_losing_blood; |
124 |
| - break; |
125 |
| - case 3: |
126 |
| - Comment = Basement_Res.I_need_to_dress_my_hand; |
127 |
| - break; |
128 |
| - default: |
129 |
| - Comment = Basement_Res.I_should_have_a_look_at_the_medical_cabinet_over_there_to_dress_my_wound; |
130 |
| - break; |
131 |
| - } |
132 |
| - |
133 |
| - if (Game.Ego.Inventory.HasItem<InventoryItems.Bandages>() || Game.Ego.Inventory.HasItem<InventoryItems.BandagesCut>()) |
134 |
| - { |
135 |
| - Comment = Basement_Res.I_should_use_those_bandages_to_dress_my_wound; |
136 |
| - } |
137 |
| - |
138 |
| - yield return Game.Ego.Say(Comment); |
139 |
| - Comments++; |
140 |
| - Entity.World.Interactive = true; |
141 |
| - Tree.GUI.Interaction.Scene.Reset(); |
142 |
| - } |
143 |
| - |
144 |
| - void OnUpdateDrops() |
145 |
| - { |
146 |
| - if (0 == BloodDropCounter && SpawnDrops) |
147 |
| - { |
148 |
| - BloodDropCounter = Randomizer.CreateInt(80, 160); |
149 |
| - SpawnDrop(); |
150 |
| - } |
151 |
| - |
152 |
| - UpdateDrops(); |
153 |
| - BloodDropCounter--; |
154 |
| - if (Drops.Count == 0 && !SpawnDrops) |
155 |
| - { |
156 |
| - Enabled = false; |
157 |
| - } |
158 |
| - } |
159 |
| - |
160 |
| - void SpawnDrop() |
161 |
| - { |
162 |
| - // spawn new blooddrop |
163 |
| - var frame = (byte)Randomizer.CreateInt(15); |
164 |
| - var ttl = 500 + Randomizer.CreateInt(50, 150); |
165 |
| - var Transform = Get<Transform>(); |
166 |
| - var DirectionDisplacment = Vector2.Zero; |
167 |
| - |
168 |
| - switch (Transform.Direction4) |
169 |
| - { |
170 |
| - case Directions4.Left: DirectionDisplacment = new Vector2(-10, -25 + 9); break; |
171 |
| - case Directions4.Up: DirectionDisplacment = new Vector2(10, -7); break; |
172 |
| - case Directions4.Down: DirectionDisplacment = new Vector2(-23, -7); break; |
173 |
| - case Directions4.Right: DirectionDisplacment = new Vector2(-11, -11 + 9); break; |
174 |
| - } |
175 |
| - |
176 |
| - // some random displacement |
177 |
| - var RandomDisplacement = new Vector2(Randomizer.CreateInt(-3, 3), Randomizer.CreateInt(-2, 2)); |
178 |
| - var position = Transform.Position + DirectionDisplacment + RandomDisplacement; |
179 |
| - |
180 |
| - var id = typeof(RyanBlooddrop).FullName + "_" + TotalBloodDrops; |
181 |
| - var z = .0f; |
182 |
| - |
183 |
| - switch (Transform.Direction4) |
184 |
| - { |
185 |
| - case Directions4.Up: |
186 |
| - case Directions4.Down: z = Transform.Z + 1; break; |
187 |
| - case Directions4.Left: z = Transform.Z - 5; break; |
188 |
| - case Directions4.Right: z = Transform.Z + 5; break; |
189 |
| - } |
190 |
| - |
191 |
| - var bloodDrop = new RyanBlooddrop(position, frame, ttl, id, z); |
192 |
| - Drops.Add(bloodDrop); |
193 |
| - |
194 |
| - Entity.DrawScene.Push(bloodDrop); |
195 |
| - TotalBloodDrops++; |
196 |
| - } |
197 |
| - |
198 |
| - void UpdateDrops() |
199 |
| - { |
200 |
| - for (int i = Drops.Count - 1; i >= 0; i--) |
201 |
| - { |
202 |
| - Drops[i].TimeToLive--; |
203 |
| - if (Drops[i].TimeToLive <= 0) |
204 |
| - { |
205 |
| - Drops[i].UpdateScene.Pop(Drops[i]); |
206 |
| - Drops.RemoveAt(i); |
207 |
| - } |
208 |
| - } |
209 |
| - } |
210 |
| - |
211 |
| - public static BloodDropEmitter Create(Entity entity) |
212 |
| - { |
213 |
| - return entity.Add<BloodDropEmitter>(); |
214 |
| - } |
215 |
| - } |
| 15 | + [Serializable] |
| 16 | + public class BloodDropEmitter : Component, IContent, IUpdate |
| 17 | + { |
| 18 | + private readonly List<RyanBlooddrop> _drops = new List<RyanBlooddrop>(); |
| 19 | + private bool _spawnDrops = true; |
| 20 | + private int _totalBloodDrops = 0; |
| 21 | + private int _bloodDropCounter = 0; |
| 22 | + private int _commentCounter = -1; |
| 23 | + private int _comments = 0; |
| 24 | + [NonSerialized] |
| 25 | + private Texture2D _texture; |
| 26 | + public Texture2D Texture => _texture; |
| 27 | + |
| 28 | + public BloodDropEmitter() |
| 29 | + { |
| 30 | + _drops = new List<RyanBlooddrop>(); |
| 31 | + Enabled = true; |
| 32 | + } |
| 33 | + |
| 34 | + public void Start() |
| 35 | + { |
| 36 | + _spawnDrops = true; |
| 37 | + Enabled = true; |
| 38 | + } |
| 39 | + |
| 40 | + public void Stop() |
| 41 | + { |
| 42 | + _spawnDrops = false; |
| 43 | + } |
| 44 | + |
| 45 | + private Randomizer Randomizer => Entity.World.Get<Randomizer>(); |
| 46 | + |
| 47 | + public bool Enabled { get; set; } |
| 48 | + public float UpdateOrder { get; set; } |
| 49 | + |
| 50 | + public void LoadContent(ContentLoader content) |
| 51 | + { |
| 52 | + _texture = content.Load<Texture2D>(SessionSeven.content.rooms.basement.blooddrops); |
| 53 | + foreach (var drop in _drops) |
| 54 | + { |
| 55 | + drop.Get<Sprite>().SetTexture(_texture, 16, 1); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + public void UnloadContent() |
| 60 | + { |
| 61 | + |
| 62 | + } |
| 63 | + |
| 64 | + public void Update() |
| 65 | + { |
| 66 | + OnUpdateDrops(); |
| 67 | + OnUpdateComments(); |
| 68 | + } |
| 69 | + |
| 70 | + public void ResetCommentCounter() |
| 71 | + { |
| 72 | + _commentCounter = Randomizer.CreateInt(1000, 1500); |
| 73 | + } |
| 74 | + |
| 75 | + private void OnUpdateComments() |
| 76 | + { |
| 77 | + const string commentBloodScript = "commentblood"; |
| 78 | + |
| 79 | + if (-1 == _commentCounter && !Game.Ego.Get<Scripts>().HasScript(commentBloodScript)) |
| 80 | + { |
| 81 | + ResetCommentCounter(); |
| 82 | + } |
| 83 | + |
| 84 | + if (0 == _commentCounter) |
| 85 | + { |
| 86 | + if (Entity.World.Interactive && |
| 87 | + Verbs.Walk.Equals(Tree.GUI.Interaction.Scene.SelectedVerb) && |
| 88 | + null == Tree.GUI.Interaction.Scene.SelectedPrimary && |
| 89 | + !Game.Ego.Get<Scripts>().HasScript(commentBloodScript)) |
| 90 | + { |
| 91 | + _commentCounter = -1; |
| 92 | + Game.Ego.Stop(); |
| 93 | + Game.Ego.StartScript(CommentScript(), commentBloodScript); |
| 94 | + } |
| 95 | + } |
| 96 | + else if (_commentCounter > 0 && Entity.World.Interactive) |
| 97 | + { |
| 98 | + _commentCounter--; |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + private IEnumerator CommentScript() |
| 103 | + { |
| 104 | + Game.Ego.Turn(Directions4.Down); |
| 105 | + Entity.World.Interactive = false; |
| 106 | + string comment; |
| 107 | + switch (_comments) |
| 108 | + { |
| 109 | + case 0: |
| 110 | + comment = Basement_Res.My_hand_is_wounded; |
| 111 | + break; |
| 112 | + case 1: |
| 113 | + comment = Basement_Res.My_hand_is_losing_blood; |
| 114 | + break; |
| 115 | + case 2: |
| 116 | + comment = Basement_Res.My_hand_is_still_losing_blood; |
| 117 | + break; |
| 118 | + case 3: |
| 119 | + comment = Basement_Res.I_need_to_dress_my_hand; |
| 120 | + break; |
| 121 | + default: |
| 122 | + comment = Basement_Res.I_should_have_a_look_at_the_medical_cabinet_over_there_to_dress_my_wound; |
| 123 | + break; |
| 124 | + } |
| 125 | + |
| 126 | + if (Game.Ego.Inventory.HasItem<InventoryItems.Bandages>() || Game.Ego.Inventory.HasItem<InventoryItems.BandagesCut>()) |
| 127 | + { |
| 128 | + comment = Basement_Res.I_should_use_those_bandages_to_dress_my_wound; |
| 129 | + } |
| 130 | + |
| 131 | + yield return Game.Ego.Say(comment); |
| 132 | + _comments++; |
| 133 | + Entity.World.Interactive = true; |
| 134 | + Tree.GUI.Interaction.Scene.Reset(); |
| 135 | + } |
| 136 | + |
| 137 | + private void OnUpdateDrops() |
| 138 | + { |
| 139 | + if (0 == _bloodDropCounter && _spawnDrops) |
| 140 | + { |
| 141 | + _bloodDropCounter = Randomizer.CreateInt(80, 160); |
| 142 | + SpawnDrop(); |
| 143 | + } |
| 144 | + |
| 145 | + UpdateDrops(); |
| 146 | + _bloodDropCounter--; |
| 147 | + if (_drops.Count == 0 && !_spawnDrops) |
| 148 | + { |
| 149 | + Enabled = false; |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + private void SpawnDrop() |
| 154 | + { |
| 155 | + // spawn new blooddrop |
| 156 | + var frame = (byte)Randomizer.CreateInt(15); |
| 157 | + var ttl = 500 + Randomizer.CreateInt(50, 150); |
| 158 | + var transform = Get<Transform>(); |
| 159 | + var directionDisplacment = Vector2.Zero; |
| 160 | + |
| 161 | + switch (transform.Direction4) |
| 162 | + { |
| 163 | + case Directions4.Left: directionDisplacment = new Vector2(-10, -25 + 9); break; |
| 164 | + case Directions4.Up: directionDisplacment = new Vector2(10, -7); break; |
| 165 | + case Directions4.Down: directionDisplacment = new Vector2(-23, -7); break; |
| 166 | + case Directions4.Right: directionDisplacment = new Vector2(-11, -11 + 9); break; |
| 167 | + } |
| 168 | + |
| 169 | + // some random displacement |
| 170 | + var randomDisplacement = new Vector2(Randomizer.CreateInt(-3, 3), Randomizer.CreateInt(-2, 2)); |
| 171 | + var position = transform.Position + directionDisplacment + randomDisplacement; |
| 172 | + |
| 173 | + var id = typeof(RyanBlooddrop).FullName + "_" + _totalBloodDrops; |
| 174 | + var z = .0f; |
| 175 | + |
| 176 | + switch (transform.Direction4) |
| 177 | + { |
| 178 | + case Directions4.Up: |
| 179 | + case Directions4.Down: z = transform.Z + 1; break; |
| 180 | + case Directions4.Left: z = transform.Z - 5; break; |
| 181 | + case Directions4.Right: z = transform.Z + 5; break; |
| 182 | + } |
| 183 | + |
| 184 | + var bloodDrop = new RyanBlooddrop(position, frame, ttl, id, z); |
| 185 | + _drops.Add(bloodDrop); |
| 186 | + |
| 187 | + Entity.DrawScene.Push(bloodDrop); |
| 188 | + _totalBloodDrops++; |
| 189 | + } |
| 190 | + |
| 191 | + private void UpdateDrops() |
| 192 | + { |
| 193 | + for (var i = _drops.Count - 1; i >= 0; i--) |
| 194 | + { |
| 195 | + _drops[i].TimeToLive--; |
| 196 | + if (_drops[i].TimeToLive <= 0) |
| 197 | + { |
| 198 | + _drops[i].UpdateScene.Pop(_drops[i]); |
| 199 | + _drops.RemoveAt(i); |
| 200 | + } |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + public static BloodDropEmitter Create(Entity entity) |
| 205 | + { |
| 206 | + return entity.Add<BloodDropEmitter>(); |
| 207 | + } |
| 208 | + } |
216 | 209 | }
|
0 commit comments