From: Astrid S. <ast...@us...> - 2008-06-17 10:47:17
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/client/entity In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv10320/src/games/stendhal/client/entity Modified Files: RPEntity.java Log Message: extracted method evaluate attack provided test for it Index: RPEntity.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/client/entity/RPEntity.java,v retrieving revision 1.226 retrieving revision 1.227 diff -C2 -d -r1.226 -r1.227 *** RPEntity.java 16 Jun 2008 11:53:03 -0000 1.226 --- RPEntity.java 17 Jun 2008 10:47:21 -0000 1.227 *************** *** 707,711 **** attackTarget = (RPEntity) GameObjects.getInstance().get( targetEntityID); ! if (attackTarget != null) { onAttack(attackTarget); --- 707,711 ---- attackTarget = (RPEntity) GameObjects.getInstance().get( targetEntityID); ! if (attackTarget != null) { onAttack(attackTarget); *************** *** 718,746 **** if (attackTarget != null) { ! int risk; ! int damage; ! ! if (object.has("risk")) { ! risk = object.getInt("risk"); ! } else { ! risk = 0; ! } ! ! if (object.has("damage")) { ! damage = object.getInt("damage"); ! } else { ! damage = 0; ! } ! ! if (risk == 0) { ! onAttackMissed(attackTarget); ! attackTarget.onMissed(this); ! } else if ((risk > 0) && (damage == 0)) { ! onAttackBlocked(attackTarget); ! attackTarget.onBlocked(this); ! } else if ((risk > 0) && (damage > 0)) { ! onAttackDamage(attackTarget, damage); ! attackTarget.onDamaged(this, damage); ! } } --- 718,722 ---- if (attackTarget != null) { ! evaluateAttack(object, attackTarget); } *************** *** 764,767 **** --- 740,768 ---- } + protected void evaluateAttack(final RPObject object, RPEntity entity) { + int risk = 0; + int damage = 0; + + if (object.has("risk")) { + risk = object.getInt("risk"); + } + if (risk == 0) { + onAttackMissed(attackTarget); + entity.onMissed(this); + } else if (risk > 0) { + if (object.has("damage")) { + damage = object.getInt("damage"); + } + if (damage == 0) { + onAttackBlocked(attackTarget); + entity.onBlocked(this); + } else if (damage > 0) { + onAttackDamage(attackTarget, damage); + entity.onDamaged(this, damage); + } + } + + } + /** * Release this entity. This should clean anything that isn't automatically |