OSDN Git Service

indentation
[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                 internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
85                 {
86 #if DEBUG
87                         clientAPI.Logger.VerboseDebug("Sign Designator Invoked!");
88 #endif
89                         //sign Text into a POI field...
90                         BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign;
91
92                         if (signEntity != null && !String.IsNullOrEmpty(signEntity.text))
93                         {
94
95                                 poi.AddReplace(
96                                                         new PointOfInterest
97                                                         {
98                                                                 Location = posn.Copy(),
99                                                                 Notes = signEntity.text,
100                                                                 Timestamp = DateTimeOffset.UtcNow,
101                                                         }
102                                                         );
103
104                         }
105
106                 }
107
108
109                 internal static void DecodePostSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
110                 {
111 #if DEBUG
112                         clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!");
113 #endif
114                         //sign post Text into a POI field...
115                         BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost;
116
117                         if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0)
118                         {
119
120                                 poi.AddReplace(
121                                                         new PointOfInterest
122                                                         {
123                                                                 Location = posn.Copy(),
124                                                                 Notes = string.Join(",", signEntity.textByCardinalDirection),
125                                                                 Timestamp = DateTimeOffset.UtcNow,
126                                                         }
127                                                         );
128
129                         }
130                 }
131
132                 internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity)
133                 {
134                         clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
135
136                         var message = $"{entity.GetName()}";
137                         var traderJoe = entity as EntityTrader;
138                         if (traderJoe.TradeProps != null)
139                         {
140                                 message = $"{traderJoe.GetName()} Alive:{traderJoe.Alive} - Gears: {traderJoe.TradeProps.Money}, ";
141                         }
142                         poi.Upsert(entity, message);
143                 }
144
145                 internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
146                 {
147                         clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
148                         //Where to? and from!
149
150                         BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
151
152                         if (te != null)
153                         {
154
155                                 StringBuilder textTarget = new StringBuilder();
156                                 //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
157
158                                 textTarget.Append(te.Activated ? "Online " : "offline ");
159                                 textTarget.Append(" Dest.: ");
160                                 textTarget.Append(te.TargetLocation != null ? te.TargetLocation.PrettyCoords(clientAPI) : "???");//Or ABS coords?               
161
162                                 poi.AddReplace(
163                                                         new PointOfInterest
164                                                         {
165                                                                 Location = posn.Copy(),
166                                                                 Notes = textTarget.ToString(),
167                                                                 Timestamp = DateTimeOffset.UtcNow,
168                                                         }
169                                                         );
170
171                         }
172                 }
173         }
174 }
175