// -----------------------------------------------------------------------------------
    // getQuestReward
    // -----------------------------------------------------------------------------------
    public UCE_QuestReward getQuestReward(UCE_Quest quest)
    {
        if (quest.questRewards.Length == 1)
        {
            return(quest.questRewards[0]);
        }

        // -- check class based rewards

        for (int i = 0; i < quest.questRewards.Length; i++)
        {
            if (quest.questRewards[i].availableToClass != null && quest.questRewards[i].availableToClass.Length > 0)
            {
                if (UCE_checkHasClass(quest.questRewards[i].availableToClass))
                {
                    return(quest.questRewards[i]);
                }
            }
        }

        // -- check randomized rewards

        foreach (UCE_QuestReward questReward in quest.questRewards)
        {
            if (UnityEngine.Random.value <= questReward.rewardChance)
            {
                return(questReward);
            }
        }

        // -- return the very first reward if no one is found
        return(quest.questRewards[0]);
    }
    public void UCE_IncreaseQuestLootCounterFor(string lootcrateName)
    {
        for (int i = 0; i < UCE_quests.Count; ++i)
        {
            if ((!UCE_quests[i].completed || !UCE_quests[i].completedAgain) &&
                UCE_quests[i].lootTarget.Length > 0 &&
                UCE_quests[i].lootTarget.Any(x => x.target.name == lootcrateName)
                )
            {
                UCE_Quest quest    = UCE_quests[i];
                bool      bChanged = false;

                for (int j = 0; j < quest.lootTarget.Length; ++j)
                {
                    if (quest.lootTarget[j].target.name == lootcrateName &&
                        quest.lootedTarget[j] < quest.lootTarget[j].amount)
                    {
                        int idx = j;
                        quest.lootedTarget[idx]++;
                        bChanged = true;
                        break;
                    }
                }

                UCE_quests[i] = quest;
                if (bChanged)
                {
                    UCE_checkQuestCompletion(i);
                }
            }
        }
    }
    public void UCE_IncreaseHarvestNodeCounterFor(UCE_HarvestingProfessionTemplate profession)
    {
        for (int i = 0; i < UCE_quests.Count; ++i)
        {
            if ((!UCE_quests[i].completed || !UCE_quests[i].completedAgain) &&
                UCE_quests[i].harvestTarget.Length > 0 &&
                UCE_quests[i].harvestTarget.Any(x => x.target == profession)
                )
            {
                UCE_Quest quest    = UCE_quests[i];
                bool      bChanged = false;

                for (int j = 0; j < quest.harvestTarget.Length; ++j)
                {
                    if (quest.harvestTarget[j].target == profession &&
                        quest.harvestedTarget[j] < quest.harvestTarget[j].amount)
                    {
                        int idx = j;
                        quest.harvestedTarget[idx]++;
                        bChanged = true;
                        break;
                    }
                }

                UCE_quests[i] = quest;
                if (bChanged)
                {
                    UCE_checkQuestCompletion(i);
                }
            }
        }
    }
    public void UCE_IncreaseCraftCounterFor(UCE_Tmpl_Recipe recipe)
    {
        for (int i = 0; i < UCE_quests.Count; ++i)
        {
            if ((!UCE_quests[i].completed || !UCE_quests[i].completedAgain) &&
                UCE_quests[i].craftTarget.Length > 0 &&
                UCE_quests[i].craftTarget.Any(x => x.target == recipe)
                )
            {
                UCE_Quest quest    = UCE_quests[i];
                bool      bChanged = false;

                for (int j = 0; j < quest.craftTarget.Length; ++j)
                {
                    if (quest.craftTarget[j].target == recipe &&
                        quest.craftedTarget[j] < quest.craftTarget[j].amount)
                    {
                        int idx = j;
                        quest.craftedTarget[idx]++;
                        bChanged = true;
                        break;
                    }
                }

                UCE_quests[i] = quest;
                if (bChanged)
                {
                    UCE_checkQuestCompletion(i);
                }
            }
        }
    }
    public void UCE_IncreaseQuestPlayerKillCounterFor(Player victim)
    {
#if _iMMOPVP && _iMMOQUESTS
        for (int i = 0; i < UCE_quests.Count; ++i)
        {
            int index = i;

            if ((!UCE_quests[index].completed || !UCE_quests[index].completedAgain) &&
                UCE_quests[index].pvpTarget.Length > 0
                )
            {
                UCE_Quest quest = UCE_quests[index];

                for (int j = 0; j < quest.pvpTarget.Length; ++j)
                {
                    int idx = j;

                    if (UCE_CheckPvPTarget(victim, quest.pvpTarget[idx]))
                    {
                        quest.pvpedTarget[idx]++;
                        break;
                    }
                }

                UCE_quests[index] = quest;
                UCE_checkQuestCompletion(index);
            }
        }
#endif
    }
    public void UCE_IncreaseQuestMonsterKillCounterFor(Monster victim)
    {
        for (int i = 0; i < UCE_quests.Count; ++i)
        {
            int index = i;

            if ((!UCE_quests[index].completed || !UCE_quests[index].completedAgain) &&
                UCE_quests[index].killTarget.Length > 0 &&
                UCE_quests[index].killTarget.Any(x => x.target.name == victim.name)
                )
            {
                UCE_Quest quest    = UCE_quests[index];
                bool      bChanged = false;

                for (int j = 0; j < quest.killTarget.Length; ++j)
                {
                    int idx = j;
                    if (quest.killTarget[idx].target.name == victim.name &&
                        quest.killedTarget[idx] < quest.killTarget[idx].amount)
                    {
                        quest.killedTarget[idx]++;
                        bChanged = true;
                        break;
                    }
                }

                UCE_quests[index] = quest;
                if (bChanged)
                {
                    UCE_checkQuestCompletion(index);
                }
            }
        }
    }
    // -----------------------------------------------------------------------------------
    // checkGatheredItems
    // -----------------------------------------------------------------------------------
    public int[] checkGatheredItems(UCE_Quest quest)
    {
        int[] gathered = new int[10];
        int   j        = 0;

        for (int i = 0; i < quest.gatherTarget.Length; i++)
        {
            j           = i;
            gathered[j] = Mathf.Min(InventoryCount(new Item(quest.gatherTarget[j].target)), quest.gatherTarget[j].amount);
        }

        return(gathered);
    }
    // -----------------------------------------------------------------------------------
    // getHasEnoughSpace
    // -----------------------------------------------------------------------------------
    public bool getHasEnoughSpace(UCE_Quest quest)
    {
        if (quest.questRewards.Length > 0)
        {
            foreach (UCE_QuestReward questReward in quest.questRewards)
            {
                if (InventorySlotsFree() < questReward.rewardItem.Length)
                {
                    return(false);
                }
            }
        }

        return(true);
    }
    public void Cmd_UCE_AcceptQuest(int npcQuestIndex)
    {
        if (state == "IDLE" &&
            target != null &&
            isAlive &&
            target.isAlive &&
            target is Npc &&
            0 <= npcQuestIndex && npcQuestIndex < ((Npc)target).UCE_quests.Length &&
            Utils.ClosestDistance(collider, target.collider) <= interactionRange &&
            UCE_CanAcceptQuest(((Npc)target).UCE_quests[npcQuestIndex]))
        {
            int idx = UCE_GetQuestIndexByName(((Npc)target).UCE_quests[npcQuestIndex].name);

            if (idx == -1)
            {
                UCE_ScriptableQuest quest = ((Npc)target).UCE_quests[npcQuestIndex];
                UCE_quests.Add(new UCE_Quest(quest));

                // -- accept items
                if (quest.acceptItems != null && quest.acceptItems.Length > 0)
                {
                    foreach (UCE_rewardItem rewardItem in quest.acceptItems)
                    {
                        InventoryAdd(new Item(rewardItem.item), rewardItem.amount);
                    }
                }
            }
            else
            {
                UCE_Quest quest = UCE_quests[idx];
                quest.resetQuest();
                quest.completedAgain = false;
                quest.lastCompleted  = "";
                UCE_quests[idx]      = quest;

                // -- accept items
                if (quest.acceptItems != null && quest.acceptItems.Length > 0)
                {
                    foreach (UCE_rewardItem rewardItem in quest.acceptItems)
                    {
                        InventoryAdd(new Item(rewardItem.item), rewardItem.amount);
                    }
                }
            }
        }
    }
    public void Cmd_UCE_CancelQuest(string questName)
    {
        int index = UCE_GetQuestIndexByName(questName);

        UCE_Quest quest = UCE_quests[index];

        if (!UCE_HasCompletedQuest(questName))
        {
            // -- remove accept items
            if (quest.acceptItems.Length > 0)
            {
                foreach (UCE_rewardItem rewardItem in quest.acceptItems)
                {
                    InventoryRemove(new Item(rewardItem.item), rewardItem.amount);
                }
            }

            UCE_quests.RemoveAt(index);
        }
    }
    // -----------------------------------------------------------------------------------
    // UCE_CanRestartQuest
    // -----------------------------------------------------------------------------------
    public bool UCE_CanRestartQuest(UCE_ScriptableQuest quest)
    {
        int idx = UCE_GetQuestIndexByName(quest.name);

        if (idx == -1)
        {
            return(true);
        }

        UCE_Quest tmp_quest = UCE_quests[idx];

        if (UCE_CanCompleteQuest(quest.name) ||
            UCE_HasActiveQuest(quest.name) ||
            quest.repeatable <= 0 ||
            (quest.repeatable > 0 && tmp_quest.getLastCompleted() < tmp_quest.repeatable && tmp_quest.completedAgain)
            )
        {
            return(false);
        }

        return(true);
    }
