Exemplo n.º 1
0
 public TEntity SetRole(string tagId, string roleId)
 {
     try
     {
         if (string.IsNullOrEmpty(tagId))
         {
             return(null);
         }
         if (string.IsNullOrEmpty(roleId))
         {
             return(null);
         }
         var tag = GetEntity(tagId);
         if (tag == null)
         {
             return(null);
         }
         tag.CardRoleId = roleId.ToInt();
         var          entity = Put(tag);
         DataChangArg arg    = new DataChangArg(this, entity);
         StaticEvents.OnDbDataChanged(arg);
         return(entity);
     }
     catch (System.Exception ex)
     {
         Log.Error(tag, "SetRole", "Exceptioin:" + ex);
         return(null);
     }
 }
Exemplo n.º 2
0
    public void PieceMoveEvent(BasePiece piece, Cell currentCell, Cell targetCell)
    {
        var toX   = (byte)targetCell.boardPosition.x;
        var toY   = (byte)(7 - targetCell.boardPosition.y);
        var fromX = (byte)currentCell.boardPosition.x;
        var fromY = (byte)(7 - currentCell.boardPosition.y);

        if (engine.MovePiece(
                fromX, fromY, toX, toY))
        {
            var move = new EngineMove
            {
                MoveContent = engine.GetMoveHistory().ToArray()[0],
                Message     = "Ход Игрока\n"
            };

            queuedMoves.Enqueue(move);
        }
        else
        {
            SoundEvents.PlayRejectSound();
            StaticEvents.LogMsgEvent("Недопустимый ход!", LogType.Warning);
            piece.Place(board.AllCells[currentCell.boardPosition.x,
                                       currentCell.boardPosition.y]);
        }
    }
Exemplo n.º 3
0
        public async Task RunBotAsync()
        {
            // load config file and set up client
            var cfgJson = await ReadConfigFile(configPath);

            var cfgDiscord = ConfigureDiscord(cfgJson);

            Client = new DiscordClient(cfgDiscord);
            ConfigureCommands(cfgJson);
            ConfigureEvents();

            // connect, baby!
            Debug.WriteLine("Connecting to discord...");
            await Client.ConnectAsync();

            // start the save timer to backup state every hour
            SaveTimer = new Timer(60 * 60 * 1000)
            {
                AutoReset = true, Enabled = true
            };
            SaveTimer.Elapsed += (object sender, ElapsedEventArgs e) => StaticEvents.SaveTimer_Elapsed(sender, e, Client);

            // Start a timer to update the bot's status every hour
            PresenceTimer = new Timer(60 * 60 * 1000)
            {
                AutoReset = true, Enabled = true
            };
            PresenceTimer.Elapsed += (object sender, ElapsedEventArgs e) => StaticEvents.PresenceTimer_Elapsed(Client);

            // prevent premature quitting
            await Task.Delay(-1);
        }
Exemplo n.º 4
0
 private void OnUnitsArePreparedForBattle(Units units)
 {
     simulator.SetUnitsForSimulation(units);
     simulator.StartSimulation();
     statistics.StartCollectStatistics(units);
     rule.SetUnitsForRuleChecking(units);
     StaticEvents.startBattleEvent();
 }
