-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMyHouses.cs
331 lines (254 loc) · 9.85 KB
/
MyHouses.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
//MyHouses System
//A re-write of the "viewhouses" command, but for players.
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Multis;
using Server.Targeting;
using Server.Accounting;
using Server.Commands;
using Server.Spells;
namespace Server.Gumps
{
public class MyHousesGump : Gump
{
public static void Initialize()
{
CommandSystem.Register( "MyHouses", AccessLevel.Player, new CommandEventHandler( ViewHouses_OnCommand ) );
}
[Usage( "MyHouses" )]
[Description( "Displays a menu listing all houses of the. The menu also contains specific house details, and options to: go to house, and demolish house." )]
public static void ViewHouses_OnCommand( CommandEventArgs e )
{
e.Mobile.SendGump( new MyHousesGump( e.Mobile, GetMyHouses( e.Mobile ), null ) );
}
private class MyHouseComparer : IComparer<BaseHouse>
{
public static readonly IComparer<BaseHouse> Instance = new MyHouseComparer();
public int Compare( BaseHouse x, BaseHouse y )
{
return x.BuiltOn.CompareTo( y.BuiltOn );
}
}
public static List<BaseHouse> GetMyHouses( Mobile owner )
{
List<BaseHouse> list = new List<BaseHouse>();
Account acct = owner.Account as Account;
if ( acct == null )
{
list.AddRange( BaseHouse.GetHouses( owner ) );
}
else
{
for ( int i = 0; i < acct.Length; ++i )
{
Mobile mob = acct[i];
if ( mob != null )
list.AddRange( BaseHouse.GetHouses( mob ) );
}
}
list.Sort( MyHouseComparer.Instance );
return list;
}
private Mobile m_From;
private List<BaseHouse> m_List;
private BaseHouse m_Selection;
public MyHousesGump( Mobile from, List<BaseHouse> list, BaseHouse sel ) : base( 50, 40 )
{
m_From = from;
m_List = list;
m_Selection = sel;
from.CloseGump( typeof( MyHousesGump ) );
AddPage( 0 );
AddBackground( 0, 0, 240, 360, 5054 );
AddBlackAlpha( 10, 10, 220, 340 );
if ( sel == null || sel.Deleted )
{
m_Selection = null;
AddHtml( 35, 15, 120, 20, Color( "My House Types", White ), false, false );
if ( list.Count == 0 )
AddHtml( 35, 40, 160, 40, Color( "You have no houses in the world.", White ), false, false );
AddImage( 190, 17, 0x25EA );
AddImage( 207, 17, 0x25E6 );
int page = 0;
for ( int i = 0; i < list.Count; ++i )
{
if ( (i % 15) == 0 )
{
if ( page > 0 )
AddButton( 207, 17, 0x15E1, 0x15E5, 0, GumpButtonType.Page, page+1 );
AddPage( ++page );
if ( page > 1 )
AddButton( 190, 17, 0x15E3, 0x15E7, 0, GumpButtonType.Page, page-1 );
}
object name = FindMyHouseName( list[i] );
AddHtml( 15, 40 + ((i % 15) * 20), 20, 20, Color( String.Format( "{0}.", i+1 ), White ), false, false );
if ( name is int )
AddHtmlLocalized( 35, 40 + ((i % 15) * 20), 160, 20, (int)name, White16, false, false );
else if ( name is string )
AddHtml( 35, 40 + ((i % 15) * 20), 160, 20, Color( (string)name, White ), false, false );
AddButton( 198, 39 + ((i % 15) * 20), 4005, 4007, i+1, GumpButtonType.Reply, 0 );
}
}
else
{
string houseName, owner, location;
Map map = sel.Map;
houseName = (sel.Sign == null) ? "An Unnamed House" : sel.Sign.GetName();
owner = (sel.Owner == null) ? "nobody" : sel.Owner.Name;
int xLong = 0, yLat = 0, xMins = 0, yMins = 0;
bool xEast = false, ySouth = false;
bool valid = Sextant.Format( sel.Location, map, ref xLong, ref yLat, ref xMins, ref yMins, ref xEast, ref ySouth );
if ( valid )
location = String.Format( "{0}° {1}'{2}, {3}° {4}'{5}", yLat, yMins, ySouth ? "S" : "N", xLong, xMins, xEast ? "E" : "W" );
else
location = "unknown";
AddHtml( 10, 15, 220, 20, Color( Center( "My House Properties" ), White ), false, false );
AddHtml( 15, 40, 210, 20, Color( "Facet:", White ), false, false );
AddHtml( 15, 40, 210, 20, Color( Right( map == null ? "(null)" : map.Name ), White ), false, false );
AddHtml( 15, 60, 210, 20, Color( "Location:", White ), false, false );
AddHtml( 15, 60, 210, 20, Color( Right( sel.Location.ToString() ), White ), false, false );
AddHtml( 15, 80, 210, 20, Color( "Sextant:", White ), false, false );
AddHtml( 15, 80, 210, 20, Color( Right( location ), White ), false, false );
AddHtml( 15, 100, 210, 20, Color( "Owner:", White ), false, false );
AddHtml( 15, 100, 210, 20, Color( Right( owner ), White ), false, false );
AddHtml( 15, 120, 210, 20, Color( "Name:", White ), false, false );
AddHtml( 15, 120, 210, 20, Color( Right( houseName ), White ), false, false );
AddHtml( 15, 140, 210, 20, Color( "Friends:", White ), false, false );
AddHtml( 15, 140, 210, 20, Color( Right( sel.Friends.Count.ToString() ), White ), false, false );
AddHtml( 15, 160, 210, 20, Color( "Co-Owners:", White ), false, false );
AddHtml( 15, 160, 210, 20, Color( Right( sel.CoOwners.Count.ToString() ), White ), false, false );
AddHtml( 15, 180, 210, 20, Color( "Bans:", White ), false, false );
AddHtml( 15, 180, 210, 20, Color( Right( sel.Bans.Count.ToString() ), White ), false, false );
AddHtml( 15, 200, 210, 20, Color( "Decays:", White ), false, false );
AddHtml( 15, 200, 210, 20, Color( Right( sel.CanDecay ? "Yes" : "No" ), White ), false, false );
AddHtml( 15, 220, 210, 20, Color( "Decay Level:", White ), false, false );
AddHtml( 15, 220, 210, 20, Color( Right( sel.DecayLevel.ToString() ), White ), false, false );
AddButton( 15, 245, 4005, 4007, 1, GumpButtonType.Reply, 0 );
AddHtml( 50, 245, 120, 20, Color( "Go to this house", White ), false, false );
//AddButton( 15, 265, 4005, 4007, 2, GumpButtonType.Reply, 0 );
//AddHtml( 50, 265, 120, 20, Color( "Open house menu", White ), false, false );
AddButton( 15, 285, 4005, 4007, 3, GumpButtonType.Reply, 0 );
AddHtml( 50, 285, 120, 20, Color( "Demolish house", White ), false, false );
AddButton( 15, 305, 4005, 4007, 4, GumpButtonType.Reply, 0 );
AddHtml( 50, 305, 120, 20, Color( "Refresh house", White ), false, false );
}
}
public override void OnResponse( Server.Network.NetState sender, RelayInfo info )
{
if ( m_Selection == null )
{
int v = info.ButtonID - 1;
if ( v >= 0 && v < m_List.Count )
m_From.SendGump( new MyHousesGump( m_From, m_List, m_List[v] ) );
}
else if ( !m_Selection.Deleted )
{
switch ( info.ButtonID )
{
case 0:
{
m_From.SendGump( new MyHousesGump( m_From, m_List, null ) );
break;
}
case 1:
{
Map map = m_Selection.Map;
if ( m_From.Region is Regions.Jail )
{
m_From.SendMessage ("You cannot escape jail so easily foolish one.");
m_From.SendGump( new MyHousesGump( m_From, m_List, m_Selection ) );
return;
}
if ( Server.Spells.SpellHelper.CheckCombat( m_From ) || m_From.Combatant != null )
{
m_From.SendMessage ("Wouldst thou flee during the heat of battle?");
m_From.SendGump( new MyHousesGump( m_From, m_List, m_Selection ) );
return;
}
if ( Server.Factions.Sigil.ExistsOn( m_From ) )
{
m_From.SendMessage ("You cannot use this function while carrying a sigil.");
m_From.SendGump( new MyHousesGump( m_From, m_List, m_Selection ) );
return;
}
if ( m_From.Criminal )
{
m_From.SendMessage ("A criminal may not escape so easily.");
m_From.SendGump( new MyHousesGump( m_From, m_List, m_Selection ) );
return;
}
m_From.MoveToWorld( m_Selection.BanLocation, map );
m_From.SendGump( new MyHousesGump( m_From, m_List, m_Selection ) );
break;
}
case 2:
{
m_From.SendGump( new MyHousesGump( m_From, m_List, m_Selection ) );
HouseSign sign = m_Selection.Sign;
if ( sign != null && !sign.Deleted )
sign.OnDoubleClick( m_From );
break;
}
case 3:
{
m_From.SendGump( new MyHousesGump( m_From, m_List, m_Selection ) );
m_From.SendGump( new HouseDemolishGump( m_From, m_Selection ) );
break;
}
case 4:
{
m_Selection.RefreshDecay();
m_From.SendGump( new MyHousesGump( m_From, m_List, m_Selection ) );
break;
}
}
}
}
public object FindMyHouseName( BaseHouse house )
{
int multiID = house.ItemID & 0x3FFF;
HousePlacementEntry[] entries;
entries = HousePlacementEntry.ClassicHouses;
for ( int i = 0; i < entries.Length; ++i )
{
if ( entries[i].MultiID == multiID )
return entries[i].Description;
}
entries = HousePlacementEntry.TwoStoryFoundations;
for ( int i = 0; i < entries.Length; ++i )
{
if ( entries[i].MultiID == multiID )
return entries[i].Description;
}
entries = HousePlacementEntry.ThreeStoryFoundations;
for ( int i = 0; i < entries.Length; ++i )
{
if ( entries[i].MultiID == multiID )
return entries[i].Description;
}
return house.GetType().Name;
}
private const int White16 = 0x7FFF;
private const int White = 0xFFFFFF;
public string Right( string text )
{
return String.Format( "<div align=right>{0}</div>", text );
}
public string Center( string text )
{
return String.Format( "<CENTER>{0}</CENTER>", text );
}
public string Color( string text, int color )
{
return String.Format( "<BASEFONT COLOR=#{0:X6}>{1}</BASEFONT>", color, text );
}
public void AddBlackAlpha( int x, int y, int width, int height )
{
AddImageTiled( x, y, width, height, 2624 );
AddAlphaRegion( x, y, width, height );
}
}
}