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