public void StartQuest()
    {
        //Mark quest as active
        State = QuestState.ACTIVE;

        //This is the first time starting the quest
        if (_completed.Count == 0)
        {
            //Add stage 0 quest to _active
            QuestObjective stage0 = new QuestObjective(0.0, true, "", "NO", null, "OR",
                                                       new List <object> {
                true
            }, true);
            _active.Add(stage0);
            _databaseManager.QuestUpdateObjective(ID, 0, 'i', 'a');
        }
        //This is a repeat quest
        else
        {
            //Move all quest objectives to _inactive
            _inactive.AddRange(_active);
            _inactive.AddRange(_completed);

            //Reset fallback objectives as well
            _inactiveFallback.AddRange(_activeFallback);

            //Clear the active and completed lists of objectives db side
            _databaseManager.QuestClearObjectives(ID);

            //Find stage 0 in _inactive and activate it
            QuestObjective stage0 = null;
            foreach (QuestObjective qo in _inactive)
            {
                if (qo.ID == 0.0)
                {
                    stage0 = qo;
                    break;
                }
            }
            if (stage0 == null)
            {
                //Add stage 0 quest to _active
                stage0 = new QuestObjective(0.0, true, "", "NO", null, "OR",
                                            new List <object> {
                    true
                }, true);
                _active.Add(stage0);
                _databaseManager.QuestUpdateObjective(ID, 0, 'i', 'a');
            }

            ActivateObjective(stage0);
        }

        //Notify the player that the quest has started
        _messageController.EnqueueMessage("Starting quest: " + Name);

        //Start the quest
        UpdateQuest(null);
    }
    public void ProcessBonusCode(string code)
    {
        //Get bonus from code. If the function returns null, the code wasn't found
        List <string> rewards = _networkManager.BonusGetBonus(code);

        if (rewards == null)
        {
            return;
        }
        string bonusCodeDetails = null;

        switch (rewards[0])
        {
        //int id, int count
        case "ITEM":
        {
            int id    = int.Parse(rewards[1]);
            int count = int.Parse(rewards[2]);
            _inventory.QueueItemForAddition(id, count);
            if (count == 1)
            {
                bonusCodeDetails = "Item received!";
            }
            else
            {
                bonusCodeDetails = "Items received!";
            }
            break;
        }

        //int count
        case "SKILLPOINTS":
        {
            int count = int.Parse(rewards[1]);
            _stats.AddSkillPoints(count);
            bonusCodeDetails = count.ToString() + " skill points received!";
            break;
        }

        //int count
        case "STATPOINTS":
        {
            int count = int.Parse(rewards[1]);
            _stats.AddStatPoints(count);
            bonusCodeDetails = count.ToString() + " stat points received!";
            break;
        }
        }
        //Save that code has been redeemed
        _networkManager.BonusCodeActivate(code);
        //Lastly, notify the player that the bonus code has been redeemed
        MessageOverlayController messageController = GameObject.FindGameObjectWithTag("MessageOverlay").GetComponent <MessageOverlayController>();

        messageController.EnqueueMessage("Bonus code redeemed!");
        messageController.EnqueueMessage(bonusCodeDetails);
    }
Exemplo n.º 3
0
    private IEnumerator TestWalk()
    {
        Debug.Log("Start");
        npc.Move(1, 0, 1);
        yield return(new WaitForSeconds(2));

        messageController.EnqueueMessage("Hello world!");
        //npc.Speak(null, null);
        npc.Move(1, 1, 1);
        yield return(new WaitForSeconds(2));

        npc.Move(0, 1, 1);
        yield return(new WaitForSeconds(2));

        messageController.EnqueueMessage("How are you today?");
        npc.Move(-1, 1, 1);
        yield return(new WaitForSeconds(2));

        npc.Move(-1, 0, 1);
        yield return(new WaitForSeconds(2));

        npc.Move(-1, -1, 1);
        yield return(new WaitForSeconds(2));

        messageController.EnqueueMessage("Leave me alone! :(");
        npc.Move(0, -1, 1);
        yield return(new WaitForSeconds(2));

        npc.Move(1, -1, 1);
        //npc.Speak(null, null);
        yield return(new WaitForSeconds(2));

        npc.Face(0);
        yield return(new WaitForSeconds(1));

        Debug.Log("Done");
    }
 //Quality player up
 public void LevelUp()
 {
     //Increase level by 1
     PlayerLevel++;
     //Add two skill point
     AddSkillPoints(2);
     //Add four stat points
     AddStatPoints(4);
     //Save all this
     _network.DBGainLevel();
     _network.UpdatePlayerStat("Level", PlayerLevel.ToString());
     //Notify user
     if (_messageOverlay == null)
     {
         _messageOverlay = GameObject.FindGameObjectWithTag("MessageOverlay").GetComponent <MessageOverlayController>();
     }
     _messageOverlay.EnqueueMessage("Level up!");
 }
