Exemple #1
0
        private static void CreateNewItem(MmoActor player)
        {
            var oldItem = player.nebulaObject as MmoItem;

            var interestArea = new MmoClientInterestArea(player.Peer, 0, player.World)
            {
                ViewDistanceEnter = new GameMath.Vector {
                    X = 50000, Y = 50000, Z = 50000
                },
                ViewDistanceExit = new GameMath.Vector {
                    X = 100000, Y = 100000, Z = 100000
                }
            };

            var newITem = new MmoItem(player.Peer,
                                      interestArea,
                                      player.World,
                                      player.application,
                                      player.transform.position.ToArray(),
                                      player.transform.rotation.ToArray(),
                                      new System.Collections.Hashtable(),
                                      player.nebulaObject.Id,
                                      player.nebulaObject.tags,
                                      player.nebulaObject.size,
                                      player.nebulaObject.subZone,
                                      oldItem.allBehaviours);

            log.InfoFormat("why why why green");

            player.GetComponent <DamagableObject>().SetIgnoreDamageAtStart(true);
            player.GetComponent <DamagableObject>().SetIgnoreDamageInterval(30);
            oldItem.Dispose();
        }
        private void ExitWorkshop(MmoActor actor)
        {
            if (actor.WorkshopSavedInfo != null)
            {
                if (actor.WorkshopSavedInfo.NowInWorkshop)
                {
                    var interestArea = new MmoClientInterestArea(actor.Peer, 0, actor.World)
                    {
                        ViewDistanceEnter = actor.WorkshopSavedInfo.ViewDistanceEnter.ToVector(true),
                        ViewDistanceExit  = actor.WorkshopSavedInfo.ViewDistanceExit.ToVector(true)
                    };
                    actor.AddInterestArea(interestArea);

                    if (actor.Avatar != null)
                    {
                        while (!(actor.Avatar.world as MmoWorld).ItemCache.AddItem(actor.Avatar))
                        {
                            log.Info("error of adding avatar to world");
                        }
                        log.Info("item to world added");
                    }
                    else
                    {
                        log.Error("exit workshop actor avatar is null");
                    }

                    //var avatar = new MmoItem(actor.World, actor.WorkshopSavedInfo.Position, actor.WorkshopSavedInfo.Rotation, actor.WorkshopSavedInfo.Properties,
                    //    actor, actor.WorkshopSavedInfo.ItemId, (byte)ItemType.Avatar);

                    //while (actor.World.ItemCache.AddItem(avatar) == false) {
                    //    //ConsoleLogging.Get.Print(LogFilter.ALL, "error of adding new item");
                    //}
                    //actor.AddItem(avatar);
                    //actor.SetAvatar(avatar);

                    //if (actor.Avatar != null) {
                    //    actor.GetComponent<PlayerLoaderObject>().Save(true);
                    //}

                    var workshopExited = new WorkshopExited {
                        ItemId = actor.nebulaObject.Id, Position = actor.WorkshopSavedInfo.Position
                    };
                    var eventData = new EventData((byte)EventCode.WorkshopExited, workshopExited);
                    actor.Peer.SendEvent(eventData, new SendParameters {
                        ChannelId = Settings.ItemEventChannel
                    });

                    (actor.nebulaObject as MmoItem).Spawn(actor.WorkshopSavedInfo.Position);

                    actor.SetWorkshopStatus(false);
                    actor.SetNewSubZone((actor.World as MmoWorld).ResolvePositionSubzone(actor.WorkshopSavedInfo.Position.ToVector3()));
                    actor.nebulaObject.SetInvisibility(false);
                    actor.GetComponent <PetManager>().Reinitialize();
                    actor.nebulaObject.SendMessage(ComponentMessages.OnStationExited);
                }
                else
                {
                    //ConsoleLogging.Get.Print(LogFilter.ALL, "EXIT WORKSHOP: NOW IN NOT WORKSHOP");
                }
            }
            else
            {
                //ConsoleLogging.Get.Print(LogFilter.ALL, "EXIT: WORKSHOP SAVE INFO NULL");
            }
        }
        /// <summary>
        ///   Handles operation <see cref = "AddInterestArea" />: Creates a new <see cref = "InterestArea" /> and optionally attaches it to an existing <see cref = "Item" />.
        /// </summary>
        /// <param name = "peer">
        ///   The client peer.
        /// </param>
        /// <param name = "request">
        ///   The request.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        /// <returns>
        ///   An <see cref = "OperationResponse" /> with error code <see cref = "ReturnCode.Ok" /> or <see cref = "ReturnCode.InterestAreaAlreadyExists" />.
        ///   If the <see cref = "InterestArea" /> is supposed to be attached to an <see cref = "Item" /> error code <see cref = "ReturnCode.ItemNotFound" /> could be returned.
        /// </returns>
        /// <remarks>
        ///   The <see cref = "InterestArea" /> is created even if error code <see cref = "ReturnCode.ItemNotFound" /> is returned.
        /// </remarks>
        public override OperationResponse Handle(MmoActor actor, OperationRequest request, SendParameters sendParameters)
        {
            var operation = new AddInterestArea(actor.Peer.Protocol, request);

            if (!operation.IsValid)
            {
                return(new OperationResponse(request.OperationCode)
                {
                    ReturnCode = (int)ReturnCode.InvalidOperationParameter,
                    DebugMessage = operation.GetErrorMessage()
                });
            }

            operation.OnStart();
            InterestArea interestArea;

            if (actor.TryGetInterestArea(operation.InterestAreaId, out interestArea))
            {
                return(operation.GetOperationResponse((int)ReturnCode.InterestAreaAlreadyExists, "InterestAreaAlreadyExists"));
            }

            interestArea = new MmoClientInterestArea(actor.Peer, operation.InterestAreaId, actor.World);
            actor.AddInterestArea(interestArea);

            // attach interestArea to item
            Item item;

            if (operation.ItemType.HasValue && string.IsNullOrEmpty(operation.ItemId) == false)
            {
                IWorld world = actor.World;

                bool actorItem = actor.TryGetItem(operation.ItemType.Value, operation.ItemId, out item);
                if (actorItem == false)
                {
                    if (world.ItemCache.TryGetItem(operation.ItemType.Value, operation.ItemId, out item) == false)
                    {
                        return(operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound"));
                    }
                }

                if (actorItem)
                {
                    // we are already in the item thread, invoke directly
                    return(ItemOperationAddInterestArea(item, operation, interestArea));
                }

                // second parameter (peer) allows us to send an error event to the client (in case of an error)
                item.Fiber.Enqueue(() => actor.ExecItemOperation(() => ItemOperationAddInterestArea(item, operation, interestArea), sendParameters));

                // send response later
                return(null);
            }

            // free floating interestArea
            if (operation.Position != null)
            {
                lock (interestArea.SyncRoot) {
                    interestArea.Position          = operation.Position.ToVector(true);
                    interestArea.ViewDistanceEnter = operation.ViewDistanceEnter.ToVector(true);
                    interestArea.ViewDistanceExit  = operation.ViewDistanceExit.ToVector(true);
                    interestArea.UpdateInterestManagement();
                }
            }

            return(operation.GetOperationResponse(MethodReturnValue.Ok));
        }