Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function createTile(x, y)
- local tile = {}
- tile.x = x
- tile.y = y
- tile.entity = nil
- return tile
- end
- local function createLogs
- local function createBoard(width, height)
- local board = {}
- for x=1,width do
- board[x] = {}
- for y=1,height do
- board[x][y] = createTile(x,y)
- end
- end
- board.getTile = function(self, x, y)
- local tile = nil
- if self[x] ~= nil then
- if self[x][y] ~= nil then
- tile = self[x][y]
- end
- end
- return tile
- end
- board.log = createLogger()
- return board
- end
- local function copyTable(table)
- local ntable = {}
- for k,v in pairs(table) do
- if type(v) == "table" then
- ntable[k] = copyTable(v)
- else
- ntable[k] = v
- end
- end
- return ntable
- end
- local function createEntity(card, x, y, board)
- local entity = {}
- local data = {}
- data.range = card.range --the range of their attack (inf)
- data.movement = card.movement --the range of their movement (inf)
- data.health = card.health --the amount of health they have (inf)
- data.damage = card.damage --the amount of damage they deal (inf)
- data.armour = card.armour --the amount of damage they resist (0 to 50)
- data.armour_pen = card.armour_pen --the amount of amount of armour they ignore (0 to 1)
- data.cooldown = card.cooldown --the amount of turns that must pass before they can do something
- data.actions = card.actions --the amount of actions the unit can do per cooldown
- data.revives = card.revives --the amount of revives available to the unit
- data.aura = card.aura --the name of the stat buffed
- data.aura_amount = card.aura_amount --the amount that the stat is changed by
- data.aura_range = card.aura_range --the range of the aura
- local stats = copyTable(data)
- entity.data = data
- entity.stats = stats
- local pos = {}
- pos.x = x
- pos.y = y
- pos.board = board
- pos.tile = board[x][y]
- entity.protect = nil
- entity.checkProtect = function(self)
- end
- entity.takeDamage = function(self, damage, pen)
- local arm = (self.stats.armour/100)*(pen*100)
- local dmg = damage
- if arm > 0 then
- dmg = math.ceil(dmg - ((damage/100)*arm))
- end
- if entity:checkProtect() then
- else
- self.stats.health = self.stats.health - damage
- end
- return self:check()
- end
- entity.move = function(self, x, y)
- local distX = math.abs(self.pos.x-x)
- local distY = math.abs(self.pos.y-y)
- local dist = math.sqrt(distX^2 + distY^2)
- if dist <= self.stats.movement then
- local tile = self.pos.board:getTile(x, y)
- if tile ~= nil then
- if tile.entity == nil then
- self.pos.tile.entity = nil
- tile.entity = self
- return true
- end
- end
- end
- return false
- end
- entity.attack = function(self, x, y)
- local distX = math.abs(self.pos.x-x)
- local distY = math.abs(self.pos.y-y)
- local dist = math.sqrt(distX^2 + distY^2)
- if dist <= self.stats.range then
- local tile = self.pos.board:getTile(x, y)
- if tile ~= nil then
- if tile.entity ~= nil then
- if tile.entity:takeDamage(self.stats.damage, self.stats.armour_pen) then
- tile.entity = nil
- end
- return true
- end
- end
- end
- return false
- end
- entity.check = function(self)
- if self.stats.health <= 0 then
- if self.stats.revives > 0 then
- self.stats.health = self.data.health
- self.stats.revives = self.stats.revives - 1
- else
- return true
- end
- end
- return false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement