OSDN Git Service

added the name to traders so its easier to remember or something
[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                         var message = Lang.Get("tradingwindow-" + entity.Code.Path, traderName);
145                         if (traderJoe.TradeProps != null)
146                         {
147                                 message += $" - Gears: {traderJoe.TradeProps.Money}, ";
148                         }
149                         poi.AddReplace(new EntityOfInterest
150                         {
151                                 Name = "Trader",
152                                 PrettyLocation = posn.PrettyCoords(clientAPI),
153                                 Location = posn.Copy(),
154                                 Notes = message,
155                                 Timestamp = DateTime.UtcNow,
156                                 EntityId = entity.EntityId
157                         });
158                 }
159
160                 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
161                 {
162                 #if DEBUG
163                 clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
164                 #endif
165                         //Where to? and from!
166
167                         BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
168
169                         if (te != null)
170                         {
171                                 //FIXME: Delayed rescan ?
172                                 StringBuilder textTarget = new StringBuilder();
173                                 //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
174                                 textTarget.Append(te.FullyRepaired ? "Functional, " : "Broken, ");
175                                 textTarget.Append(te.Activated ? "Online, " : "Offline, ");
176                                 textTarget.Append(" Target: [ ");
177                                 textTarget.Append(te.TargetLocation != null ? "Set ]" : "Invalid ]");//Or ABS coords?           
178                                 textTarget.AppendFormat(", Range ({0} ~ {1})", te.MinTeleporterRangeInBlocks, te.MaxTeleporterRangeInBlocks);
179                                 poi.AddReplace(
180                                                         new PointOfInterest
181                                                         {
182                                                                 Name = "Translocator",
183                                                                 PrettyLocation = posn.PrettyCoords(clientAPI),
184                                                                 Location = posn.Copy(),
185                                                                 Notes = textTarget.ToString(),
186                                                                 Timestamp = DateTime.UtcNow,
187                                                                 Destination = te.TargetLocation != null ? new BlockPosJson(te.TargetLocation.Copy()) : null
188                                                         }
189                                                         );
190                         }
191                 }
192
193                 #endregion
194         }
195 }
196