Skip to content

Commit

Permalink
[Enhancement] Rework on fluids colors and new monster race type (INK) (
Browse files Browse the repository at this point in the history
…#324)

Description
Full rework on the way that the server handles the fluids, to use one single ENUM and remove all the garbage functions and maps that used to store the same values for fluids over and over again.
Add new creature race type named INK. This new race type is used mostly on creatures on the tibia "The Secret Library". Attacking those creatures or slain then will now create the proper type of blood pool/splash.

Resolves #123

OTServerBr-Global PR: opentibiabr/otservbr-global#544
  • Loading branch information
marcosvf132 authored Apr 25, 2022
1 parent 0ea8dd6 commit ce36520
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 245 deletions.
171 changes: 91 additions & 80 deletions data/items/items.xml

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions data/scripts/actions/other/fluids.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@ poison:setParameter(CONDITION_PARAM_TICKINTERVAL, 4000)
poison:setParameter(CONDITION_PARAM_FORCEUPDATE, true)

local fluidMessage = {
[3] = "Aah...",
[4] = "Urgh!",
[5] = "Mmmh.",
[7] = "Aaaah...",
[10] = "Aaaah...",
[11] = "Urgh!",
[13] = "Urgh!",
[15] = "Aah...",
[19] = "Urgh!",
[43] = "Aaaah..."
[1] = "Gulp.", -- water
[2] = "Aah...", -- wine
[3] = "Aah...", -- beer
[4] = "Gulp.", -- mud
[5] = "Gulp.", -- blood
[6] = "Urgh!", -- slime
[7] = "Gulp.", -- oil
[8] = "Urgh!", -- urine
[9] = "Gulp.", -- milk
[10] = "Aaaah...", -- manafluid
[11] = "Aaaah...", -- lifefluid
[12] = "Mmmh.", -- lemonade
[13] = "Aah...", -- rum
[14] = "Mmmh.", -- fruit juice
[15] = "Mmmh.", -- coconut milk
[16] = "Aah...", -- mead
[17] = "Gulp.", -- tea
[18] = "Urgh!" -- ink
}

local fluid = Action()
Expand Down
6 changes: 5 additions & 1 deletion src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,13 +718,17 @@ bool Creature::dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreatur
Item* splash;
switch (getRace()) {
case RACE_VENOM:
splash = Item::CreateItem(ITEM_FULLSPLASH, FLUID_GREEN);
splash = Item::CreateItem(ITEM_FULLSPLASH, FLUID_SLIME);
break;

case RACE_BLOOD:
splash = Item::CreateItem(ITEM_FULLSPLASH, FLUID_BLOOD);
break;

case RACE_INK:
splash = Item::CreateItem(ITEM_FULLSPLASH, FLUID_INK);
break;

default:
splash = nullptr;
break;
Expand Down
1 change: 1 addition & 0 deletions src/creatures/creatures_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ enum RaceType_t : uint8_t {
RACE_UNDEAD,
RACE_FIRE,
RACE_ENERGY,
RACE_INK,
};

enum BlockType_t : uint8_t {
Expand Down
2 changes: 2 additions & 0 deletions src/creatures/monsters/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ MonsterType* Monsters::loadMonster(const std::string& file, const std::string& m
mType->info.race = RACE_FIRE;
} else if (tmpStrValue == "energy" || tmpInt == 5) {
mType->info.race = RACE_ENERGY;
} else if (tmpStrValue == "ink" || tmpInt == 6) {
mType->info.race = RACE_INK;
} else {
SPDLOG_WARN("[Monsters::loadMonster] - Unknown race type {}. {}",
attr.as_string(), file);
Expand Down
43 changes: 14 additions & 29 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,8 @@ Thing* Game::internalGetThing(Player* player, const Position& pos, int32_t index
}

int32_t subType;
if (it.isFluidContainer() && index < static_cast<int32_t>(sizeof(reverseFluidMap) / sizeof(uint8_t))) {
subType = reverseFluidMap[index];
if (it.isFluidContainer()) {
subType = index;
} else {
subType = -1;
}
Expand Down Expand Up @@ -4305,18 +4305,11 @@ void Game::playerBuyItem(uint32_t playerId, uint16_t spriteId, uint8_t count, ui
return;
}

uint8_t subType;
if (it.isSplash() || it.isFluidContainer()) {
subType = clientFluidToServer(count);
} else {
subType = count;
}

if (!player->hasShopItemForSale(it.id, subType)) {
if (!player->hasShopItemForSale(it.id, count)) {
return;
}

merchant->onPlayerBuyItem(player, it.id, subType, amount, ignoreCap, inBackpacks);
merchant->onPlayerBuyItem(player, it.id, count, amount, ignoreCap, inBackpacks);
}

void Game::playerSellItem(uint32_t playerId, uint16_t spriteId, uint8_t count, uint8_t amount, bool ignoreEquipped)
Expand All @@ -4340,14 +4333,7 @@ void Game::playerSellItem(uint32_t playerId, uint16_t spriteId, uint8_t count, u
return;
}

uint8_t subType;
if (it.isSplash() || it.isFluidContainer()) {
subType = clientFluidToServer(count);
} else {
subType = count;
}

merchant->onPlayerSellItem(player, it.id, subType, amount, ignoreEquipped);
merchant->onPlayerSellItem(player, it.id, count, amount, ignoreEquipped);
}

void Game::playerCloseShop(uint32_t playerId)
Expand Down Expand Up @@ -4377,21 +4363,15 @@ void Game::playerLookInShop(uint32_t playerId, uint16_t spriteId, uint8_t count)
return;
}

uint8_t subType;
if (it.isFluidContainer() || it.isSplash()) {
subType = clientFluidToServer(count);
} else {
subType = count;
}

if (!g_events().eventPlayerOnLookInShop(player, &it, subType)) {
if (!g_events().eventPlayerOnLookInShop(player, &it, count)) {
SPDLOG_ERROR("Game::playerLookInShop - Lua event callback is wrong");
return;
}

std::ostringstream ss;
ss << "You see " << Item::getDescription(it, 1, nullptr, subType);
ss << "You see " << Item::getDescription(it, 1, nullptr, count);
player->sendTextMessage(MESSAGE_LOOK, ss.str());
merchant->onPlayerCheckItem(player, it.id, subType);
merchant->onPlayerCheckItem(player, it.id, count);
}

void Game::playerLookAt(uint32_t playerId, const Position& pos, uint8_t stackPos)
Expand Down Expand Up @@ -5639,6 +5619,11 @@ void Game::combatGetTypeInfo(CombatType_t combatType, Creature* target, TextColo
}
}
break;
case RACE_INK:
color = TEXTCOLOR_LIGHTGREY;
effect = CONST_ME_HITAREA;
splash = Item::CreateItem(ITEM_SMALLSPLASH, FLUID_INK);
break;
case RACE_UNDEAD:
color = TEXTCOLOR_LIGHTGREY;
effect = CONST_ME_HITAREA;
Expand Down
6 changes: 3 additions & 3 deletions src/items/functions/item_parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ const std::unordered_map<std::string, RaceType_t> RaceTypesMap = {
{"undead", RACE_UNDEAD},
{"fire", RACE_FIRE},
{"energy", RACE_ENERGY},
{"ink", RACE_INK},
};

const std::unordered_map<std::string, FluidTypes_t> FluidTypesMap = {
const std::unordered_map<std::string, Fluids_t> FluidTypesMap = {
{"water", FLUID_WATER },
{"blood", FLUID_BLOOD},
{"beer", FLUID_BEER},
Expand All @@ -205,11 +206,10 @@ const std::unordered_map<std::string, FluidTypes_t> FluidTypesMap = {
{"wine", FLUID_WINE },
{"mud", FLUID_MUD },
{"fruitjuice", FLUID_FRUITJUICE },
{"lava", FLUID_LAVA },
{"rum", FLUID_RUM },
{"swamp", FLUID_SWAMP },
{"tea", FLUID_TEA },
{"mead", FLUID_MEAD },
{"ink", FLUID_INK },
};

const std::unordered_map<std::string, WeaponType_t> WeaponTypesMap = {
Expand Down
2 changes: 1 addition & 1 deletion src/items/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class ItemType
Ammo_t ammoType = AMMO_NONE;
ShootType_t shootType = CONST_ANI_NONE;
RaceType_t corpseType = RACE_NONE;
FluidTypes_t fluidSource = FLUID_NONE;
Fluids_t fluidSource = FLUID_NONE;
TileFlags_t floorChange = TILESTATE_NONE;
std::map<ImbuementTypes_t, uint16_t> imbuementTypes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,8 @@ int MonsterTypeFunctions::luaMonsterTypeRace(lua_State* L) {
monsterType->info.race = RACE_FIRE;
} else if (race == "energy") {
monsterType->info.race = RACE_ENERGY;
} else if (race == "ink") {
monsterType->info.race = RACE_INK;
} else {
SPDLOG_WARN("[MonsterTypeFunctions::luaMonsterTypeRace] - "
"Unknown race type {}", race);
Expand Down
6 changes: 3 additions & 3 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ProtocolGame::AddItem(NetworkMessage &msg, uint16_t id, uint8_t count)
}
else if (it.isSplash() || it.isFluidContainer())
{
msg.addByte(fluidMap[count & 7]);
msg.addByte(count);
}
else if (it.isContainer())
{
Expand Down Expand Up @@ -99,7 +99,7 @@ void ProtocolGame::AddItem(NetworkMessage &msg, const Item *item)
}
else if (it.isSplash() || it.isFluidContainer())
{
msg.addByte(fluidMap[item->getFluidType() & 7]);
msg.addByte(static_cast<uint8_t>(item->getFluidType()));
}
else if (it.isContainer())
{
Expand Down Expand Up @@ -7087,7 +7087,7 @@ void ProtocolGame::AddShopItem(NetworkMessage &msg, const ShopBlock &shopBlock)
msg.add<uint16_t>(shopBlock.itemId);

if (it.isSplash() || it.isFluidContainer()) {
msg.addByte(static_cast<int32_t>(serverFluidToClient(shopBlock.itemSubType)));
msg.addByte(static_cast<uint8_t>(shopBlock.itemSubType));
} else {
msg.addByte(0x00);
}
Expand Down
20 changes: 0 additions & 20 deletions src/utils/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,26 +1036,6 @@ CombatType_t indexToCombatType(size_t v)
return static_cast<CombatType_t>(1 << v);
}

uint8_t serverFluidToClient(uint8_t serverFluid)
{
uint8_t size = sizeof(clientToServerFluidMap) / sizeof(uint8_t);
for (uint8_t i = 0; i < size; ++i) {
if (clientToServerFluidMap[i] == serverFluid) {
return i;
}
}
return 0;
}

uint8_t clientFluidToServer(uint8_t clientFluid)
{
uint8_t size = sizeof(clientToServerFluidMap) / sizeof(uint8_t);
if (clientFluid >= size) {
return 0;
}
return clientToServerFluidMap[clientFluid];
}

ItemAttrTypes stringToItemAttribute(const std::string& str)
{
if (str == "aid") {
Expand Down
3 changes: 0 additions & 3 deletions src/utils/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ std::string getWeaponName(WeaponType_t weaponType);
size_t combatTypeToIndex(CombatType_t combatType);
CombatType_t indexToCombatType(size_t v);

uint8_t serverFluidToClient(uint8_t serverFluid);
uint8_t clientFluidToServer(uint8_t clientFluid);

ItemAttrTypes stringToItemAttribute(const std::string& str);

const char* getReturnMessage(ReturnValue value);
Expand Down
116 changes: 21 additions & 95 deletions src/utils/utils_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,101 +399,27 @@ enum MessageClasses : uint8_t {
MESSAGE_POTION = 52, /* Orange creature say*/
};

enum FluidColors_t : uint8_t {
FLUID_EMPTY,
FLUID_BLUE,
FLUID_RED,
FLUID_BROWN,
FLUID_GREEN,
FLUID_YELLOW,
FLUID_WHITE,
FLUID_PURPLE,
};

enum FluidTypes_t : uint8_t {
FLUID_NONE = FLUID_EMPTY,
FLUID_WATER = FLUID_BLUE,
FLUID_BLOOD = FLUID_RED,
FLUID_BEER = FLUID_BROWN,
FLUID_SLIME = FLUID_GREEN,
FLUID_LEMONADE = FLUID_YELLOW,
FLUID_MILK = FLUID_WHITE,
FLUID_MANA = FLUID_PURPLE,

FLUID_LIFE = FLUID_RED + 8,
FLUID_OIL = FLUID_BROWN + 8,
FLUID_URINE = FLUID_YELLOW + 8,
FLUID_COCONUTMILK = FLUID_WHITE + 8,
FLUID_WINE = FLUID_PURPLE + 8,

FLUID_MUD = FLUID_BROWN + 16,
FLUID_FRUITJUICE = FLUID_YELLOW + 16,

FLUID_LAVA = FLUID_RED + 24,
FLUID_RUM = FLUID_BROWN + 24,
FLUID_SWAMP = FLUID_GREEN + 24,

FLUID_TEA = FLUID_BROWN + 32,

FLUID_MEAD = FLUID_BROWN + 40,
};

const uint8_t reverseFluidMap[] = {
FLUID_EMPTY,
FLUID_WATER,
FLUID_MANA,
FLUID_BEER,
FLUID_EMPTY,
FLUID_BLOOD,
FLUID_SLIME,
FLUID_EMPTY,
FLUID_LEMONADE,
FLUID_MILK,
};

const uint8_t clientToServerFluidMap[] = {
FLUID_EMPTY,
FLUID_WATER,
FLUID_MANA,
FLUID_BEER,
FLUID_MUD,
FLUID_BLOOD,
FLUID_SLIME,
FLUID_RUM,
FLUID_LEMONADE,
FLUID_MILK,
FLUID_WINE,
FLUID_LIFE,
FLUID_URINE,
FLUID_OIL,
FLUID_FRUITJUICE,
FLUID_COCONUTMILK,
FLUID_TEA,
FLUID_MEAD,
};

enum ClientFluidTypes_t : uint8_t {
CLIENTFLUID_EMPTY = 0,
CLIENTFLUID_BLUE = 1,
CLIENTFLUID_PURPLE = 2,
CLIENTFLUID_BROWN_1 = 3,
CLIENTFLUID_BROWN_2 = 4,
CLIENTFLUID_RED = 5,
CLIENTFLUID_GREEN = 6,
CLIENTFLUID_BROWN = 7,
CLIENTFLUID_YELLOW = 8,
CLIENTFLUID_WHITE = 9,
};

const uint8_t fluidMap[] = {
CLIENTFLUID_EMPTY,
CLIENTFLUID_BLUE,
CLIENTFLUID_RED,
CLIENTFLUID_BROWN_1,
CLIENTFLUID_GREEN,
CLIENTFLUID_YELLOW,
CLIENTFLUID_WHITE,
CLIENTFLUID_PURPLE,
enum Fluids_t : uint8_t {
FLUID_NONE = 0, /* Blue */
FLUID_WATER = 1, /* Blue */
FLUID_WINE = 2, /* Purple */
FLUID_BEER = 3, /* Brown */
FLUID_MUD = 4, /* Brown */
FLUID_BLOOD = 5, /* Red */
FLUID_SLIME = 6, /* Green */
FLUID_OIL = 7, /* Brown */
FLUID_URINE = 8, /* Yellow */
FLUID_MILK = 9, /* White */
FLUID_MANA = 10, /* Purple */
FLUID_LIFE = 11, /* Red */
FLUID_LEMONADE = 12, /* Yellow */
FLUID_RUM = 13, /* Brown */
FLUID_FRUITJUICE = 14, /* Yellow */
FLUID_COCONUTMILK = 15, /* White */
FLUID_MEAD = 16, /* Brown */
FLUID_TEA = 17, /* Brown */
FLUID_INK = 18 /* Black */
// 12.85 last fluid is 18, 19+ is a loop from 0 to 18 over and over again
};

enum SquareColor_t : uint8_t {
Expand Down

0 comments on commit ce36520

Please sign in to comment.