download uoamVendors.cs
Language: C#
LOC: 300
Project Info
SunUO
Server: BerliOS (SVN)
Type: svn
...\trunk\scripts\legacy\Misc\
   Animations.cs
   AOS.cs
   AttackMessage.cs
   AutoRestart.cs
   AutoSave.cs
   Broadcasts.cs
   CharacterCreation.cs
   Cleanup.cs
   ClientVerification.cs
   CrashGuard.cs
   DataPath.cs
   DispellableAttribute.cs
   ...llableFieldAttribute.cs
   DoorGenerator.cs
   Email.cs
   Fastwalk.cs
   FindByName.cs
   FindRunes.cs
   FoodDecay.cs
   Guild.cs
   HardwareInfo.cs
   InhumanSpeech.cs
   Keywords.cs
   LightCycle.cs
   LoginStats.cs
   Loot.cs
   LootPack.cs
   MapDefinitions.cs
   NameList.cs
   NameVerification.cs
   Notoriety.cs
   OreInfo.cs
   Paperdoll.cs
   Poison.cs
   ProfanityProtection.cs
   Profile.cs
   ProtocolExtensions.cs
   RegenRates.cs
   RenameRequests.cs
   SE.cs
   ServerList.cs
   ShardPoller.cs
   ShrinkTable.cs
   SkillCheck.cs
   SocketOptions.cs
   TextDefinition.cs
   Titles.cs
   TreasureMapProtection.cs
   uoamVendors.cs
   VendorGenerator.cs
   Weather.cs
   WeightOverloading.cs
   WelcomeTimer.cs
   ZLib.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
using System;
using System.Collections;
using System.IO;
using Server.Mobiles;
using Server.Items;

// Version 0.8

namespace Server
{
	public class UOAMVendorGenerator
	{
		private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

		private static int m_Count;

		//configuration
		private const int NPCCount = 2;//2 npcs per type (so a mage spawner will spawn 2 npcs, a alchemist and herbalist spawner will spawn 4 npcs total)
		private const int HomeRange = 5;//How far should they wander?
		private const bool TotalRespawn = true;//Should we spawn them up right away?
		private static TimeSpan MinTime = TimeSpan.FromMinutes( 2.5 );//min spawn time
		private static TimeSpan MaxTime = TimeSpan.FromMinutes( 10.0 );//max spawn time
		private const int Team = 0;//"team" the npcs are on

		public static void Initialize()
		{
			Commands.Register( "UOAMVendors", AccessLevel.Administrator, new CommandEventHandler( Generate_OnCommand ) );
		}

		[Usage( "UOAMVendors" )]
		[Description( "Generates vendor spawners from Data/Common.MAP (taken from UOAutoMap)" )]
		private static void Generate_OnCommand( CommandEventArgs e )
		{
			Parse( e.Mobile );
		}

