From e8acb49fefc0e567510b4058b6571599a0158b62 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sat, 3 May 2008 15:39:40 +0000 Subject: * For your fragging desire, damage enabled land works, but watch out!, life does not regenerate until you're dead! --- OpenSim/Region/Environment/Scenes/SceneEvents.cs | 13 +++++ OpenSim/Region/Environment/Scenes/ScenePresence.cs | 56 +++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Environment/Scenes') diff --git a/OpenSim/Region/Environment/Scenes/SceneEvents.cs b/OpenSim/Region/Environment/Scenes/SceneEvents.cs index 002fc5d..53a8d0f 100644 --- a/OpenSim/Region/Environment/Scenes/SceneEvents.cs +++ b/OpenSim/Region/Environment/Scenes/SceneEvents.cs @@ -151,6 +151,10 @@ namespace OpenSim.Region.Environment.Scenes public event NewInventoryItemUploadComplete OnNewInventoryItemUploadComplete; + public delegate void AvatarKillData(uint KillerLocalID, ScenePresence avatar); + + public event AvatarKillData OnAvatarKilled; + /// /// RegisterCapsEvent is called by Scene after the Caps object /// has been instantiated and before it is return to the @@ -267,6 +271,7 @@ namespace OpenSim.Region.Environment.Scenes private NewInventoryItemUploadComplete handlerNewInventoryItemUpdateComplete = null; private LandBuy handlerLandBuy = null; private LandBuy handlerValidateLandBuy = null; + private AvatarKillData handlerAvatarKill = null; public void TriggerOnScriptChangedEvent(uint localID, uint change) { @@ -574,5 +579,13 @@ namespace OpenSim.Region.Environment.Scenes handlerScriptNotAtTargetEvent(localID); } } + public void TriggerAvatarKill(uint KillerObjectLocalID, ScenePresence DeadAvatar) + { + handlerAvatarKill = OnAvatarKilled; + if (handlerAvatarKill != null) + { + handlerAvatarKill(KillerObjectLocalID, DeadAvatar); + } + } } } diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 6a50336..453c18f 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -67,6 +67,9 @@ namespace OpenSim.Region.Environment.Scenes private LLVector3 m_requestedSitOffset = new LLVector3(); private float m_sitAvatarHeight = 2.0f; private float m_godlevel = 0; + + private bool m_invulnerable = true; + private LLVector3 m_LastChildAgentUpdatePosition = new LLVector3(); private int m_perfMonMS = 0; @@ -83,6 +86,7 @@ namespace OpenSim.Region.Environment.Scenes private bool m_newForce = false; private bool m_newCoarseLocations = true; private bool m_gotAllObjectsInScene = false; + private float m_health = 100f; private LLVector3 m_lastVelocity = LLVector3.Zero; @@ -183,6 +187,11 @@ namespace OpenSim.Region.Environment.Scenes set { m_updateflag = value; } get { return m_updateflag; } } + public bool Invulnerable + { + set { m_invulnerable = value; } + get { return m_invulnerable; } + } private readonly ulong m_regionHandle; @@ -334,6 +343,11 @@ namespace OpenSim.Region.Environment.Scenes get { return m_parentID; } set { m_parentID = value; } } + public float Health + { + get { return m_health; } + set { m_health = value; } + } /// /// These are the region handles known by the avatar. @@ -602,6 +616,7 @@ namespace OpenSim.Region.Environment.Scenes { m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; + m_physicsActor.UnSubscribeEvents(); m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; PhysicsActor = null; } @@ -1894,16 +1909,55 @@ namespace OpenSim.Region.Environment.Scenes } //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; + m_physicsActor.SubscribeEvents(1000); m_physicsActor.LocalID = LocalId; } // Event called by the physics plugin to tell the avatar about a collision. private void PhysicsCollisionUpdate(EventArgs e) { + if (e == null) + return; + CollisionEventUpdate collisionData = (CollisionEventUpdate)e; + Dictionary coldata = collisionData.m_objCollisionList; + float starthealth = Health; + uint killerObj = 0; + foreach (uint localid in coldata.Keys) + { + if (coldata[localid] <= 0.10f || m_invulnerable) + continue; + //if (localid == 0) + //continue; + + Health -= coldata[localid] * 5; + + if (Health <= 0) + { + if (localid != 0) + killerObj = localid; + } + //m_log.Debug("[AVATAR]: Collision with localid: " + localid.ToString() + " at depth: " + coldata[localid].ToString()); + } + //Health = 100; + if (!m_invulnerable) + { + if (starthealth != Health) + { + ControllingClient.SendHealth(Health); + } + if (m_health <= 0) + m_scene.EventManager.TriggerAvatarKill(killerObj, this); + } + + bool isUserMoving = Velocity.X > 0 || Velocity.Y > 0; UpdateMovementAnimations(isUserMoving); } - + public void setHealthWithUpdate(float health) + { + Health = health; + ControllingClient.SendHealth(Health); + } internal void Close() { lock (m_attachments) -- cgit v1.1