Skip to content

Commit

Permalink
Plants are LO now
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhael-Danilov committed Apr 6, 2019
1 parent 150cb69 commit 44b76b0
Show file tree
Hide file tree
Showing 24 changed files with 132 additions and 223 deletions.
Expand Up @@ -96,7 +96,7 @@ public boolean affectLevelObjects() {
}

@Override
public boolean nonPassable() {
public boolean nonPassable(Char ch) {
return true;
}
}
Expand Up @@ -76,7 +76,7 @@ public boolean affectLevelObjects() {
}

@Override
public boolean nonPassable() {
public boolean nonPassable(Char ch) {
return true;
}
}
Expand Up @@ -16,7 +16,7 @@
public abstract class LevelObject implements Bundlable, Presser {

@Packable
private int pos = -1;
protected int pos = -1;

@Packable
protected int layer = 0;
Expand Down Expand Up @@ -50,7 +50,7 @@ public boolean stepOn(Char hero) {
return true;
}

public boolean nonPassable() {
public boolean nonPassable(Char ch) {
return false;
}

Expand Down
@@ -1,7 +1,15 @@
package com.nyrds.pixeldungeon.levels.objects;

import com.nyrds.android.util.TrackedRuntimeException;
import com.watabou.pixeldungeon.actors.mobs.npcs.WandMaker;
import com.watabou.pixeldungeon.levels.Level;
import com.watabou.pixeldungeon.plants.Dreamweed;
import com.watabou.pixeldungeon.plants.Earthroot;
import com.watabou.pixeldungeon.plants.Fadeleaf;
import com.watabou.pixeldungeon.plants.Firebloom;
import com.watabou.pixeldungeon.plants.Icecap;
import com.watabou.pixeldungeon.plants.Sorrowmoss;
import com.watabou.pixeldungeon.plants.Sungrass;
import com.watabou.pixeldungeon.utils.Utils;

import org.json.JSONException;
Expand Down Expand Up @@ -34,7 +42,14 @@ private static void initObjectsMap() {
registerObjectClass(PortalGateReceiver.class);
registerObjectClass(Trap.class);
registerObjectClass(Deco.class);

registerObjectClass(Dreamweed.class);
registerObjectClass(Earthroot.class);
registerObjectClass(Fadeleaf.class);
registerObjectClass(Firebloom.class);
registerObjectClass(Icecap.class);
registerObjectClass(WandMaker.Rotberry.class);
registerObjectClass(Sorrowmoss.class);
registerObjectClass(Sungrass.class);
}

public static boolean isValidObjectClass(String objectClass) {
Expand Down
@@ -1,5 +1,6 @@
package com.nyrds.pixeldungeon.levels.objects;

import com.nyrds.ForRestoreFromBundle;
import com.nyrds.Packable;
import com.nyrds.android.lua.LuaEngine;
import com.nyrds.android.util.Util;
Expand Down Expand Up @@ -65,6 +66,7 @@ public class Trap extends LevelObject {
@Packable(defaultValue = "-1")
private int usedImageIndex;

@ForRestoreFromBundle
public Trap() {
this(-1);
}
Expand Down Expand Up @@ -202,7 +204,7 @@ private int usedImage() {
}

@Override
public boolean nonPassable() {
public boolean nonPassable(Char ch) {
return !secret && uses > 0;
}

Expand Down
Expand Up @@ -36,7 +36,7 @@ public void move(int from, int to) {

public void fall() {

origin.set( width / 2, height - DungeonTilemap.SIZE / 2 );
origin.set( width / 2, height - DungeonTilemap.SIZE / 2.f );
angularSpeed = Random.Int( 2 ) == 0 ? -720 : 720;

getParent().add(new FallTweener(this));
Expand All @@ -57,8 +57,8 @@ public void reset(LevelObject object) {
int ys = object.getSpriteYS();

frames = new TextureFilm(texture, xs, ys);
centerShift = new PointF(-(xs - DungeonTilemap.SIZE) / 2, -(ys-DungeonTilemap.SIZE) / 2);
origin.set(xs / 2, ys / 2);
centerShift = new PointF(-(xs - DungeonTilemap.SIZE) / 2.f, -(ys-DungeonTilemap.SIZE) / 2.f);
origin.set(xs / 2.f, ys / 2.f);

reset(object.image());
alpha(1f);
Expand Down
Expand Up @@ -47,8 +47,7 @@ public int attackProc(@NonNull Char enemy, int damage ) {

try {
Plant plant = (Plant) PlantClasses[getKind()].newInstance();
plant.pos = enemy.getPos();


plant.effect(enemy.getPos(),enemy);

die(this);
Expand Down
Expand Up @@ -676,12 +676,12 @@ private static void markActorsAsUnpassableIgnoreFov() {
}
}

private static void markObjects() {
private static void markObjects(Char ch) {
for (int i = 0; i < level.objects.size(); i++) {
SparseArray<LevelObject> objectLayer = level.objects.valueAt(i);
for (int j = 0; j < objectLayer.size(); j++) {
LevelObject object = objectLayer.valueAt(j);
if (object.nonPassable()) {
if (object.nonPassable(ch)) {
passable[object.getPos()] = false;
}
}
Expand Down Expand Up @@ -728,7 +728,7 @@ public static int findPath(Hero ch, int from, int to, boolean pass[], boolean[]

markActorsAsUnpassable(ch, visible);

markObjects();
markObjects(ch);

return PathFinder.getStep(from, to, passable);
}
Expand All @@ -755,7 +755,7 @@ public static int findPath(Char ch, int from, int to, boolean pass[]) {

markActorsAsUnpassableIgnoreFov();

markObjects();
markObjects(ch);

return PathFinder.getStep(from, to, passable);

Expand All @@ -770,7 +770,7 @@ public static int flee(Char ch, int cur, int from, boolean pass[]) {
}

markActorsAsUnpassableIgnoreFov();
markObjects();
markObjects(ch);

passable[cur] = true;

Expand Down
Expand Up @@ -287,23 +287,27 @@ public static void complete() {
public static class Rotberry extends Plant {

{
image = 7;
plantName = Game.getVar(R.string.WandMaker_RotberryName);
imageIndex = 7;
}

@Override
public void activate( Char ch ) {
super.activate( ch );

GameScene.add( Blob.seed( pos, 100, ToxicGas.class ) );

Dungeon.level.drop( new Seed(), pos ).sprite.drop();

if (ch != null) {
Buff.prolong( ch, Roots.class, TICK * 3 );
}
public String name() {
return Game.getVar(R.string.WandMaker_RotberryName);
}


@Override
public boolean interact(Char ch) {

GameScene.add( Blob.seed( pos, 100, ToxicGas.class ) );

Dungeon.level.drop( new Seed(), pos ).sprite.drop();

if (ch != null) {
Buff.prolong( ch, Roots.class, TICK * 3 );
}
return super.interact(ch);
}

@Override
public String desc() {
return Game.getVar(R.string.WandMaker_RotberryDesc);
Expand Down
Expand Up @@ -372,7 +372,6 @@ public enum LayerId {
private Set<ScriptedActor> scripts = new HashSet<>();
public Set<Mob> mobs = new HashSet<>();
public Map<Class<? extends Blob>, Blob> blobs = new HashMap<>();
public SparseArray<Plant> plants = new SparseArray<>();
private SparseArray<Heap> heaps = new SparseArray<>();
public SparseArray<SparseArray<LevelObject>> objects = new SparseArray<>();

Expand Down Expand Up @@ -585,8 +584,6 @@ public void restoreFromBundle(Bundle bundle) {
mobs = new HashSet<>();
heaps = new SparseArray<>();
blobs = new HashMap<>();
plants = new SparseArray<>();


width = bundle.optInt(WIDTH, 32); // old levels compat
height = bundle.optInt(HEIGHT, 32);
Expand Down Expand Up @@ -627,8 +624,10 @@ public void restoreFromBundle(Bundle bundle) {
heaps.put(heap.pos, heap);
}


///Pre 28.6 saves compatibility
for (Plant plant : bundle.getCollection(PLANTS, Plant.class)) {
plants.put(plant.pos, plant);
putLevelObject(plant);
}

for (LevelObject object : bundle.getCollection(OBJECTS, LevelObject.class)) {
Expand Down Expand Up @@ -675,7 +674,6 @@ public void storeInBundle(Bundle bundle) {
bundle.put(EXIT, exits);

bundle.put(HEAPS, heaps.values());
bundle.put(PLANTS, plants.values());

ArrayList<LevelObject> objectsArray = new ArrayList<>();

Expand Down Expand Up @@ -1112,13 +1110,15 @@ public void addLevelObject(LevelObject obj) {

public void plant(Plant.Seed seed, int pos) {

Plant plant = plants.get(pos);
if (plant != null) {
plant.wither();
LevelObject lo = getTopLevelObject(pos);

if (lo != null) {
lo.bump(seed);
}

plant = seed.couch(pos);
plants.put(pos, plant);
Plant plant = seed.couch(pos);
putLevelObject(plant);

if (GameScene.isSceneReady()) {
GameScene.add(plant);
}
Expand All @@ -1141,10 +1141,6 @@ public boolean remove(LevelObject levelObject) {
return false;
}

public void uproot(int pos) {
plants.delete(pos);
}

public int pitCell() {
return randomRespawnCell();
}
Expand Down Expand Up @@ -1258,11 +1254,6 @@ public void press(int cell, Presser actor) {
set(cell, Terrain.INACTIVE_TRAP);
GameScene.updateMap(cell);
}

Plant plant = plants.get(cell);
if (plant != null) {
plant.activate(chr);
}
}

private void markFovCellSafe(int p) {
Expand Down
Expand Up @@ -38,7 +38,7 @@ public static void paint( Level level, Room room ) {
for (int i=0; i < bushes; i++) {
int cellToPlant = room.random(level);

if(level.plants.get(cellToPlant)==null) {
if(level.getTopLevelObject(cellToPlant)==null) {
level.plant( new Sungrass.Seed(), cellToPlant );
}
}
Expand Down
Expand Up @@ -36,19 +36,13 @@
public class Dreamweed extends Plant {

public Dreamweed() {
image = 3;
plantName = Game.getVar(R.string.Dreamweed_Name);
imageIndex = 3;
}

public void effect(int pos, Char ch) {
GameScene.add( Blob.seed( pos, 300 + 20 * Dungeon.depth, ConfusionGas.class ) );
}

@Override
public String desc() {
return Game.getVar(R.string.Dreamweed_Desc);
}


public static class Seed extends Plant.Seed {
{
plantName = Game.getVar(R.string.Dreamweed_Name);
Expand Down
Expand Up @@ -38,8 +38,7 @@
public class Earthroot extends Plant {

public Earthroot() {
image = 5;
plantName = Game.getVar(R.string.Earthroot_Name);
imageIndex = 5;
}

public void effect(int pos, Char ch) {
Expand All @@ -52,12 +51,7 @@ public void effect(int pos, Char ch) {
Camera.main.shake(1, 0.4f);
}
}

@Override
public String desc() {
return Game.getVar(R.string.Earthroot_Desc);
}


public static class Seed extends Plant.Seed {
{
plantName = Game.getVar(R.string.Earthroot_Name);
Expand Down
Expand Up @@ -36,8 +36,7 @@
public class Fadeleaf extends Plant {

public Fadeleaf () {
image = 6;
plantName = Game.getVar(R.string.Fadeleaf_Name);
imageIndex = 6;
}

public void effect(int pos, Char ch) {
Expand Down
Expand Up @@ -38,8 +38,7 @@
public class Firebloom extends Plant {

public Firebloom() {
image = 0;
plantName = Game.getVar(R.string.Firebloom_Name);
imageIndex = 0;
}

public void effect(int pos, Char ch) {
Expand Down
Expand Up @@ -37,8 +37,7 @@
public class Icecap extends Plant {

public Icecap() {
image = 1;
plantName = Game.getVar(R.string.Icecap_Name);
imageIndex = 1;
}

@Override
Expand All @@ -52,12 +51,7 @@ public void effect(int pos, Char ch ) {
}
}
}

@Override
public String desc() {
return Game.getVar(R.string.Icecap_Desc);
}


public static class Seed extends Plant.Seed {
{
plantName = Game.getVar(R.string.Icecap_Name);
Expand Down

0 comments on commit 44b76b0

Please sign in to comment.