Esempio n. 1
0
        public async Task <bool> createToken(THHGame game, CardDefine define, int position)
        {
            if (game == null)
            {
                throw new ArgumentNullException(nameof(game));
            }
            if (define == null)
            {
                throw new ArgumentNullException(nameof(define));
            }
            if (field.count >= field.maxCount)
            {
                return(false);
            }
            await game.triggers.doEvent(new CreateTokenEventArg()
            {
                player = this, define = define, position = position
            }, async arg =>
            {
                THHPlayer player = arg.player;
                define           = arg.define;
                position         = arg.position;
                if (field.count >= field.maxCount)
                {
                    return;
                }
                game.logger.log(player + "召唤" + define.GetType().Name + "位于" + position);
                arg.card = game.createCard(define);
                await tryPutIntoField(game, null, arg.card, position);
            });

            return(true);
        }
Esempio n. 2
0
        static GenericMenu getMenu(SerializedProperty property)
        {
            int         id   = property.intValue;
            GenericMenu menu = new GenericMenu();

            menu.AddItem(new GUIContent("None"), id == 0, () =>
            {
                property.intValue = 0;
                property.serializedObject.ApplyModifiedProperties();
            });
            foreach (var group in getCardDefines().GroupBy(c => c.getCharacterID()))
            {
                CardDefine character = getCardDefines().FirstOrDefault(c => c.id == group.Key);
                foreach (var define in group.OrderBy(c => c.GetType().Name))
                {
                    string path = "";
                    if (character != null)
                    {
                        path = character.GetType().Name;
                    }
                    else
                    {
                        path = "Neutral";
                    }
                    int typeId = define.getCategory();
                    if (typeId == CardCategory.SERVANT)
                    {
                        path += "/Servant";
                    }
                    else if (typeId == CardCategory.SKILL)
                    {
                        path += "/Skill";
                    }
                    else if (typeId == CardCategory.SPELL)
                    {
                        path += "/Spell";
                    }
                    else if (typeId == CardCategory.ITEM)
                    {
                        path += "/Item";
                    }
                    path += "/" + define.GetType().Name;
                    menu.AddItem(new GUIContent(path), define.id == id, () =>
                    {
                        property.intValue = define.id;
                        property.serializedObject.ApplyModifiedProperties();
                    });
                }
            }
            return(menu);
        }
        bool isExcelContainCard(Worksheet sheet, CardDefine card)
        {
            int idIndex    = findColIndex(sheet, "ID");
            int classIndex = findColIndex(sheet, "Class");

            foreach (var pRow in sheet.Cells.Rows)
            {
                if (numberToInt(pRow.Value.GetCell(idIndex).Value) == card.id)
                {
                    return(true);
                }
                else if (pRow.Value.GetCell(classIndex).StringValue == card.GetType().Name)
                {
                    return(true);
                }
            }
            return(false);
        }
        void saveCardToXml(CardDefine card, XmlDocument xml)
        {
            xml["Card"]["ID"].InnerText = card.id.ToString();
            if (card is ServantCardDefine)
            {
                xml["Card"]["Type"].InnerText = "Servant";
            }
            else if (card is MasterCardDefine)
            {
                xml["Card"]["Type"].InnerText = "Master";
            }
            else if (card is SkillCardDefine)
            {
                xml["Card"]["Type"].InnerText = "Skill";
            }
            xml["Card"]["Cost"].InnerText   = card.getProp <int>("cost").ToString();
            xml["Card"]["Attack"].InnerText = card.getProp <int>("attack").ToString();
            xml["Card"]["Life"].InnerText   = card.getProp <int>("life").ToString();
            if (card.getProp <string[]>("tags") is string[] tags)
            {
                xml["Card"]["Tags"].InnerText = string.Join(",", tags);
            }
            else
            {
                xml["Card"]["Tags"].InnerText = null;
            }
            if (card.getProp <string[]>("keywords") is string[] keywords)
            {
                xml["Card"]["Keywords"].InnerText = string.Join(",", keywords);
            }
            else
            {
                xml["Card"]["Keywords"].InnerText = null;
            }
            if (_manager != null)
            {
                var skin = _manager.getSkin(card.id);
                xml["Card"]["Skin"]["Image"].InnerText = skin == null ? null : skin.image != null ? skin.image.name + ".png" : null;
                xml["Card"]["Skin"]["Name"].InnerText  = skin == null?card.GetType().Name : skin.name;

                xml["Card"]["Skin"]["Desc"].InnerText = skin == null ? null : skin.desc;
            }
        }
