mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-22 05:38:46 +07:00
Added support for assigning float to stat
Created Stat#encodeFloat(float,int) to encode floats into fixed point int Added maxhp stat to monster attributes Changed debugging to output float stat
This commit is contained in:
@ -123,7 +123,7 @@ public class Actioneer extends PassiveSystem {
|
|||||||
log.debug("{} attack {}", entityId, targetId);
|
log.debug("{} attack {}", entityId, targetId);
|
||||||
|
|
||||||
Attributes attrs = mAttributesWrapper.get(targetId).attrs;
|
Attributes attrs = mAttributesWrapper.get(targetId).attrs;
|
||||||
log.debug("{} {}", targetId, attrs.get(Stat.hitpoints));
|
log.debug("{} {}", targetId, attrs.get(Stat.hitpoints).toFloat());
|
||||||
break;
|
break;
|
||||||
case 27: // teleport
|
case 27: // teleport
|
||||||
mPosition.get(entityId).position.set(targetVec);
|
mPosition.get(entityId).position.set(targetVec);
|
||||||
|
@ -157,7 +157,11 @@ public class ServerEntityFactory extends EntityFactory {
|
|||||||
Attributes attrs = new Attributes();
|
Attributes attrs = new Attributes();
|
||||||
PropertyList base = attrs.base();
|
PropertyList base = attrs.base();
|
||||||
base.clear();
|
base.clear();
|
||||||
base.put(Stat.hitpoints, MathUtils.random(monstats.minHP[0], monstats.maxHP[0]));
|
final float hitpoints = MathUtils.random(monstats.minHP[0], monstats.maxHP[0]);
|
||||||
|
// FIXME: this can be more elegant -- add support for putting float or auto converting?
|
||||||
|
final int encodedHitpoints = Stat.encodeFloat(hitpoints, 8); // see above note, this is crude
|
||||||
|
base.put(Stat.hitpoints, encodedHitpoints);
|
||||||
|
base.put(Stat.maxhp, encodedHitpoints);
|
||||||
|
|
||||||
attrs.reset(); // propagate base changes
|
attrs.reset(); // propagate base changes
|
||||||
mAttributesWrapper.create(id).attrs = attrs;
|
mAttributesWrapper.create(id).attrs = attrs;
|
||||||
|
@ -820,6 +820,14 @@ public class Stat implements Comparable<Stat> {
|
|||||||
return ((val >>> shift) + ((val & mask) / (float) pow));
|
return ((val >>> shift) + ((val & mask) / (float) pow));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFloat(float value) {
|
||||||
|
this.val = encodeFloat(value, entry.ValShift);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int encodeFloat(float value, int precision) {
|
||||||
|
return (int) (value * (1 << precision));
|
||||||
|
}
|
||||||
|
|
||||||
public long toLong() {
|
public long toLong() {
|
||||||
return UnsignedInts.toLong(val);
|
return UnsignedInts.toLong(val);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user