void Spell::postCastSpell(Player* player, bool finishedCast /*= true*/, bool payCost /*= true*/) const { if (finishedCast) { if (!player->hasFlag(PlayerFlag_HasNoExhaustion)) { if (cooldown > 0) { Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, cooldown, 0, false, spellId); player->addCondition(condition); } if (groupCooldown > 0) { Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, groupCooldown, 0, false, group); player->addCondition(condition); } if (secondaryGroupCooldown > 0) { Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, secondaryGroupCooldown, 0, false, secondaryGroup); player->addCondition(condition); } } if (aggressive) { player->addInFightTicks(); } } if (payCost) { Spell::postCastSpell(player, getManaCost(player), getSoulCost()); } }
void Weapon::onUsedWeapon(Player* player, Item* item, Tile* destTile) const { if (!player->hasFlag(PlayerFlag_NotGainSkill)) { skills_t skillType; uint32_t skillPoint = 0; if (getSkillType(player, item, skillType, skillPoint)) { player->addSkillAdvance(skillType, skillPoint); } } if (!player->hasFlag(PlayerFlag_HasNoExhaustion) && exhaustion > 0) { player->addWeaponExhaust(exhaustion); } int32_t manaCost = getManaCost(player); if (manaCost > 0) { player->addManaSpent(manaCost); player->changeMana(-manaCost); } if (!player->hasFlag(PlayerFlag_HasInfiniteSoul) && soul > 0) { player->changeSoul(-soul); } }
int32_t Weapon::playerWeaponCheck(Player* player, Creature* target) const { const Position& playerPos = player->getPosition(); const Position& targetPos = target->getPosition(); if (playerPos.z != targetPos.z) { return 0; } int32_t trueRange; const ItemType& it = Item::items[getID()]; if (it.weaponType == WEAPON_AMMO) { trueRange = player->getShootRange(); } else { trueRange = range; } if (std::max<int32_t>(Position::getDistanceX(playerPos, targetPos), Position::getDistanceY(playerPos, targetPos)) > trueRange) { return 0; } if (!player->hasFlag(PlayerFlag_IgnoreWeaponCheck)) { if (!enabled) { return 0; } if (player->getMana() < getManaCost(player)) { return 0; } if (player->getPlayerInfo(PLAYERINFO_SOUL) < soul) { return 0; } if (isPremium() && !player->isPremium()) { return 0; } if (!vocWeaponMap.empty()) { if (vocWeaponMap.find(player->getVocationId()) == vocWeaponMap.end()) { return 0; } } int32_t damageModifier = 100; if (player->getLevel() < getReqLevel()) { damageModifier = (isWieldedUnproperly() ? damageModifier / 2 : 0); } if (player->getMagicLevel() < getReqMagLv()) { damageModifier = (isWieldedUnproperly() ? damageModifier / 2 : 0); } return damageModifier; } return 100; }
void Weapon::onUsedWeapon(Player* player, Item* item, Tile* destTile) const { if (!player->hasFlag(PlayerFlag_NotGainSkill)) { skills_t skillType; uint32_t skillPoint = 0; if (getSkillType(player, item, skillType, skillPoint) && player->getZone() != ZONE_PVP || g_config.getBoolean(ConfigManager::PVPZONE_ADDSKILLS)) { player->addSkillAdvance(skillType, skillPoint); } } if (!player->hasFlag(PlayerFlag_HasNoExhaustion) && exhaustion > 0) { player->addWeaponExhaust(exhaustion); } int32_t manaCost = getManaCost(player); if (manaCost > 0) { player->changeMana(-(int32_t)manaCost); if(player->getZone() != ZONE_PVP || g_config.getBoolean(ConfigManager::PVPZONE_ADDSKILLS)) player->addManaSpent(manaCost); } if (!player->hasFlag(PlayerFlag_HasInfiniteSoul) && soul > 0) { player->changeSoul(-soul); } }
int LifeorManaCost::canPay() { MTGCardInstance * _target = (MTGCardInstance *) target; if (_target->controller()->getManaPool()->canAfford(getManaCost()) || _target->controller()->life > 1) { return 1; } return 0; }
int32_t Weapon::playerWeaponCheck(Player* player, Creature* target, uint8_t shootRange) const { const Position& playerPos = player->getPosition(); const Position& targetPos = target->getPosition(); if (playerPos.z != targetPos.z) { return 0; } if (std::max<uint32_t>(Position::getDistanceX(playerPos, targetPos), Position::getDistanceY(playerPos, targetPos)) > shootRange) { return 0; } if (!player->hasFlag(PlayerFlag_IgnoreWeaponCheck)) { if (!enabled) { return 0; } if (player->getMana() < getManaCost(player)) { return 0; } if (player->getSoul() < soul) { return 0; } if (isPremium() && !player->isPremium()) { return 0; } if (!vocWeaponMap.empty()) { if (vocWeaponMap.find(player->getVocationId()) == vocWeaponMap.end()) { return 0; } } int32_t damageModifier = 100; if (auto chance = g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE)) { if (boolean_random(static_cast<double>(chance) / 100.0)) { damageModifier += g_config.getNumber(ConfigManager::CRITICAL_HIT_EXTRA); std::cout << "Critical hit!" << std::endl; } } if (player->getLevel() < getReqLevel()) { damageModifier = (isWieldedUnproperly() ? damageModifier / 2 : 0); } if (player->getMagicLevel() < getReqMagLv()) { damageModifier = (isWieldedUnproperly() ? damageModifier / 2 : 0); } return damageModifier; } return 100; }
void Weapon::onUsedWeapon(Player* player, Item* item, Tile* destTile) const { if (!player->hasFlag(PlayerFlag_NotGainSkill)) { skills_t skillType; uint32_t skillPoint; if (getSkillType(player, item, skillType, skillPoint)) { player->addSkillAdvance(skillType, skillPoint); } } uint32_t manaCost = getManaCost(player); if (manaCost != 0) { player->addManaSpent(manaCost); player->changeMana(-static_cast<int32_t>(manaCost)); } if (!player->hasFlag(PlayerFlag_HasInfiniteSoul) && soul > 0) { player->changeSoul(-static_cast<int32_t>(soul)); } if (breakChance != 0 && uniform_random(1, 100) <= breakChance) { decrementItemCount(item); return; } switch (action) { case WEAPONACTION_REMOVECOUNT: decrementItemCount(item); break; case WEAPONACTION_REMOVECHARGE: { uint16_t charges = item->getCharges(); if (charges > 1) { g_game.transformItem(item, item->getID(), charges - 1); } else { g_game.internalRemoveItem(item); } break; } case WEAPONACTION_MOVE: g_game.internalMoveItem(item->getParent(), destTile, INDEX_WHEREEVER, item, 1, nullptr, FLAG_NOLIMIT); break; default: break; } }
int32_t Weapon::playerWeaponCheck(Player* player, Creature* target, uint8_t shootRange) const { const Position& playerPos = player->getPosition(); const Position& targetPos = target->getPosition(); if (playerPos.z != targetPos.z) { return 0; } if (std::max<uint32_t>(Position::getDistanceX(playerPos, targetPos), Position::getDistanceY(playerPos, targetPos)) > shootRange) { return 0; } if (!player->hasFlag(PlayerFlag_IgnoreWeaponCheck)) { if (!enabled) { return 0; } if (player->getMana() < getManaCost(player)) { return 0; } if (player->getSoul() < soul) { return 0; } if (isPremium() && !player->isPremium()) { return 0; } if (!vocWeaponMap.empty()) { if (vocWeaponMap.find(player->getVocationId()) == vocWeaponMap.end()) { return 0; } } int32_t damageModifier = 100; if (player->getLevel() < getReqLevel()) { damageModifier = (isWieldedUnproperly() ? damageModifier / 2 : 0); } if (player->getMagicLevel() < getReqMagLv()) { damageModifier = (isWieldedUnproperly() ? damageModifier / 2 : 0); } return damageModifier; } return 100; }
bool Spell::playerSpellCheck(Player* player) const { if (player->hasFlag(PlayerFlag_CannotUseSpells)) { return false; } if (player->hasFlag(PlayerFlag_IgnoreSpellCheck)) { return true; } if (!enabled) { return false; } if (aggressive && (range < 1 || (range > 0 && !player->getAttackedCreature())) && player->getSkull() == SKULL_BLACK) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return false; } if (aggressive && player->hasCondition(CONDITION_PACIFIED)) { player->sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED); g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF); return false; } if (aggressive && !player->hasFlag(PlayerFlag_IgnoreProtectionZone) && player->getZone() == ZONE_PROTECTION) { player->sendCancelMessage(RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE); return false; } if (player->hasCondition(CONDITION_SPELLGROUPCOOLDOWN, group) || player->hasCondition(CONDITION_SPELLCOOLDOWN, spellId) || (secondaryGroup != SPELLGROUP_NONE && player->hasCondition(CONDITION_SPELLGROUPCOOLDOWN, secondaryGroup))) { player->sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED); if (isInstant()) { g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF); } return false; } if (player->getLevel() < level) { player->sendCancelMessage(RETURNVALUE_NOTENOUGHLEVEL); g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF); return false; } if (player->getMagicLevel() < magLevel) { player->sendCancelMessage(RETURNVALUE_NOTENOUGHMAGICLEVEL); g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF); return false; } if (player->getMana() < getManaCost(player) && !player->hasFlag(PlayerFlag_HasInfiniteMana)) { player->sendCancelMessage(RETURNVALUE_NOTENOUGHMANA); g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF); return false; } if (player->getSoul() < soul && !player->hasFlag(PlayerFlag_HasInfiniteSoul)) { player->sendCancelMessage(RETURNVALUE_NOTENOUGHSOUL); g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF); return false; } if (isInstant() && isLearnable()) { if (!player->hasLearnedInstantSpell(getName())) { player->sendCancelMessage(RETURNVALUE_YOUNEEDTOLEARNTHISSPELL); g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF); return false; } } else if (!vocSpellMap.empty() && vocSpellMap.find(player->getVocationId()) == vocSpellMap.end()) { player->sendCancelMessage(RETURNVALUE_YOURVOCATIONCANNOTUSETHISSPELL); g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF); return false; } if (needWeapon) { switch (player->getWeaponType()) { case WEAPON_SWORD: case WEAPON_CLUB: case WEAPON_AXE: break; default: { player->sendCancelMessage(RETURNVALUE_YOUNEEDAWEAPONTOUSETHISSPELL); g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF); return false; } } } if (isPremium() && !player->isPremium()) { player->sendCancelMessage(RETURNVALUE_YOUNEEDPREMIUMACCOUNT); g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF); return false; } return true; }