OSDN Git Service

Altered TSV encoding to use special ASCII
[automap/automap.git] / Automap / Designators / DefaultDesignators.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Drawing;
4 using System.Text;
5 using System.Text.RegularExpressions;
6
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;
12
13 namespace Automap
14 {
15         public static class DefaultDesignators
16         {               
17                 public static BlockDesignator Roads =
18                          new BlockDesignator(
19                                 new AssetLocation("game", "stonepath"),
20                                 Color.Yellow,
21                                 EnumBlockMaterial.Gravel
22                         );
23
24                 public static BlockDesignator GroundSigns =
25                          new BlockDesignator(
26                                 new AssetLocation("game", "sign-ground"),
27                                 Color.Teal,
28                                 EnumBlockMaterial.Wood,
29                                 DecodeSign
30                         );
31
32                 public static BlockDesignator WallSigns =
33                          new BlockDesignator(
34                                 new AssetLocation("game", "sign-wall"),
35                                 Color.Teal,
36                                 EnumBlockMaterial.Wood,
37                                 DecodeSign
38                         );
39
40                 public static BlockDesignator PostSigns =
41                          new BlockDesignator(
42                                 new AssetLocation("game", "signpost"),
43                                 Color.Teal,
44                                 EnumBlockMaterial.Wood,
45                                 DecodePostSign
46                         );
47
48                 public static BlockDesignator Translocators =
49                          new BlockDesignator(
50                                 new AssetLocation("game", "statictranslocator-normal"),
51                                 Color.SteelBlue,
52                                 EnumBlockMaterial.Metal,
53                                 DecodeTranslocator
54                         );
55
56                 public static EntityDesignator Traders =
57                          new EntityDesignator(
58                                 new AssetLocation("game", "humanoid-trader"),
59                                 Color.LightGoldenrodYellow,
60                                 EnumEntityState.Active,
61                                 KeepTrackOfMerchant
62                         );
63
64                 /// <summary>
65                 /// Not just blocks, but block-entities as well!
66                 /// </summary>
67                 /// <returns>The block designators.</returns>
68                 public static List<BlockDesignator> DefaultBlockDesignators()
69                 {
70                         return new List<BlockDesignator>{
71                                 DefaultDesignators.Roads,
72                                 DefaultDesignators.GroundSigns,
73                                 DefaultDesignators.WallSigns,
74                                 DefaultDesignators.PostSigns,
75                                 DefaultDesignators.Translocators,
76                                 };
77                 }
78
79                 public static List<EntityDesignator> DefaultEntityDesignators()
80                 {
81                         return new List<EntityDesignator>{
82                                 DefaultDesignators.Traders,
83                 };
84                 }
85
86                 #region Designators
87
88                 internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
89                 {
90 #if DEBUG
91                         clientAPI.Logger.VerboseDebug("Sign Designator Invoked!");
92 #endif
93                         //sign Text into a POI field...
94                         BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign;
95
96                         if (signEntity != null && !String.IsNullOrEmpty(signEntity.text))
97                         {
98
99                                 poi.AddReplace(
100                                                         new PointOfInterest
101                                                         {
102                                                                 Name = "Sign",
103                                                                 PrettyLocation = posn.PrettyCoords(clientAPI),
104                                                                 Location = posn.Copy(),
105                                                                 Notes = signEntity.text,
106                                                                 Timestamp = DateTime.UtcNow,
107                                                         }
108                                                         );
109                         }
110                 }
111
112
113                 internal static void DecodePostSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
114                 {
115 #if DEBUG
116                         clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!");
117 #endif
118                         //sign post Text into a POI field...
119                         BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost;
120
121                         if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0)
122                         {
123
124                                 poi.AddReplace(
125                                                         new PointOfInterest
126                                                         {
127                                                                 Name = "Signpost",
128                                                                 PrettyLocation = posn.PrettyCoords(clientAPI),
129                                                                 Location = posn.Copy(),
130                                                                 Notes = string.Join(",", signEntity.textByCardinalDirection),
131                                                                 Timestamp = DateTime.UtcNow,
132                                                         }
133                                                         );
134                         }
135                 }
136
137                 internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity)
138                 {
139                         //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
140
141                         var traderJoe = entity as EntityTrader;
142                         var message = $"{entity.GetName()} Alive: {traderJoe.Alive}";
143                         if (traderJoe.TradeProps != null)
144                         {
145                                 message += $" - Gears: {traderJoe.TradeProps.Money}, ";
146                         }
147                         poi.AddReplace(new EntityOfInterest
148                         {
149                                 Name = "Trader",
150                                 PrettyLocation = posn.PrettyCoords(clientAPI),
151                                 Location = posn.Copy(),
152                                 Notes = message,
153                                 Timestamp = DateTime.UtcNow,
154                                 EntityId = entity.EntityId
155                         });
156                 }
157
158                 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
159                 {
160                 #if DEBUG
161                 clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
162                 #endif
163                         //Where to? and from!
164
165                         BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
166
167                         if (te != null)
168                         {
169                                 //FIXME: Delayed rescan ?
170                                 StringBuilder textTarget = new StringBuilder();
171                                 //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
172                                 textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
173                                 textTarget.Append(te.Activated ? "Online, " : "Offline, ");
174                                 textTarget.Append(" Target: [ ");
175                                 textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?           
176                                 textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
177                                 poi.AddReplace(
178                                                         new PointOfInterest
179                                                         {
180                                                                 Name = "Translocator",
181                                                                 PrettyLocation = posn.PrettyCoords(clientAPI),
182                                                                 Location = posn.Copy(),
183                                                                 Notes = textTarget.ToString(),
184                                                                 Timestamp = DateTime.UtcNow,
185                                                                 Destination = te.TargetLocation != null ? new BlockPosJson(te.TargetLocation.Copy()) : null
186                                                         }
187                                                         );
188                         }
189                 }
190
191                 #endregion
192         }
193 }
194