Skip to content

Commit

Permalink
fix: conditions speed (#876)
Browse files Browse the repository at this point in the history
  • Loading branch information
beats-dh authored Dec 9, 2023
1 parent bfe193a commit 890db68
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion data-canary/scripts/runes/paralyze_rune.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_UNDEFINEDDAMAGE)

local condition = Condition(CONDITION_PARALYZE)
condition:setParameter(CONDITION_PARAM_TICKS, 6000)
condition:setFormula(-1, 81, -1, 81)
condition:setFormula(-1, 0, -1, 0)
combat:addCondition(condition)

local rune = Spell("rune")
Expand Down
2 changes: 1 addition & 1 deletion data-canary/scripts/spells/support/charge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_HASTE)
condition:setParameter(CONDITION_PARAM_TICKS, 5000)
condition:setFormula(0.9, -72, 0.9, -72)
condition:setFormula(1.9, 40, 1.9, 40)
combat:addCondition(condition)

local spell = Spell("instant")
Expand Down
2 changes: 1 addition & 1 deletion data-canary/scripts/spells/support/haste.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_HASTE)
condition:setParameter(CONDITION_PARAM_TICKS, 33000)
condition:setFormula(0.3, -24, 0.3, -24)
condition:setFormula(1.3, 40, 1.3, 40)
combat:addCondition(condition)

local spell = Spell("instant")
Expand Down
2 changes: 1 addition & 1 deletion data-canary/scripts/spells/support/sharpshooter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ combat:addCondition(skill)

local speed = Condition(CONDITION_PARALYZE)
speed:setParameter(CONDITION_PARAM_TICKS, 10000)
speed:setFormula(-0.7, 56, -0.7, 56)
speed:setFormula(-0.73, 0, -0.73, 0)
combat:addCondition(speed)

local exhaustHealGroup = Condition(CONDITION_SPELLGROUPCOOLDOWN)
Expand Down
2 changes: 1 addition & 1 deletion data-canary/scripts/spells/support/strong_haste.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_HASTE)
condition:setParameter(CONDITION_PARAM_TICKS, 21000)
condition:setFormula(0.7, -0, 0.7, -0)
condition:setFormula(1.7, 40, 1.7, 40)
combat:addCondition(condition)

local spell = Spell("instant")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_UNDEFINEDDAMAGE)

local condition = Condition(CONDITION_PARALYZE)
condition:setParameter(CONDITION_PARAM_TICKS, 6000)
condition:setFormula(-1, 81, -1, 81)
condition:setFormula(-1, 0, -1, 0)
combat:addCondition(condition)

local rune = Spell("rune")
Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/scripts/spells/support/charge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_HASTE)
condition:setParameter(CONDITION_PARAM_TICKS, 5000)
condition:setFormula(0.9, -0, 0.9, -0)
condition:setFormula(1.9, 40, 1.9, 40)
combat:addCondition(condition)

local spell = Spell("instant")
Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/scripts/spells/support/haste.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_HASTE)
condition:setParameter(CONDITION_PARAM_TICKS, 30000)
condition:setFormula(0.3, -0, 0.3, -0)
condition:setFormula(1.3, 40, 1.3, 40)
combat:addCondition(condition)

local spell = Spell("instant")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_HASTE)
condition:setParameter(CONDITION_PARAM_TICKS, 22000)
condition:setFormula(0.7, -56, 0.7, -56)
condition:setFormula(1.7, 40, 1.7, 40)
combat:addCondition(condition)

local spell = Spell("instant")
Expand Down
32 changes: 26 additions & 6 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2085,8 +2085,9 @@ void ConditionSpeed::setFormulaVars(float NewMina, float NewMinb, float NewMaxa,
}

void ConditionSpeed::getFormulaValues(int32_t var, int32_t &min, int32_t &max) const {
min = (var * mina) + minb;
max = (var * maxa) + maxb;
int32_t difference = var - 40;
min = mina * difference + minb;
max = maxa * difference + maxb;
}

