Esempio n. 1
0
    public List <ItemEntry> GetItems(EnemyType type, bool isHero, int level)
    {
        string xpath = "";

        if (!isHero)
        {
            xpath = "/enemy/normal/level[" + level + "]";
        }
        else
        {
            xpath = "/enemy/hero/" + type.ToString();
        }

        XmlElement node = (XmlElement)xmlDoc.SelectSingleNode(xpath);

        if (node == null)
        {
            Debug.Log("On EnemyLootReader: " + type.ToString() + " not found");
            return(null);
        }
        XmlNodeList      itemnodes = node.SelectNodes("item");
        List <ItemEntry> items     = new List <ItemEntry>();

        for (int i = 0; i < itemnodes.Count; i++)
        {
            ItemEntry  itemEntry = new ItemEntry();
            XmlElement itemnode  = (XmlElement)itemnodes[i];
            itemEntry.primaryType = GameEventHelper.getItemPrimaryTypeFromString(itemnode["type"].InnerXml);
            itemEntry.itemType    = GameEventHelper.getItemTypeFromString(itemEntry.primaryType, itemnode["typeEnum"].InnerXml);
            itemEntry.number      = int.Parse(itemnode["number"].InnerXml);
            itemEntry.posibility  = int.Parse(itemnode["posibility"].InnerXml);
            items.Add(itemEntry);
        }
        return(items);
    }
    public Item GetItemData(ItemType itemType)
    {
        Item   item  = new Item();
        string xpath = "//" + itemType.ToString();

        xpath = "items" + xpath;
        XmlElement node = (XmlElement)xmlDoc.SelectSingleNode(xpath);

        if (node == null)
        {
            Debug.Log("On ItemReader: " + itemType.ToString() + " not found");
            return(null);
        }
        item.itemType        = itemType;
        item.itemPrimaryType = (ItemPrimaryType)System.Enum.Parse(typeof(ItemPrimaryType), node.ParentNode.Name);
        item.Intro           = (node["intro"].InnerXml);
        item.Use             = (node["use"].InnerXml);
        item.Access          = (node["access"].InnerXml);
        item.sprite          = Resources.Load("UI/item/" + itemType.ToString(), typeof(Sprite)) as Sprite;

        if (item.itemPrimaryType == ItemPrimaryType.Buff)
        {
            XmlElement buffnode = (XmlElement)node.SelectSingleNode("buff");
            int        counter  = int.Parse(buffnode["counter"].InnerXml);
            int        value    = int.Parse(buffnode["value"].InnerXml);

            string attributeType = buffnode["attribute"].InnerXml;
            item.buff = new BuffEntry(GameEventHelper.getAttributeTypeFromString(attributeType),
                                      counter, value);
        }
        return(item);
    }
    private static void HandleEarlyParticipation(GameSession session, PacketReader packet)
    {
        int        eventId         = packet.ReadInt();
        AttendGift attendanceEvent = DatabaseManager.Events.FindAttendGiftEvent();

        if (attendanceEvent is null || attendanceEvent.SkipDayCurrencyType == GameEventCurrencyType.None)
        {
            return;
        }

        GameEventUserValue skipDay = GameEventHelper.GetUserValue(session.Player, attendanceEvent.Id,
                                                                  attendanceEvent.EndTimestamp, GameEventUserValueType.AttendanceEarlyParticipationRemaining);

        int.TryParse(skipDay.EventValue, out int skipsTotal);

        if (skipsTotal >= attendanceEvent.SkipDaysAllowed)
        {
            return;
        }

        // Charge player
        CurrencyType currencyType = attendanceEvent.SkipDayCurrencyType switch
        {
            GameEventCurrencyType.Meso => CurrencyType.Meso,
            GameEventCurrencyType.Meret => CurrencyType.Meret,
            _ => CurrencyType.Meret
        };

        switch (currencyType)
        {
        case CurrencyType.Meso:
            if (!session.Player.Wallet.Meso.Modify(-attendanceEvent.SkipDayCost))
            {
                return;
            }

            break;

        case CurrencyType.Meret:
            if (!session.Player.Account.Meret.Modify(-attendanceEvent.SkipDayCost))
            {
                return;
            }

            break;

        default:
            return;
        }

        skipsTotal++;
        skipDay.UpdateValue(session, skipsTotal);

        UpdateRewardsClaimed(session, attendanceEvent);
    }
    private static void UpdateRewardsClaimed(GameSession session, AttendGift attendanceEvent)
    {
        GameEventUserValue rewardsClaimValue = GameEventHelper.GetUserValue(session.Player, attendanceEvent.Id,
                                                                            attendanceEvent.EndTimestamp, GameEventUserValueType.AttendanceRewardsClaimed);

        int.TryParse(rewardsClaimValue.EventValue, out int convertedValue);

        convertedValue++;
        GiveAttendanceReward(session, attendanceEvent, convertedValue);
        rewardsClaimValue.UpdateValue(session, convertedValue);
    }
