mirror of
https://github.com/ErikasKontenis/SabrehavenServer.git
synced 2025-10-16 07:14:55 +02:00
Full Distribution
This commit is contained in:
116
data/lib/core/creature.lua
Normal file
116
data/lib/core/creature.lua
Normal 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
|
Reference in New Issue
Block a user