Esempio n. 1
0
        public void UseCashItem(Packet iPacket)
        {
            short slot     = iPacket.ReadShort();
            int   itemID   = iPacket.ReadInt();
            bool  itemUsed = false;

            Item item = this[ItemType.Cash, slot];

            if (item == null || itemID != item.MapleID)
            {
                return;
            }

            switch (item.MapleID)
            {
                #region TeleportRocks
            case (int)UsableCashItems.TeleportRock:
            {
            }
            break;

            case (int)UsableCashItems.CokeTeleportRock:
            {
            }
            break;

            case (int)UsableCashItems.VIPTeleportRock:
            {
                itemUsed = this.Parent.Trocks.Use(itemID, iPacket);
            }
            break;
                #endregion

                #region AP/SP Reset
            case (int)UsableCashItems.APReset:
            {
                StatisticType statDestination = (StatisticType)iPacket.ReadInt();
                StatisticType statSource      = (StatisticType)iPacket.ReadInt();

                CharacterStats.AddAbility(this.Parent, statDestination, 1, true);
                CharacterStats.AddAbility(this.Parent, statSource, -1, true);

                itemUsed = true;
            }
            break;

            case (int)UsableCashItems.SPReset1stJob:
            {
                if (!IsFirstJob(this.Parent.Job))
                {
                    return;
                }
                //TODO: skill change
                itemUsed = true;
            }
            break;

            case (int)UsableCashItems.SPReset2stJob:
            {
                if (!IsSecondJob(this.Parent.Job))
                {
                    return;
                }
                //TODO: skill change
                itemUsed = true;
            }
            break;

            case (int)UsableCashItems.SPReset3stJob:
            {
                if (!IsThirdJob(this.Parent.Job))
                {
                    return;
                }
                //TODO: skill change
                itemUsed = true;
            }
            break;

            case (int)UsableCashItems.SPReset4stJob:
            {
                if (!IsFourthJob(this.Parent.Job))
                {
                    return;
                }
                //TODO: skill change
                itemUsed = true;
            }
            break;
                #endregion

                #region ItemTags/ItemGuards
            case (int)UsableCashItems.ItemTag:
            {
                short targetSlot = iPacket.ReadShort();
                if (targetSlot == 0)
                {
                    return;
                }

                Item targetItem = this[ItemType.Equipment, targetSlot];
                if (targetItem == null)
                {
                    return;
                }

                targetItem.Creator = this.Parent.Name;
                targetItem.Update();     // TODO: This does not seem to update the item's creator.

                itemUsed = true;
            }
            break;

            case (int)UsableCashItems.ItemGuard:
            {
            }
            break;

            case (int)UsableCashItems.Incubator:     //doest belong here by name only by ordering of usableCashItemsID
            {
            }
            break;

            case (int)UsableCashItems.ItemGuard7Days:
            {
            }
            break;

            case (int)UsableCashItems.ItemGuard30Days:
            {
            }
            break;

            case (int)UsableCashItems.ItemGuard90Days:
            {
            }
            break;
                #endregion

                #region Megaphones/Messengers
            case (int)UsableCashItems.CheapMegaphone:
            {
                // NOTE: You can't use a megaphone unless you're over level 10.
                if (this.Parent.Level < 11)
                {
                    return;
                }

                string text    = iPacket.ReadString();
                string message = string.Format($"{this.Parent.Name} : {text}");         // TODO: Include medal name.

                // NOTE: In GMS, this sends to everyone on the current channel, not the map (despite the item's description).
                using (Packet oPacket = new Packet(ServerOperationCode.BroadcastMsg))
                {
                    oPacket
                    .WriteByte((byte)NoticeType.Megaphone)
                    .WriteString(message);

                    //this.Parent.Client.Channel.Broadcast(oPacket);
                }

                itemUsed = true;
            }
            break;

            case (int)UsableCashItems.Megaphone:
            {
                if (this.Parent.Level < 11)
                {
                    return;
                }

                string text    = iPacket.ReadString();
                string message = string.Format($"{this.Parent.Name} : {text}");         // TODO: Include medal name.

                // NOTE: In GMS, this sends to everyone on the current channel, not the map (despite the item's description).
                using (Packet oPacket = new Packet(ServerOperationCode.BroadcastMsg))
                {
                    oPacket
                    .WriteByte((byte)NoticeType.Megaphone)
                    .WriteString(message);

                    //this.Parent.Client.Channel.Broadcast(oPacket);
                }

                itemUsed = true;
            }
            break;

            case (int)UsableCashItems.SuperMegaphone:
            {
                if (this.Parent.Level < 11)
                {
                    return;
                }

                string text    = iPacket.ReadString();
                bool   whisper = iPacket.ReadBool();

                string message = string.Format($"{this.Parent.Name} : {text}");         // TODO: Include medal name.

                using (Packet oPacket = new Packet(ServerOperationCode.BroadcastMsg))
                {
                    oPacket
                    .WriteByte((byte)NoticeType.SuperMegaphone)
                    .WriteString(message)
                    .WriteByte(WvsGame.ChannelID)
                    .WriteBool(whisper);

                    //this.Parent.Client.World.Broadcast(oPacket);
                }

                itemUsed = true;
            }
            break;

            case (int)UsableCashItems.HeartMegaphone:
            {
                if (this.Parent.Level < 11)
                {
                    return;
                }
            }
            break;

            case (int)UsableCashItems.SkullMegaphone:
            {
                if (this.Parent.Level < 11)
                {
                    return;
                }
            }
            break;

            case (int)UsableCashItems.MapleTVMessenger:
            {
                if (this.Parent.Level < 11)
                {
                    return;
                }
            }
            break;

            case (int)UsableCashItems.MapleTVStarMessenger:
            {
                if (this.Parent.Level < 11)
                {
                    return;
                }
            }
            break;

            case (int)UsableCashItems.MapleTVHeartMessenger:
            {
                if (this.Parent.Level < 11)
                {
                    return;
                }
            }
            break;

            case (int)UsableCashItems.Megassenger:
            {
                if (this.Parent.Level < 11)
                {
                    return;
                }
            }
            break;

            case (int)UsableCashItems.StarMegassenger:
            {
                if (this.Parent.Level < 11)
                {
                    return;
                }
            }
            break;

            case (int)UsableCashItems.HeartMegassenger:
            {
                if (this.Parent.Level < 11)
                {
                    return;
                }
            }
            break;

            case (int)UsableCashItems.ItemMegaphone:     // NOTE: Item Megaphone.
            {
                if (this.Parent.Level < 11)
                {
                    return;
                }

                string text        = iPacket.ReadString();
                bool   whisper     = iPacket.ReadBool();
                bool   includeItem = iPacket.ReadBool();

                Item targetItem = null;

                if (includeItem)
                {
                    ItemType type       = (ItemType)iPacket.ReadInt();
                    short    targetSlot = iPacket.ReadShort();

                    targetItem = this[type, targetSlot];

                    if (targetItem == null)
                    {
                        return;
                    }
                }

                string message = string.Format($"{this.Parent.Name} : {text}");         // TODO: Include medal name.

                using (Packet oPacket = new Packet(ServerOperationCode.BroadcastMsg))
                {
                    oPacket
                    .WriteByte((byte)NoticeType.ItemMegaphone)
                    .WriteString(message)
                    .WriteByte(WvsGame.ChannelID)
                    .WriteBool(whisper)
                    .WriteByte((byte)(targetItem != null ? targetItem.Slot : 0));

                    if (targetItem != null)
                    {
                        oPacket.WriteBytes(targetItem.ToByteArray(true));
                    }

                    //this.Parent.Client.World.Broadcast(oPacket);
                }

                itemUsed = true;
            }
            break;
                #endregion

                #region FloatingMessage
            case (int)UsableCashItems.KoreanKite:
            {
            }
            break;

            case (int)UsableCashItems.HeartBalloon:
            {
            }
            break;

            case (int)UsableCashItems.GraduationBanner:
            {
            }
            break;

            case (int)UsableCashItems.AdmissionBanner:
            {
            }
            break;
                #endregion

                #region otherStuff
            case (int)UsableCashItems.Note:     // NOTE: Memo.
            {
                //string targetName = iPacket.ReadString();
                //string message = iPacket.ReadString();

                //if (this.Parent.Client.World.IsCharacterOnline(targetName))
                //{
                //    using (Packet oPacket = new Packet(ServerOperationCode.MemoResult))
                //    {
                //        oPacket
                //            .WriteByte((byte)MemoResult.Error)
                //            .WriteByte((byte)MemoError.ReceiverOnline);

                //        this.Parent.Client.Send(oPacket);
                //    }
                //}
                //else if (!Database.Exists("characters", "Name = {0}", targetName))
                //{
                //    using (Packet oPacket = new Packet(ServerOperationCode.MemoResult))
                //    {
                //        oPacket
                //            .WriteByte((byte)MemoResult.Error)
                //            .WriteByte((byte)MemoError.ReceiverInvalidName);

                //        this.Parent.Client.Send(oPacket);
                //    }
                //}
                //else if (false) // TODO: Receiver's inbox is full. I believe the maximum amount is 5, but need to verify.
                //{
                //    using (Packet oPacket = new Packet(ServerOperationCode.MemoResult))
                //    {
                //        oPacket
                //            .WriteByte((byte)MemoResult.Error)
                //            .WriteByte((byte)MemoError.ReceiverInboxFull);

                //        this.Parent.Client.Send(oPacket);
                //    }
                //}
                //else
                //{
                //    Datum datum = new Datum("memos");

                //    datum["CharacterID"] = Database.Fetch("characters", "ID", "Name = {0}", targetName);
                //    datum["Sender"] = this.Parent.Name;
                //    datum["Message"] = message;
                //    datum["Received"] = DateTime.Now;

                //    datum.Insert();

                //    using (Packet oPacket = new Packet(ServerOperationCode.MemoResult))
                //    {
                //        oPacket.WriteByte((byte)MemoResult.Sent);

                //        this.Parent.Client.Send(oPacket);
                //    }

                //    used = true;
                //}
            }
            break;

            case (int)UsableCashItems.CongratulatorySong:
            {
            }
            break;

            case (int)UsableCashItems.PetNameTag:
            {
                //// TODO: Get the summoned pet.

                //string name = iPacket.ReadString();

                //using (Packet oPacket = new Packet(ServerOperationCode.PetNameChanged))
                //{
                //    oPacket
                //        .WriteInt(this.Parent.ID)
                //        .WriteByte() // NOTE: Index.
                //        .WriteString(name)
                //        .WriteByte();

                //    this.Parent.Map.Broadcast(oPacket);
                //}
            }
            break;

            case (int)UsableCashItems.BronzeSackofMesos:
            {
            }
            break;

            case (int)UsableCashItems.SilverSackofMesos:
            {
            }
            break;

            case (int)UsableCashItems.GoldSackofMesos:
            {
                this.Parent.Meso += item.Meso;

                // TODO: We definitely need a GainMeso method with inChat parameter.
                using (Packet oPacket = new Packet(ServerOperationCode.Message))
                {
                    oPacket
                    .WriteByte((byte)MessageType.IncreaseMeso)
                    .WriteInt(item.Meso)
                    .WriteShort();

                    this.Parent.Client.Send(oPacket);
                }

                itemUsed = true;
            }
            break;

            case (int)UsableCashItems.FungusScroll:
            {
            }
            break;

            case (int)UsableCashItems.OinkerDelight:
            {
            }
            break;

            case (int)UsableCashItems.ZetaNightmare:
            {
            }
            break;

            case (int)UsableCashItems.ChalkBoard:
            {
            }
            break;

            case (int)UsableCashItems.ChalkBoard2:
            {
                string text = iPacket.ReadString();
                this.Parent.Chalkboard = text;
            }
            break;

            case (int)UsableCashItems.ScissorsofKarma:
            {
            }
            break;

            case (int)UsableCashItems.ViciousHammer:
            {
            }
            break;
                #endregion
            }

            if (itemUsed)
            {
                this.Remove(itemID, 1);
            }
            else
            {
                Character.Release(this.Parent);  // TODO: Blank inventory update.
            }
        }