コード例 #1
0
    public void Prepared(string IPAddress)
    {
        if (Room.AllAi())
        {
            PThread.Async(() => {
                PThread.WaitUntil(() => ReadyToStartGameFlag);
                StartGame();
            });
        }

        PPlayer TargetPlayer = PNetworkManager.NetworkServer.Game.PlayerList.Find((PPlayer Player) => Player.IPAddress.Equals(IPAddress));

        if (TargetPlayer != null)
        {
            lock (PreparedList) {
                PreparedList[TargetPlayer.Index] = true;
            }
            if (PreparedList.TrueForAll((bool x) => x))
            {
                PThread.Async(() => {
                    PThread.WaitUntil(() => ReadyToStartGameFlag);
                    StartGame();
                });
            }
        }
    }
コード例 #2
0
ファイル: PStartGameOrder.cs プロジェクト: ClazyChen/Richer-4
 public PStartGameOrder() : base("start_game",
                                 (string[] args, string IPAddress) => {
     if (!PNetworkManager.NetworkServer.Game.StartGameFlag)
     {
         if (PNetworkManager.NetworkServer.Game.Room.IsFull())
         {
             PThread.Async(() => {
                 PNetworkManager.NetworkServer.Game.StartGame();
             });
         }
     }
 },
                                 (string[] args) => {
     string MapName  = args[1];
     int PlayerIndex = Convert.ToInt32(args[2]);
     PMap Map        = PSystem.MapList.Find((PMap TempMap) => TempMap.Name.Equals(MapName));
     if (Map != null)
     {
         PSystem.PlayerIndex = PlayerIndex;
         PNetworkManager.NetworkClient.GameStatus = new PGameStatus(Map, PSystem.CurrentMode);
         PNetworkManager.NetworkClient.GameStatus.StartGame();
         PUIManager.AddNewUIAction("StartGame[Client]-初始化地图切换到MUI", () => {
             PUIManager.ChangeUI <PMapUI>();
         });
     }
 }) {
 }
コード例 #3
0
    private void EndGame()
    {
        if (EndGameFlag)
        {
            return;
        }
        Monitor.CallTime(PTime.EndGameTime);
        EndGameFlag          = true;
        ReadyToStartGameFlag = false;
        PreparedList         = new List <bool>();
        PlayerList.ForEach((PPlayer Player) => {
            PreparedList.Add(Player.IsAI);
        });
        PThread.Async(() => {
            Logic.ShutDown();
            Monitor.RemoveAll();
            TagManager.RemoveAll();
            List <PPlayer> WinnerList = GetWinner();
            PlayerList.ForEach((PPlayer Player) => {
                PNetworkManager.NetworkServer.TellClient(Player, new PGameOverOrder(Winners(), WinnerList.Contains(Player)));
            });

            ReadyToStartGameFlag = true;
        });
    }
コード例 #4
0
 public bool AskHaveGeneral(PPlayer Player, string GeneralName)
 {
     ChosenAnswer = -1;
     PNetworkManager.NetworkServer.TellClient(Player, new PTestGeneralOrder(Player.Index.ToString(), GeneralName));
     PThread.WaitUntil(() => ChosenAnswer >= 0);
     return(ChosenAnswer == 0);
 }
コード例 #5
0
 public int Ask(PPlayer Player, string Title, string[] Options, string[] ToolTips = null)
 {
     ChosenAnswer = -1;
     PNetworkManager.NetworkServer.TellClient(Player, new PAskOrder(Title, Options.Length, Options, ToolTips));
     PThread.WaitUntil(() => ChosenAnswer >= 0);
     return(ChosenAnswer);
 }
コード例 #6
0
    public PCard AskToChooseOwnCard(PPlayer Player, string Title, bool AllowHandCards = true, bool AllowEquipment = true, bool AllowJudge = false)
    {
        PGame Game = PNetworkManager.NetworkServer.Game;

        Game.TagManager.CreateTag(new PChooseCardTag(Player, null, AllowHandCards, AllowEquipment, AllowJudge));
        PNetworkManager.NetworkServer.TellClient(Player, new PShowInformationOrder(Title));
        PThread.WaitUntil(() => Game.TagManager.FindPeekTag <PChooseCardTag>(PChooseCardTag.TagName).Card != null);
        return(Game.TagManager.PopTag <PChooseCardTag>(PChooseCardTag.TagName).Card);
    }
