PageRenderTime 51ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Scripts/Multis/BaseHouse.cs

https://bitbucket.org/Kel/crepuscule
C# | 2638 lines | 2086 code | 528 blank | 24 comment | 701 complexity | 33c4752f9480179011ab52a823d84943 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Collections;
  3. using Server;
  4. using Server.Items;
  5. using Server.Mobiles;
  6. using Server.Multis.Deeds;
  7. using Server.Regions;
  8. using Server.Network;
  9. using Server.Targeting;
  10. using Server.Accounting;
  11. using Server.ContextMenus;
  12. using Server.Gumps;
  13. using System.Collections.Generic;
  14. //using Server.Engines.BulkOrders;
  15. namespace Server.Multis
  16. {
  17. public abstract class BaseHouse : BaseMulti
  18. {
  19. public const int MaxCoOwners = 15;
  20. public const int MaxFriends = 50;
  21. public const int MaxBans = 50;
  22. private bool m_Public;
  23. private HouseRegion m_Region;
  24. private HouseSign m_Sign;
  25. private TrashBarrel m_Trash;
  26. private ArrayList m_Doors;
  27. private Mobile m_Owner;
  28. private ArrayList m_Access;
  29. private ArrayList m_Bans;
  30. private ArrayList m_CoOwners;
  31. private ArrayList m_Friends;
  32. private ArrayList m_LockDowns;
  33. private ArrayList m_Secures;
  34. private ArrayList m_Addons;
  35. private int m_MaxLockDowns;
  36. private int m_MaxSecures;
  37. private int m_Price;
  38. private int m_Visits;
  39. private DateTime m_BuiltOn, m_LastTraded;
  40. private static Hashtable m_Table = new Hashtable();
  41. public virtual bool IsAosRules{ get{ return Core.AOS; } }
  42. public virtual HousePlacementEntry GetAosEntry()
  43. {
  44. return HousePlacementEntry.Find( this );
  45. }
  46. public virtual int GetAosMaxSecures()
  47. {
  48. HousePlacementEntry hpe = GetAosEntry();
  49. if ( hpe == null )
  50. return 0;
  51. return hpe.Storage;
  52. }
  53. public virtual int GetAosMaxLockdowns()
  54. {
  55. HousePlacementEntry hpe = GetAosEntry();
  56. if ( hpe == null )
  57. return 0;
  58. return hpe.Lockdowns;
  59. }
  60. public virtual int GetAosCurSecures( out int fromSecures, out int fromVendors, out int fromLockdowns )
  61. {
  62. fromSecures = 0;
  63. fromVendors = 0;
  64. fromLockdowns = 0;
  65. ArrayList list = m_Secures;
  66. for ( int i = 0; list != null && i < list.Count; ++i )
  67. {
  68. SecureInfo si = (SecureInfo)list[i];
  69. fromSecures += si.Item.TotalItems;
  70. }
  71. if ( m_LockDowns != null )
  72. fromLockdowns += m_LockDowns.Count;
  73. List<Mobile> list2 = m_Region.Mobiles;
  74. for (int i = 0; i < list2.Count; ++i)
  75. {
  76. object obj = list2[i];
  77. if ( obj is PlayerVendor )
  78. {
  79. Container pack = ((PlayerVendor)obj).Backpack;
  80. if ( pack != null )
  81. fromVendors += pack.TotalItems;
  82. }
  83. }
  84. return fromSecures + fromVendors + fromLockdowns;
  85. }
  86. public virtual bool CanPlaceNewVendor()
  87. {
  88. if ( !IsAosRules )
  89. return true;
  90. return CheckAosLockdowns( 10 );
  91. }
  92. public const int MaximumBarkeepCount = 2;
  93. public virtual bool CanPlaceNewBarkeep()
  94. {
  95. List<Mobile> mobs = m_Region.Mobiles;
  96. int avail = MaximumBarkeepCount;
  97. for ( int i = 0; avail > 0 && i < mobs.Count; ++i )
  98. {
  99. if ( mobs[i] is PlayerBarkeeper )
  100. --avail;
  101. }
  102. return ( avail > 0 );
  103. }
  104. public virtual bool CheckAosLockdowns( int need )
  105. {
  106. return ( (GetAosCurLockdowns() + need) <= GetAosMaxLockdowns() );
  107. }
  108. public virtual bool CheckAosStorage( int need )
  109. {
  110. int fromSecures, fromVendors, fromLockdowns;
  111. return ( (GetAosCurSecures( out fromSecures, out fromVendors, out fromLockdowns ) + need) <= GetAosMaxSecures() );
  112. }
  113. public static void Configure()
  114. {
  115. Item.LockedDownFlag = 1;
  116. Item.SecureFlag = 2;
  117. }
  118. public virtual int GetAosCurLockdowns()
  119. {
  120. int v = 0;
  121. if ( m_LockDowns != null )
  122. v += m_LockDowns.Count;
  123. if ( m_Secures != null )
  124. v += m_Secures.Count;
  125. List<Mobile> list = m_Region.Mobiles;
  126. for ( int i = 0; i < list.Count; ++i )
  127. {
  128. object obj = list[i];
  129. if ( obj is PlayerVendor )
  130. v += 10;
  131. }
  132. return v;
  133. }
  134. public static bool CheckLockedDown( Item item )
  135. {
  136. BaseHouse house = FindHouseAt( item );
  137. return ( house != null && house.IsLockedDown( item ) );
  138. }
  139. public static bool CheckSecured( Item item )
  140. {
  141. BaseHouse house = FindHouseAt( item );
  142. return ( house != null && house.IsSecure( item ) );
  143. }
  144. public static bool CheckLockedDownOrSecured( Item item )
  145. {
  146. BaseHouse house = FindHouseAt( item );
  147. return ( house != null && (house.IsSecure( item ) || house.IsLockedDown( item )) );
  148. }
  149. public static ArrayList GetHouses( Mobile m )
  150. {
  151. ArrayList list = new ArrayList();
  152. if ( m != null )
  153. {
  154. ArrayList exists = (ArrayList)m_Table[m];
  155. if ( exists != null )
  156. {
  157. for ( int i = 0; i < exists.Count; ++i )
  158. {
  159. BaseHouse house = exists[i] as BaseHouse;
  160. if ( house != null && !house.Deleted && house.Owner == m )
  161. list.Add( house );
  162. }
  163. }
  164. }
  165. return list;
  166. }
  167. public static bool CheckHold(Mobile m, Container cont, Item item, bool message, bool checkItems, int plusItems, int plusWeight)
  168. {
  169. BaseHouse house = FindHouseAt(cont);
  170. if (house == null || !house.IsAosRules)
  171. return true;
  172. if (house.IsSecure(cont) && !house.CheckAosStorage(1 + item.TotalItems + plusItems))
  173. {
  174. if (message)
  175. m.SendLocalizedMessage(1061839); // This action would exceed the secure storage limit of the house.
  176. return false;
  177. }
  178. return true;
  179. }
  180. public static bool CheckAccessible( Mobile m, Item item )
  181. {
  182. if ( m.AccessLevel >= AccessLevel.GameMaster )
  183. return true; // Staff can access anything
  184. BaseHouse house = FindHouseAt( item );
  185. if ( house == null )
  186. return true;
  187. SecureAccessResult res = house.CheckSecureAccess( m, item );
  188. switch ( res )
  189. {
  190. case SecureAccessResult.Insecure: break;
  191. case SecureAccessResult.Accessible: return true;
  192. case SecureAccessResult.Inaccessible: return false;
  193. }
  194. if ( house.IsLockedDown( item ) )
  195. return house.IsCoOwner( m ) && (item is Container);
  196. return true;
  197. }
  198. public static BaseHouse FindHouseAt( Mobile m )
  199. {
  200. if ( m == null || m.Deleted )
  201. return null;
  202. return FindHouseAt( m.Location, m.Map, 16 );
  203. }
  204. public static BaseHouse FindHouseAt( Item item )
  205. {
  206. if ( item == null || item.Deleted )
  207. return null;
  208. return FindHouseAt( item.GetWorldLocation(), item.Map, item.ItemData.Height );
  209. }
  210. public static BaseHouse FindHouseAt( Point3D loc, Map map, int height )
  211. {
  212. if ( map == null || map == Map.Internal )
  213. return null;
  214. Sector sector = map.GetSector( loc );
  215. for ( int i = 0; i < sector.Multis.Count; ++i )
  216. {
  217. BaseHouse house = sector.Multis[i] as BaseHouse;
  218. if ( house != null && house.IsInside( loc, height ) )
  219. return house;
  220. }
  221. return null;
  222. }
  223. public bool IsInside( Mobile m )
  224. {
  225. if ( m == null || m.Deleted || m.Map != this.Map )
  226. return false;
  227. return IsInside( m.Location, 16 );
  228. }
  229. public bool IsInside( Item item )
  230. {
  231. if ( item == null || item.Deleted || item.Map != this.Map )
  232. return false;
  233. return IsInside( item.Location, item.ItemData.Height );
  234. }
  235. public bool CheckAccessibility( Item item, Mobile from )
  236. {
  237. SecureAccessResult res = CheckSecureAccess( from, item );
  238. switch ( res )
  239. {
  240. case SecureAccessResult.Insecure: break;
  241. case SecureAccessResult.Accessible: return true;
  242. case SecureAccessResult.Inaccessible: return false;
  243. }
  244. if ( !IsLockedDown( item ) )
  245. return true;
  246. else if ( from.AccessLevel >= AccessLevel.GameMaster )
  247. return true;
  248. else if ( item is Runebook )
  249. return true;
  250. else if ( item is ISecurable )
  251. return HasSecureAccess( from, ((ISecurable)item).Level );
  252. else if ( item is Container )
  253. return IsCoOwner( from );
  254. else if ( item is BaseLight )
  255. return IsFriend( from );
  256. else if ( item is PotionKeg )
  257. return IsFriend( from );
  258. else if ( item is BaseBoard )
  259. return true;
  260. else if ( item is Dices )
  261. return true;
  262. else if ( item is RecallRune )
  263. return true;
  264. else if ( item is TreasureMap )
  265. return true;
  266. else if ( item is Clock )
  267. return true;
  268. else if ( item is BaseBook )
  269. return true;
  270. else if ( item is BaseInstrument )
  271. return true;
  272. else if ( item is Dyes || item is DyeTub )
  273. return true;
  274. return false;
  275. }
  276. public virtual bool IsInside( Point3D p, int height )
  277. {
  278. if ( Deleted )
  279. return false;
  280. MultiComponentList mcl = Components;
  281. int x = p.X - (X + mcl.Min.X);
  282. int y = p.Y - (Y + mcl.Min.Y);
  283. if ( x < 0 || x >= mcl.Width || y < 0 || y >= mcl.Height )
  284. return false;
  285. if ( this is HouseFoundation && y < (mcl.Height-1) )
  286. return true;
  287. Tile[] tiles = mcl.Tiles[x][y];
  288. for ( int j = 0; j < tiles.Length; ++j )
  289. {
  290. Tile tile = tiles[j];
  291. int id = tile.ID & 0x3FFF;
  292. ItemData data = TileData.ItemTable[id];
  293. // Slanted roofs do not count; they overhang blocking south and east sides of the multi
  294. if ( (data.Flags & TileFlag.Roof) != 0 )
  295. continue;
  296. // Signs and signposts are not considered part of the multi
  297. if ( (id >= 0xB95 && id <= 0xC0E) || (id >= 0xC43 && id <= 0xC44) )
  298. continue;
  299. int tileZ = tile.Z + this.Z;
  300. if ( p.Z == tileZ || (p.Z + height) > tileZ )
  301. return true;
  302. }
  303. return false;
  304. }
  305. public SecureAccessResult CheckSecureAccess( Mobile m, Item item )
  306. {
  307. if ( m_Secures == null || !(item is Container) )
  308. return SecureAccessResult.Insecure;
  309. for ( int i = 0; i < m_Secures.Count; ++i )
  310. {
  311. SecureInfo info = (SecureInfo)m_Secures[i];
  312. if ( info.Item == item )
  313. return HasSecureAccess( m, info.Level ) ? SecureAccessResult.Accessible : SecureAccessResult.Inaccessible;
  314. }
  315. return SecureAccessResult.Insecure;
  316. }
  317. public BaseHouse( int multiID, Mobile owner, int MaxLockDown, int MaxSecure ) : base( multiID | 0x4000 )
  318. {
  319. m_BuiltOn = DateTime.Now;
  320. m_LastTraded = DateTime.MinValue;
  321. m_Doors = new ArrayList();
  322. m_LockDowns = new ArrayList();
  323. m_Secures = new ArrayList();
  324. m_Addons = new ArrayList();
  325. m_CoOwners = new ArrayList();
  326. m_Friends = new ArrayList();
  327. m_Bans = new ArrayList();
  328. m_Access = new ArrayList();
  329. m_Region = new HouseRegion( this );
  330. m_Owner = owner;
  331. m_MaxLockDowns = MaxLockDown;
  332. m_MaxSecures = MaxSecure;
  333. UpdateRegionArea();
  334. if ( owner != null )
  335. {
  336. ArrayList list = (ArrayList)m_Table[owner];
  337. if ( list == null )
  338. m_Table[owner] = list = new ArrayList();
  339. list.Add( this );
  340. }
  341. Movable = false;
  342. }
  343. public BaseHouse( Serial serial ) : base( serial )
  344. {
  345. }
  346. public override void OnMapChange()
  347. {
  348. if ( m_LockDowns == null )
  349. return;
  350. m_Region.Map = this.Map;
  351. if ( m_Sign != null && !m_Sign.Deleted )
  352. m_Sign.Map = this.Map;
  353. if ( m_Trash != null && !m_Trash.Deleted )
  354. m_Trash.Map = this.Map;
  355. if ( m_Doors != null )
  356. {
  357. foreach ( Item item in m_Doors )
  358. item.Map = this.Map;
  359. }
  360. if ( m_LockDowns != null )
  361. {
  362. foreach ( Item item in m_LockDowns )
  363. item.Map = this.Map;
  364. }
  365. }
  366. public virtual void ChangeSignType( int itemID )
  367. {
  368. if ( m_Sign != null )
  369. m_Sign.ItemID = itemID;
  370. }
  371. public abstract Rectangle2D[] Area{ get; }
  372. public virtual void UpdateRegionArea()
  373. {
  374. Rectangle2D[] area = this.Area;
  375. ArrayList coords = new ArrayList( area.Length );
  376. for ( int i = 0; i < area.Length; ++i )
  377. coords.Add( new Rectangle2D( X + area[i].Start.X, Y + area[i].Start.Y, area[i].Width, area[i].Height ) );
  378. m_Region.Coords = coords;
  379. }
  380. public override void OnLocationChange( Point3D oldLocation )
  381. {
  382. if ( m_LockDowns == null )
  383. return;
  384. int x = base.Location.X - oldLocation.X;
  385. int y = base.Location.Y - oldLocation.Y;
  386. int z = base.Location.Z - oldLocation.Z;
  387. if ( m_Sign != null && !m_Sign.Deleted )
  388. m_Sign.Location = new Point3D( m_Sign.X + x, m_Sign.Y + y, m_Sign.Z + z );
  389. if ( m_Trash != null && !m_Trash.Deleted )
  390. m_Trash.Location = new Point3D( m_Trash.X + x, m_Trash.Y + y, m_Trash.Z + z );
  391. UpdateRegionArea();
  392. m_Region.GoLocation = new Point3D( m_Region.GoLocation.X + x, m_Region.GoLocation.Y + y, m_Region.GoLocation.Z + z );
  393. if ( m_Doors != null )
  394. {
  395. foreach ( Item item in m_Doors )
  396. {
  397. if ( !item.Deleted )
  398. item.Location = new Point3D( item.X + x, item.Y + y, item.Z + z );
  399. }
  400. }
  401. if ( m_LockDowns != null )
  402. {
  403. foreach ( Item item in m_LockDowns )
  404. {
  405. if ( !item.Deleted )
  406. item.Location = new Point3D( item.X + x, item.Y + y, item.Z + z );
  407. }
  408. }
  409. }
  410. public BaseDoor AddEastDoor( int x, int y, int z )
  411. {
  412. return AddEastDoor( true, x, y, z );
  413. }
  414. public BaseDoor AddEastDoor( bool wood, int x, int y, int z )
  415. {
  416. BaseDoor door = MakeDoor( wood, DoorFacing.SouthCW );
  417. AddDoor( door, x, y, z );
  418. return door;
  419. }
  420. public BaseDoor AddSouthDoor( int x, int y, int z )
  421. {
  422. return AddSouthDoor( true, x, y, z );
  423. }
  424. public BaseDoor AddSouthDoor( bool wood, int x, int y, int z )
  425. {
  426. BaseDoor door = MakeDoor( wood, DoorFacing.WestCW );
  427. AddDoor( door, x, y, z );
  428. return door;
  429. }
  430. public BaseDoor AddEastDoor( int x, int y, int z, uint k )
  431. {
  432. return AddEastDoor( true, x, y, z, k );
  433. }
  434. public BaseDoor AddEastDoor( bool wood, int x, int y, int z, uint k )
  435. {
  436. BaseDoor door = MakeDoor( wood, DoorFacing.SouthCW );
  437. door.Locked = true;
  438. door.KeyValue = k;
  439. AddDoor( door, x, y, z );
  440. return door;
  441. }
  442. public BaseDoor AddSouthDoor( int x, int y, int z, uint k )
  443. {
  444. return AddSouthDoor( true, x, y, z, k );
  445. }
  446. public BaseDoor AddSouthDoor( bool wood, int x, int y, int z, uint k )
  447. {
  448. BaseDoor door = MakeDoor( wood, DoorFacing.WestCW );
  449. door.Locked = true;
  450. door.KeyValue = k;
  451. AddDoor( door, x, y, z );
  452. return door;
  453. }
  454. public BaseDoor[] AddSouthDoors( int x, int y, int z, uint k )
  455. {
  456. return AddSouthDoors( true, x, y, z, k );
  457. }
  458. public BaseDoor[] AddSouthDoors( bool wood, int x, int y, int z, uint k )
  459. {
  460. BaseDoor westDoor = MakeDoor( wood, DoorFacing.WestCW );
  461. BaseDoor eastDoor = MakeDoor( wood, DoorFacing.EastCCW );
  462. westDoor.Locked = true;
  463. eastDoor.Locked = true;
  464. westDoor.KeyValue = k;
  465. eastDoor.KeyValue = k;
  466. westDoor.Link = eastDoor;
  467. eastDoor.Link = westDoor;
  468. AddDoor( westDoor, x, y, z );
  469. AddDoor( eastDoor, x + 1, y, z );
  470. return new BaseDoor[2]{ westDoor, eastDoor };
  471. }
  472. public uint CreateKeys( Mobile m )
  473. {
  474. uint value = Key.RandomValue();
  475. if ( !IsAosRules )
  476. {
  477. Key packKey = new Key( KeyType.Gold );
  478. Key bankKey = new Key( KeyType.Gold );
  479. packKey.KeyValue = value;
  480. bankKey.KeyValue = value;
  481. packKey.LootType = LootType.Newbied;
  482. bankKey.LootType = LootType.Newbied;
  483. BankBox box = m.BankBox;
  484. if ( box == null || !box.TryDropItem( m, bankKey, false ) )
  485. bankKey.Delete();
  486. m.AddToBackpack( packKey );
  487. }
  488. return value;
  489. }
  490. public BaseDoor[] AddSouthDoors( int x, int y, int z )
  491. {
  492. return AddSouthDoors( true, x, y, z, false );
  493. }
  494. public BaseDoor[] AddSouthDoors( bool wood, int x, int y, int z, bool inv )
  495. {
  496. BaseDoor westDoor = MakeDoor( wood, inv ? DoorFacing.WestCCW : DoorFacing.WestCW );
  497. BaseDoor eastDoor = MakeDoor( wood, inv ? DoorFacing.EastCW : DoorFacing.EastCCW );
  498. westDoor.Link = eastDoor;
  499. eastDoor.Link = westDoor;
  500. AddDoor( westDoor, x, y, z );
  501. AddDoor( eastDoor, x + 1, y, z );
  502. return new BaseDoor[2]{ westDoor, eastDoor };
  503. }
  504. public BaseDoor MakeDoor( bool wood, DoorFacing facing )
  505. {
  506. if ( wood )
  507. return new DarkWoodHouseDoor( facing );
  508. else
  509. return new MetalHouseDoor( facing );
  510. }
  511. public void AddDoor( BaseDoor door, int xoff, int yoff, int zoff )
  512. {
  513. door.MoveToWorld( new Point3D( xoff+this.X, yoff+this.Y, zoff+this.Z ), this.Map );
  514. m_Doors.Add( door );
  515. }
  516. public void AddTrashBarrel( Mobile from )
  517. {
  518. for ( int i = 0; m_Doors != null && i < m_Doors.Count; ++i )
  519. {
  520. BaseDoor door = m_Doors[i] as BaseDoor;
  521. Point3D p = door.Location;
  522. if ( door.Open )
  523. p = new Point3D( p.X - door.Offset.X, p.Y - door.Offset.Y, p.Z - door.Offset.Z );
  524. if ( (from.Z + 16) >= p.Z && (p.Z + 16) >= from.Z )
  525. {
  526. if ( from.InRange( p, 1 ) )
  527. {
  528. from.SendLocalizedMessage( 502120 ); // You cannot place a trash barrel near a door or near steps.
  529. return;
  530. }
  531. }
  532. }
  533. if ( m_Trash == null || m_Trash.Deleted )
  534. {
  535. m_Trash = new TrashBarrel();
  536. m_Trash.Movable = false;
  537. m_Trash.MoveToWorld( from.Location, from.Map );
  538. from.SendLocalizedMessage( 502121 ); /* You have a new trash barrel.
  539. * Three minutes after you put something in the barrel, the trash will be emptied.
  540. * Be forewarned, this is permanent! */
  541. }
  542. else
  543. {
  544. m_Trash.MoveToWorld( from.Location, from.Map );
  545. }
  546. }
  547. public void SetSign( int xoff, int yoff, int zoff )
  548. {
  549. m_Sign = new HouseSign( this );
  550. m_Sign.MoveToWorld( new Point3D( this.X + xoff, this.Y + yoff, this.Z + zoff ), this.Map );
  551. }
  552. private void SetLockdown( Item i, bool locked )
  553. {
  554. SetLockdown( i, locked, false );
  555. }
  556. private void SetLockdown( Item i, bool locked, bool checkContains )
  557. {
  558. if ( m_LockDowns == null )
  559. return;
  560. i.Movable = !locked;
  561. i.IsLockedDown = locked;
  562. if ( locked )
  563. {
  564. if ( !checkContains || !m_LockDowns.Contains( i ) )
  565. m_LockDowns.Add( i );
  566. }
  567. else
  568. {
  569. m_LockDowns.Remove( i );
  570. }
  571. if ( !locked )
  572. i.SetLastMoved();
  573. if ( (i is Container) && (!locked || !(i is BaseBoard)) )
  574. {
  575. foreach ( Item c in i.Items )
  576. SetLockdown( c, locked, checkContains );
  577. }
  578. }
  579. public bool LockDown( Mobile m, Item item )
  580. {
  581. return LockDown( m, item, true );
  582. }
  583. public bool LockDown( Mobile m, Item item, bool checkIsInside )
  584. {
  585. if ( !IsCoOwner( m ) )
  586. return false;
  587. if ( item.Movable && !IsSecure( item ) )
  588. {
  589. int amt = 1 + item.TotalItems;
  590. Item rootItem = item.RootParent as Item;
  591. if ( checkIsInside && item.RootParent is Mobile )
  592. {
  593. m.SendLocalizedMessage( 1005525 );//That is not in your house
  594. }
  595. else if ( checkIsInside && !IsInside( item.GetWorldLocation(), item.ItemData.Height ) )
  596. {
  597. m.SendLocalizedMessage( 1005525 );//That is not in your house
  598. }
  599. else if ( IsSecure( rootItem ) )
  600. {
  601. m.SendLocalizedMessage( 501737 ); // You need not lock down items in a secure container.
  602. }
  603. else if ( rootItem != null && !IsLockedDown( rootItem ) )
  604. {
  605. m.SendLocalizedMessage( 501736 ); // You must lockdown the container first!
  606. }
  607. else if ( IsAosRules ? (!CheckAosLockdowns( amt ) || !CheckAosStorage( amt )) : (this.LockDownCount + amt) > m_MaxLockDowns )
  608. {
  609. m.SendLocalizedMessage( 1005379 );//That would exceed the maximum lock down limit for this house
  610. }
  611. else
  612. {
  613. SetLockdown( item, true );
  614. return true;
  615. }
  616. }
  617. else if ( m_LockDowns.IndexOf( item ) != -1 )
  618. {
  619. m.SendLocalizedMessage( 1005526 );//That is already locked down
  620. return true;
  621. }
  622. else
  623. {
  624. m.SendLocalizedMessage( 1005377 );//You cannot lock that down
  625. }
  626. return false;
  627. }
  628. private class TransferItem: CrepusculeItem
  629. {
  630. private BaseHouse m_House;
  631. public TransferItem( BaseHouse house ) : base( 0x14F0 )
  632. {
  633. m_House = house;
  634. Hue = 0x480;
  635. Movable = false;
  636. Name = "a house transfer contract";
  637. }
  638. public override void GetProperties( ObjectPropertyList list )
  639. {
  640. base.GetProperties( list );
  641. string houseName, owner, location;
  642. Item sign = ( m_House == null ? null : m_House.Sign );
  643. if ( sign == null || sign.Name == null || sign.Name == "a house sign" )
  644. houseName = "nothing";
  645. else
  646. houseName = sign.Name;
  647. Mobile houseOwner = ( m_House == null ? null : m_House.Owner );
  648. if ( houseOwner == null )
  649. owner = "nobody";
  650. else
  651. owner = houseOwner.Name;
  652. int xLong = 0, yLat = 0, xMins = 0, yMins = 0;
  653. bool xEast = false, ySouth = false;
  654. bool valid = m_House != null && Sextant.Format( m_House.Location, m_House.Map, ref xLong, ref yLat, ref xMins, ref yMins, ref xEast, ref ySouth );
  655. if ( valid )
  656. location = String.Format( "{0}° {1}'{2}, {3}° {4}'{5}", yLat, yMins, ySouth ? "S" : "N", xLong, xMins, xEast ? "E" : "W" );
  657. else
  658. location = "????";
  659. list.Add( 1061112, Utility.FixHtml( houseName ) ); // House Name: ~1_val~
  660. list.Add( 1061113, owner ); // Owner: ~1_val~
  661. list.Add( 1061114, location ); // Location: ~1_val~
  662. }
  663. public TransferItem( Serial serial ) : base( serial )
  664. {
  665. }
  666. public override void Serialize( GenericWriter writer )
  667. {
  668. base.Serialize( writer );
  669. writer.Write( (int) 0 ); // version
  670. }
  671. public override void Deserialize( GenericReader reader )
  672. {
  673. base.Deserialize( reader );
  674. int version = reader.ReadInt();
  675. Delete();
  676. }
  677. public override bool AllowSecureTrade( Mobile from, Mobile to, Mobile newOwner, bool accepted )
  678. {
  679. if ( !base.AllowSecureTrade( from, to, newOwner, accepted ) )
  680. return false;
  681. else if ( !accepted )
  682. return true;
  683. if ( Deleted || m_House == null || m_House.Deleted || !m_House.IsOwner( from ) || !from.CheckAlive() || !to.CheckAlive() )
  684. return false;
  685. if ( BaseHouse.HasAccountHouse( to ) )
  686. {
  687. from.SendLocalizedMessage( 501388 ); // You cannot transfer ownership to another house owner or co-owner!
  688. return false;
  689. }
  690. return m_House.CheckTransferPosition( from, to );
  691. }
  692. public override void OnSecureTrade( Mobile from, Mobile to, Mobile newOwner, bool accepted )
  693. {
  694. if ( Deleted || m_House == null || m_House.Deleted || !m_House.IsOwner( from ) || !from.CheckAlive() || !to.CheckAlive() )
  695. return;
  696. Delete();
  697. if ( !accepted )
  698. return;
  699. from.SendLocalizedMessage( 501338 ); // You have transferred ownership of the house.
  700. to.SendLocalizedMessage( 501339 ); /* You are now the owner of this house.
  701. * The house's co-owner, friend, ban, and access lists have been cleared.
  702. * You should double-check the security settings on any doors and teleporters in the house.
  703. */
  704. m_House.RemoveKeys( from );
  705. m_House.Owner = to;
  706. m_House.Bans.Clear();
  707. m_House.Friends.Clear();
  708. m_House.CoOwners.Clear();
  709. m_House.ChangeLocks( to );
  710. }
  711. }
  712. public bool CheckTransferPosition( Mobile from, Mobile to )
  713. {
  714. bool isValid = true;
  715. Item sign = m_Sign;
  716. Point3D p = ( sign == null ? Point3D.Zero : sign.GetWorldLocation() );
  717. if ( from.Map != Map || to.Map != Map )
  718. isValid = false;
  719. else if ( sign == null )
  720. isValid = false;
  721. else if ( from.Map != sign.Map || to.Map != sign.Map )
  722. isValid = false;
  723. else if ( IsInside( from ) )
  724. isValid = false;
  725. else if ( IsInside( to ) )
  726. isValid = false;
  727. else if ( !from.InRange( p, 2 ) )
  728. isValid = false;
  729. else if ( !to.InRange( p, 2 ) )
  730. isValid = false;
  731. if ( !isValid )
  732. from.SendLocalizedMessage( 1062067 ); // In order to transfer the house, you and the recipient must both be outside the building and within two paces of the house sign.
  733. return isValid;
  734. }
  735. public void BeginConfirmTransfer( Mobile from, Mobile to )
  736. {
  737. if ( Deleted || !from.CheckAlive() || !IsOwner( from ) )
  738. return;
  739. if ( from == to )
  740. {
  741. from.SendLocalizedMessage( 1005330 ); // You cannot transfer a house to yourself, silly.
  742. }
  743. else if ( to.Player )
  744. {
  745. if ( BaseHouse.HasAccountHouse( to ) )
  746. {
  747. from.SendLocalizedMessage( 501388 ); // You cannot transfer ownership to another house owner or co-owner!
  748. }
  749. else if ( CheckTransferPosition( from, to ) )
  750. {
  751. from.SendLocalizedMessage( 1005326 ); // Please wait while the other player verifies the transfer.
  752. to.SendGump( new Gumps.HouseTransferGump( from, to, this ) );
  753. }
  754. }
  755. else
  756. {
  757. from.SendLocalizedMessage( 501384 ); // Only a player can own a house!
  758. }
  759. }
  760. public void EndConfirmTransfer( Mobile from, Mobile to )
  761. {
  762. if ( Deleted || !from.CheckAlive() || !IsOwner( from ) )
  763. return;
  764. if (from == to)
  765. {
  766. from.SendLocalizedMessage(1005330); // You cannot transfer a house to yourself, silly.
  767. }
  768. else if (to.Player)
  769. {
  770. if (BaseHouse.HasAccountHouse(to))
  771. {
  772. from.SendLocalizedMessage(501388); // You cannot transfer ownership to another house owner or co-owner!
  773. }
  774. else if (CheckTransferPosition(from, to))
  775. {
  776. NetState fromState = from.NetState, toState = to.NetState;
  777. if (fromState != null && toState != null)
  778. {
  779. if (from.HasTrade)
  780. {
  781. from.SendLocalizedMessage(1062071); // You cannot trade a house while you have other trades pending.
  782. }
  783. else if (to.HasTrade)
  784. {
  785. to.SendLocalizedMessage(1062071); // You cannot trade a house while you have other trades pending.
  786. }
  787. else
  788. {
  789. Container c = fromState.AddTrade(toState);
  790. c.DropItem(new TransferItem(this));
  791. }
  792. }
  793. }
  794. }
  795. else
  796. {
  797. from.SendLocalizedMessage(501384); // Only a player can own a house!
  798. }
  799. }
  800. public void Release( Mobile m, Item item )
  801. {
  802. if ( !IsCoOwner( m ) )
  803. return;
  804. if ( IsLockedDown( item ) )
  805. {
  806. item.PublicOverheadMessage( Server.Network.MessageType.Label, 0x3B2, 501657 );//[no longer locked down]
  807. SetLockdown( item, false );
  808. //TidyItemList( m_LockDowns );
  809. }
  810. else if ( IsSecure( item ) )
  811. {
  812. ReleaseSecure( m, item );
  813. }
  814. else
  815. {
  816. m.SendLocalizedMessage( 501722 );//That isn't locked down...
  817. }
  818. }
  819. public void AddSecure( Mobile m, Item item )
  820. {
  821. if ( m_Secures == null || !IsOwner( m ) )
  822. return;
  823. if ( !IsInside( item ) )
  824. {
  825. m.SendLocalizedMessage( 1005525 ); // That is not in your house
  826. }
  827. else if ( IsLockedDown( item ) )
  828. {
  829. m.SendLocalizedMessage( 1010550 ); // This is already locked down and cannot be secured.
  830. }
  831. else if ( !(item is Container) )
  832. {
  833. LockDown( m, item );
  834. }
  835. else
  836. {
  837. SecureInfo info = null;
  838. for ( int i = 0; info == null && i < m_Secures.Count; ++i )
  839. if ( ((SecureInfo)m_Secures[i]).Item == item )
  840. info = (SecureInfo)m_Secures[i];
  841. if ( info != null )
  842. {
  843. m.SendGump( new Gumps.SetSecureLevelGump( m_Owner, info ) );
  844. }
  845. else if ( item.Parent != null )
  846. {
  847. m.SendLocalizedMessage( 1010423 ); // You cannot secure this, place it on the ground first.
  848. }
  849. else if ( !item.Movable )
  850. {
  851. m.SendLocalizedMessage( 1010424 ); // You cannot secure this.
  852. }
  853. else if ( !IsAosRules && SecureCount >= MaxSecures )
  854. {
  855. // The maximum number of secure items has been reached :
  856. m.SendLocalizedMessage( 1008142, true, MaxSecures.ToString() );
  857. }
  858. else if ( IsAosRules ? !CheckAosLockdowns( 1 ) : ((LockDownCount + 125) >= MaxLockDowns) )
  859. {
  860. m.SendLocalizedMessage( 1005379 ); // That would exceed the maximum lock down limit for this house
  861. }
  862. else if ( IsAosRules && !CheckAosStorage( item.TotalItems ) )
  863. {
  864. m.SendLocalizedMessage( 1061839 ); // This action would exceed the secure storage limit of the house.
  865. }
  866. else
  867. {
  868. info = new SecureInfo( (Container)item, SecureLevel.CoOwners );
  869. item.IsLockedDown = false;
  870. item.IsSecure = true;
  871. m_Secures.Add( info );
  872. m_LockDowns.Remove( item );
  873. item.Movable = false;
  874. m.SendGump( new Gumps.SetSecureLevelGump( m_Owner, info ) );
  875. }
  876. }
  877. }
  878. public bool HasSecureAccess( Mobile m, SecureLevel level )
  879. {
  880. if ( m.AccessLevel >= AccessLevel.GameMaster )
  881. return true;
  882. switch ( level )
  883. {
  884. case SecureLevel.Owner: return IsOwner( m );
  885. case SecureLevel.CoOwners: return IsCoOwner( m );
  886. case SecureLevel.Friends: return IsFriend( m );
  887. case SecureLevel.Anyone: return true;
  888. }
  889. return false;
  890. }
  891. public void ReleaseSecure( Mobile m, Item item )
  892. {
  893. if ( m_Secures == null || !IsOwner( m ) || item is StrongBox )
  894. return;
  895. for ( int i = 0; i < m_Secures.Count; ++i )
  896. {
  897. SecureInfo info = (SecureInfo)m_Secures[i];
  898. if ( info.Item == item && HasSecureAccess( m, info.Level ) )
  899. {
  900. item.IsLockedDown = false;
  901. item.IsSecure = false;
  902. item.Movable = true;
  903. item.SetLastMoved();
  904. item.PublicOverheadMessage( Server.Network.MessageType.Label, 0x3B2, 501656 );//[no longer secure]
  905. m_Secures.RemoveAt( i );
  906. return;
  907. }
  908. }
  909. m.SendLocalizedMessage( 501717 );//This isn't secure...
  910. }
  911. public override bool Decays
  912. {
  913. get
  914. {
  915. return false;
  916. }
  917. }
  918. public void AddStrongBox( Mobile from )
  919. {
  920. if ( !IsCoOwner( from ) )
  921. return;
  922. if ( from == Owner )
  923. {
  924. from.SendLocalizedMessage( 502109 ); // Owners don't get a strong box
  925. return;
  926. }
  927. if ( IsAosRules ? !CheckAosLockdowns( 1 ) : ((LockDownCount + 1) > m_MaxLockDowns) )
  928. {
  929. from.SendLocalizedMessage( 1005379 );//That would exceed the maximum lock down limit for this house
  930. return;
  931. }
  932. foreach ( SecureInfo info in m_Secures )
  933. {
  934. Container c = info.Item;
  935. if ( !c.Deleted && c is StrongBox && ((StrongBox)c).Owner == from )
  936. {
  937. from.SendLocalizedMessage( 502112 );//You already have a strong box
  938. return;
  939. }
  940. }
  941. for ( int i = 0; m_Doors != null && i < m_Doors.Count; ++i )
  942. {
  943. BaseDoor door = m_Doors[i] as BaseDoor;
  944. Point3D p = door.Location;
  945. if ( door.Open )
  946. p = new Point3D( p.X - door.Offset.X, p.Y - door.Offset.Y, p.Z - door.Offset.Z );
  947. if ( (from.Z + 16) >= p.Z && (p.Z + 16) >= from.Z )
  948. {
  949. if ( from.InRange( p, 1 ) )
  950. {
  951. from.SendLocalizedMessage( 502113 ); // You cannot place a strongbox near a door or near steps.
  952. return;
  953. }
  954. }
  955. }
  956. StrongBox sb = new StrongBox( from, this );
  957. sb.Movable = false;
  958. sb.IsLockedDown = false;
  959. sb.IsSecure = true;
  960. m_Secures.Add( new SecureInfo( sb, SecureLevel.CoOwners ) );
  961. sb.MoveToWorld( from.Location, from.Map );
  962. }
  963. public void Kick( Mobile from, Mobile targ )
  964. {
  965. if ( !IsFriend( from ) || m_Friends == null )
  966. return;
  967. if ( targ.AccessLevel > AccessLevel.Player && from.AccessLevel <= targ.AccessLevel )
  968. {
  969. from.SendLocalizedMessage( 501346 ); // Uh oh...a bigger boot may be required!
  970. }
  971. else if ( IsFriend( targ ) )
  972. {
  973. from.SendLocalizedMessage( 501348 ); // You cannot eject a friend of the house!
  974. }
  975. else if ( targ is PlayerVendor )
  976. {
  977. from.SendLocalizedMessage( 501351 ); // You cannot eject a vendor.
  978. }
  979. else if ( !IsInside( targ ) )
  980. {
  981. from.SendLocalizedMessage( 501352 ); // You may not eject someone who is not in your house!
  982. }
  983. else
  984. {
  985. targ.MoveToWorld( BanLocation, Map );
  986. from.SendLocalizedMessage( 1042840, targ.Name ); // ~1_PLAYER NAME~ has been ejected from this house.
  987. targ.SendLocalizedMessage( 501341 ); /* You have been ejected from this house.
  988. * If you persist in entering, you may be banned from the house.
  989. */
  990. }
  991. }
  992. public void RemoveAccess( Mobile from, Mobile targ )
  993. {
  994. if ( !IsFriend( from ) || m_Access == null )
  995. return;
  996. if ( m_Access.Contains( targ ) )
  997. {
  998. m_Access.Remove( targ );
  999. if ( !HasAccess( targ ) && IsInside( targ ) )
  1000. {
  1001. targ.Location = BanLocation;
  1002. targ.SendLocalizedMessage( 1060734 ); // Your access to this house has been revoked.
  1003. }
  1004. from.SendLocalizedMessage( 1050051 ); // The invitation has been revoked.
  1005. }
  1006. }
  1007. public void RemoveBan( Mobile from, Mobile targ )
  1008. {
  1009. if ( !IsCoOwner( from ) || m_Bans == null )
  1010. return;
  1011. if ( m_Bans.Contains( targ ) )
  1012. {
  1013. m_Bans.Remove( targ );
  1014. from.SendLocalizedMessage( 501297 ); // The ban is lifted.
  1015. }
  1016. }
  1017. public void Ban( Mobile from, Mobile targ )
  1018. {
  1019. if ( !IsFriend( from ) || m_Bans == null )
  1020. return;
  1021. if ( targ.AccessLevel > AccessLevel.Player && from.AccessLevel <= targ.AccessLevel )
  1022. {
  1023. from.SendLocalizedMessage( 501354 ); // Uh oh...a bigger boot may be required.
  1024. }
  1025. else if ( IsFriend( targ ) )
  1026. {
  1027. from.SendLocalizedMessage( 501348 ); // You cannot eject a friend of the house!
  1028. }
  1029. else if ( targ is PlayerVendor )
  1030. {
  1031. from.SendLocalizedMessage( 501351 ); // You cannot eject a vendor.
  1032. }
  1033. else if ( m_Bans.Count >= MaxBans )
  1034. {
  1035. from.SendLocalizedMessage( 501355 ); // The ban limit for this house has been reached!
  1036. }
  1037. else if ( IsBanned( targ ) )
  1038. {
  1039. from.SendLocalizedMessage( 501356 ); // This person is already banned!
  1040. }
  1041. else if ( !IsInside( targ ) )
  1042. {
  1043. from.SendLocalizedMessage( 501352 ); // You may not eject someone who is not in your house!
  1044. }
  1045. else if ( !Public && IsAosRules )
  1046. {
  1047. from.SendLocalizedMessage( 1062521 ); // You cannot ban someone from a private house. Revoke their access instead.
  1048. }
  1049. else if ( targ is BaseCreature && ((BaseCreature)targ).NoHouseRestrictions )
  1050. {
  1051. from.SendLocalizedMessage( 1062040 ); // You cannot ban that.
  1052. }
  1053. else
  1054. {
  1055. m_Bans.Add( targ );
  1056. from.SendLocalizedMessage( 1042839, targ.Name ); // ~1_PLAYER_NAME~ has been banned from this house.
  1057. targ.SendLocalizedMessage( 501340 ); // You have been banned from this house.
  1058. targ.MoveToWorld( BanLocation, Map );
  1059. }
  1060. }
  1061. public PlayerVendor FindPlayerVendor()
  1062. {
  1063. Region r = m_Region;
  1064. if ( r == null )
  1065. return null;
  1066. List<Mobile> list = r.Mobiles;
  1067. for ( int i = 0; i < list.Count; ++i )
  1068. {
  1069. PlayerVendor pv = list[i] as PlayerVendor;
  1070. if ( pv != null && Contains( pv ) )
  1071. return pv;
  1072. }
  1073. return null;
  1074. }
  1075. public void GrantAccess( Mobile from, Mobile targ )
  1076. {
  1077. if ( !IsFriend( from ) || m_Access == null )
  1078. return;
  1079. if ( HasAccess( targ ) )
  1080. {
  1081. from.SendLocalizedMessage( 1060729 ); // That person already has access to this house.
  1082. }
  1083. else if ( !targ.Player )
  1084. {
  1085. from.SendLocalizedMessage( 1060712 ); // That is not a player.
  1086. }
  1087. else if ( IsBanned( targ ) )
  1088. {
  1089. from.SendLocalizedMessage( 501367 ); // This person is banned! Unban them first.
  1090. }
  1091. else
  1092. {
  1093. m_Access.Add( targ );
  1094. targ.SendLocalizedMessage( 1060735 ); // You have been granted access to this house.
  1095. }
  1096. }
  1097. public void AddCoOwner( Mobile from, Mobile targ )
  1098. {
  1099. if ( !IsOwner( from ) || m_CoOwners == null || m_Friends == null )
  1100. return;
  1101. if ( IsOwner( targ ) )
  1102. {
  1103. from.SendLocalizedMessage( 501360 ); // This person is already the house owner!
  1104. }
  1105. else if ( m_Friends.Contains( targ ) )
  1106. {
  1107. from.SendLocalizedMessage( 501361 ); // This person is a friend of the house. Remove them first.
  1108. }
  1109. else if ( !targ.Player )
  1110. {
  1111. from.SendLocalizedMessage( 501362 ); // That can't be a co-owner of the house.
  1112. }
  1113. else if ( HasAccountHouse( targ ) )
  1114. {
  1115. from.SendLocalizedMessage( 501364 ); // That person is already a house owner.
  1116. }
  1117. else if ( IsBanned( targ ) )
  1118. {
  1119. from.SendLocalizedMessage( 501367 ); // This person is banned! Unban them first.
  1120. }
  1121. else if ( m_CoOwners.Count >= MaxCoOwners )
  1122. {
  1123. from.SendLocalizedMessage( 501368 ); // Your co-owner list is full!
  1124. }
  1125. else if ( m_CoOwners.Contains( targ ) )
  1126. {
  1127. from.SendLocalizedMessage( 501369 ); // This person is already on your co-owner list!
  1128. }
  1129. else
  1130. {
  1131. m_CoOwners.Add( targ );
  1132. targ.Delta( MobileDelta.Noto );
  1133. targ.SendLocalizedMessage( 501343 ); // You have been made a co-owner of this house.
  1134. }
  1135. }
  1136. public void RemoveCoOwner( Mobile from, Mobile targ )
  1137. {
  1138. if ( !IsOwner( from ) || m_CoOwners == null )
  1139. return;
  1140. if ( m_CoOwners.Contains( targ ) )
  1141. {
  1142. m_CoOwners.Remove( targ );
  1143. targ.Delta( MobileDelta.Noto );
  1144. from.SendLocalizedMessage( 501299 ); // Co-owner removed from list.
  1145. targ.SendLocalizedMessage( 501300 ); // You have been removed as a house co-owner.
  1146. foreach ( SecureInfo info in m_Secures )
  1147. {
  1148. Container c = info.Item;
  1149. if ( c is StrongBox && ((StrongBox)c).Owner == targ )
  1150. {
  1151. c.IsLockedDown = false;
  1152. c.IsSecure = false;
  1153. m_Secures.Remove( c );
  1154. c.Destroy();
  1155. break;
  1156. }
  1157. }
  1158. }
  1159. }
  1160. public void AddFriend( Mobile from, Mobile targ )
  1161. {
  1162. if ( !IsCoOwner( from ) || m_Friends == null || m_CoOwners == null )
  1163. return;
  1164. if ( IsOwner( targ ) )
  1165. {
  1166. from.SendLocalizedMessage( 501370 ); // This person is already an owner of the house!
  1167. }
  1168. else if ( m_CoOwners.Contains( targ ) )
  1169. {
  1170. from.SendLocalizedMessage( 501369 ); // This person is already on your co-owner list!
  1171. }
  1172. else if ( !targ.Player )
  1173. {
  1174. from.SendLocalizedMessage( 501371 ); // That can't be a friend of the house.
  1175. }
  1176. else if ( IsBanned( targ ) )
  1177. {
  1178. from.SendLocalizedMessage( 501374 ); // This person is banned! Unban them first.
  1179. }
  1180. else if ( m_Friends.Count >= MaxFriends )
  1181. {
  1182. from.SendLocalizedMessage( 501375 ); // Your friends list is full!
  1183. }
  1184. else if ( m_Friends.Contains( targ ) )
  1185. {
  1186. from.SendLocalizedMessage( 501376 ); // This person is already on your friends list!
  1187. }
  1188. else
  1189. {
  1190. m_Friends.Add( targ );
  1191. targ.Delta( MobileDelta.Noto );
  1192. targ.SendLocalizedMessage( 501337 ); // You have been made a friend of this house.
  1193. }
  1194. }
  1195. public void RemoveFriend( Mobile from, Mobile targ )
  1196. {
  1197. if ( !IsCoOwner( from ) || m_Friends == null )
  1198. return;
  1199. if ( m_Friends.Contains( targ ) )
  1200. {
  1201. m_Friends.Remove( targ );
  1202. targ.Delta( MobileDelta.Noto );
  1203. from.SendLocalizedMessage( 501298 ); // Friend removed from list.
  1204. targ.SendLocalizedMessage( 1060751 ); // You are no longer a friend of this house.
  1205. }
  1206. }
  1207. public override void Serialize( GenericWriter writer )
  1208. {
  1209. base.Serialize( writer );
  1210. writer.Write( (int) 10 ); // version
  1211. writer.Write( (int) m_Visits );
  1212. writer.Write( (int) m_Price );
  1213. writer.WriteMobileList( m_Access );
  1214. writer.Write( m_BuiltOn );
  1215. writer.Write( m_LastTraded );
  1216. writer.WriteItemList( m_Addons, true );
  1217. writer.Write( m_Secures.Count );
  1218. for ( int i = 0; i < m_Secures.Count; ++i )
  1219. ((SecureInfo)m_Secures[i]).Serialize( writer );
  1220. writer.Write( m_Public );
  1221. writer.Write( BanLocation );
  1222. writer.Write( m_Owner );
  1223. // Version 5 no longer serializes region coords
  1224. /*writer.Write( (int)m_Region.Coords.Count );
  1225. foreach( Rectangle2D rect in m_Region.Coords )
  1226. {
  1227. writer.Write( rect );
  1228. }*/
  1229. writer.WriteMobileList( m_CoOwners, true );
  1230. writer.WriteMobileList( m_Friends, true );
  1231. writer.WriteMobileList( m_Bans, true );
  1232. writer.Write( m_Sign );
  1233. writer.Write( m_Trash );
  1234. writer.WriteItemList( m_Doors, true );
  1235. writer.WriteItemList( m_LockDowns, true );
  1236. //writer.WriteItemList( m_Secures, true );
  1237. writer.Write( (int) m_MaxLockDowns );
  1238. writer.Write( (int) m_MaxSecures );
  1239. // Items in locked down containers that aren't locked down themselves must decay!
  1240. for ( int i = 0; i < m_LockDowns.Count; ++i )
  1241. {
  1242. Item item = (Item)m_LockDowns[i];
  1243. if ( item is Container && !(item is BaseBoard) )
  1244. {
  1245. var cont = (Container)item;
  1246. var children = cont.Items;
  1247. for ( int j = 0; j < children.Count; ++j )
  1248. {
  1249. Item child = (Item)children[j];
  1250. if ( child.Decays && !child.IsLockedDown && !child.IsSecure && (child.LastMoved + child.DecayTime) <= DateTime.Now )
  1251. Timer.DelayCall( TimeSpan.Zero, new TimerCallback( child.Delete ) );
  1252. }
  1253. }
  1254. }
  1255. }
  1256. public override void Deserialize( GenericReader reader )
  1257. {
  1258. base.Deserialize( reader );
  1259. int version = reader.ReadInt();
  1260. int count;
  1261. m_Region = new HouseRegion( this );
  1262. switch ( version )
  1263. {
  1264. case 10: // just a signal for updates
  1265. case 9:
  1266. {
  1267. m_Visits = reader.ReadInt();
  1268. goto case 8;
  1269. }
  1270. case 8:
  1271. {
  1272. m_Price = reader.ReadInt();
  1273. goto case 7;
  1274. }
  1275. case 7:
  1276. {
  1277. m_Access = reader.ReadMobileList();
  1278. goto case 6;
  1279. }
  1280. case 6:
  1281. {
  1282. m_BuiltOn = reader.ReadDateTime();
  1283. m_LastTraded = reader.ReadDateTime();
  1284. goto case 5;
  1285. }
  1286. case 5: // just removed fields
  1287. case 4:
  1288. {
  1289. m_Addons = reader.ReadItemList();
  1290. goto case 3;
  1291. }
  1292. case 3:
  1293. {
  1294. count = reader.ReadInt();
  1295. m_Secures = new ArrayList( count );
  1296. for ( int i = 0; i < count; ++i )
  1297. {
  1298. SecureInfo info = new SecureInfo( reader );
  1299. if ( info.Item != null )
  1300. {
  1301. info.Item.IsSecure = true;
  1302. m_Secures.Add( info );
  1303. }
  1304. }
  1305. goto case 2;
  1306. }
  1307. case 2:
  1308. {
  1309. m_Public = reader.ReadBool();
  1310. goto case 1;
  1311. }
  1312. case 1:
  1313. {
  1314. m_Region.GoLocation = reader.ReadPoint3D();
  1315. goto case 0;
  1316. }
  1317. case 0:
  1318. {
  1319. if ( version < 4 )
  1320. m_Addons = new ArrayList();
  1321. if ( version < 7 )
  1322. m_Access = new ArrayList();
  1323. if ( version < 8 )
  1324. m_Price = DefaultPrice;
  1325. m_Owner = reader.ReadMobile();
  1326. if ( version < 5 )
  1327. {
  1328. count = reader.ReadInt();
  1329. for(int i=0;i<count;i++)
  1330. reader.ReadRect2D();
  1331. }
  1332. UpdateRegionArea();
  1333. Region.AddRegion( m_Region );
  1334. m_CoOwners = reader.ReadMobileList();
  1335. m_Friends = reader.ReadMobileList();
  1336. m_Bans = reader.ReadMobileList();
  1337. m_Sign = reader.ReadItem() as HouseSign;
  1338. m_Trash = reader.ReadItem() as TrashBarrel;
  1339. m_Doors = reader.ReadItemList();
  1340. m_LockDowns = reader.ReadItemList();
  1341. for ( int i = 0; i < m_LockDowns.Count; ++i )
  1342. ((Item)m_LockDowns[i]).IsLockedDown = true;
  1343. if ( version < 3 )
  1344. {
  1345. ArrayList items = reader.ReadItemList();
  1346. m_Secures = new ArrayList( items.Count );
  1347. for ( int i = 0; i < items.Count; ++i )
  1348. {
  1349. Container c = items[i] as Container;
  1350. if ( c != null )
  1351. {
  1352. c.IsSecure = true;
  1353. m_Secures.Add( new SecureInfo( c, SecureLevel.CoOwners ) );
  1354. }
  1355. }
  1356. }
  1357. m_MaxLockDowns = reader.ReadInt();
  1358. m_MaxSecures = reader.ReadInt();
  1359. if ( (Map == null || Map == Map.Internal) && Location == Point3D.Zero )
  1360. Delete();
  1361. if ( m_Owner != null )
  1362. {
  1363. ArrayList list = (ArrayList)m_Table[m_Owner];
  1364. if ( list == null )
  1365. m_Table[m_Owner] = list = new ArrayList();
  1366. list.Add( this );
  1367. }
  1368. break;
  1369. }
  1370. }
  1371. if ( version <= 1 )
  1372. ChangeSignType( 0xBD2 );//private house, plain brass sign
  1373. if ( version < 10 )
  1374. {
  1375. /* NOTE: This can exceed the house lockdown limit. It must be this way, because
  1376. * we do not want players' items to decay without them knowing. Or not even
  1377. * having a chance to fix it themselves.
  1378. */
  1379. Timer.DelayCall( TimeSpan.Zero, new TimerCallback( FixLockdowns_Sandbox ) );
  1380. }
  1381. }
  1382. private void FixLockdowns_Sandbox()
  1383. {
  1384. ArrayList lockDowns = new ArrayList();
  1385. for ( int i = 0; m_LockDowns != null && i < m_LockDowns.Count; ++i )
  1386. {
  1387. Item item = (Item)m_LockDowns[i];
  1388. if ( item is Container )
  1389. lockDowns.Add( item );
  1390. }
  1391. for ( int i = 0; i < lockDowns.Count; ++i )
  1392. SetLockdown( (Item)lockDowns[i], true, true );
  1393. }
  1394. [CommandProperty( AccessLevel.GameMaster )]
  1395. public Mobile Owner
  1396. {
  1397. get
  1398. {
  1399. return m_Owner;
  1400. }
  1401. set
  1402. {
  1403. if ( m_Owner != null )
  1404. {
  1405. ArrayList list = (ArrayList)m_Table[m_Owner];
  1406. if ( list == null )
  1407. m_Table[m_Owner] = list = new ArrayList();
  1408. list.Remove( this );
  1409. m_Owner.Delta( MobileDelta.Noto );
  1410. }
  1411. m_Owner = value;
  1412. if ( m_Owner != null )
  1413. {
  1414. ArrayList list = (ArrayList)m_Table[m_Owner];
  1415. if ( list == null )
  1416. m_Table[m_Owner] = list = new ArrayList();
  1417. list.Add( this );
  1418. m_Owner.Delta( MobileDelta.Noto );
  1419. }
  1420. if ( m_Sign != null )
  1421. m_Sign.InvalidateProperties();
  1422. }
  1423. }
  1424. [CommandProperty( AccessLevel.GameMaster )]
  1425. public int Visits
  1426. {
  1427. get{ return m_Visits; }
  1428. set{ m_Visits = value; }
  1429. }
  1430. [CommandProperty( AccessLevel.GameMaster )]
  1431. public bool Public
  1432. {
  1433. get
  1434. {
  1435. return m_Public;
  1436. }
  1437. set
  1438. {
  1439. if ( m_Public != value )
  1440. {
  1441. m_Public = value;
  1442. if ( !m_Public )//privatizing the house, change to brass sign
  1443. ChangeSignType( 0xBD2 );
  1444. if ( m_Sign != null )
  1445. m_Sign.InvalidateProperties();
  1446. }
  1447. }
  1448. }
  1449. [CommandProperty( AccessLevel.GameMaster )]
  1450. public int MaxSecures
  1451. {
  1452. get
  1453. {
  1454. return m_MaxSecures;
  1455. }
  1456. set
  1457. {
  1458. m_MaxSecures = value;
  1459. }
  1460. }
  1461. [CommandProperty( AccessLevel.GameMaster )]
  1462. public Point3D BanLocation
  1463. {
  1464. get
  1465. {
  1466. return m_Region.GoLocation;
  1467. }
  1468. set
  1469. {
  1470. m_Region.GoLocation = new Point3D( m_Region.GoLocation.X + value.X, m_Region.GoLocation.Y + value.Y, m_Region.GoLocation.Z + value.Z );
  1471. }
  1472. }
  1473. [CommandProperty( AccessLevel.GameMaster )]
  1474. public int MaxLockDowns
  1475. {
  1476. get
  1477. {
  1478. return m_MaxLockDowns;
  1479. }
  1480. set
  1481. {
  1482. m_MaxLockDowns = value;
  1483. }
  1484. }
  1485. public Region Region{ get{ return m_Region; } }
  1486. public ArrayList CoOwners{ get{ return m_CoOwners; } set{ m_CoOwners = value; } }
  1487. public ArrayList Friends{ get{ return m_Friends; } set{ m_Friends = value; } }
  1488. public ArrayList Access{ get{ return m_Access; } set{ m_Access = value; } }
  1489. public ArrayList Bans{ get{ return m_Bans; } set{ m_Bans = value; } }
  1490. public ArrayList Doors{ get{ return m_Doors; } set{ m_Doors = value; } }
  1491. public int LockDownCount
  1492. {
  1493. get
  1494. {
  1495. int count = 0;
  1496. if ( m_LockDowns != null )
  1497. count += m_LockDowns.Count;
  1498. if ( m_Secures != null )
  1499. {
  1500. for ( int i = 0; i < m_Secures.Count; ++i )
  1501. {
  1502. SecureInfo info = (SecureInfo)m_Secures[i];
  1503. if ( info.Item.Deleted )
  1504. continue;
  1505. else if ( info.Item is StrongBox )
  1506. count += 1;
  1507. else
  1508. count += 125;
  1509. }
  1510. }
  1511. return count;
  1512. }
  1513. }
  1514. public int SecureCount
  1515. {
  1516. get
  1517. {
  1518. int count = 0;
  1519. if ( m_Secures != null )
  1520. {
  1521. for ( int i = 0; i < m_Secures.Count; i++ )
  1522. {
  1523. SecureInfo info = (SecureInfo)m_Secures[i];
  1524. if ( info.Item.Deleted )
  1525. continue;
  1526. else if ( !(info.Item is StrongBox) )
  1527. count += 1;
  1528. }
  1529. }
  1530. return count;
  1531. }
  1532. }
  1533. public ArrayList Addons{ get{ return m_Addons; } set{ m_Addons = value; } }
  1534. public ArrayList LockDowns{ get{ return m_LockDowns; } }
  1535. public ArrayList Secures{ get{ return m_Secures; } }
  1536. public HouseSign Sign{ get{ return m_Sign; } set{ m_Sign = value; } }
  1537. public DateTime BuiltOn
  1538. {
  1539. get{ return m_BuiltOn; }
  1540. set{ m_BuiltOn = value; }
  1541. }
  1542. public DateTime LastTraded
  1543. {
  1544. get{ return m_LastTraded; }
  1545. set{ m_LastTraded = value; }
  1546. }
  1547. public override void OnDelete()
  1548. {
  1549. new FixColumnTimer( this ).Start();
  1550. if ( m_Region != null )
  1551. Region.RemoveRegion( m_Region );
  1552. base.OnDelete();
  1553. }
  1554. private class FixColumnTimer : Timer
  1555. {
  1556. private Map m_Map;
  1557. private int m_StartX, m_StartY, m_EndX, m_EndY;
  1558. public FixColumnTimer( BaseMulti multi ) : base( TimeSpan.Zero )
  1559. {
  1560. m_Map = multi.Map;
  1561. MultiComponentList mcl = multi.Components;
  1562. m_StartX = multi.X + mcl.Min.X;
  1563. m_StartY = multi.Y + mcl.Min.Y;
  1564. m_EndX = multi.X + mcl.Max.X;
  1565. m_EndY = multi.Y + mcl.Max.Y;
  1566. }
  1567. protected override void OnTick()
  1568. {
  1569. if ( m_Map == null )
  1570. return;
  1571. for ( int x = m_StartX; x <= m_EndX; ++x )
  1572. for ( int y = m_StartY; y <= m_EndY; ++y )
  1573. m_Map.FixColumn( x, y );
  1574. }
  1575. }
  1576. public override void OnAfterDelete()
  1577. {
  1578. base.OnAfterDelete();
  1579. if ( m_Owner != null )
  1580. {
  1581. ArrayList list = (ArrayList)m_Table[m_Owner];
  1582. if ( list == null )
  1583. m_Table[m_Owner] = list = new ArrayList();
  1584. list.Remove( this );
  1585. }
  1586. Region.RemoveRegion( m_Region );
  1587. if ( m_Sign != null )
  1588. m_Sign.Delete();
  1589. if ( m_Trash != null )
  1590. m_Trash.Delete();
  1591. if ( m_Doors != null )
  1592. {
  1593. for ( int i = 0; i < m_Doors.Count; ++i )
  1594. {
  1595. Item item = (Item)m_Doors[i];
  1596. if ( item != null )
  1597. item.Delete();
  1598. }
  1599. m_Doors.Clear();
  1600. }
  1601. if ( m_LockDowns != null )
  1602. {
  1603. for ( int i = 0; i < m_LockDowns.Count; ++i )
  1604. {
  1605. Item item = (Item)m_LockDowns[i];
  1606. if ( item != null )
  1607. {
  1608. item.IsLockedDown = false;
  1609. item.IsSecure = false;
  1610. item.Movable = true;
  1611. item.SetLastMoved();
  1612. }
  1613. }
  1614. m_LockDowns.Clear();
  1615. }
  1616. if ( m_Secures != null )
  1617. {
  1618. for ( int i = 0; i < m_Secures.Count; ++i )
  1619. {
  1620. SecureInfo info = (SecureInfo)m_Secures[i];
  1621. if ( info.Item is StrongBox )
  1622. {
  1623. info.Item.Destroy();
  1624. }
  1625. else
  1626. {
  1627. info.Item.IsLockedDown = false;
  1628. info.Item.IsSecure = false;
  1629. info.Item.Movable = true;
  1630. info.Item.SetLastMoved();
  1631. }
  1632. }
  1633. m_Secures.Clear();
  1634. }
  1635. if ( m_Addons != null )
  1636. {
  1637. for ( int i = 0; i < m_Addons.Count; ++i )
  1638. {
  1639. Item item = (Item)m_Addons[i];
  1640. if ( item != null )
  1641. item.Delete();
  1642. }
  1643. m_Addons.Clear();
  1644. }
  1645. }
  1646. public static bool HasHouse( Mobile m )
  1647. {
  1648. if ( m == null )
  1649. return false;
  1650. ArrayList list = (ArrayList)m_Table[m];
  1651. if ( list == null )
  1652. return false;
  1653. for ( int i = 0; i < list.Count; ++i )
  1654. {
  1655. BaseHouse h = (BaseHouse)list[i];
  1656. if ( !h.Deleted )
  1657. return true;
  1658. }
  1659. return false;
  1660. }
  1661. public static bool HasAccountHouse( Mobile m )
  1662. {
  1663. Account a = m.Account as Account;
  1664. if ( a == null )
  1665. return false;
  1666. for ( int i = 0; i < 5; ++i )
  1667. if ( a[i] != null && HasHouse( a[i] ) )
  1668. return true;
  1669. return false;
  1670. }
  1671. public bool CheckAccount( Mobile mobCheck, Mobile accCheck )
  1672. {
  1673. if ( accCheck != null )
  1674. {
  1675. Account a = accCheck.Account as Account;
  1676. if ( a != null )
  1677. {
  1678. for ( int i = 0; i < 5; ++i )
  1679. …

Large files files are truncated, but you can click here to view the full file