OSDN Git Service

the previous way could return non english stuff, which is bad
[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.Config;
11 using Vintagestory.API.MathTools;
12 using Vintagestory.GameContent;
13
14 namespace Automap
15 {
16         public static class DefaultDesignators
17         {               
18                 public static BlockDesignator Roads =
19                          new BlockDesignator(
20                                 new AssetLocation("game", "stonepath"),
21                                 Color.Yellow,
22                                 EnumBlockMaterial.Gravel
23                         );
24
25                 public static BlockDesignator GroundSigns =
26                          new BlockDesignator(
27                                 new AssetLocation("game", "sign-ground"),
28                                 Color.Teal,
29                                 EnumBlockMaterial.Wood,
30                                 DecodeSign
31                         );
32
33                 public static BlockDesignator WallSigns =
34                          new BlockDesignator(
35                                 new AssetLocation("game", "sign-wall"),
36                                 Color.Teal,
37                                 EnumBlockMaterial.Wood,
38                                 DecodeSign
39                         );
40
41                 public static BlockDesignator PostSigns =
42                          new BlockDesignator(
43                                 new AssetLocation("game", "signpost"),
44                                 Color.Teal,
45                                 EnumBlockMaterial.Wood,
46                                 DecodePostSign
47                         );
48
49                 public static BlockDesignator Translocators =
50                          new BlockDesignator(
51                                 new AssetLocation("game", "statictranslocator-normal"),
52                                 Color.SteelBlue,
53                                 EnumBlockMaterial.Metal,
54                                 DecodeTranslocator
55                         );
56
57                 public static EntityDesignator Traders =
58                          new EntityDesignator(
59                                 new AssetLocation("game", "humanoid-trader"),
60                                 Color.LightGoldenrodYellow,
61                                 EnumEntityState.Active,
62                                 KeepTrackOfMerchant
63                         );
64
65                 /// <summary>
66                 /// Not just blocks, but block-entities as well!
67                 /// </summary>
68                 /// <returns>The block designators.</returns>
69                 public static List<BlockDesignator> DefaultBlockDesignators()
70                 {
71                         return new List<BlockDesignator>{
72                                 DefaultDesignators.Roads,
73                                 DefaultDesignators.GroundSigns,
74                                 DefaultDesignators.WallSigns,
75                                 DefaultDesignators.PostSigns,
76                                 DefaultDesignators.Translocators,
77                                 };
78                 }
79
80                 public static List<EntityDesignator> DefaultEntityDesignators()
81                 {
82                         return new List<EntityDesignator>{
83                                 DefaultDesignators.Traders,
84                 };
85                 }
86
87                 #region Designators
88
89                 internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
90                 {
91 #if DEBUG
92                         clientAPI.Logger.VerboseDebug("Sign Designator Invoked!");
93 #endif
94                         //sign Text into a POI field...
95                         BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign;
96
97                         if (signEntity != null && !String.IsNullOrEmpty(signEntity.text))
98                         {
99
100                                 poi.AddReplace(
101                                                         new PointOfInterest
102                                                         {
103                                                                 Name = "Sign",
104                                                                 PrettyLocation = posn.PrettyCoords(clientAPI),
105                                                                 Location = posn.Copy(),
106                                                                 Notes = signEntity.text,
107                                                                 Timestamp = DateTime.UtcNow,
108                                                         }
109                                                         );
110                         }
111                 }
112
113
114                 internal static void DecodePostSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
115                 {
116 #if DEBUG
117                         clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!");
118 #endif
119                         //sign post Text into a POI field...
120                         BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost;
121
122                         if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0)
123                         {
124
125                                 poi.AddReplace(
126                                                         new PointOfInterest
127                                                         {
128                                                                 Name = "Signpost",
129                                                                 PrettyLocation = posn.PrettyCoords(clientAPI),
130                                                                 Location = posn.Copy(),
131                                                                 Notes = string.Join(",", signEntity.textByCardinalDirection),
132                                                                 Timestamp = DateTime.UtcNow,
133                                                         }
134                                                         );
135                         }
136                 }
137
138                 internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity)
139                 {
140                         //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
141
142                         var traderJoe = entity as EntityTrader;
143                         var traderName = entity.GetBehavior<EntityBehaviorNameTag>()?.DisplayName;
144                         string code;
145                         // this makes me ill
146                         switch (entity.Code.Path) {
147                                 case "humanoid-trader-artisan":
148                                         code = "{0} the artisan";
149                                         break;
150                                 case "humanoid-trader-treasurehunter":
151                                         code = "{0} the treasure hunter";
152                                         break;
153                                 case "humanoid-trader-buildmaterials":
154                                         code = "{0} the building materials trader";
155                                         break;
156                                 case "humanoid-trader-clothing":
157                                         code = "{0} the clothing merchant";
158                                         break;
159                                 case "humanoid-trader-commodities":
160                                         code = "{0} the commodities merchant";
161                                         break;
162                                 case "humanoid-trader-foods":
163                                         code = "{0} the foods supplier";
164                                         break;
165                                 case "humanoid-trader-furniture":
166                                         code = "{0} the furniture trader";
167                                         break;
168                                 case "humanoid-trader-luxuries":
169                                         code = "{0} the luxuries merchant";
170                                         break;
171                                 case "humanoid-trader-survivalgoods":
172                                         code = "{0} the survival goods supplier";
173                                         break;
174                                 default:
175                                         code = "";
176                                         break;
177                         }
178                         var message = string.Format(code, traderName);
179                         if (traderJoe.TradeProps != null)
180                         {
181                                 message += $" - Gears: {traderJoe.TradeProps.Money}, ";
182                         }
183                         poi.AddReplace(new EntityOfInterest
184                         {
185                                 Name = "Trader",
186                                 PrettyLocation = posn.PrettyCoords(clientAPI),
187                                 Location = posn.Copy(),
188                                 Notes = message,
189                                 Timestamp = DateTime.UtcNow,
190                                 EntityId = entity.EntityId
191                         });
192                 }
193
194                 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
195                 {
196                 #if DEBUG
197                 clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
198                 #endif
199                         //Where to? and from!
200
201                         BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
202
203                         if (te != null)
204                         {
205                                 //FIXME: Delayed rescan ?
206                                 StringBuilder textTarget = new StringBuilder();
207                                 //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
208                                 textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
209                                 textTarget.Append(te.Activated ? "Online, " : "Offline, ");
210                                 textTarget.Append(" Target: [ ");
211                                 textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?           
212                                 textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
213                                 poi.AddReplace(
214                                                         new PointOfInterest
215                                                         {
216                                                                 Name = "Translocator",
217                                                                 PrettyLocation = posn.PrettyCoords(clientAPI),
218                                                                 Location = posn.Copy(),
219                                                                 Notes = textTarget.ToString(),
220                                                                 Timestamp = DateTime.UtcNow,
221                                                                 Destination = te.TargetLocation != null ? new BlockPosJson(te.TargetLocation.Copy()) : null
222                                                         }
223                                                         );
224                         }
225                 }
226
227                 #endregion
228         }
229 }
230