コード例 #7
0
 public bool AskYesOrNo(PPlayer Player, string Title)
 {
     ChosenAnswer = -1;
     PNetworkManager.NetworkServer.TellClient(Player, new PAskOrder(Title, 2, new string[] {
         "YES", "NO"
     }));
     PThread.WaitUntil(() => ChosenAnswer >= 0);
     return(ChosenAnswer == 0);
 }
コード例 #8
0
 /// <summary>
 /// 向所有的客户端发送命令
 /// </summary>
 /// <param name="order">命令</param>
 public void TellClients(POrder order)
 {
     foreach (PClientCommander commander in CommanderList)
     {
         commander.Send(order);
     }
     if (CommanderList.Count > 0)
     {
         PThread.Delay(Config.SendDelay);
     }
 }
コード例 #9
0
ファイル: PNetworkManager.cs プロジェクト: ClazyChen/Richer-4
 /// <summary>
 /// 建立单一服务器,用于全AI测试
 /// </summary>
 /// <param name="GameMap">游戏地图</param>
 /// <param name="GameMode">游戏模式</param>
 public static void CreateSingleServer(PMap GameMap, PMode GameMode)
 {
     AbortClient();
     CurrentHostType = PHostType.Server;
     PThread.Async(() => {
         _NetworkServer = new PServer()
         {
             maxConnectionNumber = GameMode.PlayerNumber,
             Game = new PGame(GameMap, GameMode)
         };
     });
 }
コード例 #10
0
 /// <summary>
 /// 向客户端发送命令
 /// </summary>
 /// <param name="IPAddress">目标客户端的IP地址</param>
 /// <param name="order">命令</param>
 public void TellClient(string IPAddress, POrder order)
 {
     foreach (PClientCommander commander in CommanderList)
     {
         if (commander.RemoteIPAddress.Equals(IPAddress))
         {
             commander.Send(order);
             break;
         }
     }
     PThread.Delay(Config.SendDelay);
 }
コード例 #11
0
ファイル: PUIManager.cs プロジェクト: ClazyChen/Richer-4
 void Update()
 {
     lock (ActionWaitingList) {
         Queue <NamedAction> TempQueue = new Queue <NamedAction>();
         while (ActionWaitingList.Count > 0)
         {
             NamedAction CurrentAction = ActionWaitingList.Dequeue();
             try {
                 if (CurrentAction != null)
                 {
                     if (CurrentAction.AnimationID > 0)
                     {
                         if (CurrentAnimationID > 0 && CurrentAnimationID != CurrentAction.AnimationID)
                         {
                             TempQueue.Enqueue(CurrentAction);
                             continue;
                         }
                         //} else {
                         //    if (CurrentAnimationID == 0) {
                         //        WaitingAnimation.Remove(CurrentAction.AnimationID);
                         //    }
                         //    CurrentAnimationID = CurrentAction.AnimationID;
                         //}
                     }
                     if (!CurrentAction.Name.Equals(string.Empty))
                     {
                         // PLogger.Log("执行操作 " + CurrentAction.ToString());
                     }
                     bool ActionCompleted = false;
                     PThread.Async(() => {
                         PThread.Delay(0.5f);
                         if (!ActionCompleted)
                         {
                             PLogger.Log("操作异常:" + CurrentAction.ToString());
                             throw new TimeoutException("UI操作超时");
                         }
                     });
                     CurrentAction.Action();
                     ActionCompleted = true;
                 }
             } catch (Exception e) {
                 PLogger.Log("操作 " + CurrentAction.ToString() + " 发生错误");
                 PLogger.Log(e.ToString());
             }
         }
         while (TempQueue.Count > 0)
         {
             ActionWaitingList.Enqueue(TempQueue.Dequeue());
         }
     }
 }
