OSDN Git Service

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