mirror of
https://github.com/ErikasKontenis/SabrehavenServer.git
synced 2025-11-28 23:46:49 +01:00
implement creature hiddenHealth
This commit is contained in:
@@ -162,6 +162,13 @@ class Creature : virtual public Thing
|
||||
direction = dir;
|
||||
}
|
||||
|
||||
bool isHealthHidden() const {
|
||||
return hiddenHealth;
|
||||
}
|
||||
void setHiddenHealth(bool b) {
|
||||
hiddenHealth = b;
|
||||
}
|
||||
|
||||
int32_t getThrowRange() const final {
|
||||
return 1;
|
||||
}
|
||||
@@ -511,6 +518,7 @@ class Creature : virtual public Thing
|
||||
bool cancelNextWalk = false;
|
||||
bool hasFollowPath = false;
|
||||
bool forceUpdateFollowPath = false;
|
||||
bool hiddenHealth = false;
|
||||
|
||||
//creature script events
|
||||
bool hasEventRegistered(CreatureEventType_t event) const {
|
||||
|
||||
@@ -1922,6 +1922,7 @@ void LuaScriptInterface::registerFunctions()
|
||||
registerMethod("Creature", "addHealth", LuaScriptInterface::luaCreatureAddHealth);
|
||||
registerMethod("Creature", "getMaxHealth", LuaScriptInterface::luaCreatureGetMaxHealth);
|
||||
registerMethod("Creature", "setMaxHealth", LuaScriptInterface::luaCreatureSetMaxHealth);
|
||||
registerMethod("Creature", "setHiddenHealth", LuaScriptInterface::luaCreatureSetHiddenHealth);
|
||||
|
||||
registerMethod("Creature", "getSkull", LuaScriptInterface::luaCreatureGetSkull);
|
||||
registerMethod("Creature", "setSkull", LuaScriptInterface::luaCreatureSetSkull);
|
||||
@@ -2311,6 +2312,7 @@ void LuaScriptInterface::registerFunctions()
|
||||
registerMethod("MonsterType", "isIllusionable", LuaScriptInterface::luaMonsterTypeIsIllusionable);
|
||||
registerMethod("MonsterType", "isHostile", LuaScriptInterface::luaMonsterTypeIsHostile);
|
||||
registerMethod("MonsterType", "isPushable", LuaScriptInterface::luaMonsterTypeIsPushable);
|
||||
registerMethod("MonsterType", "isHealthShown", LuaScriptInterface::luaMonsterTypeIsHealthShown);
|
||||
|
||||
registerMethod("MonsterType", "canPushItems", LuaScriptInterface::luaMonsterTypeCanPushItems);
|
||||
registerMethod("MonsterType", "canPushCreatures", LuaScriptInterface::luaMonsterTypeCanPushCreatures);
|
||||
@@ -6677,6 +6679,21 @@ int LuaScriptInterface::luaCreatureSetMaxHealth(lua_State* L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::luaCreatureSetHiddenHealth(lua_State* L)
|
||||
{
|
||||
// creature:setHiddenHealth(hide)
|
||||
Creature* creature = getUserdata<Creature>(L, 1);
|
||||
if (creature) {
|
||||
creature->setHiddenHealth(getBoolean(L, 2));
|
||||
g_game.addCreatureHealth(creature);
|
||||
pushBoolean(L, true);
|
||||
}
|
||||
else {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::luaCreatureGetSkull(lua_State* L)
|
||||
{
|
||||
// creature:getSkull()
|
||||
@@ -10880,6 +10897,19 @@ int LuaScriptInterface::luaMonsterTypeIsPushable(lua_State* L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::luaMonsterTypeIsHealthShown(lua_State* L)
|
||||
{
|
||||
// monsterType:isHealthShown()
|
||||
MonsterType* monsterType = getUserdata<MonsterType>(L, 1);
|
||||
if (monsterType) {
|
||||
pushBoolean(L, !monsterType->info.hiddenHealth);
|
||||
}
|
||||
else {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaScriptInterface::luaMonsterTypeCanPushItems(lua_State* L)
|
||||
{
|
||||
// monsterType:canPushItems()
|
||||
|
||||
@@ -752,6 +752,7 @@ class LuaScriptInterface
|
||||
static int luaCreatureAddHealth(lua_State* L);
|
||||
static int luaCreatureGetMaxHealth(lua_State* L);
|
||||
static int luaCreatureSetMaxHealth(lua_State* L);
|
||||
static int luaCreatureSetHiddenHealth(lua_State* L);
|
||||
|
||||
static int luaCreatureGetSkull(lua_State* L);
|
||||
static int luaCreatureSetSkull(lua_State* L);
|
||||
@@ -1128,6 +1129,7 @@ class LuaScriptInterface
|
||||
static int luaMonsterTypeIsIllusionable(lua_State* L);
|
||||
static int luaMonsterTypeIsHostile(lua_State* L);
|
||||
static int luaMonsterTypeIsPushable(lua_State* L);
|
||||
static int luaMonsterTypeIsHealthShown(lua_State* L);
|
||||
|
||||
static int luaMonsterTypeCanPushItems(lua_State* L);
|
||||
static int luaMonsterTypeCanPushCreatures(lua_State* L);
|
||||
|
||||
@@ -54,6 +54,7 @@ Monster::Monster(MonsterType* mtype) :
|
||||
healthMax = mType->info.healthMax;
|
||||
baseSpeed = mType->info.baseSpeed;
|
||||
internalLight = mType->info.light;
|
||||
hiddenHealth = mType->info.hiddenHealth;
|
||||
|
||||
// register creature events
|
||||
for (const std::string& scriptName : mType->info.scripts) {
|
||||
|
||||
@@ -690,6 +690,8 @@ bool Monsters::loadMonster(const std::string& file, const std::string& monsterNa
|
||||
mType->info.targetDistance = std::max<int32_t>(1, pugi::cast<int32_t>(attr.value()));
|
||||
} else if (strcasecmp(attrName, "runonhealth") == 0) {
|
||||
mType->info.runAwayHealth = pugi::cast<int32_t>(attr.value());
|
||||
} else if (strcasecmp(attrName, "hidehealth") == 0) {
|
||||
mType->info.hiddenHealth = attr.as_bool();
|
||||
} else {
|
||||
std::cout << "[Warning - Monsters::loadMonster] Unknown flag attribute: " << attrName << ". " << file << std::endl;
|
||||
}
|
||||
|
||||
@@ -1434,7 +1434,14 @@ void ProtocolGame::sendCreatureHealth(const Creature* creature)
|
||||
NetworkMessage msg;
|
||||
msg.addByte(0x8C);
|
||||
msg.add<uint32_t>(creature->getID());
|
||||
msg.addByte(std::ceil((static_cast<double>(creature->getHealth()) / std::max<int32_t>(creature->getMaxHealth(), 1)) * 100));
|
||||
|
||||
if (creature->isHealthHidden()) {
|
||||
msg.addByte(0x00);
|
||||
}
|
||||
else {
|
||||
msg.addByte(std::ceil((static_cast<double>(creature->getHealth()) / std::max<int32_t>(creature->getMaxHealth(), 1)) * 100));
|
||||
}
|
||||
|
||||
writeToOutputBuffer(msg);
|
||||
}
|
||||
|
||||
@@ -1848,7 +1855,13 @@ void ProtocolGame::AddCreature(NetworkMessage& msg, const Creature* creature, bo
|
||||
msg.addString(creature->getName());
|
||||
}
|
||||
|
||||
msg.addByte(std::ceil((static_cast<double>(creature->getHealth()) / std::max<int32_t>(creature->getMaxHealth(), 1)) * 100));
|
||||
if (creature->isHealthHidden()) {
|
||||
msg.addByte(0x00);
|
||||
}
|
||||
else {
|
||||
msg.addByte(std::ceil((static_cast<double>(creature->getHealth()) / std::max<int32_t>(creature->getMaxHealth(), 1)) * 100));
|
||||
}
|
||||
|
||||
msg.addByte(creature->getDirection());
|
||||
|
||||
if (!creature->isInGhostMode() && !creature->isInvisible()) {
|
||||
|
||||
Reference in New Issue
Block a user