		public static void Parse( Mobile from )
		{
			string vendor_path = Path.Combine(Core.Config.ConfigDirectory, "Common.map");
			m_Count = 0;

			if ( File.Exists( vendor_path ) )
			{
				from.SendMessage( "Generating Vendors..." );

				using ( StreamReader ip = new StreamReader( vendor_path ) )
				{
					string line;

					while ( (line = ip.ReadLine()) != null )
					{
						int indexOf = line.IndexOf( ':' );

						if ( indexOf == -1 )
							continue;

						string type = line.Substring( 0, ++indexOf ).Trim();
						string sub = line.Substring( indexOf ).Trim();

						string[] split = sub.Split( ' ' );

						if ( split.Length < 3 )
							continue;

						split = new string[]{ type, split[0], split[1], split[2] };

						switch(split[0].ToLower()) 
						{
							case "-healer:":
								PlaceNPC( split[1], split[2], split[3], "Healer", "HealerGuildmaster" );
								break;
							case "-baker:":
								PlaceNPC( split[1], split[2], split[3], "Baker" );
								break;
							case "-gypsymaiden:":
								PlaceNPC( split[1], split[2], split[3], "GypsyMaiden" );
								break;
							case "-gypsybank:":
								PlaceNPC( split[1], split[2], split[3], "GypsyBanker" );
								break;
							case "-bank:":
								PlaceNPC( split[1], split[2], split[3], "Banker", "Minter" );
								break;
							case "-inn:":
								PlaceNPC( split[1], split[2], split[3], "Innkeeper" );
								break;
							case "-provisioner:":
								PlaceNPC( split[1], split[2], split[3], "Provisioner", "Cobbler" );
								break;
							case "-tailor:":
								PlaceNPC( split[1], split[2], split[3], "Tailor", "Weaver", "TailorGuildmaster" );
								break;
							case "-tavern:":
								PlaceNPC( split[1], split[2], split[3], "Tavernkeeper", "Waiter", "Cook", "Barkeeper" );
								break;
							case "-reagents:":
								PlaceNPC( split[1], split[2], split[3], "Herbalist", "Alchemist", "CustomHairstylist" );
								break;
							case "-fortuneteller:":
								PlaceNPC( split[1], split[2], split[3], "FortuneTeller" );
								break;
							case "-holymage:":
								PlaceNPC( split[1], split[2], split[3], "HolyMage" );
								break;
							case "-chivalrykeeper:":
								PlaceNPC( split[1], split[2], split[3], "KeeperOfChivalry" );
								break;
							case "-mage:":
								PlaceNPC( split[1], split[2], split[3], "Mage", "Alchemist", "MageGuildmaster" );
								break;
							case "-arms:":
								PlaceNPC( split[1], split[2], split[3], "Armorer", "Weaponsmith" );
								break;
							case "-tinker:":
								PlaceNPC( split[1], split[2], split[3], "Tinker", "TinkerGuildmaster" );
								break;
							case "-gypsystable:":
								PlaceNPC( split[1], split[2], split[3], "GypsyAnimalTrainer" );
								break;
							case "-stable:":
								PlaceNPC( split[1], split[2], split[3], "AnimalTrainer" );
								break;
							case "-blacksmith:":
								PlaceNPC( split[1], split[2], split[3], "Blacksmith", "BlacksmithGuildmaster" );
								break;
							case "-bowyer:":
							case "-fletcher:":
								PlaceNPC( split[1], split[2], split[3], "Bowyer" );
								break;
							case "-carpenter:":
								PlaceNPC( split[1], split[2], split[3], "Carpenter", "Architect", "RealEstateBroker" );
								break;
							case "-butcher:":
								PlaceNPC( split[1], split[2], split[3], "Butcher" );
								break;
							case "-jeweler:":
								PlaceNPC( split[1], split[2], split[3], "Jeweler" );
								break;
							case "-tanner:":
								PlaceNPC( split[1], split[2], split[3], "Tanner", "Furtrader" );
								break;
							case "-bard:":
								PlaceNPC( split[1], split[2], split[3], "Bard", "BardGuildmaster" );
								break;
							case "-market:":
								PlaceNPC( split[1], split[2], split[3], "Butcher", "Farmer" );
								break;
							case "-library:":
								PlaceNPC( split[1], split[2], split[3], "Scribe" );
								break;
							case "-shipwright:":
								PlaceNPC( split[1], split[2], split[3], "Shipwright", "Mapmaker" );
								break;
							case "-docks:":
								PlaceNPC( split[1], split[2], split[3], "Fisherman" );
								break;

							case "-beekeeper:":
								PlaceNPC( split[1], split[2], split[3], "Beekeeper" );
								break;
							
							
								// Guilds & Misc
							case "-tinkers guild:":
								PlaceNPC( split[1], split[2], split[3], "TinkerGuildmaster" );
								break;
							case "-blacksmiths guild:":
								PlaceNPC( split[1], split[2], split[3], "BlacksmithGuildmaster" );
								break;
							case "-sorcerors guild:":
								PlaceNPC( split[1], split[2], split[3], "MageGuildmaster" );
								break;
							case "-customs:": break;
							case "-painter:": break;
							case "-theater:": break;
							case "-warriors guild:":
								PlaceNPC( split[1], split[2], split[3], "WarriorGuildmaster" );
								break;
							case "-archers guild:":
								PlaceNPC( split[1], split[2], split[3], "RangerGuildmaster" );
								break;
							case "-thieves guild:":
								PlaceNPC( split[1], split[2], split[3], "ThiefGuildmaster" );
								break;
							case "-miners guild:":
								PlaceNPC( split[1], split[2], split[3], "MinerGuildmaster" );
								break;
							case "-fishermans guild:":
								PlaceNPC( split[1], split[2], split[3], "FisherGuildmaster" );
								break;
							case "-merchants guild:":
								PlaceNPC( split[1], split[2], split[3], "MerchantGuildmaster" );
								break;
							case "-illusionists guild:": break;
							case "-armourers guild:": break;
							case "-sorcerers guild:": break;
							case "-mages guild:":
								PlaceNPC( split[1], split[2], split[3], "MageGuildmaster" );
								break;
							case "-weapons guild:": break;
							case "-bardic guild:":
								PlaceNPC( split[1], split[2], split[3], "BardGuildmaster" );
								break;
							case "-rogues guild:":
								break;

								// Skip
							case "+landmark:":
							case "-point of interest:":
							case "+shrine:":
							case "+moongate:":
							case "+dungeon:":
							case "+scenic:":
							case "-gate:":
							case "+Body of Water:":
							case "+ruins:":
							case "+teleporter:":
							case "+Terrain:":
							case "-exit:":
							case "-bridge:":
							case "-other:":
							case "+champion:":
							case "-stairs:":
							case "-guild:":
							case "+graveyard:":
							case "+Island:":
							case "+town:":
								break;
							/*default:
								Console.WriteLine(split[0]);
								break;*/
						}
					}
				}
				from.SendMessage( "Done, added {0} spawners",m_Count );
			}
			else
			{
				from.SendMessage( "{0} not found!", vendor_path );
			}
		}

