OSDN Git Service

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