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?.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)
188 //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
190 var traderJoe = entity as EntityTrader;
191 var traderName = entity.GetBehavior<EntityBehaviorNameTag>( )?.DisplayName;
194 switch (entity.Code.Path) {
195 case "humanoid-trader-artisan":
196 code = "{0} the artisan";
198 case "humanoid-trader-treasurehunter":
199 code = "{0} the treasure hunter";
201 case "humanoid-trader-buildmaterials":
202 code = "{0} the building materials trader";
204 case "humanoid-trader-clothing":
205 code = "{0} the clothing merchant";
207 case "humanoid-trader-commodities":
208 code = "{0} the commodities merchant";
210 case "humanoid-trader-foods":
211 code = "{0} the foods supplier";
213 case "humanoid-trader-furniture":
214 code = "{0} the furniture trader";
216 case "humanoid-trader-luxuries":
217 code = "{0} the luxuries merchant";
219 case "humanoid-trader-survivalgoods":
220 code = "{0} the survival goods supplier";
226 var message = string.Format(code, traderName);
227 if (traderJoe.TradeProps != null) {
228 message += $" - Gears: {traderJoe.TradeProps.Money}, ";
230 poi.AddReplace(new EntityOfInterest {
232 PrettyLocation = posn.PrettyCoords(clientAPI),
233 Location = posn.Copy( ),
235 Timestamp = DateTime.UtcNow,
236 EntityId = entity.EntityId
240 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
243 clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
245 //Where to? and from!
247 BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
250 //FIXME: Delayed rescan ?
251 StringBuilder textTarget = new StringBuilder( );
253 textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
254 textTarget.Append(te.Activated ? "Online, " : "Offline, ");//Property hardcoded TRUE ?!
255 textTarget.Append(" Target: [ ");
256 textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?
257 textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
259 new PointOfInterest {
260 Name = "Translocator",
261 PrettyLocation = posn.PrettyCoords(clientAPI),
262 Location = posn.Copy( ),
263 Notes = textTarget.ToString( ),
264 Timestamp = DateTime.UtcNow,
265 Destination = te.TargetLocation != null ? new BlockPosJson(te.TargetLocation.Copy( )) : null
272 internal static void DecodeTeleport(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
275 clientAPI.Logger.VerboseDebug("Teleport Designator Invoked!");
279 BlockEntityTeleporter tele = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityTeleporter;
283 //TeleporterManager teleManager = clientAPI.ModLoader.GetModSystem<TeleporterManager>();
284 TeleporterLocation location = AccessTools.FieldRefAccess<BlockEntityTeleporter, TeleporterLocation>(tele, @"tpLocation");//TeleporterLocation tpLocation;
286 if (location != null)
288 StringBuilder textTarget = new StringBuilder( );
289 textTarget.Append(" Target: [ ");
290 textTarget.Append($" '{location.SourceName}' @ {location.SourcePos?.PrettyCoords(clientAPI)} -> '{location.TargetName}' @ {location.TargetPos?.PrettyCoords(clientAPI)} ");//Or ABS coords?
291 textTarget.Append(" ]");
293 new PointOfInterest {
295 PrettyLocation = posn.PrettyCoords(clientAPI),
296 Location = posn.Copy( ),
297 Notes = textTarget.ToString( ),
298 Timestamp = DateTime.UtcNow,
299 Destination = location.TargetPos != null ? new BlockPosJson(location.TargetPos.Copy( )) : null
306 internal static void NoteWildbeehive(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
309 clientAPI.Logger.VerboseDebug("Wild bee hive Designator Invoked!");
312 BlockEntityBeehive bees = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityBeehive;
315 EnumHivePopSize hiveSize = AccessTools.FieldRefAccess<BlockEntityBeehive, EnumHivePopSize>(bees, @"hivePopSize");
317 StringBuilder textTarget = new StringBuilder( );
318 textTarget.AppendLine($" Population: {(hiveSize != null? hiveSize.ToString() : "?")} ");
321 new PointOfInterest {
322 Name = "Wildbeehive",
323 PrettyLocation = posn.PrettyCoords(clientAPI),
324 Location = posn.Copy( ),
325 Notes = textTarget.ToString( ),
326 Timestamp = DateTime.UtcNow,
332 internal static void NotePineResinLeak(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
335 clientAPI.Logger.VerboseDebug("Resin leaking Pine tree Designator Invoked!");
337 //Note:Due to how Block-Entities are handled...only Harvested resin is tracked....
339 new PointOfInterest {
341 PrettyLocation = posn.PrettyCoords(clientAPI),
342 Location = posn.Copy( ),
343 Notes = String.Empty,
344 Timestamp = DateTime.UtcNow,