public void Die(PPlayer Player, PPlayer Killer) { PNetworkManager.NetworkServer.TellClients(new PShowInformationOrder(Player.Name + "死亡!")); Monitor.CallTime(PTime.DieTime, new PDyingTag(Player, Killer)); Map.BlockList.ForEach((PBlock Block) => { if (Player.Equals(Block.Lord)) { Block.Lord = null; Block.HouseNumber = 0; Block.BusinessType = PBusinessType.NoType; PNetworkManager.NetworkServer.TellClients(new PRefreshBlockBasicOrder(Block)); } }); CardManager.ThrowAll(Player.Area); Player.IsAlive = false; PNetworkManager.NetworkServer.TellClients(new PDieOrder(Player.Index.ToString())); Monitor.CallTime(PTime.AfterDieTime, new PDyingTag(Player, Killer)); if (GameOver()) { PLogger.Log("游戏结束"); EndGame(); } else if (!NowPlayer.IsAlive) { PLogger.Log("因为当前玩家死亡,回合中止"); TagManager.PopTag <PStepCountTag>(PStepCountTag.TagName); TagManager.PopTag <PDiceResultTag>(PDiceResultTag.TagName); TagManager.PopTag <PTag>(PTag.FreeTimeOperationTag.Name); Monitor.EndTurnDirectly = true; } }
void Start() { #region 从Canvas中的UI层建立UI列表 UIList = new List <PAbstractUI>(); Transform Canvas = GameObject.Find("Canvas").transform; for (int i = 0; i < Canvas.childCount; ++i) { Transform Child = Canvas.GetChild(i); if (Child.name.EndsWith("UI")) { Type UIClassType = Type.GetType("P" + Child.name); if (UIClassType != null) { try { PAbstractUI UIInstance = (PAbstractUI)Activator.CreateInstance(UIClassType, BindingFlags.Default, null, new object[] { Child }, null); UIInstance.Name = Child.name; UIList.Add(UIInstance); } catch (Exception e) { PLogger.Log("PUIManager - UI名格式错误:" + Child.name); Debug.Log(e.ToString()); } } } } #endregion ChangeUI <PInitialUI>(); }
/// <summary> /// 发送一个字符串 /// </summary> /// <param name="message">发送的字符串信息</param> public virtual void Send(string message) { PLogger.Log("发送消息:" + message); lock (sendQueue) { sendQueue.Enqueue(PNetworkConfig.MessageStartFlag + message + PNetworkConfig.MessageEndFlag); } }
private void StartExportCommandHandler() { try { if (string.IsNullOrEmpty(ExportPath) || CurrentExporter == null || !ExportNodes.Any()) { throw new NullReferenceException("Bad Export path // no export nodes // no exporter chosen"); } exportTask = Task.Run(() => { var dataList = new List <DataTuple>(); foreach (var node in ExportNodes) { dataList.AddRange(GatherExportList(node)); } ExportProcess(dataList); }); } catch (Exception ex) { MessageBoxInstance.Raise(ex.Message); PLogger.Log(ex.Message); } }
private void ProcessMessage(string message) { PLogger.Log("接收信息:" + message); List <string> messages = new List <string>(message.Split(' ')); messages.RemoveAll((string x) => x.Equals(string.Empty)); string[] MessageList = messages.ToArray(); if (MessageList.Length < 1) { return; } string OrderName = MessageList[0].Split('\'')[0]; try { int OrderIndex = Convert.ToInt32(MessageList[0].Split('\'')[1]); if (OrderIndex <= CurrentIndex) { PLogger.Log("不正当的信息:" + message); return; } else { CurrentIndex = OrderIndex; } POrder Order = POrder.GetOrder(OrderName); Order.ClientResponseAction(MessageList); } catch (Exception e) { PLogger.Log("客户端处理信息时发生错误:" + message); PLogger.Log(e.ToString()); } }
public P_YooHsi() : base(CardName, PCardType.DefensorCard) { Point = 3; Index = 51; foreach (PTime Time in new PTime[] { PTime.Card.AfterBecomeTargetTime }) { MoveInEquipTriggerList.Add((PPlayer Player, PCard Card) => { return(new PTrigger(CardName) { IsLocked = true, Player = Player, Time = Time, Condition = (PGame Game) => { PUseCardTag UseCardTag = Game.TagManager.FindPeekTag <PUseCardTag>(PUseCardTag.TagName); return UseCardTag.TargetList.Count >= 2 && UseCardTag.TargetList.Contains(Player) && UseCardTag.Card.Type.Equals(PCardType.SchemeCard); }, Effect = (PGame Game ) => { AnnouceUseEquipmentSkill(Player); PUseCardTag UseCardTag = Game.TagManager.FindPeekTag <PUseCardTag>(PUseCardTag.TagName); PLogger.Log("玉玺发动记录:" + UseCardTag.TargetList.Remove(Player)); } }); }); } }
public void SetField(string FieldName, object Value) { PLogger.Log("重设标签[" + Name + "." + FieldName + "] = " + Value.ToString()); PTagField TagField = FieldList.Find((PTagField Field) => Field.Name.Equals(FieldName)); if (TagField != null) { TagField.Field = Value; } }
private void BrowseCommandHandler() { try { ExportPath = FileDialogInstance.Raise(); } catch (Exception ex) { PLogger.Log(ex.Message); } }
public PRoom(PMode Mode) : this(Mode.PlayerNumber) { for (int i = 0; i < Mode.PlayerNumber; ++i) { PlayerList[i].PlayerType = Mode.Seats[i].DefaultType; PLogger.Log((i + 1).ToString() + " NICKNAME=" + PlayerList[i].Nickname + " NAME=" + Mode.Seats[i].Name); if (PlayerList[i].Nickname.Equals(string.Empty)) { PlayerList[i].Nickname = Mode.Seats[i].Name; } } }
public void Install(PMonitor Monitor) { TriggerList.ForEach((PTrigger Trigger) => { Monitor.AddTrigger(Trigger); }); Monitor.Game.PlayerList.ForEach((PPlayer Player) => { PPlayer TargetPlayer = Player; MultiPlayerTriggerList.ForEach((Converter <PPlayer, PTrigger> TriggerTemplate) => { Monitor.AddTrigger(TriggerTemplate(TargetPlayer)); }); }); PLogger.Log(" 规则装载完毕:" + Name); }
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()); } } }
public PMode3v1() : base("神兽模式", 4, new int[] { 1, 1, 1, 2 }) { Bonus = 5; Seats[3].DefaultType = PPlayerType.AI; Seats[3].Name = "青龙/白虎/朱雀/玄武"; Installer.Add(new PTrigger("神兽提前获取土地和房屋") { IsLocked = true, Time = PTime.InstallModeTime, Effect = (PGame Game) => { // 随机获得8个土地和2个商业用地 List <PBlock> LandList = Game.Map.BlockList.FindAll((PBlock _Block) => _Block.CanPurchase && !_Block.IsBusinessLand); List <PBlock> BusinessList = Game.Map.BlockList.FindAll((PBlock _Block) => _Block.CanPurchase && _Block.IsBusinessLand); PMath.Wash(LandList); PMath.Wash(BusinessList); int TotalLandCount = (LandList.Count + BusinessList.Count) / 3; int BusinessCount = BusinessList.Count / 3; int LandCount = TotalLandCount - BusinessCount; PLogger.Log(" 获得" + LandCount.ToString() + "领地;" + BusinessCount.ToString() + "商业用地"); List <PBlock> GotList = LandList.GetRange(0, LandCount); GotList.AddRange(BusinessList.GetRange(0, BusinessCount)); GotList.ForEach((PBlock Block) => { Block.Lord = Game.PlayerList[PlayerNumber - 1]; Block.HouseNumber = 1; if (Block.IsBusinessLand) { Block.BusinessType = PBusinessType.Institute; } PNetworkManager.NetworkServer.TellClients(new PRefreshBlockBasicOrder(Block)); }); } }); Installer.Add(new PTrigger("生成神兽") { IsLocked = true, Time = PTime.InstallModeTime, Effect = (PGame Game) => { List <PGeneral> PossibleBoss = new List <PGeneral>() { new P_QingLong(), new P_BaiHu(), new P_ZhuQue(), new P_XuanWu() }; PMath.Wash(PossibleBoss); Game.PlayerList[PlayerNumber - 1].General = PossibleBoss[0]; PNetworkManager.NetworkServer.TellClients(new PShowInformationOrder("BOSS:" + PossibleBoss[0].Name)); } }); }
public string Raise() { OpenFileDialog dialog = new OpenFileDialog() { Filter = DialogFilter }; if (dialog.ShowDialog() != DialogResult.OK && string.IsNullOrEmpty(dialog?.FileName)) { PLogger.Log("File dialog closed"); } return(dialog.FileName); }
private bool Connecting() { try { if (((Client.Client.Poll(1000, SelectMode.SelectRead) && (Client.Client.Available == 0)) || !Client.Client.Connected)) { return(false); } } catch (Exception e) { PLogger.Log("网络错误"); PLogger.Log(e.ToString()); return(false); } return(true); }
public T PopTag <T>(string Name) where T : PTag { T Tag = FindPeekTag <T>(Name); if (Tag != null) { PLogger.Log("销毁标签:" + Tag.Name); TagList.Remove(Tag); if (Owner != null) { PNetworkManager.NetworkServer.TellClients(new PRefreshMarkStringOrder(Owner)); } } return(Tag); }
/// <summary> /// 新建一个游戏 /// </summary> /// <param name="_Map">原型地图(新建的游戏采用其复制品)</param> /// <param name="_GameMode">游戏模式</param> public PGame(PMap _Map, PMode _GameMode) : base(_Map, _GameMode) { Room = new PRoom(GameMode); PLogger.Log("新建游戏,模式:" + GameMode.Name); this._Map = _Map; GameMode.Open(this); Logic = new PGameLogic(this); Monitor = new PMonitor(this); TagManager = new PTagManager(); CardManager = new PCardManager(this); GameMode.Install(this); StartGameFlag = false; EndGameFlag = false; ReadyToStartGameFlag = true; PreparedList = new List <bool>(); }
public PIntroduceSelfOrder() : base("hello", (string[] args, string IPAddress) => { string Nickname = args[1]; PLogger.Log("新的连接:" + Nickname + " @" + IPAddress); if (PNetworkManager.Game.Room.AddPlayer(Nickname, IPAddress)) { PLogger.Log("加入房间成功"); PNetworkManager.NetworkServer.TellClient(IPAddress, new PRoomModeOrder(PNetworkManager.Game.GameMode.Name)); PNetworkManager.NetworkServer.TellClients(new PRoomDataOrder(PNetworkManager.Game.Room.ToString())); } else { PLogger.Log("加入房间失败"); } }, null) { }
public PRoomDataOrder() : base("room", null, (string[] args) => { try { int Capacity = int.Parse(args[1]); PSystem.CurrentRoom = new PRoom(Capacity); #region 分析房间的属性 int Index = 2; for (int i = 0; i < Capacity; ++i) { PPlayerType playerType = FindInstance <PPlayerType>(args[Index++]); if (playerType != null) { PSystem.CurrentRoom.PlayerList[i].PlayerType = playerType; PSystem.CurrentRoom.PlayerList[i].Nickname = args[Index++]; if (PSystem.CurrentRoom.PlayerList[i].Nickname.Equals("&")) { PSystem.CurrentRoom.PlayerList[i].Nickname = string.Empty; } } } #endregion #region 更新RUI的数据(未打开则先打开)及开始游戏按钮可交互性 PUIManager.AddNewUIAction("RoomData-更新RUI数据", () => { if (!PUIManager.IsCurrentUI <PRoomUI>()) { PUIManager.ChangeUI <PRoomUI>(); //如果游戏已经开始,把游戏关闭 } PUIManager.GetUI <PRoomUI>().SeatList.ForEach((PRoomUI.PSeat Seat) => { Seat.Update(); }); PUIManager.GetUI <PRoomUI>().StartGameButton.interactable = PSystem.CurrentRoom.IsFull(); }); #endregion } catch (Exception e) { PLogger.Log("房间数据错误"); PLogger.Log(e.ToString()); } }) { }
private void ExportProcess(List <DataTuple> data) { try { ProgressBarMaximum = data.Count; CurrentExporter.ExportPath = ExportPath; CurrentExporter.Init("OutData"); IsStartButtonEnabled = false; IsStopButtonEnabled = true; IsPauseButtonEnabled = true; for (var index = 0; index < data.Count; ++index) { //check if we need to pause WaitHandle.WaitAny(new WaitHandle[] { pauseEvent, cancelEvent }); if (cancelationRequested) { PLogger.Log("Export cancellation requested"); cancelationRequested = false; ProgressBarValue = 0; return; } CurrentExporter.Export(data[index]); ProgressBarValue = index; } IsStartButtonEnabled = true; IsStopButtonEnabled = false; IsPauseButtonEnabled = false; ProgressBarValue = 0; } catch (Exception ex) { MessageBoxInstance.Raise(ex.Message); PLogger.Log(ex.Message); } }
public PSwitchSeatOrder() : base("switch_seat", (string[] args, string IPAddress) => { try { int TargetPlace = int.Parse(args[1]); if (!PNetworkManager.Game.Room.PlayerList[TargetPlace].PlayerType.Equals(PPlayerType.Player)) { if (PNetworkManager.Game.GameMode.Seats[TargetPlace].Locked) { } else { PNetworkManager.Game.Room.SwitchSeatAttribute(TargetPlace); PNetworkManager.NetworkServer.TellClients(new PRoomDataOrder(PNetworkManager.Game.Room.ToString())); } } } catch { PLogger.Log("SwitchSeat-错误:" + args[1]); } }, null) { }
/// <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; }); }
private void ProcessMessage(string message, string IPAddress) { PLogger.Log("接收信息 (" + IPAddress + "):" + message); List <string> messages = new List <string>(message.Split(' ')); messages.RemoveAll((string x) => x.Equals(string.Empty)); string[] MessageList = messages.ToArray(); if (MessageList.Length < 1) { return; } string OrderName = MessageList[0]; try { POrder Order = POrder.GetOrder(OrderName); Order.ServerResponseAction(MessageList, IPAddress); } catch (Exception e) { PLogger.Log("服务器处理信息时发生错误:" + message); PLogger.Log(e.ToString()); } }
public void GenerateNodeAndAdd(SubHandleCLI subHandle, ITreeNodeViewModel parent) { var storageType = (StorageType)subHandle?.GetType(); if (storageType != StorageType.IStorage) { PLogger.Log("Wrong/null storage passed..."); return; } var iStorage = subHandle.GetStorage(); if (iStorage.IsNull()) { PLogger.Log("iStorage was null"); return; } var node = Utilities.FormNodeFromStorage(iStorage); AddElementBack(node, parent); }
public PMoveSeatOrder() : base("move_seat", (string[] args, string IPAddress) => { try { int TargetPlace = int.Parse(args[1]); if (!PNetworkManager.Game.Room.PlayerList[TargetPlace].PlayerType.Equals(PPlayerType.Player)) { if (PNetworkManager.Game.GameMode.Seats[TargetPlace].Locked) { // 位置被锁定,不可更换 } else { PNetworkManager.Game.Room.MovePlayer(PNetworkManager.Game.Room.FindIndexByIPAddress(IPAddress), TargetPlace); PNetworkManager.NetworkServer.TellClients(new PRoomDataOrder(PNetworkManager.Game.Room.ToString())); } } } catch { PLogger.Log("MoveSeat-错误:" + args[1]); } }, null) { }
/// <summary> /// 启动结算 /// </summary> /// <param name="Name">添加的操作名</param> /// <param name="action">添加的操作方法</param> public void StartSettle(PSettle Settle) { SettleRecord NewSettleRecord = new SettleRecord(Settle); lock (SettleRecordStack) { SettleRecordStack.Push(NewSettleRecord); } PLogger.Log("开始结算 " + Settle.Name); NewSettleRecord.Settle.SettleAction(Game); //NewSettleRecord.ActionThread.Start(); //PThread.WaitUntil(() => NewSettleRecord.Finished); PLogger.Log("终止结算 " + Settle.Name); //if (NewSettleRecord.ActionThread.IsAlive) { // NewSettleRecord.ActionThread.Abort(); //} lock (SettleRecordStack) { if (SettleRecordStack.Count > 0 && NewSettleRecord.Equals(SettleRecordStack.Peek())) { SettleRecordStack.Pop(); } } }
/// <summary> /// Player的标签域不能有两个同名标签 /// </summary> /// <param name="Tag">如果为数字标签,数字相加</param> public void CreateTag(PTag Tag) { if (Owner != null && ExistTag(Tag.Name)) { if (Tag is PNumberedTag) { FindPeekTag <PNumberedTag>(Tag.Name).Value += ((PNumberedTag)Tag).Value; } else { PopTag <PTag>(Tag.Name); } } if (Owner == null || !ExistTag(Tag.Name)) { PLogger.Log("创建标签:" + Tag.Name); Tag.FieldList.ForEach((PTag.PTagField Field) => PLogger.Log(" 域 " + Field + " = " + (Field.Field != null ? Field.Field.ToString() : "null"))); TagList.Add(Tag); } if (Owner != null) { PNetworkManager.NetworkServer.TellClients(new PRefreshMarkStringOrder(Owner)); } }
private static string GetIPAddressList() { string IPv4Address = string.Empty; try { string hostName = Dns.GetHostName(); IPAddress[] addressArray = Dns.GetHostAddresses(hostName); foreach (IPAddress address in addressArray) { if (address.AddressFamily == AddressFamily.InterNetwork) { if (!IPv4Address.Equals(string.Empty)) { IPv4Address += ";"; } IPv4Address += address.ToString(); } } } catch (Exception e) { PLogger.Log("获取IP失败"); PLogger.Log(e.ToString()); } return(IPv4Address); }
public static GeneralTreeNodeViewModel FormNodeFromStorage(IStorageCLI storage) { if (storage == null || storage.IsNull()) { PLogger.Log("Node was null, skipping..."); return(null); } var newNode = new GeneralTreeNodeViewModel() { InnerStorage = storage }; //EnumStreams here var infoIt = new IIteratorCLI(); storage.EnumStreams(ref infoIt); var subHandle = new SubHandleCLI(); while (true) { bool isDone = infoIt?.ProcessNext(ref subHandle) ?? false; var type = subHandle?.GetType(); if (type != StorageType.BinaryStream || isDone) { break; } var stream = subHandle.GetBinaryStream(); ProcessNodeProperties(newNode, stream); } return(newNode); }
/// <summary> /// 开始游戏 /// </summary> /// 和客户端上的开始游戏不同,初始化玩家列表的时候 /// 从Room而非客户端用于同步的CurrentRoom获得数据 public new void StartGame(List <PGeneral> DefaultGenerals = null) { if (Room.IsFull()) { #region 初始化玩家列表 PlayerList = new List <PPlayer>(); for (int i = 0; i < PlayerNumber; ++i) { PPlayer Player = new PPlayer() { Index = i, Name = Room.PlayerList[i].PlayerType.Equals(PPlayerType.Player) ? Room.PlayerList[i].Nickname : "P" + (i + 1).ToString(), IsAlive = true, Money = PPlayer.Config.DefaultMoney, TeamIndex = GameMode.Seats[i].Party - 1 }; if (DefaultGenerals != null && i < DefaultGenerals.Count) { Player.General = DefaultGenerals[i]; } Player.Tags = new PTagManager(Player); PlayerList.Add(Player); PBlock Position = Map.BlockList.Find((PBlock Block) => Block.StartPointIndex == i % Map.StartPointNumber); if (Position != null) { PlayerList[i].Position = Position; } else { PlayerList[i].Position = Map.BlockList[0]; } } #endregion NowPlayer = null; NowPeriod = null; StartGameFlag = true; EndGameFlag = false; ReadyToStartGameFlag = false; CardManager.InitializeCardHeap(); PLogger.Log("开始进行规则装载"); PObject.ListSubTypeInstances <PSystemTriggerInstaller>().ForEach((PSystemTriggerInstaller Installer) => { Installer.Install(Monitor); }); PNetworkManager.NetworkServer.Game.PlayerList.ForEach((PPlayer Player) => { PNetworkManager.NetworkServer.TellClient(Player, new PStartGameOrder(Map.Name, Player.Index.ToString())); }); if (PSystem.AllAi) { Room.PlayerList.ForEach((PRoom.PlayerInRoom Player) => { Player.PlayerType = PPlayerType.AI; }); } NowPlayer = PlayerList[0]; Monitor.CallTime(PTime.InstallModeTime); if (DefaultGenerals == null) { Monitor.CallTime(PTime.ChooseGeneralTime); } Monitor.CallTime(PTime.StartGameTime); NowPeriod = PPeriod.StartTurn; PNetworkManager.NetworkServer.TellClients(new PStartTurnOrder(NowPlayerIndex.ToString())); Logic.StartLogic(PPeriod.StartTurn.Execute()); } }
public PXmlReader(string XmlFileName) { PLogger.Log("读入地图:" + XmlFileName); Document = new XmlDocument(); Document.Load(XmlFileName); }