/// <summary> /// Spawns an item. /// </summary> /// <param name = "item"> /// The mmo item. /// </param> /// <param name = "operation"> /// The operation. /// </param> /// <param name = "interestArea"> /// The interest Area. /// </param> /// <returns> /// error code ok /// </returns> private OperationResponse ItemOperationSpawn(MmoItem item, SpawnItem operation, InterestArea interestArea) { // this should always return Ok MethodReturnValue result = this.CheckAccess(item); if (result) { item.Rotation = operation.Rotation; item.Spawn(operation.Position); ((MmoWorld)this.World).Radar.AddItem(item, operation.Position); if (interestArea != null) { lock (interestArea.SyncRoot) { interestArea.SubscribeItem(item); } } } operation.OnComplete(); return operation.GetOperationResponse(result); }
/// <summary> /// Handles operation <see cref = "SpawnItem" />: Creates a new <see cref = "Item" /> and optionally subscribes an <see cref = "InterestArea" /> to it. /// </summary> /// <param name = "peer"> /// The client peer. /// </param> /// <param name = "request"> /// The request. /// </param> /// <returns> /// An <see cref = "OperationResponse" /> with error code <see cref = "ReturnCode.Ok" />, <see cref = "ReturnCode.ItemAlreadyExists" /> or <see cref = "ReturnCode.InterestAreaNotFound" />. /// </returns> public OperationResponse OperationSpawnItem(PeerBase peer, OperationRequest request) { var operation = new SpawnItem(peer.Protocol, request); if (!operation.IsValid) { return new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() }; } operation.OnStart(); InterestArea interestArea; if (operation.InterestAreaId.HasValue) { if (this.TryGetInterestArea(operation.InterestAreaId.Value, out interestArea) == false) { return operation.GetOperationResponse((int)ReturnCode.InterestAreaNotFound, "InterestAreaNotFound"); } } else { interestArea = null; } IWorld world = this.World; var item = new MmoItem(world, operation.Position, operation.Rotation, operation.Properties, this, operation.ItemId, operation.ItemType); if (world.ItemCache.AddItem(item)) { this.AddItem(item); return this.ItemOperationSpawn(item, operation, interestArea); } item.Dispose(); return operation.GetOperationResponse((int)ReturnCode.ItemAlreadyExists, "ItemAlreadyExists"); }