123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ET.Server
- {
- [FriendOf(typeof (HGHHMainCheckerComponent))]
- public static class HGHHMainCheckerComponentSystem
- {
- [ObjectSystem]
- public class HGHHMainCheckerComponentAwakeSystem: AwakeSystem<HGHHMainCheckerComponent>
- {
- protected override void Awake(HGHHMainCheckerComponent self)
- {
- Log.Info($"创建黄冈晃晃主逻辑组件...");
- self.Flag = false;
- self.Time = 0;
- self.State = 0;
- self.Players = new Player[4];
- self.CurrentRound = 0;
- self.CardList = new List<int>();
-
- for (int i = 0; i < 4; i++)
- {
- foreach (int value in HghhConstValue.Values)
- {
- self.CardList.Add(value);
- }
- RandomGenerator.Shuffle(self.CardList);
- }
- }
- }
-
- [ObjectSystem]
- public class HGHHMainCheckerComponentDestroySystem: DestroySystem<HGHHMainCheckerComponent>
- {
- protected override void Destroy(HGHHMainCheckerComponent self)
- {
- Log.Info($"销毁黄冈晃晃主逻辑组件...");
- }
- }
- [ObjectSystem]
- public class HGHHMainCheckerComponentUpdateSystem: UpdateSystem<HGHHMainCheckerComponent>
- {
- protected override void Update(HGHHMainCheckerComponent self)
- {
- Room room = self.GetParent<Room>();
- if (room == null)
- {
- Log.Error($"黄冈晃晃主逻辑组件获取不到主实体...");
- return;
- }
- Log.Debug($"检测: 黄冈晃晃-房间号:{room.RoomId}, 状态:{self.State}...");
-
- try
- {
- self.Check(room);
- }
- catch (Exception e)
- {
- Log.Error($"move timer error: {self.Id}\n{e}");
- }
- }
- }
- private static void Check(this HGHHMainCheckerComponent self, Room room)
- {
- Log.Debug($"检测: 黄冈晃晃-房间号:{room.RoomId}...");
- switch (self.State)
- {
- case 0:
-
- Log.Debug($"检测: 黄冈晃晃-房间号:{room.RoomId}, 状态:检测是否可开局...");
- if (self.CheckReadySatrt(room))
- {
- self.State = 1;
- self.Flag = false;
- self.Time = 0;
- }
- break;
- case 1:
-
- if (!self.Flag)
- {
- if (self.Time >= 3)
- {
- self.Start(room);
- self.Flag = true;
- self.Time = 0;
- Log.Debug($"检测: 黄冈晃晃-房间号:{room.RoomId}, 状态:开局...VS动画...");
- }
- }
- else
- {
- if (self.Time > 0)
- {
- self.State = 2;
- self.Flag = false;
- self.Time = 0;
- }
- }
- break;
- case 2:
-
- if (!self.Flag)
- {
- self.Flag = true;
- self.Time = 0;
-
- self.DrawCard(room);
- }
- else
- {
-
- if (self.Time > 30)
- {
-
- }
- }
- break;
- case 3:
-
-
- break;
- }
- self.Time++;
- }
-
-
-
-
-
-
- private static bool CheckReadySatrt(this HGHHMainCheckerComponent self, Room room)
- {
- if (!room.IsStart() || self.State != 0)
- {
- return false;
- }
-
-
- foreach (Player player in room.GetAllPlayers().Values.Where(player => player != null))
- {
- MessageHelper.SendToClient(player, new G2C_ReadySatrtPush(){ReadySatrtTime = 3});
- }
- return true;
- }
-
-
-
-
-
- private static void Start(this HGHHMainCheckerComponent self, Room room)
- {
- self.CurrentRound += 1;
-
- int rand1 = RandomGenerator.RandomNumber(1, 7);
- int rand2 = RandomGenerator.RandomNumber(1, 7);
- self.Rand = new[] { rand1, rand2 };
-
- self.ZhuangPos = (rand1 + rand2) % 4;
-
- self.CurrentPlayer = room.GetAllPlayers()[self.ZhuangPos];
-
- self.DrawCardPlayer = room.GetAllPlayers()[self.ZhuangPos];
-
- self.SendCard(room);
-
- for (int index = 0; index < room.GetAllPlayers().Count; index++)
- {
- Player player = room.GetAllPlayers()[index];
- if (player != null)
- {
- player.State = 2;
- RoomInfo roomInfo = new RoomInfo();
- roomInfo.Type = 1;
- roomInfo.State = self.State;
- roomInfo.Time = self.Time;
- roomInfo.Rand1 = self.Rand[0];
- roomInfo.Rand2 = self.Rand[1];
- roomInfo.CardNum = self.CardList.Count;
-
- roomInfo.MyInfo = self.PlayerInfoToProto(player, true);
-
- roomInfo.OtherInfo = new List<PlayerInfo>();
- int[] nextPos = room.GetSorcPos(index);
- foreach (int pos in nextPos)
- {
- Player other = room.GetAllPlayers()[pos];
- if (other != null)
- {
- roomInfo.OtherInfo.Add(self.PlayerInfoToProto(other, false));
- }
- }
- MessageHelper.SendToClient(player, new G2C_SatrtPush(){info = roomInfo});
-
- Log.Info($"房间id={room.RoomId}, 玩家id={player.Id}, 玩家={player.Name}, 手牌信息={player.RemainCards}");
- }
- }
- }
-
-
-
-
-
-
- private static void SendCard(this HGHHMainCheckerComponent self, Room room)
- {
- foreach (Player player in room.GetAllPlayers().Values)
- {
- if (player == null)
- {
- continue;
- }
- for (int i = 0; i < 13; i++)
- {
- int card = self.CardList[0];
- player.RemainCards.Add(card);
- self.CardList.RemoveAt(0);
- }
- }
- }
-
-
-
-
-
- private static void DrawCard(this HGHHMainCheckerComponent self, Room room)
- {
-
- }
-
-
-
-
-
-
-
- public static RoomInfo RoomToProto(this HGHHMainCheckerComponent self, Room room)
- {
- RoomInfo info = new ();
- info.RoomId = room.RoomId;
- info.Type = room.Type;
- info.OwnerId = room.OwnerId;
- info.State = self.State;
-
-
-
-
-
-
- return info;
- }
-
-
-
-
-
-
-
- public static PlayerInfo PlayerInfoToProto(this HGHHMainCheckerComponent self, Player player, bool flag)
- {
- PlayerInfo info = new ();
- info.id = player.Id;
- info.name = player.Name;
- info.sex = player.Sex;
- info.exp = player.Exp;
- info.level = player.Level;
- info.vip = 0;
- info.pos = player.Pos;
- info.state = player.State;
- info.isAuto = player.IsAuto;
- info.cardInfo = new CardInfo();
- if (flag)
- {
- info.cardInfo.RemainCards = player.RemainCards;
- }
- info.cardInfo.RemainCardsNum = player.RemainCards.Count;
- info.cardInfo.DisCards = player.DisCards;
-
- return info;
- }
- }
- }
|