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! --- .../Communications/CommunicationsManager.cs | 13 ++++ OpenSim/Framework/IClientAPI.cs | 1 + .../Region/ClientStack/LindenUDP/LLClientView.cs | 6 ++ .../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 +++++++++++++++- .../Region/Examples/SimpleModule/MyNpcCharacter.cs | 3 + OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 4 +- 9 files changed, 173 insertions(+), 5 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Communications/CommunicationsManager.cs b/OpenSim/Framework/Communications/CommunicationsManager.cs index ee0d164..2813aa0 100644 --- a/OpenSim/Framework/Communications/CommunicationsManager.cs +++ b/OpenSim/Framework/Communications/CommunicationsManager.cs @@ -259,6 +259,19 @@ namespace OpenSim.Framework.Communications } } } + public string UUIDNameRequestString(LLUUID uuid) + { + UserProfileData profileData = m_userService.GetUserProfile(uuid); + if (profileData != null) + { + //LLUUID profileId = profileData.ID; + string firstname = profileData.FirstName; + string lastname = profileData.SurName; + + return firstname + " " + lastname; + } + return "(hippos)"; + } public List GenerateAgentPickerRequestResponse(LLUUID queryID, string query) { diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 8f41728..02dfc8c 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -729,6 +729,7 @@ namespace OpenSim.Framework uint flags, LLUUID flImageID, LLUUID imageID, string profileURL, LLUUID partnerID); void SendScriptQuestion(LLUUID taskID, string taskName, string ownerName, LLUUID itemID, int question); + void SendHealth(float health); byte[] GetThrottlesPacked(float multiplier); diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 9d77a14..c890b31 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -4849,6 +4849,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP OutPacket(logReply, ThrottleOutPacketType.Task); } + public void SendHealth(float health) + { + HealthMessagePacket healthpacket = (HealthMessagePacket)PacketPool.Instance.GetPacket(PacketType.HealthMessage); + healthpacket.HealthData.Health = health; + OutPacket(healthpacket, ThrottleOutPacketType.Task); + } public ClientInfo GetClientInfo() { 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) diff --git a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs index a227d82..25c9093 100644 --- a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs @@ -615,5 +615,8 @@ namespace OpenSim.Region.Examples.SimpleModule public void SendScriptQuestion(LLUUID objectID, string taskName, string ownerName, LLUUID itemID, int question) { } + public void SendHealth(float health) + { + } } } diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 39f94cb..3d0855f 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -113,7 +113,7 @@ namespace OpenSim.Region.Physics.OdePlugin public bool collidelock = false; public int m_eventsubscription = 0; - private CollisionEventUpdate CollisionEventsThisFrame = null; + private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate(); public OdeCharacter(String avName, OdeScene parent_scene, PhysicsVector pos, CollisionLocker dode, PhysicsVector size) { @@ -869,9 +869,11 @@ namespace OpenSim.Region.Physics.OdePlugin public override void SubscribeEvents(int ms) { m_eventsubscription = ms; + _parent_scene.addCollisionEventReporting(this); } public override void UnSubscribeEvents() { + _parent_scene.remCollisionEventReporting(this); m_eventsubscription = 0; } public void AddCollisionEvent(uint CollidedWith, float depth) -- cgit v1.1