示例#1
0
    public void CalculateResult(Slots lSlot, Slots rSlot)
    {
        CalculateTurn(lSlot, rSlot);

        int count1st = SlotTurn1st.Count;
        int count2nd = SlotTurn2nd.Count;
        int index1st = 0;
        int index2nd = 0;

        bool bFirstTurn = true;
        bool bEndGame   = false;
        bool bOutOfMove = false;

        TurnCount = 1;

        BattleRecordController.Instance.Reset( );

        bool bWin = false;

        while (!bEndGame)
        {
            // record TURN
            BattleRecordController.Instance.CreateRecord();
            BattleRecordController.RecordTurn(TurnCount);

            if (bFirstTurn)
            {
                BattleRecordController.RecrodIsLeft(bLFirst);

                bFirstTurn = !DoTurn(ref index1st, ref index2nd, count1st, SlotTurn1st, SlotTurn2nd, out bOutOfMove, out bEndGame);

                if (index2nd >= SlotTurn2nd.Count)                  // they had reach max
                {
                    bFirstTurn = true;
                }

                if (bEndGame)
                {
                    if (bLFirst)
                    {
                        bWin = true;
                    }
                    else
                    {
                        bWin = false;
                    }
                }
            }
            else
            {
                BattleRecordController.RecrodIsLeft(!bLFirst);

                bFirstTurn = DoTurn(ref index2nd, ref index1st, count2nd, SlotTurn2nd, SlotTurn1st, out bOutOfMove, out bEndGame);

                if (index1st >= SlotTurn1st.Count)
                {
                    bFirstTurn = false;
                }

                if (bEndGame)
                {
                    if (bLFirst)
                    {
                        bWin = false;
                    }
                    else
                    {
                        bWin = true;
                    }
                }
            }

            Debug.Log("Next 1st : " + index1st);
            Debug.Log("Next 2nd : " + index2nd);

            if (index1st >= SlotTurn1st.Count &&
                index2nd >= SlotTurn2nd.Count && !bEndGame)
            {
                Debug.Log("NEW TURN");
                index1st   = 0;
                index2nd   = 0;
                bFirstTurn = true;
                TurnCount += 1;
            }

            if (bEndGame)
            {
                Debug.Log("END GAME");
            }
        }

        Debug.Log("Turn count : " + TurnCount);

        BattleRecordController.Instance.WinGameResult = bWin;
        BattleRecords records = BattleRecordController.Instance.PBattleRecords;

        foreach (var record in records)
        {
            Debug.Log("Turn : " + record.Turn);
            Debug.Log("Attacker : " + record.AttackerSlot.Charname);
            Debug.Log("Defender : " + record.DefenderSlot.Charname);
            Debug.Log("Damage dealed : " + record.Damage);
            Debug.Log("Has dodgle : " + record.Dodged);
            Debug.Log("Has blocked : " + record.Blocked);
            Debug.Log("Has crit : " + record.Crit);
            Debug.Log("-------------------------");
            Debug.Log("Attacker HP : " + record.AttackerSlot.CharHealth + "/" + record.AttackerSlot.CharMaxHealth);
            Debug.Log("Defender HP : " + record.DefenderSlot.CharHealth + "/" + record.DefenderSlot.CharMaxHealth);
            Debug.Log("-------------------------");
        }

        if (bWin)
        {
            Debug.Log("You win");
        }
        else
        {
            Debug.Log("You lose");
        }

        lSlot.Reset();
        rSlot.Reset();
    }
