Пример #1
0
    /// <summary>
    /// Is run when this criteria is completed
    /// </summary>
    /// <param name="player">The player who completed the criteria</param>
    public virtual void Complete(CQPlayerObject player, CQExamplePlayer unit)
    {
        EventInfoHolder tmpE = new EventInfoHolder();

        tmpE.criteria = this;
        tmpE.player   = player;
        tmpE.unit     = unit;
        QuestHandler.TriggerEvent("CriteriaCompleted", tmpE); //Sends out the CriteriaCompleted event
        if (!dontDespawnObjectsWhenComplete)
        {
            bool despawn = true;
            foreach (CQPlayerObject p in quest.playersUnCompleted)
            {
                if (quest.activeCriterias[p].Contains(this))
                {
                    despawn = false;
                }
            }
            if (despawn == true)
            {
                foreach (SpawnZone zone in spawnZones)
                {
                    zone.DespawnQuestObjects();
                    zone.Spawn = false;
                }
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Runs when this objects trigger colliders with another
    /// </summary>
    /// <param name="other">The other object colliding with this one</param>
    public void OnTriggerEnter(Collider other)
    {
        if (other.GetComponent <Sword>())
        {
            health -= other.GetComponentInParent <CQExamplePlayer>().Damage;
            player  = other.GetComponentInParent <CQPlayerObject>();
            unit    = other.GetComponentInParent <CQExamplePlayer>();

            if (health <= 0)
            { // Checks if this object is out of health, kills it if that is true
                health = 0;
                if (questObject == null)
                {
                    questObject = GetComponent <QuestObject>();
                }
                if (questObject != null)
                {
                    if (questObject.criteria)
                    {
                        questObject.criteria.Remove(this.gameObject);
                        if (QuestHandler.Instance.availableQuests[player].Contains(questObject.criteria.Quest))
                        {
                            questObject.criteria.Progress(player, unit); // Send quest progress result, with the killer
                        }
                    }
                    Destroy(this.gameObject);
                }
            }
        }
    }
Пример #3
0
    /// <summary>
    /// Completes a Criteria.
    /// </summary>
    /// <param name="player">The player who completed it</param>
    /// <param name="criteria">The criteria to complete</param>
    /// <param name="unit">The unit who completed the criteria</param>
    public virtual void CriteriaCompleted(CQExamplePlayer unit, CQPlayerObject player, Criteria criteria)
    {
        if (unCompletedCriterias.ContainsKey(player) != true || completedCriterias.ContainsKey(player) != true || activeCriterias.ContainsKey(player) != true || completedOptionalCriterias.ContainsKey(player) != true)
        {
            AddPlayerToCriterias();
        }
        if (unCompletedCriterias[player].Contains(criteria)) //TODO: Some check if its in activeCriterias aswell?
        {
            ProcessCriteria(unit, player, criteria);
        }
        else if (activeOptionalCriterias[player].Contains(criteria))
        {
            ProcessOptionalCriteria(unit, player, criteria);
        }
        else if (completedCriterias[player].Contains(criteria) || completedOptionalCriterias[player].Contains(criteria))
        {
            //Criteria has already been completed by that player
        }
        else
        {
            Debug.LogWarning(criteria + " not found in any lists in " + this + ". " + criteria + " could not be completed");
        }

        EventInfoHolder tmpE = new EventInfoHolder();

        tmpE.player = player;
        tmpE.quest  = this;
        QuestHandler.TriggerEvent("UpdateQuestTracker", tmpE); //Sends out the UpdateQuestTracker event
    }
Пример #4
0
 /// <summary>
 /// Use this for initialization
 /// </summary>
 private void Start()
 {
     if (player == null)
     {
         player = GetComponentInParent <CQExamplePlayer>();
     }
 }
Пример #5
0
 /// <summary>
 /// Give's the Reward when the player completes the quest.
 /// </summary>
 /// <param name="unit">The unit who completed the quest</param>
 /// <param name="player">The player who completed the quest</param>
 public virtual void GiveReward(CQExamplePlayer unit, CQPlayerObject player, List <Reward> rewards)
 {
     foreach (Reward reward in rewards)
     {
         EventInfoHolder tmpE = new EventInfoHolder();
         tmpE.player = player;
         tmpE.unit   = unit;
         tmpE.quest  = this;
         tmpE.reward = reward;
         QuestHandler.TriggerEvent("GiveReward", tmpE); //Sends out the QuestCompleted event
     }
 }
Пример #6
0
    /// <summary>
    /// Processes an optional criteria
    /// </summary>
    /// <param name="unit">The unit who completed the criteria</param>
    /// <param name="player">The player who completed the criteria</param>
    /// <param name="criteria">The criteria which is completed</param>
    public virtual void ProcessOptionalCriteria(CQExamplePlayer unit, CQPlayerObject player, Criteria criteria)
    {
        activeOptionalCriterias[player].Remove(criteria);
        completedOptionalCriterias[player].Add(criteria);
        if (CustomQuestSettings.SettingsHolder.optionalCriteriaSpecificRewards && criteria.giveRewardsOnCompletion)
        {
            GiveReward(unit, player, criteria.rewards);
        }
        else if (optionalThresholds[criteria.Level] > 0) //Ignores thresholds if its value is 0 or lower
        {                                                //Threshold logic
            int thresholdCounter = 0;
            foreach (Criteria c in completedOptionalCriterias[player])
            {
                if (c.Level == criteria.Level)
                {
                    thresholdCounter += 1;
                }
            }
            if (optionalThresholds[criteria.Level] <= thresholdCounter)
            {     //Threshold reached
                for (int i = 0; i < activeOptionalCriterias[player].Count; i++)
                { //Removing the rest of the activeCriterias and uncompleted criterias
                    completedOptionalCriterias[player].Remove(activeOptionalCriterias[player][i]);
                    activeOptionalCriterias[player].Remove(activeOptionalCriterias[player][i]);
                }
                int counter = 0;
                while (activeOptionalCriterias[player].Count <= 0)
                { //Adds the new level of criterias
                    if (!matchOptionalLevels)
                    {
                        foreach (Criteria c in optionalCriterias)
                        {
                            if (c.Level == criteria.Level + counter)
                            {
                                activeOptionalCriterias[player].Add(c);
                                c.StartCriteria(player);
                            }
                        }
                    }
                    counter++;
                }
            }
        }

        criteria.Complete(player, unit);
    }
Пример #7
0
 /// <summary>
 /// Updates the player progress.
 /// </summary>
 /// <param name="player"></param>
 public virtual void Progress(CQPlayerObject player, CQExamplePlayer unit)
 {
     if (playerProgression.ContainsKey(player))
     {
         playerProgression[player] += 1;
         if (playerProgression[player] <= amount)
         {
             EventInfoHolder tmpE = new EventInfoHolder();
             tmpE.player   = player;
             tmpE.unit     = unit;
             tmpE.criteria = this;
             QuestHandler.TriggerEvent("CriterionProgress", tmpE); //Sends out the CriteriaProgress event
         }
         if (playerProgression[player] >= amount)
         {
             Quest.CriteriaCompleted(unit, player, this);
         }
     }
 }
Пример #8
0
 /// <summary>
 /// When a object collides with this object, it runs some checks to check if the its a player, and if it has completed all the needed criterias. If all that is good, it completed the quest.
 /// </summary>
 /// <param name="coll">The other collider</param>
 public void OnTriggerEnter(Collider coll)
 {
     if (handInByCollision)
     {
         if (coll.GetComponentInParent <CQPlayerObject>())
         {
             CQPlayerObject  CQplayer = coll.GetComponentInParent <CQPlayerObject>();
             CQExamplePlayer player   = coll.GetComponentInParent <CQExamplePlayer>();
             foreach (Quest q in quests)
             {
                 if (q != null)
                 {
                     if (q.handInObjects.Contains(this))
                     {
                         if (q.unCompletedCriterias.ContainsKey(CQplayer) != true || q.completedCriterias.ContainsKey(CQplayer) != true)
                         {
                             q.AddPlayerToCriterias();
                         }
                         if (q.activeCriterias.ContainsKey(CQplayer))
                         {
                             if (q.activeCriterias[CQplayer].Count <= 0)
                             {
                                 q.OnCompletion(CQplayer, player);
                             }
                             else
                             {
                                 for (int i = q.activeCriterias[CQplayer].Count - 1; i >= 0; i--)
                                 {
                                     Criteria c = q.activeCriterias[CQplayer][i];
                                     if (c.type == criteriaType.Deliver)
                                     {
                                         for (int j = player.items.Count - 1; j >= 0; j--)
                                         {
                                             if (player.items.Count > j)
                                             {
                                                 if (player.items[j])
                                                 {
                                                     if (player.items[j].GetComponent <QuestObject>())
                                                     {
                                                         if (player.items[j].GetComponent <QuestObject>().criteria == c)
                                                         {
                                                             if ((player.items[j]))
                                                             {
                                                                 c.Remove(player.items[j].gameObject);
                                                             }
                                                             player.items.RemoveAt(j);
                                                             c.Progress(CQplayer, player);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 if (q.activeCriterias[CQplayer].Count <= 0)
                                 {
                                     q.OnCompletion(CQplayer, player);
                                 }
                             }
                         }
                     }
                 }
                 else
                 {
                     quests.Remove(q);
                     break;
                 }
             }
         }
     }
 }
Пример #9
0
 /// <summary>
 /// Processes a criteria
 /// </summary>
 /// <param name="unit">The unit who completed the criteria</param>
 /// <param name="player">The player who completed the criteria</param>
 /// <param name="criteria">The criteria which is completed</param>
 public virtual void ProcessCriteria(CQExamplePlayer unit, CQPlayerObject player, Criteria criteria)
 {
     unCompletedCriterias[player].Remove(criteria);
     activeCriterias[player].Remove(criteria);
     completedCriterias[player].Add(criteria);
     if (activeCriterias[player].Count <= 0 && unCompletedCriterias[player].Count > 0)
     {
         int counter = 1;
         while (activeCriterias[player].Count <= 0)
         { //Adds the new level of criterias
             foreach (Criteria c in unCompletedCriterias[player])
             {
                 if (c.Level == criteria.Level + counter)
                 {
                     activeCriterias[player].Add(c);
                     c.StartCriteria(player);
                 }
             }
             if (matchOptionalLevels)
             {
                 activeOptionalCriterias[player].Clear();
                 foreach (Criteria c in optionalCriterias)
                 {
                     if (c.Level == criteria.Level + counter)
                     {
                         activeOptionalCriterias[player].Add(c);
                         c.StartCriteria(player);
                     }
                 }
             }
             counter++;
             if (counter > 100)
             {
                 Debug.Log("infinite loop prevented");
                 break;
             }
         }
     }
     else if (thresholds.Count > 0)          //Checks for any threshold level - Prevents errors.
     {
         if (thresholds[criteria.Level] > 0) //Ignores thresholds if its value is 0 or lower
         {                                   //Threshold logic
             int thresholdCounter = 0;
             foreach (Criteria c in completedCriterias[player])
             {
                 if (c.Level == criteria.Level)
                 {
                     thresholdCounter += 1;
                 }
             }
             if (thresholds[criteria.Level] <= thresholdCounter)
             {     //Threshold reached
                 for (int i = 0; i < activeCriterias[player].Count; i++)
                 { //Removing the rest of the activeCriterias and uncompleted criterias
                     unCompletedCriterias[player].Remove(activeCriterias[player][i]);
                     activeCriterias[player].Remove(activeCriterias[player][i]);
                 }
                 int counter = 0;
                 while (activeCriterias[player].Count <= 0)
                 { //Adds the new level of criterias
                     foreach (Criteria c in unCompletedCriterias[player])
                     {
                         if (c.Level == criteria.Level + counter)
                         {
                             activeCriterias[player].Add(c);
                             c.StartCriteria(player);
                         }
                     }
                     if (matchOptionalLevels)
                     {
                         activeOptionalCriterias[player].Clear();
                         foreach (Criteria c in optionalCriterias)
                         {
                             if (c.Level == criteria.Level + counter)
                             {
                                 activeOptionalCriterias[player].Add(c);
                                 c.StartCriteria(player);
                             }
                         }
                     }
                     counter++;
                     if (counter > 100)
                     {
                         Debug.Log("infinite loop prevented");
                         break;
                     }
                 }
             }
         }
     }
     if (activeCriterias[player].Count > 0)
     {
         EventInfoHolder tmpE = new EventInfoHolder();
         tmpE.quest = this;
         QuestHandler.TriggerEvent("ResetQuestInList", tmpE); //Sends out the ResetQuestInList event
     }
     if (autoComplete == true && activeCriterias[player].Count <= 0)
     {
         OnCompletion(player, unit);
     }
     if (CustomQuestSettings.SettingsHolder.criteriaSpecificRewards && criteria.giveRewardsOnCompletion)
     {
         GiveReward(unit, player, criteria.rewards);
     }
     criteria.Complete(player, unit);
 }
Пример #10
0
    /// <summary>
    /// Run if Quest is completed
    /// </summary>
    /// <param name="player">The player completing the quest</param>
    /// <param name="unit">The unit completing the quest</param>
    public virtual void OnCompletion(CQPlayerObject player, CQExamplePlayer unit)
    {
        if (playersUnCompleted.Contains(player))
        {
            EventInfoHolder tmpE = new EventInfoHolder();
            tmpE.player = player;
            tmpE.unit   = unit;
            tmpE.quest  = this;
            QuestHandler.TriggerEvent("QuestCompleted", tmpE); //Sends out the QuestCompleted event

            List <Criteria> allCriterias = new List <Criteria>(criterias);
            allCriterias.AddRange(optionalCriterias);
            foreach (Criteria c in allCriterias)
            {
                if (c.type == criteriaType.Deliver || c.type == criteriaType.Gather)
                {
                    for (int i = unit.items.Count - 1; i >= 0; i--)
                    {
                        if (unit.items[i] != null)
                        {
                            if (unit.items[i].GetComponent <QuestObject>())
                            {
                                if (unit.items[i].GetComponent <QuestObject>().criteria == c)
                                {
                                    c.Remove(unit.items[i].gameObject);
                                    unit.items.RemoveAt(i);
                                }
                            }
                        }
                    }
                }
            }

            //Gives rewards
            GiveReward(unit, player, rewards);                                          //Standard rewards
            if (completedOptionalThreshold <= completedOptionalCriterias[player].Count) //If the player has completed enought optional objectives, gives the player the 'optional' rewards
            {
                GiveReward(unit, player, optionalRewards);                              //optional rewards
            }
            if (CustomQuestSettings.SettingsHolder.criteriaSpecificRewards)
            {
                foreach (Criteria c in completedCriterias[player])
                {
                    if (!c.giveRewardsOnCompletion)
                    {
                        GiveReward(unit, player, c.rewards); //Individual criteria rewards
                    }
                }
            }
            if (CustomQuestSettings.SettingsHolder.optionalCriteriaSpecificRewards)
            {
                foreach (Criteria c in completedOptionalCriterias[player])
                {
                    if (!c.giveRewardsOnCompletion)
                    {
                        GiveReward(unit, player, c.rewards); //Individual optional criteria rewards
                    }
                }
            }

            QuestHandler.Instance.availableQuests[player].Remove(this);
            foreach (Quest quest in questsToUnlock)
            {
                if (quest != null)
                {
                    quest.UnlockQuest(this, player);
                }
            }
            //  QuestHandler.Instance.UpdateQuestTracker();
            if (!playersCompleted.Contains(player))
            {
                playersCompleted.Add(player);
            }
            playersUnCompleted.Remove(player);

            if (noSpawnIfNoPlayer == true)
            {
                if (playersUnCompleted.Count <= 0)
                {
                    List <Criteria> tmpCriteria = new List <Criteria>(criterias);
                    tmpCriteria.AddRange(optionalCriterias);
                    foreach (Criteria criteria in tmpCriteria)
                    {
                        foreach (SpawnZone zone in criteria.spawnZones)
                        {
                            zone.DespawnQuestObjects();
                        }
                    }
                    StopSpawning();
                }
            }

            if (repeatable == false)
            {
                if (dontDelete == false)
                {
                    bool delete = true;
                    if (!singleComplete)
                    {
                        foreach (CQPlayerObject p in QuestHandler.Instance.players)
                        {
                            if (!playersCompleted.Contains(p))
                            {
                                delete = false;
                            }
                        }
                    }
                    if (delete == true)
                    {
                        QuestHandler.Instance.allQuests.Remove(this);
                        List <Criteria> tmpCriteria = new List <Criteria>(criterias);
                        tmpCriteria.AddRange(optionalCriterias);
                        foreach (Criteria criteria in tmpCriteria)
                        {
                            foreach (SpawnZone zone in criteria.spawnZones)
                            {
                                zone.DespawnQuestObjects();
                            }
                        }
                        Destroy(this.gameObject);
                    }
                }
            }
            else
            {
                //Debug.Log(repeatableTime);
                //if (repeatableTime > 0)
                //{
                List <Criteria> tmpCriteria = new List <Criteria>(criterias);
                tmpCriteria.AddRange(optionalCriterias);
                foreach (Criteria criteria in tmpCriteria)
                {
                    if (!criteria.dontDespawnObjectsWhenComplete)
                    {
                        foreach (SpawnZone zone in criteria.spawnZones)
                        {
                            zone.DespawnQuestObjects();
                        }
                    }
                }
                if (!remainingRepeatableTime.ContainsKey(player))
                {
                    remainingRepeatableTime.Add(player, repeatableTime);
                }
                else
                {
                    remainingRepeatableTime[player] = repeatableTime;
                }
                tmpE.quest = this;
                QuestHandler.TriggerEvent("ResetQuestInList", tmpE); //Sends out the ResetQuestInList event
                //}
                tmpE.player = player;
                tmpE.quest  = this;
                QuestHandler.TriggerEvent("UpdateQuestTracker", tmpE); //Sends out the UpdateQuestTracker event
            }
        }
    }