Ejemplo n.º 1
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
    }
Ejemplo n.º 2
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;
                }
            }
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Run if Quest failed
    /// </summary>
    /// <param name="player">The player failing the quest</param>
    public virtual void OnFail(CQPlayerObject player)
    {
        EventInfoHolder tmpE = new EventInfoHolder();

        tmpE.quest  = this;
        tmpE.player = player;
        QuestHandler.TriggerEvent("QuestFailed", tmpE); //Sends out the QuestFailed event

        QuestHandler.Instance.availableQuests[player].Remove(this);
        playersUnCompleted.Remove(player);
        ResetCriterias(player);

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

        //TODO: Delete, if all players has failed it, and they are not allowed to try again. (OneTry == true) (List of players who failed?)

        tmpE.player = player;
        tmpE.quest  = this;
        QuestHandler.TriggerEvent("UpdateQuestTracker", tmpE); //Sends out the UpdateQuestTracker event
    }
Ejemplo n.º 4
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);
                }
            }
        }
    }
Ejemplo n.º 5
0
 /// <summary>
 /// Starts the progress of a quest pop up.
 /// </summary>
 /// <param name="player">The player recieving the quest pop up</param>
 public void StartQuestPopUp(CQPlayerObject player, Quest quest)
 {
     if (quest)
     {
         if (quest.pickUpAble == true)
         {
             if (FindObjectOfType <QuestUI>())
             {
                 EventInfoHolder tmpE = new EventInfoHolder();
                 tmpE.player     = player;
                 tmpE.quest      = quest;
                 tmpE.questGiver = this;
                 QuestHandler.TriggerEvent("StartQuestPopUp", tmpE); //Sends out the StartQuestPopUp event
             }
             else
             {
                 QuestHandler.Instance.QuestsDiscovered(quest, player);
             }
         }
     }
     else
     {
         Debug.LogWarning("Quest is null in: " + this.gameObject + " Cannot give quest");
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Starts the time and spawn on this criteria
 /// </summary>
 public virtual void StartCriteria(CQPlayerObject player)
 {
     if (timed)
     {
         if (!remainingTimer.ContainsKey(player))
         {
             remainingTimer.Add(player, time);
         }
         else
         {
             remainingTimer[player] = time;
         }
     }
     if (quest.startSpawningOnDiscover)
     {
         foreach (SpawnZone zone in spawnZones)
         {
             if (zone != null)
             {
                 zone.Spawn = true;
                 quest.SpawnQuestObjects(criteriaObject, zone.initialSpawnAmount, zone);
             }
         }
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Use this for initialization
 /// </summary>
 private void Start()
 {
     cQPlayer              = GetComponent <CQPlayerObject>();
     _animator             = GetComponent <Animator>();
     m_characterController = GetComponent <CharacterController>();
     m_Camera              = Camera.main;
     m_MouseLook.Init(transform, m_Camera.transform);
     Cursor.visible = false;
 }
Ejemplo n.º 8
0
    /// <summary>
    /// Is run when this criteria fails
    /// </summary>
    public virtual void Fail(CQPlayerObject player)
    {
        EventInfoHolder tmpE = new EventInfoHolder();

        tmpE.criteria = this;
        tmpE.player   = player;
        QuestHandler.TriggerEvent("CriteriaFailed", tmpE); //Sends out the CriteriaFailed event
        quest.CriteriaFailed(player, this);
        remainingTimer.Remove(player);
    }
Ejemplo n.º 9
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
     }
 }
Ejemplo n.º 10
0
    /// <summary>
    /// Starts all the criterias spawn
    /// </summary>
    /// <param name="player">The player starting the spawn</param>
    public virtual void StartSpawning(CQPlayerObject player)
    {
        List <Criteria> tmpCriteria = new List <Criteria>(criterias);

        tmpCriteria.AddRange(optionalCriterias);
        foreach (Criteria c in tmpCriteria)
        {
            if (c.Level == 0)
            {
                c.StartCriteria(player);
            }
        }
    }
Ejemplo n.º 11
0
 /// <summary>
 /// Adds a player to the players list
 /// </summary>
 /// <param name="p">The player to be added</param>
 public void AddPlayer(CQPlayerObject p)
 {
     players.Add(p);
     availableQuests.Add(p, new List <Quest>()); //Add a list to all players
     foreach (Quest quest in allQuests)
     {
         if (quest.startAvailability == true)
         {
             if (!availableQuests[p].Contains(quest))
             {
                 QuestsDiscovered(quest, p);
             }
         }
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Unlocks the quest if no quests are left uncompleted.
 /// </summary>
 /// <param name="quest">The quest this quest removes from its unCompletedQuests</param>
 /// <param name="player">The player unlocking the quest</param>
 public virtual void UnlockQuest(Quest quest, CQPlayerObject player)
 {
     unCompletedQuests.Remove(quest);
     if (unCompletedQuests.Count <= 0)
     {
         pickUpAble = true;
         if (startAvailability == true)
         {
             QuestHandler.Instance.QuestsDiscovered(this, player);
         }
         if (Vector3.Distance(player.transform.position, questGivers[0].transform.position) < questGivers[0].radius)
         {
             questGivers[0].StartQuestPopUp(player, this);
         }
     }
 }
Ejemplo n.º 13
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);
    }
Ejemplo n.º 14
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);
         }
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Resest the criterias for this quest
 /// </summary>
 /// <param name="player">The player to reset the criterias for</param>
 public virtual void ResetCriterias(CQPlayerObject player)
 {
     if (unCompletedCriterias.ContainsKey(player) != true || completedCriterias.ContainsKey(player) != true || completedOptionalCriterias.ContainsKey(player) != true)
     {
         AddPlayerToCriterias();
     }
     unCompletedCriterias[player].Clear();
     foreach (Criteria c in criterias)
     {
         c.playerProgression[player] = 0;
         unCompletedCriterias[player].Add(c);
     }
     foreach (Criteria c in optionalCriterias)
     {
         c.playerProgression[player] = 0;
         unCompletedCriterias[player].Add(c);
     }
     completedCriterias[player].Clear();
     completedOptionalCriterias[player].Clear();
 }
