Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backpackSize Refactor #287

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 34 additions & 42 deletions Dungeoneer/src/com/interrupt/dungeoneer/entities/EntitySpawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ public class EntitySpawner extends DirectionalEntity {
public EntitySpawner() { artType = ArtType.hidden; tex = 0; }

public enum ItemPlacement { world, player_hotbar, player_inventory, player_equip }

@EditorProperty(group = "Spawns") public String entityCategory = "Decorations";
@EditorProperty(group = "Spawns") public String entityName = "Skull";
@EditorProperty(group = "Spawns") public float spawnVelocity = 0.1f;
@EditorProperty(group = "Spawns") public Vector3 spawnSpread = new Vector3(0,0,0);
@EditorProperty(group = "Spawns") public boolean destroyAfterSpawn = false;
@EditorProperty(group = "Spawns") public String spawnSound = null;
@EditorProperty(group = "Spawns") ItemPlacement placement = ItemPlacement.world;

@Override
public void tick(Level level, float delta) {

}

@Override
public void onTrigger(Entity instigator, String value) {
if(!isActive) return;

Entity spawned = Game.instance.entityManager.getEntity(entityCategory, entityName);
if(spawned != null) {
Vector3 speed = getDirection();
speed.scl(spawnVelocity);

spawned.xa = speed.x;
spawned.ya = speed.y;
spawned.za = speed.z;

spawned.x = x + (Game.rand.nextFloat() * spawnSpread.x * 0.5f) - spawnSpread.x * 0.5f;
spawned.y = y + (Game.rand.nextFloat() * spawnSpread.y * 0.5f) - spawnSpread.y * 0.5f;
spawned.z = z + (Game.rand.nextFloat() * spawnSpread.z * 0.5f) - spawnSpread.z * 0.5f;
Expand All @@ -50,45 +50,37 @@ public void onTrigger(Entity instigator, String value) {
if(spawnSound != null) {
Audio.playPositionedSound(spawnSound, new Vector3(x,y,z), 1f, 12f);
}

if(destroyAfterSpawn) isActive = false;
}

public void placeInInventory(Entity e) {
if(e == null)
public void placeInInventory(Entity entity) {
if(null == entity)
return;

if(e instanceof Item) {
Item item = (Item)e;

if(Game.instance == null || Game.instance.player == null)
return;

Player p = Game.instance.player;

// might need to initialize this?
if(p.inventory != null) {
if (p.inventory.size < p.inventorySize) {
for (int i = 0; i < p.inventorySize; i++)
p.inventory.add(null);
}
}

boolean foundSpot = false;

if(placement == ItemPlacement.player_hotbar || placement == ItemPlacement.player_equip) {
foundSpot = p.addToInventory(item, placement == ItemPlacement.player_equip);
}
else {
foundSpot = p.addToBackpack(item);
if(!foundSpot) {
foundSpot = p.addToInventory(item, placement == ItemPlacement.player_equip);
}
}

if(!foundSpot) {
p.throwItem(item, Game.GetLevel(), 0f, 0f);
}
}
if(!(entity instanceof Item))
return;

if(null == Game.instance || null == Game.instance.player)
return;

Item item = (Item)entity;
Player player = Game.instance.player;

boolean foundSpot = false;

if(placement == ItemPlacement.player_hotbar || placement == ItemPlacement.player_equip) {
foundSpot = player.addToInventory(item, placement == ItemPlacement.player_equip);
}
else {
foundSpot = player.addToBackpack(item);
if(!foundSpot) {
foundSpot = player.addToInventory(item, placement == ItemPlacement.player_equip);
}
}

if(!foundSpot) {
player.throwItem(item, Game.GetLevel(), 0f, 0f);
}
}
}
56 changes: 24 additions & 32 deletions Dungeoneer/src/com/interrupt/dungeoneer/entities/ItemSpawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public class ItemSpawner extends DirectionalEntity {
public enum ItemType { melee, ranged, armor, wands, potions, scrolls, decorations, unique, junk, food }

public enum ItemPlacement { world, player_hotbar, player_inventory, player_equip }

@EditorProperty(group = "Spawns") public ItemType itemType = ItemType.melee;
@EditorProperty(group = "Spawns") public Integer itemLevel = null;
@EditorProperty(group = "Spawns") public Item.ItemCondition itemCondition = Item.ItemCondition.normal;
@EditorProperty(group = "Spawns") public String itemName = null;
@EditorProperty(group = "Spawns") boolean waitForTrigger = false;
@EditorProperty(group = "Spawns") ItemPlacement placement = ItemPlacement.world;

@Override
public void init(Level level, Source source) {
if(!waitForTrigger && (source == Source.LEVEL_START || source == Source.SPAWNED) && isActive) {
Expand Down Expand Up @@ -92,42 +92,34 @@ else if(itemType == ItemType.food) {
return null;
}

public void placeInInventory(Entity e) {
if(e == null)
public void placeInInventory(Entity entity) {
if(null == entity)
return;

if(e instanceof Item) {
Item item = (Item)e;
if(!(entity instanceof Item))
return;

if(Game.instance == null || Game.instance.player == null)
return;
if(null == Game.instance || null == Game.instance.player)
return;

Player p = Game.instance.player;

// might need to initialize this?
if(p.inventory != null) {
if (p.inventory.size < p.inventorySize) {
for (int i = 0; i < p.inventorySize; i++)
p.inventory.add(null);
}
}
Item item = (Item)entity;
Player player = Game.instance.player;

boolean foundSpot = false;
boolean foundSpot = false;

if(placement == ItemPlacement.player_hotbar || placement == ItemPlacement.player_equip) {
foundSpot = p.addToInventory(item, placement == ItemPlacement.player_equip);
}
else {
foundSpot = p.addToBackpack(item);
if(!foundSpot) {
foundSpot = p.addToInventory(item, placement == ItemPlacement.player_equip);
}
}
if(placement == ItemPlacement.player_hotbar || placement == ItemPlacement.player_equip) {
foundSpot = player.addToInventory(item, placement == ItemPlacement.player_equip);
}
else {
foundSpot = player.addToBackpack(item);
if(!foundSpot) {
foundSpot = player.addToInventory(item, placement == ItemPlacement.player_equip);
}
}

if(!foundSpot) {
p.throwItem(item, Game.GetLevel(), 0f, 0f);
}
}
if(!foundSpot) {
player.throwItem(item, Game.GetLevel(), 0f, 0f);
}
}

@Override
Expand All @@ -136,4 +128,4 @@ public void onTrigger(Entity instigator, String value) {
spawn(Game.GetLevel());
}
}
}
}
Loading