OSDN Git Service

Added assists aiding Aspiring Apiarists
[automap/automap.git] / Automap / Designators / DefaultDesignators.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Drawing;
4 using System.Text;
5 using System.Text.RegularExpressions;
6 using HarmonyLib;
7 using Vintagestory.API.Client;
8 using Vintagestory.API.Common;
9 using Vintagestory.API.Common.Entities;
10 using Vintagestory.API.Config;
11 using Vintagestory.API.MathTools;
12 using Vintagestory.GameContent;
13
14 namespace Automap
15 {
16         public static class DefaultDesignators
17         {
18                 #region Defaults
19
20                 public static BlockDesignator Roads =
21                          new BlockDesignator(
22                                 new AssetLocation("game", "stonepath"),
23                                 Color.Yellow,
24                                 EnumBlockMaterial.Gravel
25                         );
26
27                 public static BlockDesignator GroundSigns =
28                          new BlockDesignator(
29                                 new AssetLocation("game", "sign-ground"),
30                                 Color.Teal,
31                                 EnumBlockMaterial.Wood,
32                                 DecodeSign
33                         );
34
35                 public static BlockDesignator WallSigns =
36                          new BlockDesignator(
37                                 new AssetLocation("game", "sign-wall"),
38                                 Color.Teal,
39                                 EnumBlockMaterial.Wood,
40                                 DecodeSign
41                         );
42
43                 public static BlockDesignator PostSigns =
44                          new BlockDesignator(
45                                 new AssetLocation("game", "signpost"),
46                                 Color.Teal,
47                                 EnumBlockMaterial.Wood,
48                                 DecodePostSign
49                         );
50
51                 public static BlockDesignator Translocators =
52                          new BlockDesignator(
53                                 new AssetLocation("game", "statictranslocator-normal"),
54                                 Color.SteelBlue,
55                                 EnumBlockMaterial.Metal,
56                                 DecodeTranslocator
57                         );
58
59                 public static BlockDesignator Teleporters =
60                          new BlockDesignator(
61                                 new AssetLocation("game", "teleporterbase"),
62                                 Color.SeaGreen,
63                                 EnumBlockMaterial.Wood,
64                                 DecodeTeleport
65                         );
66
67                 public static EntityDesignator Traders =
68                          new EntityDesignator(
69                                 new AssetLocation("game", "humanoid-trader"),
70                                 Color.LightGoldenrodYellow,
71                                 EnumEntityState.Active,
72                                 KeepTrackOfMerchant
73                         );
74
75                 public static BlockDesignator Wildbeehives =
76                          new BlockDesignator(
77                                 new AssetLocation("game", "wildbeehive"),
78                                 Color.Honeydew,
79                                 EnumBlockMaterial.Other,
80                                 NoteWildbeehive
81                         );
82
83                 /// <summary>
84                 /// Not just blocks, but block-entities as well!
85                 /// </summary>
86                 /// <returns>The block designators.</returns>
87                 public static List<BlockDesignator> DefaultBlockDesignators
88                 {
89                         get
90                         {
91                                 return new List<BlockDesignator>{
92                                         DefaultDesignators.Roads,
93                                         DefaultDesignators.GroundSigns,
94                                         DefaultDesignators.WallSigns,
95                                         DefaultDesignators.PostSigns,
96                                         DefaultDesignators.Translocators,
97                                         DefaultDesignators.Teleporters,
98                         DefaultDesignators.Wildbeehives,
99                                         };
100                         }
101                 }
102
103                 public static List<EntityDesignator> DefaultEntityDesignators
104                 {
105                         get
106                         {
107                                 return new List<EntityDesignator>{
108                                                 DefaultDesignators.Traders,
109                                 };
110                         }
111                 }
112
113                 #endregion
114
115
116                 #region Designators
117
118                 internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
119                 {
120 #if DEBUG
121                 clientAPI.Logger.VerboseDebug("Sign Designator Invoked!");
122 #endif
123                 //sign Text into a POI field...
124                 BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign;
125
126                 if (signEntity != null && !String.IsNullOrEmpty(signEntity.text)) {
127
128                 poi.AddReplace(
129                                         new PointOfInterest {
130                                                 Name = "Sign",
131                                                 PrettyLocation = posn.PrettyCoords(clientAPI),
132                                                 Location = posn.Copy( ),
133                                                 Notes = signEntity.text,
134                                                 Timestamp = DateTime.UtcNow,
135                                         }
136                                         );
137                 }
138                 }
139
140
141                 internal static void DecodePostSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
142                 {
143 #if DEBUG
144                 clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!");
145 #endif
146                 //sign post Text into a POI field...
147                 BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost;
148
149                 if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0) {
150
151                 poi.AddReplace(
152                                         new PointOfInterest {
153                                                 Name = "Signpost",
154                                                 PrettyLocation = posn.PrettyCoords(clientAPI),
155                                                 Location = posn.Copy( ),
156                                                 Notes = string.Join(",", signEntity.textByCardinalDirection),
157                                                 Timestamp = DateTime.UtcNow,
158                                         }
159                                         );
160                 }
161                 }
162
163                 internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity)
164                 {
165                 //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
166
167                 var traderJoe = entity as EntityTrader;
168                 var traderName = entity.GetBehavior<EntityBehaviorNameTag>( )?.DisplayName;
169                 string code;
170                 // this makes me ill
171                 switch (entity.Code.Path) {
172                 case "humanoid-trader-artisan":
173                         code = "{0} the artisan";
174                         break;
175                 case "humanoid-trader-treasurehunter":
176                         code = "{0} the treasure hunter";
177                         break;
178                 case "humanoid-trader-buildmaterials":
179                         code = "{0} the building materials trader";
180                         break;
181                 case "humanoid-trader-clothing":
182                         code = "{0} the clothing merchant";
183                         break;
184                 case "humanoid-trader-commodities":
185                         code = "{0} the commodities merchant";
186                         break;
187                 case "humanoid-trader-foods":
188                         code = "{0} the foods supplier";
189                         break;
190                 case "humanoid-trader-furniture":
191                         code = "{0} the furniture trader";
192                         break;
193                 case "humanoid-trader-luxuries":
194                         code = "{0} the luxuries merchant";
195                         break;
196                 case "humanoid-trader-survivalgoods":
197                         code = "{0} the survival goods supplier";
198                         break;
199                 default:
200                         code = "";
201                         break;
202                 }
203                 var message = string.Format(code, traderName);
204                 if (traderJoe.TradeProps != null) {
205                 message += $" - Gears: {traderJoe.TradeProps.Money}, ";
206                 }
207                 poi.AddReplace(new EntityOfInterest {
208                         Name = "Trader",
209                         PrettyLocation = posn.PrettyCoords(clientAPI),
210                         Location = posn.Copy( ),
211                         Notes = message,
212                         Timestamp = DateTime.UtcNow,
213                         EntityId = entity.EntityId
214                 });
215                 }
216
217                 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
218                 {
219 #if DEBUG
220                 clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
221 #endif
222                 //Where to? and from!
223
224                 BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
225
226                 if (te != null) {
227                 //FIXME: Delayed rescan ?
228                 StringBuilder textTarget = new StringBuilder( );
229                 //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
230                 textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
231                 textTarget.Append(te.Activated ? "Online, " : "Offline, ");
232                 textTarget.Append(" Target: [ ");
233                 textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?           
234                 textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
235                 poi.AddReplace(
236                                         new PointOfInterest {
237                                                 Name = "Translocator",
238                                                 PrettyLocation = posn.PrettyCoords(clientAPI),
239                                                 Location = posn.Copy( ),
240                                                 Notes = textTarget.ToString( ),
241                                                 Timestamp = DateTime.UtcNow,
242                                                 Destination = te.TargetLocation != null ? new BlockPosJson(te.TargetLocation.Copy( )) : null
243                                         }
244                                         );
245                 }
246                 }
247
248
249                 internal static void DecodeTeleport(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
250                 {
251                 #if DEBUG
252                 clientAPI.Logger.VerboseDebug("Teleport Designator Invoked!");
253                 #endif
254                 
255
256                 BlockEntityTeleporter tele = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityTeleporter;
257
258                 if (tele != null) 
259                         {
260                         //TeleporterManager teleManager = clientAPI.ModLoader.GetModSystem<TeleporterManager>();
261                         TeleporterLocation location = AccessTools.FieldRefAccess<BlockEntityTeleporter, TeleporterLocation>(tele, @"tpLocation");//TeleporterLocation tpLocation;
262
263                         if (location != null) 
264                         {
265                         StringBuilder textTarget = new StringBuilder( );
266                         textTarget.Append(" Target: [ ");
267                         textTarget.Append($" '{location.SourceName}' @ {location.SourcePos?.PrettyCoords(clientAPI)} -> '{location.TargetName}' @ {location.TargetPos?.PrettyCoords(clientAPI)}  ");//Or ABS coords?            
268                         textTarget.Append(" ]");
269                         poi.AddReplace(
270                                                 new PointOfInterest {
271                                                         Name = "Teleport",
272                                                         PrettyLocation = posn.PrettyCoords(clientAPI),
273                                                         Location = posn.Copy( ),
274                                                         Notes = textTarget.ToString( ),
275                                                         Timestamp = DateTime.UtcNow,
276                                                         Destination = location.TargetPos != null ? new BlockPosJson(location.TargetPos.Copy( )) : null
277                                                 }
278                                                 );
279                         }
280                 }
281                 }
282
283                 internal static void NoteWildbeehive(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
284                 {
285                 #if DEBUG
286                 clientAPI.Logger.VerboseDebug("Wild bee hive Designator Invoked!");
287                 #endif
288
289                 BlockEntityBeehive bees = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityBeehive;
290
291                 if (bees != null) {                             
292                 EnumHivePopSize hiveSize = AccessTools.FieldRefAccess<BlockEntityBeehive, EnumHivePopSize>(bees, @"hivePopSize");//TeleporterLocation tpLocation;
293
294                 StringBuilder textTarget = new StringBuilder( );
295                 textTarget.AppendLine($" Population: {(hiveSize != null? hiveSize.ToString() : "?")} ");                
296                 
297                 poi.AddReplace(
298                                         new PointOfInterest {
299                                                 Name = "Wildbeehive",
300                                                 PrettyLocation = posn.PrettyCoords(clientAPI),
301                                                 Location = posn.Copy( ),
302                                                 Notes = textTarget.ToString( ),
303                                                 Timestamp = DateTime.UtcNow,
304                                         }
305                                         );              
306                 }
307                 }
308
309                 #endregion
310         }
311 }
312