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(); }); } } }
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); }
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); }
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); }
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); }
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)); } }); } }
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(); }
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(); }); }
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); }
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 }