CombatModule.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using Nini.Config;
  30. using OpenSim.Region.Framework.Interfaces;
  31. using OpenSim.Region.Framework.Scenes;
  32. using OpenMetaverse;
  33. namespace OpenSim.Region.CoreModules.Avatar.Combat.CombatModule
  34. {
  35. public class CombatModule : IRegionModule
  36. {
  37. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  38. /// <summary>
  39. /// Region UUIDS indexed by AgentID
  40. /// </summary>
  41. //private Dictionary<UUID, UUID> m_rootAgents = new Dictionary<UUID, UUID>();
  42. /// <summary>
  43. /// Scenes by Region Handle
  44. /// </summary>
  45. private Dictionary<ulong, Scene> m_scenel = new Dictionary<ulong, Scene>();
  46. /// <summary>
  47. /// Startup
  48. /// </summary>
  49. /// <param name="scene"></param>
  50. /// <param name="config"></param>
  51. public void Initialise(Scene scene, IConfigSource config)
  52. {
  53. lock (m_scenel)
  54. {
  55. if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
  56. {
  57. m_scenel[scene.RegionInfo.RegionHandle] = scene;
  58. }
  59. else
  60. {
  61. m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
  62. }
  63. }
  64. scene.EventManager.OnAvatarKilled += KillAvatar;
  65. scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
  66. }
  67. public void PostInitialise()
  68. {
  69. }
  70. public void Close()
  71. {
  72. }
  73. public string Name
  74. {
  75. get { return "CombatModule"; }
  76. }
  77. public bool IsSharedModule
  78. {
  79. get { return true; }
  80. }
  81. private void KillAvatar(uint killerObjectLocalID, ScenePresence DeadAvatar)
  82. {
  83. if (killerObjectLocalID == 0)
  84. DeadAvatar.ControllingClient.SendAgentAlertMessage("You committed suicide!", true);
  85. else
  86. {
  87. bool foundResult = false;
  88. string resultstring = "";
  89. List<ScenePresence> allav = DeadAvatar.Scene.GetScenePresences();
  90. try
  91. {
  92. foreach (ScenePresence av in allav)
  93. {
  94. if (av.LocalId == killerObjectLocalID)
  95. {
  96. av.ControllingClient.SendAlertMessage("You fragged " + DeadAvatar.Firstname + " " + DeadAvatar.Lastname);
  97. resultstring = av.Firstname + " " + av.Lastname;
  98. foundResult = true;
  99. }
  100. }
  101. } catch (InvalidOperationException)
  102. {
  103. }
  104. if (!foundResult)
  105. {
  106. SceneObjectPart part = DeadAvatar.Scene.GetSceneObjectPart(killerObjectLocalID);
  107. if (part != null)
  108. {
  109. ScenePresence av = DeadAvatar.Scene.GetScenePresence(part.OwnerID);
  110. if (av != null)
  111. {
  112. av.ControllingClient.SendAlertMessage("You fragged " + DeadAvatar.Firstname + " " + DeadAvatar.Lastname);
  113. resultstring = av.Firstname + " " + av.Lastname;
  114. DeadAvatar.ControllingClient.SendAgentAlertMessage("You got killed by " + resultstring + "!", true);
  115. }
  116. else
  117. {
  118. string killer = DeadAvatar.Scene.CommsManager.UUIDNameRequestString(part.OwnerID);
  119. DeadAvatar.ControllingClient.SendAgentAlertMessage("You impaled yourself on " + part.Name + " owned by " + killer +"!", true);
  120. }
  121. //DeadAvatar.Scene. part.ObjectOwner
  122. }
  123. else
  124. {
  125. DeadAvatar.ControllingClient.SendAgentAlertMessage("You died!", true);
  126. }
  127. }
  128. }
  129. DeadAvatar.Health = 100;
  130. DeadAvatar.Scene.TeleportClientHome(DeadAvatar.UUID, DeadAvatar.ControllingClient);
  131. }
  132. private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID)
  133. {
  134. ILandObject obj = avatar.Scene.LandChannel.GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
  135. if ((obj.landData.Flags & (uint)ParcelFlags.AllowDamage) != 0)
  136. {
  137. avatar.Invulnerable = false;
  138. }
  139. else
  140. {
  141. avatar.Invulnerable = true;
  142. }
  143. }
  144. }
  145. }