Beispiel #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();
        }
        public OperationResponse ItemOperationExecAction(MmoItem item, ExecAction operation, MmoActor actor)
        {
            if (item.Owner == null)
            {
                return new OperationResponse((byte)OperationCode.ExecAction)
                       {
                           ReturnCode = (int)ReturnCode.Fatal, DebugMessage = "Item owner is null in ExecAction"
                       }
            }
            ;
            object[] parameters = operation.Parameters;
            if (operation.Action == "CreateRaider" || operation.Action == "DestroyAnyRaider")
            {
                ArrayList arrLst = new ArrayList(parameters);

                arrLst.Insert(0, actor.World);
                parameters = arrLst.ToArray();
            }
            var       method = item.Owner.ActionExecutor.GetType().GetMethod(operation.Action);
            Hashtable result = null;

            if (method != null)
            {
                object respObject = method.Invoke(item.Owner.ActionExecutor, parameters);
                if (respObject != null && respObject is Hashtable)
                {
                    result = respObject as Hashtable;
                }
            }
            else
            {
                return(new OperationResponse((byte)OperationCode.ExecAction, new ExecActionResponse {
                    Action = operation.Action, ItemId = string.Empty, Result = new Hashtable()
                })
                {
                    ReturnCode = (short)ReturnCode.Fatal,
                    DebugMessage = string.Format("Method: {0} not founded in ExecAction", operation.Action)
                });
            }
            operation.OnComplete();
            if (result == null)
            {
                result = new Hashtable();
            }
            ExecActionResponse response = new ExecActionResponse {
                Result = result, Action = operation.Action, ItemId = item.Id
            };

            return(new OperationResponse((byte)OperationCode.ExecAction, response)
            {
                ReturnCode = (int)ReturnCode.Ok,
                DebugMessage = string.Format("action: {0} completed", operation.Action)
            });
        }
    }