コード例 #12
0
 public PFreeTimeTriggerInstaller() : base("玩家空闲时间点")
 {
     foreach (PTime Time in new PTime[] { PPeriod.FirstFreeTime.During, PPeriod.SecondFreeTime.During })
     {
         TriggerList.Add(new PTrigger("玩家的空闲时间点")
         {
             IsLocked  = true,
             Time      = Time,
             Condition = (PGame Game) => Game.NowPlayer.IsUser,
             Effect    = (PGame Game) => {
                 Game.TagManager.CreateTag(PTag.FreeTimeOperationTag);
                 PThread.WaitUntil(() => !Game.TagManager.ExistTag(PTag.FreeTimeOperationTag.Name));
             }
         });
     }
 }
コード例 #13
0
ファイル: PMessageBox.cs プロジェクト: ClazyChen/Richer-4
 public void CreateMessages(string Title, string[] ButtonTexts, string[] ToolTips = null) {
     int ButtonNumber = ButtonTexts.Length;
     float DeltaHeight = PrototypeUI.UIBackgroundImage.GetComponent<RectTransform>().rect.height * PrototypeUI.UIBackgroundImage.GetComponent<RectTransform>().lossyScale.y;
     Vector3 CenterPoint = PrototypeUI.UIBackgroundImage.GetComponent<RectTransform>().position;
     TitleText.text = Title;
     TitleText.rectTransform.position = CenterPoint + new Vector3(0, DeltaHeight * ButtonNumber /2);
     for (int i = 0; i < ButtonNumber; ++ i) {
         AddSubUI().Initialize(ButtonTexts[i], i, ButtonNumber, CenterPoint, DeltaHeight, ToolTips == null ? string.Empty : ToolTips[i]);
     }
     Monitor = new Thread(() => {
         PMessage ChosenMessage = null;
         PThread.WaitUntil(() => {
             ChosenMessage = GroupUIList.Find((PMessage Message) => Message.IsChosen);
             if (ChosenMessage != null && !(Title.Equals("点将") && ChosenMessage.MessageText.Contains("未获得"))) {
                 return true;
             } else {
                 if (ChosenMessage != null) {
                     ChosenMessage.IsChosen = false;
                 }
                 return false;
             }
         });
         #region 点将卡和手气卡的特殊判定
         if (Title.Contains("点将卡") && ChosenMessage.Index == 0) {
             // 使用了点将卡
             PSystem.UserManager.ChooseGeneral--;
             PSystem.UserManager.Write();
         }
         if (Title.Contains("手气卡") && ChosenMessage.Index == 0) {
             // 使用了手气卡
             PSystem.UserManager.Lucky--;
             PSystem.UserManager.Write();
         }
         #endregion
         PThread.Async(() => {
             PNetworkManager.NetworkClient.Send(new PChooseResultOrder(ChosenMessage.Index.ToString()));
             PUIManager.AddNewUIAction("关闭选项框", () => {
                 Close();
             });
         });
     }) {
         IsBackground = true
     };
     Monitor.Start();
 }
コード例 #14
0
 public void Open()
 {
     CameraThread = new Thread(() => {
         while (true)
         {
             if (IsTracking && !IsChangingPerspective)
             {
                 PUIManager.AddNewUIAction(string.Empty, () => {
                     Track();
                 });
             }
             PThread.Delay(Config.CameraInterval);
         }
     })
     {
         IsBackground = true
     };
     CameraThread.Start();
 }
コード例 #15
0
    public PBlock AskToChooseBlock(PPlayer Player, string Title, Predicate <PBlock> Condition = null)
    {
        PGame  Game   = PNetworkManager.NetworkServer.Game;
        PBlock Answer = null;

        Game.TagManager.CreateTag(new PChooseBlockTag(Player, null));
        PNetworkManager.NetworkServer.TellClient(Player, new PShowInformationOrder(Title));
        while (Answer == null)
        {
            PThread.WaitUntil(() => Game.TagManager.FindPeekTag <PChooseBlockTag>(PChooseBlockTag.TagName).Block != null);
            Answer = Game.TagManager.FindPeekTag <PChooseBlockTag>(PChooseBlockTag.TagName).Block;
            if (Condition != null && !Condition(Answer))
            {
                Answer = null;
                PThread.Delay(0.2f);
            }
        }
        return(Game.TagManager.PopTag <PChooseBlockTag>(PChooseBlockTag.TagName).Block);
    }