bool ConditionSpeed::setParam(ConditionParam_t param, int32_t value) {
Expand Down Expand Up @@ -2145,9 +2146,19 @@ bool ConditionSpeed::startCondition(std::shared_ptr<Creature> creature) {
}

if (speedDelta == 0) {
int32_t min, max;
getFormulaValues(creature->getBaseSpeed(), min, max);
int32_t min;
int32_t max;
auto baseSpeed = creature->getBaseSpeed();
getFormulaValues(baseSpeed, min, max);
speedDelta = uniform_random(min, max);

if (conditionType == CONDITION_HASTE) {
speedDelta = speedDelta - baseSpeed;
}

if (conditionType == CONDITION_PARALYZE && speedDelta < baseSpeed - 40) {
speedDelta = 40 - baseSpeed;
}
}

g_game().changeSpeed(creature, speedDelta);
Expand All @@ -2173,7 +2184,7 @@ void ConditionSpeed::addCondition(std::shared_ptr<Creature> creature, const std:

setTicks(addCondition->getTicks());

const std::shared_ptr<ConditionSpeed> &conditionSpeed = addCondition->static_self_cast<ConditionSpeed>();
const auto &conditionSpeed = addCondition->static_self_cast<ConditionSpeed>();
int32_t oldSpeedDelta = speedDelta;
speedDelta = conditionSpeed->speedDelta;
mina = conditionSpeed->mina;
Expand All @@ -2184,8 +2195,17 @@ void ConditionSpeed::addCondition(std::shared_ptr<Creature> creature, const std:
if (speedDelta == 0) {
int32_t min;
int32_t max;
getFormulaValues(creature->getBaseSpeed(), min, max);
auto baseSpeed = creature->getBaseSpeed();
getFormulaValues(baseSpeed, min, max);
speedDelta = uniform_random(min, max);

if (conditionType == CONDITION_HASTE) {
speedDelta = speedDelta - baseSpeed;
}

if (conditionType == CONDITION_PARALYZE && speedDelta < baseSpeed - 40) {
speedDelta = 40 - baseSpeed;
}
}

int32_t newSpeedChange = (speedDelta - oldSpeedDelta);
Expand Down
6 changes: 5 additions & 1 deletion src/creatures/monsters/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ bool Monsters::deserializeSpell(const std::shared_ptr<MonsterSpell> spell, spell
combatPtr->setParam(COMBAT_PARAM_TYPE, spell->combatType);
} else if (spellName == "speed") {
int32_t speedChange = 0;
int32_t speedChangeValue = 0;
int32_t speedChangeRange = 0;
int32_t duration = 10000;

if (spell->duration != 0) {
Expand All @@ -144,7 +146,9 @@ bool Monsters::deserializeSpell(const std::shared_ptr<MonsterSpell> spell, spell
}

std::shared_ptr<ConditionSpeed> condition = Condition::createCondition(CONDITIONID_COMBAT, conditionType, duration, 0)->static_self_cast<ConditionSpeed>();
condition->setFormulaVars(speedChange / 1000.0, 0, speedChange / 1000.0, 0);
speedChangeRange = speedChange / 2;
speedChangeValue = uniform_random(speedChangeRange, speedChange);
condition->setFormulaVars(speedChangeValue / 1000.0, 40, speedChangeValue / 1000.0, 40);
combatPtr->addCondition(condition);
} else if (spellName == "outfit") {
int32_t duration = 10000;
Expand Down
6 changes: 3 additions & 3 deletions src/io/iobestiary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool IOBestiary::parseCharmCombat(const std::shared_ptr<Charm> charm, std::share
if (charm->type == CHARM_OFFENSIVE) {
if (charm->id == CHARM_CRIPPLE) {
std::shared_ptr<ConditionSpeed> cripple = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_PARALYZE, 10000, 0)->static_self_cast<ConditionSpeed>();
cripple->setFormulaVars(-1, 81, -1, 81);
cripple->setFormulaVars(-1, 0, -1, 0);
target->addCondition(cripple);
player->sendCancelMessage(charm->cancelMsg);
return false;
Expand Down Expand Up @@ -71,14 +71,14 @@ bool IOBestiary::parseCharmCombat(const std::shared_ptr<Charm> charm, std::share
}
case CHARM_ADRENALINE: {
std::shared_ptr<ConditionSpeed> adrenaline = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_HASTE, 10000, 0)->static_self_cast<ConditionSpeed>();
adrenaline->setFormulaVars(1.5, -0, 1.5, -0);
adrenaline->setFormulaVars(2.5, 40, 2.5, 40);
player->addCondition(adrenaline);
player->sendCancelMessage(charm->cancelMsg);
return false;
}
case CHARM_NUMB: {
std::shared_ptr<ConditionSpeed> numb = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_PARALYZE, 10000, 0)->static_self_cast<ConditionSpeed>();
numb->setFormulaVars(-1, 81, -1, 81);
numb->setFormulaVars(-1, 0, -1, 0);
target->addCondition(numb);
player->sendCancelMessage(charm->cancelMsg);
return false;
Expand Down

0 comments on commit 890db68

Please sign in to comment.