Ejemplo n.º 16
0
 /// <summary>
 /// If a player collides with the QuestGiver, the questgiver will give the quest to the player by instantiating it.
 /// </summary>
 /// <param name="coll">The collider colliding with the questGiver</param>
 public void OnTriggerEnter(Collider coll)
 {
     if (radius > 0 && walkIntoStartQuest == true)
     {
         CQPlayerObject player = coll.GetComponent <CQPlayerObject>();
         if (player == null)
         {
             player = coll.GetComponentInParent <CQPlayerObject>();
         }
         if (player != null)
         {
             foreach (Quest quest in quests)
             {
                 if (quest != null && quest.pickUpAble == true)
                 {
                     StartQuestPopUp(player, quest);
                 }
             }
         }
     }
 }
Ejemplo n.º 17
0
    /*** Public Methods ***/

    /// <summary>
    /// Tells the quest system that a quest has been discovered by a player
    /// </summary>
    /// <param name="quest">The quest discovered</param>
    /// <param name="player">The player who discovered the quest</param>
    public void QuestsDiscovered(Quest quest, CQPlayerObject player)
    {
        if (!availableQuests[player].Contains(quest))
        {
            availableQuests[player].Add(quest);
            quest.playersUnCompleted.Add(player);
            if (quest.startSpawningOnDiscover)
            {
                quest.StartSpawning(player);
            }
            if (!allQuests.Contains(quest))
            {
                allQuests.Add(quest);
            }
            quest.ResetCriterias(player);
            if (quest.timed)
            {
                if (!quest.remainingTime.ContainsKey(player))
                {
                    quest.remainingTime.Add(player, quest.time);
                }
                else
                {
                    quest.remainingTime[player] = quest.time;
                }
            }
            quest.StartCriterias();

            EventInfoHolder tmpE = new EventInfoHolder();
            tmpE.player = player;
            tmpE.quest  = quest;
            TriggerEvent("UpdateQuestTracker", tmpE); //Sends out the UpdateQuestTracker event

            if (quest.autoComplete == true && quest.criterias.Count == 0)
            {
                quest.OnCompletion(player, player.GetComponent <CQExamplePlayer>());
            }
        }
    }
Ejemplo n.º 18
0
    /// <summary>
    /// If a player collides with the QuestGiver, the questgiver will give the quest to the player by instantiating it.
    /// </summary>
    /// <param name="coll">The collider colliding with the questGiver</param>

    void OnTriggerStay(Collider coll)
    {
        questpopup.SetActive(true);
        if (radius > 0 && walkIntoStartQuest == true && Input.GetKeyDown(KeyCode.E))
        {
            CQPlayerObject player = coll.GetComponent<CQPlayerObject>();
            if (player == null)
            {
                player = coll.GetComponentInParent<CQPlayerObject>();
            }
            if (player != null)
            {
                foreach (Quest quest in quests)
                {
                    if (quest != null && quest.pickUpAble == true)
                    {
                        StartQuestPopUp(player, quest);
                    }
                }
            }
        }
    }
