/// <summary> /// Handles operation SpawnItem: Creates a new Item and optionally subscribes an InterestArea to it. /// </summary> 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(); var item = new Item(operation.Position, operation.Rotation, operation.Properties, this, operation.ItemId, operation.ItemType, this.World); if (this.World.ItemCache.AddItem(item)) { this.AddItem(item); return this.ItemOperationSpawn(item, operation); } item.Dispose(); return operation.GetOperationResponse((int)ReturnCode.ItemAlreadyExists, "ItemAlreadyExists"); }
/// <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"); }