This repository has been archived by the owner on Feb 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinePet.js
1470 lines (1360 loc) · 48.2 KB
/
MinePet.js
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Mine Pet Script 1.1v
* Team META #project 2
*
* @since 2016.8.1
*/
const Bitmap = android.graphics.Bitmap,
BitmapFactory = android.graphics.BitmapFactory,
Color = android.graphics.Color,
ColorDrawable = android.graphics.drawable.ColorDrawable,
NinePatchDrawable = android.graphics.drawable.NinePatchDrawable,
Gravity = android.view.Gravity,
View = android.view.View,
Button = android.widget.Button,
LinearLayout = android.widget.LinearLayout,
PopupWindow = android.widget.PopupWindow,
RelativeLayout = android.widget.RelativeLayout,
TextView = android.widget.TextView,
MainActivity = com.mojang.minecraftpe.MainActivity,
Runnable = java.lang.Runnable,
ctx = MainActivity.currentMainActivity.get(),
CENTER = Gravity.CENTER,
LEFT = Gravity.LEFT,
RIGHT = Gravity.RIGHT,
TOP = Gravity.TOP,
BOTTOM = Gravity.BOTTOM,
BLACK = Color.BLACK,
DKGRAY = Color.DKGRAY,
GRAY = Color.GRAY,
WHITE = Color.WHITE,
DARK = Color.argb(250, 40, 40, 40),
NONE = Color.TRANSPARENT,
RED = Color.parseColor("#EF5350"),
INDIGO = Color.parseColor("#5C6BC0"),
BLUE = Color.parseColor("#42A5F5"),
LIGHT_BLUE = Color.parseColor("#29B6F6"),
CYAN = Color.parseColor("#26C6DA"),
TEAL = Color.parseColor("#26A69A"),
GREEN = Color.parseColor("#66BB6A"),
LIGHT_GREEN = Color.parseColor("#9CCC65"),
LIME = Color.parseColor("#D4E157"),
YELLOW = Color.parseColor("#FFEE58"),
AMBER = Color.parseColor("#FFCA28"),
ORANGE = Color.parseColor("#FFA726"),
DEEP_ORANGE = Color.parseColor("#FF7043"),
BLUEGRAY = Color.parseColor("#78909C"),
Visible = Color.argb(140, 40, 40, 40),
PURPLE = Color.parseColor("#BA68C8"),
DEEP_PURPLE = Color.parseColor("#7E57C2"),
PINK = Color.parseColor("#F06292"),
density = ctx.getResources().getDisplayMetrics().density;
var GUI = {},
itemImageLoader = {},
myPet = null,
meal = [364];
var DATA = {
speed: 50,
dmg: -5,
hp: null,
knock: -100,
name: "NONAME"
};
ModPE.setItem(700, "name_tag", 0, "Name Tag");
/**
* AI Prototype
* @author Adagio(magicwhos@gmail.com)
* @since 2016.6.1
* @version 1.1
*/
var mobArr = [],
ai = {};
ai.death = function(v) {
var number = mobArr.indexOf(v);
if (number != -1) {
mobArr[number].deathHook();
mobArr[number].entity = null;
mobArr.splice(number, 1);
}
}
ai.tick = function() {
var pe = Player.getEntity(),
__A = null || function() {};
Entity.action(mobArr, function(__F) {
var __B = function() {} || null;
(__F.entity !== null ? function() {
__C = null || function() {};
var __D = null || (__F.isAttacked ? __C : function() {
Entity.setSaw(__F.entity, pe);
__F.move()
.changeType()
.attack();
__F.tick(__F);
})();
var __E = null || (__F.getHealth() < __F.hp ? function() {
new java.lang.Thread({
run: function() {
__F.isAttacked = true;
__F.isAttackedHook(__F);
java.lang.Thread.sleep(__F.delay << 5 >> 5);
__F.isAttacked = false;
}
}).start();
__F.hp = null || __F.getHealth();
} : __C)();
} : __B)();
} || __A);
}
function MakePet(entity) {
this.entity = entity;
this.maxHp = Entity.getMaxHealth(this.entity);
this.hp = Entity.getHealth(this.entity);
this.isAttacked = false;
this.isAttacktive = true;
this.target = Player.getEntity();
this.type = "NORMAL";
this.delay = 500;
this.mode = 0;
this.damage = {
NORMAL: -4,
ATTACK: -6,
AVOID: -2,
COUNTER_ATTACK: -8
};
this.knockBack = {
NORMAL: -100,
ATTACK: -150,
AVOID: -80,
COUNTER_ATTACK: -200
};
this.speed = {
NORMAL: 80,
ATTACK: 100,
AVOID: -20,
COUNTER_ATTACK: 120
};
mobArr.push(this);
return this;
}
MakePet.prototype = {};
MakePet.prototype.setSkin = function(path) {
Entity.setMobSkin(this.entity, path);
return this;
};
MakePet.prototype.getEntity = function() {
return this.entity;
};
MakePet.prototype.getType = function() {
return this.type;
};
MakePet.prototype.setType = function(type) {
this.type = type;
return this;
};
MakePet.setRenderType = function(renderer) {
Entity.setRenderType(this.entity, renderer);
return this;
};
MakePet.prototype.getHealth = function() {
return Entity.getHealth(this.entity);
};
MakePet.prototype.setHealth = function(n) {
this.hp = n;
Entity.setHealth(this.entity, n);
return this;
};
MakePet.prototype.getMaxHealth = function(n) {
return this.maxHp;
};
MakePet.prototype.setMaxHealth = function(n) {
this.maxHp = n;
Entity.setMaxHealth(this.entity, n);
return this;
};
MakePet.prototype.setDamage = function(type, n) {
if (type !== "ALL") this.damage[type] = n;
else {
for (var i in this.damage) this.damage[i] = n;
}
return this;
};
MakePet.prototype.setKnockBack = function(type, n) {
if (type !== "ALL") this.knockBack[type] = n;
else {
for (var i in this.knockBack) this.knockBack[i] = n;
}
return this;
};
MakePet.prototype.setSpeed = function(type, n) {
if (type !== "ALL") this.speed[type] = n;
else {
for (var i in this.speed) this.speed[i] = n;
}
return this;
};
MakePet.prototype.setTarget = function(ent) {
this.target = ent;
return this;
};
MakePet.prototype.getTarget = function(ent) {
return this.target;
};
MakePet.prototype.move = function() {
if(!this.isAttacktive && Entity.getDst(this.target, this.entity) > 4) {
if(this.mode == 1) Entity.setImmobile(this.entity, true);
else Entity.setImmobile(this.entity, false);
Entity.grab(this.entity, this.target, this.speed[this.type]);
}
return this;
};
MakePet.prototype.setDelay = function(mSecond) {
this.delay = mSecond;
return this;
};
MakePet.prototype.getDelay = function() {
return this.delay;
};
MakePet.prototype.setAttacktive = function(bool) {
this.isAttacktive = bool;
return this;
};
MakePet.prototype.getAttacktive = function() {
return this.isAttacktive;
};
MakePet.prototype.attack = function() {
if(this.isAttacktive) {
if (Entity.getDst(this.target, this.entity) <= 2) {
Entity.dmg(this.target, this.damage[this.type]);
if (this.knockBack[this.type] !== null) {
Entity.grab(this.target, this.entity, this.knockBack[this.type]);
}
this.attackHook(this, this.target);
}
}
return this;
};
MakePet.prototype.changeType = function() {
var hp = this.getHealth();
if (hp >= this.maxHp) this.type = "COUNTER_ATTACK";
else if (hp >= this.maxHp / 4 * 3) this.type = "NORMAL";
else if (hp >= this.maxHp / 4 * 2) this.type = "ATTACK";
else if (hp >= this.maxHp / 4 * 1) this.type = "AVOID";
else if (hp < this.maxHp / 4) this.type = "COUNTER_ATTACK";
return this;
};
MakePet.prototype.tick = function(ai) {};
MakePet.prototype.attackHook = function(ai, victim) {};
MakePet.prototype.isAttackedHook = function(ai) {};
MakePet.prototype.deathHook = function(ai) {};
function deathHook(a, v) {
ai.death(v);
}
function dp(pixel) {
return Math.ceil(pixel * density);
}
function attackHook(a, v) {
if (Player.getCarriedItem() == 700) {
preventDefault();
myPet = new MakePet(v);
myPet.setDamage("ALL", DATA.dmg)
.setKnockBack("ALL", DATA.knockBack)
.setSpeed("ALL", DATA.speed)
.setMaxHealth(20)
.setHealth(20)
.setTarget(Player.getEntity())
.setAttacktive(false)
.attackHook = function(attacker, victim) {
if (Entity.getHealth(victim) <= 0) {
attacker.setAttacktive(false)
.setTarget(Player.getEntity());
}
};
print("펫으로 설정했습니다.");
} else {
if(myPet.entity !== v && myPet !== null) {
myPet.setAttacktive(true);
myPet.setTarget(v);
}
}
}
function modTick() {
ai.tick();
}
function newLevel() {
GUI.open();
Player.addItemCreativeInv(700, 2, 0);
}
function leaveGame() {
GUI.close();
}
/**
* GUI의 Basic Source 입니다.
* @since 2016.08.05
*/
(GUI => {
"use strict";
GUI.sheet = BitmapFactory.decodeStream(ModPE.openInputStreamFromTexturePack("images/gui/spritesheet.png"));
GUI.touchGUI = BitmapFactory.decodeStream(ModPE.openInputStreamFromTexturePack("images/gui/touchgui.png"));
GUI.touchGUI2 = BitmapFactory.decodeStream(ModPE.openInputStreamFromTexturePack("images/gui/touchgui2.png"));
GUI.createNinePatch = (bitmap, x, y, xx, yy) => {
var NO_COLOR = 0x00000001;
var buffer = java.nio.ByteBuffer.allocate(84).order(java.nio.ByteOrder.nativeOrder());
buffer.put(0x01);
buffer.put(0x02);
buffer.put(0x02);
buffer.put(0x09);
for (var i = 0; i < 7; i++) {
buffer.putInt(0);
}
buffer.putInt(y);
buffer.putInt(yy);
buffer.putInt(x);
buffer.putInt(xx);
for (i = 0; i < 9; i++) {
buffer.putInt(NO_COLOR);
}
var drawable = new NinePatchDrawable(ctx.getResources(), bitmap, buffer.array(), new android.graphics.Rect(), null);
return drawable;
};
GUI.buttonNormal = function() {
var bitmap = Bitmap.createBitmap(GUI.sheet, 8, 32, 8, 8);
var bit = Bitmap.createScaledBitmap(bitmap, dp(16), dp(16), false);
return GUI.createNinePatch(bit, dp(4), dp(4), dp(12), dp(14));
};
GUI.buttonPress = function() {
var bitmap = Bitmap.createBitmap(GUI.sheet, 0, 32, 8, 8);
var bit = Bitmap.createScaledBitmap(bitmap, dp(16), dp(16), false);
return GUI.createNinePatch(bit, dp(4), dp(4), dp(12), dp(14));
};
GUI.window = function() {
var bitmap = Bitmap.createBitmap(GUI.sheet, 1, 1, 14, 14);
bitmap.setPixel(0, 0, 0x00000001);
bitmap.setPixel(13, 13, 0x00000001);
bitmap.setPixel(0, 13, 0x00000001);
bitmap.setPixel(13, 0, 0x00000001);
var bit = Bitmap.createScaledBitmap(bitmap, dp(32), dp(32), false);
return GUI.createNinePatch(bit, dp(8), dp(8), dp(16), dp(16));
};
GUI.ctx = ctx;
GUI.isOpen = false;
GUI.isMove = false;
GUI.mainWindow = null;
GUI.moveButtonWindow = null;
GUI.width = ctx.getWindowManager()
.getDefaultDisplay()
.getWidth();
GUI.height = ctx.getWindowManager()
.getDefaultDisplay()
.getHeight();
/**
* newLevel 함수에 호출되는 메인 버튼을 생성합니다.
* @since 2016.08.05
*/
GUI.open = function() {
GUI.runOnUiThread(ctx, function() {
var mainButton = new Button(ctx);
var mainLayout = new RelativeLayout(ctx);
GUI.onClick(mainButton, function() {
GUI.openMenu();
});
GUI.setClickEffect(mainButton);
mainLayout.addView(mainButton);
GUI.mainWindow = new PopupWindow(mainLayout, dp(48), dp(48), false);
GUI.mainWindow.showAtLocation(ctx.getWindow()
.getDecorView(), RIGHT | BOTTOM, 0, 0);
});
};
/**
* newLevel 함수에 호출되는 메인 버튼을 제거합니다.
* @since 2016.08.05
*/
GUI.close = function() {
GUI.runOnUiThread(ctx, function() {
if (GUI.mainWindow !== null) {
GUI.mainWindow.dismiss();
}
GUI.mainWindow = null;
});
};
/**
* open 버튼을 클릭할 시 생성되는 메인 메뉴를 생성합니다.
* @since 2016.08.05
*/
GUI.openMenu = function() {
GUI.runOnUiThread(ctx, function() {
if (myPet !== null) {
var layout = new LinearLayout(ctx);
layout.setOrientation(1);
layout.setPadding(dp(8), dp(8), dp(8), dp(8));
var title = new TextView(ctx);
title.setText("Mine Pet");
title.setGravity(LEFT);
title.setTextColor(YELLOW);
title.setTextSize(24);
title.setShadowLayer(1, dp(2), dp(2), Color.argb(255, 44, 44, 44));
layout.addView(title);
layout.addView(GUI.widget.line(2, WHITE));
layout.addView(GUI.widget.space());
var healthButton = new Button(ctx);
healthButton.setText("체력:" + Entity.getHealth(myPet.entity));
healthButton.setTextColor(WHITE);
healthButton.setId(0);
GUI.setClickEffect(healthButton);
GUI.onClick(healthButton, function(v) {
GUI.openOption(v.getId());
});
layout.addView(healthButton);
layout.addView(GUI.widget.space());
var speedButton = new Button(ctx);
speedButton.setText("속력");
speedButton.setTextColor(WHITE);
speedButton.setId(1);
GUI.setClickEffect(speedButton);
GUI.onClick(speedButton, function(v) {
GUI.openOption(v.getId());
});
layout.addView(speedButton);
layout.addView(GUI.widget.space());
var dmgButton = new Button(ctx);
dmgButton.setText("공격력");
dmgButton.setTextColor(WHITE);
dmgButton.setId(2);
GUI.setClickEffect(dmgButton);
GUI.onClick(dmgButton, function(v) {
GUI.openOption(v.getId());
});
layout.addView(dmgButton);
layout.addView(GUI.widget.space());
var modeButton = new Button(ctx);
modeButton.setText((myPet.mode === 0 ? "걷기" : "앉기"));
modeButton.setTextColor(WHITE);
GUI.setClickEffect(modeButton);
GUI.onClick(modeButton, function(v) {
myPet.mode++;
if (myPet.mode === 3) {
myPet.mode = 0;
}
if (myPet.mode === 0) {
v.setText("걷기");
}
if (myPet.mode === 1) {
v.setText("앉기");
}
if (myPet.mode === 2) {
v.setText("타기");
Entity.rideAnimal(Player.getEntity(), myPet.entity);
} else {
var ent = Level.spawnMob(Player.getX(), Player.getY(), Player.getZ(), 81);
Entity.rideAnimal(Player.getEntity(), ent);
Entity.remove(ent);
}
});
layout.addView(modeButton);
layout.addView(GUI.widget.space());
layout.addView(GUI.widget.line(2, WHITE));
layout.addView(GUI.widget.space());
var settingButton = new Button(ctx);
settingButton.setText("설정");
settingButton.setTextColor(WHITE);
settingButton.setId(3);
GUI.setClickEffect(settingButton);
GUI.onClick(settingButton, function(v) {
});
layout.addView(settingButton);
GUI.menuWindow = new PopupWindow(layout, GUI.width / 3, GUI.height, true);
GUI.menuWindow.setBackgroundDrawable(GUI.window());
GUI.menuWindow.showAtLocation(ctx.getWindow()
.getDecorView(), RIGHT | BOTTOM, 0, 0);
} else {
print("펫이 존재하지 않습니다.");
}
});
};
/**
* open 버튼을 클릭할 시 생성되는 메인 메뉴를 제거합니다.
* @since 2016.08.05
*/
GUI.closeMenu = function() {
GUI.runOnUiThread(ctx, function() {
if (GUI.menuWindow !== null) {
GUI.menuWindow.dismiss();
}
GUI.menuWindow = null;
});
};
/**
* 버튼에 따라 여러가지 옵션창을 생성합니다.
* @since 2016.08.05
*/
GUI.openOption = function(id) {
switch (id) {
case 0:
GUI.openHealth();
break;
case 1:
GUI.openSpeed();
break;
case 2:
GUI.openDamage();
break;
}
};
/**
* 텍스트를 반복시켜 반환합니다
* @since 2016.9.17
*/
GUI.repeatText = function(str, n) {
var text = "";
for (var i = 0; i < n; i++) {
text += str;
}
return text;
}
/**
* myPet의 체력을 수정할 수 있는 창을 생성합니다.
* @since 2016.08.05
*/
GUI.openHealth = function() {
GUI.runOnUiThread(ctx, function() {
var layout = new LinearLayout(ctx);
layout.setOrientation(1);
layout.setPadding(dp(8), dp(8), dp(8), dp(8));
var title = new TextView(ctx);
title.setText("Health");
title.setGravity(LEFT);
title.setTextColor(YELLOW);
title.setTextSize(24);
title.setShadowLayer(1, dp(2), dp(2), Color.argb(255, 44, 44, 44));
layout.addView(title);
layout.addView(GUI.widget.line(2, WHITE));
layout.addView(GUI.widget.space());
var healthView = new TextView(ctx);
healthView.setGravity(CENTER);
healthView.setTextColor(RED);
healthView.setTextSize(16);
healthView.setText(GUI.repeatText("1", myPet.getHealth()));
layout.addView(healthView);
var button = new Button(ctx);
button.setText("heal");
GUI.setClickEffect(button);
GUI.onClick(button, function() {
let meal = [364];
for (var i = 0; i < 55; i++) {
var slot = Player.getInventorySlot(i);
if (meal.indexOf(slot) !== -1) {
Entity.dmg(myPet.entity, 4);
Player.setInventorySlot(i, slot, Player.getInventorySlotCount(i) - 1, Player.getInventorySlotData(i));
break;
}
}
print("먹이가 없습니다.");
});
layout.addView(button);
var window = new PopupWindow(layout, GUI.width / 3, GUI.height / 3, true);
window.setBackgroundDrawable(GUI.window());
window.showAtLocation(ctx.getWindow()
.getDecorView(), RIGHT | BOTTOM, GUI.width / 3, GUI.height / 3);
});
};
/**
* myPet의 속력을 수정할 수 있는 창을 생성합니다.
* @since 2016.08.05
*/
GUI.openSpeed = function() {
GUI.runOnUiThread(ctx, function() {
var layout = new LinearLayout(ctx);
layout.setOrientation(1);
layout.setPadding(dp(8), dp(8), dp(8), dp(8));
var title = new TextView(ctx);
title.setText("speed");
title.setGravity(LEFT);
title.setTextColor(YELLOW);
title.setTextSize(24);
title.setShadowLayer(1, dp(2), dp(2), Color.argb(255, 44, 44, 44));
layout.addView(title);
layout.addView(GUI.widget.line(2, WHITE));
layout.addView(GUI.widget.space());
var speedView = new TextView(ctx);
speedView.setGravity(CENTER);
speedView.setTextColor(RED);
speedView.setTextSize(16);
speedView.setText(GUI.repeatText("2", myPet.speed.NORMAL) + "%");
layout.addView(speedView);
var button = new Button(ctx);
button.setText("heal");
GUI.setClickEffect(button);
GUI.onClick(button, function() {
let meal = [364];
for (var i = 0; i < 55; i++) {
var slot = Player.getInventorySlot(i);
if (meal.indexOf(slot) !== -1) {
Entity.dmg(myPet.entity, 4);
Player.setInventorySlot(i, slot, Player.getInventorySlotCount(i) - 1, Player.getInventorySlotData(i));
break;
}
}
print("먹이가 없습니다.");
});
layout.addView(button);
var window = new PopupWindow(layout, GUI.width / 3, GUI.height / 3, true);
window.setBackgroundDrawable(GUI.window());
window.showAtLocation(ctx.getWindow()
.getDecorView(), RIGHT | BOTTOM, GUI.width / 3, GUI.height / 3);
});
};
/**
* myPet의 공격력을 수정할 수 있는 창을 생성합니다.
* @since 2016.08.05
*/
GUI.openDamage = function() {
GUI.runOnUiThread(ctx, function() {
var layout = new LinearLayout(ctx);
layout.setOrientation(1);
layout.setPadding(dp(8), dp(8), dp(8), dp(8));
var title = new TextView(ctx);
title.setText("Damage");
title.setGravity(LEFT);
title.setTextColor(YELLOW);
title.setTextSize(24);
title.setShadowLayer(1, dp(2), dp(2), Color.argb(255, 44, 44, 44));
layout.addView(title);
layout.addView(GUI.widget.line(2, WHITE));
layout.addView(GUI.widget.space());
var healthView = new TextView(ctx);
healthView.setGravity(CENTER);
healthView.setTextColor(RED);
healthView.setText(GUI.repeatText("3", myPet.damage.NORMAL));
healthView.setTextSize(16);
layout.addView(healthView);
var button = new Button(ctx);
button.setText("heal");
GUI.setClickEffect(button);
GUI.onClick(button, function() {
for (var i = 0; i < 55; i++) {
var slot = Player.getInventorySlot(i);
if (meal.indexOf(slot) !== -1) {
Entity.dmg(myPet.entity, 4);
Player.setInventorySlot(i, slot, Player.getInventorySlotCount(i) - 1, Player.getInventorySlotData(i));
break;
}
}
});
layout.addView(button);
var window = new PopupWindow(layout, GUI.width / 3, GUI.height / 3, true);
window.setBackgroundDrawable(GUI.window());
window.showAtLocation(ctx.getWindow()
.getDecorView(), RIGHT | BOTTOM, GUI.width / 3, GUI.height / 3);
});
};
/**
* myPet을 움직일 수 있게 만드는 버튼을 생성합니다.
* @since 2016.08.05
*/
GUI.openMoveButton = function() {
if (!GUI.isMove) {
GUI.runOnUiThread(ctx, function() {
var layout = new RelativeLayout(ctx);
var button = new Button(ctx);
GUI.setClickEffect(button);
GUI.onClick(button, function(v) {
myPet.move();
});
GUI.moveButtonWindow = new PopupWindow(layout, dp(48), dp(48), true);
GUI.moveButtonWindow.showAtLocation(ctx.getWindow()
.getDecorView(), RIGHT | BOTTOM, 0, dp(50));
});
GUI.isMove = true;
}
};
/**
* myPet을 움직일 수 있게 만드는 버튼을 제거합니다.
* @since 2016.08.07
*/
GUI.openMoveButton = function() {
if (GUI.isMove) {
GUI.runOnUiThread(ctx, function() {
if (GUI.moveButtonWindow !== null) {
GUI.moveButtonWindow.dismiss();
}
GUI.moveButtonWindow = null;
});
GUI.isMove = false;
}
};
/**
* Activity의 UiThread를 실행합니다.
* @since 2016.08.05
* @param {Context} ctx Activity
* @param {Function} content 실행할 함수
*/
GUI.runOnUiThread = function(ctx, content) {
ctx.runOnUiThread(new Runnable({
run: function() {
try {
content();
} catch (error) {
clientMessage(ChatColor.DARK_RED + "[ERROR : " + error + ", LINE: " + error.lineNumber + "]");
}
}
}));
};
/**
* 버튼에 마인크래프트 형식의 클릭효과를 부여합니다.
* @since 2016.08.05
* @param {Widget} view 해당위젯
*/
GUI.setClickEffect = function(view) {
GUI.runOnUiThread(ctx, function() {
view.setBackgroundDrawable(GUI.buttonNormal());
view.setOnTouchListener(new View.OnTouchListener({
onTouch: function(v, event) {
switch (event.action) {
case android.view.MotionEvent.ACTION_DOWN: //버튼에 손 댔을 때
view.setBackgroundDrawable(GUI.buttonPress());
break;
case android.view.MotionEvent.ACTION_UP: //버튼에서 손 땟을때
view.setBackgroundDrawable(GUI.buttonNormal());
break;
}
return false;
}
}));
});
};
GUI.onClick = function(view, content) {
GUI.runOnUiThread(ctx, function() {
view.setOnClickListener(new View.OnClickListener({
onClick: function(v) {
if (content !== null) {
content(v);
}
}
}));
});
};
GUI.onLongClick = function(view, content) {
GUI.runOnUiThread(ctx, function() {
view.setOnLongClickListener(new View.OnLongClickListener({
onLongClick: function() {
if (content !== null) {
content();
}
return true;
}
}));
});
};
GUI.onTouch = function(view, func, func2, func3) {
GUI.runOnUiThread(ctx, function() {
view.setOnTouchListener(new View.OnTouchListener({
onTouch: function(v, event) {
switch (event.action) {
case android.view.MotionEvent.ACTION_DOWN: //버튼에 손 댔을 때
if (func !== null) {
func(v);
}
break;
case android.view.MotionEvent.ACTION_UP: //버튼에서 손 땟을때
if (func2 !== null) {
func2(v);
}
break;
case android.view.MotionEvent.ACTION_MOVE:
if (func3 !== null) {
func3(v);
}
break;
}
return false;
}
}));
});
};
})(GUI);
(widget => {
"use strict";
/**
* 띄어쓰기용 위젯을 반환합니다.
* @since 2016.08.05
*/
widget.space = () => {
var text = new TextView(ctx);
text.setText("");
text.setTextSize(2);
return text;
};
/**
* Line 위젯을 반환합니다.
* @since 2016.08.05
* @param {Number} size 크기
* @param {Color} color 색
*/
widget.line = (size, color) => {
var line = new TextView(ctx);
line.setText("");
line.setTextSize(size);
line.setBackgroundDrawable(new ColorDrawable(color));
return line;
};
})(GUI.widget || (GUI.widget = {}));
/**
* @file
* <h3>Change Log</h3>
* <ol>
* <li>Fixed jsdoc tags.</li>
* <li>Fixed methods</li>
* <li>Faster source.</li>
* <li>New methods
* <ul>
* <li>Entity.getPointedBlock(x, y, z);</li>
* <li>Entity.getEntityInArea(x, y, z, x2, y2, z2);</li>
* <li>Entity.getFilterEntity(arr, () => { return Entity.getHealth(ent) > 10; });</li>
* <li>Level.rnd2Number(-5, 5);</li>
* </ul>
* </li>
* </ol>
* @author Adagio <magicwho@naver.com>
* @since 2016-05-02
* @version 2.0
*/
/**
* @namespace Entity
*/
(Entity => {
"use strict";
/**
* Entity에게 함수를 실행합니다.
* @since 2016-05-02
* @param {Array.<Object>} arr 실행할 Entity
* @param {Function} func 실행할 함수
*/
Entity.action = (arr, func) => {
for (let i = arr.length; i--;) {
let entity = arr[i];
if (entity !== null) {
func(entity, i);
}
}
};
/**
* attacker이 victim의 등을 타격유무를 반환합니다.
* @since 2016-05-28
* @param {Object} attacker
* @param {Object} victim
* @returns {} attacker이 victim의 등을 타격유무
*/
Entity.attackedBack = (attacker, victim) => {
let yaw = Entity.getYaw(attacker) % 360,
yaw2 = Entity.getYaw(victim) % 360,
pitch = Entity.getPitch(attacker),
pitch2 = Entity.getPitch(victim);
if (yaw <= yaw2 + 80 && yaw >= yaw2 - 80) {
if (pitch <= pitch2 + 40 && pitch >= pitch2 - 40) {
return true;
}
}
return false;
};
/**
* Entity에게 지정한 데미지를 줍니다.
* @since 2016-05-02
* @param {Object} entity Entity
* @param {Number} damage 데미지
*/
Entity.dmg = (entity, damage) => {
if (Entity.getHealth(entity) > damage) {
Entity.setHealth(entity, Entity.getHealth(entity) + damage);
} else {
Entity.addEffect(myPet.target, MobEffect.harm, 1, 100000, true, false);
}
};
/**
* Entity를 폭발시킵니다.
* @since 2016-05-02
* @param {Object} entity Entity
* @param {Number} power 폭발 강도
* @returns {Object} Entity
*/
Entity.explode = (entity, power) => {
Level.explode(Entity.getX(entity), Entity.getY(entity), Entity.getZ(entity), power);
return entity;
};
/**
* 모든 몹을 가져옵니다.
* @since 2016-05-02
* @returns {Array.<Object>} 모든 몹 Entity
*/
Entity.getAllMob = () => {
return Entity.getAll().filter(entity => {
let typeId = Entity.getEntityTypeId(entity);
return typeId > 0 && typeId < 61 && entity !== null;
});
};
/**
* Entity와 Entity2의 사이의 거리를 반환합니다.
* @since 2016-05-02
* @param {Object} entity Entity
* @param {Object} entity2 Entity2
* @returns {Number} Entity와 Entity2의 사이의 거리
*/
Entity.getDst = (entity, entity2) => {
return Math.hypot(Entity.getX(entity) - Entity.getX(entity2), Entity.getY(entity) - Entity.getY(entity2), Entity.getZ(entity) - Entity.getZ(entity2));
};
/**
* 범위 안에 있는 몹을 모두 반환합니다.
* @since 2016-05-02
* @param {Number} sx Standard coord X
* @param {Number} sy Standard coord Y
* @param {Number} sz Standard coord Z
* @param {Number} ex Object coord X
* @param {Number} ey Object coord Y
* @param {Number} ez Object coord Z
* @returns {Array.<Object>} 범위 안에 있는 몹
*/
Entity.getEntityInArea = (sx, sy, sz, ex, ey, ez) => {
return Entity.getAllMob().filter(entity => {
let x = Entity.getX(entity),
y = Entity.getY(entity),
z = Entity.getZ(entity);
return x <= Math.max(sx, ex) && x >= Math.min(sx, ex) && y <= Math.max(sy, ey) && y >= Math.min(sy, ey) && z <= Math.max(sz, ez) && z >= Math.min(sz, ez);
});
};
/**