コード例 #16
0
ファイル: PAnimation.cs プロジェクト: ClazyChen/Richer-4
 public static void AddAnimation(string Name, Action Animation, int FrameNumber = 1, float TotalTime = 0.0f, Action Callback = null, Action Preparation = null)
 {
     PThread.Async(() => {
         int ID = IDCount++;
         PUIManager.RegisterAnimation(ID);
         // PLogger.Log("注册动画 " + Name + " #" + ID);
         PThread.WaitUntil(() => PUIManager.IsAvailable(ID));
         // PLogger.Log("开始动画 " + Name + " #" + ID);
         PUIManager.AddNewUIAction(string.Empty, () => {
             Preparation?.Invoke();
         }, ID);
         PThread.Repeat(() => {
             PUIManager.AddNewUIAction(string.Empty, Animation, ID);
         }, FrameNumber, TotalTime);
         PUIManager.AddNewUIAction(string.Empty, () => { }, ID, true);
         // PLogger.Log("结束动画 " + Name + " #" + ID);
         Callback?.Invoke();
     });
 }
コード例 #17
0
ファイル: PNetworkManager.cs プロジェクト: ClazyChen/Richer-4
 /// <summary>
 /// 建立服务器,同时建立和它连接的客户端
 /// </summary>
 /// <param name="GameMap">游戏地图</param>
 /// <param name="GameMode">游戏模式</param>
 public static void CreateServer(PMap GameMap, PMode GameMode)
 {
     AbortClient();
     CurrentHostType = PHostType.Server;
     PThread.Async(() => {
         _NetworkServer = new PServer()
         {
             maxConnectionNumber = GameMode.PlayerNumber,
             Game = new PGame(GameMap, GameMode)
         };
         Thread.Sleep(PNetworkConfig.ListenerInterval);
         try {
             _NetworkClient = new PClient(new TcpClient(PNetworkConfig.IP.ToString(), PNetworkConfig.ServerPort));
         } catch (Exception e) {
             PLogger.Log("服务器客户端创建错误");
             PLogger.Log(PNetworkConfig.IP.ToString());
             PLogger.Log(e.ToString());
         }
         CurrentNickname = PNetworkConfig.DefaultNickname;
     });
 }
コード例 #18
0
 public PClickOnSkillOrder() : base("click_on_skill",
                                    (string[] args, string IPAddress) => {
     int SkillIndex = Convert.ToInt32(args[1]);
     PGame Game     = PNetworkManager.Game;
     PPlayer Player = Game.PlayerList.Find((PPlayer _Player) => _Player.IPAddress.Equals(IPAddress));
     if (Player != null && Player.IsAlive && SkillIndex < Player.General.SkillList.Count)
     {
         PSkill Skill = Player.General.SkillList[SkillIndex];
         if (Skill != null)
         {
             bool UseSkill = false;
             if (Game.Logic.WaitingForEndFreeTime() && Game.NowPlayer.Equals(Player) && Game.TagManager.ExistTag(PTag.FreeTimeOperationTag.Name))
             {
                 PTrigger Trigger = Skill.TriggerList.Find((Func <PPlayer, PSkill, PTrigger> TriggerGenerator) => TriggerGenerator(Player, Skill).Time.Equals(Game.NowPeriod.During))?.Invoke(Player, Skill);
                 if (Trigger != null)
                 {
                     if (Trigger.Condition(Game))
                     {
                         PThread.Async(() => {
                             Game.Logic.StartSettle(new PSettle("发动技能[" + Trigger.Name + "]", Trigger.Effect));
                         });
                         UseSkill = true;
                     }
                 }
             }
             if (Skill.SoftLockOpen && !UseSkill)
             {
                 Skill.Lock = !Skill.Lock;
                 Game.Monitor.FindTriggers(Skill.Name).ForEach((PTrigger Trigger) => {
                     Trigger.IsLocked = Skill.Lock;
                 });
                 PNetworkManager.NetworkServer.TellClient(Player, new PRefreshGeneralOrder(Player));
             }
         }
     }
 },
                                    null) {
 }
