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! --- .../Currency/SampleMoney/SampleMoneyModule.cs | 77 +++++++++++++++++++++- .../Environment/Modules/World/Land/LandObject.cs | 5 ++ OpenSim/Region/Environment/Scenes/SceneEvents.cs | 13 ++++ OpenSim/Region/Environment/Scenes/ScenePresence.cs | 56 +++++++++++++++- 4 files changed, 147 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs index 966c5e2..aa7e690 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs @@ -186,6 +186,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney scene.EventManager.OnClientClosed += ClientLoggedOut; scene.EventManager.OnValidateLandBuy += ValidateLandBuy; scene.EventManager.OnLandBuy += processLandBuy; + scene.EventManager.OnAvatarKilled += KillAvatar; } } @@ -1390,7 +1391,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney { if (avatar.Scene.RegionInfo.originRegionID != m_rootAgents[avatar.UUID]) { + + m_rootAgents[avatar.UUID] = avatar.Scene.RegionInfo.originRegionID; + + //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); // Claim User! my user! Mine mine mine! if (m_MoneyAddress.Length > 0) @@ -1400,12 +1405,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney { Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret); - if ((bool) hresult["success"] == true) + if ((bool)hresult["success"] == true) { int funds = 0; try { - funds = (Int32) hresult["funds"]; + funds = (Int32)hresult["funds"]; } catch (InvalidCastException) { @@ -1414,11 +1419,23 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney } else { - avatar.ControllingClient.SendAgentAlertMessage((string) hresult["errorMessage"], true); + avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true); } } } } + else + { + ILandObject obj = avatar.Scene.LandChannel.getLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); + if ((obj.landData.landFlags & (uint)Parcel.ParcelFlags.AllowDamage) != 0) + { + avatar.Invulnerable = false; + } + else + { + avatar.Invulnerable = true; + } + } } else { @@ -1457,6 +1474,60 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); } + private void KillAvatar(uint killerObjectLocalID, ScenePresence DeadAvatar) + { + if (killerObjectLocalID == 0) + DeadAvatar.ControllingClient.SendAgentAlertMessage("You committed suicide!", true); + else + { + bool foundResult = false; + string resultstring = ""; + List allav = DeadAvatar.Scene.GetScenePresences(); + try + { + foreach (ScenePresence av in allav) + { + if (av.LocalId == killerObjectLocalID) + { + av.ControllingClient.SendAlertMessage("You fragged " + DeadAvatar.Firstname + " " + DeadAvatar.Lastname); + resultstring = av.Firstname + " " + av.Lastname; + foundResult = true; + } + } + } catch (System.InvalidOperationException) + { + + } + + if (!foundResult) + { + SceneObjectPart part = DeadAvatar.Scene.GetSceneObjectPart(killerObjectLocalID); + if (part != null) + { + ScenePresence av = DeadAvatar.Scene.GetScenePresence(part.OwnerID); + if (av != null) + { + av.ControllingClient.SendAlertMessage("You fragged " + DeadAvatar.Firstname + " " + DeadAvatar.Lastname); + resultstring = av.Firstname + " " + av.Lastname; + DeadAvatar.ControllingClient.SendAgentAlertMessage("You got killed by " + resultstring + "!", true); + } + else + { + string killer = DeadAvatar.Scene.CommsManager.UUIDNameRequestString(part.OwnerID); + DeadAvatar.ControllingClient.SendAgentAlertMessage("You impailed yourself on " + part.Name + " owned by " + killer +"!", true); + } + //DeadAvatar.Scene. part.ObjectOwner + } + else + { + DeadAvatar.ControllingClient.SendAgentAlertMessage("You died!", true); + } + } + } + DeadAvatar.Health = 100; + DeadAvatar.Scene.TeleportClientHome(DeadAvatar.UUID, DeadAvatar.ControllingClient); + } + #endregion } diff --git a/OpenSim/Region/Environment/Modules/World/Land/LandObject.cs b/OpenSim/Region/Environment/Modules/World/Land/LandObject.cs index e297b10..628ea04 100644 --- a/OpenSim/Region/Environment/Modules/World/Land/LandObject.cs +++ b/OpenSim/Region/Environment/Modules/World/Land/LandObject.cs @@ -336,6 +336,11 @@ namespace OpenSim.Region.Environment.Modules.World.Land { if (over.landData.localID == landData.localID) { + if ((over.landData.landFlags & (uint)Parcel.ParcelFlags.AllowDamage) != 0) + avatars[i].Invulnerable = false; + else + avatars[i].Invulnerable = true; + sendLandUpdateToClient(avatars[i].ControllingClient); } } 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