Пример #1
0
    private void LoadAchieveDatas()
    {
        Util.Sqlite.DataReader reader = Database.Execute(Database.Type.UserData,
                                                         "SELECT achieve_name, achieve_type, achieve_step, achieve_count, achieve_goal FROM user_achieve"
                                                         );
        while (true == reader.Read())
        {
            Achieve achieve = new Achieve(
                reader.GetString("achieve_name"),
                reader.GetString("achieve_type"),
                reader.GetInt32("achieve_step"),
                reader.GetInt32("achieve_count"),
                reader.GetInt32("achieve_goal")
                );

            achieves.Add(achieve.type, achieve);
            ProgressManager.Instance.Add(achieve);
        }
    }
Пример #2
0
    public Quest GetAvailableQuest()
    {
        Util.Sqlite.DataReader reader = Database.Execute(Database.Type.MetaData,
                                                         "SELECT quest_id FROM meta_quest ORDER BY RANDOM() LIMIT 1"
                                                         );

        while (true == reader.Read())
        {
            return(Find(reader.GetString("quest_id")));
        }
        return(null);
    }
Пример #3
0
    private void LoadAchieveMetas()
    {
        Dictionary <string, List <Achieve.Meta> > achieve_metas = new Dictionary <string, List <Achieve.Meta> >();

        Util.Sqlite.DataReader reader = Database.Execute(Database.Type.MetaData,
                                                         "SELECT achieve_type, achieve_step, achieve_name, achieve_goal, sprite_path, reward_stat_type, reward_stat_value, description FROM meta_achieve order by achieve_type, achieve_step"
                                                         );
        while (true == reader.Read())
        {
            Achieve.Meta meta = new Achieve.Meta()
            {
                type        = reader.GetString("achieve_type"),
                step        = reader.GetInt32("achieve_step"),
                name        = reader.GetString("achieve_name"),
                goal        = reader.GetInt32("achieve_goal"),
                sprite_path = reader.GetString("sprite_path"),
                description = reader.GetString("description")
            };
            meta.reward_stat = new Stat.Data()
            {
                type = (StatType)reader.GetInt32("reward_stat_type"), value = reader.GetFloat("reward_stat_value")
            };

            if (false == achieve_metas.ContainsKey(meta.type))
            {
                achieve_metas[meta.type] = new List <Achieve.Meta>();
            }

            achieve_metas[meta.type].Add(meta);
        }

        foreach (var itr in achieve_metas)
        {
            if (false == achieves.ContainsKey(itr.Key))
            {
                Achieve achieve = new Achieve(
                    itr.Value[0].name,
                    itr.Key,
                    1,
                    0,
                    itr.Value[0].goal
                    );

                Database.Execute(Database.Type.UserData,
                                 "INSERT INTO user_achieve(achieve_name, achieve_type, achieve_step, achieve_count, achieve_goal) VALUES('" + achieve.name + "','" + achieve.type + "',1,0," + achieve.goal + ")"
                                 );

                achieve.metas = itr.Value;
                achieves.Add(achieve.type, achieve);
                ProgressManager.Instance.Add(achieve);
            }
            else
            {
                if (false == achieves.ContainsKey(itr.Key))
                {
                    Debug.LogError("invalid achievemt type(type:" + itr.Key + ")");
                    continue;
                }

                Achieve achieveData = achieves[itr.Key];
                achieveData.metas = itr.Value;

                if (Achieve.State.Complete == achieveData.state)
                {
                    ProgressManager.Instance.Remove(achieveData);
                }
            }
        }
    }
Пример #4
0
    public Quest Find(string questID)
    {
        Quest quest = null;

        {
            Util.Sqlite.DataReader reader = Database.Execute(Database.Type.MetaData,
                                                             "SELECT quest_id, quest_name, reward_coin, reward_item_id, sprite_path FROM meta_quest WHERE quest_id='" + questID + "'"
                                                             );
            while (true == reader.Read())
            {
                quest                = new Quest();
                quest.quest_id       = reader.GetString("quest_id");
                quest.quest_name     = reader.GetString("quest_name");
                quest.sprite_path    = reader.GetString("sprite_path");
                quest.reward.coin    = reader.GetInt32("reward_coin");
                quest.reward.item_id = reader.GetString("reward_item_id");
            }

            if (null == quest)
            {
                throw new System.Exception("invalid quest(quest_id:" + questID + ")");
            }
        }
        {
            Util.Sqlite.DataReader reader = Database.Execute(Database.Type.MetaData,
                                                             "SELECT quest_step, progress_name, progress_type, progress_key, progress_goal FROM meta_quest_progress WHERE quest_id='" + questID + "' ORDER BY quest_step"
                                                             );
            while (true == reader.Read())
            {
                QuestProgress progress = new QuestProgress();
                progress.name  = reader.GetString("progress_name");
                progress.type  = reader.GetString("progress_type");
                progress.key   = reader.GetString("progress_key");
                progress.goal  = reader.GetInt32("progress_goal");
                progress.quest = quest;
                quest.AddProgress(reader.GetInt32("quest_step"), progress);
            }

            if (0 == quest.progresses.Count)
            {
                throw new System.Exception("quest progress count is 0(quest_id:" + questID + ")");
            }
        }
        {
            Util.Sqlite.DataReader reader = Database.Execute(Database.Type.MetaData,
                                                             "SELECT dialogue_type, dialogue_num, dialogue_text, sprite_path FROM meta_quest_dialogue WHERE quest_id='" + questID + "' ORDER BY dialogue_type, dialogue_num"
                                                             );
            while (true == reader.Read())
            {
                Quest.Dialogue dialogue = new Quest.Dialogue();
                dialogue.sprite_path = reader.GetString("sprite_path");
                dialogue.text        = reader.GetString("dialogue_text");
                int dialogueType = reader.GetInt32("dialogue_type");

                switch (dialogueType)
                {
                case 1:
                    quest.start_dialogues.Add(dialogue);
                    break;

                case 2:
                    break;

                case 3:
                    quest.complete_dialogues.Add(dialogue);
                    break;
                }
            }
        }

        return(quest);
    }
