示例#1
0
 private Buff findEqualBuff(Buff toAdd) {
   for (Buff b : buffList) {
     if (toAdd.getClass().equals(b.getClass())) {
       return b;
     }
   }
   return null;
 }
示例#2
0
 private boolean isImmuneTo(Buff newBuff) {
   for (Class<? extends Buff> buff : immunityList.keySet()) {
     if (buff.isAssignableFrom(newBuff.getClass())) {
       UpgradeType immuneType = immunityList.get(buff);
       return immuneType.equals(UpgradeType.NULL) || immuneType.equals(newBuff.getType());
     }
   }
   return false;
 }
示例#3
0
 /**
  * Advances time of buffs in myObject by increment 1
  *
  * @param myObject
  */
 public void update(GameObject myObject) {
   ArrayList<Buff> removeBuffer = new ArrayList<Buff>();
   for (Buff buff : buffList) {
     if (buff.timeLeft() <= 0) {
       removeBuffer.add(buff);
     }
     buff.advanceTime(1, myObject);
   }
   for (Buff toRemove : removeBuffer) {
     removeBuff(toRemove, myObject);
   }
 }
示例#4
0
 public void castSpell(Ability ability) {
   if (ability.state != Ability.State.READY
       && ability.abilityStats.castType != Castable.CastType.TOGGLE) return;
   if (ability.abilityStats.castType == Castable.CastType.ALIVETARGET) {
     if (owner.selectedUnit == null
         || !Alive.class.isAssignableFrom(owner.selectedUnit.getClass())) return;
     ability.setTarget((Alive) owner.selectedUnit);
   }
   try {
     ability.activate();
   } catch (SLEImproperInputException e) {
     System.out.println("The hero was unable to cast the spell due to improper input");
     e.printStackTrace();
   }
   for (Buff b : getBuffs())
     if (b.activationTrigger == Buff.TriggerType.ONSPELLCAST) b.trigger(this);
 }
示例#5
0
 public void receiveBuff(Buff toAdd, GameObject myObject) {
   if (isImmuneTo(toAdd)) {
     return;
   }
   Buff equalBuff = findEqualBuff(toAdd);
   if (equalBuff == null) {
     applyBuff(toAdd, myObject);
   } else if (toAdd.isStrongerBuff(equalBuff)) {
     removeBuff(equalBuff, myObject);
     applyBuff(toAdd, myObject);
   }
 }
示例#6
0
  @Override
  protected void write() {
    Queue<Buff> buffs = fill(_buffer.length);

    if (buffs != null) {
      int offset = 0;

      for (; ; ) {
        Buff buff = buffs.poll();

        if (buff == null) break;

        int remaining = buff.remaining();
        buff.getImmutably(_buffer, offset, remaining);
        buff.recycle();
        offset += remaining;
      }

      writeComplete();
    }
  }
示例#7
0
  @Override
  void getBlock(URI uri, long tick) {
    Buff duplicate = null;

    synchronized (this) {
      if (Debug.THREADS) ThreadAssert.resume(this, false);

      int index = Tick.indexOf(_ticks, tick);

      if (index >= 0) {
        Buff buff = _buffs[index];

        if (buff != null) {
          duplicate = buff.duplicate();

          if (Debug.THREADS) ThreadAssert.exchangeGive(duplicate, duplicate);
        }
      }

      if (Debug.THREADS) ThreadAssert.suspend(this);
    }

    if (duplicate != null) {
      Buff[] duplicates = new Buff[] {duplicate};

      if (Debug.THREADS) {
        ThreadAssert.exchangeTake(duplicate);
        ThreadAssert.exchangeGive(duplicates, duplicate);
      }

      uri.onBlock(this, tick, duplicates, null, true, null, false, null);

      if (Debug.THREADS) ThreadAssert.exchangeTake(duplicates);

      duplicate.recycle();
    }
  }
  @Test
  public void should_getInstantDamageMessage_return_message_when_is_a_Instant_buff() {

    assertThat(critial.getInstantDamageMessage(), is("发动了全力一击,"));
  }
 @Override
 public void detach() {
   target.paralysed = false;
   if (target instanceof Hero) ((Hero) target).restoreHealth = false;
   super.detach();
 }
 @Override
 public void restoreFromBundle(Bundle bundle) {
   super.restoreFromBundle(bundle);
   level = bundle.getInt(LEVEL);
 }
