tibia-client/modules/game/thing.lua

204 lines
8.3 KiB
Lua
Raw Normal View History

2012-01-03 21:41:00 +01:00
2012-01-13 01:31:39 +01:00
function Thing:isInsideContainer()
local pos = self:getPos()
return (pos and pos.x == 65535 and pos.y >= 64)
end
function Thing:getContainerId()
local pos = self:getPos()
if not pos then return 0 end
return pos.y - 64
end
2012-01-03 21:41:00 +01:00
-- public functions
2012-01-09 21:54:37 +01:00
function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing)
local keyboardModifiers = g_window.getKeyboardModifiers()
2012-01-12 02:21:59 +01:00
2012-01-12 00:10:44 +01:00
local selectedThing = Game.getSelectedThing()
if mouseButton == MouseRightButton and selectedThing then
Game.setSelectedThing(nil)
return true
end
2012-01-12 02:21:59 +01:00
2012-01-12 00:10:44 +01:00
if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton and not Game.getSelectedThing() then
2012-01-09 21:54:37 +01:00
-- todo auto walk
return true
end
2012-01-12 02:21:59 +01:00
2012-01-09 21:54:37 +01:00
if not Options.classicControl then
2012-01-12 00:10:44 +01:00
if mouseButton == MouseLeftButton and selectedThing then
2012-01-20 06:45:56 +01:00
Game.useWith(Game.getSelectedThing(), multiUseThing)
2012-01-12 00:10:44 +01:00
Game.setSelectedThing(nil)
2012-01-13 01:31:39 +01:00
restoreCursor()
2012-01-12 00:10:44 +01:00
return true
elseif keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
2012-01-09 21:54:37 +01:00
Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.look(lookThing)
return true
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
if useThing:isContainer() then
2012-01-13 01:31:39 +01:00
if useThing:isInsideContainer() then
Game.open(useThing, useThing:getContainerId())
else
Game.open(useThing, Containers.getFreeContainerId())
end
2012-01-09 21:54:37 +01:00
elseif useThing:isMultiUse() then
2012-01-12 00:10:44 +01:00
Game.setSelectedThing(useThing)
2012-01-12 02:21:59 +01:00
setTargetCursor()
2012-01-09 21:54:37 +01:00
else
Game.use(useThing)
end
return true
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.attack(creatureThing)
return true
end
else
2012-01-12 00:10:44 +01:00
if mouseButton == MouseLeftButton and selectedThing then
Game.useWith(Game.getSelectedThing(), multiUseThing)
Game.setSelectedThing(nil)
2012-01-12 02:21:59 +01:00
restoreCursor()
2012-01-12 00:10:44 +01:00
return true
elseif multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
2012-01-09 21:54:37 +01:00
if multiUseThing:asCreature() then
Game.attack(multiUseThing:asCreature())
elseif multiUseThing:isContainer() then
2012-01-13 01:31:39 +01:00
if multiUseThing:isInsideContainer() then
Game.open(multiUseThing, multiUseThing:getContainerId())
else
Game.open(multiUseThing, Containers.getFreeContainerId())
end
2012-01-09 21:54:37 +01:00
elseif multiUseThing:isMultiUse() then
2012-01-12 00:10:44 +01:00
Game.setSelectedThing(multiUseThing)
2012-01-12 02:21:59 +01:00
setTargetCursor()
2012-01-09 21:54:37 +01:00
else
2012-01-13 01:31:39 +01:00
Game.use(multiUseThing)
2012-01-09 21:54:37 +01:00
end
return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.look(lookThing)
return true
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.attack(creatureThing)
return true
end
end
2012-01-12 02:21:59 +01:00
2012-01-09 21:54:37 +01:00
return false
end
2012-01-04 14:02:35 +01:00
function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
2012-01-03 21:41:00 +01:00
local menu = createWidget('PopupMenu')
2012-01-12 02:21:59 +01:00
2012-01-04 14:02:35 +01:00
if lookThing then
menu:addOption('Look', function() Game.look(lookThing) end)
end
2012-01-03 21:41:00 +01:00
2012-01-04 14:02:35 +01:00
if useThing then
if useThing:isContainer() then
2012-01-13 01:31:39 +01:00
if useThing:isInsideContainer() then
menu:addOption('Open', function() Game.open(useThing, useThing:getContainerId()) end)
menu:addOption('Open in new window', function() Game.open(useThing, Containers.getFreeContainerId()) end)
else
menu:addOption('Open', function() Game.open(useThing, Containers.getFreeContainerId()) end)
end
else
2012-01-04 14:02:35 +01:00
if useThing:isMultiUse() then
2012-01-13 01:31:39 +01:00
menu:addOption('Use with ...', function() Game.setSelectedThing(useThing) setTargetCursor() end)
else
2012-01-04 14:02:35 +01:00
menu:addOption('Use', function() Game.use(useThing) end)
end
end
2012-01-12 02:21:59 +01:00
2012-01-04 14:02:35 +01:00
if useThing:isRotateable() then
menu:addOption('Rotate', function() Game.rotate(useThing) end)
end
2012-01-12 02:21:59 +01:00
end
2012-01-12 02:21:59 +01:00
if lookThing and not lookThing:asCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then
menu:addSeparator()
menu:addOption('Trade with ...', function() print('trade with') end)
2012-01-04 14:02:35 +01:00
end
2012-01-12 02:21:59 +01:00
-- check for move up
2012-01-12 02:21:59 +01:00
2012-01-04 14:02:35 +01:00
if creatureThing then
menu:addSeparator()
2012-01-12 02:21:59 +01:00
2012-01-04 14:02:35 +01:00
if creatureThing:asLocalPlayer() then
2012-01-14 02:37:15 +01:00
menu:addOption('Set Outfit', function() Game.requestOutfit() end)
2012-01-12 02:21:59 +01:00
if creatureThing:asPlayer():isPartyMember() --[[and not fighting]] then
if creatureThing:asPlayer():isPartyLeader() then
if creatureThing:asPlayer():isPartySharedExperienceActive() then
menu:addOption('Disable Shared Experience', function() Game.partyShareExperience(false) end)
else
menu:addOption('Enable Shared Experience', function() Game.partyShareExperience(true) end)
end
end
menu:addOption('Leave Party', function() Game.partyLeave() end)
end
2012-01-12 02:21:59 +01:00
else
2012-01-07 23:24:29 +01:00
local localPlayer = Game.getLocalPlayer()
if localPlayer then
if localPlayer:getAttackingCreature() ~= creatureThing then
menu:addOption('Attack', function() Game.attack(creatureThing) end)
else
menu:addOption('Stop Attack', function() Game.cancelAttack() end)
end
2012-01-12 02:21:59 +01:00
2012-01-07 23:24:29 +01:00
if localPlayer:getFollowingCreature() ~= creatureThing then
menu:addOption('Follow', function() Game.follow(creatureThing) end)
else
menu:addOption('Stop Follow', function() Game.cancelFollow() end)
end
2012-01-12 02:21:59 +01:00
if creatureThing:asPlayer() then
menu:addSeparator()
menu:addOption('Message to ' .. creatureThing:getName(), function() print('message') end)
menu:addOption('Add to VIP list', function() Game.addVip(creatureThing:getName()) end)
menu:addOption('Ignore ' .. creatureThing:getName(), function() print('ignore') end)
2012-01-12 02:21:59 +01:00
local localPlayerShield = localPlayer:asCreature():getShield()
local creatureShield = creatureThing:getShield()
2012-01-12 02:21:59 +01:00
if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then
if creatureShield == ShieldWhiteYellow then
menu:addOption('Join ' .. creatureThing:getName() .. '\'s Party', function() Game.partyJoin(creatureThing:getId()) end)
else
menu:addOption('Invite to Party', function() Game.partyInvite(creatureThing:getId()) end)
end
elseif localPlayerShield == ShieldWhiteYellow then
if creatureShield == ShieldWhiteBlue then
menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() Game.partyRevokeInvitation(creatureThing:getId()) end)
end
elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then
if creatureShield == ShieldWhiteBlue then
menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() Game.partyRevokeInvitation(creatureThing:getId()) end)
elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield == ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then
menu:addOption('Pass Leadership to ' .. creatureThing:getName(), function() Game.partyPassLeadership(creatureThing:getId()) end)
else
menu:addOption('Invite to Party', function() Game.partyInvite(creatureThing:getId()) end)
end
end
end
2012-01-05 15:24:38 +01:00
end
end
menu:addSeparator()
2012-01-05 13:48:10 +01:00
menu:addOption('Copy Name', function() g_window.setClipboardText(creatureThing:getName()) end)
2012-01-12 02:21:59 +01:00
2012-01-03 21:41:00 +01:00
end
2012-01-12 02:21:59 +01:00
2012-01-03 21:41:00 +01:00
menu:display(menuPosition)
end
2012-01-13 01:31:39 +01:00