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,
76 /// Not just blocks, but block-entities as well!
78 /// <returns>The block designators.</returns>
79 public static List<BlockDesignator> DefaultBlockDesignators
83 return new List<BlockDesignator>{
84 DefaultDesignators.Roads,
85 DefaultDesignators.GroundSigns,
86 DefaultDesignators.WallSigns,
87 DefaultDesignators.PostSigns,
88 DefaultDesignators.Translocators,
89 DefaultDesignators.Teleporters,
94 public static List<EntityDesignator> DefaultEntityDesignators
98 return new List<EntityDesignator>{
99 DefaultDesignators.Traders,
109 internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
112 clientAPI.Logger.VerboseDebug("Sign Designator Invoked!");
114 //sign Text into a POI field...
115 BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign;
117 if (signEntity != null && !String.IsNullOrEmpty(signEntity.text)) {
120 new PointOfInterest {
122 PrettyLocation = posn.PrettyCoords(clientAPI),
123 Location = posn.Copy( ),
124 Notes = signEntity.text,
125 Timestamp = DateTime.UtcNow,
132 internal static void DecodePostSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
135 clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!");
137 //sign post Text into a POI field...
138 BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost;
140 if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0) {
143 new PointOfInterest {
145 PrettyLocation = posn.PrettyCoords(clientAPI),
146 Location = posn.Copy( ),
147 Notes = string.Join(",", signEntity.textByCardinalDirection),
148 Timestamp = DateTime.UtcNow,
154 internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity)
156 //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
158 var traderJoe = entity as EntityTrader;
159 var traderName = entity.GetBehavior<EntityBehaviorNameTag>( )?.DisplayName;
162 switch (entity.Code.Path) {
163 case "humanoid-trader-artisan":
164 code = "{0} the artisan";
166 case "humanoid-trader-treasurehunter":
167 code = "{0} the treasure hunter";
169 case "humanoid-trader-buildmaterials":
170 code = "{0} the building materials trader";
172 case "humanoid-trader-clothing":
173 code = "{0} the clothing merchant";
175 case "humanoid-trader-commodities":
176 code = "{0} the commodities merchant";
178 case "humanoid-trader-foods":
179 code = "{0} the foods supplier";
181 case "humanoid-trader-furniture":
182 code = "{0} the furniture trader";
184 case "humanoid-trader-luxuries":
185 code = "{0} the luxuries merchant";
187 case "humanoid-trader-survivalgoods":
188 code = "{0} the survival goods supplier";
194 var message = string.Format(code, traderName);
195 if (traderJoe.TradeProps != null) {
196 message += $" - Gears: {traderJoe.TradeProps.Money}, ";
198 poi.AddReplace(new EntityOfInterest {
200 PrettyLocation = posn.PrettyCoords(clientAPI),
201 Location = posn.Copy( ),
203 Timestamp = DateTime.UtcNow,
204 EntityId = entity.EntityId
208 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
211 clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
213 //Where to? and from!
215 BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
218 //FIXME: Delayed rescan ?
219 StringBuilder textTarget = new StringBuilder( );
220 //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
221 textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
222 textTarget.Append(te.Activated ? "Online, " : "Offline, ");
223 textTarget.Append(" Target: [ ");
224 textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?
225 textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
227 new PointOfInterest {
228 Name = "Translocator",
229 PrettyLocation = posn.PrettyCoords(clientAPI),
230 Location = posn.Copy( ),
231 Notes = textTarget.ToString( ),
232 Timestamp = DateTime.UtcNow,
233 Destination = te.TargetLocation != null ? new BlockPosJson(te.TargetLocation.Copy( )) : null
240 internal static void DecodeTeleport(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
243 clientAPI.Logger.VerboseDebug("Teleport Designator Invoked!");
247 BlockEntityTeleporter tele = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityTeleporter;
251 //TeleporterManager teleManager = clientAPI.ModLoader.GetModSystem<TeleporterManager>();
252 TeleporterLocation location = AccessTools.FieldRefAccess<BlockEntityTeleporter, TeleporterLocation>(tele, @"tpLocation");//TeleporterLocation tpLocation;
254 if (location != null)
256 StringBuilder textTarget = new StringBuilder( );
257 textTarget.Append(" Target: [ ");
258 textTarget.Append($" '{location.SourceName}' @ {location.SourcePos?.PrettyCoords(clientAPI)} -> '{location.TargetName}' @ {location.TargetPos?.PrettyCoords(clientAPI)} ");//Or ABS coords?
259 textTarget.Append(" ]");
261 new PointOfInterest {
263 PrettyLocation = posn.PrettyCoords(clientAPI),
264 Location = posn.Copy( ),
265 Notes = textTarget.ToString( ),
266 Timestamp = DateTime.UtcNow,
267 Destination = location.TargetPos != null ? new BlockPosJson(location.TargetPos.Copy( )) : null