public object Deserialize(
            StreamReader streamReader,
            SerializationContext serializationContext,
            PropertyMetaData propertyMetaData = null)
        {
            var mess = new GenericCmdMessage();
            mess.N3MessageType = (N3MessageType)streamReader.ReadInt32();
            mess.Identity = streamReader.ReadIdentity();
            mess.Unknown = streamReader.ReadByte();
            mess.Temp1 = streamReader.ReadInt32();
            mess.Count = streamReader.ReadInt32();
            mess.Action = (GenericCmdAction)streamReader.ReadInt32();
            mess.Temp4 = streamReader.ReadInt32();
            mess.User = streamReader.ReadIdentity();
            int len = 1;
            if (mess.Action == GenericCmdAction.UseItemOnItem)
            {
                len = 2;
            }

            mess.Target = new Identity[len];
            for (int i = 0; i < mess.Target.Length; i++)
            {
                mess.Target[i] = streamReader.ReadIdentity();
            }
            return mess;
        }
예제 #2
0
        /// <summary>
        /// </summary>
        /// <param name="message">
        /// </param>
        /// <param name="client">
        /// </param>
        /// <exception cref="NullReferenceException">
        /// </exception>
        public static void Read(GenericCmdMessage message, ZoneClient client)
        {
            switch (message.Action)
            {
                case GenericCmdAction.Get:
                    break;
                case GenericCmdAction.Drop:
                    break;
                case GenericCmdAction.Use:
                    if (message.Target.Type == IdentityType.Inventory)
                    {
                        Item item = null;
                        try
                        {
                            item = client.Character.BaseInventory.GetItemInContainer(
                                (int)message.Target.Type,
                                message.Target.Instance);
                        }
                        catch (Exception)
                        {
                        }

                        if (item == null)
                        {
                            throw new NullReferenceException(
                                "No item found at " + message.Target.Type + "/" + message.Target.Instance);
                        }

                        TemplateAction.Send(client, item, (int)message.Target.Type, message.Target.Instance);

                        if (ItemLoader.ItemList[item.HighID].IsConsumable())
                        {
                            item.MultipleCount--;
                            if (item.MultipleCount == 0)
                            {
                                client.Character.BaseInventory.RemoveItem(
                                    (int)message.Target.Type,
                                    message.Target.Instance);

                                DeleteItem.Send(client, (int)message.Target.Type, message.Target.Instance);
                            }
                        }

                        item.PerformAction(client.Character, EventType.OnUse, message.Target.Instance);
                        Reply(message, client);
                    }
                    else
                    {
                        string s = "Generic Command received:\r\nAction: " + message.Action.ToString() + "("
                                   + ((int)message.Action).ToString() + ")\r\nTarget: " + message.Target.Type + " "
                                   + ((int)message.Target.Type).ToString("X8") + ":"
                                   + message.Target.Instance.ToString("X8");
                        if (PlayfieldLoader.PFData.ContainsKey(client.Character.Playfield.Identity.Instance))
                        {
                            StatelData sd =
                                PlayfieldLoader.PFData[client.Playfield.Identity.Instance].Statels.FirstOrDefault(
                                    x =>
                                        (x.StatelIdentity.Type == message.Target.Type)
                                        && (x.StatelIdentity.Instance == message.Target.Instance));

                            if (sd != null)
                            {
                                s = s + "\r\nFound Statel with " + sd.Events.Count + " events";
                                Events onUse = sd.Events.FirstOrDefault(x => x.EventType == (int)EventType.OnUse);
                                if (onUse != null)
                                {
                                    onUse.Perform(client.Character, client.Character);
                                }
                            }
                        }

                        client.Character.Send(new ChatTextMessage() { Identity = client.Character.Identity, Text = s });
                    }

                    break;
            }
        }
예제 #3
0
 /// <summary>
 /// </summary>
 /// <param name="message">
 /// </param>
 /// <param name="client">
 /// </param>
 private static void Reply(GenericCmdMessage message, ZoneClient client)
 {
     // Acknowledge action
     message.Identity = client.Character.Identity;
     message.Temp1 = 1;
     message.Unknown = 0;
     client.SendCompressed(message);
 }