Advertisement
Neo-Craft

XelorHandler

Oct 29th, 2016
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.08 KB | None | 0 0
  1. package koh.game.fights.utils;
  2.  
  3. import koh.game.dao.DAO;
  4. import koh.game.entities.actors.Player;
  5. import koh.game.entities.spells.EffectInstanceDice;
  6. import koh.game.entities.spells.SpellLevel;
  7. import koh.game.fights.Fight;
  8. import koh.game.fights.FightState;
  9. import koh.game.fights.Fighter;
  10. import koh.game.fights.IFightObject;
  11. import koh.game.fights.effects.buff.BuffMinimizeEffects;
  12. import koh.game.fights.layers.FightPortal;
  13. import koh.game.utils.Three;
  14. import koh.protocol.client.enums.ActionIdEnum;
  15. import koh.protocol.client.enums.SequenceTypeEnum;
  16. import koh.protocol.client.enums.StatsEnum;
  17. import koh.protocol.client.enums.TextInformationTypeEnum;
  18. import koh.protocol.messages.game.actions.fight.GameActionFightPointsVariationMessage;
  19. import koh.protocol.messages.game.actions.fight.GameActionFightSpellCastMessage;
  20. import koh.protocol.messages.game.basic.TextInformationMessage;
  21. import org.apache.commons.lang3.ArrayUtils;
  22. import org.apache.commons.lang3.mutable.MutableObject;
  23.  
  24. import java.util.Arrays;
  25.  
  26. import static koh.protocol.client.enums.StatsEnum.CAST_SPELL_ON_CRITICAL_HIT;
  27.  
  28. /**
  29.  * Created by Melancholia on 10/29/16.
  30.  */
  31. public class XelorHandler {
  32.  
  33.     //@Spell 91 Frappe du xelôr
  34.     public static void xelorStrike(Fighter fighter, SpellLevel spellLevel, Short cellId, boolean friend) {
  35.         if (fighter.getMutex() == null) {
  36.             return;
  37.         }
  38.         synchronized (fighter.getMutex()) {
  39.             try {
  40.                 final short oldCell = cellId;
  41.                 final MutableObject<Three<Integer, int[], Integer>> portalQuery = new MutableObject<>();
  42.                 if (!preCast(fighter, spellLevel, oldCell, cellId, fighter.getFight(), friend, portalQuery)) {
  43.                     return;
  44.                 }
  45.                 final MutableObject<EffectInstanceDice[]> spellEffects = new MutableObject<>();
  46.  
  47.                 final boolean isCritical = isCritical(fighter, spellLevel, cellId, portalQuery.getValue().tree, spellEffects, portalQuery);
  48.  
  49.                 //TODO : fin du code :@
  50.  
  51.  
  52.             } catch (Exception e) {
  53.                 e.printStackTrace();
  54.             }
  55.         }
  56.     }
  57.  
  58.  
  59.     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) {
  60.         if (fight.getFightState() != FightState.STATE_ACTIVE || fight.getFightLoopState() == Fight.FightLoopState.STATE_WAIT_END) {
  61.             return false;
  62.         }
  63.         fight.getChallenges()
  64.                 .values()
  65.                 .stream()
  66.                 .filter(cl -> cl.canBeAnalyzed())
  67.                 .forEach(ch -> ch.onFighterCastSpell(fighter, spellLevel));
  68.  
  69.  
  70.         if (fight.getCell(cellId).hasGameObject(IFightObject.FightObjectType.OBJECT_PORTAL)) {
  71.             portalQuery.setValue(fight.getTargetThroughPortal(fighter,
  72.                     cellId,
  73.                     true,
  74.                     fight.getCell(cellId).getObjects().stream()
  75.                             .filter(x -> x.getObjectType() == IFightObject.FightObjectType.OBJECT_PORTAL)
  76.                             .findFirst()
  77.                             .map(f -> (FightPortal) f)
  78.                             .get().caster.getTeam()
  79.             ));
  80.             cellId = portalQuery.getValue().first.shortValue();
  81.         }
  82.         else{
  83.             portalQuery.setValue(new Three<>(-1, EMPTY_INTS, 0));
  84.         }
  85.  
  86.         Fighter targetE = fight.hasEnnemyInCell(cellId, fighter.getTeam());
  87.         if (friend && targetE == null) {
  88.             targetE = fight.hasFriendInCell(cellId, fighter.getTeam());
  89.         }
  90.  
  91.         final int targetId = targetE == null ? -1 : targetE.getID();
  92.  
  93.         if (!fight.canLaunchSpell(fighter, spellLevel, fighter.getCellId(), oldCell, targetId)) {
  94.             fighter.send(new TextInformationMessage(TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 175));
  95.             fight.startSequence(SequenceTypeEnum.SEQUENCE_SPELL);
  96.             fighter.send(new GameActionFightPointsVariationMessage(ActionIdEnum.ACTION_CHARACTER_ACTION_POINTS_LOST, fighter.getID(), fighter.getID(), (short) 0));
  97.             fight.endSequence(SequenceTypeEnum.SEQUENCE_SPELL, false);
  98.             return false;
  99.         }
  100.  
  101.         portalQuery.getValue().tree = targetId;
  102.         fight.startSequence(SequenceTypeEnum.SEQUENCE_SPELL);
  103.         fighter.setUsedAP(fighter.getUsedAP() + spellLevel.getApCost());
  104.  
  105.         fighter.getSpellsController().actualize(spellLevel, targetId);
  106.  
  107.         return true;
  108.     }
  109.  
  110.     public static boolean isCritical(Fighter fighter, SpellLevel spellLevel, Short cellId, int targetId, final MutableObject<EffectInstanceDice[]> spellEffects, final MutableObject<Three<Integer, int[], Integer>> portalQuery) {
  111.         boolean isCc = false;
  112.         if (spellLevel.getCriticalHitProbability() != 0 && spellLevel.getCriticalEffect().length > 0) {
  113.             final int tauxCC = fighter.getStats().getTotal(StatsEnum.ADD_CRITICAL_HIT) + spellLevel.getCriticalHitProbability();
  114.  
  115.             if (tauxCC > (Fight.RANDOM.nextDouble() * 100)) {
  116.                 isCc = true;
  117.             }
  118.         }
  119.  
  120.         isCc &= !fighter.getBuff().getAllBuffs().anyMatch(x -> x instanceof BuffMinimizeEffects);
  121.         if (isCc && fighter.getStats().getTotal(CAST_SPELL_ON_CRITICAL_HIT) > 0 && fighter.isPlayer()) { //Turquoise
  122.             fighter.getPlayer().getInventoryCache().getEffects(CAST_SPELL_ON_CRITICAL_HIT.value())
  123.                     //filter turquoise
  124.                     .forEach(list -> {
  125.                         list.filter(e -> e.diceNum == 5952)
  126.                                 .forEach(effect -> {
  127.                                     fighter.getFight().launchSpell(fighter, DAO.getSpells().findSpell(effect.diceNum).getSpellLevel(effect.diceSide), fighter.getCellId(), true, true, true, -1);
  128.                                 });
  129.                     });
  130.         }
  131.  
  132.         spellEffects.setValue(isCc || spellLevel.getEffects() == null ? spellLevel.getCriticalEffect() : spellLevel.getEffects());
  133.  
  134.         final boolean silentCast = Arrays.stream(spellEffects.getValue()).allMatch(x -> !ArrayUtils.contains(Fight.EFFECT_NOT_SILENCED, x.getEffectType()));
  135.  
  136.  
  137.         for (Player player : fighter.getFight().observable$Stream()) {
  138.             player.send(new GameActionFightSpellCastMessage(ActionIdEnum.ACTION_FIGHT_CAST_SPELL,
  139.                     fighter.getID(),
  140.                     targetId,
  141.                     (spellLevel.getSpellId() == 2763 ? true : ((!fighter.isVisibleFor(player) && silentCast) || (Arrays.stream(spellEffects.getValue()).anyMatch(e -> e.getEffectType() == StatsEnum.LAYING_TRAP_LEVEL)))) ? 0 : cellId,
  142.                     (byte) (isCc ? 2 : 1),
  143.                     spellLevel.getSpellId() == 2763 ? true : (!fighter.isVisibleFor(player) && silentCast), spellLevel.getSpellId() == 0 ? 2 : spellLevel.getSpellId(),
  144.                     spellLevel.getGrade(),
  145.                     portalQuery.getValue().second)
  146.             );
  147.         }
  148.  
  149.         return isCc;
  150.     }
  151.  
  152.     private static final int[] EMPTY_INTS = new int[0];
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement