package org.avslor.JourneyThroughAvslor.Engine.Shared.Utility;
import org.json.JSONObject;

import java.io.IOException;
import java.nio.file.Path;

/*   Copyright 2013 James Loyd , Joshua Theze
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
public class Utility
{
    public static double getAttackDamage(double attackPoints, double frequency)
    {
       return attackPoints * frequency;
    }

    /*
     * This will probably need to be refactored to read a change log or something. Or simply to drive a window of the UI
     * that we will call about.
     */
    public static void getProjectInfo()
    {
    }

    public static JSONObject getJSONOBject()
    {
        //for the time being
        return new JSONObject();
    }

    public static JSONObject readStoryAssets()
    {
        return new JSONObject();
    }

    public static String getExceptionType(String e)
    {
        int whereIsColon = 0;
        char[] someText = new char[e.length()];
        someText = e.toCharArray();
        StringBuffer buffer = new StringBuffer();
        for(int i =0; i<someText.length;i++)
        {
            if(someText[i]==':')
            {
                whereIsColon = i;
                break;
            }
        }
        for(int j=0;j<whereIsColon;j++)
        {
            buffer.append(someText[j]);
        }
        return buffer.toString();
    }

    public static String handleIT(Exception e) throws IOException
    {
        boolean isSecondTry = false;
        try
        {
            BugInfo tempBug = BugInfo.createBugReport(e);
            tempBug.SaveBugTxtFile();
            StringBuffer buffer = new StringBuffer();
            buffer.append("There was an error. \n\t");
            buffer.append("Bug" + tempBug.getBugNumber() + " has been created in somehwhere.");
            buffer.append("You may look at it and paste its contents as a bug on Github. \n");
            buffer.append("Sorry for the inconvenience. In most cases, you may continue to play the game.");
            return buffer.toString();
        }
        catch (IOException f)
        {
            StringBuffer buffer = new StringBuffer();
            if (isSecondTry == false)
            {
                buffer.append("Something went wrong. We will attempt one more time.");
                handleIT(f);
                isSecondTry = true;
            }
            else
            {
              buffer.append("\n During the second try, something messed up");
              buffer.append(" \n You will have to a manually create a bug report on github.");
            }

            return buffer.toString();
        }
    }

    public static String getVersion()
    {
        bugReportFolder();
        return "pre-alpha";
    }

    public static boolean bugReportFolder()
    {
        System.out.println(getLocalDirectory());
        return true;

    }

    public static String getLocalDirectory()
    {
        return  System.getProperty("user.dir");
    }
}

@@ -85,16 +85,37 @@
 bject;%0A%0A
+import java.io.File;%0A
 import j
@@ -160,16 +160,44 @@
 le.Path;
+%0Aimport java.nio.file.Paths;
 %0A%0A/*   C
@@ -3270,35 +3270,8 @@
   %7B%0A
-        bugReportFolder();%0A
     
@@ -3327,17 +3327,19 @@
 boolean 
-b
+IsB
 ugReport
@@ -3344,16 +3344,21 @@
 rtFolder
+There
 ()%0A    %7B
@@ -3370,35 +3370,59 @@
     
-System.out.println(getLocal
+File file = new File(%22./Bugs%22);%0A        if (file.is
 Dire
@@ -3429,17 +3429,16 @@
 ctory())
-;
 %0A       
@@ -3442,28 +3442,301 @@
     
-return true;%0A%0A    %7D%0A
+%7B%0A            return true;%0A        %7D%0A        else%0A        %7B%0A            return false;%0A        %7D%0A    %7D%0A%0A    public static void initializeBugFolder(boolean isItThere)%0A    %7B%0A        File file = new File(%22./Bugs%22);%0A        if(isItThere == false)%0A        %7B%0A            file.mkdir();%0A        %7D%0A    %7D
 %0A   

update to utility to check and see if bug folder is there