1-- @docclass Player
2
3PlayerStates = {
4 None = 0,
5 Poison = 1,
6 Burn = 2,
7 Energy = 4,
8 Drunk = 8,
9 ManaShield = 16,
10 Paralyze = 32,
11 Haste = 64,
12 Swords = 128,
13 Drowning = 256,
14 Freezing = 512,
15 Dazzled = 1024,
16 Cursed = 2048,
17 PartyBuff = 4096,
18 PzBlock = 8192,
19 Pz = 16384,
20 Bleeding = 32768,
21 Hungry = 65536
22}
23
24InventorySlotOther = 0
25InventorySlotHead = 1
26InventorySlotNeck = 2
27InventorySlotBack = 3
28InventorySlotBody = 4
29InventorySlotRight = 5
30InventorySlotLeft = 6
31InventorySlotLeg = 7
32InventorySlotFeet = 8
33InventorySlotFinger = 9
34InventorySlotAmmo = 10
35InventorySlotPurse = 11
36
37InventorySlotFirst = 1
38InventorySlotLast = 10
39
40function Player:isPartyLeader()
41 local shield = self:getShield()
42 return (shield == ShieldWhiteYellow or
43 shield == ShieldYellow or
44 shield == ShieldYellowSharedExp or
45 shield == ShieldYellowNoSharedExpBlink or
46 shield == ShieldYellowNoSharedExp)
47end
48
49function Player:isPartyMember()
50 local shield = self:getShield()
51 return (shield == ShieldWhiteYellow or
52 shield == ShieldYellow or
53 shield == ShieldYellowSharedExp or
54 shield == ShieldYellowNoSharedExpBlink or
55 shield == ShieldYellowNoSharedExp or
56 shield == ShieldBlueSharedExp or
57 shield == ShieldBlueNoSharedExpBlink or
58 shield == ShieldBlueNoSharedExp or
59 shield == ShieldBlue)
60end
61
62function Player:isPartySharedExperienceActive()
63 local shield = self:getShield()
64 return (shield == ShieldYellowSharedExp or
65 shield == ShieldYellowNoSharedExpBlink or
66 shield == ShieldYellowNoSharedExp or
67 shield == ShieldBlueSharedExp or
68 shield == ShieldBlueNoSharedExpBlink or
69 shield == ShieldBlueNoSharedExp)
70end
71
72function Player:hasVip(creatureName)
73 for id, vip in pairs(g_game.getVips()) do
74 if (vip[1] == creatureName) then return true end
75 end
76 return false
77end
78
79function Player:isMounted()
80 local outfit = self:getOutfit()
81 return outfit.mount ~= nil and outfit.mount > 0
82end
83
84function Player:toggleMount()
85 if g_game.getFeature(GamePlayerMounts) then
86 g_game.mount(not self:isMounted())
87 end
88end
89
90function Player:mount()
91 if g_game.getFeature(GamePlayerMounts) then
92 g_game.mount(true)
93 end
94end
95
96function Player:dismount()
97 if g_game.getFeature(GamePlayerMounts) then
98 g_game.mount(false)
99 end
100end
101
102function Player:getItem(itemId, subType)
103 return g_game.findPlayerItem(itemId, subType or -1)
104end
105
106function Player:getItems(itemId, subType)
107 local subType = subType or -1
108
109 local items = {}
110 for i=InventorySlotFirst,InventorySlotLast do
111 local item = self:getInventoryItem(i)
112 if item and item:getId() == itemId and (subType == -1 or item:getSubType() == subType) then
113 table.insert(items, item)
114 end
115 end
116
117 for i, container in pairs(g_game.getContainers()) do
118 for j, item in pairs(container:getItems()) do
119 if item:getId() == itemId and (subType == -1 or item:getSubType() == subType) then
120 item.container = container
121 table.insert(items, item)
122 end
123 end
124 end
125 return items
126end
127
128function Player:getItemsCount(itemId)
129 local items, count = self:getItems(itemId), 0
130 for i=1,#items do
131 count = count + items[i]:getCount()
132 end
133 return count
134end
135
136function Player:hasState(state, states)
137 if not states then
138 states = self:getStates()
139 end
140
141 for i = 1, 32 do
142 local pow = math.pow(2, i-1)
143 if pow > states then break end
144
145 local states = bit32.band(states, pow)
146 if states == state then
147 return true
148 end
149 end
150 return false
151end
152