Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Welcome party in lua #4818

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions data/cpplinter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1098,13 +1098,6 @@ Weapon = {}
---@field onHear fun(creature:Creature, speaker:Creature, words:string, type:integer):nil
---@field onChangeZone fun(creature:Creature, fromZone:integer, toZone:integer):nil
---@field onUpdateStorage fun(creature:Creature, key:integer, value?:integer, oldValue?:integer, isSpawn?:boolean):nil
---@field onJoin fun(party:Party, player:Player):boolean
---@field onLeave fun(party:Party, player:Player):boolean
---@field onDisband fun(party:Party):boolean
---@field onShareExperience fun(party:Party, exp:integer, rawExp:integer):integer
---@field onInvite fun(party:Party, player:Player):boolean
---@field onRevokeInvitation fun(party:Party, player:Player):boolean
---@field onPassLeadership fun(party:Party, player:Player):boolean
---@field onLook fun(player:Player, thing:Thing, position:Position, distance:integer, description?:string):string
---@field onLookInBattleList fun(player:Player, creature:Creature, distance:integer, description?:string):string
---@field onLookInTrade fun(player:Player, partner:Player, item:Item, distance:integer, description?:string):string
Expand Down Expand Up @@ -1139,13 +1132,6 @@ EventCallback = Event()
---@field onHear boolean
---@field onChangeZone boolean
---@field onUpdateStorage boolean
---@field onJoin boolean
---@field onLeave boolean
---@field onDisband boolean
---@field onShareExperience boolean
---@field onInvite boolean
---@field onRevokeInvitation boolean
---@field onPassLeadership boolean
---@field onLook boolean
---@field onLookInBattleList boolean
---@field onLookInTrade boolean
Expand Down
9 changes: 0 additions & 9 deletions data/events/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
<event class="Creature" method="onChangeZone" enabled="0" />
<event class="Creature" method="onUpdateStorage" enabled="1" />

<!-- Party methods -->
<event class="Party" method="onJoin" enabled="0" />
<event class="Party" method="onLeave" enabled="0" />
<event class="Party" method="onDisband" enabled="0" />
<event class="Party" method="onShareExperience" enabled="1" />
<event class="Party" method="onInvite" enabled="0" />
<event class="Party" method="onRevokeInvitation" enabled="0" />
<event class="Party" method="onPassLeadership" enabled="0" />

<!-- Player methods -->
<event class="Player" method="onBrowseField" enabled="0" />
<event class="Player" method="onLook" enabled="1" />
Expand Down
67 changes: 0 additions & 67 deletions data/events/scripts/party.lua

This file was deleted.

56 changes: 45 additions & 11 deletions data/lib/core/position.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ function mt.__sub(lhs, rhs)
end

function mt.__concat(lhs, rhs) return tostring(lhs) .. tostring(rhs) end

function mt.__eq(lhs, rhs) return lhs.x == rhs.x and lhs.y == rhs.y and lhs.z == rhs.z end

function mt.__tostring(self) return string.format("Position(%d, %d, %d)", self.x, self.y, self.z) end

Position.directionOffset = {
[DIRECTION_NORTH] = {x = 0, y = -1},
[DIRECTION_EAST] = {x = 1, y = 0},
[DIRECTION_SOUTH] = {x = 0, y = 1},
[DIRECTION_WEST] = {x = -1, y = 0},
[DIRECTION_SOUTHWEST] = {x = -1, y = 1},
[DIRECTION_SOUTHEAST] = {x = 1, y = 1},
[DIRECTION_NORTHWEST] = {x = -1, y = -1},
[DIRECTION_NORTHEAST] = {x = 1, y = -1}
[DIRECTION_NORTH] = { x = 0, y = -1 },
[DIRECTION_EAST] = { x = 1, y = 0 },
[DIRECTION_SOUTH] = { x = 0, y = 1 },
[DIRECTION_WEST] = { x = -1, y = 0 },
[DIRECTION_SOUTHWEST] = { x = -1, y = 1 },
[DIRECTION_SOUTHEAST] = { x = 1, y = 1 },
[DIRECTION_NORTHWEST] = { x = -1, y = -1 },
[DIRECTION_NORTHEAST] = { x = 1, y = -1 }
}

local abs, max = math.abs, math.max
Expand Down Expand Up @@ -72,7 +74,39 @@ function Position:moveUpstairs()
return self
end

