Guest User

corpse.cs Runuo 2.3

a guest
Mar 8th, 2015
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.69 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Server;
  5. using Server.ContextMenus;
  6. using Server.Engines.PartySystem;
  7. using Server.Engines.Quests;
  8. using Server.Engines.Quests.Doom;
  9. using Server.Engines.Quests.Haven;
  10. using Server.Guilds;
  11. using Server.Misc;
  12. using Server.Mobiles;
  13.  
  14. using Server.Network;
  15. namespace Server.Items
  16. {
  17. public interface IDevourer
  18. {
  19. bool Devour( Corpse corpse );
  20. }
  21.  
  22. [Flags]
  23. public enum CorpseFlag
  24. {
  25. None = 0x00000000,
  26.  
  27. /// <summary>
  28. /// Has this corpse been carved?
  29. /// </summary>
  30. Carved = 0x00000001,
  31.  
  32. /// <summary>
  33. /// If true, this corpse will not turn into bones
  34. /// </summary>
  35. NoBones = 0x00000002,
  36.  
  37. /// <summary>
  38. /// If true, the corpse has turned into bones
  39. /// </summary>
  40. IsBones = 0x00000004,
  41.  
  42. /// <summary>
  43. /// Has this corpse yet been visited by a taxidermist?
  44. /// </summary>
  45. VisitedByTaxidermist = 0x00000008,
  46.  
  47. /// <summary>
  48. /// Has this corpse yet been used to channel spiritual energy? (AOS Spirit Speak)
  49. /// </summary>
  50. Channeled = 0x00000010,
  51.  
  52. /// <summary>
  53. /// Was the owner criminal when he died?
  54. /// </summary>
  55. Criminal = 0x00000020,
  56.  
  57. /// <summary>
  58. /// Has this corpse been animated?
  59. /// </summary>
  60. Animated = 0x00000040,
  61.  
  62. /// <summary>
  63. /// Has this corpse been self looted?
  64. /// </summary>
  65. SelfLooted = 0x00000080,
  66. }
  67.  
  68. public class Corpse : Container, ICarvable
  69. {
  70. private Mobile m_Owner; // Whos corpse is this?
  71. private Mobile m_Killer; // Who killed the owner?
  72. private CorpseFlag m_Flags; // @see CorpseFlag
  73.  
  74. private List<Mobile> m_Looters; // Who's looted this corpse?
  75. private List<Item> m_EquipItems; // List of dropped equipment when the owner died. Ingame, these items display /on/ the corpse, not just inside
  76. private List<Item> m_RestoreEquip; // List of items equipped when the owner died. Includes insured and blessed items.
  77. private List<Mobile> m_Aggressors; // Anyone from this list will be able to loot this corpse; we attacked them, or they attacked us when we were freely attackable
  78.  
  79. private string m_CorpseName; // Value of the CorpseNameAttribute attached to the owner when he died -or- null if the owner had no CorpseNameAttribute; use "the remains of ~name~"
  80. private IDevourer m_Devourer; // The creature that devoured this corpse
  81.  
  82. // For notoriety:
  83. private AccessLevel m_AccessLevel; // Which AccessLevel the owner had when he died
  84. private Guild m_Guild; // Which Guild the owner was in when he died
  85. private int m_Kills; // How many kills the owner had when he died
  86.  
  87. private DateTime m_TimeOfDeath; // What time was this corpse created?
  88.  
  89. private HairInfo m_Hair; // This contains the hair of the owner
  90. private FacialHairInfo m_FacialHair; // This contains the facial hair of the owner
  91.  
  92. // For Forensics Evaluation
  93. public string m_Forensicist; // Name of the first PlayerMobile who used Forensic Evaluation on the corpse
  94.  
  95. public static readonly TimeSpan MonsterLootRightSacrifice = TimeSpan.FromMinutes( 2.0 );
  96.  
  97. public static readonly TimeSpan InstancedCorpseTime = TimeSpan.FromMinutes( 3.0 );
  98.  
  99. [CommandProperty( AccessLevel.GameMaster )]
  100. public virtual bool InstancedCorpse
  101. {
  102. get
  103. {
  104. if ( !Core.SE )
  105. return false;
  106.  
  107. return ( DateTime.Now < (m_TimeOfDeath + InstancedCorpseTime) );
  108. }
  109. }
  110.  
  111. private Dictionary<Item, InstancedItemInfo> m_InstancedItems;
  112.  
  113. private class InstancedItemInfo
  114. {
  115. private Mobile m_Mobile;
  116. private Item m_Item;
  117.  
  118. private bool m_Perpetual; //Needed for Rummaged stuff. CONTRARY to the Patchlog, cause a later FoF contradicts it. Verify on OSI.
  119. public bool Perpetual { get { return m_Perpetual; } set { m_Perpetual = value; } }
  120.  
  121. public InstancedItemInfo( Item i, Mobile m )
  122. {
  123. m_Item = i;
  124. m_Mobile = m;
  125. }
  126.  
  127. public bool IsOwner( Mobile m )
  128. {
  129. if ( m_Item.LootType == LootType.Cursed ) //Cursed Items are part of everyone's instanced corpse... (?)
  130. return true;
  131.  
  132. if ( m == null )
  133. return false; //sanity
  134.  
  135. if ( m_Mobile == m )
  136. return true;
  137.  
  138. Party myParty = Party.Get( m_Mobile );
  139.  
  140. return (myParty != null && myParty == Party.Get( m ));
  141. }
  142. }
  143. public override bool IsChildVisibleTo( Mobile m, Item child )
  144.  
  145. {
  146. if ( !m.Player || m.AccessLevel > AccessLevel.Player ) //Staff and creatures not subject to instancing.
  147. return true;
  148.  
  149. if ( m_InstancedItems != null )
  150. {
  151. InstancedItemInfo info;
  152.  
  153. if ( m_InstancedItems.TryGetValue( child, out info ) && (InstancedCorpse || info.Perpetual) )
  154. {
  155. return info.IsOwner( m ); //IsOwner checks Party stuff.
  156. }
  157. }
  158.  
  159. return true;
  160. }
  161.  
  162. private void AssignInstancedLoot()
  163. {
  164. if ( m_Aggressors.Count == 0 || this.Items.Count == 0 )
  165. return;
  166.  
  167. if ( m_InstancedItems == null )
  168. m_InstancedItems = new Dictionary<Item, InstancedItemInfo>();
  169.  
  170. List<Item> m_Stackables = new List<Item>();
  171. List<Item> m_Unstackables = new List<Item>();
  172.  
  173. for ( int i = 0; i < this.Items.Count; i++ )
  174. {
  175. Item item = this.Items[i];
  176.  
  177. if ( item.LootType != LootType.Cursed ) //Don't have curesd items take up someone's item spot.. (?)
  178. {
  179. if ( item.Stackable )
  180. m_Stackables.Add( item );
  181. else
  182. m_Unstackables.Add( item );
  183. }
  184. }
  185.  
  186. List<Mobile> attackers = new List<Mobile>( m_Aggressors );
  187.  
  188. for ( int i = 1; i < attackers.Count -1; i++ ) //randomize
  189. {
  190. int rand = Utility.Random( i + 1 );
  191.  
  192. Mobile temp = attackers[rand];
  193. attackers[rand] = attackers[i];
  194. attackers[i] = temp;
  195. }
  196.  
  197. //stackables first, for the remaining stackables, have those be randomly added after
  198.  
  199. for ( int i = 0; i < m_Stackables.Count; i++ )
  200. {
  201. Item item = m_Stackables[i];
  202.  
  203. if ( item.Amount >= attackers.Count )
  204. {
  205. int amountPerAttacker = (item.Amount / attackers.Count);
  206. int remainder = (item.Amount % attackers.Count);
  207.  
  208. for ( int j = 0; j < ((remainder == 0) ? attackers.Count -1 : attackers.Count); j++ )
  209. {
  210. Item splitItem = Mobile.LiftItemDupe( item, item.Amount - amountPerAttacker ); //LiftItemDupe automagically adds it as a child item to the corpse
  211.  
  212. m_InstancedItems.Add( splitItem, new InstancedItemInfo( splitItem, attackers[j] ) );
  213.  
  214. //What happens to the remaining portion? TEMP FOR NOW UNTIL OSI VERIFICATION: Treat as Single Item.
  215. }
  216.  
  217. if ( remainder == 0 )
  218. {
  219. m_InstancedItems.Add( item, new InstancedItemInfo( item, attackers[attackers.Count - 1] ) );
  220. //Add in the original item (which has an equal amount as the others) to the instance for the last attacker, cause it wasn't added above.
  221. }
  222. else
  223. {
  224. m_Unstackables.Add( item );
  225. }
  226. }
  227. else
  228. {
  229. //What happens in this case? TEMP FOR NOW UNTIL OSI VERIFICATION: Treat as Single Item.
  230. m_Unstackables.Add( item );
  231. }
  232. }
  233.  
  234. for ( int i = 0; i < m_Unstackables.Count; i++ )
  235. {
  236. Mobile m = attackers[i % attackers.Count];
  237. Item item = m_Unstackables[i];
  238.  
  239. m_InstancedItems.Add( item, new InstancedItemInfo( item, m ) );
  240. }
  241. }
  242.  
  243. public void AddCarvedItem( Item carved, Mobile carver )
  244. {
  245. this.DropItem( carved );
  246.  
  247. if ( this.InstancedCorpse )
  248. {
  249. if ( m_InstancedItems == null )
  250. m_InstancedItems = new Dictionary<Item, InstancedItemInfo>();
  251.  
  252. m_InstancedItems.Add( carved, new InstancedItemInfo( carved, carver ) );
  253. }
  254. }
  255.  
  256. public override bool IsDecoContainer
  257. {
  258. get{ return false; }
  259. }
  260.  
  261. [CommandProperty( AccessLevel.GameMaster )]
  262. public DateTime TimeOfDeath
  263. {
  264. get{ return m_TimeOfDeath; }
  265. set{ m_TimeOfDeath = value; }
  266. }
  267.  
  268. public override bool DisplayWeight { get { return false; } }
  269.  
  270. public HairInfo Hair { get { return m_Hair; } }
  271. public FacialHairInfo FacialHair { get { return m_FacialHair; } }
  272.  
  273. [CommandProperty( AccessLevel.GameMaster )]
  274. public bool IsBones
  275. {
  276. get { return GetFlag( CorpseFlag.IsBones ); }
  277. }
  278.  
  279. [CommandProperty( AccessLevel.GameMaster )]
  280. public bool Devoured
  281. {
  282. get { return (m_Devourer != null); }
  283. }
  284.  
  285. [CommandProperty( AccessLevel.GameMaster )]
  286. public bool Carved
  287. {
  288. get{ return GetFlag( CorpseFlag.Carved ); }
  289. set { SetFlag( CorpseFlag.Carved, value ); }
  290. }
  291.  
  292. [CommandProperty( AccessLevel.GameMaster )]
  293. public bool VisitedByTaxidermist
  294. {
  295. get { return GetFlag( CorpseFlag.VisitedByTaxidermist ); }
  296. set { SetFlag( CorpseFlag.VisitedByTaxidermist, value ); }
  297. }
  298.  
  299. [CommandProperty( AccessLevel.GameMaster )]
  300. public bool Channeled
  301. {
  302. get { return GetFlag( CorpseFlag.Channeled ); }
  303. set { SetFlag( CorpseFlag.Channeled, value ); }
  304. }
  305.  
  306. [CommandProperty( AccessLevel.GameMaster )]
  307. public bool Animated
  308. {
  309. get { return GetFlag( CorpseFlag.Animated ); }
  310. set { SetFlag( CorpseFlag.Animated, value ); }
  311. }
  312.  
  313. [CommandProperty( AccessLevel.GameMaster )]
  314. public bool SelfLooted
  315. {
  316. get { return GetFlag( CorpseFlag.SelfLooted ); }
  317. set { SetFlag( CorpseFlag.SelfLooted, value ); }
  318. }
  319.  
  320. [CommandProperty( AccessLevel.GameMaster )]
  321. public AccessLevel AccessLevel
  322. {
  323. get{ return m_AccessLevel; }
  324. }
  325.  
  326. public List<Mobile> Aggressors
  327. {
  328. get{ return m_Aggressors; }
  329. }
  330.  
  331. public List<Mobile> Looters
  332. {
  333. get{ return m_Looters; }
  334. }
  335.  
  336. [CommandProperty( AccessLevel.GameMaster )]
  337. public Mobile Killer
  338. {
  339. get{ return m_Killer; }
  340. }
  341.  
  342. public List<Item> EquipItems
  343. {
  344. get{ return m_EquipItems; }
  345. }
  346.  
  347. public List<Item> RestoreEquip
  348. {
  349. get { return m_RestoreEquip; }
  350. set { m_RestoreEquip = value; }
  351. }
  352.  
  353. public Guild Guild
  354. {
  355. get{ return m_Guild; }
  356. }
  357.  
  358. [CommandProperty( AccessLevel.GameMaster )]
  359. public int Kills
  360. {
  361. get{ return m_Kills; }
  362. set{ m_Kills = value; }
  363. }
  364.  
  365. [CommandProperty( AccessLevel.GameMaster )]
  366. public bool Criminal
  367. {
  368. get { return GetFlag( CorpseFlag.Criminal ); }
  369. set { SetFlag( CorpseFlag.Criminal, value ); }
  370. }
  371.  
  372. [CommandProperty( AccessLevel.GameMaster )]
  373. public Mobile Owner
  374. {
  375. get{ return m_Owner; }
  376. }
  377.  
  378. public void TurnToBones()
  379. {
  380. if ( Deleted )
  381. return;
  382.  
  383. ProcessDelta();
  384. SendRemovePacket();
  385. ItemID = Utility.Random( 0xECA, 9 ); // bone graphic
  386. Hue = 0;
  387. ProcessDelta();
  388.  
  389. SetFlag( CorpseFlag.NoBones, true );
  390. SetFlag( CorpseFlag.IsBones, true );
  391.  
  392. BeginDecay( m_BoneDecayTime );
  393. }
  394.  
  395. private static TimeSpan m_DefaultDecayTime = TimeSpan.FromMinutes( 7.0 );
  396. private static TimeSpan m_BoneDecayTime = TimeSpan.FromMinutes( 7.0 );
  397.  
  398. private Timer m_DecayTimer;
  399. private DateTime m_DecayTime;
  400.  
  401. public void BeginDecay( TimeSpan delay )
  402. {
  403. if ( m_DecayTimer != null )
  404. m_DecayTimer.Stop();
  405.  
  406. m_DecayTime = DateTime.Now + delay;
  407.  
  408. m_DecayTimer = new InternalTimer( this, delay );
  409. m_DecayTimer.Start();
  410. }
  411.  
  412. public override void OnAfterDelete()
  413. {
  414. if ( m_DecayTimer != null )
  415. m_DecayTimer.Stop();
  416.  
  417. m_DecayTimer = null;
  418. }
  419.  
  420. private class InternalTimer : Timer
  421. {
  422. private Corpse m_Corpse;
  423.  
  424. public InternalTimer( Corpse c, TimeSpan delay ) : base( delay )
  425. {
  426. m_Corpse = c;
  427. Priority = TimerPriority.FiveSeconds;
  428. }
  429.  
  430. protected override void OnTick()
  431. {
  432. if ( !m_Corpse.GetFlag( CorpseFlag.NoBones ) )
  433. m_Corpse.TurnToBones();
  434. else
  435. m_Corpse.Delete();
  436. }
  437. }
  438.  
  439. public static string GetCorpseName( Mobile m )
  440. {
  441. if ( m is BaseCreature )
  442. {
  443. BaseCreature bc = (BaseCreature)m;
  444.  
  445. if ( bc.CorpseNameOverride != null )
  446. return bc.CorpseNameOverride;
  447. }
  448.  
  449. Type t = m.GetType();
  450.  
  451. object[] attrs = t.GetCustomAttributes( typeof( CorpseNameAttribute ), true );
  452.  
  453. if ( attrs != null && attrs.Length > 0 )
  454. {
  455. CorpseNameAttribute attr = attrs[0] as CorpseNameAttribute;
  456.  
  457. if ( attr != null )
  458. return attr.Name;
  459. }
  460.  
  461. return null;
  462. }
  463.  
  464. public static void Initialize()
  465. {
  466. Mobile.CreateCorpseHandler += new CreateCorpseHandler( Mobile_CreateCorpseHandler );
  467. }
  468.  
  469. public static Container Mobile_CreateCorpseHandler( Mobile owner, HairInfo hair, FacialHairInfo facialhair, List<Item> initialContent, List<Item> equipItems )
  470. {
  471. bool shouldFillCorpse = true;
  472.  
  473. //if ( owner is BaseCreature )
  474. // shouldFillCorpse = !((BaseCreature)owner).IsBonded;
  475.  
  476. Corpse c;
  477. if( owner is MilitiaFighter )
  478. c = new MilitiaFighterCorpse( owner, hair, facialhair, shouldFillCorpse ? equipItems : new List<Item>() );
  479. else
  480. c = new Corpse( owner, hair, facialhair, shouldFillCorpse ? equipItems : new List<Item>() );
  481.  
  482. owner.Corpse = c;
  483.  
  484. if ( shouldFillCorpse )
  485. {
  486. for ( int i = 0; i < initialContent.Count; ++i )
  487. {
  488. Item item = initialContent[i];
  489.  
  490. if ( Core.AOS && owner.Player && item.Parent == owner.Backpack )
  491. c.AddItem( item );
  492. else
  493. c.DropItem( item );
  494.  
  495. if ( owner.Player && Core.AOS )
  496. c.SetRestoreInfo( item, item.Location );
  497. }
  498.  
  499. if ( !owner.Player )
  500. {
  501. c.AssignInstancedLoot();
  502. }
  503. else if ( Core.AOS )
  504. {
  505. PlayerMobile pm = owner as PlayerMobile;
  506.  
  507. if ( pm != null )
  508. c.RestoreEquip = pm.EquipSnapshot;
  509. }
  510. }
  511. else
  512. {
  513. c.Carved = true; // TODO: Is it needed?
  514. }
  515.  
  516. Point3D loc = owner.Location;
  517. Map map = owner.Map;
  518.  
  519. if ( map == null || map == Map.Internal )
  520. {
  521. loc = owner.LogoutLocation;
  522. map = owner.LogoutMap;
  523. }
  524.  
  525. c.MoveToWorld( loc, map );
  526.  
  527. return c;
  528. }
  529.  
  530. public override bool IsPublicContainer{ get{ return true; } }
  531.  
  532. public Corpse( Mobile owner, List<Item> equipItems ) : this( owner, null, null, equipItems )
  533. {
  534. }
  535.  
  536. public Corpse( Mobile owner, HairInfo hair, FacialHairInfo facialhair, List<Item> equipItems )
  537. : base( 0x2006 )
  538. {
  539. // To supress console warnings, stackable must be true
  540. Stackable = true;
  541. Amount = owner.Body; // protocol defines that for itemid 0x2006, amount=body
  542. Stackable = false;
  543.  
  544. Movable = false;
  545. Hue = owner.Hue;
  546. Direction = owner.Direction;
  547. Name = owner.Name;
  548.  
  549. m_Owner = owner;
  550.  
  551. m_CorpseName = GetCorpseName( owner );
  552.  
  553. m_TimeOfDeath = DateTime.Now;
  554.  
  555. m_AccessLevel = owner.AccessLevel;
  556. m_Guild = owner.Guild as Guild;
  557. m_Kills = owner.Kills;
  558. SetFlag( CorpseFlag.Criminal, owner.Criminal );
  559.  
  560. m_Hair = hair;
  561. m_FacialHair = facialhair;
  562.  
  563. // This corpse does not turn to bones if: the owner is not a player
  564. SetFlag( CorpseFlag.NoBones, !owner.Player );
  565.  
  566. m_Looters = new List<Mobile>();
  567. m_EquipItems = equipItems;
  568.  
  569. m_Aggressors = new List<Mobile>( owner.Aggressors.Count + owner.Aggressed.Count );
  570. //bool addToAggressors = !( owner is BaseCreature );
  571.  
  572. bool isBaseCreature = (owner is BaseCreature);
  573.  
  574. TimeSpan lastTime = TimeSpan.MaxValue;
  575.  
  576. for ( int i = 0; i < owner.Aggressors.Count; ++i )
  577. {
  578. AggressorInfo info = owner.Aggressors[i];
  579.  
  580. if ( (DateTime.Now - info.LastCombatTime) < lastTime )
  581. {
  582. m_Killer = info.Attacker;
  583. lastTime = (DateTime.Now - info.LastCombatTime);
  584. }
  585.  
  586. if ( !isBaseCreature && !info.CriminalAggression )
  587. m_Aggressors.Add( info.Attacker );
  588. }
  589.  
  590. for ( int i = 0; i < owner.Aggressed.Count; ++i )
  591. {
  592. AggressorInfo info = owner.Aggressed[i];
  593.  
  594. if ( (DateTime.Now - info.LastCombatTime) < lastTime )
  595. {
  596. m_Killer = info.Defender;
  597. lastTime = (DateTime.Now - info.LastCombatTime);
  598. }
  599.  
  600. if ( !isBaseCreature )
  601. m_Aggressors.Add( info.Defender );
  602. }
  603.  
  604. if ( isBaseCreature )
  605. {
  606. BaseCreature bc = (BaseCreature)owner;
  607.  
  608. Mobile master = bc.GetMaster();
  609. if( master != null )
  610. m_Aggressors.Add( master );
  611.  
  612. List<DamageStore> rights = BaseCreature.GetLootingRights( bc.DamageEntries, bc.HitsMax );
  613. for ( int i = 0; i < rights.Count; ++i )
  614. {
  615. DamageStore ds = rights[i];
  616.  
  617. if ( ds.m_HasRight )
  618. m_Aggressors.Add( ds.m_Mobile );
  619. }
  620. }
  621.  
  622. BeginDecay( m_DefaultDecayTime );
  623.  
  624. DevourCorpse();
  625. }
  626.  
  627. public Corpse( Serial serial ) : base( serial )
  628. {
  629. }
  630.  
  631. protected bool GetFlag( CorpseFlag flag )
  632. {
  633. return ((m_Flags & flag) != 0);
  634. }
  635.  
  636. protected void SetFlag( CorpseFlag flag, bool on )
  637. {
  638. m_Flags = (on ? m_Flags | flag : m_Flags & ~flag);
  639. }
  640.  
  641. public override void Serialize( GenericWriter writer )
  642. {
  643. base.Serialize( writer );
  644.  
  645. writer.Write( (int) 12 ); // version
  646.  
  647. if ( m_RestoreEquip == null )
  648. {
  649. writer.Write( false );
  650. }
  651. else
  652. {
  653. writer.Write( true );
  654. writer.Write( m_RestoreEquip );
  655. }
  656.  
  657. writer.Write( (int)m_Flags );
  658.  
  659. writer.WriteDeltaTime( m_TimeOfDeath );
  660.  
  661. List<KeyValuePair<Item, Point3D>> list = ( m_RestoreTable == null ? null : new List<KeyValuePair<Item, Point3D>>( m_RestoreTable ) );
  662. int count = ( list == null ? 0 : list.Count );
  663.  
  664. writer.Write( count );
  665.  
  666. for ( int i = 0; i < count; ++i )
  667. {
  668. KeyValuePair<Item, Point3D> kvp = list[i];
  669. Item item = kvp.Key;
  670. Point3D loc = kvp.Value;
  671.  
  672. writer.Write( item );
  673.  
  674. if ( item.Location == loc )
  675. {
  676. writer.Write( false );
  677. }
  678. else
  679. {
  680. writer.Write( true );
  681. writer.Write( loc );
  682. }
  683. }
  684.  
  685. writer.Write( m_DecayTimer != null );
  686.  
  687. if ( m_DecayTimer != null )
  688. writer.WriteDeltaTime( m_DecayTime );
  689.  
  690. writer.Write( m_Looters );
  691. writer.Write( m_Killer );
  692.  
  693. writer.Write( m_Aggressors );
  694.  
  695. writer.Write( m_Owner );
  696.  
  697. writer.Write( (string) m_CorpseName );
  698.  
  699. writer.Write( (int) m_AccessLevel );
  700. writer.Write( (Guild) m_Guild );
  701. writer.Write( (int) m_Kills );
  702.  
  703. writer.Write( m_EquipItems );
  704. }
  705.  
  706. public override void Deserialize( GenericReader reader )
  707. {
  708. base.Deserialize( reader );
  709.  
  710. int version = reader.ReadInt();
  711.  
  712. switch ( version )
  713. {
  714. case 12:
  715. {
  716. if ( reader.ReadBool() )
  717. m_RestoreEquip = reader.ReadStrongItemList();
  718.  
  719. goto case 11;
  720. }
  721. case 11:
  722. {
  723. // Version 11, we move all bools to a CorpseFlag
  724. m_Flags = (CorpseFlag)reader.ReadInt();
  725.  
  726. m_TimeOfDeath = reader.ReadDeltaTime();
  727.  
  728. int count = reader.ReadInt();
  729.  
  730. for( int i = 0; i < count; ++i )
  731. {
  732. Item item = reader.ReadItem();
  733.  
  734. if( reader.ReadBool() )
  735. SetRestoreInfo( item, reader.ReadPoint3D() );
  736. else if( item != null )
  737. SetRestoreInfo( item, item.Location );
  738. }
  739.  
  740. if( reader.ReadBool() )
  741. BeginDecay( reader.ReadDeltaTime() - DateTime.Now );
  742.  
  743. m_Looters = reader.ReadStrongMobileList();
  744. m_Killer = reader.ReadMobile();
  745.  
  746. m_Aggressors = reader.ReadStrongMobileList();
  747. m_Owner = reader.ReadMobile();
  748.  
  749. m_CorpseName = reader.ReadString();
  750.  
  751. m_AccessLevel = (AccessLevel)reader.ReadInt();
  752. reader.ReadInt(); // guild reserve
  753. m_Kills = reader.ReadInt();
  754.  
  755. m_EquipItems = reader.ReadStrongItemList();
  756. break;
  757. }
  758. case 10:
  759. {
  760. m_TimeOfDeath = reader.ReadDeltaTime();
  761.  
  762. goto case 9;
  763. }
  764. case 9:
  765. {
  766. int count = reader.ReadInt();
  767.  
  768. for ( int i = 0; i < count; ++i )
  769. {
  770. Item item = reader.ReadItem();
  771.  
  772. if ( reader.ReadBool() )
  773. SetRestoreInfo( item, reader.ReadPoint3D() );
  774. else if ( item != null )
  775. SetRestoreInfo( item, item.Location );
  776. }
  777.  
  778. goto case 8;
  779. }
  780. case 8:
  781. {
  782. SetFlag( CorpseFlag.VisitedByTaxidermist, reader.ReadBool() );
  783.  
  784. goto case 7;
  785. }
  786. case 7:
  787. {
  788. if ( reader.ReadBool() )
  789. BeginDecay( reader.ReadDeltaTime() - DateTime.Now );
  790.  
  791. goto case 6;
  792. }
  793. case 6:
  794. {
  795. m_Looters = reader.ReadStrongMobileList();
  796. m_Killer = reader.ReadMobile();
  797.  
  798. goto case 5;
  799. }
  800. case 5:
  801. {
  802. SetFlag( CorpseFlag.Carved, reader.ReadBool() );
  803.  
  804. goto case 4;
  805. }
  806. case 4:
  807. {
  808. m_Aggressors = reader.ReadStrongMobileList();
  809.  
  810. goto case 3;
  811. }
  812. case 3:
  813. {
  814. m_Owner = reader.ReadMobile();
  815.  
  816. goto case 2;
  817. }
  818. case 2:
  819. {
  820. SetFlag( CorpseFlag.NoBones, reader.ReadBool() );
  821.  
  822. goto case 1;
  823. }
  824. case 1:
  825. {
  826. m_CorpseName = reader.ReadString();
  827.  
  828. goto case 0;
  829. }
  830. case 0:
  831. {
  832. if ( version < 10 )
  833. m_TimeOfDeath = DateTime.Now;
  834.  
  835. if ( version < 7 )
  836. BeginDecay( m_DefaultDecayTime );
  837.  
  838. if ( version < 6 )
  839. m_Looters = new List<Mobile>();
  840.  
  841. if ( version < 4 )
  842. m_Aggressors = new List<Mobile>();
  843.  
  844. m_AccessLevel = (AccessLevel)reader.ReadInt();
  845. reader.ReadInt(); // guild reserve
  846. m_Kills = reader.ReadInt();
  847. SetFlag( CorpseFlag.Criminal, reader.ReadBool() );
  848.  
  849. m_EquipItems = reader.ReadStrongItemList();
  850.  
  851. break;
  852. }
  853. }
  854. }
  855.  
  856. public bool DevourCorpse()
  857. {
  858. if( Devoured || Deleted || m_Killer == null || m_Killer.Deleted || !m_Killer.Alive || !(m_Killer is IDevourer) || m_Owner == null || m_Owner.Deleted )
  859. return false;
  860.  
  861. m_Devourer = (IDevourer)m_Killer; // Set the devourer the killer
  862. return m_Devourer.Devour( this ); // Devour the corpse if it hasn't
  863. }
  864.  
  865. public override void SendInfoTo( NetState state, bool sendOplPacket )
  866. {
  867. base.SendInfoTo( state, sendOplPacket );
  868.  
  869. if ( ItemID == 0x2006 )
  870. {
  871. state.Send( new CorpseContent( state.Mobile, this ) );
  872. state.Send( new CorpseEquip( state.Mobile, this ) );
  873. }
  874. }
  875.  
  876. public bool IsCriminalAction( Mobile from )
  877. {
  878. if ( from == m_Owner || from.AccessLevel >= AccessLevel.GameMaster )
  879. return false;
  880.  
  881. Party p = Party.Get( m_Owner );
  882.  
  883. if ( p != null && p.Contains( from ) )
  884. {
  885. PartyMemberInfo pmi = p[m_Owner];
  886.  
  887. if ( pmi != null && pmi.CanLoot )
  888. return false;
  889. }
  890.  
  891. return ( NotorietyHandlers.CorpseNotoriety( from, this ) == Notoriety.Innocent );
  892. }
  893.  
  894. public override bool CheckItemUse( Mobile from, Item item )
  895. {
  896. if ( !base.CheckItemUse( from, item ) )
  897. return false;
  898.  
  899. if ( item != this )
  900. return CanLoot( from, item );
  901.  
  902. return true;
  903. }
  904.  
  905. public override bool CheckLift( Mobile from, Item item, ref LRReason reject )
  906. {
  907. if ( !base.CheckLift( from, item, ref reject ) )
  908. return false;
  909.  
  910. return CanLoot( from,item );
  911. }
  912.  
  913. public override void OnItemUsed( Mobile from, Item item )
  914. {
  915. base.OnItemUsed( from, item );
  916.  
  917. if ( item is Food )
  918. from.RevealingAction();
  919.  
  920. if ( item != this && IsCriminalAction( from ) )
  921. from.CriminalAction( true );
  922.  
  923. if ( !m_Looters.Contains( from ) )
  924. m_Looters.Add( from );
  925.  
  926. if ( m_InstancedItems != null && m_InstancedItems.ContainsKey( item ) )
  927. m_InstancedItems.Remove( item );
  928. }
  929.  
  930. public override void OnItemLifted( Mobile from, Item item )
  931. {
  932. base.OnItemLifted( from, item );
  933.  
  934. if ( item != this && from != m_Owner )
  935. from.RevealingAction();
  936.  
  937. if ( item != this && IsCriminalAction( from ) )
  938. from.CriminalAction( true );
  939.  
  940. if ( !m_Looters.Contains( from ) )
  941. m_Looters.Add( from );
  942.  
  943. if ( m_InstancedItems != null && m_InstancedItems.ContainsKey( item ) )
  944. m_InstancedItems.Remove( item );
  945. }
  946.  
  947. private class OpenCorpseEntry : ContextMenuEntry
  948. {
  949. public OpenCorpseEntry() : base( 6215, 2 )
  950. {
  951. }
  952.  
  953. public override void OnClick()
  954. {
  955. Corpse corpse = Owner.Target as Corpse;
  956.  
  957. if ( corpse != null && Owner.From.CheckAlive() )
  958. corpse.Open( Owner.From, false );
  959. }
  960. }
  961.  
  962. public override void GetContextMenuEntries( Mobile from, List<ContextMenuEntry> list )
  963. {
  964. base.GetContextMenuEntries( from, list );
  965.  
  966. if ( Core.AOS && m_Owner == from && from.Alive )
  967. list.Add( new OpenCorpseEntry() );
  968. }
  969.  
  970. private Dictionary<Item, Point3D> m_RestoreTable;
  971.  
  972. public bool GetRestoreInfo( Item item, ref Point3D loc )
  973. {
  974. if ( m_RestoreTable == null || item == null )
  975. return false;
  976.  
  977. return m_RestoreTable.TryGetValue( item, out loc );
  978. }
  979.  
  980. public void SetRestoreInfo( Item item, Point3D loc )
  981. {
  982. if ( item == null )
  983. return;
  984.  
  985. if ( m_RestoreTable == null )
  986. m_RestoreTable = new Dictionary<Item, Point3D>();
  987.  
  988. m_RestoreTable[item] = loc;
  989. }
  990.  
  991. public void ClearRestoreInfo( Item item )
  992. {
  993. if ( m_RestoreTable == null || item == null )
  994. return;
  995.  
  996. m_RestoreTable.Remove( item );
  997.  
  998. if ( m_RestoreTable.Count == 0 )
  999. m_RestoreTable = null;
  1000. }
  1001.  
  1002. public bool CanLoot( Mobile from, Item item )
  1003. {
  1004. if ( !IsCriminalAction( from ) )
  1005. return true;
  1006.  
  1007. Map map = this.Map;
  1008.  
  1009. if ( map == null || (map.Rules & MapRules.HarmfulRestrictions) != 0 )
  1010. return false;
  1011.  
  1012. return true;
  1013. }
  1014.  
  1015. public bool CheckLoot( Mobile from, Item item )
  1016. {
  1017. if ( !CanLoot( from, item ) )
  1018. {
  1019. if ( m_Owner == null || !m_Owner.Player )
  1020. from.SendLocalizedMessage( 1005035 ); // You did not earn the right to loot this creature!
  1021. else
  1022. from.SendLocalizedMessage( 1010049 ); // You may not loot this corpse.
  1023.  
  1024. return false;
  1025. }
  1026. else if ( IsCriminalAction( from ) )
  1027. {
  1028. if ( m_Owner == null || !m_Owner.Player )
  1029. from.SendLocalizedMessage( 1005036 ); // Looting this monster corpse will be a criminal act!
  1030. else
  1031. from.SendLocalizedMessage( 1005038 ); // Looting this corpse will be a criminal act!
  1032. }
  1033.  
  1034. return true;
  1035. }
  1036.  
  1037. public virtual void Open( Mobile from, bool checkSelfLoot )
  1038. {
  1039. if ( from.AccessLevel > AccessLevel.Player || from.InRange( this.GetWorldLocation(), 2 ) )
  1040. {
  1041. #region Self Looting
  1042. if ( checkSelfLoot && from == m_Owner && !GetFlag( CorpseFlag.SelfLooted ) && this.Items.Count != 0 )
  1043. {
  1044. DeathRobe robe = from.FindItemOnLayer( Layer.OuterTorso ) as DeathRobe;
  1045.  
  1046. if ( robe != null )
  1047. {
  1048. Map map = from.Map;
  1049.  
  1050. if ( map != null && map != Map.Internal )
  1051. {
  1052. robe.MoveToWorld( from.Location, map );
  1053. robe.BeginDecay();
  1054. }
  1055. }
  1056.  
  1057. Container pack = from.Backpack;
  1058.  
  1059. if ( m_RestoreEquip != null && pack != null )
  1060. {
  1061. List<Item> packItems = new List<Item>( pack.Items ); // Only items in the top-level pack are re-equipped
  1062.  
  1063. for ( int i = 0; i < packItems.Count; i++ )
  1064. {
  1065. Item packItem = packItems[i];
  1066.  
  1067. if ( m_RestoreEquip.Contains( packItem ) && packItem.Movable )
  1068. from.EquipItem( packItem );
  1069. }
  1070. }
  1071.  
  1072. List<Item> items = new List<Item>( this.Items );
  1073.  
  1074. bool didntFit = false;
  1075.  
  1076. for ( int i = 0; !didntFit && i < items.Count; ++i )
  1077. {
  1078. Item item = items[i];
  1079. Point3D loc = item.Location;
  1080.  
  1081. if ( ( item.Layer == Layer.Hair || item.Layer == Layer.FacialHair ) || !item.Movable || !GetRestoreInfo( item, ref loc ) )
  1082. continue;
  1083.  
  1084. if ( pack != null && pack.CheckHold( from, item, false, true ) )
  1085. {
  1086. item.Location = loc;
  1087. pack.AddItem( item );
  1088.  
  1089. if ( m_RestoreEquip != null && m_RestoreEquip.Contains( item ) )
  1090. from.EquipItem( item );
  1091. }
  1092. else
  1093. {
  1094. didntFit = true;
  1095. }
  1096. }
  1097.  
  1098. from.PlaySound( 0x3E3 );
  1099.  
  1100. if ( this.Items.Count != 0 )
  1101. {
  1102. from.SendLocalizedMessage( 1062472 ); // You gather some of your belongings. The rest remain on the corpse.
  1103. }
  1104. else
  1105. {
  1106. SetFlag( CorpseFlag.Carved, true );
  1107.  
  1108. if ( ItemID == 0x2006 )
  1109. {
  1110. ProcessDelta();
  1111. SendRemovePacket();
  1112. ItemID = Utility.Random( 0xECA, 9 ); // bone graphic
  1113. Hue = 0;
  1114. ProcessDelta();
  1115. }
  1116.  
  1117. from.SendLocalizedMessage( 1062471 ); // You quickly gather all of your belongings.
  1118. }
  1119.  
  1120. SetFlag( CorpseFlag.SelfLooted, true );
  1121. }
  1122. #endregion
  1123.  
  1124. if ( !CheckLoot( from, null ) )
  1125. return;
  1126.  
  1127. #region Quests
  1128. PlayerMobile player = from as PlayerMobile;
  1129.  
  1130. if ( player != null )
  1131. {
  1132. QuestSystem qs = player.Quest;
  1133.  
  1134. if ( qs is UzeraanTurmoilQuest )
  1135. {
  1136. GetDaemonBoneObjective obj = qs.FindObjective( typeof( GetDaemonBoneObjective ) ) as GetDaemonBoneObjective;
  1137.  
  1138. if ( obj != null && obj.CorpseWithBone == this && ( !obj.Completed || UzeraanTurmoilQuest.HasLostDaemonBone( player ) ) )
  1139. {
  1140. Item bone = new QuestDaemonBone();
  1141.  
  1142. if ( player.PlaceInBackpack( bone ) )
  1143. {
  1144. obj.CorpseWithBone = null;
  1145. player.SendLocalizedMessage( 1049341, "", 0x22 ); // You rummage through the bones and find a Daemon Bone! You quickly place the item in your pack.
  1146.  
  1147. if ( !obj.Completed )
  1148. obj.Complete();
  1149. }
  1150. else
  1151. {
  1152. bone.Delete();
  1153. player.SendLocalizedMessage( 1049342, "", 0x22 ); // Rummaging through the bones you find a Daemon Bone, but can't pick it up because your pack is too full. Come back when you have more room in your pack.
  1154. }
  1155.  
  1156. return;
  1157. }
  1158. }
  1159. else if ( qs is TheSummoningQuest )
  1160. {
  1161. VanquishDaemonObjective obj = qs.FindObjective( typeof( VanquishDaemonObjective ) ) as VanquishDaemonObjective;
  1162.  
  1163. if ( obj != null && obj.Completed && obj.CorpseWithSkull == this )
  1164. {
  1165. GoldenSkull sk = new GoldenSkull();
  1166.  
  1167. if ( player.PlaceInBackpack( sk ) )
  1168. {
  1169. obj.CorpseWithSkull = null;
  1170. player.SendLocalizedMessage( 1050022 ); // For your valor in combating the devourer, you have been awarded a golden skull.
  1171. qs.Complete();
  1172. }
  1173. else
  1174. {
  1175. sk.Delete();
  1176. player.SendLocalizedMessage( 1050023 ); // You find a golden skull, but your backpack is too full to carry it.
  1177. }
  1178. }
  1179. }
  1180. }
  1181.  
  1182. #endregion
  1183.  
  1184. base.OnDoubleClick( from );
  1185. }
  1186. else
  1187. {
  1188. from.SendLocalizedMessage( 500446 ); // That is too far away.
  1189. return;
  1190. }
  1191. }
  1192.  
  1193. public override void OnDoubleClick( Mobile from )
  1194. {
  1195. Open( from, Core.AOS );
  1196. }
  1197.  
  1198. public override bool CheckContentDisplay( Mobile from )
  1199. {
  1200. return false;
  1201. }
  1202.  
  1203. public override bool DisplaysContent{ get{ return false; } }
  1204.  
  1205. public override void AddNameProperty( ObjectPropertyList list )
  1206. {
  1207. if ( ItemID == 0x2006 ) // Corpse form
  1208. {
  1209. if ( m_CorpseName != null )
  1210. list.Add( m_CorpseName );
  1211. else
  1212. list.Add( 1046414, this.Name ); // the remains of ~1_NAME~
  1213. }
  1214. else // Bone form
  1215. {
  1216. list.Add( 1046414, this.Name ); // the remains of ~1_NAME~
  1217. }
  1218. }
  1219.  
  1220. public override void OnAosSingleClick( Mobile from )
  1221. {
  1222. int hue = Notoriety.GetHue( NotorietyHandlers.CorpseNotoriety( from, this ) );
  1223. ObjectPropertyList opl = this.PropertyList;
  1224.  
  1225. if ( opl.Header > 0 )
  1226. from.Send( new MessageLocalized( Serial, ItemID, MessageType.Label, hue, 3, opl.Header, Name, opl.HeaderArgs ) );
  1227. }
  1228.  
  1229. public override void OnSingleClick( Mobile from )
  1230. {
  1231. int hue = Notoriety.GetHue( NotorietyHandlers.CorpseNotoriety( from, this ) );
  1232.  
  1233. if ( ItemID == 0x2006 ) // Corpse form
  1234. {
  1235. if ( m_CorpseName != null )
  1236. from.Send( new AsciiMessage( Serial, ItemID, MessageType.Label, hue, 3, "", m_CorpseName ) );
  1237. else
  1238. from.Send( new MessageLocalized( Serial, ItemID, MessageType.Label, hue, 3, 1046414, "", Name ) );
  1239. }
  1240. else // Bone form
  1241. {
  1242. from.Send( new MessageLocalized( Serial, ItemID, MessageType.Label, hue, 3, 1046414, "", Name ) );
  1243. }
  1244. }
  1245.  
  1246. public void Carve( Mobile from, Item item )
  1247. {
  1248. if ( IsCriminalAction( from ) && this.Map != null && (this.Map.Rules & MapRules.HarmfulRestrictions) != 0 )
  1249. {
  1250. if ( m_Owner == null || !m_Owner.Player )
  1251. from.SendLocalizedMessage( 1005035 ); // You did not earn the right to loot this creature!
  1252. else
  1253. from.SendLocalizedMessage( 1010049 ); // You may not loot this corpse.
  1254.  
  1255. return;
  1256. }
  1257.  
  1258. Mobile dead = m_Owner;
  1259.  
  1260. if ( GetFlag( CorpseFlag.Carved ) || dead == null )
  1261. {
  1262. from.SendLocalizedMessage( 500485 ); // You see nothing useful to carve from the corpse.
  1263. }
  1264. else if ( ((Body)Amount).IsHuman && ItemID == 0x2006 )
  1265. {
  1266. new Blood( 0x122D ).MoveToWorld( Location, Map );
  1267.  
  1268. new Torso().MoveToWorld( Location, Map );
  1269. new LeftLeg().MoveToWorld( Location, Map );
  1270. new LeftArm().MoveToWorld( Location, Map );
  1271. new RightLeg().MoveToWorld( Location, Map );
  1272. new RightArm().MoveToWorld( Location, Map );
  1273. new Head( dead.Name ).MoveToWorld( Location, Map );
  1274.  
  1275. SetFlag( CorpseFlag.Carved, true );
  1276.  
  1277. ProcessDelta();
  1278. SendRemovePacket();
  1279. ItemID = Utility.Random( 0xECA, 9 ); // bone graphic
  1280. Hue = 0;
  1281. ProcessDelta();
  1282.  
  1283. if ( IsCriminalAction( from ) )
  1284. from.CriminalAction( true );
  1285. }
  1286. else if ( dead is BaseCreature )
  1287. {
  1288. ((BaseCreature)dead).OnCarve( from, this, item );
  1289. }
  1290. else
  1291. {
  1292. from.SendLocalizedMessage( 500485 ); // You see nothing useful to carve from the corpse.
  1293. }
  1294. }
  1295. }
  1296. }
Advertisement
Add Comment
Please, Sign In to add comment