示例#2
0
        void Connect(int rpUserID)
        {
            if (r_UserID == rpUserID)
            {
                return;
            }

            Disconnect();

            r_UserID = rpUserID;

            var rFilename     = r_UserID + ".db";
            var rDatabaseFile = new FileInfo(Path.Combine(RecordDirectory.FullName, rFilename));

            if (!rDatabaseFile.Exists)
            {
                TryMigrateFromOldVersion(rFilename, rDatabaseFile);
            }

            r_Connection = new SQLiteConnection($@"Data Source={rDatabaseFile.FullName}; Page Size=8192", true).OpenAndReturn();

            if (IsReadOnlyMode)
            {
                using (var rSourceConnection = r_Connection)
                {
                    r_Connection = new SQLiteConnection("Data Source=:memory:; Page Size=8192").OpenAndReturn();
                    rSourceConnection.BackupDatabase(r_Connection, "main", "main", -1, null, 0);
                }
            }

            using (var rCommand = r_Connection.CreateCommand())
            {
                rCommand.CommandText =
                    "PRAGMA journal_mode = DELETE; " +
                    "PRAGMA foreign_keys = ON;";

                rCommand.ExecuteNonQuery();
            }

            using (var rTransaction = r_Connection.BeginTransaction())
            {
                CheckVersion();

                r_Resources         = new ResourcesRecords(r_Connection).ConnectAndReturn();
                r_Experience        = new ExperienceRecords(r_Connection).ConnectAndReturn();
                r_Expedition        = new ExpeditionRecords(r_Connection).ConnectAndReturn();
                r_Construction      = new ConstructionRecords(r_Connection).ConnectAndReturn();
                r_Development       = new DevelopmentRecords(r_Connection).ConnectAndReturn();
                r_Sortie            = new SortieRecords(r_Connection).ConnectAndReturn();
                r_Battle            = new BattleRecords(r_Connection).ConnectAndReturn();
                r_Fate              = new FateRecords(r_Connection).ConnectAndReturn();
                r_RankingPoints     = new RankingPointsRecords(r_Connection).ConnectAndReturn();
                r_SortieConsumption = new SortieConsumptionRecords(r_Connection).ConnectAndReturn();

                QuestProgress = new QuestProgressRecords(r_Connection).ConnectAndReturn();

                foreach (var rProvider in r_CustomRecordsGroupProviders)
                {
                    var rGroup = rProvider.Create(r_Connection).ConnectAndReturn();
                    r_CustomRecordsGroups[rGroup.GroupName] = rGroup;
                }

                rTransaction.Commit();
            }

            r_BattleDetail = new BattleDetailRecords(r_Connection, r_UserID).ConnectAndReturn();

            r_Connection.Update += OnDatabaseUpdate;

            IsConnected = true;
        }
        void Connect(int rpUserID)
        {
            if (r_UserID == rpUserID)
            {
                return;
            }

            Resources?.Dispose();
            Ships?.Dispose();
            Experience?.Dispose();
            Expedition?.Dispose();
            Construction?.Dispose();
            Development?.Dispose();
            Sortie?.Dispose();
            Battle?.Dispose();
            RankingPoints?.Dispose();
            Fate?.Dispose();
            QuestProgress?.Dispose();
            BattleDetail?.Dispose();

            if (r_Connection != null)
            {
                r_Connection.Update -= OnDatabaseUpdate;

                r_Connection.Dispose();
            }

            foreach (var rCustomGroup in r_CustomRecordsGroups.Values)
            {
                rCustomGroup.Dispose();
            }

            IsConnected = false;

            r_UserID = rpUserID;

            r_Connection = new SQLiteConnection($@"Data Source=Records\{r_UserID}.db;Page Size=8192").OpenAndReturn();

            if (IsReadOnlyMode)
            {
                using (var rSourceConnection = r_Connection)
                {
                    r_Connection = new SQLiteConnection("Data Source=:memory:;Page Size=8192").OpenAndReturn();
                    rSourceConnection.BackupDatabase(r_Connection, "main", "main", -1, null, 0);
                }
            }

            using (var rTransaction = r_Connection.BeginTransaction())
            {
                CheckVersion();

                Resources     = new ResourcesRecords(r_Connection).ConnectAndReturn();
                Ships         = new ShipsRecords(r_Connection).ConnectAndReturn();
                Experience    = new ExperienceRecords(r_Connection).ConnectAndReturn();
                Expedition    = new ExpeditionRecords(r_Connection).ConnectAndReturn();
                Construction  = new ConstructionRecords(r_Connection).ConnectAndReturn();
                Development   = new DevelopmentRecords(r_Connection).ConnectAndReturn();
                Sortie        = new SortieRecords(r_Connection).ConnectAndReturn();
                Battle        = new BattleRecords(r_Connection).ConnectAndReturn();
                RankingPoints = new RankingPointsRecords(r_Connection).ConnectAndReturn();
                Fate          = new FateRecords(r_Connection).ConnectAndReturn();

                QuestProgress = new QuestProgressRecords(r_Connection).ConnectAndReturn();

                foreach (var rProvider in r_CustomRecordsGroupProviders)
                {
                    var rGroup = rProvider.Create(r_Connection).ConnectAndReturn();
                    r_CustomRecordsGroups[rGroup.GroupName] = rGroup;
                }

                rTransaction.Commit();
            }

            BattleDetail = new BattleDetailRecords(r_Connection, r_UserID).ConnectAndReturn();

            r_Connection.Update += OnDatabaseUpdate;

            IsConnected = true;
        }