Beispiel #1
0
  /**
   * Checks whether player have needed skill for gathering and skill level is sufficient
   *
   * @param player
   * @param template
   * @return
   */
  private boolean checkPlayerSkill(final Player player, final GatherableTemplate template) {
    int harvestSkillId = template.getHarvestSkill();

    // check skill is available
    if (!player.getSkillList().isSkillPresent(harvestSkillId)) {
      // TODO send some message ?
      return false;
    }
    if (player.getSkillList().getSkillLevel(harvestSkillId) < template.getSkillLevel()) {
      // TODO send some message ?
      return false;
    }
    return true;
  }
Beispiel #2
0
 /**
  * Each skill is a separate object upon invocation Skill level will be populated from player
  * SkillList
  *
  * @param skillTemplate
  * @param effector
  * @param world
  */
 public Skill(SkillTemplate skillTemplate, Player effector, Creature firstTarget) {
   this(
       skillTemplate,
       effector,
       effector.getSkillList().getSkillLevel(skillTemplate.getSkillId()),
       firstTarget,
       null);
 }
Beispiel #3
0
  public void rewardPlayer(Player player) {
    if (player != null) {
      int skillLvl = getObjectTemplate().getSkillLevel();
      int xpReward =
          (int)
              ((0.008 * (skillLvl + 100) * (skillLvl + 100) + 60)
                  * player.getRates().getGatheringXPRate());

      if (player
          .getSkillList()
          .addSkillXp(player, getObjectTemplate().getHarvestSkill(), xpReward)) {
        PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.EXTRACT_GATHER_SUCCESS_GETEXP());
        player.getCommonData().addExp(xpReward);
      } else
        PacketSendUtility.sendPacket(
            player,
            SM_SYSTEM_MESSAGE.MSG_DONT_GET_PRODUCTION_EXP(
                new DescriptionId(
                    DataManager.SKILL_DATA
                        .getSkillTemplate(getObjectTemplate().getHarvestSkill())
                        .getNameId())));
    }
  }
Beispiel #4
0
  /**
   * Start gathering process
   *
   * @param player
   */
  public void onStartUse(final Player player) {
    // basic actions, need to improve here
    final GatherableTemplate template = this.getObjectTemplate();

    if (!checkPlayerSkill(player, template)) return;

    List<Material> materials = template.getMaterials().getMaterial();

    int index = 0;
    Material material = materials.get(index); // default is 0
    int count = materials.size();

    if (count < 1) {
      // error - theoretically if XML data is correct, this should never happen.
      return;
    } else if (count == 1) {
      // default is 0
    } else {
      if (player.getInventory().isFull()) {
        PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.EXTRACT_GATHER_INVENTORY_IS_FULL());
        return;
      }

      int gatherRate =
          1; // 1x rates (probably make config later, if fixed to non-linear statistic probability)
      float maxrate = 0;
      int rate = 0;
      int i = 0; // index counter

      // sort materials to ascending order
      SortedMap<Integer, Integer> hasMat = new TreeMap<Integer, Integer>();
      for (Material mat : materials) {
        maxrate += mat.getRate(); // get maxrate
        hasMat.put(
            mat.getRate(),
            i); // sort and save index of materials (key is rate and rate is unique on each
                // gatherId)
        i++;
      }

      Iterator<Integer> it = hasMat.keySet().iterator();
      while (it.hasNext()) {
        rate = it.next();
        float percent = Rnd.get() * 100f;
        float chance = ((rate / maxrate) * 100f * gatherRate);

        // default index is to 0, look to up little bit on 'material'
        if (percent < chance) {
          index = hasMat.get(rate); // return index				
          material = materials.get(index);
          break;
        }
      }
    }

    final Material finalMaterial = material;

    if (state != GatherState.GATHERING) {
      state = GatherState.GATHERING;
      currentGatherer = player.getObjectId();
      player
          .getObserveController()
          .attach(
              new StartMovingListener() {

                @Override
                public void moved() {
                  finishGathering(player);
                }
              });
      int skillLvlDiff =
          player.getSkillList().getSkillLevel(template.getHarvestSkill())
              - template.getSkillLevel();
      task = new GatheringTask(player, this, finalMaterial, skillLvlDiff);
      task.start();
    }
  }