This commit is contained in:
Eduardo Bart 2012-10-05 16:13:50 -03:00
parent ced5c035b9
commit fa8b77f0c8
7 changed files with 32 additions and 3 deletions

View File

@ -41,6 +41,7 @@ function init()
connect(Creature, { connect(Creature, {
onSkullChange = updateCreatureSkull, onSkullChange = updateCreatureSkull,
onEmblemChange = updateCreatureEmblem, onEmblemChange = updateCreatureEmblem,
onOutfitChange = onCreatureOutfitChange,
onHealthPercentChange = onCreatureHealthPercentChange, onHealthPercentChange = onCreatureHealthPercentChange,
onPositionChange = onCreaturePositionChange, onPositionChange = onCreaturePositionChange,
onAppear = onCreatureAppear, onAppear = onCreatureAppear,
@ -67,6 +68,7 @@ function terminate()
disconnect(Creature, { disconnect(Creature, {
onSkullChange = updateCreatureSkull, onSkullChange = updateCreatureSkull,
onEmblemChange = updateCreatureEmblem, onEmblemChange = updateCreatureEmblem,
onOutfitChange = onCreatureOutfitChange,
onHealthPercentChange = onCreatureHealthPercentChange, onHealthPercentChange = onCreatureHealthPercentChange,
onPositionChange = onCreaturePositionChange, onPositionChange = onCreaturePositionChange,
onAppear = onCreatureAppear, onAppear = onCreatureAppear,
@ -126,6 +128,8 @@ function doCreatureFitFilters(creature)
return false return false
end end
if not creature:canBeSeen() then return false end
local hidePlayers = hidePlayersButton:isChecked() local hidePlayers = hidePlayersButton:isChecked()
local hideNPCs = hideNPCsButton:isChecked() local hideNPCs = hideNPCsButton:isChecked()
local hideMonsters = hideMonstersButton:isChecked() local hideMonsters = hideMonstersButton:isChecked()
@ -168,9 +172,17 @@ function onCreaturePositionChange(creature, newPos, oldPos)
end end
end end
function onCreatureOutfitChange(creature, outfit, oldOutfit)
if not creature:canBeSeen() then
removeCreature(creature)
elseif doCreatureFitFilters(creature) then
removeCreature(creature)
addCreature(creature)
end
end
function onCreatureAppear(creature) function onCreatureAppear(creature)
local player = g_game.getLocalPlayer() if doCreatureFitFilters(creature) then
if creature ~= player and creature:getPosition().z == player:getPosition().z and doCreatureFitFilters(creature) then
addCreature(creature) addCreature(creature)
end end
end end

View File

@ -60,6 +60,9 @@ Creature::Creature() : Thing()
void Creature::draw(const Point& dest, float scaleFactor, bool animate) void Creature::draw(const Point& dest, float scaleFactor, bool animate)
{ {
if(!canBeSeen())
return;
Point animationOffset = animate ? m_walkOffset : Point(0,0); Point animationOffset = animate ? m_walkOffset : Point(0,0);
if(m_showTimedSquare && animate) { if(m_showTimedSquare && animate) {
@ -523,6 +526,7 @@ void Creature::setDirection(Otc::Direction direction)
void Creature::setOutfit(const Outfit& outfit) void Creature::setOutfit(const Outfit& outfit)
{ {
Outfit oldOutfit = outfit;
if(outfit.getCategory() != ThingCategoryCreature) { if(outfit.getCategory() != ThingCategoryCreature) {
if(!g_things.isValidDatId(outfit.getAuxId(), outfit.getCategory())) if(!g_things.isValidDatId(outfit.getAuxId(), outfit.getCategory()))
return; return;
@ -534,6 +538,8 @@ void Creature::setOutfit(const Outfit& outfit)
m_outfit = outfit; m_outfit = outfit;
} }
m_walkAnimationPhase = 0; // might happen when player is walking and outfit is changed. m_walkAnimationPhase = 0; // might happen when player is walking and outfit is changed.
callLuaField("onOutfitChange", m_outfit, oldOutfit);
} }
void Creature::setSpeed(uint16 speed) void Creature::setSpeed(uint16 speed)

View File

@ -102,6 +102,8 @@ public:
bool isWalking() { return m_walking; } bool isWalking() { return m_walking; }
bool isRemoved() { return m_removed; } bool isRemoved() { return m_removed; }
bool isInvisible() { return m_outfit.getCategory() == ThingCategoryEffect && m_outfit.getAuxId() == 13; }
bool canBeSeen() { return !isInvisible() || isPlayer(); }
bool isCreature() { return true; } bool isCreature() { return true; }

View File

@ -368,6 +368,8 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Creature>("showStaticSquare", &Creature::showStaticSquare); g_lua.bindClassMemberFunction<Creature>("showStaticSquare", &Creature::showStaticSquare);
g_lua.bindClassMemberFunction<Creature>("hideStaticSquare", &Creature::hideStaticSquare); g_lua.bindClassMemberFunction<Creature>("hideStaticSquare", &Creature::hideStaticSquare);
g_lua.bindClassMemberFunction<Creature>("isWalking", &Creature::isWalking); g_lua.bindClassMemberFunction<Creature>("isWalking", &Creature::isWalking);
g_lua.bindClassMemberFunction<Creature>("isInvisible", &Creature::isInvisible);
g_lua.bindClassMemberFunction<Creature>("canBeSeen", &Creature::canBeSeen);
g_lua.registerClass<ItemType>(); g_lua.registerClass<ItemType>();
g_lua.bindClassMemberFunction<ItemType>("getServerId", &ItemType::getServerId); g_lua.bindClassMemberFunction<ItemType>("getServerId", &ItemType::getServerId);

View File

@ -28,6 +28,8 @@ int push_luavalue(const Outfit& outfit)
g_lua.newTable(); g_lua.newTable();
g_lua.pushInteger(outfit.getId()); g_lua.pushInteger(outfit.getId());
g_lua.setField("type"); g_lua.setField("type");
g_lua.pushInteger(outfit.getAuxId());
g_lua.setField("auxType");
g_lua.pushInteger(outfit.getAddons()); g_lua.pushInteger(outfit.getAddons());
g_lua.setField("addons"); g_lua.setField("addons");
g_lua.pushInteger(outfit.getHead()); g_lua.pushInteger(outfit.getHead());
@ -50,6 +52,8 @@ bool luavalue_cast(int index, Outfit& outfit)
if(g_lua.isTable(index)) { if(g_lua.isTable(index)) {
g_lua.getField("type", index); g_lua.getField("type", index);
outfit.setId(g_lua.popInteger()); outfit.setId(g_lua.popInteger());
g_lua.getField("auxType", index);
outfit.setAuxId(g_lua.popInteger());
g_lua.getField("addons", index); g_lua.getField("addons", index);
outfit.setAddons(g_lua.popInteger()); outfit.setAddons(g_lua.popInteger());
g_lua.getField("head", index); g_lua.getField("head", index);

View File

@ -175,6 +175,9 @@ void MapView::draw(const Rect& rect)
// avoid drawing texts on map in far zoom outs // avoid drawing texts on map in far zoom outs
if(m_viewMode == NEAR_VIEW && m_drawTexts) { if(m_viewMode == NEAR_VIEW && m_drawTexts) {
for(const CreaturePtr& creature : m_cachedFloorVisibleCreatures) { for(const CreaturePtr& creature : m_cachedFloorVisibleCreatures) {
if(!creature->canBeSeen())
continue;
Point creatureOffset = Point(16 - creature->getDisplacementX(), -3 - creature->getDisplacementY()); Point creatureOffset = Point(16 - creature->getDisplacementX(), -3 - creature->getDisplacementY());
Position pos = creature->getPosition(); Position pos = creature->getPosition();
Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset; Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset;

View File

@ -451,7 +451,7 @@ bool Tile::isWalkable()
if(thing->isCreature()) { if(thing->isCreature()) {
CreaturePtr creature = thing->static_self_cast<Creature>(); CreaturePtr creature = thing->static_self_cast<Creature>();
if(!creature->isPassable()) if(!creature->isPassable() && creature->canBeSeen())
return false; return false;
} }
} }