예제 #1
0
    public void Init()
    {
        CreateAchieveTableIfNotExists();

        Util.Sqlite.DataReader reader = Database.Execute(Database.Type.UserData,
                                                         "SELECT bgm_volume, sfx_volume FROM user_setting"
                                                         );

        int rowCount = 0;

        while (true == reader.Read())
        {
            rowCount++;
            bgm.value = reader.GetFloat("bgm_volume");
            AudioManager.Instance.Volumn("BGM", bgm.value);
            sfx.value = reader.GetFloat("sfx_volume");
            AudioManager.Instance.Volumn("SFX", sfx.value);
        }

        if (0 == rowCount)
        {
            Database.Execute(Database.Type.UserData, "INSERT INTO user_setting(bgm_volume, sfx_volume) VALUES (1, 1)");
            bgm.value = 1.0f;
            AudioManager.Instance.Volumn("BGM", bgm.value);
            sfx.value = 1.0f;
            AudioManager.Instance.Volumn("SFX", sfx.value);
        }

        close.onClick.AddListener(() =>
        {
            gameObject.SetActive(false);
        });

        bgm.onValueChanged.AddListener((float value) =>
        {
            AudioManager.Instance.Volumn("BGM", value);
            Database.Execute(Database.Type.UserData, "UPDATE user_setting SET bgm_volume=" + value);
        });

        sfx.onValueChanged.AddListener((float value) =>
        {
            AudioManager.Instance.Volumn("SFX", value);
            Database.Execute(Database.Type.UserData, "UPDATE user_setting SET sfx_volume=" + value);
        });
    }
예제 #2
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);
                }
            }
        }
    }
예제 #3
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);
        }