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.MathTools;
11 using Vintagestory.GameContent;
15 public static class DefaultDesignators
17 private static Regex stripControlChars = new Regex(@"\s", RegexOptions.Multiline);
19 public static BlockDesignator Roads =
21 new AssetLocation("game", "stonepath"),
23 EnumBlockMaterial.Gravel
26 public static BlockDesignator GroundSigns =
28 new AssetLocation("game", "sign-ground"),
30 EnumBlockMaterial.Wood,
34 public static BlockDesignator WallSigns =
36 new AssetLocation("game", "sign-wall"),
38 EnumBlockMaterial.Wood,
42 public static BlockDesignator PostSigns =
44 new AssetLocation("game", "signpost"),
46 EnumBlockMaterial.Wood,
50 public static BlockDesignator Translocators =
52 new AssetLocation("game", "statictranslocator-normal"),
54 EnumBlockMaterial.Metal,
58 public static EntityDesignator Traders =
60 new AssetLocation("game", "humanoid-trader"),
61 Color.LightGoldenrodYellow,
62 EnumEntityState.Active,
67 /// Not just blocks, but block-entities as well!
69 /// <returns>The block designators.</returns>
70 public static List<BlockDesignator> DefaultBlockDesignators()
72 return new List<BlockDesignator>{
73 DefaultDesignators.Roads,
74 DefaultDesignators.GroundSigns,
75 DefaultDesignators.WallSigns,
76 DefaultDesignators.PostSigns,
77 DefaultDesignators.Translocators,
81 public static List<EntityDesignator> DefaultEntityDesignators()
83 return new List<EntityDesignator>{
84 DefaultDesignators.Traders,
90 internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
93 clientAPI.Logger.VerboseDebug("Sign Designator Invoked!");
95 //sign Text into a POI field...
96 BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign;
98 if (signEntity != null && !String.IsNullOrEmpty(signEntity.text))
105 PrettyLocation = posn.PrettyCoords(clientAPI),
106 Location = posn.Copy(),
107 Notes = stripControlChars.Replace(signEntity.text, " "),
108 Timestamp = DateTime.UtcNow,
117 internal static void DecodePostSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
120 clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!");
122 //sign post Text into a POI field...
123 BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost;
125 if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0)
132 PrettyLocation = posn.PrettyCoords(clientAPI),
133 Location = posn.Copy(),
134 Notes = stripControlChars.Replace(string.Join(",", signEntity.textByCardinalDirection), " "),
135 Timestamp = DateTime.UtcNow,
142 internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity)
144 //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
146 var traderJoe = entity as EntityTrader;
147 var message = $"{entity.GetName()} Alive: {traderJoe.Alive}";
148 if (traderJoe.TradeProps != null)
150 message += $" - Gears: {traderJoe.TradeProps.Money}, ";
152 poi.AddReplace(new EntityOfInterest
155 PrettyLocation = posn.PrettyCoords(clientAPI),
156 Location = posn.Copy(),
158 Timestamp = DateTime.UtcNow,
159 EntityId = entity.EntityId
163 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
166 clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
168 //Where to? and from!
170 BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
174 //FIXME: Delayed rescan ?
175 StringBuilder textTarget = new StringBuilder();
176 //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
177 textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
178 textTarget.Append(te.Activated ? "Online, " : "Offline, ");
179 textTarget.Append(" Target: [ ");
180 textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?
181 textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
185 Name = "Translocator",
186 PrettyLocation = posn.PrettyCoords(clientAPI),
187 Location = posn.Copy(),
188 Notes = textTarget.ToString(),
189 Timestamp = DateTime.UtcNow,
190 Destination = te.TargetLocation != null ? new BlockPosJson(te.TargetLocation.Copy()) : null