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 0, 1, 1, 1, 0, 0, 0, 0},
55{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
56{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
57{0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0}
58}
59
60--Diagonal waves
61AREADIAGONAL_WAVE4 = {
62{0, 0, 0, 0, 1, 0},
63{0, 0, 0, 1, 1, 0},
64{0, 0, 1, 1, 1, 0},
65{0, 1, 1, 1, 1, 0},
66{1, 1, 1, 1, 1, 0},
67{0, 0, 0, 0, 0, 3}
68}
69
70AREADIAGONAL_SQUAREWAVE5 = {
71{1, 1, 1, 0, 0},
72{1, 1, 1, 0, 0},
73{1, 1, 1, 0, 0},
74{0, 0, 0, 1, 0},
75{0, 0, 0, 0, 3}
76}
77
78AREADIAGONAL_WAVE6 = {
79{0, 0, 1},
80{0, 3, 0},
81{1, 0, 0}
82}
83
84--Beams
85AREA_BEAM1 = {
86{3}
87}
88
89AREA_BEAM5 = {
90{1},
91{1},
92{1},
93{1},
94{3}
95}
96
97AREA_BEAM7 = {
98{1},
99{1},
100{1},
101{1},
102{1},
103{1},
104{3}
105}
106
107AREA_BEAM8 = {
108{1},
109{1},
110{1},
111{1},
112{1},
113{1},
114{1},
115{3}
116}
117
118--Diagonal Beams
119AREADIAGONAL_BEAM5 = {
120{1, 0, 0, 0, 0},
121{0, 1, 0, 0, 0},
122{0, 0, 1, 0, 0},
123{0, 0, 0, 1, 0},
124{0, 0, 0, 0, 3}
125}
126
127AREADIAGONAL_BEAM7 = {
128{1, 0, 0, 0, 0, 0, 0},
129{0, 1, 0, 0, 0, 0, 0},
130{0, 0, 1, 0, 0, 0, 0},
131{0, 0, 0, 1, 0, 0, 0},
132{0, 0, 0, 0, 1, 0, 0},
133{0, 0, 0, 0, 0, 1, 0},
134{0, 0, 0, 0, 0, 0, 3}
135}
136
137--Circles
138AREA_CIRCLE2X2 = {
139{0, 1, 1, 1, 0},
140{1, 1, 1, 1, 1},
141{1, 1, 3, 1, 1},
142{1, 1, 1, 1, 1},
143{0, 1, 1, 1, 0}
144}
145
146AREA_CIRCLE3X3 = {
147{0, 0, 1, 1, 1, 0, 0},
148{0, 1, 1, 1, 1, 1, 0},
149{1, 1, 1, 1, 1, 1, 1},
150{1, 1, 1, 3, 1, 1, 1},
151{1, 1, 1, 1, 1, 1, 1},
152{0, 1, 1, 1, 1, 1, 0},
153{0, 0, 1, 1, 1, 0, 0}
154}
155
156-- Crosses
157AREA_CROSS1X1 = {
158{0, 1, 0},
159{1, 3, 1},
160{0, 1, 0}
161}
162
163AREA_CIRCLE5X5 = {
164{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
165{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
166{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
167{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
168{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
169{1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1},
170{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
171{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
172{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
173{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
174{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}
175}
176
177AREA_CIRCLE6X6 = {
178{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
179{0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
180{0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
181{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
182{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
183{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
184{1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1},
185{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
186{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
187{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
188{0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
189{0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
190{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}
191}
192
193--Squares
194AREA_SQUARE1X1 = {
195{1, 1, 1},
196{1, 3, 1},
197{1, 1, 1}
198}
199
200-- Walls
201AREA_WALLFIELD = {
202{1, 1, 3, 1, 1}
203}
204
205AREADIAGONAL_WALLFIELD = {
206{0, 0, 0, 0, 1},
207{0, 0, 0, 1, 1},
208{0, 1, 3, 1, 0},
209{1, 1, 0, 0, 0},
210{1, 0, 0, 0, 0},
211}
212
213-- Spells-only arrays
214
215--This HUGE array contains all corpses of the game, until protocol 8.0
216-- It is used on animate dead rune and on undead legion spell. No unmoveable corpses are there.
217CORPSES = {
2182806,2807,2808,2809,2810,2811,2812,2813,2814,2815,2816,2817,2818,2819,2820,2821,2822,2823,
2192824,2825,2826,2827,2828,2829,2830,2831,2832,2833,2834,2835,2836,2837,2838,2839,2840,2841,
2202842,2843,2844,2845,2846,2847,2848,2849,2850,2851,2852,2853,2854,2855,2856,2857,2858,2859,
2212879,2880,2881,2882,2883,2884,2885,2886,2887,2888,2889,2890,2891,2892,2893,2894,2895,2896,
2222897,2898,2899,2900,2901,2902,2903,2904,2905,2906,2907,2908,2909,2910,2911,2912,2913,2914,
2232915,2916,2917,2918,2919,2920,2921,2922,2923,2924,2925,2926,2927,2928,2929,2930,2931,2932,
2242933,2934,2935,2936,2937,2938,2939,2940,2941,2942,2943,2944,2945,2946,2947,2948,2949,2950,
2252951,2952,2953,2954,2955,2956,2957,2958,2959,2960,2961,2962,2963,2964,2965,2966,2967,2968,
2262969,2970,2971,2972,2973,2974,2975,2976,2977,2978,2979,2980,2981,2982,2983,2984,2985,2986,
2272987,2988,2989,2990,2991,2992,2993,2994,2995,2996,2997,2998,2999,3000,3001,3002,3003,3004,
2283005,3006,3007,3008,3009,3010,3011,3012,3013,3014,3015,3016,3017,3018,3019,3020,3021,3022,
2293023,3024,3025,3026,3027,3028,3029,3030,3031,3032,3033,3034,3035,3036,3037,3038,3039,3040,
2303041,3042,3043,3044,3045,3046,3047,3048,3049,3050,3051,3052,3053,3054,3055,3056,3057,3058,
2313059,3060,3061,3062,3063,3064,3065,3066,3067,3068,3069,3070,3071,3072,3073,3074,3075,3076,
2323077,3078,3079,3080,3081,3082,3083,3084,3085,3086,3087,3088,3089,3090,3091,3092,3093,3094,
2333095,3096,3097,3098,3099,3100,3101,3102,3103,3104,3105,3106,3107,3108,3109,3110,3111,3112,
2343113,3114,3115,3116,3117,3118,3119,3120,3121,3128,3129,3130,3131,3132,3133,3134,4252,4253,
2354254,4255,4256,4257,4258,4259,4260,4261,4262,4263,4264,4265,4266,4267,4268,4269,4270,4271,
2364272,4273,4274,4275,4276,4277,4278,4279,4280,4281,4282,4283,4284,4285,4286,4287,4288,4289,
2374290,4291,4292,4293,4294,4295,4296,4297,4298,4299,4300,4301,4302,4303,4304,4305,4306,4307,
2384308,4309,4310,4311,4312,4313,4314,4315,4316,4317,4318,4319,4320,4321,4322,4323,4324,4325,
2394326,4327,5522,5523,5524,5525,5526,5527,5528,5529,5530,5531,5532,5533,5534,5535,5536,5537,
2405538,5540,5541,5542,5565,5566,5567,5568,5625,5626,5627,5628,5629,5630,5666,5667,5668,5688,
2415689,5690,5727,5728,5729,5762,5765,5766,5767,5931,5932,5933,5934,5935,5936,5965,6022,6082,
2426083,6084,6303,6304,6305,6307,6308,6309,6310,6313,6314,6315,6317,6318,6319,6321,6322,6323,
2436325,6326,6327,6328,6329,6330,6333,6334,6335,6337,6338,6339,6341,6342,6343,6345,6346,6347,
2446349,6350,6351,6355,6365,6366,6367,6520,6521,6522,6560,7092,7093,7094,7256,7257,7258,7283,
2457284,7285,7317,7318,7319,7321,7322,7323,7325,7326,7328,7329,7331,7332,7333,7335,7336,7337,
2467339,7340,7341,7345,7346,7347,7623,7624,7625,7626,7627,7629,7630,7631,7638,7639,7640,7741,
2477742,7743,7848,7849,7908,7927,7928,7929,7931,7970,7971,8272}
248
249-- This array contains all destroyable field items
250FIELDS = {1487,1488,1489,1490,1491,1492,1493,1494,1495,1496,1500,1501,1502,1503,1504}
251
252function Player:addPartyCondition(combat, variant, condition, baseMana)
253 local party = self:getParty()
254 if not party then
255 self:sendCancelMessage(RETURNVALUE_NOPARTYMEMBERSINRANGE)
256 self:getPosition():sendMagicEffect(CONST_ME_POFF)
257 return false
258 end
259
260 local positions = combat:getPositions(self, variant)
261 local members = party:getMembers()
262 members[#members + 1] = party:getLeader()
263
264 local affectedMembers = {}
265 for _, member in ipairs(members) do
266 local memberPosition = member:getPosition()
267 for _, position in ipairs(positions) do
268 if memberPosition == position then
269 affectedMembers[#affectedMembers + 1] = member
270 end
271 end
272 end
273
274 if #affectedMembers <= 1 then
275 self:sendCancelMessage(RETURNVALUE_NOPARTYMEMBERSINRANGE)
276 self:getPosition():sendMagicEffect(CONST_ME_POFF)
277 return false
278 end
279
280 local mana = math.ceil(#affectedMembers * math.pow(0.9, #affectedMembers - 1) * baseMana)
281 if self:getMana() < mana then
282 self:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
283 self:getPosition():sendMagicEffect(CONST_ME_POFF)
284 return false
285 end
286
287 self:addMana(-mana)
288 self:addManaSpent(mana)
289
290 for _, member in ipairs(affectedMembers) do
291 member:addCondition(condition)
292 end
293
294 for _, position in ipairs(positions) do
295 position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
296 end
297 return true
298end
299
300function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
301 if not conjureCount and conjureId ~= 0 then
302 local itemType = ItemType(conjureId)
303 if itemType:getId() == 0 then
304 return false
305 end
306
307 local charges = itemType:getCharges()
308 if charges ~= 0 then
309 conjureCount = charges
310 end
311 end
312
313 if reagentId ~= 0 and not self:removeItem(reagentId, 1, -1) then
314 self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
315 self:getPosition():sendMagicEffect(CONST_ME_POFF)
316 return false
317 end
318
319 local item = self:addItem(conjureId, conjureCount)
320 if not item then
321 self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
322 self:getPosition():sendMagicEffect(CONST_ME_POFF)
323 return false
324 end
325
326 if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
327 item:decay()
328 end
329
330 self:getPosition():sendMagicEffect(item:getType():isRune() and CONST_ME_MAGIC_RED or effect)
331 return true
332end
333
334function Creature:addAttributeCondition(parameters)
335 local condition = Condition(CONDITION_ATTRIBUTES)
336 for _, parameter in ipairs(parameters) do
337 if parameter.key and parameter.value then
338 condition:setParameter(parameter.key, parameter.value)
339 end
340 end
341
342 self:addCondition(condition)
343end
344