Exemplo n.º 1
0
 public void CmdAccept(int npcQuestIndex)
 {
     // validate
     // use collider point(s) to also work with big entities
     if (player.state == "IDLE" &&
         player.target != null &&
         player.target.health.current > 0 &&
         player.target is Npc npc &&
         0 <= npcQuestIndex && npcQuestIndex < npc.quests.quests.Length &&
         Utils.ClosestDistance(player, npc) <= player.interactionRange)
     {
         ScriptableQuestOffer npcQuest = npc.quests.quests[npcQuestIndex];
         if (npcQuest.acceptHere && CanAccept(npcQuest.quest))
         {
             quests.Add(new Quest(npcQuest.quest));
         }
     }
 }
Exemplo n.º 2
0
    public void CmdComplete(int npcQuestIndex)
    {
        // validate
        // use collider point(s) to also work with big entities
        if (player.state == "IDLE" &&
            player.target != null &&
            player.target.health.current > 0 &&
            player.target is Npc npc &&
            0 <= npcQuestIndex && npcQuestIndex < npc.quests.quests.Length &&
            Utils.ClosestDistance(player, npc) <= player.interactionRange)
        {
            ScriptableQuestOffer npcQuest = npc.quests.quests[npcQuestIndex];
            if (npcQuest.completeHere)
            {
                int index = GetIndexByName(npcQuest.quest.name);
                if (index != -1)
                {
                    // can complete it? (also checks inventory space for reward, if any)
                    Quest quest = quests[index];
                    if (CanComplete(quest.name))
                    {
                        // call quest.OnCompleted to remove quest items from
                        // inventory, etc.
                        quest.OnCompleted(player);

                        // gain rewards
                        player.gold += quest.rewardGold;
                        player.experience.current += quest.rewardExperience;
                        if (quest.rewardItem != null)
                        {
                            inventory.Add(new Item(quest.rewardItem), 1);
                        }

                        // complete quest
                        quest.completed = true;
                        quests[index]   = quest;
                    }
                }
            }
        }
    }