OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
CombatModule.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using Nini.Config;
31 using OpenSim.Framework;
32 using OpenSim.Region.Framework.Interfaces;
33 using OpenSim.Region.Framework.Scenes;
34 using OpenSim.Services.Interfaces;
35 using OpenMetaverse;
36 
37 using Mono.Addins;
38 
39 namespace OpenSim.Region.CoreModules.Avatar.Combat.CombatModule
40 {
41  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "CombatModule")]
43  {
44  //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 
49  //private Dictionary<UUID, UUID> m_rootAgents = new Dictionary<UUID, UUID>();
50 
54  private Dictionary<ulong, Scene> m_scenel = new Dictionary<ulong, Scene>();
55 
61  public void Initialise(IConfigSource config)
62  {
63  }
64 
65  public void AddRegion(Scene scene)
66  {
67  lock (m_scenel)
68  {
69  if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
70  {
71  m_scenel[scene.RegionInfo.RegionHandle] = scene;
72  }
73  else
74  {
75  m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
76  }
77  }
78 
79  scene.EventManager.OnAvatarKilled += KillAvatar;
80  scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
81  }
82 
83  public void RemoveRegion(Scene scene)
84  {
85  if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
86  m_scenel.Remove(scene.RegionInfo.RegionHandle);
87 
88  scene.EventManager.OnAvatarKilled -= KillAvatar;
89  scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel;
90  }
91 
92  public void RegionLoaded(Scene scene)
93  {
94  }
95 
96  public void PostInitialise()
97  {
98  }
99 
100  public void Close()
101  {
102  }
103 
104  public string Name
105  {
106  get { return "CombatModule"; }
107  }
108 
109  public Type ReplaceableInterface
110  {
111  get { return null; }
112  }
113 
114 
115  private void KillAvatar(uint killerObjectLocalID, ScenePresence deadAvatar)
116  {
117  string deadAvatarMessage;
118  ScenePresence killingAvatar = null;
119 // string killingAvatarMessage;
120 
121  // check to see if it is an NPC and just remove it
122  INPCModule NPCmodule = deadAvatar.Scene.RequestModuleInterface<INPCModule>();
123  if (NPCmodule != null && NPCmodule.DeleteNPC(deadAvatar.UUID, deadAvatar.Scene))
124  {
125  return;
126  }
127 
128  if (killerObjectLocalID == 0)
129  deadAvatarMessage = "You committed suicide!";
130  else
131  {
132  // Try to get the avatar responsible for the killing
133  killingAvatar = deadAvatar.Scene.GetScenePresence(killerObjectLocalID);
134  if (killingAvatar == null)
135  {
136  // Try to get the object which was responsible for the killing
137  SceneObjectPart part = deadAvatar.Scene.GetSceneObjectPart(killerObjectLocalID);
138  if (part == null)
139  {
140  // Cause of death: Unknown
141  deadAvatarMessage = "You died!";
142  }
143  else
144  {
145  // Try to find the avatar wielding the killing object
146  killingAvatar = deadAvatar.Scene.GetScenePresence(part.OwnerID);
147  if (killingAvatar == null)
148  {
149  IUserManagement userManager = deadAvatar.Scene.RequestModuleInterface<IUserManagement>();
150  string userName = "Unkown User";
151  if (userManager != null)
152  userName = userManager.GetUserName(part.OwnerID);
153  deadAvatarMessage = String.Format("You impaled yourself on {0} owned by {1}!", part.Name, userName);
154  }
155  else
156  {
157  // killingAvatarMessage = String.Format("You fragged {0}!", deadAvatar.Name);
158  deadAvatarMessage = String.Format("You got killed by {0}!", killingAvatar.Name);
159  }
160  }
161  }
162  else
163  {
164 // killingAvatarMessage = String.Format("You fragged {0}!", deadAvatar.Name);
165  deadAvatarMessage = String.Format("You got killed by {0}!", killingAvatar.Name);
166  }
167  }
168  try
169  {
170  deadAvatar.ControllingClient.SendAgentAlertMessage(deadAvatarMessage, true);
171  if (killingAvatar != null)
172  killingAvatar.ControllingClient.SendAlertMessage("You fragged " + deadAvatar.Firstname + " " + deadAvatar.Lastname);
173  }
174  catch (InvalidOperationException)
175  { }
176 
177  deadAvatar.setHealthWithUpdate(100.0f);
178  deadAvatar.Scene.TeleportClientHome(deadAvatar.UUID, deadAvatar.ControllingClient);
179  }
180 
181  private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID)
182  {
183  try
184  {
185  ILandObject obj = avatar.Scene.LandChannel.GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
186  if (obj == null)
187  return;
188  if ((obj.LandData.Flags & (uint)ParcelFlags.AllowDamage) != 0
189  || avatar.Scene.RegionInfo.RegionSettings.AllowDamage)
190  {
191  avatar.Invulnerable = false;
192  }
193  else
194  {
195  avatar.Invulnerable = true;
196  if (avatar.Health < 100.0f)
197  {
198  avatar.setHealthWithUpdate(100.0f);
199  }
200  }
201  }
202  catch (Exception)
203  {
204  }
205  }
206  }
207 }
bool DeleteNPC(UUID agentID, Scene scene)
Delete an NPC.
Scene Scene
The scene to which this entity belongs
Definition: EntityBase.cs:46
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
Definition: CombatModule.cs:96
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
Definition: CombatModule.cs:65
Interactive OpenSim region server
Definition: OpenSim.cs:55
uint Flags
Parcel settings. Access flags, Fly, NoPush, Voice, Scripts allowed, etc. ParcelFlags ...
Definition: LandData.cs:402
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
Definition: CombatModule.cs:83
This maintains the relationship between a UUID and a user name.
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
Definition: CombatModule.cs:92