Esempio n. 5
0
 public bool isStandardCard(CardDefine c)
 {
     if (c.id == 0)
     {
         return(false);
     }
     if (c.GetType().Assembly != typeof(THHGame).Assembly)
     {
         return(false);
     }
     //if (!(c is SpellCardDefine))
     //{
     //    if (!(c is ServantCardDefine) && !(c is GeneratedCardDefine))
     //        return false;
     //}
     if (!(c is ServantCardDefine) && !(c is GeneratedCardDefine))
     {
         return(false);
     }
     if (c is ServantCardDefine servant)
     {
         if (servant.isToken)
         {
             return(false);
         }
     }
     else if (c is GeneratedCardDefine generated)
     {
         if (generated.type != CardDefineType.SERVANT)
         {
             return(false);
         }
         if (generated.getProp <bool>(nameof(ServantCardDefine.isToken)))
         {
             return(false);
         }
     }
     return(true);
 }
        void saveCardToExcel(CardDefine card, Worksheet sheet)
        {
            int idIndex    = findColIndex(sheet, "ID");
            int classIndex = findColIndex(sheet, "Class");
            int cardRow    = sheet.Cells.Rows.Count;//如果表里没有这张卡,那么就新增

            foreach (var pRow in sheet.Cells.Rows)
            {
                if (numberToInt(pRow.Value.GetCell(idIndex).Value) == card.id)
                {
                    cardRow = pRow.Key;//如果有相同ID的卡,复写
                    sheet.Cells[cardRow, classIndex] = new Cell(card.GetType().Name);
                }
                else if (pRow.Value.GetCell(classIndex).StringValue == card.GetType().Name)
                {
                    cardRow = pRow.Key;//如果有相同类型的卡,复写
                    sheet.Cells[cardRow, idIndex] = new Cell(card.id);
                }
            }

            sheet.Cells[cardRow, idIndex] = new Cell(card.id);
            int typeIndex = findColIndex(sheet, "Type");

            if (card is ServantCardDefine)
            {
                sheet.Cells[cardRow, typeIndex] = new Cell("Servant");
            }
            else if (card is MasterCardDefine)
            {
                sheet.Cells[cardRow, typeIndex] = new Cell("Master");
            }
            else if (card is SkillCardDefine)
            {
                sheet.Cells[cardRow, typeIndex] = new Cell("Skill");
            }
            else if (card is SpellCardDefine)
            {
                sheet.Cells[cardRow, typeIndex] = new Cell("Spell");
            }
            else if (card is ItemCardDefine)
            {
                sheet.Cells[cardRow, typeIndex] = new Cell("Item");
            }
            int costIndex = findColIndex(sheet, "Cost");

            sheet.Cells[cardRow, costIndex] = new Cell(card.getProp <int>("cost"));
            int attackIndex = findColIndex(sheet, "Attack");

            sheet.Cells[cardRow, attackIndex] = new Cell(card.getProp <int>("attack"));
            int lifeIndex = findColIndex(sheet, "Life");

            sheet.Cells[cardRow, lifeIndex] = new Cell(card.getProp <int>("life"));
            int tagsIndex = findColIndex(sheet, "Tags");

            if (card.getProp <string[]>("tags") is string[] tags)
            {
                sheet.Cells[cardRow, tagsIndex] = new Cell(string.Join(",", tags));
            }
            else
            {
                sheet.Cells[cardRow, tagsIndex] = new Cell(null);
            }
            int keywordsIndex = findColIndex(sheet, "Keywords");

            if (card.getProp <string[]>("keywords") is string[] keywords)
            {
                sheet.Cells[cardRow, keywordsIndex] = new Cell(string.Join(",", keywords));
            }
            else
            {
                sheet.Cells[cardRow, keywordsIndex] = new Cell(null);
            }
            if (_manager != null)
            {
                var skin       = _manager.getSkin(card.id);
                int imageIndex = findColIndex(sheet, "Image");
                if (skin == null)
                {
                    sheet.Cells[cardRow, imageIndex] = new Cell(sheet.Cells[cardRow, imageIndex].StringValue);
                }
                else
                {
                    if (skin.image != null && !string.IsNullOrEmpty(skin.image.name))
                    {
                        string path = AssetDatabase.GetAssetPath(skin.image);
                        if (path.Contains("Resources/"))
                        {
                            path = path.removeHead("Resources/").removeRear(".");
                            sheet.Cells[cardRow, imageIndex] = new Cell("res:" + path);
                        }
                        else
                        {
                            sheet.Cells[cardRow, imageIndex] = new Cell(skin.image.name + ".png");
                        }
                    }
                    else
                    {
                        sheet.Cells[cardRow, imageIndex] = new Cell(sheet.Cells[cardRow, imageIndex].StringValue);
                    }
                }
                int nameIndex = findColIndex(sheet, "Name");
                sheet.Cells[cardRow, nameIndex] = new Cell(skin == null ? (!string.IsNullOrEmpty(sheet.Cells[cardRow, nameIndex].StringValue) ? sheet.Cells[cardRow, nameIndex].StringValue : card.GetType().Name) : skin.name);
                int descIndex = findColIndex(sheet, "Desc");
                sheet.Cells[cardRow, descIndex] = new Cell(skin == null ? sheet.Cells[cardRow, descIndex].StringValue : skin.desc);
            }
        }