コード例 #19
0
    public bool AnnounceArch(PArchInfo ArchInfo)
    {
        if (ArchInfo == null)
        {
            return(false);
        }
        bool Refresh = false;

        lock (ArchList) {
            if (!ArchList.Exists((string x) => ArchInfo.Name.Equals(x)))
            {
                ArchList.Add(ArchInfo.Name);
                PSystem.UserManager.ArchPoint += ArchInfo.ArchPoint;
                PSystem.UserManager.Write();
                Refresh = true;
            }
        }
        if (Refresh)
        {
            PThread.Async(() => Write());
        }
        return(Refresh);
    }
コード例 #20
0
 public PClickOnCardOrder() : base("click_on_card",
                                   (string[] args, string IPAddress) => {
     int CardIndex = Convert.ToInt32(args[1]);
     PGame Game    = PNetworkManager.Game;
     PChooseCardTag ChooseCardTag = Game.TagManager.FindPeekTag <PChooseCardTag>(PChooseCardTag.TagName);
     if (ChooseCardTag != null && ChooseCardTag.Player.IPAddress.Equals(IPAddress))
     {
         ChooseCardTag.Card = ChooseCardTag.Player.Area.GetCard(CardIndex, ChooseCardTag.AllowHandCards, ChooseCardTag.AllowEquipment, ChooseCardTag.AllowJudge);
     }
     else if (Game.Logic.WaitingForEndFreeTime() && Game.NowPlayer.IPAddress.Equals(IPAddress) && Game.TagManager.ExistTag(PTag.FreeTimeOperationTag.Name) && Game.NowPlayer.IsAlive)
     {
         PCard Card = Game.NowPlayer.Area.GetCard(CardIndex);
         if (Card != null)
         {
             PTrigger Trigger = null;
             if (Game.NowPlayer.Area.HandCardArea.CardList.Contains(Card))
             {
                 Trigger = Card.FindTrigger(Game.NowPeriod.During);
             }
             else if (Game.NowPlayer.Area.EquipmentCardArea.CardList.Contains(Card))
             {
                 Trigger = Card.FindEquipmentTrigger(Game.NowPeriod.During);
             }
             if (Trigger != null)
             {
                 if (Trigger.Condition(Game))
                 {
                     PThread.Async(() => {
                         Game.Logic.StartSettle(new PSettle("主动触发" + Trigger.Name, Trigger.Effect));
                     });
                 }
             }
         }
     }
 },
                                   null) {
 }
コード例 #21
0
 public override void Open()
 {
     base.Open();
     #region 返回按钮:回到InitialUI
     ReturnButton.onClick.AddListener(() => {
         PNetworkManager.AbortServer();
         PUIManager.AddNewUIAction("返回:转到IUI", () => PUIManager.ChangeUI <PInitialUI>());
     });
     #endregion
     #region 确定按钮:创建服务器
     EnterButton.onClick.AddListener(() => {
         string[] Parts = CodeInputField.text.Split(';');
         if (Parts.Length <= 2)
         {
             return;
         }
         int Times           = Math.Min(100, Math.Max(1, Convert.ToInt32(Parts[Parts.Length - 1])));
         PSystem.AllAiConfig = CodeInputField.text;
         PNetworkManager.CreateSingleServer(PSystem.CurrentMap, PSystem.CurrentMode);
         PThread.Async(() => {
             for (int i = 0; i < Times; ++i)
             {
                 string Time = DateTime.Now.ToLocalTime().ToString();
                 //PLogger.StartLogging(false);
                 List <PGeneral> GeneralList = GenerateGenerals(PSystem.AllAiConfig);
                 PNetworkManager.Game.Room.PlayerList.ForEach((PRoom.PlayerInRoom Player) => Player.PlayerType = PPlayerType.AI);
                 PNetworkManager.Game.StartGame(GeneralList);
                 PThread.WaitUntil(() => PNetworkManager.Game.ReadyToStartGameFlag);
                 PUIManager.AddNewUIAction("增加结果序列", () => {
                     PUIManager.GetUI <PTestUI>().ResultInputField.text += "Time: " + Time + "; Position: " + string.Join(",", PNetworkManager.Game.PlayerList.ConvertAll((PPlayer Player) => Player.General.Name)) + "; Winners: " + PNetworkManager.Game.Winners(true) + "\n";
                 });
             }
         });
     });
     #endregion
 }