Esempio n. 5
0
        public PositiveGameEvent GetRandomPositiveGameEvent(bool hasAttackItem)
        {
            var query = _database.PositiveGameEvents.AsQueryable();

            //If we don't have an attack item, we can only get low-reward items.
            if (!hasAttackItem)
            {
                query = query.Where(p => p.Money < 50);
            }

            var gameEvents = query.ToList();

            return(GameEventHelper.GetRandomPositiveGameEvent(gameEvents));
        }
    private static void HandleClaimReward(GameSession session, PacketReader packet)
    {
        int rewardTier = packet.ReadInt();

        RPS rpsEvent = DatabaseManager.Events.FindRockPaperScissorsEvent();

        if (rpsEvent is null)
        {
            return;
        }

        GameEventUserValue rewardsAccumulatedValue = GameEventHelper.GetUserValue(session.Player, rpsEvent.Id,
                                                                                  TimeInfo.Tomorrow(), GameEventUserValueType.RPSRewardsClaimed);
        List <string> rewardsClaimedStrings = rewardsAccumulatedValue.EventValue.Split(",").ToList();

        foreach (string rewardString in rewardsClaimedStrings)
        {
            // User has not claimed any rewards
            if (rewardString == "")
            {
                break;
            }

            if (int.TryParse(rewardString, out int rewardInt) && rewardInt == rewardTier)
            {
                return;
            }
        }

        RPSTier tier = rpsEvent.Tiers.ElementAtOrDefault(rewardTier);

        if (tier is null)
        {
            return;
        }

        foreach (RPSReward reward in tier.Rewards)
        {
            Item item = new(reward.ItemId, reward.ItemAmount, reward.ItemRarity);

            session.Player.Inventory.AddItem(session, item, true);
        }

        // update event value
        rewardsClaimedStrings.Add(rewardTier.ToString());
        rewardsAccumulatedValue.UpdateValue(session, string.Join(",", rewardsClaimedStrings));
    }
    private static void HandleBeginTimer(GameSession session)
    {
        AttendGift attendanceEvent = DatabaseManager.Events.FindAttendGiftEvent();

        if (attendanceEvent is null)
        {
            return;
        }

        GameEventUserValue accumulatedTime = GameEventHelper.GetUserValue(session.Player, attendanceEvent.Id,
                                                                          TimeInfo.Tomorrow(), GameEventUserValueType.AttendanceAccumulatedTime);

        if (accumulatedTime.ExpirationTimestamp < TimeInfo.Now())
        {
            accumulatedTime.ExpirationTimestamp = TimeInfo.Tomorrow();
            accumulatedTime.EventValue          = "0";
            DatabaseManager.GameEventUserValue.Update(accumulatedTime);
        }
    }
    private static void HandleClaim(GameSession session)
    {
        AttendGift attendanceEvent = DatabaseManager.Events.FindAttendGiftEvent();

        if (attendanceEvent is null || attendanceEvent.EndTimestamp < TimeInfo.Now())
        {
            session.Send(AttendancePacket.Notice((int)AttendanceNotice.EventNotFound));
            return;
        }

        GameEventUserValue timeValue = GameEventHelper.GetUserValue(session.Player, attendanceEvent.Id,
                                                                    TimeInfo.Tomorrow(), GameEventUserValueType.AttendanceAccumulatedTime);

        long.TryParse(timeValue.EventValue, out long accumulatedTime);
        if (TimeInfo.Now() - session.Player.LastLogTime + accumulatedTime <
            attendanceEvent.TimeRequired)
        {
            return;
        }

        GameEventUserValue completeTimestampValue = GameEventHelper.GetUserValue(session.Player, attendanceEvent.Id,
                                                                                 attendanceEvent.EndTimestamp, GameEventUserValueType.AttendanceCompletedTimestamp);

        long.TryParse(completeTimestampValue.EventValue, out long completedTimestamp);

        DateTimeOffset savedTime = DateTimeOffset.FromUnixTimeSeconds(completedTimestamp);

        if (DateTimeOffset.Now.UtcDateTime < savedTime.UtcDateTime && DateTimeOffset.Now.Date != savedTime.Date)
        {
            session.Send(AttendancePacket.Notice((int)AttendanceNotice.EventHasAlreadyBeenCompleted));
            return;
        }

        // get current day value
        UpdateRewardsClaimed(session, attendanceEvent);

        // update completed timestamp
        long convertedValue2 = TimeInfo.Now();

        completeTimestampValue.UpdateValue(session, convertedValue2);
    }
