std::string Item::getDescription(int32_t lookDistance) const { std::stringstream s; const ItemType& it = items[id]; if (it.name.length()) { if(isStackable() && count > 1){ s << (int)count << " " << it.name << "s."; if(lookDistance <= 1) { s << std::endl << "They weight " << std::fixed << std::setprecision(2) << ((double) count * it.weight) << " oz."; } } else{ if(items[id].runeMagLevel != -1) { s << "a spell rune for level " << it.runeMagLevel << "." << std::endl; s << "It's an \"" << it.name << "\" spell ("; if(getItemCharge()) s << (int)getItemCharge(); else s << "1"; s << "x)."; } else if(isWeapon() && (getAttack() || getDefense())) { if(getAttack()){ s << "a " << it.name << " (Atk:" << (int)getAttack() << " Def:" << (int)getDefense() << ")."; } else{ s << "a " << it.name << " (Def:" << (int)getDefense() << ")."; } } else if(getArmor()){ s << "a " << it.name << " (Arm:" << (int)getArmor() << ")."; } else if(isFluidContainer()){ s << "a " << it.name; if(fluid == 0){ s << ". It is empty."; } else{ s << " of " << items[fluid].name << "."; } } else if(isSplash()){ s << "a " << it.name << " of "; if(fluid == 0){ s << items[1].name << "."; } else{ s << items[fluid].name << "."; } } else if(it.isKey()){ s << "a " << it.name << " (Key:" << actionId << ")."; } else if(it.isGroundTile()){ s << it.name << "."; } else if(it.isContainer()){ s << "a " << it.name << " (Vol:" << getContainer()->capacity() << ")."; } else if(it.allowDistRead){ s << it.name << "." << std::endl; if(lookDistance <= 4){ if(text && text->length() > 0){ s << "You read: " << *text; } else s << "Nothing is written on it."; } else s << "You are too far away to read it."; } else{ s << "a " << it.name << "."; } if(lookDistance <= 1){ double weight = getWeight(); if(weight > 0) s << std::endl << "It weighs " << std::fixed << std::setprecision(2) << weight << " oz."; } if(specialDescription) s << std::endl << specialDescription->c_str(); else if(lookDistance <= 1 && it.description.length()){ s << std::endl << it.description; } } } else s << "an item of type " << id <<"."; return s.str(); }
BlockType_t Creature::blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage, bool checkDefense/* = false*/, bool checkArmor/* = false*/) { BlockType_t blockType = BLOCK_NONE; if(isImmune(combatType)) { damage = 0; blockType = BLOCK_IMMUNITY; } else if(checkDefense || checkArmor) { bool hasDefense = false; if(blockCount > 0) { --blockCount; hasDefense = true; } if(checkDefense && hasDefense) { int32_t maxDefense = getDefense(), minDefense = maxDefense / 2; damage -= random_range(minDefense, maxDefense); if(damage <= 0) { damage = 0; blockType = BLOCK_DEFENSE; checkArmor = false; } } if(checkArmor) { int32_t armorValue = getArmor(), minArmorReduction = 0, maxArmorReduction = 0; if(armorValue > 1) { minArmorReduction = (int32_t)std::ceil(armorValue * 0.475); maxArmorReduction = (int32_t)std::ceil( ((armorValue * 0.475) - 1) + minArmorReduction); } else if(armorValue == 1) { minArmorReduction = 1; maxArmorReduction = 1; } damage -= random_range(minArmorReduction, maxArmorReduction); if(damage <= 0) { damage = 0; blockType = BLOCK_ARMOR; } } if(hasDefense && blockType != BLOCK_NONE) onBlockHit(blockType); } if(attacker) { attacker->onAttackedCreature(this); attacker->onAttackedCreatureBlockHit(this, blockType); } onAttacked(); return blockType; }