⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 battle.cpp

📁 S.C.O.U.R.G.E.是一款类似Rogue的游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      scourge->getMap()->addDescription(message);    } else {      // scroll was removed from inventory before casting      sprintf(message, "Couldn't find scroll, cancelled spell.");      scourge->getMap()->addDescription(message);      creature->cancelTarget();      return;    }  }  sprintf(message, "%s casts %s!",           creature->getName(),           creature->getActionSpell()->getName());  scourge->getMap()->addDescription(message, 1, 0.15f, 1);  ((MD2Shape*)(creature->getShape()))->setAttackEffect(true);  // spell succeeds?  // FIXME: use stats like IQ here to modify spell success rate...  SpellCaster *sc = new SpellCaster(this, creature->getActionSpell(), false);  if(!projectileHit &&      (int)(100.0f * rand() / RAND_MAX) < creature->getActionSpell()->getFailureRate()) {    sc->spellFailed();  } else {    // get exp for casting the spell    if(!creature->isMonster()) {      bool b = creature->getStateMod(Constants::leveled);      if(!creature->getStateMod(Constants::dead)) {        int n = creature->addExperience(creature->getActionSpell()->getExp());        if(n > 0) {          sprintf(message, "%s gains %d experience points.", creature->getName(), n);          scourge->getMap()->addDescription(message);          if(!b && creature->getStateMod(Constants::leveled)) {            sprintf(message, "%s gains a level!", creature->getName());            scourge->getMap()->addDescription(message, 1.0f, 0.5f, 0.5f);          }        }      }    }    sc->spellSucceeded();  }  delete sc;  // cancel action  creature->cancelTarget();}void Battle::launchProjectile() {  sprintf(message, "...%s shoots a projectile", creature->getName());  scourge->getMap()->addDescription(message);   if(!Projectile::addProjectile(creature, creature->getTargetCreature(), item,                                 scourge->getShapePalette()->findShapeByName("ARROW"),                                creature->getMaxProjectileCount(item))) {    // max number of projectiles in the air    // FIXME: do something...     // (like print message: can't launch projectile due to use of fixed-sized array in code?)  }}void Battle::projectileHitTurn(Scourge *scourge, Projectile *proj, Creature *target) {  // configure a turn  Creature *oldTarget = proj->getCreature()->getTargetCreature();  proj->getCreature()->setTargetCreature(target);  Battle *battle = new Battle(scourge, proj->getCreature());  battle->projectileHit = true;  if(proj->getItem()) {    battle->initItem(proj->getItem());  } else if(proj->getSpell()) {    battle->spell = proj->getSpell();  }  // play it  battle->fightTurn();  delete battle;  proj->getCreature()->cancelTarget();  proj->getCreature()->setTargetCreature(oldTarget);}void Battle::projectileHitTurn(Scourge *scourge, Projectile *proj, int x, int y) {  // configure a turn  proj->getCreature()->setTargetLocation(x, y, 0);  Battle *battle = new Battle(scourge, proj->getCreature());  battle->projectileHit = true;  if(proj->getItem()) {    battle->initItem(proj->getItem());  } else if(proj->getSpell()) {    battle->spell = proj->getSpell();  }  // play it  battle->fightTurn();    delete battle;  proj->getCreature()->cancelTarget();}void Battle::hitWithItem() {  if(item) {    sprintf(message, "%s attacks %s with %s! (I:%d,S:%d)",             creature->getName(),             creature->getTargetCreature()->getName(),            item->getItemName(),            creatureInitiative, speed);    scourge->getMap()->addDescription(message);    ((MD2Shape*)(creature->getShape()))->setAttackEffect(true);  } else if(dist <= Constants::MIN_DISTANCE) {    sprintf(message, "%s attacks %s with bare hands! (I:%d,S:%d)",             creature->getName(),             creature->getTargetCreature()->getName(),            creatureInitiative, speed);    scourge->getMap()->addDescription(message);    ((MD2Shape*)(creature->getShape()))->setAttackEffect(true);  }  // take a swing  int tohit = creature->getToHit(item);  int ac = creature->getTargetCreature()->getSkillModifiedArmor();  sprintf(message, "...%s defends with armor=%d", creature->getTargetCreature()->getName(), ac);  scourge->getMap()->addDescription(message);  sprintf(message, "...toHit=%d vs. AC=%d", tohit, ac);  scourge->getMap()->addDescription(message);  if(tohit > ac) {    // deal out the damage    dealDamage(creature->getDamage(item));  } else {    // missed    sprintf(message, "...and misses! (toHit=%d vs. AC=%d)", tohit, ac);    scourge->getMap()->addDescription(message);  }}void Battle::dealDamage(int damage, int effect) {  if(damage) {      sprintf(message, "...and hits! for %d points of damage", damage);    scourge->getMap()->addDescription(message, 1.0f, 0.5f, 0.5f);    // target creature death    if(creature->getTargetCreature()->takeDamage(damage, effect)) {               creature->getShape()->setCurrentAnimation((int)MD2_TAUNT);        sprintf(message, "...%s is killed!", creature->getTargetCreature()->getName());      scourge->getMap()->addDescription(message, 1.0f, 0.5f, 0.5f);      if((creature->getTargetCreature()->isMonster() && !MONSTER_IMORTALITY) ||          !GOD_MODE)        scourge->creatureDeath(creature->getTargetCreature());      // add exp. points and money      if(!creature->isMonster()) {        // FIXME: try to move to party.cpp        for(int i = 0; i < scourge->getParty()->getPartySize(); i++) {          bool b = scourge->getParty()->getParty(i)->getStateMod(Constants::leveled);          if(!scourge->getParty()->getParty(i)->getStateMod(Constants::dead)) {            int n = scourge->getParty()->getParty(i)->addExperience(creature->getTargetCreature());            if(n > 0) {              sprintf(message, "%s gains %d experience points.", scourge->getParty()->getParty(i)->getName(), n);              scourge->getMap()->addDescription(message);              if(!b && scourge->getParty()->getParty(i)->getStateMod(Constants::leveled)) {                sprintf(message, "%s gains a level!", scourge->getParty()->getParty(i)->getName());                scourge->getMap()->addDescription(message, 1.0f, 0.5f, 0.5f);              }            }            n = scourge->getParty()->getParty(i)->addMoney(creature->getTargetCreature());            if(n > 0) {              sprintf(message, "%s finds %d coins!", scourge->getParty()->getParty(i)->getName(), n);              scourge->getMap()->addDescription(message);            }          }        }        // end of FIXME        // see if this is a mission objective        if(scourge->getCurrentMission() &&            creature->getTargetCreature()->getMonster() &&           scourge->getCurrentMission()->monsterSlain(creature->getTargetCreature()->getMonster())) {          scourge->missionCompleted();        }      }    }  } else {    sprintf(message, "...and hits! but causes no damage");    scourge->getMap()->addDescription(message);  }}void Battle::initTurn() {  float range = 0.0f;  // select a weapon  if(creature->getAction() == Constants::ACTION_NO_ACTION) {    // already selected weapon?    if(item) return;    Item *i = creature->getBestWeapon(dist);      if(i) range = i->getRpgItem()->getDistance();    // set up distance range for ranged weapons (do it here so it only happens when the action changes)    creature->setDistanceRange(0, Constants::MIN_DISTANCE);    if(range >= 8) {      creature->setDistanceRange(range * 0.5f, range);    }    initItem(i);  } else {    // or init action    switch(creature->getAction()) {    case Constants::ACTION_CAST_SPELL:      range = creature->getActionSpell()->getDistance();      speed = creature->getActionSpell()->getSpeed() *               (scourge->getUserConfiguration()->getGameSpeedTicks() + 80);      creatureInitiative = creature->getInitiative(NULL, creature->getActionSpell());      // set up distance range for ranged weapons (do it here so it only happens when the action changes)      creature->setDistanceRange(0, Constants::MIN_DISTANCE);      if(range >= 8) {        creature->setDistanceRange(range * 0.5f, range);      }      break;    case Constants::ACTION_EAT_DRINK:      range = creature->getActionItem()->getRpgItem()->getDistance();      speed = creature->getActionItem()->getRpgItem()->getSpeed() *              (scourge->getUserConfiguration()->getGameSpeedTicks() + 80);      creatureInitiative = creature->getInitiative(creature->getActionItem(), NULL);      // set up distance range for ranged weapons (do it here so it only happens when the action changes)      creature->setDistanceRange(0, Constants::MIN_DISTANCE);      if(range >= 8) {        creature->setDistanceRange(range * 0.5f, range);      }      break;    default:      cerr << "*** Error: unhandled action: " << creature->getAction() << endl;    }  }  }void Battle::initItem(Item *item) {  this->item = item;  // (!item) is a bare-hands attack		  speed = (item ? item->getRpgItem()->getSpeed() : Constants::HAND_WEAPON_SPEED) *           (scourge->getUserConfiguration()->getGameSpeedTicks() + 80);  //	(scourge->getUserConfiguration()->getGameSpeedTicks() + 80);  creatureInitiative = creature->getInitiative(item);}void Battle::executeEatDrinkAction() {  // is it still in the inventory?  int index = creature->findInInventory(creature->getActionItem());  if(index > -1) {    if(creature->eatDrink(creature->getActionItem())){      creature->removeInventory(index);    }  }  // cancel action  creature->cancelTarget();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -