Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package koh.game.fights.utils;
- import koh.game.dao.DAO;
- import koh.game.entities.actors.Player;
- import koh.game.entities.spells.EffectInstanceDice;
- import koh.game.entities.spells.SpellLevel;
- import koh.game.fights.Fight;
- import koh.game.fights.FightState;
- import koh.game.fights.Fighter;
- import koh.game.fights.IFightObject;
- import koh.game.fights.effects.buff.BuffMinimizeEffects;
- import koh.game.fights.layers.FightPortal;
- import koh.game.utils.Three;
- import koh.protocol.client.enums.ActionIdEnum;
- import koh.protocol.client.enums.SequenceTypeEnum;
- import koh.protocol.client.enums.StatsEnum;
- import koh.protocol.client.enums.TextInformationTypeEnum;
- import koh.protocol.messages.game.actions.fight.GameActionFightPointsVariationMessage;
- import koh.protocol.messages.game.actions.fight.GameActionFightSpellCastMessage;
- import koh.protocol.messages.game.basic.TextInformationMessage;
- import org.apache.commons.lang3.ArrayUtils;
- import org.apache.commons.lang3.mutable.MutableObject;
- import java.util.Arrays;
- import static koh.protocol.client.enums.StatsEnum.CAST_SPELL_ON_CRITICAL_HIT;
- /**
- * Created by Melancholia on 10/29/16.
- */
- public class XelorHandler {
- //@Spell 91 Frappe du xelôr
- public static void xelorStrike(Fighter fighter, SpellLevel spellLevel, Short cellId, boolean friend) {
- if (fighter.getMutex() == null) {
- return;
- }
- synchronized (fighter.getMutex()) {
- try {
- final short oldCell = cellId;
- final MutableObject<Three<Integer, int[], Integer>> portalQuery = new MutableObject<>();
- if (!preCast(fighter, spellLevel, oldCell, cellId, fighter.getFight(), friend, portalQuery)) {
- return;
- }
- final MutableObject<EffectInstanceDice[]> spellEffects = new MutableObject<>();
- final boolean isCritical = isCritical(fighter, spellLevel, cellId, portalQuery.getValue().tree, spellEffects, portalQuery);
- //TODO : fin du code :@
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- private static boolean preCast(Fighter fighter, SpellLevel spellLevel, final short oldCell, Short cellId, final Fight fight, boolean friend, final MutableObject<Three<Integer, int[], Integer>> portalQuery) {
- if (fight.getFightState() != FightState.STATE_ACTIVE || fight.getFightLoopState() == Fight.FightLoopState.STATE_WAIT_END) {
- return false;
- }
- fight.getChallenges()
- .values()
- .stream()
- .filter(cl -> cl.canBeAnalyzed())
- .forEach(ch -> ch.onFighterCastSpell(fighter, spellLevel));
- if (fight.getCell(cellId).hasGameObject(IFightObject.FightObjectType.OBJECT_PORTAL)) {
- portalQuery.setValue(fight.getTargetThroughPortal(fighter,
- cellId,
- true,
- fight.getCell(cellId).getObjects().stream()
- .filter(x -> x.getObjectType() == IFightObject.FightObjectType.OBJECT_PORTAL)
- .findFirst()
- .map(f -> (FightPortal) f)
- .get().caster.getTeam()
- ));
- cellId = portalQuery.getValue().first.shortValue();
- }
- else{
- portalQuery.setValue(new Three<>(-1, EMPTY_INTS, 0));
- }
- Fighter targetE = fight.hasEnnemyInCell(cellId, fighter.getTeam());
- if (friend && targetE == null) {
- targetE = fight.hasFriendInCell(cellId, fighter.getTeam());
- }
- final int targetId = targetE == null ? -1 : targetE.getID();
- if (!fight.canLaunchSpell(fighter, spellLevel, fighter.getCellId(), oldCell, targetId)) {
- fighter.send(new TextInformationMessage(TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 175));
- fight.startSequence(SequenceTypeEnum.SEQUENCE_SPELL);
- fighter.send(new GameActionFightPointsVariationMessage(ActionIdEnum.ACTION_CHARACTER_ACTION_POINTS_LOST, fighter.getID(), fighter.getID(), (short) 0));
- fight.endSequence(SequenceTypeEnum.SEQUENCE_SPELL, false);
- return false;
- }
- portalQuery.getValue().tree = targetId;
- fight.startSequence(SequenceTypeEnum.SEQUENCE_SPELL);
- fighter.setUsedAP(fighter.getUsedAP() + spellLevel.getApCost());
- fighter.getSpellsController().actualize(spellLevel, targetId);
- return true;
- }
- public static boolean isCritical(Fighter fighter, SpellLevel spellLevel, Short cellId, int targetId, final MutableObject<EffectInstanceDice[]> spellEffects, final MutableObject<Three<Integer, int[], Integer>> portalQuery) {
- boolean isCc = false;
- if (spellLevel.getCriticalHitProbability() != 0 && spellLevel.getCriticalEffect().length > 0) {
- final int tauxCC = fighter.getStats().getTotal(StatsEnum.ADD_CRITICAL_HIT) + spellLevel.getCriticalHitProbability();
- if (tauxCC > (Fight.RANDOM.nextDouble() * 100)) {
- isCc = true;
- }
- }
- isCc &= !fighter.getBuff().getAllBuffs().anyMatch(x -> x instanceof BuffMinimizeEffects);
- if (isCc && fighter.getStats().getTotal(CAST_SPELL_ON_CRITICAL_HIT) > 0 && fighter.isPlayer()) { //Turquoise
- fighter.getPlayer().getInventoryCache().getEffects(CAST_SPELL_ON_CRITICAL_HIT.value())
- //filter turquoise
- .forEach(list -> {
- list.filter(e -> e.diceNum == 5952)
- .forEach(effect -> {
- fighter.getFight().launchSpell(fighter, DAO.getSpells().findSpell(effect.diceNum).getSpellLevel(effect.diceSide), fighter.getCellId(), true, true, true, -1);
- });
- });
- }
- spellEffects.setValue(isCc || spellLevel.getEffects() == null ? spellLevel.getCriticalEffect() : spellLevel.getEffects());
- final boolean silentCast = Arrays.stream(spellEffects.getValue()).allMatch(x -> !ArrayUtils.contains(Fight.EFFECT_NOT_SILENCED, x.getEffectType()));
- for (Player player : fighter.getFight().observable$Stream()) {
- player.send(new GameActionFightSpellCastMessage(ActionIdEnum.ACTION_FIGHT_CAST_SPELL,
- fighter.getID(),
- targetId,
- (spellLevel.getSpellId() == 2763 ? true : ((!fighter.isVisibleFor(player) && silentCast) || (Arrays.stream(spellEffects.getValue()).anyMatch(e -> e.getEffectType() == StatsEnum.LAYING_TRAP_LEVEL)))) ? 0 : cellId,
- (byte) (isCc ? 2 : 1),
- spellLevel.getSpellId() == 2763 ? true : (!fighter.isVisibleFor(player) && silentCast), spellLevel.getSpellId() == 0 ? 2 : spellLevel.getSpellId(),
- spellLevel.getGrade(),
- portalQuery.getValue().second)
- );
- }
- return isCc;
- }
- private static final int[] EMPTY_INTS = new int[0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement