Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- |
2 | -- PalletTrigger |
3 | -- |
4 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
5 | |
6 | PalletTrigger = {}; |
7 | |
8 | -- TODO sync this over the network (play the sound only for the client that was using the pallet fork, use palletFork.owner) |
9 | |
10 | local PalletTrigger_mt = Class(PalletTrigger, Object); |
11 | |
12 | InitStaticObjectClass(PalletTrigger, "PalletTrigger", ObjectIds.OBJECT_PALLET_TRIGGER); |
13 | |
14 | function PalletTrigger:onCreate(id) |
15 | local trigger = PalletTrigger:new(g_server ~= nil, g_client ~= nil); |
16 | --print("created pallet trigger, id: ", id); |
17 | local index = g_currentMission:addOnCreateLoadedObject(trigger); |
18 | trigger:load(id); |
19 | trigger:register(true); |
20 | --[[if g_client ~= nil then |
21 | g_client:getServerConnection():sendEvent(OnCreateLoadedObjectEvent:new(index)); |
22 | end;]] |
23 | end; |
24 | |
25 | function PalletTrigger:new(isServer, isClient) |
26 | |
27 | local self = Object:new(isServer, isClient, PalletTrigger_mt); |
28 | self.triggerId = 0; |
29 | self.deletePalletTimerId = 0; |
30 | return self; |
31 | end; |
32 | |
33 | function PalletTrigger:load(id) |
34 | self.triggerId = id; |
35 | addTrigger(self.triggerId, "triggerCallback", self); |
36 | |
37 | self.currentPallet = 0; |
38 | self.deletePalletTimerId = 0; |
39 | |
40 | return self; |
41 | end; |
42 | |
43 | function PalletTrigger:update() |
44 | end; |
45 | |
46 | function PalletTrigger:delete() |
47 | removeTrigger(self.triggerId); |
48 | if self.deletePalletTimerId ~= 0 then |
49 | removeTimer(self.deletePalletTimerId); |
50 | end; |
51 | |
52 | PalletTrigger:superClass().delete(self); |
53 | end; |
54 | |
55 | function PalletTrigger:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay) |
56 | |
57 | if otherId ~= 0 then |
58 | if onLeave then |
59 | local isPallet = getUserAttribute(otherId, "isPallet"); |
60 | |
61 | if isPallet ~= nil and isPallet then |
62 | --print("Pallet left trigger: ", tostring(otherId)); |
63 | self.currentPallet = 0; |
64 | end; |
65 | end; |
66 | |
67 | if onEnter then |
68 | local isPallet = getUserAttribute(otherId, "isPallet"); |
69 | |
70 | if isPallet ~= nil and isPallet then |
71 | self.currentPallet = otherId; |
72 | end; |
73 | end; |
74 | |
75 | if onLeave then |
76 | if self.isServer then |
77 | if self.deletePalletTimerId == 0 and self.currentPallet ~= 0 then |
78 | local isPalletFork = getUserAttribute(otherId, "isPalletFork"); |
79 | if isPalletFork ~= nil and isPalletFork then |
80 | --print("Pallet Fork left trigger: ", tostring(otherId)); |
81 | self.deletePalletTimerId = addTimer(2000, "palletTriggerTimerCallback", self); |
82 | end; |
83 | end; |
84 | end; |
85 | end; |
86 | end; |
87 | end; |
88 | |
89 | -- this is only executed on the server |
90 | function PalletTrigger:palletTriggerTimerCallback() |
91 | if self.currentPallet ~= 0 then |
92 | --print("Ka-Ching!"); |
93 | delete(self.currentPallet); |
94 | self.currentPallet = 0; |
95 | local difficultyMultiplier = 2 ^ (3 - g_currentMission.missionStats.difficulty); |
96 | --g_currentMission.missionStats.money = g_currentMission.missionStats.money + 400 * difficultyMultiplier; |
97 | local money = 400 * difficultyMultiplier; |
98 | g_currentMission:addSharedMoney(money); |
99 | g_currentMission:addMoneyChange(money, FSBaseMission.MONEY_TYPE_SINGLE, true); |
100 | -- g_currentMission:increaseReputation(1); |
101 | |
102 | playSample(g_currentMission.cashRegistrySound, 1, 1, 0); |
103 | |
104 | end; |
105 | self.deletePalletTimerId = 0; |
106 | return false; -- remove this timer |
107 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de