//! zinc
library AlchemistCreation requires LinkedList, optional FloatingTextArc
{
public List recipes;
constant string itemEffect = "Abilities\\Spells\\Other\\Transmute\\GoldBottleMissile.mdl";
constant string green = "|c0096FF96";
constant string yellow = "|c00FFFF00";
constant string red = "|c00FF0000";
constant string blue = "|c007EBFF1";
constant string end = "|r";
public constant integer cauldron = 'H000';
public function PrepareCraft(unit u)
{
integer i = 0;
boolean check;
Link x = recipes.first;
while(i < recipes.size)
{
check = ItemRecipe(x.data).Craft(u);
x = x.next;
i = i + 1;
}
static if(LIBRARY_FloatingTextArc)
{
if(!check)
{
ArcingTextTag.create(yellow + "That combination of items is invalid." + end, u);
}
}
}
function Actions()
{
unit u = GetManipulatingUnit();
if(GetUnitTypeId(u) == cauldron)
{
DestroyEffect(AddSpecialEffect(itemEffect, GetUnitX(u), GetUnitY(u)));
static if(LIBRARY_FloatingTextArc)
{
ArcingTextTag.create(blue + "Added: " + yellow + GetItemName(GetManipulatedItem()) + end + end, u);
}
}
u = null;
}
function onInit()
{
trigger t = CreateTrigger();
TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM);
TriggerAddAction(t, function Actions);
recipes = List.create();
}
public struct ItemRecipe
{
List parts;
integer summon;
real failRate = 25;
real dublicateChance = 25;
real psuedoIncrease = 0;
real timedLife = 0; // 0 = permanent (no timer)
real numberOfFails = 0;
real numberOfDublicates = 0; //used to calculate success/fail rate depending on streak
string spawnEffect = "Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl";
string failEffect = "Units\\NightElf\\Wisp\\WispExplode.mdl";
public method Craft(unit u) -> boolean
{
integer i = 0;
boolean check = true;
real luck, x, y;
unit temp;
Link l = parts.first;
while(i < parts.size)
{
if(!UnitHasItemOfTypeBJ(u, l.data))
{
check = false;
break;
}
l = l.next;
i += 1;
}
if(check)
{
luck = GetRandomReal(1,100);
x = GetUnitX(u);
y = GetUnitY(u);
if(luck > failRate)
{
CreateUnit(GetOwningPlayer(u), summon, x, y, 0);
if(timedLife > 0)
{
UnitApplyTimedLife(temp, 'BTLF', timedLife);
}
luck = GetRandomReal(1,100);
DestroyEffect(AddSpecialEffect(spawnEffect, x, y));
if(dublicateChance > 0 && dublicateChance > luck)
{
temp = CreateUnit(GetOwningPlayer(u), summon, x, y, 0);
if(timedLife > 0)
{
UnitApplyTimedLife(temp, 'BTLF', timedLife);
}
static if(LIBRARY_FloatingTextArc)
{
ArcingTextTag.create(green + "Perfect brew! you created 2x: " + yellow + GetUnitName(temp) + end + end, u);
}
}
else
{
static if(LIBRARY_FloatingTextArc)
{
ArcingTextTag.create(blue + "Success! You created: " + yellow + GetUnitName(temp) + end + end, u);
}
}
}
else
{
DestroyEffect(AddSpecialEffect(failEffect, x, y));
static if(LIBRARY_FloatingTextArc)
{
ArcingTextTag.create(red + "Failed!" + end, u);
}
}
RemoveItem(GetItemOfTypeFromUnitBJ(u, parts.first.data));
RemoveItem(GetItemOfTypeFromUnitBJ(u, parts.first.next.data));
}
return check;
}
method add(integer part)
{
Link.create(parts, part);
}
static method create(integer result) -> thistype
{
thistype this = thistype.allocate();
summon = result;
parts = List.create();
Link.create(recipes, this);
return this;
}
}
}
//! endzinc