/** * @param attacker * @param target * @param skillDamages * @return Damage made to target (-hp value) */ public static int calculateMagicalAttackToTarget( Creature attacker, Creature attacked, SkillElement element) { CreatureGameStats<?> ags = attacker.getGameStats(); int resultDamage = 0; if (attacker instanceof Player) { int min = ags.getCurrentStat(StatEnum.MAIN_MIN_DAMAGES); int max = ags.getCurrentStat(StatEnum.MAIN_MAX_DAMAGES); Equipment equipment = ((Player) attacker).getEquipment(); int base = Math.round(Rnd.get(min, max) * ags.getCurrentStat(StatEnum.KNOWLEDGE) * 0.01f); resultDamage = base + ags.getStatBonus(StatEnum.MAGICAL_ATTACK); if (attacker.isInState(CreatureState.POWERSHARD)) { Item mainHandPowerShard = equipment.getMainHandPowerShard(); if (mainHandPowerShard != null) { resultDamage += mainHandPowerShard.getItemTemplate().getWeaponBoost(); equipment.usePowerShard(mainHandPowerShard, 1); } } } // magical resistance resultDamage = Math.round( resultDamage * (1 - attacked.getGameStats().getMagicalDefenseFor(element) / 1000f)); if (resultDamage <= 0) resultDamage = 1; return resultDamage; }
/** * This method is used for creating new players * * @param playerCommonData * @param playerAppearance * @param account * @return Player */ public static Player newPlayer( PlayerCommonData playerCommonData, PlayerAppearance playerAppearance, Account account) { PlayerInitialData playerInitialData = DataManager.PLAYER_INITIAL_DATA; LocationData ld = playerInitialData.getSpawnLocation(playerCommonData.getRace()); WorldPosition position = World.getInstance() .createPosition(ld.getMapId(), ld.getX(), ld.getY(), ld.getZ(), ld.getHeading(), 0); playerCommonData.setPosition(position); Player newPlayer = new Player(new PlayerController(), playerCommonData, playerAppearance, account); // Starting skills newPlayer.setSkillList(new PlayerSkillList()); SkillLearnService.addNewSkills(newPlayer); // Starting items PlayerCreationData playerCreationData = playerInitialData.getPlayerCreationData(playerCommonData.getPlayerClass()); Storage playerInventory = new PlayerStorage(StorageType.CUBE); Storage regularWarehouse = new PlayerStorage(StorageType.REGULAR_WAREHOUSE); Storage accountWarehouse = new PlayerStorage(StorageType.ACCOUNT_WAREHOUSE); Equipment equipment = new Equipment(newPlayer); if (playerCreationData != null) { // player transfer List<ItemType> items = playerCreationData.getItems(); for (ItemType itemType : items) { int itemId = itemType.getTemplate().getTemplateId(); Item item = ItemFactory.newItem(itemId, itemType.getCount()); if (item == null) continue; // When creating new player - all equipment that has slot values will be equipped // Make sure you will not put into xml file more items than possible to equip. ItemTemplate itemTemplate = item.getItemTemplate(); if ((itemTemplate.isArmor() || itemTemplate.isWeapon()) && !(equipment.isSlotEquipped(itemTemplate.getItemSlot()))) { item.setEquipped(true); ItemSlot[] itemSlots = ItemSlot.getSlotsFor(itemTemplate.getItemSlot()); item.setEquipmentSlot(itemSlots[0].getSlotIdMask()); equipment.onLoadHandler(item); } else playerInventory.onLoadHandler(item); } } newPlayer.setStorage(playerInventory, StorageType.CUBE); newPlayer.setStorage(regularWarehouse, StorageType.REGULAR_WAREHOUSE); newPlayer.setStorage(accountWarehouse, StorageType.ACCOUNT_WAREHOUSE); newPlayer.setEquipment(equipment); newPlayer.setMailbox(new Mailbox(newPlayer)); for (int petBagId = 32; petBagId < 36; petBagId++) { Storage petBag = new PlayerStorage(StorageType.getStorageTypeById(petBagId)); newPlayer.setStorage(petBag, StorageType.getStorageTypeById(petBagId)); } /** Mark inventory and equipment as UPDATE_REQUIRED to be saved during character creation */ playerInventory.setPersistentState(PersistentState.UPDATE_REQUIRED); equipment.setPersistentState(PersistentState.UPDATE_REQUIRED); return newPlayer; }
/** * @param attacker * @param target * @return */ public static int calculateSubHandPhysicDamageToTarget(Creature attacker, Creature attacked) { CreatureGameStats<?> ags = attacker.getGameStats(); int min = ags.getCurrentStat(StatEnum.SUB_MIN_DAMAGES); int max = ags.getCurrentStat(StatEnum.SUB_MAX_DAMAGES); int average = Math.round((min + max) / 2); Equipment equipment = ((Player) attacker).getEquipment(); if (average < 1) { average = 1; log.warn("Weapon stat MIN_MAX_DAMAGE resulted average zero in sub-hand calculation"); log.warn( "Weapon ID: " + String.valueOf(equipment.getSubHandWeapon().getItemTemplate().getTemplateId())); log.warn("MIN_DAMAGE = " + String.valueOf(min)); log.warn("MAX_DAMAGE = " + String.valueOf(max)); } int base = Rnd.get(min, max); int damage = base + ags.getStatBonus(StatEnum.SUB_HAND_PHYSICAL_ATTACK); if (attacker.isInState(CreatureState.POWERSHARD)) { Item subHandPowerShard = equipment.getSubHandPowerShard(); if (subHandPowerShard != null) { damage += subHandPowerShard.getItemTemplate().getWeaponBoost(); equipment.usePowerShard(subHandPowerShard, 1); } } int dualEffect = ((Player) attacker).getEffectController().getDualEffect(); if (dualEffect == 0) { log.warn( "Missing dualeffect for player " + ((Player) attacker).getName() + " possible hack? or bug?"); dualEffect = 25; } if (Rnd.get(0, 100) < 25) damage *= (dualEffect * 0.007f); // physical defense damage -= Math.round(attacked.getGameStats().getCurrentStat(StatEnum.PHYSICAL_DEFENSE) * 0.10f); if (damage <= 0) damage = 1; return damage; }
/** * @param player * @param target * @param skillDamages * @return Damage made to target (-hp value) */ public static int calculatePhysicDamageToTarget( Creature attacker, Creature attacked, int skillDamages, int bonusDamages) { CreatureGameStats<?> ags = attacker.getGameStats(); int resultDamage = 0; if (attacker instanceof Player) { int min = ags.getCurrentStat(StatEnum.MAIN_MIN_DAMAGES); int max = ags.getCurrentStat(StatEnum.MAIN_MAX_DAMAGES); int min2 = ags.getCurrentStat(StatEnum.SUB_MIN_DAMAGES); int max2 = ags.getCurrentStat(StatEnum.SUB_MAX_DAMAGES); // weapon with higher average should be taken into account for skills if (skillDamages > 0) { if (((min + max) / 2) < ((min2 + max2) / 2)) { min = min2; max = max2; } } int average = Math.round((min + max) / 2); Equipment equipment = ((Player) attacker).getEquipment(); WeaponType weaponType = equipment.getMainHandWeaponType(); if (weaponType != null) { if (average < 1) { average = 1; log.warn("Weapon stat MIN_MAX_DAMAGE resulted average zero in main-hand calculation"); log.warn( "Weapon ID: " + String.valueOf( equipment.getMainHandWeapon().getItemTemplate().getTemplateId())); log.warn("MIN_DAMAGE = " + String.valueOf(min)); log.warn("MAX_DAMAGE = " + String.valueOf(max)); } int base = Math.round(Rnd.get(min, max) * ags.getCurrentStat(StatEnum.POWER) * 0.01f); resultDamage = base + ags.getStatBonus(StatEnum.MAIN_HAND_PHYSICAL_ATTACK) + skillDamages + bonusDamages; } else // if hand attack { int base = Rnd.get(16, 20); resultDamage = Math.round(base * (ags.getCurrentStat(StatEnum.POWER) * 0.01f)); } if (attacker.isInState(CreatureState.POWERSHARD)) { Item mainHandPowerShard = equipment.getMainHandPowerShard(); if (mainHandPowerShard != null) { resultDamage += mainHandPowerShard.getItemTemplate().getWeaponBoost(); equipment.usePowerShard(mainHandPowerShard, 1); } } } else if (attacker instanceof Summon) { int baseDamage = ags.getCurrentStat(StatEnum.MAIN_HAND_PHYSICAL_ATTACK); // 10% range for summon attack int max = ((baseDamage * attacker.getLevel()) / 10); int min = Math.round(max * 0.9f); resultDamage += Rnd.get(min, max); } else { NpcRank npcRank = ((Npc) attacker).getObjectTemplate().getRank(); double multipler = calculateRankMultipler(npcRank); double hpGaugeMod = 1 + (((Npc) attacker).getObjectTemplate().getHpGauge() / 10); int baseDamage = ags.getCurrentStat(StatEnum.MAIN_HAND_PHYSICAL_ATTACK); int max = (int) ((baseDamage * multipler * hpGaugeMod) + ((baseDamage * attacker.getLevel()) / 10)); int min = max - ags.getCurrentStat(StatEnum.MAIN_HAND_PHYSICAL_ATTACK); resultDamage += Rnd.get(min, max); } // physical defense resultDamage -= Math.round(attacked.getGameStats().getCurrentStat(StatEnum.PHYSICAL_DEFENSE) * 0.10f); if (resultDamage <= 0) resultDamage = 1; return resultDamage; }
/** * Returns the player with given objId (if such player exists) * * @param playerObjId * @param account * @return Player */ public static Player getPlayer(int playerObjId, Account account) { Player player = playerCache.get(playerObjId); if (player != null) return player; /** Player common data and appearance should be already loaded in account */ PlayerAccountData playerAccountData = account.getPlayerAccountData(playerObjId); PlayerCommonData pcd = playerAccountData.getPlayerCommonData(); PlayerAppearance appearance = playerAccountData.getAppereance(); player = new Player(new PlayerController(), pcd, appearance, account); LegionMember legionMember = LegionService.getInstance().getLegionMember(player.getObjectId()); if (legionMember != null) player.setLegionMember(legionMember); MacroList macroses = DAOManager.getDAO(PlayerMacrossesDAO.class).restoreMacrosses(playerObjId); player.setMacroList(macroses); player.setSkillList(DAOManager.getDAO(PlayerSkillListDAO.class).loadSkillList(playerObjId)); player.setKnownlist(new KnownList(player)); player.setFriendList(DAOManager.getDAO(FriendListDAO.class).load(player)); player.setBlockList(DAOManager.getDAO(BlockListDAO.class).load(player)); player.setTitleList(DAOManager.getDAO(PlayerTitleListDAO.class).loadTitleList(playerObjId)); DAOManager.getDAO(PlayerSettingsDAO.class).loadSettings(player); DAOManager.getDAO(AbyssRankDAO.class).loadAbyssRank(player); DAOManager.getDAO(PlayerNpcFactionsDAO.class).loadNpcFactions(player); DAOManager.getDAO(MotionDAO.class).loadMotionList(player); player.setVars(DAOManager.getDAO(PlayerVarsDAO.class).load(player.getObjectId())); Equipment equipment = DAOManager.getDAO(InventoryDAO.class).loadEquipment(player); ItemService.loadItemStones(equipment.getEquippedItemsWithoutStigma()); equipment.setOwner(player); player.setEquipment(equipment); player.setEffectController(new PlayerEffectController(player)); player.setFlyController(new FlyController(player)); PlayerStatFunctions.addPredefinedStatFunctions(player); player.setQuestStateList(DAOManager.getDAO(PlayerQuestListDAO.class).load(player)); player.setRecipeList(DAOManager.getDAO(PlayerRecipesDAO.class).load(player.getObjectId())); /** Account warehouse should be already loaded in account */ Storage accWarehouse = account.getAccountWarehouse(); player.setStorage(accWarehouse, StorageType.ACCOUNT_WAREHOUSE); Storage inventory = DAOManager.getDAO(InventoryDAO.class).loadStorage(playerObjId, StorageType.CUBE); ItemService.loadItemStones(inventory.getItems()); player.setStorage(inventory, StorageType.CUBE); for (int petBagId = 32; petBagId < 36; petBagId++) { Storage petBag = DAOManager.getDAO(InventoryDAO.class) .loadStorage(playerObjId, StorageType.getStorageTypeById(petBagId)); ItemService.loadItemStones(petBag.getItems()); player.setStorage(petBag, StorageType.getStorageTypeById(petBagId)); } Storage warehouse = DAOManager.getDAO(InventoryDAO.class) .loadStorage(playerObjId, StorageType.REGULAR_WAREHOUSE); ItemService.loadItemStones(warehouse.getItems()); player.setStorage(warehouse, StorageType.REGULAR_WAREHOUSE); /** Apply equipment stats (items and manastones were loaded in account) */ player.getEquipment().onLoadApplyEquipmentStats(); DAOManager.getDAO(PlayerPunishmentsDAO.class) .loadPlayerPunishments(player, PunishmentType.PRISON); DAOManager.getDAO(PlayerPunishmentsDAO.class) .loadPlayerPunishments(player, PunishmentType.GATHER); // update passive stats after effect controller, stats and equipment are initialized player.getController().updatePassiveStats(); // load saved effects DAOManager.getDAO(PlayerEffectsDAO.class).loadPlayerEffects(player); // load saved player cooldowns DAOManager.getDAO(PlayerCooldownsDAO.class).loadPlayerCooldowns(player); // load item cooldowns DAOManager.getDAO(ItemCooldownsDAO.class).loadItemCooldowns(player); // load portal cooldowns DAOManager.getDAO(PortalCooldownsDAO.class).loadPortalCooldowns(player); // load bind point DAOManager.getDAO(PlayerBindPointDAO.class).loadBindPoint(player); // load craft cooldowns DAOManager.getDAO(CraftCooldownsDAO.class).loadCraftCooldowns(player); if (player.getCommonData().getTitleId() > 0) { TitleChangeListener.onTitleChange( player.getGameStats(), player.getCommonData().getTitleId(), true); } DAOManager.getDAO(PlayerLifeStatsDAO.class).loadPlayerLifeStat(player); DAOManager.getDAO(PlayerEmotionListDAO.class).loadEmotions(player); // analyze current instance InstanceService.onPlayerLogin(player); if (CacheConfig.CACHE_PLAYERS) playerCache.put(playerObjId, player); return player; }