MyNpcCharacter.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Net;
  30. using libsecondlife;
  31. using libsecondlife.Packets;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.Environment.Scenes;
  34. namespace OpenSim.Region.Examples.SimpleModule
  35. {
  36. public class MyNpcCharacter : IClientAPI
  37. {
  38. private uint movementFlag = 0;
  39. private short flyState = 0;
  40. private LLQuaternion bodyDirection = LLQuaternion.Identity;
  41. private short count = 0;
  42. #pragma warning disable 67
  43. public event Action<IClientAPI> OnLogout;
  44. public event ObjectPermissions OnObjectPermissions;
  45. public event MoneyTransferRequest OnMoneyTransferRequest;
  46. public event Action<IClientAPI> OnConnectionClosed;
  47. public event ImprovedInstantMessage OnInstantMessage;
  48. public event ChatFromViewer OnChatFromViewer;
  49. public event TextureRequest OnRequestTexture;
  50. public event RezObject OnRezObject;
  51. public event ModifyTerrain OnModifyTerrain;
  52. public event SetAppearance OnSetAppearance;
  53. public event AvatarNowWearing OnAvatarNowWearing;
  54. public event RezSingleAttachmentFromInv OnRezSingleAttachmentFromInv;
  55. public event ObjectAttach OnObjectAttach;
  56. public event StartAnim OnStartAnim;
  57. public event StopAnim OnStopAnim;
  58. public event LinkObjects OnLinkObjects;
  59. public event DelinkObjects OnDelinkObjects;
  60. public event RequestMapBlocks OnRequestMapBlocks;
  61. public event RequestMapName OnMapNameRequest;
  62. public event TeleportLocationRequest OnTeleportLocationRequest;
  63. public event DisconnectUser OnDisconnectUser;
  64. public event RequestAvatarProperties OnRequestAvatarProperties;
  65. public event SetAlwaysRun OnSetAlwaysRun;
  66. public event GenericCall4 OnDeRezObject;
  67. public event Action<IClientAPI> OnRegionHandShakeReply;
  68. public event GenericCall2 OnRequestWearables;
  69. public event GenericCall2 OnCompleteMovementToRegion;
  70. public event UpdateAgent OnAgentUpdate;
  71. public event AgentRequestSit OnAgentRequestSit;
  72. public event AgentSit OnAgentSit;
  73. public event AvatarPickerRequest OnAvatarPickerRequest;
  74. public event Action<IClientAPI> OnRequestAvatarsData;
  75. public event AddNewPrim OnAddPrim;
  76. public event RequestGodlikePowers OnRequestGodlikePowers;
  77. public event GodKickUser OnGodKickUser;
  78. public event ObjectDuplicate OnObjectDuplicate;
  79. public event UpdateVector OnGrabObject;
  80. public event ObjectSelect OnDeGrabObject;
  81. public event MoveObject OnGrabUpdate;
  82. public event ViewerEffectEventHandler OnViewerEffect;
  83. public event FetchInventory OnAgentDataUpdateRequest;
  84. public event FetchInventory OnUserInfoRequest;
  85. public event TeleportLocationRequest OnSetStartLocationRequest;
  86. public event UpdateShape OnUpdatePrimShape;
  87. public event ObjectExtraParams OnUpdateExtraParams;
  88. public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
  89. public event ObjectSelect OnObjectSelect;
  90. public event GenericCall7 OnObjectDescription;
  91. public event GenericCall7 OnObjectName;
  92. public event UpdatePrimFlags OnUpdatePrimFlags;
  93. public event UpdatePrimTexture OnUpdatePrimTexture;
  94. public event UpdateVector OnUpdatePrimGroupPosition;
  95. public event UpdateVector OnUpdatePrimSinglePosition;
  96. public event UpdatePrimRotation OnUpdatePrimGroupRotation;
  97. public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
  98. public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
  99. public event UpdateVector OnUpdatePrimScale;
  100. public event StatusChange OnChildAgentStatus;
  101. public event GenericCall2 OnStopMovement;
  102. public event Action<LLUUID> OnRemoveAvatar;
  103. public event CreateNewInventoryItem OnCreateNewInventoryItem;
  104. public event CreateInventoryFolder OnCreateNewInventoryFolder;
  105. public event UpdateInventoryFolder OnUpdateInventoryFolder;
  106. public event MoveInventoryFolder OnMoveInventoryFolder;
  107. public event RemoveInventoryFolder OnRemoveInventoryFolder;
  108. public event RemoveInventoryItem OnRemoveInventoryItem;
  109. public event FetchInventoryDescendents OnFetchInventoryDescendents;
  110. public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
  111. public event FetchInventory OnFetchInventory;
  112. public event RequestTaskInventory OnRequestTaskInventory;
  113. public event UpdateInventoryItem OnUpdateInventoryItem;
  114. public event CopyInventoryItem OnCopyInventoryItem;
  115. public event MoveInventoryItem OnMoveInventoryItem;
  116. public event UDPAssetUploadRequest OnAssetUploadRequest;
  117. public event XferReceive OnXferReceive;
  118. public event RequestXfer OnRequestXfer;
  119. public event ConfirmXfer OnConfirmXfer;
  120. public event RezScript OnRezScript;
  121. public event UpdateTaskInventory OnUpdateTaskInventory;
  122. public event RemoveTaskInventory OnRemoveTaskItem;
  123. public event RequestAsset OnRequestAsset;
  124. public event UUIDNameRequest OnNameFromUUIDRequest;
  125. public event ParcelPropertiesRequest OnParcelPropertiesRequest;
  126. public event ParcelDivideRequest OnParcelDivideRequest;
  127. public event ParcelJoinRequest OnParcelJoinRequest;
  128. public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
  129. public event ParcelAccessListRequest OnParcelAccessListRequest;
  130. public event ParcelAccessListUpdateRequest OnParcelAccessListUpdateRequest;
  131. public event ParcelSelectObjects OnParcelSelectObjects;
  132. public event ParcelObjectOwnerRequest OnParcelObjectOwnerRequest;
  133. public event ObjectDeselect OnObjectDeselect;
  134. public event EstateOwnerMessageRequest OnEstateOwnerMessage;
  135. public event RegionInfoRequest OnRegionInfoRequest;
  136. public event EstateCovenantRequest OnEstateCovenantRequest;
  137. public event ObjectDuplicateOnRay OnObjectDuplicateOnRay;
  138. public event FriendActionDelegate OnApproveFriendRequest;
  139. public event FriendActionDelegate OnDenyFriendRequest;
  140. public event FriendshipTermination OnTerminateFriendship;
  141. public event PacketStats OnPacketStats;
  142. public event MoneyBalanceRequest OnMoneyBalanceRequest;
  143. public event UpdateAvatarProperties OnUpdateAvatarProperties;
  144. #pragma warning restore 67
  145. private LLUUID myID = LLUUID.Random();
  146. public MyNpcCharacter(EventManager eventManager)
  147. {
  148. // startPos = new LLVector3(128, (float)(Util.RandomClass.NextDouble()*100), 2);
  149. eventManager.OnFrame += Update;
  150. }
  151. private LLVector3 startPos = new LLVector3(128, 128, 2);
  152. public virtual LLVector3 StartPos
  153. {
  154. get { return startPos; }
  155. set { }
  156. }
  157. public virtual LLUUID AgentId
  158. {
  159. get { return myID; }
  160. }
  161. public LLUUID SessionId
  162. {
  163. get { return LLUUID.Zero; }
  164. }
  165. public LLUUID SecureSessionId
  166. {
  167. get { return LLUUID.Zero; }
  168. }
  169. public virtual string FirstName
  170. {
  171. get { return "Annoying"; }
  172. }
  173. private string lastName = "NPC" + Util.RandomClass.Next(1, 1000);
  174. public virtual string LastName
  175. {
  176. get { return lastName; }
  177. }
  178. public virtual String Name
  179. {
  180. get { return FirstName + LastName; }
  181. }
  182. public virtual void OutPacket(Packet newPack, ThrottleOutPacketType packType)
  183. {
  184. }
  185. public virtual void SendWearables(AvatarWearable[] wearables, int serial)
  186. {
  187. }
  188. public virtual void SendAppearance(LLUUID agentID, byte[] visualParams, byte[] textureEntry)
  189. {
  190. }
  191. public virtual void Kick(string message)
  192. {
  193. }
  194. public virtual void SendStartPingCheck(byte seq)
  195. {
  196. }
  197. public virtual void SendAvatarPickerReply(AvatarPickerReplyPacket response)
  198. {
  199. }
  200. public virtual void SendAgentDataUpdate(LLUUID agentid, LLUUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname, string grouptitle)
  201. {
  202. }
  203. public virtual void SendKillObject(ulong regionHandle, uint localID)
  204. {
  205. }
  206. public virtual void SetChildAgentThrottle(byte[] throttle)
  207. {
  208. }
  209. public byte[] GetThrottlesPacked(float multiplier)
  210. {
  211. return new byte[0];
  212. }
  213. public virtual void SendAnimations(LLUUID[] animations, int[] seqs, LLUUID sourceAgentId)
  214. {
  215. }
  216. public virtual void SendChatMessage(string message, byte type, LLVector3 fromPos, string fromName,
  217. LLUUID fromAgentID)
  218. {
  219. }
  220. public virtual void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName,
  221. LLUUID fromAgentID)
  222. {
  223. }
  224. public virtual void SendInstantMessage(LLUUID fromAgent, LLUUID fromAgentSession, string message, LLUUID toAgent,
  225. LLUUID imSessionID, string fromName, byte dialog, uint timeStamp)
  226. {
  227. }
  228. public virtual void SendLayerData(float[] map)
  229. {
  230. }
  231. public virtual void SendLayerData(int px, int py, float[] map)
  232. {
  233. }
  234. public virtual void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look)
  235. {
  236. }
  237. public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint)
  238. {
  239. }
  240. public virtual AgentCircuitData RequestClientInfo()
  241. {
  242. return new AgentCircuitData();
  243. }
  244. public virtual void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt,
  245. IPEndPoint newRegionExternalEndPoint, string capsURL)
  246. {
  247. }
  248. public virtual void SendMapBlock(List<MapBlockData> mapBlocks)
  249. {
  250. }
  251. public virtual void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags)
  252. {
  253. }
  254. public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint,
  255. uint locationID, uint flags, string capsURL)
  256. {
  257. }
  258. public virtual void SendTeleportFailed(string reason)
  259. {
  260. }
  261. public virtual void SendTeleportLocationStart()
  262. {
  263. }
  264. public virtual void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance)
  265. {
  266. }
  267. public virtual void SendAvatarData(ulong regionHandle, string firstName, string lastName, LLUUID avatarID,
  268. uint avatarLocalID, LLVector3 Pos, byte[] textureEntry, uint parentID)
  269. {
  270. }
  271. public virtual void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID,
  272. LLVector3 position, LLVector3 velocity, LLQuaternion rotation)
  273. {
  274. }
  275. public virtual void SendCoarseLocationUpdate(List<LLVector3> CoarseLocations)
  276. {
  277. }
  278. public virtual void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint)
  279. {
  280. }
  281. public virtual void SendDialog(string objectname, LLUUID objectID, LLUUID ownerID, string msg, LLUUID textureID, int ch, string[] buttonlabels)
  282. {
  283. }
  284. public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID,
  285. PrimitiveBaseShape primShape, LLVector3 pos, uint flags,
  286. LLUUID objectID, LLUUID ownerID, string text, byte[] color,
  287. uint parentID,
  288. byte[] particleSystem, LLQuaternion rotation, byte clickAction)
  289. {
  290. }
  291. public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID,
  292. PrimitiveBaseShape primShape, LLVector3 pos, uint flags,
  293. LLUUID objectID, LLUUID ownerID, string text, byte[] color,
  294. uint parentID,
  295. byte[] particleSystem, LLQuaternion rotation, byte clickAction, byte[] textureanimation)
  296. {
  297. }
  298. public virtual void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID,
  299. LLVector3 position, LLQuaternion rotation, byte state)
  300. {
  301. }
  302. public virtual void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID,
  303. LLVector3 position, LLQuaternion rotation, LLVector3 velocity,
  304. LLVector3 rotationalvelocity)
  305. {
  306. }
  307. public virtual void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID,
  308. List<InventoryItemBase> items,
  309. List<InventoryFolderBase> folders,
  310. bool fetchFolders,
  311. bool fetchItems)
  312. {
  313. }
  314. public virtual void SendInventoryItemDetails(LLUUID ownerID, InventoryItemBase item)
  315. {
  316. }
  317. public virtual void SendInventoryItemCreateUpdate(InventoryItemBase Item)
  318. {
  319. }
  320. public virtual void SendRemoveInventoryItem(LLUUID itemID)
  321. {
  322. }
  323. public virtual void SendTaskInventory(LLUUID taskID, short serial, byte[] fileName)
  324. {
  325. }
  326. public virtual void SendXferPacket(ulong xferID, uint packet, byte[] data)
  327. {
  328. }
  329. public virtual void SendNameReply(LLUUID profileId, string firstname, string lastname)
  330. {
  331. }
  332. public virtual void SendPreLoadSound(LLUUID objectID, LLUUID ownerID, LLUUID soundID)
  333. {
  334. }
  335. public virtual void SendPlayAttachedSound(LLUUID soundID, LLUUID objectID, LLUUID ownerID, float gain,
  336. byte flags)
  337. {
  338. }
  339. public void SendTriggeredSound(LLUUID soundID, LLUUID ownerID, LLUUID objectID, LLUUID parentID, ulong handle, LLVector3 position, float gain)
  340. {
  341. }
  342. public void SendAttachedSoundGainChange(LLUUID objectID, float gain)
  343. {
  344. }
  345. public void SendAlertMessage(string message)
  346. {
  347. }
  348. public void SendAgentAlertMessage(string message, bool modal)
  349. {
  350. }
  351. public void SendSystemAlertMessage(string message)
  352. {
  353. }
  354. public void SendLoadURL(string objectname, LLUUID objectID, LLUUID ownerID, bool groupOwned, string message,
  355. string url)
  356. {
  357. }
  358. public virtual void SendRegionHandshake(RegionInfo regionInfo)
  359. {
  360. if (OnRegionHandShakeReply != null)
  361. {
  362. OnRegionHandShakeReply(this);
  363. }
  364. if (OnCompleteMovementToRegion != null)
  365. {
  366. OnCompleteMovementToRegion();
  367. }
  368. }
  369. private void Update()
  370. {
  371. if (OnAgentUpdate != null)
  372. {
  373. AgentUpdatePacket pack = new AgentUpdatePacket();
  374. pack.AgentData.ControlFlags = movementFlag;
  375. pack.AgentData.BodyRotation = bodyDirection;
  376. OnAgentUpdate(this, pack);
  377. }
  378. if (flyState == 0)
  379. {
  380. movementFlag = (uint) AgentManager.ControlFlags.AGENT_CONTROL_FLY |
  381. (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG;
  382. flyState = 1;
  383. }
  384. else if (flyState == 1)
  385. {
  386. movementFlag = (uint) AgentManager.ControlFlags.AGENT_CONTROL_FLY |
  387. (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS;
  388. flyState = 2;
  389. }
  390. else
  391. {
  392. movementFlag = (uint) AgentManager.ControlFlags.AGENT_CONTROL_FLY;
  393. flyState = 0;
  394. }
  395. if (count >= 200)
  396. {
  397. if (OnChatFromViewer != null)
  398. {
  399. ChatFromViewerArgs args = new ChatFromViewerArgs();
  400. args.Message = "Kinda quiet around here, isn't it?";
  401. args.Channel = 0;
  402. args.From = FirstName + " " + LastName;
  403. args.Position = new LLVector3(128, 128, 26);
  404. args.Sender = this;
  405. args.Type = ChatTypeEnum.Shout;
  406. OnChatFromViewer(this, args);
  407. }
  408. count = -1;
  409. }
  410. count++;
  411. }
  412. public bool AddMoney(int debit)
  413. {
  414. return false;
  415. }
  416. public void SendSunPos(LLVector3 sunPos, LLVector3 sunVel)
  417. {
  418. }
  419. public void SendViewerTime(int phase)
  420. {
  421. }
  422. public void SendAvatarProperties(LLUUID avatarID, string aboutText, string bornOn, string charterMember,
  423. string flAbout, uint flags, LLUUID flImageID, LLUUID imageID, string profileURL,
  424. LLUUID partnerID)
  425. {
  426. }
  427. public void SetDebug(int newDebug)
  428. {
  429. }
  430. public void InPacket(Packet NewPack)
  431. {
  432. }
  433. public void Close(bool ShutdownCircuit)
  434. {
  435. }
  436. public void Stop()
  437. {
  438. }
  439. private uint m_circuitCode;
  440. public uint CircuitCode
  441. {
  442. get { return m_circuitCode; }
  443. set { m_circuitCode = value; }
  444. }
  445. public void SendBlueBoxMessage(LLUUID FromAvatarID, LLUUID fromSessionID, String FromAvatarName, String Message)
  446. {
  447. }
  448. public void SendLogoutPacket()
  449. {
  450. }
  451. public void Terminate()
  452. {
  453. }
  454. public ClientInfo GetClientInfo()
  455. {
  456. return null;
  457. }
  458. public void SetClientInfo(ClientInfo info)
  459. {
  460. }
  461. }
  462. }