当前位置: 首页>>代码示例>>C++>>正文


C++ Spell::setTarget方法代码示例

本文整理汇总了C++中Spell::setTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ Spell::setTarget方法的具体用法?C++ Spell::setTarget怎么用?C++ Spell::setTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Spell的用法示例。


在下文中一共展示了Spell::setTarget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: on_cast_spell

	void instance::on_cast_spell(const Event& inEvt) {
    if (!inEvt.hasProperty("Spell")) {
      Event evt(inEvt);
      reject(evt);
      return;
    }

		// find the spell object
    Spell* lSpell;
		try {
      lSpell = get_spell(convertTo<int>(inEvt.getProperty("Spell")));
    } catch (invalid_uid& e) {
      // reject the event
      log_->errorStream() << "couldn't find requested Spell with id " << inEvt.getProperty("Spell");
      Event evt(inEvt);
		  reject(evt);
      return;
    }

		Entity* lCaster = lSpell->getCaster();

    assert(lCaster && lSpell);
    log_->debugStream() << "spell cast: " << lSpell->getUID() << "#" << lSpell->getName();
    log_->debugStream() << "caster: " << lCaster->getUID() << "#" << lCaster->getName();

    // allow only ALL or CASTING spells to be cast by active puppets
    if (lSpell->getPhase() != BLOCKING && active_puppet_->getUID() != lCaster->getOwner()->getUID())
    {
      Event evt(inEvt);
		  return reject(evt);
    }
    // blocking spells can only be cast when the active is not the caster
    else if (lSpell->getPhase() == BLOCKING && active_puppet_->getUID() == lCaster->getOwner()->getUID())
    {
      Event evt(inEvt);
		  return reject(evt);
    }

    Entity* lTarget = 0;
    if (inEvt.hasProperty("T")) {
      try {
        // is the target a puppet?
        lTarget = get_puppet(convertTo<int>(inEvt.getProperty("T"))).get();
        log_->debugStream() << "target: " << lTarget->getUID() << "#" << lTarget->getName();
      } catch (invalid_uid& e) {
        try {
          // a unit?
          lTarget = get_unit(convertTo<int>(inEvt.getProperty("T")));
          log_->debugStream() << "target: " << lTarget->getUID() << "#" << lTarget->getName();
        } catch (invalid_uid& e) {
          // invalid UID
          log_->errorStream() << "couldn't find spell target with id " << inEvt.getProperty("T");
          Event evt(inEvt);
          reject(evt);
          return;
        }
      }

      assert(lTarget);
      lSpell->setTarget(lTarget);
    } else {
      // if the spell requires a target, it must be given
#ifdef PARANOID
      assert(!lSpell->requiresTarget());
#else
      // gracefully reject the event
      if (lSpell->requiresTarget())
      {
        log_->errorStream()
          << "an invalid spell request#" << lSpell->getUID()
          << "; target is required but not given";
        Event e(inEvt);
        return reject(e);
      }
#endif
      // otherwise, the spell's target is the caster itself
      lSpell->setTarget(lCaster);
    }

    // verify the caster having enough resources to cast the spell
    {
      bool valid = true;
      if (lCaster->getRank() == PUPPET)
      {
        if (lSpell->getCostWP() > ((Puppet*)lCaster)->getWP())
          valid = valid && false;

        // heroes can't have less than 1 channel
        if (lSpell->getCostChannels() >= ((Puppet*)lCaster)->getChannels())
          valid = valid && false;
      }

      if (lSpell->getCostHP() > lCaster->getHP())
        valid = valid && false;


      if (!valid)
      {
        if (lCaster->getRank() == PUPPET)
        {
//.........这里部分代码省略.........
开发者ID:amireh,项目名称:Phantom,代码行数:101,代码来源:instance.cpp


注:本文中的Spell::setTarget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。