Ejemplo n.º 12
0
    private void CharacterLoad_UCE_Quest(Player player)
    {
        var table = connection.Query <quest>(
            "SELECT name, pvped, killed, gathered, harvested, visited, crafted, looted, completed, completedAgain, lastCompleted, counter FROM character_UCE_quests WHERE character = ?",
            player.name);

        foreach (var row in table)
        {
            string questName = row.name;
            UCE_ScriptableQuest questData;
            if (UCE_ScriptableQuest.dict.TryGetValue(questName.GetStableHashCode(), out questData))
            {
                UCE_Quest quest = new UCE_Quest(questData);

                quest.pvpedTarget     = UCE_Tools.IntStringToArray(row.pvped);
                quest.killedTarget    = UCE_Tools.IntStringToArray(row.killed);
                quest.gatheredTarget  = UCE_Tools.IntStringToArray(row.gathered);
                quest.harvestedTarget = UCE_Tools.IntStringToArray(row.harvested);
                quest.visitedTarget   = UCE_Tools.IntStringToArray(row.visited);
                quest.craftedTarget   = UCE_Tools.IntStringToArray(row.crafted);
                quest.lootedTarget    = UCE_Tools.IntStringToArray(row.looted);

                foreach (int i in quest.visitedTarget)
                {
                    if (i != 0)
                    {
                        quest.visitedCount++;
                    }
                }

                quest.completed      = row.completed != 0;      // sqlite has no bool
                quest.completedAgain = row.completedAgain != 0; // sqlite has no bool
                quest.lastCompleted  = row.lastCompleted;
                quest.counter        = row.counter;
                player.UCE_quests.Add(quest);
            }
        }
    }
    // -----------------------------------------------------------------------------------
    // UCE_CanCompleteQuest
    // -----------------------------------------------------------------------------------
    public bool UCE_CanCompleteQuest(string questName)
    {
        int index = UCE_GetQuestIndexByName(questName);

        if (index != -1 &&
            (!UCE_quests[index].completed || UCE_quests[index].repeatable > 0 && !UCE_quests[index].completedAgain)
            )
        {
            UCE_Quest quest = UCE_quests[index];

            // -- check explored areas
            int explored = 0;
#if _iMMOEXPLORATION
            foreach (UCE_Area_Exploration area in quest.exploreTarget)
            {
                if (UCE_HasExploredArea(area))
                {
                    explored++;
                }
            }
#endif

            // -- check faction requirement
            bool factionRequirementsMet = true;
#if _iMMOFACTIONS
            factionRequirementsMet = UCE_CheckFactionRating(quest.factionRequirement);
#endif

            // -- validate the rest
            if (quest.IsFulfilled(checkGatheredItems(quest), explored, factionRequirementsMet))
            {
                return(true);
            }
        }

        return(false);
    }
    public void Cmd_UCE_IncreaseQuestNpcCounterFor(int index, int hash)
    {
        UCE_Quest quest    = UCE_quests[index];
        bool      bChanged = false;

        for (int j = 0; j < UCE_quests[index].visitTarget.Length; ++j)
        {
            if (UCE_quests[index].visitTarget[j].name.GetDeterministicHashCode() == hash &&
                quest.visitedTarget[j] != hash
                )
            {
                quest.visitedTarget[j] = hash;
                quest.visitedCount++;
                UCE_quests[index] = quest;
                bChanged          = true;
                break;
            }
        }

        if (bChanged)
        {
            UCE_checkQuestCompletion(index);
        }
    }
    // -----------------------------------------------------------------------------------
    // Update
    // -----------------------------------------------------------------------------------
    private void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        if (panel.activeSelf)
        {
            List <UCE_Quest> activeQuests = player.UCE_quests.Where(q => !q.completed || (q.repeatable > 0 && !q.completedAgain)).ToList();

            int maxQuests = Mathf.Min(activeQuests.Count, maxActiveQuestsToShow);

            UIUtils.BalancePrefabs(slotPrefab.gameObject, maxQuests, content);

            // -- refresh all
            for (int i = 0; i < maxQuests; ++i)
            {
                int index              = i;
                UCE_UI_QuestSlot slot  = content.GetChild(index).GetComponent <UCE_UI_QuestSlot>();
                UCE_Quest        quest = activeQuests[index];

                // -- check cache
                if (Time.time > cacheTimer[index])
                {
                    // =======================================================================

                    // -- check gathered items
                    int[] gathered = player.checkGatheredItems(quest);

                    // -- check explored areas
                    int explored = 0;
#if _iMMOEXPLORATION
                    foreach (UCE_Area_Exploration area in quest.exploreTarget)
                    {
                        if (player.UCE_HasExploredArea(area))
                        {
                            explored++;
                        }
                    }
#endif

                    // -- check faction requirement
                    bool factionRequirementsMet = true;
#if _iMMOFACTIONS
                    factionRequirementsMet = player.UCE_CheckFactionRating(quest.factionRequirement);
#endif

                    // =======================================================================

                    // name button
                    GameObject descriptionPanel = slot.descriptionText.gameObject;
                    string     prefix           = descriptionPanel.activeSelf ? hidePrefix : expandPrefix;
                    slot.nameButton.GetComponentInChildren <Text>().text = prefix + quest.name;
                    slot.nameButton.onClick.SetListener(() =>
                    {
                        descriptionPanel.SetActive(!descriptionPanel.activeSelf);
                    });

                    if (quest.IsFulfilled(gathered, explored, factionRequirementsMet))
                    {
                        slot.nameButton.GetComponent <Image>().color = fulfilledQuestColor;
                    }
                    else
                    {
                        slot.nameButton.GetComponent <Image>().color = inprogressQuestColor;
                    }

                    // -- cancel button
                    slot.cancelButton.gameObject.SetActive(false);

                    // -- update cache
                    cacheTooltip[index] = quest.TrackerTip(gathered, explored, factionRequirementsMet, player.level);
                    cacheTimer[index]   = Time.time + cacheInterval;

                    // -- update description
                    slot.descriptionText.text = cacheTooltip[index];
                }
            }
        }
    }
    // -----------------------------------------------------------------------------------
    // Update
    // -----------------------------------------------------------------------------------
    private void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        // hotkey (not while typing in chat, etc.)
        if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
        {
            panel.SetActive(!panel.activeSelf);
        }

        if (panel.activeSelf)
        {
            List <UCE_Quest> activeQuests = new List <UCE_Quest>();

            if (showActiveQuests)
            {
                activeQuests = player.UCE_quests.Where(q => !q.completed || (q.repeatable > 0 && !q.completedAgain)).ToList();
            }
            else
            {
                activeQuests = player.UCE_quests.Where(q => q.completed).ToList();
            }

            if (cacheTimer == null || cacheTimer.Length != activeQuests.Count)
            {
                cacheTooltip = new string[player.UCE_quests.Count];
                cacheTimer   = new float[player.UCE_quests.Count];
            }

            UIUtils.BalancePrefabs(slotPrefab.gameObject, activeQuests.Count, content);

            // -- refresh all
            for (int i = 0; i < activeQuests.Count; ++i)
            {
                int index              = i;
                UCE_UI_QuestSlot slot  = content.GetChild(index).GetComponent <UCE_UI_QuestSlot>();
                UCE_Quest        quest = activeQuests[index];

                // -- check cache
                if (Time.time > cacheTimer[index])
                {
                    // =======================================================================

                    // -- check gathered items
                    int[] gathered = player.checkGatheredItems(quest);

                    // -- check explored areas
                    int explored = 0;
#if _iMMOEXPLORATION
                    foreach (UCE_Area_Exploration area in quest.exploreTarget)
                    {
                        if (player.UCE_HasExploredArea(area))
                        {
                            explored++;
                        }
                    }
#endif

                    // -- check faction requirement
                    bool factionRequirementsMet = true;
#if _iMMOFACTIONS
                    factionRequirementsMet = player.UCE_CheckFactionRating(quest.factionRequirement);
#endif

                    // =======================================================================

                    // name button
                    GameObject descriptionPanel = slot.descriptionText.gameObject;
                    string     prefix           = descriptionPanel.activeSelf ? hidePrefix : expandPrefix;
                    slot.nameButton.GetComponentInChildren <Text>().text = prefix + quest.name;

                    if (showActiveQuests)
                    {
                        if (quest.IsFulfilled(gathered, explored, factionRequirementsMet))
                        {
                            slot.nameButton.GetComponent <Image>().color = fulfilledQuestColor;
                        }
                        else
                        {
                            slot.nameButton.GetComponent <Image>().color = inprogressQuestColor;
                        }
                    }
                    else
                    {
                        slot.nameButton.GetComponent <Image>().color = fulfilledQuestColor;
                    }

                    slot.nameButton.onClick.SetListener(() =>
                    {
                        descriptionPanel.SetActive(!descriptionPanel.activeSelf);
                    });

                    // -- cancel button
                    if (showActiveQuests)
                    {
                        slot.cancelButton.gameObject.SetActive(true);
                        slot.cancelButton.onClick.SetListener(() =>
                        {
                            cancelQuestPanel.Show(quest.name);
                        });
                    }
                    else
                    {
                        slot.cancelButton.gameObject.SetActive(false);
                    }

                    // -- update cache
                    cacheTooltip[index] = quest.ToolTip(gathered, explored, factionRequirementsMet);
                    cacheTimer[index]   = Time.time + cacheInterval;

                    // -- update description
                    slot.descriptionText.text = cacheTooltip[index];
                }
            }
        }
    }
