2 using System.Collections.Generic;
5 using System.Text.RegularExpressions;
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;
16 public static class DefaultDesignators
20 public static BlockDesignator Roads =
22 new AssetLocation("game", "stonepath"),
24 EnumBlockMaterial.Gravel
27 public static BlockDesignator GroundSigns =
29 new AssetLocation("game", "sign-ground"),
31 EnumBlockMaterial.Wood,
35 public static BlockDesignator WallSigns =
37 new AssetLocation("game", "sign-wall"),
39 EnumBlockMaterial.Wood,
43 public static BlockDesignator PostSigns =
45 new AssetLocation("game", "signpost"),
47 EnumBlockMaterial.Wood,
51 public static BlockDesignator Translocators =
53 new AssetLocation("game", "statictranslocator-normal"),
55 EnumBlockMaterial.Metal,
59 public static BlockDesignator Teleporters =
61 new AssetLocation("game", "teleporterbase"),
63 EnumBlockMaterial.Wood,
67 public static EntityDesignator Traders =
69 new AssetLocation("game", "humanoid-trader"),
70 Color.LightGoldenrodYellow,
71 EnumEntityState.Active,
75 public static BlockDesignator Wildbeehives =
77 new AssetLocation("game", "wildbeehive"),
79 EnumBlockMaterial.Other,
84 /// Not just blocks, but block-entities as well!
86 /// <returns>The block designators.</returns>
87 public static List<BlockDesignator> DefaultBlockDesignators
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,
103 public static List<EntityDesignator> DefaultEntityDesignators
107 return new List<EntityDesignator>{
108 DefaultDesignators.Traders,
118 internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
121 clientAPI.Logger.VerboseDebug("Sign Designator Invoked!");
123 //sign Text into a POI field...
124 BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign;
126 if (signEntity != null && !String.IsNullOrEmpty(signEntity.text)) {
129 new PointOfInterest {
131 PrettyLocation = posn.PrettyCoords(clientAPI),
132 Location = posn.Copy( ),
133 Notes = signEntity.text,
134 Timestamp = DateTime.UtcNow,
141 internal static void DecodePostSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
144 clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!");
146 //sign post Text into a POI field...
147 BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost;
149 if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0) {
152 new PointOfInterest {
154 PrettyLocation = posn.PrettyCoords(clientAPI),
155 Location = posn.Copy( ),
156 Notes = string.Join(",", signEntity.textByCardinalDirection),
157 Timestamp = DateTime.UtcNow,
163 internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity)
165 //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
167 var traderJoe = entity as EntityTrader;
168 var traderName = entity.GetBehavior<EntityBehaviorNameTag>( )?.DisplayName;
171 switch (entity.Code.Path) {
172 case "humanoid-trader-artisan":
173 code = "{0} the artisan";
175 case "humanoid-trader-treasurehunter":
176 code = "{0} the treasure hunter";
178 case "humanoid-trader-buildmaterials":
179 code = "{0} the building materials trader";
181 case "humanoid-trader-clothing":
182 code = "{0} the clothing merchant";
184 case "humanoid-trader-commodities":
185 code = "{0} the commodities merchant";
187 case "humanoid-trader-foods":
188 code = "{0} the foods supplier";
190 case "humanoid-trader-furniture":
191 code = "{0} the furniture trader";
193 case "humanoid-trader-luxuries":
194 code = "{0} the luxuries merchant";
196 case "humanoid-trader-survivalgoods":
197 code = "{0} the survival goods supplier";
203 var message = string.Format(code, traderName);
204 if (traderJoe.TradeProps != null) {
205 message += $" - Gears: {traderJoe.TradeProps.Money}, ";
207 poi.AddReplace(new EntityOfInterest {
209 PrettyLocation = posn.PrettyCoords(clientAPI),
210 Location = posn.Copy( ),
212 Timestamp = DateTime.UtcNow,
213 EntityId = entity.EntityId
217 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
220 clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
222 //Where to? and from!
224 BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
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);
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
249 internal static void DecodeTeleport(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
252 clientAPI.Logger.VerboseDebug("Teleport Designator Invoked!");
256 BlockEntityTeleporter tele = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityTeleporter;
260 //TeleporterManager teleManager = clientAPI.ModLoader.GetModSystem<TeleporterManager>();
261 TeleporterLocation location = AccessTools.FieldRefAccess<BlockEntityTeleporter, TeleporterLocation>(tele, @"tpLocation");//TeleporterLocation tpLocation;
263 if (location != null)
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(" ]");
270 new PointOfInterest {
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
283 internal static void NoteWildbeehive(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
286 clientAPI.Logger.VerboseDebug("Wild bee hive Designator Invoked!");
289 BlockEntityBeehive bees = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityBeehive;
292 EnumHivePopSize hiveSize = AccessTools.FieldRefAccess<BlockEntityBeehive, EnumHivePopSize>(bees, @"hivePopSize");//TeleporterLocation tpLocation;
294 StringBuilder textTarget = new StringBuilder( );
295 textTarget.AppendLine($" Population: {(hiveSize != null? hiveSize.ToString() : "?")} ");
298 new PointOfInterest {
299 Name = "Wildbeehive",
300 PrettyLocation = posn.PrettyCoords(clientAPI),
301 Location = posn.Copy( ),
302 Notes = textTarget.ToString( ),
303 Timestamp = DateTime.UtcNow,