package cfvbaibai.cardfantasy.engine.skill;

import cfvbaibai.cardfantasy.CardFantasyRuntimeException;
import cfvbaibai.cardfantasy.GameUI;
import cfvbaibai.cardfantasy.Randomizer;
import cfvbaibai.cardfantasy.data.Skill;
import cfvbaibai.cardfantasy.data.SkillTag;
import cfvbaibai.cardfantasy.engine.*;

import java.util.ArrayList;
import java.util.List;

public class Reforming {
    public static void apply(SkillResolver resolver, SkillUseInfo skillUseInfo, CardInfo card,Player defender) throws HeroDieSignal{
        if (card == null || card.isDead())  {
            throw new CardFantasyRuntimeException("card should not be null or dead!");
        }
        if (card.hasUsed(skillUseInfo)) {
            return;
        }
        Skill skill = skillUseInfo.getSkill();
        resolver.getStage().getUI().useSkill(card, skill, true);
        GameUI ui = resolver.getStage().getUI();
        //重整不重置限定技能
//        for (SkillUseInfo victimSkillUseInfo : card.getAllUsableSkillsIgnoreSilence()) {
//            resolver.getStage().removeUsed(victimSkillUseInfo,skillUseInfo.getOwner().getOwner(),defender);
//        }
        ui.useSkill(card, card, skillUseInfo.getSkill(), true);
        Player attackPlayer = card.getOwner();
        resolver.killCard(card,card,skill);//改为杀死卡进入墓地
    //    resolver.resolveDeathSkills(card,victim,skillUseInfo.getSkill(),result);//新生可以发动死契
        if(card.getOwner() !=attackPlayer) {
            card.switchOwner(attackPlayer);
        }
        if (card.getStatus().containsStatus(CardStatusType.召唤)) {
            for(CardStatusItem summonedStatusItem:card.getStatus().getAllItems())
            {
                if(summonedStatusItem.getType()==CardStatusType.召唤){
                    Summon.newBornApply(resolver, skillUseInfo, card, SummonType.Summoning, 1,summonedStatusItem, card.getName());//新生卡牌可以立即攻击。
                    break;
                }
            }
            card.setUsed(skillUseInfo);
        } else {
            //处理顽强司命情况下，卡牌已经回到场上，不需要再次结算降临技能。
            if (card.isAlive()) {
                return;
            }
            //强制移除卡牌，防止新生以后出现卡牌复制。
            card.getOwner().getHand().removeCard(card);
            card.getOwner().getDeck().removeCard(card);
            card.getOwner().getField().removeCard(card);
            card.getOwner().getOutField().removeCard(card);
            defender.getHand().removeCard(card);
            defender.getDeck().removeCard(card);
            defender.getField().removeCard(card);
            defender.getOutField().removeCard(card);
            resolver.summonCard(card.getOwner(), card, null, false, skillUseInfo.getSkill(), 0);
            card.setUsed(skillUseInfo);
        }
    }

    public static void reset( SkillUseInfo skillUseInfo, CardInfo card) throws HeroDieSignal {
        if(card.hasUsed(skillUseInfo))
        {
            for (SkillEffect effect : card.getEffects()) {
                if (effect.getCause() == skillUseInfo && effect.getType() == SkillEffectType.SKILL_USED) {
                    card.removeEffect(effect);
                    return;
                }
            }
        }
    }
}

@@ -1538,24 +1538,76 @@
 Type.%E5%8F%AC%E5%94%A4)) %7B%0A
+            CardStatusItem summonStatusItem = null;%0A
             
@@ -1783,228 +1783,292 @@
     
-Summon.newBornApply(resolver, skillUseInfo, card, SummonType.Summoning, 1,summonedStatusItem, card.getName());//%E6%96%B0%E7%94%9F%E5%8D%A1%E7%89%8C%E5%8F%AF%E4%BB%A5%E7%AB%8B%E5%8D%B3%E6%94%BB%E5%87%BB%E3%80%82%0A                    break;%0A                %7D%0A            %7D%0A            card.setUsed(skillUseInfo
+summonStatusItem = summonedStatusItem;%0A                    break;%0A                %7D%0A            %7D%0A            card.reset();%0A            card.addStatus(summonStatusItem);%0A            card.setUsed(skillUseInfo);%0A            resolver.summonCard(card.getOwner(), card, card, true, skill,1
 );%0A 

修复召唤物无限发动【重整】导致模拟器卡死的问题