MyNpcCharacter.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. */
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using libsecondlife;
  32. using libsecondlife.Packets;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Environment.Scenes;
  35. namespace SimpleApp
  36. {
  37. public class MyNpcCharacter : IClientAPI
  38. {
  39. private uint movementFlag = 0;
  40. private short flyState = 0;
  41. private LLQuaternion bodyDirection = LLQuaternion.Identity;
  42. private short count = 0;
  43. #pragma warning disable 67
  44. public event Action<IClientAPI> OnLogout;
  45. public event ObjectPermissions OnObjectPermissions;
  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 StartAnim OnStartAnim;
  55. public event StopAnim OnStopAnim;
  56. public event LinkObjects OnLinkObjects;
  57. public event DelinkObjects OnDelinkObjects;
  58. public event RequestMapBlocks OnRequestMapBlocks;
  59. public event RequestMapName OnMapNameRequest;
  60. public event TeleportLocationRequest OnTeleportLocationRequest;
  61. public event DisconnectUser OnDisconnectUser;
  62. public event RequestAvatarProperties OnRequestAvatarProperties;
  63. public event SetAlwaysRun OnSetAlwaysRun;
  64. public event GenericCall4 OnDeRezObject;
  65. public event Action<IClientAPI> OnRegionHandShakeReply;
  66. public event GenericCall2 OnRequestWearables;
  67. public event GenericCall2 OnCompleteMovementToRegion;
  68. public event UpdateAgent OnAgentUpdate;
  69. public event AgentRequestSit OnAgentRequestSit;
  70. public event AgentSit OnAgentSit;
  71. public event AvatarPickerRequest OnAvatarPickerRequest;
  72. public event Action<IClientAPI> OnRequestAvatarsData;
  73. public event AddNewPrim OnAddPrim;
  74. public event RequestGodlikePowers OnRequestGodlikePowers;
  75. public event GodKickUser OnGodKickUser;
  76. public event ObjectDuplicate OnObjectDuplicate;
  77. public event UpdateVector OnGrabObject;
  78. public event ObjectSelect OnDeGrabObject;
  79. public event MoveObject OnGrabUpdate;
  80. public event ViewerEffectEventHandler OnViewerEffect;
  81. public event UpdateShape OnUpdatePrimShape;
  82. public event ObjectExtraParams OnUpdateExtraParams;
  83. public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
  84. public event ObjectSelect OnObjectSelect;
  85. public event GenericCall7 OnObjectDescription;
  86. public event GenericCall7 OnObjectName;
  87. public event UpdatePrimFlags OnUpdatePrimFlags;
  88. public event UpdatePrimTexture OnUpdatePrimTexture;
  89. public event UpdateVector OnUpdatePrimGroupPosition;
  90. public event UpdateVector OnUpdatePrimSinglePosition;
  91. public event UpdatePrimRotation OnUpdatePrimGroupRotation;
  92. public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
  93. public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
  94. public event UpdateVector OnUpdatePrimScale;
  95. public event StatusChange OnChildAgentStatus;
  96. public event GenericCall2 OnStopMovement;
  97. public event Action<LLUUID> OnRemoveAvatar;
  98. public event CreateNewInventoryItem OnCreateNewInventoryItem;
  99. public event CreateInventoryFolder OnCreateNewInventoryFolder;
  100. public event UpdateInventoryFolder OnUpdateInventoryFolder;
  101. public event MoveInventoryFolder OnMoveInventoryFolder;
  102. public event FetchInventoryDescendents OnFetchInventoryDescendents;
  103. public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
  104. public event FetchInventory OnFetchInventory;
  105. public event RequestTaskInventory OnRequestTaskInventory;
  106. public event UpdateInventoryItem OnUpdateInventoryItem;
  107. public event CopyInventoryItem OnCopyInventoryItem;
  108. public event MoveInventoryItem OnMoveInventoryItem;
  109. public event RemoveInventoryItem OnRemoveInventoryItem; // rex
  110. public event UDPAssetUploadRequest OnAssetUploadRequest;
  111. public event XferReceive OnXferReceive;
  112. public event RequestXfer OnRequestXfer;
  113. public event ConfirmXfer OnConfirmXfer;
  114. public event RezScript OnRezScript;
  115. public event UpdateTaskInventory OnUpdateTaskInventory;
  116. public event RemoveTaskInventory OnRemoveTaskItem;
  117. public event RezSingleAttachmentFromInv OnRezSingleAttachmentFromInv;
  118. public event ObjectAttach OnObjectAttach;
  119. public event ObjectDetach OnObjectDetach;
  120. public event UUIDNameRequest OnNameFromUUIDRequest;
  121. public event ParcelPropertiesRequest OnParcelPropertiesRequest;
  122. public event ParcelDivideRequest OnParcelDivideRequest;
  123. public event ParcelJoinRequest OnParcelJoinRequest;
  124. public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
  125. public event ParcelAccessListRequest OnParcelAccessListRequest;
  126. public event ParcelAccessListUpdateRequest OnParcelAccessListUpdateRequest;
  127. public event ParcelSelectObjects OnParcelSelectObjects;
  128. public event ParcelObjectOwnerRequest OnParcelObjectOwnerRequest;
  129. public event ObjectDeselect OnObjectDeselect;
  130. public event EstateOwnerMessageRequest OnEstateOwnerMessage;
  131. public event RegionInfoRequest OnRegionInfoRequest;
  132. public event EstateCovenantRequest OnEstateCovenantRequest;
  133. public event FriendActionDelegate OnApproveFriendRequest;
  134. public event FriendActionDelegate OnDenyFriendRequest;
  135. public event FriendshipTermination OnTerminateFriendship;
  136. public event ReceiveRexClientScriptCmd OnReceiveRexClientScriptCmd; // rex
  137. public event ObjectClickAction OnObjectClickAction; // rex
  138. public event UpdateAssetMediaURL OnUpdateAssetMediaURL; // rex
  139. public event TriggerSound OnTriggerSound;
  140. #pragma warning restore 67
  141. private LLUUID myID = LLUUID.Random();
  142. public MyNpcCharacter(EventManager eventManager)
  143. {
  144. // startPos = new LLVector3(128, (float)(Util.RandomClass.NextDouble()*100), 2);
  145. eventManager.OnFrame += Update;
  146. }
  147. private LLVector3 startPos = new LLVector3(128, 128, 2);
  148. public virtual LLVector3 StartPos
  149. {
  150. get { return startPos; }
  151. set { }
  152. }
  153. public virtual LLUUID AgentId
  154. {
  155. get { return myID; }
  156. }
  157. public LLUUID SessionId
  158. {
  159. get { return LLUUID.Zero; }
  160. }
  161. public LLUUID SecureSessionId
  162. {
  163. get { return LLUUID.Zero; }
  164. }
  165. public virtual string FirstName
  166. {
  167. get { return "Annoying"; }
  168. }
  169. private string lastName = "NPC" + Util.RandomClass.Next(1, 1000);
  170. public virtual string LastName
  171. {
  172. get { return lastName; }
  173. }
  174. public virtual String Name
  175. {
  176. get { return FirstName + LastName; }
  177. }
  178. public virtual void OutPacket(Packet newPack, ThrottleOutPacketType packType)
  179. {
  180. }
  181. public virtual void SendWearables(AvatarWearable[] wearables, int serial)
  182. {
  183. }
  184. public virtual void SendAppearance(LLUUID agentID, byte[] visualParams, byte[] textureEntry)
  185. {
  186. }
  187. public virtual void SendRexAppearance(LLUUID agentID, string avatarAddress) // rex
  188. {
  189. }
  190. public virtual void SendRexScriptCommand(string vUnit, string vCommand, string vCmdParams) // rex
  191. {
  192. }
  193. public virtual void Kick(string message)
  194. {
  195. }
  196. public virtual void SendStartPingCheck(byte seq)
  197. {
  198. }
  199. public virtual void SendAvatarPickerReply(AvatarPickerReplyPacket response)
  200. {
  201. }
  202. public virtual void SendKillObject(ulong regionHandle, uint localID)
  203. {
  204. }
  205. public virtual void SetChildAgentThrottle(byte[] throttle)
  206. {
  207. }
  208. public virtual void SendAnimations(LLUUID[] animations, int[] seqs, LLUUID sourceAgentId)
  209. {
  210. }
  211. public virtual void SendChatMessage(string message, byte type, LLVector3 fromPos, string fromName,
  212. LLUUID fromAgentID)
  213. {
  214. }
  215. public virtual void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName,
  216. LLUUID fromAgentID)
  217. {
  218. }
  219. public virtual void SendInstantMessage(LLUUID fromAgent, LLUUID fromAgentSession, string message, LLUUID toAgent,
  220. LLUUID imSessionID, string fromName, byte dialog, uint timeStamp)
  221. {
  222. }
  223. public virtual void SendLayerData(float[] map)
  224. {
  225. }
  226. public virtual void SendLayerData(int px, int py, float[] map)
  227. {
  228. }
  229. //rex
  230. public virtual void SendMediaURL(LLUUID assetId, string mediaURL)
  231. {
  232. }
  233. public virtual void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look)
  234. {
  235. }
  236. public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint)
  237. {
  238. }
  239. public virtual AgentCircuitData RequestClientInfo()
  240. {
  241. return new AgentCircuitData();
  242. }
  243. public virtual void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt,
  244. IPEndPoint newRegionExternalEndPoint, string capsURL)
  245. {
  246. }
  247. public virtual void SendMapBlock(List<MapBlockData> mapBlocks)
  248. {
  249. }
  250. public virtual void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags)
  251. {
  252. }
  253. public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint,
  254. uint locationID, uint flags, string capsURL)
  255. {
  256. }
  257. public virtual void SendTeleportFailed()
  258. {
  259. }
  260. public virtual void SendTeleportLocationStart()
  261. {
  262. }
  263. public virtual void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance)
  264. {
  265. }
  266. public virtual void SendAvatarData(ulong regionHandle, string firstName, string lastName, LLUUID avatarID,
  267. uint avatarLocalID, LLVector3 Pos, byte[] textureEntry, uint parentID)
  268. {
  269. }
  270. public virtual void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID,
  271. LLVector3 position, LLVector3 velocity, LLQuaternion rotation)
  272. {
  273. }
  274. public virtual void SendCoarseLocationUpdate(List<LLVector3> CoarseLocations)
  275. {
  276. }
  277. public virtual void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint)
  278. {
  279. }
  280. public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID,
  281. PrimitiveBaseShape primShape, LLVector3 pos, uint flags,
  282. LLUUID objectID, LLUUID ownerID, string text, byte[] color,
  283. uint parentID,
  284. byte[] particleSystem, LLQuaternion rotation, byte clickAction)
  285. {
  286. }
  287. public virtual void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID,
  288. LLVector3 position, LLQuaternion rotation)
  289. {
  290. }
  291. public virtual void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID,
  292. LLVector3 position, LLQuaternion rotation, LLVector3 velocity,
  293. LLVector3 rotationalvelocity)
  294. {
  295. }
  296. public virtual void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID,
  297. List<InventoryItemBase> items,
  298. List<InventoryFolderBase> folders,
  299. bool fetchFolders,
  300. bool fetchItems)
  301. {
  302. }
  303. public virtual void SendInventoryItemDetails(LLUUID ownerID, InventoryItemBase item)
  304. {
  305. }
  306. public virtual void SendInventoryItemCreateUpdate(InventoryItemBase Item)
  307. {
  308. }
  309. public virtual void SendRemoveInventoryItem(LLUUID itemID)
  310. {
  311. }
  312. public virtual void SendTaskInventory(LLUUID taskID, short serial, byte[] fileName)
  313. {
  314. }
  315. public virtual void SendXferPacket(ulong xferID, uint packet, byte[] data)
  316. {
  317. }
  318. public virtual void SendNameReply(LLUUID profileId, string firstname, string lastname)
  319. {
  320. }
  321. public virtual void SendPreLoadSound(LLUUID objectID, LLUUID ownerID, LLUUID soundID)
  322. {
  323. }
  324. public virtual void SendPlayAttachedSound(LLUUID soundID, LLUUID objectID, LLUUID ownerID, float gain,
  325. byte flags)
  326. {
  327. }
  328. public void SendTriggeredSound(LLUUID soundID, LLUUID ownerID, LLUUID objectID, LLUUID parentID, ulong handle, LLVector3 position, float gain)
  329. {
  330. }
  331. public void SendAlertMessage(string message)
  332. {
  333. }
  334. public void SendAgentAlertMessage(string message, bool modal)
  335. {
  336. }
  337. public void SendSystemAlertMessage(string message)
  338. {
  339. }
  340. public void SendLoadURL(string objectname, LLUUID objectID, LLUUID ownerID, bool groupOwned, string message,
  341. string url)
  342. {
  343. }
  344. public void SendDialog(string objectname, LLUUID objectID, LLUUID ownerID, string msg, LLUUID textureID, int ch, string[] buttonlabels)
  345. {
  346. }
  347. public virtual void SendRegionHandshake(RegionInfo regionInfo)
  348. {
  349. if (OnRegionHandShakeReply != null)
  350. {
  351. OnRegionHandShakeReply(this);
  352. }
  353. if (OnCompleteMovementToRegion != null)
  354. {
  355. OnCompleteMovementToRegion();
  356. }
  357. }
  358. private void Update()
  359. {
  360. if (OnAgentUpdate != null)
  361. {
  362. AgentUpdatePacket pack = new AgentUpdatePacket();
  363. pack.AgentData.ControlFlags = movementFlag;
  364. pack.AgentData.BodyRotation = bodyDirection;
  365. OnAgentUpdate(this, pack);
  366. }
  367. if (flyState == 0)
  368. {
  369. movementFlag = (uint) AgentManager.ControlFlags.AGENT_CONTROL_FLY |
  370. (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG;
  371. flyState = 1;
  372. }
  373. else if (flyState == 1)
  374. {
  375. movementFlag = (uint) AgentManager.ControlFlags.AGENT_CONTROL_FLY |
  376. (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS;
  377. flyState = 2;
  378. }
  379. else
  380. {
  381. movementFlag = (uint) AgentManager.ControlFlags.AGENT_CONTROL_FLY;
  382. flyState = 0;
  383. }
  384. if (count >= 200)
  385. {
  386. if (OnChatFromViewer != null)
  387. {
  388. ChatFromViewerArgs args = new ChatFromViewerArgs();
  389. args.Message = "Kinda quiet around here, isn't it?";
  390. args.Channel = 0;
  391. args.From = FirstName + " " + LastName;
  392. args.Position = new LLVector3(128, 128, 26);
  393. args.Sender = this;
  394. args.Type = ChatTypeEnum.Shout;
  395. OnChatFromViewer(this, args);
  396. }
  397. count = -1;
  398. }
  399. count++;
  400. }
  401. public bool AddMoney(int debit)
  402. {
  403. return false;
  404. }
  405. public void SendSunPos(LLVector3 sunPos, LLVector3 sunVel)
  406. {
  407. }
  408. public void SendViewerTime(int phase)
  409. {
  410. }
  411. public void SendAvatarProperties(LLUUID avatarID, string aboutText, string bornOn, string charterMember,
  412. string flAbout, uint flags, LLUUID flImageID, LLUUID imageID, string profileURL,
  413. LLUUID partnerID)
  414. {
  415. }
  416. public void SetDebug(int newDebug)
  417. {
  418. }
  419. public void InPacket(Packet NewPack)
  420. {
  421. }
  422. public void Close(bool ShutdownCircuit)
  423. {
  424. }
  425. public void Stop()
  426. {
  427. }
  428. private uint m_circuitCode;
  429. public uint CircuitCode
  430. {
  431. get { return m_circuitCode; }
  432. set { m_circuitCode = value; }
  433. }
  434. public void SendBlueBoxMessage(LLUUID FromAvatarID, LLUUID fromSessionID, String FromAvatarName, String Message)
  435. {
  436. }
  437. public void SendLogoutPacket()
  438. {
  439. }
  440. public void SendScriptTeleportRequest(string objectName, string simName, LLVector3 simPosition, LLVector3 lookAt) { }
  441. }
  442. }