Code: Select all
champions = {}
skills = {
"accuracy","athletics", "armors", "critical", "dodge", "missile_weapons",
"throwing", "firearms", "light_weapons", "heavy_weapons", "concentration", "alchemy",
"fire_magic","earth_magic","water_magic","air_magic"
}
stats = {'strength','dexterity','vitality','willpower'}
conditions = {}
traits = {
"fighter","barbarian","knight","rogue","wizard","battle_mage","alchemist","farmer","human",
"minotaur","lizardman","insectoid","ratling","skilled","fast_learner","head_hunter","rage",
"fast_metabolism","endure_elements","poison_immunity","chitin_armor","quick","mutation","athletic",
"agile","healthy","strong_mind","tough","aura","aggressive","evasive","fire_resistant","cold_resistant",
"poison_resistant","natural_armor","endurance","weapon_specialization","pack_mule","meditation",
"two_handed_mastery","light_armor_proficiency","heavy_armor_proficiency","armor_expert","shield_expert",
"staff_defence","improved_alchemy","bomb_expert","backstab","assassin","firearm_mastery","dual_wield",
"improved_dual_wield","piercing_arrows","double_throw","reach","uncanny_speed","fire_mastery","air_mastery",
"earth_mastery","water_mastery","leadership","nightstalker"
}
function storeChampion(champ)
champions[champ:getName()] ={
baseStats = getBaseStats(champ),
class = champ:getClass(),
dualClass = champ:getDualClass(),
energy = champ:getEnergy(),
evasion = champ:getEvasion(),
experience = champ:getExp(),
food = champ:getFood(),
health = champ:getHealth(),
level = champ:getLevel(),
load = champ:getLoad(),
maxEnergy = champ:getMaxEnergy(),
maxHealth = champ:getMaxHealth(),
maxLoad = champ:getMaxLoad(),
name = champ:getName(),
protection = champ:getProtection(),
race = champ:getRace(),
sex = champ:getSex(),
skillLevels = getSkillLevels(champ),
traits = getTraits(champ),
skillPoints = champ:getSkillPoints()
}
end
function defineChampion(def)
champions[def.name] = def
end
function loadChampion(name,replaceChamp)
local data = champions[name]
setBaseStats(replaceChamp,data.baseStats)
replaceChamp:setRace(data.race)
replaceChamp:setSex(data.sex)
replaceChamp:setClass(data.class)
--replaceChamp:setCondition(name)
--replaceChamp:setConditionValue(name, value)
replaceChamp:setEnergy(data.energy)
replaceChamp:setFood(data.food)
replaceChamp:setHealth(data.health)
replaceChamp:setName(data.name)
if data.portrait then
replaceChamp:setPortrait(data.portrait)
end
local toTargetXp = data.experience - replaceChamp:getExp()
replaceChamp:gainExp(toTargetXp)
setSkillLevels(replaceChamp,data.skillLevels)
replaceChamp:setSkillPoints(data.skillPoints)
setTraits(replaceChamp,data.traits)
end
function getSkillLevels(champ)
local result = {}
for _,skill in ipairs(skills) do
result[skill] = champ:getSkillLevel(skill)
end
return result
end
function setSkillLevels(champ,champSkills)
for _,skill in ipairs(skills) do
local value = champSkills[skill] or 0
local currentLevel = champ:getSkillLevel(skill)
local trainToTarget = value - currentLevel
champ:trainSkill(skill,trainToTarget)
end
end
function getBaseStats(champ)
local result = {}
for _,stat in ipairs(stats) do
result[stat] = champ:getBaseStat(stat)
end
return result
end
function setBaseStats(champ,stats)
for stat,value in pairs(stats) do
champ:setBaseStat(stat,value)
end
end
function getTraits(champ)
local result = {}
for _,trait in ipairs(traits) do
result[trait] = champ:hasTrait(trait)
end
return result
end
function setTraits(champ,champTraits)
for _,trait in ipairs(traits) do
if champTraits[trait] then
champ:addTrait(trait)
else
champ:removeTrait(trait)
end
end
end
Code: Select all
local champ = {
name = 'Test Man',
race = 'ratling',
class = 'farmer',
sex='male',
portrait='assets/textures/portraits/human_male_02.tga',
experience=6000,
baseStats = {
strength=20,
dexterity=1,
vitality=18,
willpower=1
},
skillLevels = {
accuracy=1,
light_weapons=4
},
energy=110,
food=1000,
health=100,
level=4,
skillPoints=0,
traits={
human=true,
}
}
champions.script.defineChampion(champ) -- define new champion
champions.script.storeChampion(party.party:getChampion(2)) --store champion 2
champions.script.loadChampion('Test Man',party.party:getChampion(2)) -- replace champion 2 with ''Test Man'
Feel free to improve and develop it further.