forked from CuteLunaMoon/Survival-Pixel-Dungeon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevelObject.java
141 lines (114 loc) · 4.17 KB
/
LevelObject.java
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
package com.shatteredpixel.shatteredpixeldungeon.objects;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroAction;
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ObjectSprite;
import com.watabou.ErrorLog;
import com.watabou.utils.GLog;
import com.watabou.utils.Bundlable;
import com.watabou.utils.Bundle;
/**
* This file is created by Funny Game and it's
* a part of Perfect Pixel Dungeon.
* Creation Date: 11.12.2017
*/
public class LevelObject implements Bundlable {
public String name;
public int image;
public int pos;
public boolean initialised = false;
public boolean breakable;
public Class breakItem;
public Interaction interactionType = Interaction.HANDLE;
public int flags = Terrain.PASSABLE;
public ObjectSprite sprite;
{
name = "„S„u„ƒ„„";
image = 0;
breakable = true;
breakItem = null;
}
private static final String NAME = "name";
private static final String IMAGE = "image";
private static final String POS = "pos";
private static final String BREAKABLE = "breakable";
private static final String BREAK_ITEM = "breakItem";
private static final String FLAGS = "flags";
public void init(int pos){
this.pos = pos;
setFlags();
initialised = true;
}
public void setFlags(){
Dungeon.level.passable[pos] = (flags & Terrain.PASSABLE) != 0;
Dungeon.level.losBlocking[pos] = (flags & Terrain.LOS_BLOCKING) != 0;
Dungeon.level.flamable[pos] = (flags & Terrain.FLAMABLE) != 0;
Dungeon.level.solid[pos] = (flags & Terrain.SOLID) != 0;
Dungeon.level.avoid[pos] = (flags & Terrain.AVOID) != 0;
Dungeon.level.pit[pos] = (flags & Terrain.PIT) != 0;
}
public void restoreFlags(){
int flagz = Terrain.flags[Dungeon.level.map[pos]];
Dungeon.level.passable[pos] = (flagz & Terrain.PASSABLE) != 0;
Dungeon.level.losBlocking[pos] = (flagz & Terrain.LOS_BLOCKING) != 0;
Dungeon.level.flamable[pos] = (flagz & Terrain.FLAMABLE) != 0;
Dungeon.level.secret[pos] = (flagz & Terrain.SECRET) != 0;
Dungeon.level.solid[pos] = (flagz & Terrain.SOLID) != 0;
Dungeon.level.avoid[pos] = (flagz & Terrain.AVOID) != 0;
Dungeon.level.water[pos] = (flagz & Terrain.LIQUID) != 0;
Dungeon.level.pit[pos] = (flagz & Terrain.PIT) != 0;
}
public void storeInBundle(Bundle bundle){
bundle.put(NAME, name);
bundle.put(IMAGE, image);
bundle.put(POS, pos);
bundle.put(BREAKABLE, breakable);
if (breakItem != null) {
bundle.put(BREAK_ITEM, breakItem.getCanonicalName());
} else {
bundle.put(BREAK_ITEM, "");
}
bundle.put(FLAGS, flags);
}
public void restoreFromBundle(Bundle bundle){
name = bundle.getString(NAME);
image = bundle.getInt(IMAGE);
pos = bundle.getInt(POS);
breakable = bundle.getBoolean(BREAKABLE);
try {
if (bundle.getString(BREAK_ITEM) != "") {
breakItem = Class.forName(bundle.getString(BREAK_ITEM));
} else {
breakItem = null;
}
} catch (Exception e){
ErrorLog.log(e);
}
flags = bundle.getInt(FLAGS);
setFlags();
}
public String desc(){
return "";
}
public static LevelObject find (int cell){
return Dungeon.level.getTopObject(cell);
}
public void interact( Char ch ){
}
public void onPlace() {
}
public void onDestroy() {
}
public void everyTurn() {
}
public void destroy(){
Dungeon.level.deleteObject(pos, false);
}
public enum Interaction {
HANDLE,
PRESS,
NONE
}
}