public override bool interact(Level level, int xt, int yt, Player player, Item item, int attackDir) { if (item is ToolItem) { ToolItem tool = (ToolItem)item; if (tool.type == ToolType.shovel) { if (player.payStamina(4 - tool.level)) { level.setTile(xt, yt, Tile.hole, 0); level.add(new ItemEntity(new ResourceItem(Resource.dirt), xt * 16 + random.nextInt(10) + 3, yt * 16 + random.nextInt(10) + 3)); Sound.monsterHurt.play(); return true; } } if (tool.type == ToolType.hoe) { if (player.payStamina(4 - tool.level)) { level.setTile(xt, yt, Tile.farmland, 0); Sound.monsterHurt.play(); return true; } } } return false; }
public override bool interact(Level level, int xt, int yt, Player player, Item item, int attackDir) { if (item is ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.pickaxe && tool.level == 4) { if (player.payStamina(4 - tool.level)) { hurt(level, xt, yt, random.nextInt(10) + (tool.level) * 5 + 10); return true; } } } return false; }
public ItemEntity(Item item, int x, int y) { this.item = item; xx = this.x = x; yy = this.y = y; xr = 3; yr = 3; zz = 2; xa = random.nextGaussian() * 0.3; ya = random.nextGaussian() * 0.2; za = random.nextFloat() * 0.7 + 1; lifeTime = 60 * 10 + random.nextInt(60); }
public override bool interact(Level level, int xt, int yt, Player player, Item item, int attackDir) { if (item is ToolItem) { ToolItem tool = (ToolItem)item; if (tool.type == ToolType.pickaxe) { if (player.payStamina(6 - tool.level)) { hurt(level, xt, yt, 1); return true; } } } return false; }
public override bool interact(Level level, int xt, int yt, Player player, Item item, int attackDir) { if (item is ToolItem) { ToolItem tool = (ToolItem)item; if (tool.type == ToolType.shovel) { if (player.payStamina(4 - tool.level)) { level.setTile(xt, yt, Tile.dirt, 0); return true; } } } return false; }
public override bool interact(Level level, int x, int y, Player player, Item item, int attackDir) { if (item is ToolItem) { ToolItem tool = (ToolItem)item; if (tool.type == ToolType.shovel) { if (player.payStamina(4 - tool.level)) { level.add(new ItemEntity(new ResourceItem(Resource.flower), x * 16 + random.nextInt(10) + 3, y * 16 + random.nextInt(10) + 3)); level.add(new ItemEntity(new ResourceItem(Resource.flower), x * 16 + random.nextInt(10) + 3, y * 16 + random.nextInt(10) + 3)); level.setTile(x, y, Tile.grass, 0); return true; } } } return false; }
public int count(Item item) { if (item is ResourceItem) { ResourceItem ri = findResource(((ResourceItem)item).resource); if (ri != null) return ri.count; } else { int count = 0; for (int i = 0; i < items.Count; i++) { if (items[i].matches(item)) count++; } return count; } return 0; }
public void add(int slot, Item item) { if (item is ResourceItem) { ResourceItem toTake = (ResourceItem)item; ResourceItem has = findResource(toTake.resource); if (has == null) { items.Insert(slot, toTake); } else { has.count += toTake.count; } } else { items.Insert(slot, item); } }
public override bool interact(Level level, int xt, int yt, Player player, Item item, int attackDir) { if (item is ToolItem) { ToolItem tool = (ToolItem)item; if (tool.type == ToolType.shovel) { if (player.payStamina(5)) { // level.setTile(xt, yt, Tile.infiniteFall, 0); int count = random.nextInt(2) + 1; for (int i = 0; i < count; i++) { level.add(new ItemEntity(new ResourceItem(Resource.cloud), xt * 16 + random.nextInt(10) + 3, yt * 16 + random.nextInt(10) + 3)); } return true; } } } return false; }
public void add(Item item) { add(items.Count, item); }
private void attack() { walkDist += 8; attackDir = dir; attackItem = activeItem; bool done = false; if (activeItem != null) { attackTime = 10; int yo = -2; int range = 12; if (dir == 0 && interact(x - 8, y + 4 + yo, x + 8, y + range + yo)) done = true; if (dir == 1 && interact(x - 8, y - range + yo, x + 8, y - 4 + yo)) done = true; if (dir == 3 && interact(x + 4, y - 8 + yo, x + range, y + 8 + yo)) done = true; if (dir == 2 && interact(x - range, y - 8 + yo, x - 4, y + 8 + yo)) done = true; if (done) return; int xt = x >> 4; int yt = (y + yo) >> 4; int r = 12; if (attackDir == 0) yt = (y + r + yo) >> 4; if (attackDir == 1) yt = (y - r + yo) >> 4; if (attackDir == 2) xt = (x - r) >> 4; if (attackDir == 3) xt = (x + r) >> 4; if (xt >= 0 && yt >= 0 && xt < level.w && yt < level.h) { if (activeItem.interactOn(level.getTile(xt, yt), level, xt, yt, this, attackDir)) { done = true; } else { if (level.getTile(xt, yt).interact(level, xt, yt, this, activeItem, attackDir)) { done = true; } } if (activeItem.isDepleted()) { activeItem = null; } } } if (done) return; if (activeItem == null || activeItem.canAttack()) { attackTime = 5; int yo = -2; int range = 20; if (dir == 0) hurt(x - 8, y + 4 + yo, x + 8, y + range + yo); if (dir == 1) hurt(x - 8, y - range + yo, x + 8, y - 4 + yo); if (dir == 3) hurt(x + 4, y - 8 + yo, x + range, y + 8 + yo); if (dir == 2) hurt(x - range, y - 8 + yo, x - 4, y + 8 + yo); int xt = x >> 4; int yt = (y + yo) >> 4; int r = 12; if (attackDir == 0) yt = (y + r + yo) >> 4; if (attackDir == 1) yt = (y - r + yo) >> 4; if (attackDir == 2) xt = (x - r) >> 4; if (attackDir == 3) xt = (x + r) >> 4; if (xt >= 0 && yt >= 0 && xt < level.w && yt < level.h) { level.getTile(xt, yt).hurt(level, xt, yt, this, random.nextInt(3) + 1, attackDir); } } }
public Recipe(Item resultTemplate) { this.resultTemplate = resultTemplate; }