Esempio n. 9
0
    public override void Handle(GameSession session, PacketReader packet)
    {
        MapleopolyMode mode = (MapleopolyMode)packet.ReadByte();

        BlueMarble mapleopolyEvent = DatabaseManager.Events.FindMapleopolyEvent();

        if (mapleopolyEvent is null)
        {
            // TODO: Find an error packet to send if event is not active
            return;
        }

        GameEventUserValue totalTileValue = GameEventHelper.GetUserValue(session.Player, mapleopolyEvent.Id, mapleopolyEvent.EndTimestamp,
                                                                         GameEventUserValueType.MapleopolyTotalTileCount);
        GameEventUserValue freeRollValue = GameEventHelper.GetUserValue(session.Player, mapleopolyEvent.Id, mapleopolyEvent.EndTimestamp,
                                                                        GameEventUserValueType.MapleopolyFreeRollAmount);
        GameEventUserValue totalTripValue = GameEventHelper.GetUserValue(session.Player, mapleopolyEvent.Id, mapleopolyEvent.EndTimestamp,
                                                                         GameEventUserValueType.MapleopolyTotalTrips);

        switch (mode)
        {
        case MapleopolyMode.Open:
            HandleOpen(session, totalTileValue, freeRollValue);
            break;

        case MapleopolyMode.Roll:
            HandleRoll(session, totalTileValue, freeRollValue);
            break;

        case MapleopolyMode.ProcessTile:
            HandleProcessTile(session, totalTileValue, freeRollValue, totalTripValue);
            break;

        default:
            LogUnknownMode(mode);
            break;
        }
    }
Esempio n. 10
0
        public NegativeGameEvent GetRandomNegativeGameEvent()
        {
            var gameEvents = Find();

            return(GameEventHelper.GetRandomNegativeGameEvent(gameEvents));
        }
    private static void HandleSelectRpsChoice(GameSession session, PacketReader packet)
    {
        session.Player.RPSSelection = (RpsChoice)packet.ReadInt();

        // delay for 1 sec for opponent to update their selection
        Task.Run(async() =>
        {
            await Task.Delay(1000);
        });

        // confirm if opponent is still in the map
        Player opponent = session.FieldManager.State.Players
                          .FirstOrDefault(x => x.Value.Value.CharacterId == session.Player.RPSOpponentId).Value?.Value;

        if (opponent == null)
        {
            return;
        }

        // handle choices
        RpsResult[,] resultMatrix =
        {
            {
                RpsResult.Draw, RpsResult.Lose, RpsResult.Win
            },
            {
                RpsResult.Win, RpsResult.Draw, RpsResult.Lose
            },
            {
                RpsResult.Lose, RpsResult.Win, RpsResult.Draw
            }
        };

        RpsResult result = resultMatrix[(int)session.Player.RPSSelection, (int)opponent.RPSSelection];

        RPS rpsEvent = DatabaseManager.Events.FindRockPaperScissorsEvent();

        if (rpsEvent is null)
        {
            return;
        }

        Item voucher = session.Player.Inventory.GetById(rpsEvent.VoucherId);

        if (voucher is null)
        {
            return;
        }

        session.Player.Inventory.ConsumeItem(session, voucher.Uid, 1);

        GameEventUserValue dailyMatches = GameEventHelper.GetUserValue(session.Player, rpsEvent.Id,
                                                                       TimeInfo.Tomorrow(), GameEventUserValueType.RPSDailyMatches);

        int.TryParse(dailyMatches.EventValue, out int dailyMatchCount);

        dailyMatchCount++;

        dailyMatches.UpdateValue(session, dailyMatchCount);
        session.Send(RockPaperScissorsPacket.MatchResults(result, session.Player.RPSSelection, opponent.RPSSelection));
    }