示例#11
0
  public void read(byte[] buffer, int length) {
    if (resumeRead()) {
      Buff buff = Buff.getOrCreate();
      buff.position(Buff.getLargestUnsplitable());
      byte[] temp = _randomSplitter.read(buffer, 0, length, buff.remaining());
      buff.putImmutably(temp, 0, temp.length);
      buff.limit(buff.position() + temp.length);

      if (Debug.ENABLED && buff.remaining() == 0) buff.lock(buff.limit());

      read(buff);
      buff.recycle();

      suspendRead();
    }
  }
 @Test
 public void should_getDelayDamageMessage_return_what_kind_of_damage() {
   assertThat(critial.getDelayDamageMessage(), is(""));
 }
 @Override
 public void storeInBundle(Bundle bundle) {
   super.storeInBundle(bundle);
   bundle.put(LEFT, left);
 }
示例#14
0
 private void removeBuff(Buff b, GameObject myObject) {
   buffList.remove(b);
   b.unapply(myObject);
 }
示例#15
0
 private void applyBuff(Buff b, GameObject myObject) {
   b.apply(myObject);
   buffList.add(b);
 }
 @Test
 public void should_getBuffMessage_return_what_kind_of_buff() {
   assertThat(critial.getBuffMessage(), is(""));
 }
 @Test
 public void should_getDelayDamagePoint_return_how_many_damage_when_a_delayDamage_buff() {
   assertThat(critial.getDelayDamagePoint(), is(0));
 }
 @Override
 public void restoreFromBundle(Bundle bundle) {
   super.restoreFromBundle(bundle);
   left = bundle.getFloat(LEFT);
 }
  @Test
  public void should_getCritialRate_return_3_when_is_a_critial_buff() {

    assertThat(critial.getCritialRate(), is(3));
  }
  public void proc(Char enemy) {
    if (Random.Int(2) == 0) Buff.affect(enemy, Burning.class).reignite(enemy);

    enemy.sprite.emitter().burst(FlameParticle.FACTORY, 2);
  }
示例#21
0
  @Override
  void onBlock(URI uri, long tick, Buff[] buffs, long[] removals, boolean requested) {
    int capacity = 0;

    if (Debug.THREADS) ThreadAssert.exchangeTake(buffs);

    for (int i = 0; i < buffs.length; i++) capacity += buffs[i].remaining();

    Buff buff = Buff.createCustom(capacity, false);

    if (Stats.ENABLED) Stats.Instance.MemoryBlocksCreated.incrementAndGet();

    for (int i = 0; i < buffs.length; i++) {
      buff.putImmutably(buffs[i]);

      if (Debug.THREADS) ThreadAssert.exchangeGive(buffs, buffs[i]);
    }

    if (Debug.ENABLED) Debug.assertion(buff.remaining() == 0);

    buff.position(0);
    buff.mark();

    List<Buff> recycle = null;

    if (Debug.THREADS) ThreadAssert.exchangeGive(buff, buff);

    synchronized (this) {
      if (Debug.THREADS) {
        ThreadAssert.resume(this, false);
        ThreadAssert.exchangeTake(buff);
      }

      int index = Tick.indexOf(_ticks, tick);

      if (index < 0) {
        index = add(tick);
        _buffs[index] = buff;

        if (Stats.ENABLED) Stats.Instance.MemoryBlocksLive.incrementAndGet();
      } else {
        if (Debug.ENABLED) Debug.assertion(_buffs[index] != null);

        recycle = new List<Buff>();
        recycle.add(buff);
      }

      for (int i = 0; removals != null && i < removals.length; i++) {
        if (!Tick.isNull(removals[i])) {
          index = Tick.remove(_ticks, removals[i]);

          if (index >= 0) {
            if (recycle == null) recycle = new List<Buff>();

            recycle.add(_buffs[index]);
            _buffs[index] = null;

            if (Stats.ENABLED) Stats.Instance.MemoryBlocksLive.decrementAndGet();
          }
        }
      }

      if (Debug.THREADS) {
        for (int i = 0; recycle != null && i < recycle.size(); i++)
          ThreadAssert.exchangeGive(recycle, recycle.get(i));

        ThreadAssert.suspend(this);
      }
    }

    if (!location().isCache()) {
      uri.onAck(this, tick);

      if (Stats.ENABLED) Stats.Instance.AckCreated.incrementAndGet();
    }

    if (recycle != null) {
      if (Debug.THREADS) ThreadAssert.exchangeTake(recycle);

      for (int i = 0; i < recycle.size(); i++) recycle.get(i).recycle();
    }
  }
 @Override
 public void storeInBundle(Bundle bundle) {
   super.storeInBundle(bundle);
   bundle.put(LEVEL, level);
 }