Esempio n. 7
0
        void saveCardToExcel(CardDefine card, Worksheet sheet)
        {
            int idIndex  = findColIndex(sheet, "ID");
            int rowIndex = sheet.Cells.Rows.Count;

            foreach (var pRow in sheet.Cells.Rows)
            {
                if (numberToInt(pRow.Value.GetCell(idIndex).Value) == card.id)
                {
                    rowIndex = pRow.Key;
                }
            }

            sheet.Cells[rowIndex, idIndex] = new Cell(card.id);
            int typeIndex = findColIndex(sheet, "Type");

            if (card is ServantCardDefine)
            {
                sheet.Cells[rowIndex, typeIndex] = new Cell("Servant");
            }
            else if (card is MasterCardDefine)
            {
                sheet.Cells[rowIndex, typeIndex] = new Cell("Master");
            }
            else if (card is SkillCardDefine)
            {
                sheet.Cells[rowIndex, typeIndex] = new Cell("Skill");
            }
            else if (card is SpellCardDefine)
            {
                sheet.Cells[rowIndex, typeIndex] = new Cell("Spell");
            }
            int costIndex = findColIndex(sheet, "Cost");

            sheet.Cells[rowIndex, costIndex] = new Cell(card.getProp <int>("cost"));
            int attackIndex = findColIndex(sheet, "Attack");

            sheet.Cells[rowIndex, attackIndex] = new Cell(card.getProp <int>("attack"));
            int lifeIndex = findColIndex(sheet, "Life");

            sheet.Cells[rowIndex, lifeIndex] = new Cell(card.getProp <int>("life"));
            int tagsIndex = findColIndex(sheet, "Tags");

            if (card.getProp <string[]>("tags") is string[] tags)
            {
                sheet.Cells[rowIndex, tagsIndex] = new Cell(string.Join(",", tags));
            }
            else
            {
                sheet.Cells[rowIndex, tagsIndex] = new Cell(null);
            }
            int keywordsIndex = findColIndex(sheet, "Keywords");

            if (card.getProp <string[]>("keywords") is string[] keywords)
            {
                sheet.Cells[rowIndex, keywordsIndex] = new Cell(string.Join(",", keywords));
            }
            else
            {
                sheet.Cells[rowIndex, keywordsIndex] = new Cell(null);
            }
            if (_manager != null)
            {
                var skin       = _manager.GetCardSkin(card.id);
                int imageIndex = findColIndex(sheet, "Image");
                sheet.Cells[rowIndex, imageIndex] = new Cell(skin == null ? null : skin.image != null ? skin.image.name + ".png" : null);
                int nameIndex = findColIndex(sheet, "Name");
                sheet.Cells[rowIndex, nameIndex] = new Cell(skin == null ? card.GetType().Name : skin.name);
                int descIndex = findColIndex(sheet, "Desc");
                sheet.Cells[rowIndex, descIndex] = new Cell(skin == null ? null : skin.desc);
            }
        }