Пример #5
0
        // Use this for initialization
        public void Init(int dungeonLevel)
        {
            level     = dungeonLevel;
            max_level = GetMaxDungeonLevel();
            for (int i = 0; i < WIDTH * HEIGHT; i++)
            {
                Room.Data room = new Room.Data();
                room.id    = i;
                room.group = i;
                rooms[i]   = room;
            }

            int group = 0;

            while (true)
            {
                List <Room.Data> outerRooms = GetOuterRoomsInGroup(group);
                if (0 < outerRooms.Count)
                {
                    Room.Data room           = outerRooms[Random.Range(0, outerRooms.Count)];
                    int       directionCount = Random.Range(0, 3);
                    for (int i = 0; i < directionCount; i++)
                    {
                        int direction = Random.Range(0, Room.DirectionMax);
                        for (int j = 0; j < Room.DirectionMax; j++)
                        {
                            Room.Data other = GetNextRoom(room.id, direction);
                            if (null == other)
                            {
                                direction = (direction + 1) % Room.DirectionMax;
                                continue;
                            }

                            room.nexts[direction] = other;
                            switch (direction)
                            {
                            case Room.North:
                                other.nexts[Room.South] = room;
                                break;

                            case Room.East:
                                other.nexts[Room.West] = room;
                                break;

                            case Room.South:
                                other.nexts[Room.North] = room;
                                break;

                            case Room.West:
                                other.nexts[Room.East] = room;
                                break;
                            }

                            if (other.group != room.group)
                            {
                                if (room.group < other.group)
                                {
                                    ChangeGroupID(other.group, room.group);
                                }
                                else
                                {
                                    ChangeGroupID(room.group, other.group);
                                }
                                break;
                            }

                            direction = (direction + 1) % Room.DirectionMax;
                        }
                    }
                }
                int roomCountInGroupZero = 0;
                foreach (Room.Data room in rooms)
                {
                    if (0 == room.group)
                    {
                        roomCountInGroupZero++;
                    }
                }
                if (roomCountInGroupZero == WIDTH * HEIGHT)
                {
                    break;
                }
                group = (group + 1) % (WIDTH * HEIGHT);
            }

            List <Room.Data> candidates = new List <Room.Data>(rooms);
            int start = Random.Range(0, candidates.Count);

            rooms[start].type  = Room.Type.Start;
            current_room       = rooms[start];
            current_room.visit = true;
            candidates.RemoveAt(start);

            Util.Sqlite.DataReader reader = Database.Execute(Database.Type.MetaData,
                                                             "SELECT monster_id, monster_count, reward_item_chance, reward_item_id FROM meta_dungeon_monster WHERE dungeon_level=" + Mathf.Max(1, dungeonLevel % (max_level + 1))
                                                             );

            while (true == reader.Read())
            {
                int monsterCount = reader.GetInt32("monster_count");
                for (int i = 0; i < monsterCount; i++)
                {
                    if (0 == candidates.Count)
                    {
                        break;
                    }

                    int       index = Random.Range(0, candidates.Count);
                    Room.Data room  = candidates[index];
                    room.monster = MonsterManager.Instance.FindMeta(reader.GetString("monster_id"));
                    room.monster.reward_item_chance = reader.GetFloat("reward_item_chance");
                    room.monster.reward.item_id     = reader.GetString("reward_item_id");
                    candidates.RemoveAt(index);
                }
            }

            int itemBoxCount = Random.Range(0, 5);

            for (int i = 0; i < itemBoxCount; i++)
            {
                if (0 == candidates.Count)
                {
                    break;
                }
                int       index = Random.Range(0, candidates.Count);
                Room.Data room  = candidates[index];
                room.item = ItemManager.Instance.GetRandomExpendableItemMeta();
                candidates.RemoveAt(index);
            }

            {
                int       index = Random.Range(0, candidates.Count);
                Room.Data room  = candidates[index];
                room.type = Room.Type.Shop;
            }

            bool exitLock = false;
            bool keyItem  = false;

            foreach (Room.Data room in rooms)
            {
                if (null == room.item)
                {
                    continue;
                }
                if (room.item.id == "ITEM_KEY")
                {
                    exitLock = true;
                    keyItem  = true;
                    break;
                }
            }

            if (false == exitLock)
            {
                exitLock = 30 > Random.Range(0, 100);
            }

            if (true == exitLock && false == keyItem)
            {
                int index = Random.Range(0, candidates.Count);
                candidates[index].item = ItemManager.Instance.FindMeta <KeyItem.Meta>("ITEM_KEY");
                candidates.RemoveAt(index);
            }

            candidates.RemoveAll(room => room.id == current_room.id + WIDTH);
            candidates.RemoveAll(room => room.id == current_room.id + 1);
            candidates.RemoveAll(room => room.id == current_room.id - 1);
            candidates.RemoveAll(room => room.id == current_room.id - WIDTH);

            int end = Random.Range(0, candidates.Count);

            Room.Data exit = candidates[end];
            exit.type = Room.Type.Exit;
            if (true == exitLock)
            {
                exit.type = Room.Type.Lock;
            }
            candidates.RemoveAt(end);
        }