mirror of
https://github.com/opensim/opensim.git
synced 2026-08-11 03:45:35 +08:00
Resolve merge commits, stage 1
This commit is contained in:
@@ -37,6 +37,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||
{
|
||||
public class NPCAvatar : IClientAPI
|
||||
{
|
||||
/// <summary>
|
||||
/// Signal whether the avatar should land when it reaches a move target
|
||||
/// </summary>
|
||||
public bool LandAtTarget { get; set; }
|
||||
|
||||
private readonly string m_firstname;
|
||||
private readonly string m_lastname;
|
||||
private readonly Vector3 m_startPos;
|
||||
@@ -99,6 +104,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void SendSitResponse(UUID TargetID, Vector3 OffsetPos, Quaternion SitOrientation, bool autopilot,
|
||||
Vector3 CameraAtOffset, Vector3 CameraEyeOffset, bool ForceMouseLook)
|
||||
{
|
||||
@@ -189,7 +195,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||
public event DeRezObject OnDeRezObject;
|
||||
public event Action<IClientAPI> OnRegionHandShakeReply;
|
||||
public event GenericCall1 OnRequestWearables;
|
||||
public event GenericCall1 OnCompleteMovementToRegion;
|
||||
public event Action<IClientAPI, bool> OnCompleteMovementToRegion;
|
||||
public event UpdateAgent OnPreAgentUpdate;
|
||||
public event UpdateAgent OnAgentUpdate;
|
||||
public event AgentRequestSit OnAgentRequestSit;
|
||||
@@ -327,7 +333,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||
public event ScriptReset OnScriptReset;
|
||||
public event GetScriptRunning OnGetScriptRunning;
|
||||
public event SetScriptRunning OnSetScriptRunning;
|
||||
public event UpdateVector OnAutoPilotGo;
|
||||
public event Action<Vector3, bool> OnAutoPilotGo;
|
||||
|
||||
public event TerrainUnacked OnUnackedTerrain;
|
||||
|
||||
@@ -744,12 +750,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||
{
|
||||
OnRegionHandShakeReply(this);
|
||||
}
|
||||
|
||||
if (OnCompleteMovementToRegion != null)
|
||||
{
|
||||
OnCompleteMovementToRegion(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendAssetUploadCompleteMessage(sbyte AssetType, bool Success, UUID AssetFullID)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -44,32 +44,119 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
// private const bool m_enabled = false;
|
||||
|
||||
private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>();
|
||||
private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>();
|
||||
private Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>();
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource source)
|
||||
{
|
||||
scene.RegisterModuleInterface<INPCModule>(this);
|
||||
}
|
||||
IConfig config = source.Configs["NPC"];
|
||||
|
||||
private AvatarAppearance GetAppearance(UUID target, Scene scene)
|
||||
{
|
||||
if (m_appearanceCache.ContainsKey(target))
|
||||
return m_appearanceCache[target];
|
||||
|
||||
AvatarAppearance appearance = scene.AvatarService.GetAppearance(target);
|
||||
if (appearance != null)
|
||||
if (config != null && config.GetBoolean("Enabled", false))
|
||||
{
|
||||
m_appearanceCache.Add(target, appearance);
|
||||
return appearance;
|
||||
scene.RegisterModuleInterface<INPCModule>(this);
|
||||
scene.EventManager.OnSignificantClientMovement += HandleOnSignificantClientMovement;
|
||||
}
|
||||
|
||||
return new AvatarAppearance();
|
||||
}
|
||||
|
||||
public UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, UUID cloneAppearanceFrom)
|
||||
public void HandleOnSignificantClientMovement(ScenePresence presence)
|
||||
{
|
||||
lock (m_avatars)
|
||||
{
|
||||
if (m_avatars.ContainsKey(presence.UUID) && presence.MovingToTarget)
|
||||
{
|
||||
double distanceToTarget = Util.GetDistanceTo(presence.AbsolutePosition, presence.MoveToPositionTarget);
|
||||
// m_log.DebugFormat(
|
||||
// "[NPC MODULE]: Abs pos of {0} is {1}, target {2}, distance {3}",
|
||||
// presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget, distanceToTarget);
|
||||
|
||||
// Check the error term of the current position in relation to the target position
|
||||
if (distanceToTarget <= ScenePresence.SIGNIFICANT_MOVEMENT)
|
||||
{
|
||||
// We are close enough to the target
|
||||
m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0}", presence.Name);
|
||||
|
||||
presence.Velocity = Vector3.Zero;
|
||||
presence.AbsolutePosition = presence.MoveToPositionTarget;
|
||||
presence.ResetMoveToTarget();
|
||||
|
||||
if (presence.PhysicsActor.Flying)
|
||||
{
|
||||
// A horrible hack to stop the NPC dead in its tracks rather than having them overshoot
|
||||
// the target if flying.
|
||||
// We really need to be more subtle (slow the avatar as it approaches the target) or at
|
||||
// least be able to set collision status once, rather than 5 times to give it enough
|
||||
// weighting so that that PhysicsActor thinks it really is colliding.
|
||||
for (int i = 0; i < 5; i++)
|
||||
presence.PhysicsActor.IsColliding = true;
|
||||
|
||||
// Vector3 targetPos = presence.MoveToPositionTarget;
|
||||
if (m_avatars[presence.UUID].LandAtTarget)
|
||||
presence.PhysicsActor.Flying = false;
|
||||
|
||||
// float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y];
|
||||
// if (targetPos.Z - terrainHeight < 0.2)
|
||||
// {
|
||||
// presence.PhysicsActor.Flying = false;
|
||||
// }
|
||||
}
|
||||
|
||||
// m_log.DebugFormat(
|
||||
// "[NPC MODULE]: AgentControlFlags {0}, MovementFlag {1} for {2}",
|
||||
// presence.AgentControlFlags, presence.MovementFlag, presence.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// m_log.DebugFormat(
|
||||
// "[NPC MODULE]: Updating npc {0} at {1} for next movement to {2}",
|
||||
// presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget);
|
||||
|
||||
Vector3 agent_control_v3 = new Vector3();
|
||||
presence.HandleMoveToTargetUpdate(ref agent_control_v3);
|
||||
presence.AddNewMovement(agent_control_v3);
|
||||
}
|
||||
//
|
||||
//// presence.DoMoveToPositionUpdate((0, presence.MoveToPositionTarget, null);
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsNPC(UUID agentId, Scene scene)
|
||||
{
|
||||
ScenePresence sp = scene.GetScenePresence(agentId);
|
||||
if (sp == null || sp.IsChildAgent)
|
||||
return false;
|
||||
|
||||
lock (m_avatars)
|
||||
return m_avatars.ContainsKey(agentId);
|
||||
}
|
||||
|
||||
public bool SetNPCAppearance(UUID agentId, AvatarAppearance appearance, Scene scene)
|
||||
{
|
||||
ScenePresence sp = scene.GetScenePresence(agentId);
|
||||
if (sp == null || sp.IsChildAgent)
|
||||
return false;
|
||||
|
||||
lock (m_avatars)
|
||||
if (!m_avatars.ContainsKey(agentId))
|
||||
return false;
|
||||
|
||||
scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, false);
|
||||
|
||||
AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true);
|
||||
sp.Appearance = npcAppearance;
|
||||
scene.AttachmentsModule.RezAttachments(sp);
|
||||
|
||||
IAvatarFactory module = scene.RequestModuleInterface<IAvatarFactory>();
|
||||
module.SendAppearance(sp.UUID);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public UUID CreateNPC(
|
||||
string firstname, string lastname, Vector3 position, Scene scene, AvatarAppearance appearance)
|
||||
{
|
||||
NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene);
|
||||
npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue);
|
||||
@@ -84,12 +171,18 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||
acd.lastname = lastname;
|
||||
acd.ServiceURLs = new Dictionary<string, object>();
|
||||
|
||||
AvatarAppearance originalAppearance = GetAppearance(cloneAppearanceFrom, scene);
|
||||
AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true);
|
||||
AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true);
|
||||
acd.Appearance = npcAppearance;
|
||||
|
||||
// for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++)
|
||||
// {
|
||||
// m_log.DebugFormat(
|
||||
// "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
|
||||
// acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]);
|
||||
// }
|
||||
|
||||
scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
|
||||
scene.AddNewClient(npcAvatar);
|
||||
scene.AddNewClient(npcAvatar, PresenceType.Npc);
|
||||
|
||||
ScenePresence sp;
|
||||
if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
|
||||
@@ -97,13 +190,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||
m_log.DebugFormat(
|
||||
"[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID);
|
||||
|
||||
// Shouldn't call this - temporary.
|
||||
sp.CompleteMovement(npcAvatar);
|
||||
|
||||
// sp.SendAppearanceToAllOtherAgents();
|
||||
//
|
||||
// // Send animations back to the avatar as well
|
||||
// sp.Animator.SendAnimPack();
|
||||
sp.CompleteMovement(npcAvatar, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -118,7 +205,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||
return npcAvatar.AgentId;
|
||||
}
|
||||
|
||||
public void Autopilot(UUID agentID, Scene scene, Vector3 pos)
|
||||
public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget)
|
||||
{
|
||||
lock (m_avatars)
|
||||
{
|
||||
@@ -126,32 +213,72 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||
{
|
||||
ScenePresence sp;
|
||||
scene.TryGetScenePresence(agentID, out sp);
|
||||
sp.DoAutoPilot(0, pos, m_avatars[agentID]);
|
||||
|
||||
m_log.DebugFormat(
|
||||
"[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
|
||||
sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget);
|
||||
|
||||
m_avatars[agentID].LandAtTarget = landAtTarget;
|
||||
sp.MoveToTarget(pos, noFly);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Say(UUID agentID, Scene scene, string text)
|
||||
public bool StopMoveToTarget(UUID agentID, Scene scene)
|
||||
{
|
||||
lock (m_avatars)
|
||||
{
|
||||
if (m_avatars.ContainsKey(agentID))
|
||||
{
|
||||
ScenePresence sp;
|
||||
scene.TryGetScenePresence(agentID, out sp);
|
||||
|
||||
sp.Velocity = Vector3.Zero;
|
||||
sp.ResetMoveToTarget();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Say(UUID agentID, Scene scene, string text)
|
||||
{
|
||||
lock (m_avatars)
|
||||
{
|
||||
if (m_avatars.ContainsKey(agentID))
|
||||
{
|
||||
ScenePresence sp;
|
||||
scene.TryGetScenePresence(agentID, out sp);
|
||||
|
||||
m_avatars[agentID].Say(text);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void DeleteNPC(UUID agentID, Scene scene)
|
||||
public bool DeleteNPC(UUID agentID, Scene scene)
|
||||
{
|
||||
lock (m_avatars)
|
||||
{
|
||||
if (m_avatars.ContainsKey(agentID))
|
||||
{
|
||||
scene.RemoveClient(agentID);
|
||||
scene.RemoveClient(agentID, false);
|
||||
m_avatars.Remove(agentID);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
|
||||
@@ -27,11 +27,14 @@
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
using Nini.Config;
|
||||
using NUnit.Framework;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Communications;
|
||||
using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
|
||||
using OpenSim.Region.CoreModules.Framework.UserManagement;
|
||||
using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
@@ -47,25 +50,112 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
||||
[Test]
|
||||
public void TestCreate()
|
||||
{
|
||||
TestHelper.InMethod();
|
||||
TestHelpers.InMethod();
|
||||
// log4net.Config.XmlConfigurator.Configure();
|
||||
|
||||
IConfigSource config = new IniConfigSource();
|
||||
config.AddConfig("NPC");
|
||||
config.Configs["NPC"].Set("Enabled", "true");
|
||||
|
||||
AvatarFactoryModule afm = new AvatarFactoryModule();
|
||||
UserManagementModule umm = new UserManagementModule();
|
||||
|
||||
TestScene scene = SceneHelpers.SetupScene();
|
||||
SceneHelpers.SetupSceneModules(scene, config, afm, umm, new NPCModule());
|
||||
ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
|
||||
// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
|
||||
|
||||
// 8 is the index of the first baked texture in AvatarAppearance
|
||||
UUID originalFace8TextureId = TestHelpers.ParseTail(0x10);
|
||||
Primitive.TextureEntry originalTe = new Primitive.TextureEntry(UUID.Zero);
|
||||
Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8);
|
||||
originalTef.TextureID = originalFace8TextureId;
|
||||
|
||||
// We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell
|
||||
// ScenePresence.SendInitialData() to reset our entire appearance.
|
||||
scene.AssetService.Store(AssetHelpers.CreateAsset(originalFace8TextureId));
|
||||
|
||||
afm.SetAppearanceFromClient(sp.ControllingClient, originalTe, null);
|
||||
|
||||
INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
|
||||
UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance);
|
||||
|
||||
ScenePresence npc = scene.GetScenePresence(npcId);
|
||||
|
||||
Assert.That(npc, Is.Not.Null);
|
||||
Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId));
|
||||
Assert.That(umm.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMove()
|
||||
{
|
||||
TestHelpers.InMethod();
|
||||
// log4net.Config.XmlConfigurator.Configure();
|
||||
|
||||
IConfigSource config = new IniConfigSource();
|
||||
|
||||
config.AddConfig("Modules");
|
||||
config.Configs["Modules"].Set("AvatarServices", "LocalAvatarServicesConnector");
|
||||
config.AddConfig("AvatarService");
|
||||
config.Configs["AvatarService"].Set("LocalServiceModule", "OpenSim.Services.AvatarService.dll:AvatarService");
|
||||
config.Configs["AvatarService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
|
||||
config.AddConfig("NPC");
|
||||
config.Configs["NPC"].Set("Enabled", "true");
|
||||
|
||||
TestScene scene = SceneSetupHelpers.SetupScene();
|
||||
SceneSetupHelpers.SetupSceneModules(scene, config, new NPCModule(), new LocalAvatarServicesConnector());
|
||||
TestScene scene = SceneHelpers.SetupScene();
|
||||
SceneHelpers.SetupSceneModules(scene, config, new NPCModule());
|
||||
ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
|
||||
// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
|
||||
|
||||
Vector3 startPos = new Vector3(128, 128, 30);
|
||||
INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
|
||||
UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, UUID.Zero);
|
||||
UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance);
|
||||
|
||||
ScenePresence npc = scene.GetScenePresence(npcId);
|
||||
Assert.That(npc, Is.Not.Null);
|
||||
Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
|
||||
|
||||
// For now, we'll make the scene presence fly to simplify this test, but this needs to change.
|
||||
npc.PhysicsActor.Flying = true;
|
||||
|
||||
scene.Update();
|
||||
Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
|
||||
|
||||
Vector3 targetPos = startPos + new Vector3(0, 0, 10);
|
||||
npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false);
|
||||
|
||||
Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
|
||||
|
||||
scene.Update();
|
||||
|
||||
// We should really check the exact figure.
|
||||
Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X));
|
||||
Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
|
||||
Assert.That(npc.AbsolutePosition.Z, Is.GreaterThan(startPos.Z));
|
||||
Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.Z));
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
scene.Update();
|
||||
|
||||
double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
|
||||
Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move");
|
||||
Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
|
||||
Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));
|
||||
|
||||
// Try a second movement
|
||||
startPos = npc.AbsolutePosition;
|
||||
targetPos = startPos + new Vector3(10, 0, 0);
|
||||
npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false);
|
||||
|
||||
scene.Update();
|
||||
|
||||
// We should really check the exact figure.
|
||||
Assert.That(npc.AbsolutePosition.X, Is.GreaterThan(startPos.X));
|
||||
Assert.That(npc.AbsolutePosition.X, Is.LessThan(targetPos.X));
|
||||
Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
|
||||
Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
scene.Update();
|
||||
|
||||
distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
|
||||
Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move");
|
||||
Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -381,7 +381,6 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator
|
||||
{
|
||||
SceneObjectPart selectedTree = ((SceneObjectGroup)m_scene.Entities[tree]).RootPart;
|
||||
|
||||
|
||||
m_scene.DeleteSceneObject(selectedTree.ParentGroup, false);
|
||||
m_scene.ForEachClient(delegate(IClientAPI controller)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user