Full Distribution

This commit is contained in:
rasanpedromujica
2019-01-16 17:16:38 -05:00
commit 009a571331
1258 changed files with 185603 additions and 0 deletions

116
data/lib/core/creature.lua Normal file
View File

@@ -0,0 +1,116 @@
function Creature.getClosestFreePosition(self, position, extended)
local usePosition = Position(position)
local tiles = { Tile(usePosition) }
local length = extended and 2 or 1
local tile
for y = -length, length do
for x = -length, length do
if x ~= 0 or y ~= 0 then
usePosition.x = position.x + x
usePosition.y = position.y + y
tile = Tile(usePosition)
if tile then
tiles[#tiles + 1] = tile
end
end
end
end
for i = 1, #tiles do
tile = tiles[i]
if tile:getCreatureCount() == 0 and not tile:hasProperty(CONST_PROP_IMMOVABLEBLOCKSOLID) then
return tile:getPosition()
end
end
return Position()
end
function Creature:setMonsterOutfit(monster, time)
local monsterType = MonsterType(monster)
if not monsterType then
return false
end
if self:isPlayer() and not (getPlayerFlagValue(self, PlayerFlag_CanIllusionAll) or monsterType:isIllusionable()) then
return false
end
local condition = Condition(CONDITION_OUTFIT)
condition:setOutfit(monsterType:getOutfit())
condition:setTicks(time)
self:addCondition(condition)
return true
end
function Creature:setItemOutfit(item, time)
local itemType = ItemType(item)
if not itemType then
return false
end
local condition = Condition(CONDITION_OUTFIT)
condition:setOutfit({
lookTypeEx = itemType:getId()
})
condition:setTicks(time)
self:addCondition(condition)
return true
end
function Creature:addSummon(monster)
local summon = Monster(monster)
if not summon then
return false
end
summon:setTarget(nil)
summon:setFollowCreature(nil)
summon:setDropLoot(false)
summon:setMaster(self)
return true
end
function Creature:removeSummon(monster)
local summon = Monster(monster)
if not summon or summon:getMaster() ~= self then
return false
end
summon:setTarget(nil)
summon:setFollowCreature(nil)
summon:setDropLoot(true)
summon:setMaster(nil)
return true
end
function Creature.getPlayer(self)
return self:isPlayer() and self or nil
end
function Creature.isItem(self)
return false
end
function Creature.isMonster(self)
return false
end
function Creature.isNpc(self)
return false
end
function Creature.isPlayer(self)
return false
end
function Creature.isTile(self)
return false
end
function Creature.isContainer(self)
return false
end