Esempio n. 12
0
    public override void Handle(GameSession session, PacketReader packet)
    {
        long accountId = packet.ReadLong();

        if (accountId is 0)
        {
            Logger.Error("Account ID was 0. Login has failed or connection was made directly to game server.");
            session.Send(LoginResultPacket.SendLoginMode(LoginMode.SessionVerificationFailed));
            return;
        }

        AuthData authData = DatabaseManager.AuthData.GetByAccountId(accountId);

        if (authData is null)
        {
            Logger.Error("AuthData with account ID {accountId} was not found in database.", accountId);
            session.Send(LoginResultPacket.SendLoginMode(LoginMode.SystemErrorDB));
            return;
        }

        Player dbPlayer = DatabaseManager.Characters.FindPlayerById(authData.OnlineCharacterId, session);

        // Backwards seeking because we read accountId here
        packet.Skip(-8);
        HandleCommon(session, packet);

        session.InitPlayer(dbPlayer);

        Player player = session.Player;

        player.BuddyList = GameServer.BuddyManager.GetBuddies(player.CharacterId);
        player.Mailbox   = GameServer.MailManager.GetMails(player.CharacterId);

        GameServer.PlayerManager.AddPlayer(player);
        GameServer.BuddyManager.SetFriendSessions(player);

        // Only send buddy login notification if player is not changing channels
        if (!player.IsMigrating)
        {
            player.UpdateBuddies();
        }

        if (player.GuildId != 0)
        {
            Guild guild = GameServer.GuildManager.GetGuildById(player.GuildId);
            player.Guild = guild;
            GuildMember guildMember = guild.Members.First(x => x.Id == player.CharacterId);
            guildMember.Player = player;
            player.GuildMember = guildMember;
            session.Send(GuildPacket.UpdateGuild(guild));
            guild.BroadcastPacketGuild(GuildPacket.UpdatePlayer(player));
            if (!player.IsMigrating)
            {
                guild.BroadcastPacketGuild(GuildPacket.MemberLoggedIn(player), session);
            }
        }

        // Get Clubs
        foreach (ClubMember member in player.ClubMembers)
        {
            Club club = GameServer.ClubManager.GetClubById(member.ClubId);
            club.Members.First(x => x.Player.CharacterId == player.CharacterId).Player = player;
            club.BroadcastPacketClub(ClubPacket.UpdateClub(club));
            if (!player.IsMigrating)
            {
                club.BroadcastPacketClub(ClubPacket.LoginNotice(player, club), session);
            }

            player.Clubs.Add(club);
            member.Player = player;
        }

        // Get Group Chats
        player.GroupChats = GameServer.GroupChatManager.GetGroupChatsByMember(player.CharacterId);
        foreach (GroupChat groupChat in player.GroupChats)
        {
            session.Send(GroupChatPacket.Update(groupChat));
            if (!player.IsMigrating)
            {
                groupChat.BroadcastPacketGroupChat(GroupChatPacket.LoginNotice(groupChat, player));
            }
        }

        //session.Send(0x27, 0x01); // Meret market related...?
        session.Send(MushkingRoyaleSystemPacket.LoadStats(player.Account.MushkingRoyaleStats));
        session.Send(MushkingRoyaleSystemPacket.LoadMedals(player.Account));

        player.GetUnreadMailCount();
        session.Send(BuddyPacket.Initialize());
        session.Send(BuddyPacket.LoadList(player.BuddyList));
        session.Send(BuddyPacket.EndList(player.BuddyList.Count));

        // Meret market
        session.Player.GetMeretMarketPersonalListings();
        session.Player.GetMeretMarketSales();
        // UserConditionEvent
        //session.Send("BF 00 00 00 00 00 00".ToByteArray());
        // PCBangBonus
        //session.Send("A7 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00".ToByteArray());

        session.Send(TimeSyncPacket.SetInitial1());
        session.Send(TimeSyncPacket.SetInitial2());

        session.Send(StatPacket.SetStats(session.Player.FieldPlayer));
        // session.Send(StatPacket.SetStats(session.Player.FieldPlayer)); // Second packet is meant to send the stats initialized, for now we'll just send the first one

        session.Player.ClientTickSyncLoop();
        session.Send(DynamicChannelPacket.DynamicChannel(short.Parse(ConstantsMetadataStorage.GetConstant("ChannelCount"))));

        session.Send(ServerEnterPacket.Enter(session));
        session.Send(UGCPacket.Unknown22());
        session.Send(CashPacket.Unknown09());

        // SendContentShutdown f(0x01, 0x04)
        session.Send(PvpPacket.Mode0C());
        session.Send(SyncNumberPacket.Send());
        session.Send(SyncValuePacket.SetSyncValue(120000)); // unknown what this value means

        session.Send(PrestigePacket.SetLevels(player));
        session.Send(PrestigePacket.WeeklyMissions(player.PrestigeMissions));

        // Load inventory tabs
        foreach (InventoryTab tab in Enum.GetValues(typeof(InventoryTab)))
        {
            player.Inventory.LoadInventoryTab(session, tab);
        }

        if (player.Account.HomeId != 0)
        {
            Home home = GameServer.HomeManager.GetHomeById(player.Account.HomeId);
            player.Account.Home = home;
            session.Send(WarehouseInventoryPacket.StartList());
            int counter = 0;
            foreach (KeyValuePair <long, Item> kvp in home.WarehouseInventory)
            {
                session.Send(WarehouseInventoryPacket.Load(kvp.Value, ++counter));
            }

            session.Send(WarehouseInventoryPacket.EndList());

            session.Send(FurnishingInventoryPacket.StartList());
            foreach (Cube cube in home.FurnishingInventory.Values.Where(x => x.Item != null))
            {
                session.Send(FurnishingInventoryPacket.Load(cube));
            }

            session.Send(FurnishingInventoryPacket.EndList());
        }

        session.Send(QuestPacket.StartList());
        session.Send(QuestPacket.Packet1F());
        session.Send(QuestPacket.Packet20());

        IEnumerable <List <QuestStatus> > packetCount = player.QuestData.Values.ToList().SplitList(200); // Split the quest list in 200 quests per packet

        foreach (List <QuestStatus> item in packetCount)
        {
            session.Send(QuestPacket.SendQuests(item));
        }

        session.Send(QuestPacket.EndList());

        session.Send(TrophyPacket.WriteTableStart());
        List <Trophy> trophyList = new(player.TrophyData.Values);
        IEnumerable <List <Trophy> > trophyListPackets = trophyList.SplitList(60);

        foreach (List <Trophy> trophy in trophyListPackets)
        {
            session.Send(TrophyPacket.WriteTableContent(trophy));
        }

        // SendQuest, SendAchieve, SendManufacturer, SendUserMaid
        session.Send(UserEnvPacket.SetTitles(player));
        session.Send(UserEnvPacket.Send04());
        session.Send(UserEnvPacket.Send05());
        session.Send(UserEnvPacket.UpdateLifeSkills(player.GatheringCount));
        session.Send(UserEnvPacket.Send09());
        session.Send(UserEnvPacket.Send10());
        session.Send(UserEnvPacket.Send12());

        session.Send(MeretMarketPacket.ModeC9());

        session.Send(FishingPacket.LoadAlbum(player));

        session.Send(PvpPacket.Mode16());
        session.Send(PvpPacket.Mode17());

        session.Send(ResponsePetPacket.LoadAlbum());
        // LegionBattle (0xF6)
        // CharacterAbility
        // E1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

        // If the character is not a new character, this is what we would send
        session.Send(KeyTablePacket.SendFullOptions(player.GameOptions));

        if (player.MapId == (int)Map.UnknownLocation)  // tutorial map
        {
            session.Send(KeyTablePacket.AskKeyboardOrMouse());
        }

        GameEventHelper.LoadEvents(session.Player);
        List <GameEvent> gameEvents = DatabaseManager.Events.FindAll();
        IEnumerable <List <GameEvent> > gameEventPackets = gameEvents.SplitList(5);

        foreach (List <GameEvent> gameEvent in gameEventPackets)
        {
            session.Send(GameEventPacket.Load(gameEvent));
        }

        // SendKeyTable f(0x00), SendGuideRecord f(0x03), GameEvent f(0x00)
        // SendBannerList f(0x19), SendRoomDungeon f(0x05, 0x14, 0x17)
        session.Send(DungeonListPacket.DungeonList());
        // 0xF0, ResponsePet P(0F 01)
        // RequestFieldEnter
        //session.Send("16 00 00 41 75 19 03 00 01 8A 42 0F 00 00 00 00 00 00 C0 28 C4 00 40 03 44 00 00 16 44 00 00 00 00 00 00 00 00 55 FF 33 42 E8 49 01 00".ToByteArray());
        session.Send(RequestFieldEnterPacket.RequestEnter(player.FieldPlayer));

        Party party = GameServer.PartyManager.GetPartyByMember(player.CharacterId);

        if (party != null)
        {
            player.Party = party;
            if (!player.IsMigrating)
            {
                party.BroadcastPacketParty(PartyPacket.LoginNotice(player), session);
            }

            session.Send(PartyPacket.Create(party, false));
            party.BroadcastPacketParty(PartyPacket.UpdatePlayer(player));
            party.BroadcastPacketParty(PartyPacket.UpdateDungeonInfo(player));
        }

        player.IsMigrating = false;

        // SendUgc: 15 01 00 00 00 00 00 00 00 00 00 00 00 4B 00 00 00
        session.Send(HomeCommandPacket.LoadHome(player));

        player.TimeSyncLoop();
        session.Send(TimeSyncPacket.SetSessionServerTick(0));
        //session.Send("B9 00 00 E1 0F 26 89 7F 98 3C 26 00 00 00 00 00 00 00 00".ToByteArray());
        session.Send(ServerEnterPacket.Confirm());

        //session.Send(0xF0, 0x00, 0x1F, 0x78, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00);
        //session.Send(0x28, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);
    }
    public GameEvent getNewGameEvent(GameEventType type, int which)
    {
        if (which < 0 || which >= eventNums[(int)type])
        {
            return(null);
        }

        GameEvent gameEvent        = null;
        string    eventName        = "";
        string    eventDescription = "";
        int       eventCounter     = 0;

        //int eventid=0;

        if (xmlDoc != null)
        {
            string     xpath = eventxpath[(int)type];
            XmlElement node  = (XmlElement)xmlDoc.SelectNodes(xpath)[which];
            eventName        = node["name"].InnerXml;
            eventDescription = node["description"].InnerXml;
            eventCounter     = int.Parse(node["counter"].InnerXml);
        }
        else
        {
            Debug.Log("EventReader not load correctly");
            return(null);
        }

        switch (type)
        {
        case GameEventType.NormalNonoptionGainbuffEvent:
            try
            {
                XmlElement node = (XmlElement)xmlDoc.SelectNodes(eventxpath[(int)type])[which];

                XmlElement buffnode = (XmlElement)node.SelectSingleNode("buff");
                int        counter  = int.Parse(buffnode["counter"].InnerXml);
                int        value    = int.Parse(buffnode["value"].InnerXml);

                string attributeType = buffnode["attribute"].InnerXml;


                string    effectDescription = node["effectDescription"].InnerXml;
                BuffEntry entry             = new BuffEntry(GameEventHelper.getAttributeTypeFromString(attributeType),
                                                            counter, value);
                gameEvent = new NormalNonoptionGainbuffEvent(eventName, eventDescription, eventCounter, type, which,
                                                             effectDescription,
                                                             entry);
                //Debug.Log(gameEvent.ToString());
            }
            catch (Exception ex)
            {
                Debug.Log(ex.StackTrace);
            }
            break;

        case GameEventType.NormalNonoptionGainitemsEvent:
            try
            {
                XmlElement  node = (XmlElement)xmlDoc.SelectNodes(eventxpath[(int)type])[which];
                string      effectDescription = node["effectDescription"].InnerXml;
                XmlNodeList itemnodes         = node.SelectNodes("item");
                //Debug.Log("itemnodes: " + itemnodes.Count);
                List <ItemEntry> items = new List <ItemEntry>();
                for (int i = 0; i < itemnodes.Count; i++)
                {
                    ItemEntry  itemEntry = new ItemEntry();
                    XmlElement itemnode  = (XmlElement)itemnodes[i];
                    itemEntry.primaryType = GameEventHelper.getItemPrimaryTypeFromString(itemnode["type"].InnerXml);
                    itemEntry.itemType    = GameEventHelper.getItemTypeFromString(itemEntry.primaryType, itemnode["typeEnum"].InnerXml);
                    itemEntry.number      = int.Parse(itemnode["number"].InnerXml);
                    itemEntry.posibility  = int.Parse(itemnode["posibility"].InnerXml);
                    items.Add(itemEntry);
                }
                gameEvent = new NormalNonoptionGainitemsEvent(eventName, eventDescription, eventCounter, type, which, effectDescription,
                                                              items);
                //Debug.Log(gameEvent.ToString());
            }
            catch (Exception ex)
            {
                Debug.Log(ex.StackTrace);
            }
            break;

        case GameEventType.NormalNonoptionMemoryEvent:
            try
            {
                XmlElement node = (XmlElement)xmlDoc.SelectNodes(eventxpath[(int)type])[which];
                string     effectDescription = node["effectDescription"].InnerXml;

                int memoryid = int.Parse(node["memory"].InnerXml);

                gameEvent = new NormalNonoptionMemoryEvent(eventName, eventDescription, eventCounter, type, which, effectDescription,
                                                           memoryid);
            }
            catch (Exception ex)
            {
                Debug.Log(ex.StackTrace);
            }
            break;

        case GameEventType.NormalOptionEvent:
            try
            {
                XmlNodeList optionnodes = xmlDoc.SelectNodes(eventxpath[(int)type])[which].SelectNodes("options/option");
                //Debug.Log(optionnodes.Count);
                List <GameEventOption> options = new List <GameEventOption>();
                for (int i = 0; i < optionnodes.Count; i++)
                {
                    XmlElement  node      = (XmlElement)optionnodes[i];
                    string      name      = node["name"].InnerXml;
                    XmlNodeList itemnodes = node.SelectNodes("item");
                    XmlNodeList buffnodes = node.SelectNodes("buff");

                    List <ItemEntry> items = itemnodes.Count > 0?new List <ItemEntry>():null;
                    List <BuffEntry> buffs = buffnodes.Count > 0?new List <BuffEntry>():null;

                    //Debug.Log("Items: " + itemnodes.Count + "\t\tBuffs: " + buffnodes.Count);

                    for (int j = 0; j < itemnodes.Count; j++)
                    {
                        XmlElement item      = (XmlElement)itemnodes[j];
                        ItemEntry  itementry = new ItemEntry();
                        itementry.primaryType = GameEventHelper.getItemPrimaryTypeFromString(item["type"].InnerXml);
                        itementry.itemType    = GameEventHelper.getItemTypeFromString(itementry.primaryType, item["typeEnum"].InnerXml);
                        itementry.number      = int.Parse(item["number"].InnerXml);
                        itementry.posibility  = int.Parse(item["posibility"].InnerXml);

                        items.Add(itementry);
                    }

                    for (int j = 0; j < buffnodes.Count; j++)
                    {
                        XmlElement buff      = (XmlElement)buffnodes[j];
                        BuffEntry  buffentry = new BuffEntry(GameEventHelper.getAttributeTypeFromString(buff["attribute"].InnerXml),
                                                             int.Parse(buff["counter"].InnerXml), int.Parse(buff["value"].InnerXml));
                        buffs.Add(buffentry);
                    }

                    GameEventOption option = new GameEventOption(name, items, buffs, null, null);
                    options.Add(option);
                }
                gameEvent = new NormalOptionEvent(eventName, eventDescription, eventCounter, type, which,
                                                  options);
                //Debug.Log(gameEvent.ToString());
            }
            catch (Exception ex)
            {
                Debug.Log(ex.StackTrace);
            }

            break;

        case GameEventType.MysterypersonGainitemsEvent:
            try
            {
                XmlNodeList optionnodes = xmlDoc.SelectNodes(eventxpath[(int)type])[which].SelectNodes("options/option");
                //Debug.Log(optionnodes.Count);
                List <GameEventOption> options = new List <GameEventOption>();
                for (int i = 0; i < optionnodes.Count; i++)
                {
                    XmlElement node   = (XmlElement)optionnodes[i];
                    string     name   = node["name"].InnerXml;
                    string     result = node["result"].InnerXml ?? null;
                    //Debug.Log("event " + which + " " + name + result);
                    XmlNodeList itemnodes = node.SelectNodes("item");
                    XmlNodeList buffnodes = node.SelectNodes("buff");
                    XmlNodeList costnodes = node.SelectNodes("cost/item");

                    List <ItemEntry> items = itemnodes.Count > 0 ? new List <ItemEntry>() : null;
                    List <BuffEntry> buffs = buffnodes.Count > 0 ? new List <BuffEntry>() : null;
                    List <ItemEntry> costs = costnodes.Count > 0?new List <ItemEntry>():null;

                    //Debug.Log("Items: " + itemnodes.Count + "\t\tBuffs: " + buffnodes.Count);

                    for (int j = 0; j < itemnodes.Count; j++)
                    {
                        XmlElement item      = (XmlElement)itemnodes[j];
                        ItemEntry  itementry = new ItemEntry();
                        itementry.primaryType = GameEventHelper.getItemPrimaryTypeFromString(item["type"].InnerXml);
                        itementry.itemType    = GameEventHelper.getItemTypeFromString(itementry.primaryType, item["typeEnum"].InnerXml);
                        itementry.number      = int.Parse(item["number"].InnerXml);
                        itementry.posibility  = int.Parse(item["posibility"].InnerXml);

                        items.Add(itementry);
                    }

                    for (int j = 0; j < buffnodes.Count; j++)
                    {
                        XmlElement buff      = (XmlElement)buffnodes[j];
                        BuffEntry  buffentry = new BuffEntry(GameEventHelper.getAttributeTypeFromString(buff["attribute"].InnerXml),
                                                             int.Parse(buff["counter"].InnerXml), int.Parse(buff["value"].InnerXml));
                        buffs.Add(buffentry);
                    }

                    for (int j = 0; j < costnodes.Count; j++)
                    {
                        XmlElement cost      = (XmlElement)costnodes[j];
                        ItemEntry  costentry = new ItemEntry();
                        costentry.primaryType = GameEventHelper.getItemPrimaryTypeFromString(cost["type"].InnerXml);
                        costentry.itemType    = GameEventHelper.getItemTypeFromString(costentry.primaryType, cost["typeEnum"].InnerXml);
                        costentry.number      = int.Parse(cost["number"].InnerXml);
                        costentry.posibility  = 100;

                        costs.Add(costentry);
                    }

                    GameEventOption option = new GameEventOption(name, items, buffs, costs, result);
                    options.Add(option);
                }
                gameEvent = new MysterypersonGainitemsEvent(eventName, eventDescription, eventCounter, type, which, options);
                //Debug.Log(gameEvent.ToString());
            }
            catch (Exception ex)
            {
                Debug.Log(ex.StackTrace);
            }
            break;

        case GameEventType.MysterypersonGaincharacterEvent:
            try
            {
                XmlNode     eventnode   = xmlDoc.SelectNodes(eventxpath[(int)type])[which];
                XmlNodeList optionnodes = eventnode.SelectNodes("options/option");

                MonsterType monsterType = GameEventHelper.getMonsterTypeFromString(eventnode["character"].InnerXml);
                int         level       = int.Parse(eventnode["level"].InnerXml);

                List <GameEventOption> options = new List <GameEventOption>();

                for (int i = 0; i < optionnodes.Count; i++)
                {
                    XmlElement node   = (XmlElement)optionnodes[i];
                    string     name   = node["name"].InnerXml;
                    string     result = node["result"].InnerXml ?? null;
                    //Debug.Log("event " + which + " " + name + result);
                    XmlNodeList itemnodes = node.SelectNodes("item");
                    XmlNodeList buffnodes = node.SelectNodes("buff");
                    XmlNodeList costnodes = node.SelectNodes("cost/item");

                    List <ItemEntry> items = itemnodes.Count > 0 ? new List <ItemEntry>() : null;
                    List <BuffEntry> buffs = buffnodes.Count > 0 ? new List <BuffEntry>() : null;
                    List <ItemEntry> costs = costnodes.Count > 0 ? new List <ItemEntry>() : null;

                    //Debug.Log("Items: " + itemnodes.Count + "\t\tBuffs: " + buffnodes.Count);

                    for (int j = 0; j < itemnodes.Count; j++)
                    {
                        XmlElement item      = (XmlElement)itemnodes[j];
                        ItemEntry  itementry = new ItemEntry();
                        itementry.primaryType = GameEventHelper.getItemPrimaryTypeFromString(item["type"].InnerXml);
                        itementry.itemType    = GameEventHelper.getItemTypeFromString(itementry.primaryType, item["typeEnum"].InnerXml);
                        itementry.number      = int.Parse(item["number"].InnerXml);
                        itementry.posibility  = int.Parse(item["posibility"].InnerXml);

                        items.Add(itementry);
                    }

                    for (int j = 0; j < buffnodes.Count; j++)
                    {
                        XmlElement buff      = (XmlElement)buffnodes[j];
                        BuffEntry  buffentry = new BuffEntry(GameEventHelper.getAttributeTypeFromString(buff["attribute"].InnerXml),
                                                             int.Parse(buff["counter"].InnerXml), int.Parse(buff["value"].InnerXml));
                        buffs.Add(buffentry);
                    }

                    for (int j = 0; j < costnodes.Count; j++)
                    {
                        XmlElement cost      = (XmlElement)costnodes[j];
                        ItemEntry  costentry = new ItemEntry();
                        costentry.primaryType = GameEventHelper.getItemPrimaryTypeFromString(cost["type"].InnerXml);
                        costentry.itemType    = GameEventHelper.getItemTypeFromString(costentry.primaryType, cost["typeEnum"].InnerXml);
                        costentry.number      = int.Parse(cost["number"].InnerXml);
                        costentry.posibility  = 100;

                        costs.Add(costentry);
                    }

                    GameEventOption option = new GameEventOption(name, items, buffs, costs, result);
                    options.Add(option);
                }

                gameEvent = new MysterypersonGaincharacterEvent(eventName, eventDescription, eventCounter, type, which,
                                                                monsterType, level, options);
                //Debug.Log(gameEvent.ToString());
            }
            catch (Exception ex)
            {
                Debug.Log(ex.StackTrace);
            }

            break;

        default:
            break;
        }

        return(gameEvent);
    }