v0.3.5: fixed spears being able to attack through walls
This commit is contained in:
parent
b731569f85
commit
6e1bab6e89
|
@ -171,10 +171,7 @@ public class Combo extends Buff implements ActionIndicator.Action {
|
||||||
public void onSelect(Integer cell) {
|
public void onSelect(Integer cell) {
|
||||||
if (cell == null) return;
|
if (cell == null) return;
|
||||||
final Char enemy = Actor.findChar( cell );
|
final Char enemy = Actor.findChar( cell );
|
||||||
int userPos = target.pos;
|
if (enemy == null || !((Hero)target).canAttack(enemy) || target.isCharmedBy( enemy )){
|
||||||
if (enemy == null || userPos == cell || (Dungeon.hero.belongings.weapon != null ?
|
|
||||||
Level.distance( userPos, enemy.pos ) > Dungeon.hero.belongings.weapon.reachFactor(Dungeon.hero)
|
|
||||||
: !Level.adjacent( userPos, enemy.pos ))){
|
|
||||||
GLog.w( Messages.get(Combo.class, "bad_target") );
|
GLog.w( Messages.get(Combo.class, "bad_target") );
|
||||||
} else {
|
} else {
|
||||||
target.sprite.attack(cell, new Callback() {
|
target.sprite.attack(cell, new Callback() {
|
||||||
|
|
|
@ -95,6 +95,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.AttackIndicator;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.AttackIndicator;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndResurrect;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndResurrect;
|
||||||
|
@ -103,6 +104,7 @@ import com.watabou.noosa.Camera;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
import com.watabou.noosa.audio.Sample;
|
import com.watabou.noosa.audio.Sample;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
|
import com.watabou.utils.PathFinder;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -356,6 +358,27 @@ public class Hero extends Char {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canAttack(Char enemy){
|
||||||
|
if (enemy == null || pos == enemy.pos)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//can always attack adjacent enemies
|
||||||
|
if (Level.adjacent(pos, enemy.pos))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
KindOfWeapon wep = Dungeon.hero.belongings.weapon;
|
||||||
|
|
||||||
|
if (wep != null && Level.distance( pos, enemy.pos ) <= wep.reachFactor(this)){
|
||||||
|
|
||||||
|
PathFinder.buildDistanceMap(enemy.pos, BArray.not(Level.solid, null), wep.reachFactor(this));
|
||||||
|
|
||||||
|
return PathFinder.distance[pos] <= wep.reachFactor(this);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public float attackDelay() {
|
public float attackDelay() {
|
||||||
KindOfWeapon wep = rangedWeapon != null ? rangedWeapon : belongings.weapon;
|
KindOfWeapon wep = rangedWeapon != null ? rangedWeapon : belongings.weapon;
|
||||||
if (wep != null) {
|
if (wep != null) {
|
||||||
|
@ -804,11 +827,7 @@ public class Hero extends Char {
|
||||||
|
|
||||||
enemy = action.target;
|
enemy = action.target;
|
||||||
|
|
||||||
boolean inRange = belongings.weapon != null ?
|
if (enemy.isAlive() && canAttack( enemy ) && !isCharmedBy( enemy )) {
|
||||||
Level.distance( pos, enemy.pos ) <= belongings.weapon.reachFactor(this)
|
|
||||||
: Level.adjacent( pos, enemy.pos );
|
|
||||||
|
|
||||||
if (inRange && enemy.isAlive() && !isCharmedBy( enemy )) {
|
|
||||||
|
|
||||||
spend( attackDelay() );
|
spend( attackDelay() );
|
||||||
sprite.attack( enemy.pos );
|
sprite.attack( enemy.pos );
|
||||||
|
|
|
@ -23,7 +23,6 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
|
@ -97,14 +96,11 @@ public class AttackIndicator extends Tag {
|
||||||
|
|
||||||
private void checkEnemies() {
|
private void checkEnemies() {
|
||||||
|
|
||||||
int heroPos = Dungeon.hero.pos;
|
|
||||||
candidates.clear();
|
candidates.clear();
|
||||||
int v = Dungeon.hero.visibleEnemies();
|
int v = Dungeon.hero.visibleEnemies();
|
||||||
for (int i=0; i < v; i++) {
|
for (int i=0; i < v; i++) {
|
||||||
Mob mob = Dungeon.hero.visibleEnemy( i );
|
Mob mob = Dungeon.hero.visibleEnemy( i );
|
||||||
if (Dungeon.hero.belongings.weapon != null ?
|
if ( Dungeon.hero.canAttack( mob) ) {
|
||||||
Level.distance( heroPos, mob.pos ) <= Dungeon.hero.belongings.weapon.reachFactor(Dungeon.hero)
|
|
||||||
: Level.adjacent( heroPos, mob.pos )) {
|
|
||||||
candidates.add( mob );
|
candidates.add( mob );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user