		public static void PlaceNPC( string sx, string sy, string sm, params string[] types )
		{
			if ( types.Length == 0 )
				return;

			int x = Utility.ToInt32( sx );
			int y = Utility.ToInt32( sy );
			int map = Utility.ToInt32( sm );

			switch ( map )
			{
				case 0://Trammel and Felucca
					MakeSpawner( types, x, y, Map.Felucca );
					MakeSpawner( types, x, y, Map.Trammel );
					break;
				case 1://Felucca
					MakeSpawner( types, x, y, Map.Felucca );
					break;
				case 2:
					MakeSpawner( types, x, y, Map.Trammel );
					break;
				case 3:
					MakeSpawner( types, x, y, Map.Ilshenar );
					break;
				case 4:
					MakeSpawner( types, x, y, Map.Malas );
					break;
				default:
					log.WarnFormat("UOAM Vendor Parser: unknown map {0}", map);
					break;
			}
		}

		public static int GetSpawnerZ( int x, int y, Map map )
		{
			int z = map.GetAverageZ( x, y );

			if ( map.CanFit( x, y, z, 16, false, false ) )
				return z;

			for ( int i = 1; i <= 20; ++i )
			{
				if ( map.CanFit( x, y, z + i, 16, false, false ) )
					return z + i;

				if ( map.CanFit( x, y, z - i, 16, false, false ) )
					return z - i;
			}

			return z;
		}

		private static Queue m_ToDelete = new Queue();

		public static void ClearSpawners( int x, int y, int z, Map map )
		{
			IPooledEnumerable eable = map.GetItemsInRange( new Point3D( x, y, z ), 0 );

			foreach ( Item item in eable )
			{
				if ( item is Spawner && item.Z == z )
					m_ToDelete.Enqueue( item );
			}

			eable.Free();

			while ( m_ToDelete.Count > 0 )
				((Item)m_ToDelete.Dequeue()).Delete();
		}

		private static void MakeSpawner( string[] types, int x, int y, Map map )
		{
			if ( types.Length == 0 )
				return;

			int z = GetSpawnerZ( x, y, map );

			ClearSpawners( x, y, z, map );

			for ( int i = 0; i < types.Length; ++i )
			{
				bool isGuildmaster = ( types[i].EndsWith( "Guildmaster" ) );

				Spawner sp = new Spawner( types[i] );

				if ( isGuildmaster )
					sp.Count = 1;
				else
					sp.Count = NPCCount;

				sp.MinDelay = MinTime;
				sp.MaxDelay = MaxTime;
				sp.Team = Team;
				sp.HomeRange = HomeRange;

				sp.MoveToWorld( new Point3D( x, y, z ), map );

				if ( TotalRespawn )
				{
					sp.Respawn();
					sp.BringToHome();
				}

				++m_Count;
			}
		}
	}
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us