OSDN Git Service

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