2008-10-16 20:50:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) Contributors, http://opensimulator.org/
|
|
|
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2009-07-02 02:46:40 +00:00
|
|
|
* * Neither the name of the OpenSim Project nor the
|
2008-10-16 20:50:28 +00:00
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2009-02-12 18:59:45 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Nini.Config;
|
2011-03-25 23:05:51 +00:00
|
|
|
using OpenSim.Framework;
|
2009-02-12 18:59:45 +00:00
|
|
|
using OpenSim.Region.Framework.Interfaces;
|
|
|
|
using OpenSim.Region.Framework.Scenes;
|
2015-01-09 16:31:56 +00:00
|
|
|
using OpenSim.Services.Interfaces;
|
2009-07-02 02:46:40 +00:00
|
|
|
using OpenMetaverse;
|
2009-02-12 18:59:45 +00:00
|
|
|
|
2012-11-11 00:42:52 +00:00
|
|
|
using Mono.Addins;
|
|
|
|
|
2009-02-10 13:10:57 +00:00
|
|
|
namespace OpenSim.Region.CoreModules.Avatar.Combat.CombatModule
|
2008-10-16 20:50:28 +00:00
|
|
|
{
|
2012-11-13 02:08:02 +00:00
|
|
|
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "CombatModule")]
|
2012-11-11 00:42:52 +00:00
|
|
|
public class CombatModule : ISharedRegionModule
|
2008-10-16 20:50:28 +00:00
|
|
|
{
|
2008-10-17 20:45:07 +00:00
|
|
|
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
2008-10-16 20:50:28 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Region UUIDS indexed by AgentID
|
|
|
|
/// </summary>
|
2008-10-17 20:45:07 +00:00
|
|
|
//private Dictionary<UUID, UUID> m_rootAgents = new Dictionary<UUID, UUID>();
|
2008-10-16 20:50:28 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Scenes by Region Handle
|
|
|
|
/// </summary>
|
|
|
|
private Dictionary<ulong, Scene> m_scenel = new Dictionary<ulong, Scene>();
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Startup
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="scene"></param>
|
|
|
|
/// <param name="config"></param>
|
2012-11-11 00:42:52 +00:00
|
|
|
public void Initialise(IConfigSource config)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddRegion(Scene scene)
|
2008-10-16 20:50:28 +00:00
|
|
|
{
|
|
|
|
lock (m_scenel)
|
|
|
|
{
|
|
|
|
if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
|
|
|
|
{
|
|
|
|
m_scenel[scene.RegionInfo.RegionHandle] = scene;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scene.EventManager.OnAvatarKilled += KillAvatar;
|
|
|
|
}
|
|
|
|
|
2012-11-11 00:42:52 +00:00
|
|
|
public void RemoveRegion(Scene scene)
|
|
|
|
{
|
|
|
|
if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
|
|
|
|
m_scenel.Remove(scene.RegionInfo.RegionHandle);
|
|
|
|
|
|
|
|
scene.EventManager.OnAvatarKilled -= KillAvatar;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RegionLoaded(Scene scene)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-10-16 20:50:28 +00:00
|
|
|
public void PostInitialise()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get { return "CombatModule"; }
|
|
|
|
}
|
|
|
|
|
2012-11-11 00:42:52 +00:00
|
|
|
public Type ReplaceableInterface
|
2008-10-16 20:50:28 +00:00
|
|
|
{
|
2012-11-11 00:42:52 +00:00
|
|
|
get { return null; }
|
2008-10-16 20:50:28 +00:00
|
|
|
}
|
|
|
|
|
2012-11-11 00:42:52 +00:00
|
|
|
|
2010-03-17 13:40:00 +00:00
|
|
|
private void KillAvatar(uint killerObjectLocalID, ScenePresence deadAvatar)
|
2008-10-16 20:50:28 +00:00
|
|
|
{
|
2010-03-17 13:40:00 +00:00
|
|
|
string deadAvatarMessage;
|
|
|
|
ScenePresence killingAvatar = null;
|
2010-08-13 20:44:44 +00:00
|
|
|
// string killingAvatarMessage;
|
2010-03-17 13:40:00 +00:00
|
|
|
|
2012-05-04 18:37:13 +00:00
|
|
|
// check to see if it is an NPC and just remove it
|
|
|
|
INPCModule NPCmodule = deadAvatar.Scene.RequestModuleInterface<INPCModule>();
|
|
|
|
if (NPCmodule != null && NPCmodule.DeleteNPC(deadAvatar.UUID, deadAvatar.Scene))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-16 20:50:28 +00:00
|
|
|
if (killerObjectLocalID == 0)
|
2010-03-17 13:40:00 +00:00
|
|
|
deadAvatarMessage = "You committed suicide!";
|
2008-10-16 20:50:28 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-17 13:40:00 +00:00
|
|
|
// Try to get the avatar responsible for the killing
|
|
|
|
killingAvatar = deadAvatar.Scene.GetScenePresence(killerObjectLocalID);
|
|
|
|
if (killingAvatar == null)
|
2008-10-16 20:50:28 +00:00
|
|
|
{
|
2010-03-17 13:40:00 +00:00
|
|
|
// Try to get the object which was responsible for the killing
|
|
|
|
SceneObjectPart part = deadAvatar.Scene.GetSceneObjectPart(killerObjectLocalID);
|
|
|
|
if (part == null)
|
2008-10-16 20:50:28 +00:00
|
|
|
{
|
2010-03-17 13:40:00 +00:00
|
|
|
// Cause of death: Unknown
|
|
|
|
deadAvatarMessage = "You died!";
|
2008-10-16 20:50:28 +00:00
|
|
|
}
|
2010-03-17 13:40:00 +00:00
|
|
|
else
|
2008-10-16 20:50:28 +00:00
|
|
|
{
|
2010-03-17 13:40:00 +00:00
|
|
|
// Try to find the avatar wielding the killing object
|
|
|
|
killingAvatar = deadAvatar.Scene.GetScenePresence(part.OwnerID);
|
|
|
|
if (killingAvatar == null)
|
2010-11-21 21:16:52 +00:00
|
|
|
{
|
|
|
|
IUserManagement userManager = deadAvatar.Scene.RequestModuleInterface<IUserManagement>();
|
|
|
|
string userName = "Unkown User";
|
|
|
|
if (userManager != null)
|
|
|
|
userName = userManager.GetUserName(part.OwnerID);
|
|
|
|
deadAvatarMessage = String.Format("You impaled yourself on {0} owned by {1}!", part.Name, userName);
|
|
|
|
}
|
2008-10-16 20:50:28 +00:00
|
|
|
else
|
|
|
|
{
|
2010-11-21 21:16:52 +00:00
|
|
|
// killingAvatarMessage = String.Format("You fragged {0}!", deadAvatar.Name);
|
2010-03-17 13:40:00 +00:00
|
|
|
deadAvatarMessage = String.Format("You got killed by {0}!", killingAvatar.Name);
|
2008-10-16 20:50:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-17 13:40:00 +00:00
|
|
|
else
|
|
|
|
{
|
2010-08-13 20:44:44 +00:00
|
|
|
// killingAvatarMessage = String.Format("You fragged {0}!", deadAvatar.Name);
|
2010-03-17 13:40:00 +00:00
|
|
|
deadAvatarMessage = String.Format("You got killed by {0}!", killingAvatar.Name);
|
|
|
|
}
|
2008-10-16 20:50:28 +00:00
|
|
|
}
|
2010-03-17 13:40:00 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
deadAvatar.ControllingClient.SendAgentAlertMessage(deadAvatarMessage, true);
|
2010-09-12 17:43:49 +00:00
|
|
|
if (killingAvatar != null)
|
2010-03-17 13:40:00 +00:00
|
|
|
killingAvatar.ControllingClient.SendAlertMessage("You fragged " + deadAvatar.Firstname + " " + deadAvatar.Lastname);
|
|
|
|
}
|
|
|
|
catch (InvalidOperationException)
|
|
|
|
{ }
|
|
|
|
|
2012-05-04 18:37:13 +00:00
|
|
|
deadAvatar.setHealthWithUpdate(100.0f);
|
2010-03-17 13:40:00 +00:00
|
|
|
deadAvatar.Scene.TeleportClientHome(deadAvatar.UUID, deadAvatar.ControllingClient);
|
2008-10-16 20:50:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|