Ejemplo n.º 17
0
    private void CharacterLoad_UCE_Quest(Player player)
    {
#if _MYSQL && _SERVER
        List <List <object> > table = ExecuteReaderMySql("SELECT name, killed, gathered, harvested, visited, crafted, looted, completed, completedAgain, lastCompleted, counter FROM character_UCE_quests WHERE `character`=@character",
                                                         new MySqlParameter("@character", player.name));
        foreach (List <object> row in table)
        {
            string questName = (string)row[0];
            UCE_ScriptableQuest questData;
            if (UCE_ScriptableQuest.dict.TryGetValue(questName.GetDeterministicHashCode(), out questData))
            {
                UCE_Quest quest = new UCE_Quest(questData);

                quest.killedTarget    = UCE_Tools.IntStringToArray((string)row[1]);
                quest.gatheredTarget  = UCE_Tools.IntStringToArray((string)row[2]);
                quest.harvestedTarget = UCE_Tools.IntStringToArray((string)row[3]);
                quest.visitedTarget   = UCE_Tools.IntStringToArray((string)row[4]);
                quest.craftedTarget   = UCE_Tools.IntStringToArray((string)row[5]);
                quest.lootedTarget    = UCE_Tools.IntStringToArray((string)row[6]);

                foreach (int i in quest.visitedTarget)
                {
                    if (i != 0)
                    {
                        quest.visitedCount++;
                    }
                }

                quest.completed      = ((int)row[7]) != 0;    // sqlite has no bool
                quest.completedAgain = ((int)row[8]) != 0;    // sqlite has no bool
                quest.lastCompleted  = (string)row[9];
                quest.counter        = (int)row[10];
                player.UCE_quests.Add(quest);
            }
        }
#elif _SQLITE && _SERVER
        var table = connection.Query <character_UCE_quests>("SELECT name, pvped, killed, gathered, harvested, visited, crafted, looted, completed, completedAgain, lastCompleted, counter FROM character_UCE_quests WHERE character=?", player.name);
        foreach (var row in table)
        {
            string questName = row.name;
            UCE_ScriptableQuest questData;
            if (UCE_ScriptableQuest.dict.TryGetValue(questName.GetDeterministicHashCode(), out questData))
            {
                UCE_Quest quest = new UCE_Quest(questData);

                quest.pvpedTarget     = UCE_Tools.IntStringToArray(row.pvped);
                quest.killedTarget    = UCE_Tools.IntStringToArray(row.killed);
                quest.gatheredTarget  = UCE_Tools.IntStringToArray(row.gathered);
                quest.harvestedTarget = UCE_Tools.IntStringToArray(row.harvested);
                quest.visitedTarget   = UCE_Tools.IntStringToArray(row.visited);
                quest.craftedTarget   = UCE_Tools.IntStringToArray(row.crafted);
                quest.lootedTarget    = UCE_Tools.IntStringToArray(row.looted);

                foreach (int i in quest.visitedTarget)
                {
                    if (i != 0)
                    {
                        quest.visitedCount++;
                    }
                }

                quest.completed      = row.completed;
                quest.completedAgain = row.completedAgain;
                quest.lastCompleted  = row.lastCompleted;
                quest.counter        = row.counter;
                player.UCE_quests.Add(quest);
            }
        }
#endif
    }
    // -----------------------------------------------------------------------------------
    // Update
    // -----------------------------------------------------------------------------------
    private void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        if (player.target != null && player.target is Npc &&
            Utils.ClosestDistance(player.collider, player.target.collider) <= player.interactionRange)
        {
            Npc npc = (Npc)player.target;

            List <UCE_ScriptableQuest> questsAvailable = npc.UCE_QuestsVisibleFor(player);

            UIUtils.BalancePrefabs(slotPrefab.gameObject, questsAvailable.Count, content);

            // refresh all
            for (int i = 0; i < questsAvailable.Count; ++i)
            {
                UCE_UI_NpcQuestSlot slot = content.GetChild(i).GetComponent <UCE_UI_NpcQuestSlot>();

                // find quest index in original npc quest list (unfiltered)
                int npcIndex = Array.FindIndex(npc.UCE_quests, q => q.name == questsAvailable[i].name);

                // find quest index in player quest list
                int questIndex = player.UCE_GetQuestIndexByName(npc.UCE_quests[npcIndex].name);

                if (questIndex != -1)
                {
                    UCE_Quest quest = player.UCE_quests[questIndex];

                    // -- quest must be acceptable or complete-able to show
                    if (player.UCE_CanRestartQuest(quest.data) || player.UCE_CanAcceptQuest(quest.data) || player.UCE_CanCompleteQuest(quest.name))
                    {
                        ScriptableItem reward = null;
                        int            amount = 0;
                        if (npc.UCE_quests[npcIndex].questRewards.Length > 0 &&
                            npc.UCE_quests[npcIndex].questRewards[0].rewardItem.Length > 0)
                        {
                            reward = npc.UCE_quests[npcIndex].questRewards[0].rewardItem[0].item;
                            amount = npc.UCE_quests[npcIndex].questRewards[0].rewardItem[0].amount;
                        }

                        int gathered = 0;
                        foreach (UCE_gatherTarget gatherTarget in npc.UCE_quests[npcIndex].gatherTarget)
                        {
                            gathered += player.InventoryCount(new Item(gatherTarget.target));
                        }

                        // -- check explored areas
                        int explored = 0;
#if _iMMOEXPLORATION
                        foreach (UCE_Area_Exploration area in quest.exploreTarget)
                        {
                            if (player.UCE_HasExploredArea(area))
                            {
                                explored++;
                            }
                        }
#endif

                        // -- check faction requirement
                        bool factionRequirementsMet = true;
#if _iMMOFACTIONS
                        factionRequirementsMet = player.UCE_CheckFactionRating(quest.factionRequirement);
#endif
                        // -- check has space
                        bool hasSpace = player.getHasEnoughSpace(quest);

                        // -- set gameobject active
                        slot.gameObject.SetActive(true);

                        // -- name button
                        GameObject descriptionText = slot.descriptionText.gameObject;
                        string     prefix          = descriptionText.activeSelf ? hidePrefix : expandPrefix;

                        slot.nameButton.GetComponentInChildren <Text>().text = prefix + quest.name;
                        slot.nameButton.onClick.SetListener(() =>
                        {
                            descriptionText.SetActive(!descriptionText.activeSelf);
                        });

                        // description + not enough space warning (if needed)
                        slot.descriptionText.text = quest.ToolTip(player.checkGatheredItems(quest), explored, factionRequirementsMet);
                        if (!hasSpace)
                        {
                            slot.descriptionText.text += "\n<color=red>" + notEnoughSpace + "</color>";
                        }

                        if (player.UCE_CanAcceptQuest(quest.data))
                        {
                            // repeatable quest
                            slot.actionButton.interactable = true;
                            slot.actionButton.GetComponentInChildren <Text>().text = acceptButton;
                            slot.actionButton.onClick.SetListener(() =>
                            {
                                player.Cmd_UCE_AcceptQuest(npcIndex);
                            });
                        }
                        else
                        {
                            slot.actionButton.interactable = player.UCE_CanCompleteQuest(quest.name) && hasSpace;
                            slot.actionButton.GetComponentInChildren <Text>().text = completeButton;
                            slot.actionButton.onClick.SetListener(() =>
                            {
                                player.Cmd_UCE_CompleteQuest(npcIndex);
                                panel.SetActive(false);
                            });
                        }
                    }
                    else
                    {
                        // -- deactivate slot
                        slot.gameObject.SetActive(false);
                    }
                }
                else
                {
                    UCE_Quest quest = new UCE_Quest(npc.UCE_quests[npcIndex]);

                    // -- set gameobject active
                    slot.gameObject.SetActive(true);

                    // -- name button
                    GameObject descriptionText = slot.descriptionText.gameObject;
                    string     prefix          = descriptionText.activeSelf ? hidePrefix : expandPrefix;
                    slot.nameButton.GetComponentInChildren <Text>().text = prefix + quest.name;
                    slot.nameButton.onClick.SetListener(() =>
                    {
                        descriptionText.SetActive(!descriptionText.activeSelf);
                    });

                    // -- new quest
                    slot.descriptionText.text      = quest.ToolTip(player.checkGatheredItems(quest));
                    slot.actionButton.interactable = true;
                    slot.actionButton.GetComponentInChildren <Text>().text = acceptButton;
                    slot.actionButton.onClick.SetListener(() =>
                    {
                        player.Cmd_UCE_AcceptQuest(npcIndex);
                    });
                }
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
    // -----------------------------------------------------------------------------------
    // UCE_FinishQuest
    // @Server
    // -----------------------------------------------------------------------------------
    protected void UCE_FinishQuest(int index)
    {
        if (index != -1)
        {
            UCE_Quest quest = UCE_quests[index];

            if (UCE_CanCompleteQuest(quest.name))
            {
                // -- remove accept items (optional)
                if (quest.removeAtCompletion && quest.acceptItems.Length > 0)
                {
                    foreach (UCE_rewardItem rewardItem in quest.acceptItems)
                    {
                        InventoryRemove(new Item(rewardItem.item), rewardItem.amount);
                    }
                }

                // -- remove gathered items
                if (!quest.DontDestroyGathered)
                {
                    foreach (UCE_gatherTarget gatherTarget in quest.gatherTarget)
                    {
                        InventoryRemove(new Item(gatherTarget.target), gatherTarget.amount);
                    }
                }

                // -- determine the correct reward
                if (quest.questRewards.Length > 0)
                {
                    UCE_QuestReward reward = getQuestReward(quest);

                    // -- gain basic rewards
                    gold       += reward.rewardGold;
                    experience += reward.rewardExperience;
                    coins      += reward.rewardCoins;

                    // -- reward items
                    if (reward.rewardItem.Length > 0)
                    {
                        foreach (UCE_rewardItem rewardItem in reward.rewardItem)
                        {
                            InventoryAdd(new Item(rewardItem.item), rewardItem.amount);
                        }
                    }

                    // -- unlock travelroutes
#if _iMMOTRAVEL
                    foreach (UCE_Unlockroute route in reward.rewardUnlockroutes)
                    {
                        UCE_UnlockTravelroute(route);
                    }
#endif

                    // -- reward honor currency
#if _iMMOHONORSHOP
                    foreach (UCE_HonorShopCurrencyCost currency in reward.honorCurrency)
                    {
                        UCE_AddHonorCurrency(currency.honorCurrency, currency.amount);
                    }
#endif

                    // -- apply realm change
#if _iMMOPVP
                    UCE_setRealm(reward.changeRealm, reward.changeAlliedRealm);
#endif
                }

                // -- apply faction modifiers
#if _iMMOFACTIONS
                foreach (UCE_FactionModifier factionModifier in quest.factionModifiers)
                {
                    UCE_AddFactionRating(factionModifier.faction, factionModifier.amount);
                }
#endif

                // -- apply world events
#if _iMMOWORLDEVENTS
                if (quest.worldEvent != null)
                {
                    UCE_ModifyWorldEventCount(quest.worldEvent, quest.worldEventModifier);
                }
#endif

                // -- complete quest
                quest.completed = true;
                quest.counter++;

                if (quest.repeatable > 0)
                {
                    quest.resetQuest();
                    quest.completedAgain = true;
                    quest.lastCompleted  = DateTime.UtcNow.ToString("s");
                }

                UCE_quests[index] = quest;
            }
        }
    }