Merging 1.7.5 Source: actors/mobs/npcs changes
This commit is contained in:
parent
d7934760c5
commit
e931525669
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
* Pixel Dungeon
|
||||
* Copyright (C) 2012-2015 Oleg Dolya
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Poison;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.BeeSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
|
||||
import com.watabou.utils.Bundle;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
//todo: given the plan for this in shattered, should probably 'bee' a mob.
|
||||
public class Bee extends NPC {
|
||||
|
||||
{
|
||||
name = "golden bee";
|
||||
spriteClass = BeeSprite.class;
|
||||
|
||||
viewDistance = 4;
|
||||
|
||||
WANDERING = new Wandering();
|
||||
|
||||
flying = true;
|
||||
state = WANDERING;
|
||||
}
|
||||
|
||||
private int level;
|
||||
|
||||
private static final String LEVEL = "level";
|
||||
|
||||
@Override
|
||||
public void storeInBundle( Bundle bundle ) {
|
||||
super.storeInBundle( bundle );
|
||||
bundle.put( LEVEL, level );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreFromBundle( Bundle bundle ) {
|
||||
super.restoreFromBundle( bundle );
|
||||
spawn( bundle.getInt( LEVEL ) );
|
||||
}
|
||||
|
||||
public void spawn( int level ) {
|
||||
this.level = level;
|
||||
|
||||
HT = (3 + level) * 5;
|
||||
defenseSkill = 9 + level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int attackSkill( Char target ) {
|
||||
return defenseSkill;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageRoll() {
|
||||
return Random.NormalIntRange( HT / 10, HT / 4 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int attackProc( Char enemy, int damage ) {
|
||||
if (enemy instanceof Mob) {
|
||||
((Mob)enemy).aggro( this );
|
||||
}
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean act() {
|
||||
HP--;
|
||||
if (HP <= 0) {
|
||||
die( null );
|
||||
return true;
|
||||
} else {
|
||||
return super.act();
|
||||
}
|
||||
}
|
||||
|
||||
protected Char chooseEnemy() {
|
||||
|
||||
if (enemy == null || !enemy.isAlive()) {
|
||||
HashSet<Mob> enemies = new HashSet<Mob>();
|
||||
for (Mob mob:Dungeon.level.mobs) {
|
||||
if (mob.hostile && Level.fieldOfView[mob.pos]) {
|
||||
enemies.add( mob );
|
||||
}
|
||||
}
|
||||
|
||||
return enemies.size() > 0 ? Random.element( enemies ) : null;
|
||||
|
||||
} else {
|
||||
|
||||
return enemy;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return
|
||||
"Despite their small size, golden bees tend " +
|
||||
"to protect their master fiercely. They don't live long though.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact() {
|
||||
|
||||
int curPos = pos;
|
||||
|
||||
moveSprite( pos, Dungeon.hero.pos );
|
||||
move( Dungeon.hero.pos );
|
||||
|
||||
Dungeon.hero.sprite.move( Dungeon.hero.pos, curPos );
|
||||
Dungeon.hero.move( curPos );
|
||||
|
||||
Dungeon.hero.spend( 1 / Dungeon.hero.speed() );
|
||||
Dungeon.hero.busy();
|
||||
}
|
||||
|
||||
private static final HashSet<Class<?>> IMMUNITIES = new HashSet<Class<?>>();
|
||||
static {
|
||||
IMMUNITIES.add( Poison.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashSet<Class<?>> immunities() {
|
||||
return IMMUNITIES;
|
||||
}
|
||||
|
||||
private class Wandering implements AiState {
|
||||
|
||||
@Override
|
||||
public boolean act( boolean enemyInFOV, boolean justAlerted ) {
|
||||
if (enemyInFOV) {
|
||||
|
||||
enemySeen = true;
|
||||
|
||||
notice();
|
||||
state = HUNTING;
|
||||
target = enemy.pos;
|
||||
|
||||
} else {
|
||||
|
||||
enemySeen = false;
|
||||
|
||||
int oldPos = pos;
|
||||
if (getCloser( Dungeon.hero.pos )) {
|
||||
spend( 1 / speed() );
|
||||
return moveSprite( oldPos, pos );
|
||||
} else {
|
||||
spend( TICK );
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String status() {
|
||||
return Utils.format( "This %s is wandering", name );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -132,7 +132,7 @@ public class Ghost extends NPC {
|
|||
|
||||
@Override
|
||||
protected Char chooseEnemy() {
|
||||
return DUMMY;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -47,7 +47,7 @@ public class Imp extends NPC {
|
|||
|
||||
private static final String TXT_GOLEMS1 =
|
||||
"Are you an adventurer? I love adventurers! You can always rely on them " +
|
||||
"if something needs to be killed. Am I right? For bounty of course ;)\n" +
|
||||
"if something needs to be killed. Am I right? For a bounty of course ;)\n" +
|
||||
"In my case this is _golems_ who need to be killed. You see, I'm going to start a " +
|
||||
"little business here, but these stupid golems are bad for business! " +
|
||||
"It's very hard to negotiate with wandering lumps of granite, damn them! " +
|
||||
|
@ -55,7 +55,7 @@ public class Imp extends NPC {
|
|||
|
||||
private static final String TXT_MONKS1 =
|
||||
"Are you an adventurer? I love adventurers! You can always rely on them " +
|
||||
"if something needs to be killed. Am I right? For bounty of course ;)\n" +
|
||||
"if something needs to be killed. Am I right? For a bounty of course ;)\n" +
|
||||
"In my case this is _monks_ who need to be killed. You see, I'm going to start a " +
|
||||
"little business here, but these lunatics don't buy anything themselves and " +
|
||||
"will scare away other customers. " +
|
||||
|
|
|
@ -38,8 +38,7 @@ public class MirrorImage extends NPC {
|
|||
spriteClass = MirrorSprite.class;
|
||||
|
||||
state = HUNTING;
|
||||
|
||||
enemy = DUMMY;
|
||||
|
||||
}
|
||||
|
||||
public int tier;
|
||||
|
@ -95,7 +94,7 @@ public class MirrorImage extends NPC {
|
|||
|
||||
protected Char chooseEnemy() {
|
||||
|
||||
if (enemy == DUMMY || !enemy.isAlive()) {
|
||||
if (enemy == null || !enemy.isAlive()) {
|
||||
HashSet<Mob> enemies = new HashSet<Mob>();
|
||||
for (Mob mob:Dungeon.level.mobs) {
|
||||
if (mob.hostile && Level.fieldOfView[mob.pos]) {
|
||||
|
@ -103,7 +102,7 @@ public class MirrorImage extends NPC {
|
|||
}
|
||||
}
|
||||
|
||||
enemy = enemies.size() > 0 ? Random.element( enemies ) : DUMMY;
|
||||
enemy = enemies.size() > 0 ? Random.element( enemies ) : null;
|
||||
}
|
||||
|
||||
return enemy;
|
||||
|
|
|
@ -44,7 +44,7 @@ public class RatKing extends NPC {
|
|||
|
||||
@Override
|
||||
protected Char chooseEnemy() {
|
||||
return DUMMY;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue
Block a user