Exemplo n.º 5
0
    private void PlayerWhiteVsAiBlack()
    {
        Debug.Log("PlayerWhiteVsAiBlack");

        if (engine.IsGameOver())
        {
            return;
        }

        if (engine.Thinking)
        {
            return;
        }

        switch (engine.WhoseMove)
        {
        case ChessPieceColor.White:

            Debug.Log("WhoseMove White");

            SetInteractive(whitePieces, true);
            SetInteractive(blackPieces, false);
            foreach (var piece in promotedPieces)
            {
                if (piece.mainColor == Colors.WhitePieces)
                {
                    piece.enabled = true;
                }
            }
            StaticEvents.ReportOfTurnChange(false, engine.GetScore());

            break;

        case ChessPieceColor.Black:

            Debug.Log("WhoseMove Black");

            SetInteractive(whitePieces, false);
            SetInteractive(blackPieces, false);

            StaticEvents.ReportOfTurnChange(true, engine.GetScore());

            if (engine.WhoseMove != engine.HumanPlayer)
            {
                MakeEngineMove();
            }

            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
Exemplo n.º 6
0
        private void MenuLocalArchor_Click(object sender, RoutedEventArgs e)
        {
            List <string> codes = new List <string>();

            foreach (var item in DataGrid3.SelectedItems)
            {
                UDPArchor archor = item as UDPArchor;
                if (archor == null)
                {
                    continue;
                }
                codes.Add(archor.GetClientIP());
            }
            StaticEvents.OnLocateArchorByIp(codes);
        }
Exemplo n.º 7
0
    private void AiWhiteVsAiBlack()
    {
        Debug.Log("AiWhiteVsAiBlack");
        SetInteractive(whitePieces, false);
        SetInteractive(blackPieces, false);

        if (engine.IsGameOver())
        {
            return;
        }
        if (engine.Thinking)
        {
            return;
        }

        switch (engine.WhoseMove)
        {
        case ChessPieceColor.White:
            Debug.Log("WhoseMove White");
            StaticEvents.ReportOfTurnChange(false, engine.GetScore());

            engine.HumanPlayer = ChessPieceColor.Black;

            if (engine.WhoseMove != engine.HumanPlayer)
            {
                MakeEngineMove();
            }

            break;

        case ChessPieceColor.Black:

            Debug.Log("WhoseMove Black");
            StaticEvents.ReportOfTurnChange(true, engine.GetScore());

            engine.HumanPlayer = ChessPieceColor.White;

            if (engine.WhoseMove != engine.HumanPlayer)
            {
                MakeEngineMove();
            }

            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
Exemplo n.º 8
0
    private void OnGUI()
    {
        if (showDialogue != true)
        {
            return;
        }

        GUI.Box(
            new Rect(Screen.width / 2 - 300, Screen.height - 300, 600, 250),
            "");
        GUI.Label(
            new Rect(Screen.width / 2 - 250, Screen.height - 280, 500, 90),
            node[currentNode].text,
            new GUIStyle
        {
            alignment = TextAnchor.UpperLeft,
            fontSize  = Screen.height * 2 / 100,
            normal    = { textColor = Color.white }
        });

        for (var i = 0; i < node[currentNode].answer.Length; i++)
        {
            if (!GUI.Button(
                    new Rect(Screen.width / 2 - 250, Screen.height - 225 + 55 * i, 500, 45),
                    node[currentNode].answer[i].text))
            {
                continue;
            }
            if (node[currentNode].answer[i].speakEnd)
            {
                ClickSource.PlayOneShot(clickSound);
                StaticEvents.DialogEndEvent(node[currentNode].answer[i].setup);

                showDialogue = false;
                isEnd        = true;
            }

            currentNode = node[currentNode].answer[i].toNode;
        }
    }
Exemplo n.º 9
0
    private void PlayerWhiteVsPlayerBlack()
    {
        if (engine.IsGameOver())
        {
            return;
        }

        switch (engine.WhoseMove)
        {
        case ChessPieceColor.White:
            SetInteractive(whitePieces, true);
            SetInteractive(blackPieces, false);

            foreach (var piece in promotedPieces)
            {
                var isBlack = piece.mainColor != Color.white;
                piece.enabled = !isBlack;
            }

            StaticEvents.ReportOfTurnChange(false, engine.GetScore());
            break;

        case ChessPieceColor.Black:
            SetInteractive(whitePieces, false);
            SetInteractive(blackPieces, true);

            foreach (var piece in promotedPieces)
            {
                var isBlack = piece.mainColor != Color.white;
                piece.enabled = isBlack;
            }

            StaticEvents.ReportOfTurnChange(true, engine.GetScore());
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
Exemplo n.º 10
0
        public TEntity SetRole(string tagId, string roleId)
        {
            if (string.IsNullOrEmpty(tagId))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(roleId))
            {
                return(null);
            }
            var tag = GetEntity(tagId);

            if (tag == null)
            {
                return(null);
            }
            tag.CardRoleId = roleId.ToInt();
            var          entity = Put(tag);
            DataChangArg arg    = new DataChangArg(this, entity);

            StaticEvents.OnDbDataChanged(arg);
            return(entity);
        }
Exemplo n.º 11
0
    private void Start()
    {
        BasicStaticObjectStack.stackOfObjects.Clear();
        StaticArray.objectArray = new ObjectAttachedToArray[0];
        StaticObjectList.objectList.Clear();
        StaticObjectStack.stackOfObjects.Clear();
        StaticStringObjectDictionary.stringObjectDictionary.Clear();

        SerializedClassHolder.serializedClassList.Clear();
        if (ReferenceHolderHolder.holderReference)
        {
            ReferenceHolderHolder.holderReference.objectReference = null;
        }
        ReferenceHolderHolder.holderReference = null;

        staticEventsObject.RemoveAllEventsHack();
        StaticEvents.DoAThing();
        StaticEvents.DoAThingPlusX(1);

        Debug.Log("Zombies Cleaned Up");
        Resources.UnloadUnusedAssets();
        SceneManager.LoadScene("Boot");
    }
Exemplo n.º 12
0
    private void ProceedMove(MoveContent lastMove, string message)
    {
        if (lastMove.TakenPiece.PieceType.ToString() != "None")
        {
            var takenSrcCell = Extensions.FromPosition(lastMove.TakenPiece.Position);
            var takenPiece   = board.AllCells[takenSrcCell.x, takenSrcCell.y].currentPiece;

            if (takenPiece != null)
            {
                message += Extensions.PieceToStr(takenPiece) + " взятие ";
                takenPiece.Kill();
            }
        }

        if (lastMove.MovingPiecePrimary.PieceType.ToString() != "None")
        {
            var primarySrcCell = Extensions.FromPosition(lastMove.MovingPiecePrimary.SrcPosition);
            var primaryDstCell = Extensions.FromPosition(lastMove.MovingPiecePrimary.DstPosition);

            var piecePrimary = board.AllCells[primarySrcCell.x, primarySrcCell.y].currentPiece;
            if (piecePrimary != null)
            {
                if (lastMove.PawnPromotedTo == ChessPieceType.Queen)
                {
                    message += " Pawn повышение Queen ";
                    PromotePiece(piecePrimary as Pawn, board.AllCells[primaryDstCell.x, primaryDstCell.y],
                                 piecePrimary.mainColor,
                                 piecePrimary.mainColor == Color.black ? Colors.BlackPieces : Colors.WhitePieces);
                }
                else
                {
                    piecePrimary.MovePieceToCell(board.AllCells[primaryDstCell.x, primaryDstCell.y]);
                    SoundEvents.PlayMoveSound();
                    message += Extensions.PieceToStr(piecePrimary);
                }
            }
            else
            {
                Debug.Log("Piece not found and not created!");
            }
        }

        if (lastMove.MovingPieceSecondary.PieceType.ToString() != "None")
        {
            var secondarySrcCell = Extensions.FromPosition(lastMove.MovingPieceSecondary.SrcPosition);
            var secondaryDstCell = Extensions.FromPosition(lastMove.MovingPieceSecondary.DstPosition);
            var pieceSecondary   = board.AllCells[secondarySrcCell.x, secondarySrcCell.y].currentPiece;

            if (pieceSecondary != null)
            {
                message += " рокировка ";
                pieceSecondary.Place(board.AllCells[secondaryDstCell.x, secondaryDstCell.y]);
                SoundEvents.PlayMoveSound();
                message += Extensions.PieceToStr(pieceSecondary);
            }
            else
            {
                var msg = "pieceSecondary not found!";

                msg += " Src X " + secondarySrcCell.x + " Y " + secondarySrcCell.y;
                msg += " Dst X " + secondaryDstCell.x + " Y " + secondaryDstCell.y;
                Debug.LogError(msg);
                //StaticEvents.LogMsgEvent(msg, LogType.Exception);
            }
        }

        if (lastMove.EnPassantOccured)
        {
            message += " взятие на проходе ";
        }

        message += "\n" + lastMove.ToString();
        StaticEvents.LogMsgEvent(message, LogType.Log);
        CheckMove(engine);
        SwitchSides();
    }
Exemplo n.º 13
0
    private static void CheckMove(Engine engine)
    {
        string msg;

        if (engine.GetWhiteCheck())
        {
            msg = "Шах белым";
            Debug.Log(msg);
            StaticEvents.LogMsgEvent(msg, LogType.Warning);
            SoundEvents.PlayCheckSound();
        }

        if (engine.GetBlackCheck())
        {
            msg = "Шах черным";
            Debug.Log(msg);
            StaticEvents.LogMsgEvent(msg, LogType.Warning);
            SoundEvents.PlayCheckSound();
        }

        if (!engine.IsGameOver())
        {
            return;
        }

        var result    = "";
        var resultPgn = PGN.Result.Ongoing;
        var state     = EndGamesStates.None;

        if (engine.StaleMate)
        {
            resultPgn = PGN.Result.Tie;
            if (engine.InsufficientMaterial)
            {
                state  = EndGamesStates.StaleMateByInsufficientMaterial;
                result = "Ничья, недостаточно материала для мата";
            }
            else if (engine.RepeatedMove)
            {
                state  = EndGamesStates.StaleMateByRepeatedMove;
                result = "Ничья после троекратного повторения";
            }
            else if (engine.FiftyMove)
            {
                state  = EndGamesStates.StaleMateByFiftyMove;
                result = "Ничья по правилу 50 ходов";
            }
            else
            {
                state  = EndGamesStates.StaleMate;
                result = "Пат";
            }

            Debug.Log(result);
            StaticEvents.LogMsgEvent(result, LogType.Warning);
            SoundEvents.PlayCheckSound();
        }

        if (engine.GetWhiteMate())
        {
            resultPgn = PGN.Result.Black;
            result    = "Шах и мат белым";
            Debug.Log(result);
            StaticEvents.LogMsgEvent(result, LogType.Warning);
            SoundEvents.PlayCheckSound();
            state = EndGamesStates.WhiteMate;
        }

        if (engine.GetBlackMate())
        {
            resultPgn = PGN.Result.White;
            result    = "Шах и мат черным";
            Debug.Log(result);
            StaticEvents.LogMsgEvent(result, LogType.Warning);
            SoundEvents.PlayCheckSound();
            state = EndGamesStates.BlackMate;
        }

        GameStatData.PGN = GeneratePNG(engine, resultPgn);

        SoundEvents.PlayVictorySound();
        msg = "Конец игры";

        StaticEvents.LogMsgEvent(msg, LogType.Exception);
        SoundEvents.PlayCheckSound();
        EndGameEvents.EndGameEvent(state, result, engine.GetScore());
    }
Exemplo n.º 14
0
 // Use this for initialization
 void Start()
 {
     staticEvents  = GetComponent <Movement>().grid.GetComponent <StaticEvents>();
     currentEvents = new List <StaticEvent>();
 }
Exemplo n.º 15
0
 /// <summary>
 /// 发送错误警告
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="info"></param>
 public static void SendErrorWarning(this ILogger logger, string info)
 {
     logger.LogError("发送错误警告:" + info);
     StaticEvents.SendWarning();
 }
Exemplo n.º 16
0
    private void OptionsDialogWindow(int windowId)
    {
        GUI.Label(
            new Rect(10, 20, _pauseDialogWindowRect.width - 10, 30),
            "Громкость:",
            new GUIStyle
        {
            //richText = enabled,
            alignment = TextAnchor.MiddleCenter,
            fontSize  = Screen.height * 2 / 100,
            normal    = { textColor = new Color32(235, 235, 235, 255) }
        });
        GUI.Label(
            new Rect(10, 35, _pauseDialogWindowRect.width - 10, 30),
            AudioSliderValue.ToString(CultureInfo.CurrentCulture),
            new GUIStyle
        {
            //richText = enabled,
            alignment = TextAnchor.MiddleCenter,
            fontSize  = Screen.height * 2 / 100,
            normal    = { textColor = new Color32(235, 235, 235, 255) }
        });
        AudioSliderValue = GUI.HorizontalSlider(new Rect(15, 60, 170, 40),
                                                AudioSliderValue, 0.0F, 1.0F);
        GUI.Label(
            new Rect(10, 85, _pauseDialogWindowRect.width - 10, 30),
            "Сложность ИИ:",
            new GUIStyle
        {
            //richText = enabled,
            alignment = TextAnchor.MiddleCenter,
            fontSize  = Screen.height * 2 / 100,
            normal    = { textColor = new Color32(235, 235, 235, 255) }
        });
        if (GUI.Button(new Rect(15, 115, 40, 40), "<"))
        {
            if (Difficulty != Engine.Difficulty.Easy)
            {
                Difficulty--;
            }
        }
        GUI.Label(
            new Rect(10, 120, _pauseDialogWindowRect.width - 10, 30),
            Difficulty.ToString(),
            new GUIStyle
        {
            //richText = enabled,
            alignment = TextAnchor.MiddleCenter,
            fontSize  = Screen.height * 2 / 100,
            normal    = { textColor = new Color32(235, 235, 235, 255) }
        });
        if (GUI.Button(new Rect(145, 115, 40, 40), ">"))
        {
            if (Difficulty != Engine.Difficulty.VeryHard)
            {
                Difficulty++;
            }
        }

        if (GUI.Button(new Rect(5, 180, _pauseDialogWindowRect.width - 10, 35),
                       "ПРИМЕНИТЬ"))
        {
            ClickSource.PlayOneShot(clickSound);
            Debug.Log("Apply Button pressed");
            AudioListener.volume = AudioSliderValue;
            if (SettingsData.Settings != null)
            {
                SettingsData.Settings.Difficulty = Difficulty;
            }
            StaticEvents.SettingsChangeEvent(Difficulty);
        }
        else if (GUI.Button(new Rect(5, 220, _pauseDialogWindowRect.width - 10, 35),
                            "НАЗАД"))
        {
            ClickSource.PlayOneShot(clickSound);
            Debug.Log("Back to PauseMenu Button pressed");
            showOptionDialog = false;
            showPauseDialog  = true;
        }
    }