Search in sources :

Example 1 with MobWithDescriptionAndReward

use of com.microsoft.Malmo.Schemas.MobWithDescriptionAndReward in project malmo by Microsoft.

the class RewardForCatchingMobImplementation method getReward.

@Override
public void getReward(MissionInit missionInit, MultidimensionalReward reward) {
    super.getReward(missionInit, reward);
    List<Entity> trappedEntities = getCaughtEntities();
    for (MobWithDescriptionAndReward mob : this.rcmparams.getMob()) {
        // Have we caught one of these mobs?
        for (EntityTypes et : mob.getType()) {
            String mobName = et.value();
            for (Entity e : trappedEntities) {
                if (e.getName().equals(mobName)) {
                    // Potential match... check other options.
                    if (!mob.isGlobal()) {
                        // If global flag is false, our player needs to be adjacent to the mob in order to claim the reward.
                        BlockPos entityPos = new BlockPos(e.posX, e.posY, e.posZ);
                        EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
                        BlockPos playerPos = new BlockPos(player.posX, player.posY, player.posZ);
                        if (Math.abs(entityPos.getX() - playerPos.getX()) + Math.abs(entityPos.getZ() - playerPos.getZ()) > 1)
                            continue;
                    }
                    // If oneshot flag is true, only allow the reward from this mob to be counted once.
                    if (mob.isOneshot() && this.caughtEntities.contains(e))
                        continue;
                    // Can claim the reward.
                    float adjusted_reward = adjustAndDistributeReward(mob.getReward().floatValue(), this.rcmparams.getDimension(), mob.getDistribution());
                    reward.add(this.rcmparams.getDimension(), adjusted_reward);
                }
            }
        }
    }
}
Also used : EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) Entity(net.minecraft.entity.Entity) MobWithDescriptionAndReward(com.microsoft.Malmo.Schemas.MobWithDescriptionAndReward) BlockPos(net.minecraft.util.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Aggregations

EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)1 MobWithDescriptionAndReward (com.microsoft.Malmo.Schemas.MobWithDescriptionAndReward)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 Entity (net.minecraft.entity.Entity)1 BlockPos (net.minecraft.util.BlockPos)1