Ejemplo n.º 1
0
        public TestModule(ITokenizer tokenizer)
            : base("/test")
        {
            Post["/"] = parameters =>
            {
                return("default");
            };

            Get["/simulation"] = parameters =>
            {
                ContentsPrepare.Init();

                Player[] player = { new Player(), new Player(), new Player() };

                var data = PlayerDataDatabase.GetPlayerData("102");
                if (data != null)
                {
                    player[0].LoadPlayer(data);
                }

                data = PlayerDataDatabase.GetPlayerData("103");
                if (data != null)
                {
                    player[1].LoadPlayer(data);
                }

                data = PlayerDataDatabase.GetPlayerData("104");
                if (data != null)
                {
                    player[2].LoadPlayer(data);
                }

                Party users = new Party(PartyType.PLAYER, 10);
                foreach (Player p in player)
                {
                    users.AddCharacter(p);
                }

                DungeonMaster newMaster = new DungeonMaster();
                newMaster.Init(60, 4, users);

                return("turn : " + newMaster.Start());
            };
        }
        public static void Simulation(Party party)
        {
            var runningTime = Stopwatch.StartNew();

            Debug.WriteLine("start to simulation");
            Console.WriteLine("start to simulation");

            party.characters.ForEach(each => Console.WriteLine("equip : " + each.equipments.Count));

            SimulationResult result = new SimulationResult();

            long currentIdx = Interlocked.Increment(ref resultIdx);

            // over flow 확인하고 제어 할 것

            result.Id         = currentIdx;
            result.PartyLevel = party.partyLevel;
            result.Seed       = random.Next();
            result.MapSize    = 60;

            // result에 사용될 사용자 정보 기록
            result.PlayerList = new List <PlayerData>();
            party.characters.ForEach(each =>
            {
                var player = (Player)each;
                result.PlayerList.Add(player.ConvertToPlayerData());
            });

            Console.WriteLine("party level : " + party.partyLevel);

            // simulation!!!!
            DungeonMaster newMaster = new DungeonMaster();

            newMaster.Init(result.MapSize, result.Seed, party);
            var res = newMaster.Start();

            Console.WriteLine("turn : " + res);
            Console.WriteLine("looted gold : " + newMaster.record.lootedGold);
            Console.WriteLine("looted exp : " + newMaster.record.lootedExp);

            // save the result data in DB
            result.CheckedPlayer = new List <ulong>();
            Debug.Assert(SimulationResultDatabase.SetSimulationResult(result));

            party.characters.ForEach(each =>
            {
                string id = ((Player)each).pId;

                // update player data
                var playerData = PlayerDataDatabase.GetPlayerData(id);
                var userData   = UserDataDatabase.GetUserData(id);

                // 크게 할 일은 경험치 추가, 골드 추가, 아이템토큰 추가
                userData.Gold  += newMaster.record.lootedGold;
                playerData.exp += newMaster.record.lootedExp;
                newMaster.record.lootedItems.ForEach(eachItem => { userData.Token.Add((ItemToken)eachItem); });

                Debug.Assert(UserDataDatabase.SetUserData(userData));
                Debug.Assert(PlayerDataDatabase.SetPlayerData(playerData));

                // update result table
                var resultTable = ResultTableDatabase.GetResultTable(id);
                Debug.Assert(resultTable.UnreadId == -1, "unread result remains");

                resultTable.UnreadId = currentIdx;
                Debug.Assert(ResultTableDatabase.SetResultTable(resultTable), "fail to save the result table - ID : " + resultTable.PlayerId);

                // update rank
                RedisManager.UpdateRank(playerData.pId, playerData.GetScore());
            });

            Debug.WriteLine("simulation ended");
            Console.WriteLine("simulation ended");

            LogRecord.Write("[Simulation : " + runningTime.ElapsedMilliseconds + " ms]");
        }