-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSponsor.as
More file actions
162 lines (115 loc) · 3.79 KB
/
Sponsor.as
File metadata and controls
162 lines (115 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package
{
import com.newgrounds.*;
import com.newgrounds.components.MedalPopup;
import com.newgrounds.components.FlashAd;
import flash.display.*;
import flash.utils.*;
public class Sponsor
{
public static var container:DisplayObjectContainer;
public static var stageHeight:Number;
public static var medalPopup:DisplayObject;
private static var medalNames:Array = [null, "Young love", "Heartbreak", "Those Robotic Hearts of His", "Robotic efficiency", "Perfectionist"];
public static function init (stage:Stage):void
{
API.connect(stage, Secret.NG_API_ID, Secret.NG_KEY);
stageHeight = stage.stageHeight;
}
public static function testMedals (final:Boolean = false):void
{
if (! (API.sessionId && API.sessionId != "0")) return;
if (! medalPopup) {
medalPopup = new MedalPopup;
medalPopup.x = 8;
medalPopup.y = container.stage.stageHeight - medalPopup.height - 8;
container.addChild(medalPopup);
}
for (var i:int = 1; i < medalNames.length; i++) {
var name:String = medalNames[i];
var f:Function = Sponsor["testMedal"+i];
var unlocked:Boolean = f();
if (name == "Those Robotic Hearts of His" && ! final) unlocked = false;
if (unlocked) {
var medal:Medal = API.getMedal(name);
if (! medal) continue;
if (! medal.unlocked) {
medal.unlock();
//showMedal(medal);
}
}
}
}
/*private static function showMedal (medal:Medal):void
{
var size:int = 50;
var border:int = 4;
size += border*2;
var sprite:Sprite = new Sprite;
sprite.graphics.beginFill(Main.GREY);
sprite.graphics.drawRect(0, -size, size, size);
sprite.graphics.endFill();
sprite.alpha = 0;
sprite.x = border;
sprite.y = stageHeight - border;
var medalImage: Sprite = medal.attachIcon(sprite);
medalImage.x = border;
medalImage.y = -size + border;
container.addChild(sprite);
FP.tween(sprite, {alpha: 1}, 30);
FP.tween(sprite, {alpha: 0}, 30, {delay: 120, complete: function ():void {
container.removeChild(sprite);
}});
}*/
private static function testMedal1 ():Boolean
{
return testCompletion(13);
}
private static function testMedal2 ():Boolean
{
return testCompletion(25);
}
private static function testMedal3 ():Boolean
{
return testCompletion(36);
}
private static function testMedal4 ():Boolean
{
return testPerfection(18);
}
private static function testMedal5 ():Boolean
{
return testPerfection(36);
}
private static function testCompletion (last:int):Boolean {
var Level2:Class = getDefinitionByName("Level") as Class;
var Main2:Class = getDefinitionByName("Main") as Class;
for (var i:int = 0; i < last; i++) {
var md5:String = Level2.levelPacks["normal"].md5[i];
if (! Main2.so.data.levels[md5] || ! Main2.so.data.levels[md5].completed) return false;
}
return true;
}
private static function testPerfection (last:int):Boolean {
var Level2:Class = getDefinitionByName("Level") as Class;
var Main2:Class = getDefinitionByName("Main") as Class;
for (var i:int = 0; i < last; i++) {
var md5:String = Level2.levelPacks["normal"].md5[i];
var minClicksMine:int = Level2.levelPacks["normal"].minClicksArray[i];
if (! Main2.so.data.levels[md5]) return false;
var minClicksTheirs:int = Main2.so.data.levels[md5].leastClicks;
if (minClicksTheirs > minClicksMine) return false;
}
return true;
}
public static function createAd():DisplayObject {
//if (! API.connected) return null;
return new FlashAd();
}
public static function update():void {
if (! API.connected) return;
if (API.isNewgrounds) return;
Preloader.mustClick = true;
}
}
}