OSDN Git Service

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