/// <summary>
        /// 下面传上来的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void DoAction(object sender, EventArgs args)
        {
            // 处理抽卡完成的事件
            if (args is CardDrewEventArgs)
            {
                var arg = args as CardDrewEventArgs;
                UberDebug.LogDebugChannel("Frontend", $"卡{arg}抽出完毕");
                if (arg.CardRID == lastDrawCardRID)
                {
                    savedCallback?.Invoke(this, null);
                    lastDrawCardRID = -1;
                    savedCallback   = null;
                }
            }

            // 预览随从
            if (args is RetinuePreview)
            {
                servantPreviewInsert((args as RetinuePreview).Position);
            }

            if (args is IPlayerEventArgs)
            {
                (args as IPlayerEventArgs).PlayerID = SelfID;
                OnDeckAction?.Invoke(sender, args);
            }
        }
        /// <summary>
        /// 初始抽卡
        /// </summary>
        /// <param name="cards"></param>
        public void InitDraw(CardID[] cards)
        {
            GenericAction a = (evt, arg) =>
            {
                UberDebug.LogDebugChannel("Frontend", "准备进入抽卡选择模式");
                enterThrowingMode(0, 0);
            };

            DrawCard(cards, a);
        }
 void executeNext()
 {
     if (witnessQueue.Count == 0)
     {
         UberDebug.LogDebugChannel("Frontend", "所有事件播放完毕");
         QueueEmpty = true;
     }
     else
     {
         var witness = witnessQueue.Dequeue();
         UberDebug.LogDebugChannel("Frontend", $"准备播放{witness}, 队列剩余{witnessQueue.Count}");
         EventWitnessExecutor.ExecuteWitness(witness, this, (a, b) => { executeNext(); });
     }
 }
