package com.elmakers.mine.bukkit.action.builtin;

import com.elmakers.mine.bukkit.action.BaseSpellAction;
import com.elmakers.mine.bukkit.api.action.CastContext;
import com.elmakers.mine.bukkit.api.magic.Mage;
import com.elmakers.mine.bukkit.api.spell.SpellResult;
import com.elmakers.mine.bukkit.api.wand.Wand;
import com.elmakers.mine.bukkit.api.wand.WandUpgradePath;

public class UpgradePathAction extends BaseSpellAction {

    @Override
    public SpellResult perform(CastContext context) {
        Mage mage = context.getMage();
        Wand wand = mage.getActiveWand();

        // For now... eventually I need to separate out the wand part, but not doing it now.
        if (wand == null) {
            return SpellResult.NO_TARGET;
        }

        com.elmakers.mine.bukkit.api.wand.WandUpgradePath path = wand.getPath();
        WandUpgradePath nextPath = path != null ? path.getUpgrade() : null;
        if (nextPath != null && path.checkUpgradeRequirements(wand, null) && !path.canEnchant(wand)) {
            path.upgrade(wand, mage);
            return SpellResult.CAST;
        }

        return SpellResult.NO_TARGET;
    }
}

@@ -43,16 +43,126 @@
 iltin;%0A%0A
+import java.util.Arrays;%0Aimport java.util.Collection;%0A%0Aimport org.bukkit.configuration.ConfigurationSection;%0A%0A
 import c
@@ -313,16 +313,65 @@
 c.Mage;%0A
+import com.elmakers.mine.bukkit.api.spell.Spell;%0A
 import c
@@ -521,16 +521,65 @@
 adePath;
+%0Aimport com.elmakers.mine.bukkit.spell.BaseSpell;
 %0A%0Apublic
@@ -628,16 +628,256 @@
 Action %7B
+%0A    private int upgradeLevels;%0A%0A    @Override%0A    public void prepare(CastContext context, ConfigurationSection parameters) %7B%0A        super.prepare(context, parameters);%0A        upgradeLevels = parameters.getInt(%22upgrade_levels%22, 0);%0A    %7D
 %0A%0A    @O
@@ -1186,32 +1186,205 @@
 GET;%0A        %7D%0A%0A
+        if (upgradeLevels %3E 0) %7B%0A            if (wand.enchant(upgradeLevels, mage, false) %3E 0) %7B%0A                return SpellResult.CAST;%0A            %7D%0A        %7D else %7B%0A    
         com.elma
@@ -1452,24 +1452,28 @@
 ();%0A        
+  
+  
 WandUpgradeP
@@ -1528,16 +1528,20 @@
 : null;%0A
+    
         
@@ -1647,16 +1647,20 @@
         
+    
 path.upg
@@ -1681,32 +1681,36 @@
 e);%0A            
+ 
+   
 return SpellResu
@@ -1710,32 +1710,46 @@
 ellResult.CAST;%0A
+            %7D%0A
         %7D%0A%0A     
@@ -1787,10 +1787,550 @@
 ;%0A    %7D%0A
+%0A%0A    @Override%0A    public void getParameterNames(Spell spell, Collection%3CString%3E parameters) %7B%0A        super.getParameterNames(spell, parameters);%0A%0A        parameters.add(%22upgrade_levels%22);%0A    %7D%0A%0A    @Override%0A    public void getParameterOptions(Spell spell, String parameterKey, Collection%3CString%3E examples) %7B%0A        if (parameterKey.equals(%22upgrade_levels%22)) %7B%0A            examples.addAll(Arrays.asList((BaseSpell.EXAMPLE_SIZES)));%0A        %7D else %7B%0A            super.getParameterOptions(spell, parameterKey, examples);%0A        %7D%0A    %7D%0A
 %7D%0A

Add upgrade_levels parameter to UpgradePath action