CombatModule.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using System.Net.Sockets;
  32. using System.Reflection;
  33. using System.Xml;
  34. using OpenMetaverse;
  35. using log4net;
  36. using Nini.Config;
  37. using Nwc.XmlRpc;
  38. using OpenSim.Framework;
  39. using OpenSim.Region.Environment.Interfaces;
  40. using OpenSim.Region.Interfaces;
  41. using OpenSim.Region.Environment.Scenes;
  42. using OpenSim.Framework.Communications.Cache;
  43. namespace OpenSim.Region.Environment.Modules.Avatar.Combat.CombatModule
  44. {
  45. public class CombatModule : IRegionModule
  46. {
  47. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. /// <summary>
  49. /// Region UUIDS indexed by AgentID
  50. /// </summary>
  51. //private Dictionary<UUID, UUID> m_rootAgents = new Dictionary<UUID, UUID>();
  52. /// <summary>
  53. /// Scenes by Region Handle
  54. /// </summary>
  55. private Dictionary<ulong, Scene> m_scenel = new Dictionary<ulong, Scene>();
  56. /// <summary>
  57. /// Startup
  58. /// </summary>
  59. /// <param name="scene"></param>
  60. /// <param name="config"></param>
  61. public void Initialise(Scene scene, IConfigSource config)
  62. {
  63. lock (m_scenel)
  64. {
  65. if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
  66. {
  67. m_scenel[scene.RegionInfo.RegionHandle] = scene;
  68. }
  69. else
  70. {
  71. m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
  72. }
  73. }
  74. scene.EventManager.OnAvatarKilled += KillAvatar;
  75. }
  76. public void PostInitialise()
  77. {
  78. }
  79. public void Close()
  80. {
  81. }
  82. public string Name
  83. {
  84. get { return "CombatModule"; }
  85. }
  86. public bool IsSharedModule
  87. {
  88. get { return true; }
  89. }
  90. private void KillAvatar(uint killerObjectLocalID, ScenePresence DeadAvatar)
  91. {
  92. if (killerObjectLocalID == 0)
  93. DeadAvatar.ControllingClient.SendAgentAlertMessage("You committed suicide!", true);
  94. else
  95. {
  96. bool foundResult = false;
  97. string resultstring = "";
  98. List<ScenePresence> allav = DeadAvatar.Scene.GetScenePresences();
  99. try
  100. {
  101. foreach (ScenePresence av in allav)
  102. {
  103. if (av.LocalId == killerObjectLocalID)
  104. {
  105. av.ControllingClient.SendAlertMessage("You fragged " + DeadAvatar.Firstname + " " + DeadAvatar.Lastname);
  106. resultstring = av.Firstname + " " + av.Lastname;
  107. foundResult = true;
  108. }
  109. }
  110. } catch (System.InvalidOperationException)
  111. {
  112. }
  113. if (!foundResult)
  114. {
  115. SceneObjectPart part = DeadAvatar.Scene.GetSceneObjectPart(killerObjectLocalID);
  116. if (part != null)
  117. {
  118. ScenePresence av = DeadAvatar.Scene.GetScenePresence(part.OwnerID);
  119. if (av != null)
  120. {
  121. av.ControllingClient.SendAlertMessage("You fragged " + DeadAvatar.Firstname + " " + DeadAvatar.Lastname);
  122. resultstring = av.Firstname + " " + av.Lastname;
  123. DeadAvatar.ControllingClient.SendAgentAlertMessage("You got killed by " + resultstring + "!", true);
  124. }
  125. else
  126. {
  127. string killer = DeadAvatar.Scene.CommsManager.UUIDNameRequestString(part.OwnerID);
  128. DeadAvatar.ControllingClient.SendAgentAlertMessage("You impaled yourself on " + part.Name + " owned by " + killer +"!", true);
  129. }
  130. //DeadAvatar.Scene. part.ObjectOwner
  131. }
  132. else
  133. {
  134. DeadAvatar.ControllingClient.SendAgentAlertMessage("You died!", true);
  135. }
  136. }
  137. }
  138. DeadAvatar.Health = 100;
  139. DeadAvatar.Scene.TeleportClientHome(DeadAvatar.UUID, DeadAvatar.ControllingClient);
  140. }
  141. }
  142. }