Beispiel #3
0
        public OperationResponse OperationEnterWorld(PeerBase peer, OperationRequest request, SendParameters sendParameters)
        {
            var operation = new EnterWorld(peer.Protocol, request);
            if (!operation.IsValid)
            {
                return new OperationResponse(request.OperationCode) { ReturnCode = (int)ErrorCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() };
            }

            MmoWorld world = MmoWorld.Instance;

            var actor = new MmoActor(peer, world, interestArea);
            var avatar = new MmoItem(world, operation.Position, operation.Rotation, operation.Properties, actor, operation.Username, (byte)ItemType.Avatar);

            while (world.ItemCache.AddItem(avatar) == false)
            {
                Item otherAvatarItem;
                if (world.ItemCache.TryGetItem(avatar.Type, avatar.Id, out otherAvatarItem))
                {
                    avatar.Dispose();
                    actor.Dispose();
                    interestArea.Dispose();

                    ((Peer)((MmoItem)otherAvatarItem).Owner.Peer).DisconnectByOtherPeer(this, request, sendParameters);

                    // request continued later, no response here
                    return null;
                }
            }

            // init avatar
            actor.AddItem(avatar);
            actor.Avatar = avatar;

            ((Peer)peer).SetCurrentOperationHandler(actor);

            // set return values
            var responseObject = new EnterWorldResponse
            {
            };

            // send response; use item channel to ensure that this event arrives before any move or subscribe events
            var response = new OperationResponse(request.OperationCode, responseObject);
            sendParameters.ChannelId = Settings.ItemEventChannel;
            peer.SendOperationResponse(response, sendParameters);

            avatar.Spawn(operation.Position);

            // response already sent
            return null;
        }
        private OperationResponse ItemOperationMove(MmoItem item, Move operation, SendParameters sendParameters, MmoActor actor) {
            // should always be OK
            MethodReturnValue result = this.CheckAccess(item, actor);

            if (result) {
                // save previous for event
                float[] oldPosition = item.transform.position.ToArray();
                float[] oldRotation = item.transform.rotation.ToArray();

                // move
                item.transform.SetRotation(operation.Rotation);
                item.Move(operation.Position);

                float speed = 0f;
                var ship = item.GetComponent<PlayerShip>();
                var movalble = item.GetComponent<MovableObject>();
                if(ship) {
                    speed = movalble.speed;
                }

                // send event
                var eventInstance = new ItemMoved {
                    ItemId = item.Id,
                    ItemType = item.Type,
                    OldPosition = oldPosition,
                    Position = operation.Position,
                    Rotation = operation.Rotation,
                    OldRotation = oldRotation,
                    Speed = speed
                };

                var eventData = new EventData((byte)EventCode.ItemMoved, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                //I ADDED toMOVE AT POSITION
                //item.ReceiveEvent(eventData, sendParameters);

                // no response sent
                operation.OnComplete();
                return null;
            }

            return operation.GetOperationResponse(result);
        }
        private OperationResponse ItemOperationSpawn(MmoItem item, SpawnItem operation, InterestArea interestArea, MmoActor actor)
        {
            // this should always return Ok
            //MethodReturnValue result = this.CheckAccess(item, actor);

            //if (result) {
            //    item.Rotation = operation.Rotation;
            //    item.Spawn(operation.Position);

            //    if (interestArea != null) {
            //        lock (interestArea.SyncRoot) {
            //            interestArea.SubscribeItem(item);
            //        }
            //    }
            //}

            //operation.OnComplete();
            //return operation.GetOperationResponse(result);
            return(operation.GetOperationResponse(MethodReturnValue.Ok));
        }
        public override OperationResponse Handle(MmoActor actor, OperationRequest request, SendParameters sendParameters)
        {
            var operation = new ExecAction(actor.Peer.Protocol, request);

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

            operation.OnStart();
            //CL.Out("exec action called: " + operation.Action);

            Item item;
            bool actorItem = actor.TryGetItem((byte)ItemType.Avatar, operation.ItemId, out item);

            if (actorItem == false)
            {
                if (actor.World.ItemCache.TryGetItem((byte)ItemType.Avatar, operation.ItemId, out item) == false)
                {
                    //return new OperationResponse((byte)OperationCode.ExecAction) { ReturnCode = (short)ReturnCode.ItemNotFound, DebugMessage = "ItemNotFound" };
                    Hashtable methodResult = null;
                    var       method       = actor.ActionExecutor.GetType().GetMethod(operation.Action);

                    if (method != null)
                    {
                        object respObject = method.Invoke(actor.ActionExecutor, operation.Parameters);
                        if (respObject != null && respObject is Hashtable)
                        {
                            methodResult = respObject as Hashtable;
                            ExecActionResponse response = new ExecActionResponse {
                                Result = methodResult, Action = operation.Action, ItemId = string.Empty
                            };
                            return(new OperationResponse(OperationCode.ExecAction.toByte(), response)
                            {
                                ReturnCode = (int)ReturnCode.Ok,
                                DebugMessage = string.Format("Action completed when no avatar")
                            });
                        }
                    }
                    return(new OperationResponse(OperationCode.ExecAction.toByte(), new ExecActionResponse {
                        Result = new Hashtable(),
                        Action = operation.Action, ItemId = string.Empty
                    })
                    {
                        ReturnCode = (int)ReturnCode.Fatal,
                        DebugMessage = "Method not found",
                    });
                }
            }
            if (actorItem)
            {
                if (item is MmoItem)
                {
                    return(this.ItemOperationExecAction(item as MmoItem, operation, actor));
                }
                else
                {
                    return(new OperationResponse((byte)OperationCode.ExecAction, new ExecActionResponse {
                        Result = new Hashtable(), Action = operation.Action, ItemId = string.Empty
                    })
                    {
                        ReturnCode = (short)ReturnCode.Fatal,
                        DebugMessage = "Actor item Item not MmoItem"
                    });
                }
            }

            if (item is MmoItem)
            {
                MmoItem mmoItem = item as MmoItem;
                item.Fiber.Enqueue(() => actor.ExecItemOperation(() => this.ItemOperationExecAction(mmoItem, operation, actor), sendParameters));
                return(null);
            }
            else
            {
                return(new OperationResponse((byte)OperationCode.ExecAction, new ExecActionResponse {
                    Action = operation.Action, ItemId = string.Empty, Result = new Hashtable()
                })
                {
                    ReturnCode = (short)ReturnCode.Fatal,
                    DebugMessage = "Foreign Actor item Item not MmoItem"
                });
            }
        }