Ejemplo n.º 19
0
 /// <summary>
 /// Run this to fail a criteria
 /// </summary>
 /// <param name="critera">The criteria to fail</param>
 /// <param name="player">The player who failed this criteria</param>
 public virtual void CriteriaFailed(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) && activeCriterias[player].Contains(criteria))
     {
         activeCriterias[player].Remove(criteria);
         unCompletedCriterias[player].Remove(criteria);
         if (thresholds[criteria.Level] > activeCriterias[player].Count || thresholds[criteria.Level] == 0)
         {
             OnFail(player);
         }
         EventInfoHolder tmpE = new EventInfoHolder();
         tmpE.quest = this;
         QuestHandler.TriggerEvent("ResetQuestInList", tmpE); //Sends out the ResetQuestInList event
     }
     else if (activeOptionalCriterias[player].Contains(criteria))
     {
         failedOptionalCriterias[player].Add(criteria);
         activeOptionalCriterias[player].Remove(criteria);
     }
 }
Ejemplo n.º 20
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;
                 }
             }
         }
     }
 }
Ejemplo n.º 21
0
    /// <summary>
    ///  Update is called once per frame
    /// </summary>
    public virtual void Update()
    {
        if (constantAvailability)
        {
            foreach (CQPlayerObject p in QuestHandler.Instance.players)
            {
                if (repeatable)
                {
                    if (remainingRepeatableTime.ContainsKey(p))
                    {
                        if (remainingRepeatableTime[p] > 0)
                        {
                            break;
                        }
                    }
                }
                if (!QuestHandler.Instance.availableQuests[p].Contains(this))
                {
                    QuestHandler.Instance.QuestsDiscovered(this, p);
                }
            }
        }

        //Counts down the timer
        if (timed)
        {
            for (int i = playersUnCompleted.Count - 1; i >= 0; i--)
            {
                CQPlayerObject p = playersUnCompleted[i];
                remainingTime[p] -= Time.deltaTime;
                if (remainingTime[p] <= 0)
                {
                    OnFail(p);
                }
            }
        }

        //Counts down the repeaterable timer
        if (repeatable)
        {
            foreach (CQPlayerObject p in playersCompleted)
            {
                if (remainingRepeatableTime.ContainsKey(p))
                {
                    remainingRepeatableTime[p] -= Time.deltaTime;
                    if (remainingRepeatableTime[p] <= 0)
                    {
                        if (!QuestHandler.Instance.availableQuests[p].Contains(this))
                        {
                            if (startAvailability)
                            {
                                QuestHandler.Instance.QuestsDiscovered(this, p);
                            }
                        }
                        break;
                    }
                }
            }
        }

        //Count the spawn timer up, if the timer than exceeds the spawnrate it spawns the Criteria Objects and resets.
        foreach (Criteria criteria in criterias)
        {
            foreach (SpawnZone zone in criteria.spawnZones)
            {
                if (zone != null)
                {
                    zone.spawnRateTimer += Time.deltaTime;
                    if (zone.spawnRateTimer >= zone.spawnRate)
                    {
                        if (zone.Spawn == true)
                        {
                            SpawnQuestObjects(criteria.criteriaObject, zone.spawnAmount, zone);
                        }
                        zone.spawnRateTimer = 0;
                    }
                }
                else
                {
                    criteria.spawnZones.Remove(zone);
                }
            }
        }

        //Does the same as the above, but for optional criterias
        foreach (Criteria criteria in optionalCriterias)
        {
            foreach (SpawnZone zone in criteria.spawnZones)
            {
                if (zone != null)
                {
                    zone.spawnRateTimer += Time.deltaTime;
                    if (zone.spawnRateTimer >= zone.spawnRate)
                    {
                        if (zone.Spawn == true)
                        {
                            SpawnQuestObjects(criteria.criteriaObject, zone.spawnAmount, zone);
                        }
                        zone.spawnRateTimer = 0;
                    }
                }
                else
                {
                    criteria.spawnZones.Remove(zone);
                }
            }
        }
    }
Ejemplo n.º 22
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
            }
        }
    }
Ejemplo n.º 23
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);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Use this for initialization
 /// </summary>
 private void Start()
 {
     cQPlayer = GetComponent <CQPlayerObject>();
 }