Beispiel #4
0
        public static CardDefine[] getCardDefines(Assembly[] assemblies, ILogger logger)
        {
            List <CardDefine> cardList = new List <CardDefine>();

            foreach (Assembly assembly in assemblies)
            {
                foreach (Type type in assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(CardDefine)) && !t.IsAbstract && t != typeof(GeneratedCardDefine)))
                {
                    ConstructorInfo constructor = type.GetConstructor(new Type[0]);
                    if (constructor != null)
                    {
                        if (constructor.Invoke(new object[0]) is CardDefine define)
                        {
                            try
                            {
                                if (logger == null)
                                {
                                    UberDebug.LogDebugChannel("Load", "加载内置卡片" + define.ToJson());
                                }
                                else
                                {
                                    logger.log("Load", "加载内置卡片" + define.ToJson());
                                }
                                cardList.Add(define);
                            }
                            catch (Exception e)
                            {
                                if (e.InnerException is NotImplementedException)
                                {
                                    if (logger == null)
                                    {
                                        UberDebug.LogWarningChannel("Load", "忽略尚未完成的卡片" + define);
                                    }
                                    else
                                    {
                                        logger.log("Load", "忽略尚未完成的卡片" + define);
                                    }
                                }
                                else
                                {
                                    throw e;
                                }
                            }
                        }
                    }
                }
            }
            return(cardList.ToArray());
        }
        public void sendWitness(EventWitness witness)
        {
            witnessQueue.Enqueue(witness);
            UberDebug.LogDebugChannel("Frontend", $"{name} 收到事件{witness}");
            var lastStatus = QueueEmpty;

            QueueEmpty = false;

            // 当前活动且没有执行witness时,开始执行
            if (gameObject.activeSelf)
            {
                if (lastStatus)
                {
                    executeNext();
                }
                else
                {
                    DebugUtils.Debug($"{name}收到事件,当前Active但有事件block");
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// 用卡
        /// </summary>
        /// <param name="args"></param>
        void UseCard(UseCardEventArgs args)
        {
            UberDebug.LogDebugChannel("Frontend", $"玩家{args.PlayerID}使用卡牌{args.CardRID},{args}");
            int position = -1;

            int[] target = new int[0];
            if (args is UseCardWithPositionArgs)
            {
                position = (args as UseCardWithPositionArgs).Position;
            }
            else if (args is UseCardWithTargetArgs)
            {
                var arg = args as UseCardWithTargetArgs;
                target = arg.TargetCardRuntimeID;
            }
            else if (args is UseCardWithTargetPositionArgs)
            {
                var arg = args as UseCardWithTargetPositionArgs;
                position = arg.Position;
                target   = arg.TargetCardRuntimeID;
            }
            //gm.Game.use(args.PlayerID, args.CardRID, position, target);
        }
        /// <summary>
        /// 内部丢卡
        /// </summary>
        /// <param name="throwCards"></param>
        /// <param name="callback"></param>
        private void throwCardsInternal(CardViewModel[] throwCards, GenericAction callback = null)
        {
            if (throwCards.Length == 0)
            {
                callback?.Invoke(this, null);
                return;
            }

            GenericAction throwCallback = (s, a) =>
            {
                UberDebug.LogDebugChannel("Frontend", $"准备销毁{s}");
                Destroy((s as MonoBehaviour).gameObject);
            };

            GenericAction realCallback = throwCallback + callback;

            for (int i = 0; i < throwCards.Length; i++)
            {
                throwCards[i].RecvAction(new CardToStackEventArgs()
                {
                    Count = throwCards.Length, Index = i
                }, i == 0 ? realCallback : throwCallback);
            }
        }
 /// <summary>
 /// 使用这张卡
 /// </summary>
 public void Use(UseCardEventArgs arg)
 {
     UberDebug.LogDebugChannel("Frontend", $"使用卡{this}");
     DoAction(arg);
 }
Beispiel #9
0
        /// <summary>
        /// 从给出的路径中加载卡片和皮肤,支持通配符,比如“Cards/*.xls”
        /// </summary>
        /// <param name="excelPaths"></param>
        /// <returns></returns>
        public async Task load(string[] excelPaths, Assembly[] assemblies = default, ILogger logger = null, ILogger screenLogger = null)
        {
            //加载内置卡片
            screenLogger?.log("加载内置卡片");
            if (assemblies == default)
            {
                assemblies = AppDomain.CurrentDomain.GetAssemblies();
            }
            List <CardDefine> cardList = new List <CardDefine>(CardHelper.getCardDefines(assemblies, logger));

            List <string> pathList = new List <string>();

            foreach (var excelPath in excelPaths)
            {
                // 判断文件夹
                if (excelPath.Contains("*") || excelPath.Contains("?"))
                {
                    if (!PlatformCompability.Current.RequireWebRequest)
                    {
                        var pathes = ResourceManager.GetDirectoryFiles(excelPath);
                        // 去重
                        foreach (var item in pathes)
                        {
                            if (!pathList.Contains(item))
                            {
                                pathList.Add(item);
                            }
                        }
                    }
                }
                else
                {
                    if (!pathList.Contains(excelPath))
                    {
                        pathList.Add(excelPath);
                    }
                }
            }

            //加载外置卡片
            foreach (string path in pathList)
            {
                try
                {
                    screenLogger?.log("加载卡片集:" + Path.GetFileNameWithoutExtension(path));

                    CardDefine[] cards = await loadCards(path);

                    foreach (var card in cards)
                    {
                        CardDefine older = cardList.Find(c => c.id == card.id);
                        if (older != null)
                        {
                            older.merge(card);
                            UberDebug.LogDebugChannel("Load", "数据覆盖:" + card.ToJson());
                        }
                        else
                        {
                            cardList.Add(card);
                        }
                    }
                }
                catch (Exception e)
                {
                    UberDebug.LogError("读取外部卡牌文件" + path + "失败,发生异常:" + e);
                }
            }
            foreach (CardDefine card in cardList)
            {
                if (defineDic.ContainsKey(card.id))
                {
                    Debug.LogWarning("存在重复ID的卡片" + defineDic[card.id] + "和" + card);
                    continue;
                }
                defineDic.Add(card.id, card);
            }
            //加载内置皮肤
            skinDic.Clear();
            foreach (CardSkinData skin in _skins)
            {
                if (skin.image == null)
                {
                    skin.image = await getDefaultSprite();
                }
                skinDic.Add(skin.id, skin);
            }
            foreach (string path in pathList)
            {
                try
                {
                    CardSkinData[] skins = await loadSkins(path, logger : screenLogger);

                    foreach (var skin in skins)
                    {
                        if (skinDic.ContainsKey(skin.id))
                        {
                            Debug.LogWarning("存在重复ID的皮肤" + skinDic[skin.id] + "和" + skin);
                            continue;
                        }
                        skinDic.Add(skin.id, skin);
                    }
                }
                catch (Exception e)
                {
                    UberDebug.LogError("读取外部皮肤文件" + path + "失败,发生异常:" + e);
                }
            }
        }
Beispiel #10
0
 public static void Debug(string message, UnityEngine.Object context = null)
 {
     UberDebug.LogDebugChannel("Frontend", message, context);
 }