package cfvbaibai.cardfantasy.engine.skill;


import cfvbaibai.cardfantasy.CardFantasyRuntimeException;
import cfvbaibai.cardfantasy.data.CardSkill;
import cfvbaibai.cardfantasy.data.Skill;
import cfvbaibai.cardfantasy.data.SkillTag;
import cfvbaibai.cardfantasy.engine.Hand;
import cfvbaibai.cardfantasy.engine.SkillUseInfo;
import cfvbaibai.cardfantasy.engine.SkillResolver;
import cfvbaibai.cardfantasy.engine.CardInfo;

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

//给两个手牌添加技能
public class HandCardAddSkill {
    public static void apply(SkillResolver resolver, SkillUseInfo skillUseInfo, CardInfo card, Skill addSkill) {
        if (card == null || card.isDead()) {
            throw new CardFantasyRuntimeException("card should not be null or dead!");
        }
        Skill skill = skillUseInfo.getSkill();
        CardSkill cardSkill = new CardSkill(addSkill.getType(), addSkill.getLevel(), 0, false, false, false, false);
        resolver.getStage().getUI().useSkill(card, skill, true);
        List<CardInfo> allHandCards = card.getOwner().getHand().toList();
        CardInfo oneCard = null;
        CardInfo twoCard = null;
        List<CardInfo> addCard=new ArrayList<CardInfo>();
        for (CardInfo ally : allHandCards) {
            if(!(null ==oneCard)){
                if(ally.getSummonDelay()<oneCard.getSummonDelay())
                {
                    twoCard = oneCard;
                    oneCard =ally;
                }
                else if(!(null==twoCard))
                {
                    if(ally.getSummonDelay()<oneCard.getSummonDelay())
                    {
                        twoCard = ally;
                    }
                }
                else{
                    twoCard = ally;
                }
            }
            else{
                oneCard = ally;
            }
        }
        if(!(null ==oneCard))
        {
            addCard.add(oneCard);
        }
        if(!(null==twoCard))
        {
            addCard.add(twoCard);
        }
        for (CardInfo once : addCard) {
            if(once.containsAllUsableSkillsWithTag(SkillTag.抗沉默)&&addSkill.getType().containsTag(SkillTag.抗沉默))
            {
                continue;
            }
            cardSkill.setGiveSkill(1);
            if(once.containsUsableSkill(cardSkill.getType())){
                continue;
            }
            once.addSkill(cardSkill);
        }
    }

    //移除的结算在死亡移除buff时完成了。
//    public static void remove(SkillResolver resolver, SkillUseInfo skillUseInfo, CardInfo card,Skill addSkill) {
//        CardSkill cardSkill = new CardSkill(addSkill.getType(), addSkill.getLevel(), 0, false, false, false, false);
//        for (CardInfo ally : card.getOwner().getField().toList()) {
//            if (ally == null) { continue; }
//            ally.removeSkill(cardSkill);
//        }
//    }

//    public static void removeAll(SkillResolver resolver,SkillUseInfo skillUseInfo,CardInfo card) {
//        card.removeAllGiveSkill();
//    }
}

@@ -39,16 +39,68 @@
 kill;%0A%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import c
@@ -319,58 +319,12 @@
 ine.
-Hand;%0Aimport cfvbaibai.cardfantasy.engine.SkillUse
+Card
 Info
@@ -416,68 +416,20 @@
 ine.
-CardInfo;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List
+SkillUseInfo
 ;%0A%0A/
@@ -1212,34 +1212,33 @@
       if
-(!(null ==oneCard)
+ (oneCard != null
 )%7B%0A     
@@ -1242,32 +1242,33 @@
               if
+ 
 (ally.getSummonD
@@ -1265,33 +1265,35 @@
 getSummonDelay()
-%3C
+ %3C 
 oneCard.getSummo
@@ -1301,32 +1301,16 @@
 Delay())
-%0A               
  %7B%0A     
@@ -1372,16 +1372,17 @@
 neCard =
+ 
 ally;%0A  
@@ -1424,42 +1424,26 @@
 e if
-(!(null==twoCard))%0A               
+ (twoCard != null)
  %7B%0A 
@@ -1463,16 +1463,17 @@
       if
+ 
 (ally.ge
@@ -1512,36 +1512,16 @@
 Delay())
-%0A                   
  %7B%0A     
@@ -1594,37 +1594,22 @@
        %7D
-%0A               
  else
+ 
 %7B%0A      
@@ -1673,25 +1673,14 @@
    %7D
-%0A           
  else
+ 
 %7B%0A  
@@ -1747,35 +1747,26 @@
   if
-(!(null ==oneCard))%0A       
+ (oneCard != null)
  %7B%0A 
@@ -1822,34 +1822,26 @@
   if
-(!(null==twoCard))%0A       
+ (twoCard != null)
  %7B%0A 
@@ -1929,32 +1929,33 @@
 %7B%0A            if
+ 
 (once.containsAl
@@ -2035,28 +2035,16 @@
 ag.%E6%8A%97%E6%B2%89%E9%BB%98))
-%0A           
  %7B%0A     
@@ -2131,16 +2131,17 @@
       if
+ 
 (once.co

Fix some code warnings