implement creature hiddenHealth

This commit is contained in:
ErikasKontenis 2019-12-12 17:41:44 +02:00
parent e415a533a4
commit 68a58ae041
9 changed files with 82 additions and 8 deletions

View File

@ -6,7 +6,7 @@ Home = [32417,31583,7]
Radius = 3
Behaviour = {
ADDRESS,"hello$",! -> "Hi."
ADDRESS,"hello$",! -> "Whatcha do in my place?"
ADDRESS,"hi$",! -> *
ADDRESS,! -> Idle
BUSY,"hello$",! -> "Wait, %N.", Queue
@ -17,5 +17,7 @@ VANISH,! -> NOP
"bye" -> "Bye.", Idle
"farewell" -> *
"fight" -> "You. Weak."
"job" -> "No time for such a stupid thing."
"name" -> "Ajax."
}

View File

@ -16,10 +16,13 @@ VANISH,! -> "Good bye."
"bye" -> "Good bye.", Idle
"buy" -> "I can offer you food."
"drinks" -> "Well, we usually drink around here, but right now we're running dry. However, I sell juice squeezers to make fruit juice."
"tavern" -> "I can offer you food and drinks. I also offer juice squeezers."
"buy" -> *
"do","you","sell" -> *
"do","you","have" -> *
"food" -> "Are you looking for food? I have banana, blueberry, cheese, mango, meat, melon, orange, pear, pumpkin, red apple and strawberry."
"food" -> "Are you looking for food? I have cheese, ham and meat as well as a variety of fruits."
"fruits" -> "I have bananas, apples, oranges, strawberries, melons, pumpkin, blueberries, mangoes and pears, sweety."
"banana" -> Type=3587, Amount=1, Price=5, "Do you want to buy a banana for %P gold?", Topic=1
"blueberry" -> Type=3588, Amount=1, Price=1, "Do you want to buy blueberry for %P gold?", Topic=1

View File

@ -14,11 +14,24 @@ BUSY,"hi$",! -> *
BUSY,! -> NOP
VANISH,! -> "Good bye."
"bye" -> "Good bye, %N!", Idle
"bye" -> "May there always be wind in your sails, %N.", Idle
"farewell" -> *
"name" -> "Raymond Striker, at your service."
"job" -> "I am one of the free captains of the Shattered Isles, who selected me as their spokesperson."
"captains" -> "We don't consider ourselves as pirates, but as freedom fighters. But there are indeed pirates out there. They are true bandits, cutthroats and murderers. They are the ones responsible for the horrible acts that are accredited to us."
"ferumbras" -> "It is rumoured that he has established some base on one of the isles in the past."
"Liberty","Bay" -> "One day the city will bear this name justly and with pride."
"Thais" -> "Thais is not the source of the evil that has befallen our isles. It might end up as a victim itself whenever Venore feels powerful enough."
"Venore" -> "The scheming trade barons of Venore know nothing but profit and power. For that, they lie and murder and would readily sell their souls."
"Carlin" -> "We have loose trade relations with Carlin."
"Eleonore",QuestValue(17502)>12 -> "She is my only and true love. It hurts me deeply that the mermaid's magic let me forget her. I feel so guilty and can only hope that Eleonore can forgive my weakness."
"King" -> "I doubt the king gains as much from the occupation of the isles as the Venoreans do."
"mission",QuestValue(17502)=6 -> "Don't ask about silly missions. All I can think about is this lovely mermaid.", Topic=1
"Eleonore",QuestValue(17502)=6 -> "Eleonore ... Yes, I remember her... vaguely. She is a pretty girl ... but still only a girl and now I am in love with a beautiful and passionate woman. A true mermaid even.", Topic=1
Topic=1,"mermaid" -> "The mermaid is the most beautiful creature I have ever met. She is so wonderful. It was some kind of magic as we first met. A look in her eyes and I suddenly knew there would be never again another woman in my life but her.", SetQuestValue(17502,7)
"mermaid",QuestValue(17502)=7 -> "The mermaid is the most beautiful creature I have ever met. She is so wonderful. It was some kind of magic as we first met. A look in her eyes and I suddenly knew there would be never again another woman in my life but her."
"mermaid",QuestValue(17502)>6,QuestValue(17502)<12 -> "The mermaid is the most beautiful creature I have ever met. She is so wonderful. It was some kind of magic as we first met. A look in her eyes and I suddenly knew there would be never again another woman in my life but her."
"mermaid",QuestValue(17502)>12 -> "I am deeply ashamed that I lacked the willpower to resist her spell. Thank you for your help in that matter. Now my head is once more free to think about our mission."
"marina",QuestValue(17502)>12 -> *
}

View File

@ -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 {

View File

@ -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()

View File

@ -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);

View File

@ -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) {

View File

@ -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;
}

View File

@ -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()) {