public void UpdateGameEventPanel(GameEvent gameEvent)
    {
        Clear();
        mainPanel.gameObject.SetActive(true);
        this.gameEvent = gameEvent;
        switch (gameEvent.eventType)
        {
        case GameEventType.NormalNonoptionGainbuffEvent:
            try
            {
                NormalNonoptionGainbuffEvent convertedEvent = (NormalNonoptionGainbuffEvent)gameEvent;
                EnableNonoptionPart();
                currentBuff  = convertedEvent.GetBuff();
                effectString = convertedEvent.GetEffectDescription();
                effect.text  = effectString;
            } catch (InvalidCastException ex)
            {
                Debug.Log(ex.StackTrace);
            }
            break;

        case GameEventType.NormalNonoptionGainitemsEvent:
            try
            {
                NormalNonoptionGainitemsEvent convertedEvent = (NormalNonoptionGainitemsEvent)gameEvent;
                EnableNonoptionPart();
                currentItems = convertedEvent.GetItems();
                effectString = convertedEvent.GetEffectDescription();
                effect.text  = effectString;
            } catch (InvalidCastException ex)
            {
                Debug.Log(ex.StackTrace);
            }
            break;

        case GameEventType.NormalNonoptionMemoryEvent:
            try
            {
                NormalNonoptionMemoryEvent convertedEvent = (NormalNonoptionMemoryEvent)gameEvent;
                EnableNonoptionPart();
                currentMemory = convertedEvent.GetMemoryId();
                effectString  = convertedEvent.GetEffectDescription();
                effect.text   = effectString;
            } catch (InvalidCastException ex)
            {
                Debug.Log(ex.StackTrace);
            }
            break;

        case GameEventType.NormalOptionEvent:
            try
            {
                NormalOptionEvent convertedEvent = (NormalOptionEvent)gameEvent;
                EnableOptionPart();
                currentOptions = convertedEvent.GetOptions();
                for (int i = 0; i < optionsButton.Count; i++)
                {
                    if (i < currentOptions.Count)
                    {
                        optionsButton[i].gameObject.SetActive(true);
                        optionsButton[i].GetComponent <Text>().text = currentOptions[i].name;
                    }
                    else
                    {
                        optionsButton[i].gameObject.SetActive(false);
                    }
                }
            } catch (InvalidCastException ex)
            {
                Debug.Log(ex.StackTrace);
            }

            break;

        case GameEventType.MysterypersonGainitemsEvent:
            try
            {
                MysterypersonGainitemsEvent convertedEvent = (MysterypersonGainitemsEvent)gameEvent;
                EnableOptionPart();
                currentOptions = convertedEvent.GetOptions();
                for (int i = 0; i < optionsButton.Count; i++)
                {
                    if (i < currentOptions.Count)
                    {
                        optionsButton[i].gameObject.SetActive(true);
                        optionsButton[i].GetComponent <Text>().text = currentOptions[i].name;
                    }
                    else
                    {
                        optionsButton[i].gameObject.SetActive(false);
                    }
                }
            } catch (InvalidCastException ex)
            {
                Debug.Log(ex.StackTrace);
            }
            break;

        case GameEventType.MysterypersonGaincharacterEvent:
            try
            {
                MysterypersonGaincharacterEvent convertedEvent = (MysterypersonGaincharacterEvent)gameEvent;
                EnableOptionPart();
                currentMonsterType  = convertedEvent.GetMonsterType();
                currentMonsterLevel = convertedEvent.GetLevel();
                currentOptions      = convertedEvent.GetOptions();
                for (int i = 0; i < optionsButton.Count; i++)
                {
                    if (i < currentOptions.Count)
                    {
                        optionsButton[i].gameObject.SetActive(true);
                        optionsButton[i].GetComponent <Text>().text = currentOptions[i].name;
                    }
                    else
                    {
                        optionsButton[i].gameObject.SetActive(false);
                    }
                }
            } catch (InvalidCastException ex)
            {
                Debug.Log(ex.StackTrace);
            }
            break;

        default:
            break;
        }
        name.text        = gameEvent.eventName;
        description.text = gameEvent.eventDescription;
        eventReader      = new GameEventReader();
        Sprite sprite;

        if ((sprite = Resources.Load(imagePath + eventReader.GetGameEventIndex(gameEvent), typeof(Sprite)) as Sprite) != null)
        {
            cg.sprite = sprite;
        }
    }
    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);
    }