Here is the code segment.
def createNewRecipe(stringToParse)
#first check for nil and comments
return nil if stringToParse == nil
return nil if stringToParse.strip.empty?
return nil if stringToParse.lstrip.index("#") != nil
#first parse out the text info
#split at the whitespace
attributes = stringToParse.split
name = attributes[0].gsub("_", " ") #the first position is name
itemType = attributes[1].to_i #2nd is item type
numOfIngs = attributes[2].to_i #3nd position is the num of ingredients
x = 0
ingreds = [] #ingredients start at the 3rd position
while x < numOfIngs
number = attributes[x + 3]
ingredientType = number[0,1].to_i
index = number[1,number.length - 1].to_i
case ingredientType #switch for ingredients
when 0
ingreds.push($data_items[index])
when 1
ingreds.push($data_weapons[index])
when 2
ingreds.push($data_armors[index])
end
x += 1
end
y = 0
amounts = [] #amounts start after the ingredients
while y < numOfIngs
amounts.push(attributes[x + y + 3].to_i)
y += 1
end
currentIndex = x + y + 3
case itemType #switch for resulting items
when 0
normalItem = $data_items[attributes[currentIndex].to_i]
criticalItem = $data_items[attributes[currentIndex + 2].to_i]
when 1
normalItem = $data_weapons[attributes[currentIndex].to_i]
criticalItem = $data_weapons[attributes[currentIndex + 2].to_i]
when 2
normalItem = $data_armors[attributes[currentIndex].to_i]
criticalItem = $data_armors[attributes[currentIndex + 2].to_i]
end
normalAmount = attributes[currentIndex + 1].to_i
critAmount = attributes[currentIndex + 3].to_i
critChance = attributes[currentIndex + 4].to_i
difficulty = attributes[currentIndex + 5].to_i
bonusStat = attributes[currentIndex + 6].to_i
bonusInterval = attributes[currentIndex + 7].to_i
category = attributes[currentIndex + 8].to_i
#next, create the Recipe object, initialize it and return it!
thisRecipe = Recipe.new(name, ingreds, amounts, normalItem, normalAmount, <===This is line 259
criticalItem, critAmount, critChance, difficulty,
bonusStat, bonusInterval, category)
return thisRecipe
end
#----------------------------------------------------------------------------
# Returns the array of recipes that are available
#----------------------------------------------------------------------------
def recipeList
return @recipes
end
#----------------------------------------------------------------------------
# Discovers the recipe at recipeIndex
#----------------------------------------------------------------------------
def discover(recipeIndex)
@recipes[recipeIndex].setDiscovered
end
#----------------------------------------------------------------------------
# Returns the difficulties of the specified stat
#----------------------------------------------------------------------------
def difficulties(stat)
case stat
when 0
return @atkThresholds
when 1
return @defThresholds
when 2
return @spiThresholds
when 3
return @agiThresholds
end
end
#first check for nil and comments
return nil if stringToParse == nil
return nil if stringToParse.strip.empty?
return nil if stringToParse.lstrip.index("#") != nil
#first parse out the text info
#split at the whitespace
attributes = stringToParse.split
name = attributes[0].gsub("_", " ") #the first position is name
itemType = attributes[1].to_i #2nd is item type
numOfIngs = attributes[2].to_i #3nd position is the num of ingredients
x = 0
ingreds = [] #ingredients start at the 3rd position
while x < numOfIngs
number = attributes[x + 3]
ingredientType = number[0,1].to_i
index = number[1,number.length - 1].to_i
case ingredientType #switch for ingredients
when 0
ingreds.push($data_items[index])
when 1
ingreds.push($data_weapons[index])
when 2
ingreds.push($data_armors[index])
end
x += 1
end
y = 0
amounts = [] #amounts start after the ingredients
while y < numOfIngs
amounts.push(attributes[x + y + 3].to_i)
y += 1
end
currentIndex = x + y + 3
case itemType #switch for resulting items
when 0
normalItem = $data_items[attributes[currentIndex].to_i]
criticalItem = $data_items[attributes[currentIndex + 2].to_i]
when 1
normalItem = $data_weapons[attributes[currentIndex].to_i]
criticalItem = $data_weapons[attributes[currentIndex + 2].to_i]
when 2
normalItem = $data_armors[attributes[currentIndex].to_i]
criticalItem = $data_armors[attributes[currentIndex + 2].to_i]
end
normalAmount = attributes[currentIndex + 1].to_i
critAmount = attributes[currentIndex + 3].to_i
critChance = attributes[currentIndex + 4].to_i
difficulty = attributes[currentIndex + 5].to_i
bonusStat = attributes[currentIndex + 6].to_i
bonusInterval = attributes[currentIndex + 7].to_i
category = attributes[currentIndex + 8].to_i
#next, create the Recipe object, initialize it and return it!
thisRecipe = Recipe.new(name, ingreds, amounts, normalItem, normalAmount, <===This is line 259
criticalItem, critAmount, critChance, difficulty,
bonusStat, bonusInterval, category)
return thisRecipe
end
#----------------------------------------------------------------------------
# Returns the array of recipes that are available
#----------------------------------------------------------------------------
def recipeList
return @recipes
end
#----------------------------------------------------------------------------
# Discovers the recipe at recipeIndex
#----------------------------------------------------------------------------
def discover(recipeIndex)
@recipes[recipeIndex].setDiscovered
end
#----------------------------------------------------------------------------
# Returns the difficulties of the specified stat
#----------------------------------------------------------------------------
def difficulties(stat)
case stat
when 0
return @atkThresholds
when 1
return @defThresholds
when 2
return @spiThresholds
when 3
return @agiThresholds
end
end