function Position:isInRange(from, to)
function Position:getOffsetX(from, to)
return from.x - to.x
end

function Position:getOffsetY(from, to)
return from.y - to.y
end

function Position:getOffsetZ(from, to)
return from.z - to.z
end

function Position:getDistanceX(from, to)
return math.abs(from:getOffsetX(to))
end

function Position:getDistanceY(from, to)
return math.abs(from:getOffsetY(to))
end

function Position:getDistanceZ(from, to)
return math.abs(from:getOffsetZ(to))
end

function Position:isInRange(from, to, deltax, deltay, deltaz)
if deltax and deltay then
if deltaz then
return from:getDistanceX(to) <= deltax and from:getDistanceY(to) <= deltay and
from:getDistanceZ(to) <= deltaz
end
return from:getDistanceX(to) <= deltax and from:getDistanceY(to) <= deltay
end

-- No matter what corner from and to is, we want to make
-- life easier by calculating north-west and south-east
local zone = {
Expand All @@ -89,8 +123,8 @@ function Position:isInRange(from, to)
}

if self.x >= zone.nW.x and self.x <= zone.sE.x
and self.y >= zone.nW.y and self.y <= zone.sE.y
and self.z >= zone.nW.z and self.z <= zone.sE.z then
and self.y >= zone.nW.y and self.y <= zone.sE.y
and self.z >= zone.nW.z and self.z <= zone.sE.z then
return true
end
return false
Expand Down
8 changes: 0 additions & 8 deletions data/scripts/lib/event_callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ ec.onTargetCombat = {returnValue=true}
ec.onHear = {}
ec.onChangeZone = {}
ec.onUpdateStorage = {}
-- Party
ec.onJoin = {}
ec.onLeave = {}
ec.onDisband = {}
ec.onShareExperience = {}
ec.onInvite = {}
ec.onRevokeInvitation = {}
ec.onPassLeadership = {}
-- Player
ec.onBrowseField = {}
ec.onLook = {[5] = 1}
Expand Down
108 changes: 108 additions & 0 deletions data/scripts/network/party.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
do
-- Invite packet
local handler = PacketHandler(0xA3)

function handler.onReceive(player, msg)
local targetId = msg:getU32()
local target = Player(targetId)
if not target then
return
end

local party = player:getParty()
if party then
party:invite(player, target)
end
end

handler:register()
end

do
-- Join packet
local handler = PacketHandler(0xA4)

function handler.onReceive(player, msg)
local targetId = msg:getU32()
local target = Player(targetId)
if not target then
return
end

local party = player:getParty()
if party then
party:join(player, target)
end
end

handler:register()
end

do
-- Revoke invite packet
local handler = PacketHandler(0xA5)

function handler.onReceive(player, msg)
local targetId = msg:getU32()
local target = Player(targetId)
if not target then
return
end

local party = player:getParty()
if party then
party:revokeInvitation(player, target)
end
end

handler:register()
end

do
-- Pass leadership packet
local handler = PacketHandler(0xA6)

function handler.onReceive(player, msg)
local targetId = msg:getU32()
local target = Player(targetId)
if not target then
return
end

local party = player:getParty()
if party then
party:passLeadership(player, target)
end
end

handler:register()
end

do
-- Leave packet
local handler = PacketHandler(0xA7)

function handler.onReceive(player, msg)
local party = player:getParty()
if party then
party:leave(player)
end
end

handler:register()
end

do
-- Shared experience packet
local handler = PacketHandler(0xA8)

function handler.onReceive(player, msg)
local active = msg:getByte() == 1
local party = player:getParty()
if party then
party:setSharedExperience(player, active)
end
end

handler:register()
end
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ set(tfs_SRC
${CMAKE_CURRENT_LIST_DIR}/otserv.cpp
${CMAKE_CURRENT_LIST_DIR}/outfit.cpp
${CMAKE_CURRENT_LIST_DIR}/outputmessage.cpp
${CMAKE_CURRENT_LIST_DIR}/party.cpp
${CMAKE_CURRENT_LIST_DIR}/player.cpp
${CMAKE_CURRENT_LIST_DIR}/podium.cpp
${CMAKE_CURRENT_LIST_DIR}/position.cpp
Expand Down
Loading
Loading