2 using System.Collections.Generic;
5 using System.Text.RegularExpressions;
9 using Vintagestory.API.Client;
10 using Vintagestory.API.Common;
11 using Vintagestory.API.Common.Entities;
12 using Vintagestory.API.Config;
13 using Vintagestory.API.MathTools;
14 using Vintagestory.GameContent;
18 public static class DefaultDesignators
22 public static BlockDesignator Roads =
24 new AssetLocation("game", "stonepath"),
26 EnumBlockMaterial.Gravel
29 public static BlockDesignator GroundSigns =
31 new AssetLocation("game", "sign-ground"),
33 EnumBlockMaterial.Wood,
37 public static BlockDesignator WallSigns =
39 new AssetLocation("game", "sign-wall"),
41 EnumBlockMaterial.Wood,
45 public static BlockDesignator PostSigns =
47 new AssetLocation("game", "signpost"),
49 EnumBlockMaterial.Wood,
53 public static BlockDesignator Translocators =
55 new AssetLocation("game", "statictranslocator-normal"),
57 EnumBlockMaterial.Metal,
61 public static BlockDesignator Teleporters =
63 new AssetLocation("game", "teleporterbase"),
65 EnumBlockMaterial.Wood,
69 public static EntityDesignator Traders =
71 new AssetLocation("game", "humanoid-trader"),
72 Color.LightGoldenrodYellow,
73 EnumEntityState.Active,
77 public static BlockDesignator Wildbeehives =
79 new AssetLocation("game", "wildbeehive"),
81 EnumBlockMaterial.Other,
86 public static BlockDesignator PineResinLeaks =
88 new AssetLocation("game", "log-resin"),
90 EnumBlockMaterial.Wood,
98 /// Not just blocks, but block-entities as well!
100 /// <returns>The block designators.</returns>
101 public static List<BlockDesignator> DefaultBlockDesignators
105 return new List<BlockDesignator>{
106 DefaultDesignators.Roads,
107 DefaultDesignators.GroundSigns,
108 DefaultDesignators.WallSigns,
109 DefaultDesignators.PostSigns,
110 DefaultDesignators.Translocators,
111 DefaultDesignators.Teleporters,
112 DefaultDesignators.Wildbeehives,
113 DefaultDesignators.PineResinLeaks,
118 public static List<EntityDesignator> DefaultEntityDesignators
122 return new List<EntityDesignator>{
123 DefaultDesignators.Traders,
128 internal static Encoding SaferUnicodeEncoding = Encoding.GetEncoding(Encoding.UTF8.WebName,
129 new EncoderReplacementFallback(@" "),
130 new DecoderReplacementFallback(@" "));
137 internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
140 clientAPI.Logger.VerboseDebug("Sign Designator Invoked!");
142 //sign Text into a POI field...
143 BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign;
145 if (signEntity != null && !String.IsNullOrEmpty(signEntity.text)) {
147 var textTemp = SaferUnicodeEncoding.GetBytes(signEntity.text);
150 new PointOfInterest {
152 PrettyLocation = posn.PrettyCoords(clientAPI),
153 Location = posn.Copy( ),
154 Notes = SaferUnicodeEncoding.GetString(textTemp).Normalize(),
155 Timestamp = DateTime.UtcNow,
162 internal static void DecodePostSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
165 clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!");
167 //sign post Text into a POI field...
168 BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost;
170 if (signEntity != null && signEntity.textByCardinalDirection != null && signEntity.textByCardinalDirection?.Length > 0) {
172 var textTemp = SaferUnicodeEncoding.GetBytes(string.Join(",", signEntity.textByCardinalDirection));
175 new PointOfInterest {
177 PrettyLocation = posn.PrettyCoords(clientAPI),
178 Location = posn.Copy( ),
179 Notes = SaferUnicodeEncoding.GetString(textTemp).Normalize(),
180 Timestamp = DateTime.UtcNow,
186 internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity)
189 clientAPI.Logger.VerboseDebug("TRADER Designator Invoked!");
191 //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
193 var traderJoe = entity as EntityTrader;
194 if (traderJoe == null) return;
196 var traderName = entity.GetBehavior<EntityBehaviorNameTag>( )?.DisplayName ?? @"?";
199 switch (entity.Code.Path) {
200 case "humanoid-trader-artisan":
201 code = "{0} the artisan";
203 case "humanoid-trader-treasurehunter":
204 code = "{0} the treasure hunter";
206 case "humanoid-trader-buildmaterials":
207 code = "{0} the building materials trader";
209 case "humanoid-trader-clothing":
210 code = "{0} the clothing merchant";
212 case "humanoid-trader-commodities":
213 code = "{0} the commodities merchant";
215 case "humanoid-trader-foods":
216 code = "{0} the foods supplier";
218 case "humanoid-trader-furniture":
219 code = "{0} the furniture trader";
221 case "humanoid-trader-luxuries":
222 code = "{0} the luxuries merchant";
224 case "humanoid-trader-survivalgoods":
225 code = "{0} the survival goods supplier";
231 var message = string.Format(code, traderName);
232 if (traderJoe.TradeProps != null) {
233 message += $" - Gears: {traderJoe.TradeProps.Money}, ";
235 poi.AddReplace(new EntityOfInterest {
237 PrettyLocation = posn.PrettyCoords(clientAPI),
238 Location = posn.Copy( ),
240 Timestamp = DateTime.UtcNow,
241 EntityId = entity.EntityId
245 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
248 clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
250 //Where to? and from!
252 BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
255 //FIXME: Delayed rescan ?
256 StringBuilder textTarget = new StringBuilder( );
258 textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
259 textTarget.Append(te.Activated ? "Online, " : "Offline, ");//Property hardcoded TRUE ?!
260 textTarget.Append(" Target: [ ");
261 textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?
262 textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
264 new PointOfInterest {
265 Name = "Translocator",
266 PrettyLocation = posn.PrettyCoords(clientAPI),
267 Location = posn.Copy( ),
268 Notes = textTarget.ToString( ),
269 Timestamp = DateTime.UtcNow,
270 Destination = te.TargetLocation != null ? new BlockPosJson(te.TargetLocation.Copy( )) : null
277 internal static void DecodeTeleport(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
280 clientAPI.Logger.VerboseDebug("Teleport Designator Invoked!");
284 BlockEntityTeleporter tele = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityTeleporter;
288 //TeleporterManager teleManager = clientAPI.ModLoader.GetModSystem<TeleporterManager>();
289 TeleporterLocation location = AccessTools.FieldRefAccess<BlockEntityTeleporter, TeleporterLocation>(tele, @"tpLocation");//TeleporterLocation tpLocation;
291 if (location != null)
293 StringBuilder textTarget = new StringBuilder( );
294 textTarget.Append(" Target: [ ");
295 textTarget.Append($" '{location.SourceName}' @ {location.SourcePos?.PrettyCoords(clientAPI)} -> '{location.TargetName}' @ {location.TargetPos?.PrettyCoords(clientAPI)} ");//Or ABS coords?
296 textTarget.Append(" ]");
298 new PointOfInterest {
300 PrettyLocation = posn.PrettyCoords(clientAPI),
301 Location = posn.Copy( ),
302 Notes = textTarget.ToString( ),
303 Timestamp = DateTime.UtcNow,
304 Destination = location.TargetPos != null ? new BlockPosJson(location.TargetPos.Copy( )) : null
311 internal static void NoteWildbeehive(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
314 clientAPI.Logger.VerboseDebug("Wild bee hive Designator Invoked!");
317 BlockEntityBeehive bees = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityBeehive;
320 EnumHivePopSize hiveSize = AccessTools.FieldRefAccess<BlockEntityBeehive, EnumHivePopSize>(bees, @"hivePopSize");
322 StringBuilder textTarget = new StringBuilder( );
323 textTarget.AppendLine($" Population: {(hiveSize != null? hiveSize.ToString() : "?")} ");
326 new PointOfInterest {
327 Name = "Wildbeehive",
328 PrettyLocation = posn.PrettyCoords(clientAPI),
329 Location = posn.Copy( ),
330 Notes = textTarget.ToString( ),
331 Timestamp = DateTime.UtcNow,
337 internal static void NotePineResinLeak(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
340 clientAPI.Logger.VerboseDebug("Resin leaking Pine tree Designator Invoked!");
342 //Note:Due to how Block-Entities are handled...only Harvested resin is tracked....
344 new PointOfInterest {
346 PrettyLocation = posn.PrettyCoords(clientAPI),
347 Location = posn.Copy( ),
348 Notes = String.Empty,
349 Timestamp = DateTime.UtcNow,