Skip to content

Commit

Permalink
fix networkmessage / fix pos distances / otcv8 features
Browse files Browse the repository at this point in the history
  • Loading branch information
MillhioreBT committed Apr 28, 2024
1 parent e365292 commit 093fc81
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 106 deletions.
8 changes: 4 additions & 4 deletions src/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ std::vector<Tile*> getList(const MatrixArea& area, const Position& targetPos, co

std::vector<Tile*> vec;

auto center = area.getCenter();
auto& center = area.getCenter();

Position tmpPos(targetPos.x - center.first, targetPos.y - center.second, targetPos.z);
for (uint32_t row = 0; row < area.getRows(); ++row, ++tmpPos.y) {
Expand Down Expand Up @@ -437,7 +437,7 @@ bool Combat::setParam(CombatParam_t param, uint32_t value)
return false;
}

int32_t Combat::getParam(CombatParam_t param)
int32_t Combat::getParam(CombatParam_t param) const
{
switch (param) {
case COMBAT_PARAM_TYPE:
Expand Down Expand Up @@ -1222,8 +1222,8 @@ void TargetCallback::onTargetCombat(Creature* creature, Creature* target) const

const MatrixArea& AreaCombat::getArea(const Position& centerPos, const Position& targetPos) const
{
int32_t dx = centerPos.getOffsetX(targetPos);
int32_t dy = centerPos.getOffsetY(targetPos);
int32_t dx = targetPos.getOffsetX(centerPos);
int32_t dy = targetPos.getOffsetY(centerPos);

Direction dir;
if (dx < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/combat.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Combat
bool loadCallBack(CallBackParam key, LuaScriptInterface* scriptInterface);

bool setParam(CombatParam_t param, uint32_t value);
int32_t getParam(CombatParam_t param);
int32_t getParam(CombatParam_t param) const;

void setArea(AreaCombat* area);
bool hasArea() const { return area != nullptr; }
Expand Down
142 changes: 142 additions & 0 deletions src/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,148 @@ enum ReloadTypes_t : uint8_t
RELOAD_TYPE_WEAPONS,
};

enum class GameFeature : uint8_t
{
ProtocolChecksum = 1,
AccountNames = 2,
ChallengeOnLogin = 3,
PenalityOnDeath = 4,
NameOnNpcTrade = 5,
DoubleFreeCapacity = 6,
DoubleExperience = 7,
TotalCapacity = 8,
SkillsBase = 9,
PlayerRegenerationTime = 10,
ChannelPlayerList = 11,
PlayerMounts = 12,
EnvironmentEffect = 13,
CreatureEmblems = 14,
ItemAnimationPhase = 15,
MagicEffectU16 = 16,
PlayerMarket = 17,
SpritesU32 = 18,
TileAddThingWithStackpos = 19,
OfflineTrainingTime = 20,
PurseSlot = 21,
FormatCreatureName = 22,
SpellList = 23,
ClientPing = 24,
ExtendedClientPing = 25,
DoubleHealth = 28,
DoubleSkills = 29,
ChangeMapAwareRange = 30,
MapMovePosition = 31,
AttackSeq = 32,
BlueNpcNameColor = 33,
DiagonalAnimatedText = 34,
LoginPending = 35,
NewSpeedLaw = 36,
ForceFirstAutoWalkStep = 37,
MinimapRemove = 38,
DoubleShopSellAmount = 39,
ContainerPagination = 40,
ThingMarks = 41,
LooktypeU16 = 42,
PlayerStamina = 43,
PlayerAddons = 44,
MessageStatements = 45,
MessageLevel = 46,
NewFluids = 47,
PlayerStateU16 = 48,
NewOutfitProtocol = 49,
PVPMode = 50,
WritableDate = 51,
AdditionalVipInfo = 52,
BaseSkillU16 = 53,
CreatureIcons = 54,
HideNpcNames = 55,
SpritesAlphaChannel = 56,
PremiumExpiration = 57,
BrowseField = 58,
EnhancedAnimations = 59,
OGLInformation = 60,
MessageSizeCheck = 61,
PreviewState = 62,
LoginPacketEncryption = 63,
ClientVersion = 64,
ContentRevision = 65,
ExperienceBonus = 66,
Authenticator = 67,
UnjustifiedPoints = 68,
SessionKey = 69,
DeathType = 70,
IdleAnimations = 71,
KeepUnawareTiles = 72,
IngameStore = 73,
IngameStoreHighlights = 74,
IngameStoreServiceType = 75,
AdditionalSkills = 76,
DistanceEffectU16 = 77,
Prey = 78,
DoubleMagicLevel = 79,

ExtendedOpcode = 80,
MinimapLimitedToSingleFloor = 81,
SendWorldName = 82,

DoubleLevel = 83,
DoubleSoul = 84,
DoublePlayerGoodsMoney = 85,
CreatureWalkthrough = 86,
DoubleTradeMoney = 87,
SequencedPackets = 88,
Tibia12Protocol = 89,

// 90-99 otclientv8 features
NewWalking = 90,
SlowerManualWalking = 91,

ItemTooltip = 93,

Bot = 95,
BiggerMapCache = 96,
ForceLight = 97,
NoDebug = 98,
BotProtection = 99,

// Custom features for customer
CreatureDirectionPassable = 100,
FasterAnimations = 101,
CenteredOutfits = 102,
SendIdentifiers = 103,
WingsAndAura = 104,
PlayerStateU32 = 105,
OutfitShaders = 106,
ForceAllowItemHotkeys = 107,
CountU16 = 108,
DrawAuraOnTop = 109,

// advanced features
PacketSizeU32 = 110,
PacketCompression = 111,

// OTCv8-dev features
OldInformationBar = 112,
HealthInfoBackground = 113,
WingOffset = 114,
AuraFrontAndBack = 115,

MapDrawGroundFirst = 116,
MapIgnoreCorpseCorrection = 117,
DontCacheFiles = 118,
BigAurasCenter = 119,
NewUpdateWalk = 120,
NewCreatureStacking = 121,
CreaturesMana = 122,
QuickLootFlags = 123,
DontMergeAnimatedText = 124,
MissionId = 125,
ItemCustomAttributes = 126,
AnimatedTextCustomFont = 127,

LastFeature = 130
};

inline constexpr int32_t CHANNEL_GUILD = 0x00;
inline constexpr int32_t CHANNEL_PARTY = 0x01;
inline constexpr int32_t CHANNEL_PRIVATE = 0xFFFF;
Expand Down
18 changes: 9 additions & 9 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ void Creature::updateTileCache(const Tile* tile, const Position& pos)
{
const Position& myPos = getPosition();
if (pos.z == myPos.z) {
int32_t dx = myPos.getOffsetX(pos);
int32_t dy = myPos.getOffsetY(pos);
int32_t dx = pos.getOffsetX(myPos);
int32_t dy = pos.getOffsetY(myPos);
updateTileCache(tile, dx, dy);
}
}
Expand All @@ -359,8 +359,8 @@ int32_t Creature::getWalkCache(const Position& pos) const
return 1;
}

if (int32_t dx = myPos.getOffsetX(pos); std::abs(dx) <= maxWalkCacheWidth) {
if (int32_t dy = myPos.getOffsetY(pos); std::abs(dy) <= maxWalkCacheHeight) {
if (int32_t dx = pos.getOffsetX(myPos); std::abs(dx) <= maxWalkCacheWidth) {
if (int32_t dy = pos.getOffsetY(myPos); std::abs(dy) <= maxWalkCacheHeight) {
if (localMapCache[maxWalkCacheHeight + dy][maxWalkCacheWidth + dx]) {
return 1;
}
Expand Down Expand Up @@ -476,7 +476,7 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos
if (oldPos.z != newPos.z) {
// floor change extra cost
lastStepCost = 2;
} else if (newPos.getDistanceX(oldPos) >= 1 && oldPos.getDistanceY(newPos) >= 1) {
} else if (newPos.getDistanceX(oldPos) >= 1 && newPos.getDistanceY(oldPos) >= 1) {
// diagonal extra cost
lastStepCost = 3;
if (getPlayer()) {
Expand All @@ -492,7 +492,7 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos
std::forward_list<Creature*> despawnList;
for (Creature* summon : summons) {
const Position& pos = summon->getPosition();
if (newPos.getDistanceZ(pos) > 2 || std::max(newPos.getDistanceX(pos), pos.getDistanceY(newPos)) > 30) {
if (newPos.getDistanceZ(pos) > 2 || std::max(newPos.getDistanceX(pos), newPos.getDistanceY(pos)) > 30) {
despawnList.push_front(summon);
}
}
Expand Down Expand Up @@ -1565,7 +1565,7 @@ bool FrozenPathingConditionCall::isInRange(const Position& startPos, const Posit
return false;
}
} else {
int32_t dx = targetPos.getOffsetX(startPos);
int32_t dx = startPos.getOffsetX(targetPos);

int32_t dxMax = (dx >= 0 ? fpp.maxTargetDist : 0);
if (testPos.x > targetPos.x + dxMax) {
Expand All @@ -1577,7 +1577,7 @@ bool FrozenPathingConditionCall::isInRange(const Position& startPos, const Posit
return false;
}

int32_t dy = targetPos.getOffsetY(startPos);
int32_t dy = startPos.getOffsetY(targetPos);

int32_t dyMax = (dy >= 0 ? fpp.maxTargetDist : 0);
if (testPos.y > targetPos.y + dyMax) {
Expand All @@ -1603,7 +1603,7 @@ bool FrozenPathingConditionCall::operator()(const Position& startPos, const Posi
return false;
}

int32_t testDist = std::max(targetPos.getDistanceX(testPos), testPos.getDistanceY(targetPos));
int32_t testDist = std::max(targetPos.getDistanceX(testPos), targetPos.getDistanceY(testPos));
if (fpp.maxTargetDist == 1) {
if (testDist < fpp.minTargetDist || testDist > fpp.maxTargetDist) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3195,7 +3195,7 @@ void Game::playerLookAt(uint32_t playerId, const Position& pos, uint8_t stackPos

int32_t lookDistance = -1;
if (thing != player) {
lookDistance = std::max(playerPos.getDistanceX(thingPos), thingPos.getDistanceY(playerPos));
lookDistance = std::max(playerPos.getDistanceX(thingPos), playerPos.getDistanceY(thingPos));
if (playerPos.z != thingPos.z) {
lookDistance += 15;
}
Expand Down
1 change: 1 addition & 0 deletions src/itemloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ enum itemattrib_t
ITEM_ATTR_WRITEABLE3, // deprecated

ITEM_ATTR_WAREID,
ITEM_ATTR_CLASSIFICATION,

ITEM_ATTR_LAST
};
Expand Down
8 changes: 8 additions & 0 deletions src/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,13 @@ bool Items::loadFromOtb(const std::string& file)
break;
}

case ITEM_ATTR_CLASSIFICATION: {
if (!stream.skip(1)) {
return false;
}
break;
}

default: {
// skip unknown attributes
if (!stream.skip(datalen)) {
Expand Down Expand Up @@ -552,6 +559,7 @@ bool Items::loadFromOtb(const std::string& file)
iType.rotatable = hasBitSet(FLAG_ROTATABLE, flags);
iType.canReadText = hasBitSet(FLAG_READABLE, flags);
iType.lookThrough = hasBitSet(FLAG_LOOKTHROUGH, flags);
iType.isAnimation = hasBitSet(FLAG_ANIMATION, flags);
// iType.walkStack = !hasBitSet(FLAG_FULLTILE, flags);
iType.forceUse = hasBitSet(FLAG_FORCEUSE, flags);

Expand Down
1 change: 1 addition & 0 deletions src/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ class ItemType
bool isHangable = false;
bool allowDistRead = false;
bool lookThrough = false;
bool isAnimation = false;
bool stopTime = false;
bool showCount = true;
bool supply = false;
Expand Down
41 changes: 37 additions & 4 deletions src/luanetworkmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ using namespace Lua;
// NetworkMessage
int luaNetworkMessageCreate(lua_State* L)
{
// NetworkMessage()
// NetworkMessage([player])
pushUserdata<NetworkMessage>(L, new NetworkMessage);
setMetatable(L, -1, "NetworkMessage");

if (const auto player = getPlayer(L, 1)) {
lua_pushinteger(L, player->getID());
lua_setiuservalue(L, 2, 1);
}
return 1;
}

Expand Down Expand Up @@ -211,7 +216,17 @@ int luaNetworkMessageAddItem(lua_State* L)

NetworkMessage* message = getUserdata<NetworkMessage>(L, 1);
if (message) {
message->addItem(item, false);
if (getAssociatedValue(L, 1, 1)) {
if (const auto player = getPlayer(L, -1)) {
message->addItem(item, player->isOTCv8());
} else {
reportErrorFunc(L, LuaScriptInterface::getErrorDesc(LuaErrorCode::PLAYER_NOT_FOUND));
lua_pushnil(L);
return 1;
}
} else {
message->addItem(item, false);
}
pushBoolean(L, true);
} else {
lua_pushnil(L);
Expand Down Expand Up @@ -239,7 +254,17 @@ int luaNetworkMessageAddItemId(lua_State* L)
}
}

message->addItemId(itemId, false);
if (getAssociatedValue(L, 1, 1)) {
if (const auto player = getPlayer(L, -1)) {
message->addItemId(itemId, player->isOTCv8());
} else {
reportErrorFunc(L, LuaScriptInterface::getErrorDesc(LuaErrorCode::PLAYER_NOT_FOUND));
lua_pushnil(L);
return 1;
}
} else {
message->addItemId(itemId, false);
}
pushBoolean(L, true);
return 1;
}
Expand Down Expand Up @@ -309,7 +334,7 @@ int luaNetworkMessageSkipBytes(lua_State* L)

int luaNetworkMessageSendToPlayer(lua_State* L)
{
// networkMessage:sendToPlayer(player)
// networkMessage:sendToPlayer([player])
NetworkMessage* message = getUserdata<NetworkMessage>(L, 1);
if (!message) {
lua_pushnil(L);
Expand All @@ -322,6 +347,14 @@ int luaNetworkMessageSendToPlayer(lua_State* L)
return 1;
}

if (getAssociatedValue(L, 1, 1)) {
if (const auto p = getPlayer(L, -1)) {
p->sendNetworkMessage(*message);
pushBoolean(L, true);
return 1;
}
}

reportErrorFunc(L, LuaScriptInterface::getErrorDesc(LuaErrorCode::PLAYER_NOT_FOUND));
lua_pushnil(L);
return 1;
Expand Down
Loading

0 comments on commit 093fc81

Please sign in to comment.