From: Astrid S. <ast...@us...> - 2008-03-27 14:57:57
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/entity In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv18572/src/games/stendhal/server/entity Modified Files: RPEntity.java Log Message: still moving stuff to rpentity Index: RPEntity.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/RPEntity.java,v retrieving revision 1.258 retrieving revision 1.259 diff -C2 -d -r1.258 -r1.259 *** RPEntity.java 26 Mar 2008 22:17:07 -0000 1.258 --- RPEntity.java 27 Mar 2008 14:57:47 -0000 1.259 *************** *** 20,25 **** import games.stendhal.server.core.engine.StendhalRPZone; import games.stendhal.server.core.events.TutorialNotifier; - import games.stendhal.server.core.rp.StendhalRPAction; import games.stendhal.server.core.rule.ActionManager; import games.stendhal.server.entity.item.Corpse; import games.stendhal.server.entity.item.Item; --- 20,25 ---- import games.stendhal.server.core.engine.StendhalRPZone; import games.stendhal.server.core.events.TutorialNotifier; import games.stendhal.server.core.rule.ActionManager; + import games.stendhal.server.entity.creature.Creature; import games.stendhal.server.entity.item.Corpse; import games.stendhal.server.entity.item.Item; *************** *** 2004,2017 **** defender.rememberAttacker(this); ! if (this.canHit(defender)) { defender.applyDefXP(this); int damage = this.damageDone(defender); if (damage > 0) { // limit damage to target HP damage = Math.min(damage, defender.getHP()); ! damage = StendhalRPAction.handleLifesteal(this, this.getWeapons(), damage); defender.onDamaged(this, damage); --- 2004,2019 ---- defender.rememberAttacker(this); ! if (this.canHit(defender)) { defender.applyDefXP(this); int damage = this.damageDone(defender); + + if (damage > 0) { // limit damage to target HP damage = Math.min(damage, defender.getHP()); ! damage = this.handleLifesteal(this, this.getWeapons(), damage); defender.onDamaged(this, damage); *************** *** 2041,2044 **** } ! } --- 2043,2110 ---- } ! /** ! * Calculate lifesteal and update hp of source. ! * ! * @param attacker ! * the RPEntity doing the hit ! * @param attackerWeapons ! * the weapons of the RPEntity doing the hit ! * @param damage ! * the damage done by this hit. ! * @return damage (may be altered inside this method) ! */ ! public int handleLifesteal(RPEntity attacker, ! List<Item> attackerWeapons, int damage) { ! ! // Calculate the lifesteal value based on the configured factor ! // In case of a lifesteal weapon used together with a non-lifesteal ! // weapon, ! // weight it based on the atk-values of the weapons. ! float sumAll = 0; ! float sumLifesteal = 0; ! ! // Creature with lifesteal profile? ! if (attacker instanceof Creature) { ! sumAll = 1; ! String value = ((Creature) attacker).getAIProfile("lifesteal"); ! if (value == null) { ! // The creature doesn't steal life. ! return damage; ! } ! sumLifesteal = Float.parseFloat(value); ! } else { ! // weapons with lifesteal attribute for players ! for (Item weaponItem : attackerWeapons) { ! sumAll += weaponItem.getAttack(); ! if (weaponItem.has("lifesteal")) { ! sumLifesteal += weaponItem.getAttack() ! * weaponItem.getDouble("lifesteal"); ! } ! } ! } ! ! // process the lifesteal ! if (sumLifesteal != 0) { ! // 0.5f is used for rounding ! int lifesteal = (int) (damage * sumLifesteal / sumAll + 0.5f); ! ! if (lifesteal >= 0) { ! if (attacker.heal(lifesteal, true) == 0) { ! // If no effective healing, reduce damage ! if (damage > 1) { ! damage /= 2; ! } ! } ! } else { ! /* ! * Negative lifesteal means that we hurt ourselves. ! */ ! attacker.damage(-lifesteal, attacker); ! } ! ! attacker.notifyWorldAboutChanges(); ! } ! return damage; ! } ! } |