function CheckSorceressButtonValidity(pPlayer)
local iCurrentCulture = pPlayer:GetJONSCulture()
if (iCurrentCulture > 30) then
return true;
end
return false;
end
local SorceressMissionButton = {
Name = "SorceressMissionButton",
Title = "Summon Skeleton",
OrderPriority = 200,
IconAtlas = "UNIT_ACTION_ATLAS_TH_EVIL_SPIRITS",
PortraitIndex = 0,
ToolTip = function(action, unit)
local sTooltip;
local pPlayer = Players[Game:GetActivePlayer()];
local bIsValid = CheckSorceressButtonValidity(pPlayer);
if bIsValid then
sTooltip = "Summons a Skeleton"
else
sTooltip = "Can only be used when you have sufficient culture"
end
return sTooltip
end, -- or a TXT_KEY_ or a function
Condition = function(action, unit)
if unit:GetMoves() <= 0 then
return false
end
if unit:IsHasPromotion(GameInfoTypes.PROMOTION_SUMMON_ES_SKELETON) then
return true
else
return false
end
--print(string.format("Condition %s called for unit %i for player %i", action.Name, unit:GetID(), unit:GetOwner()));
end, -- or nil or a boolean, default is true
Disabled = function(action, unit)
local pPlayer = Players[Game:GetActivePlayer()];
local bIsValid = CheckSorceressButtonValidity(pPlayer);
if bIsValid then
return false
end
return true;
end, -- or nil or a boolean, default is false
Action = function(action, unit, eClick)
if eClick == Mouse.eRClick then
return
end
local pPlayer = Players[Game:GetActivePlayer()];
print("Summoning a Skeleton.")
if pPlayer:IsHuman() then
pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, "Summoning!" ,"One of your sorceresses summoned a skeleton!", -1, -1);
end
local iSkeletonUnitID = GameInfo.Units.UNIT_ES_SKELETON.ID
skeleton = pPlayer:InitUnit (iSkeletonUnitID, unit:GetX(), unit:GetY() );
skeleton:JumpToNearestValidPlot();
unit:SetMoves(unit:GetMoves() - 1)
unit:SetHasPromotion(GameInfoTypes.PROMOTION_SUMMON_ES_SKELETON, false)
pPlayer:ChangeJONSCulture(-30);
end,
}
LuaEvents.UnitPanelActionAddin(SorceressMissionButton)