heroes-of-nerevelon/lib/faction.lua
Neckrat 9c35fc2581 move character to lib
Co-authored-by: Ivan Yuriev <ivanyr44@gmail.com>
2025-08-03 22:06:45 +03:00

44 lines
1.1 KiB
Lua

--- @class Faction
local Faction = {}
Faction.name = ""
Faction.characters = {}
Faction.style = {}
--- some sort of global variable :clown:
--- @type table<string, Faction>
FactionList = {}
--- @param name string
function AddFaction(name)
FactionList[name] = Faction { name = name }
end
--- @param name string
--- @param character table
function AddCharacter(name, character)
if FactionList[name] == nil then
print("Cannot add character to faction ", name, "\nFaction does not exist!")
else
FactionList[name]:append(character)
end
end
--- @param name string
--- @param character Character
function RemoveCharacter(name, character)
if FactionList[name].characters[character.name] == nil then
print("I cant remove character in Faction ", name, ", because this character doesnt exist!")
end
FactionList[name]:remove(character)
end
--- @param character Character
function Faction:append(character)
self.characters[character.name] = character
end
--- @param character Character
function Faction:remove(character)
self.characters[character.name] = nil
end