Exemplo n.º 5
0
    public void UpdateAchievements(List <object> worldEvent)
    {
        //Get the achievement stat that matches this event
        AchievementStat stat   = null;
        GameAction?     action = worldEvent[0] as GameAction?;

        if (action == null)
        {
            return;                     //Just in case
        }
        foreach (AchievementStat s in _achievementStats)
        {
            if (action == s.Stat)
            {
                stat = s;
                break;
            }
        }
        //If nothing matches the event, return
        if (stat == null)
        {
            return;
        }

        //Update this stat's value, depending on the message type
        switch (action)
        {
        //Format: <ACTION> <ID> <QUANTITY>. We want quantity
        case GameAction.CRAFTED:
        case GameAction.CONSUMED:
        case GameAction.DISCARDED:
        case GameAction.DROPPED:                //Not implemented
        case GameAction.LOOTED:                 //Not implemented
        case GameAction.NPC_GIVE:
        case GameAction.NPC_RECEIVE:
        case GameAction.PICKED_UP:
        case GameAction.QUEST_CONSUMED:     //Not implemented
        case GameAction.TRADE_GIVE:         //Not implemented
        case GameAction.TRADE_RECEIVED:     //Not implemented
            if (worldEvent[2] is int)       //Just in case
            {
                stat.AddToValue((int)worldEvent[2]);
            }
            break;

        //Format: <ACTION>. Just increment stat by one
        case GameAction.ATTACK_MAGIC:
        case GameAction.ATTACK_MELEE:
        case GameAction.ATTACK_RANGED:
        case GameAction.ATTACK_HEAL:
        case GameAction.MONSTER_KILLED:
        case GameAction.MOUSE_CLICK:
        case GameAction.SECRET_AREA:
        default:
            stat.AddToValue(1);
            break;
            //Many action types are not included - these only send strings and thus can't be used here
        }
        //Save this update on the server
        _networkManager.UpdateAchievementStat(stat.ID, stat.Value);

        //Update all achievements that subscribe to this stat
        foreach (Achievement a in stat.Subscribers)
        {
            //Ignore completed achievements
            if (a.IsCompleted())
            {
                continue;
            }

            //If this latest stat update completed the achievement, notify the user and save this to the server
            if (a.JustCompleted())
            {
                //Notify user
                if (_messageOverlayController == null)
                {
                    _messageOverlayController = GameObject.FindGameObjectWithTag("MessageOverlay").GetComponent <MessageOverlayController>();
                }
                _messageOverlayController.EnqueueMessage("Achievement \"" + a.Name + "\" completed!");
                //Save this to the server
                _networkManager.UpdateAchievement(a.ID, a.State);

                //Check for milestone completion
                int completedInGroup = a.Group.NumberCompleted();
                foreach (AchievementMilestone m in a.Group.Milestones)
                {
                    //Skip completed milestones
                    if (m.IsCompleted())
                    {
                        continue;
                    }
                    //If milestone has been completed, notify user and save to server
                    if (m.Required <= completedInGroup)
                    {
                        m.Complete();
                        //Notify user
                        _messageOverlayController.EnqueueMessage("\"" + a.Group.Name + "\" milestone completed!");
                        //Save to server
                        _networkManager.UpdateMilestone(m.ID, m.State);
                    }
                }
            }

            //Lastly, set that the achievement group has been modified
            a.Group.AnyChanges = true;
        }
    }