Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
omeranha committed Apr 30, 2022
1 parent e06dd7f commit 844f374
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 27 deletions.
34 changes: 26 additions & 8 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,14 +838,16 @@ void Combat::CombatFunc(Creature* caster, const Position& pos, const AreaCombat*
}
//
CombatDamage tmpDamage;
if(data) {
tmpDamage.origin = data->origin;
tmpDamage.primary.type = data->primary.type;
tmpDamage.primary.value = data->primary.value;
tmpDamage.secondary.type = data->secondary.type;
tmpDamage.secondary.value = data->secondary.value;
tmpDamage.critical = data->critical;
}
if (data) {
tmpDamage.origin = data->origin;
tmpDamage.primary.type = data->primary.type;
tmpDamage.primary.value = data->primary.value;
tmpDamage.secondary.type = data->secondary.type;
tmpDamage.secondary.value = data->secondary.value;
tmpDamage.critical = data->critical;
tmpDamage.fatal = data->fatal;
}

tmpDamage.affected = affected;
for (Tile* tile : tileList) {
if (canDoCombat(caster, tile, params.aggressive) != RETURNVALUE_NOERROR) {
Expand Down Expand Up @@ -919,6 +921,14 @@ void Combat::doCombatHealth(Creature* caster, Creature* target, CombatDamage& da
damage.primary.value += (damage.primary.value * caster->getPlayer()->getSkillLevel(SKILL_CRITICAL_HIT_DAMAGE ))/100;
damage.secondary.value += (damage.secondary.value * caster->getPlayer()->getSkillLevel(SKILL_CRITICAL_HIT_DAMAGE ))/100;
}

// fatal hit (onslaught)
double_t fatalChance = caster->getPlayer()->getFatalChance();
if (fatalChance > 0 && uniform_random(1, 100) <= fatalChance) {
damage.fatal = true;
damage.primary.value += (damage.primary.value * 0.6);
damage.secondary.value += (damage.secondary.value * 0.6);
}
}
if (canCombat) {
if (target && caster && params.distanceEffect != CONST_ANI_NONE) {
Expand All @@ -942,6 +952,14 @@ void Combat::doCombatHealth(Creature* caster, const Position& position, const Ar
damage.primary.value += (damage.primary.value * caster->getPlayer()->getSkillLevel(SKILL_CRITICAL_HIT_DAMAGE ))/100;
damage.secondary.value += (damage.secondary.value * caster->getPlayer()->getSkillLevel(SKILL_CRITICAL_HIT_DAMAGE ))/100;
}

// fatal hit (onslaught)
double_t fatalChance = caster->getPlayer()->getFatalChance();
if (damage.primary.type != COMBAT_HEALING && fatalChance > 0 && uniform_random(1, 100) <= fatalChance) {
damage.fatal = true;
damage.primary.value += (damage.primary.value * 0.6);
damage.secondary.value += (damage.secondary.value * 0.6);
}
}
CombatFunc(caster, position, area, params, CombatHealthFunc, &damage);
}
Expand Down
5 changes: 4 additions & 1 deletion src/creatures/creatures_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ enum BlockType_t : uint8_t {
BLOCK_NONE,
BLOCK_DEFENSE,
BLOCK_ARMOR,
BLOCK_IMMUNITY
BLOCK_IMMUNITY,
BLOCK_DODGE
};

enum BestiaryType_t : uint8_t {
Expand Down Expand Up @@ -756,6 +757,7 @@ struct CombatDamage {
int affected;
bool extension;
std::string exString;
bool fatal;

CombatDamage() {
origin = ORIGIN_NONE;
Expand All @@ -765,6 +767,7 @@ struct CombatDamage {
affected = 1;
extension = false;
exString = "";
fatal = false;
}
};

Expand Down
28 changes: 28 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,34 @@ void Player::onThink(uint32_t interval)
addMessageBuffer();
}

// momentum(cooldown resets), checks and eligibility (chance to trigger every 2 seconds)
if (getZone() != ZONE_PROTECTION && hasCondition(CONDITION_INFIGHT) && ((OTSYS_TIME()/1000) % 2) == 0 && getMomentumChance() > 0 && uniform_random(1, 100) <= getMomentumChance()) {
bool triggered = false;
auto it = conditions.begin(), end = conditions.end();
while (it != end) {
if ((*it)->getEndTime() >= OTSYS_TIME()) {
ConditionType_t type = (*it)->getType();
uint32_t spellId = (*it)->getSubId();
int32_t ticks = (*it)->getTicks();
int32_t newTicks = (ticks <= 2000) ? 0 : 2000;
if (type == CONDITION_SPELLCOOLDOWN || (type == CONDITION_SPELLGROUPCOOLDOWN && spellId > SPELLGROUP_SUPPORT)) {
(*it)->setTicks(newTicks);
if (type == CONDITION_SPELLGROUPCOOLDOWN) {
sendSpellGroupCooldown(static_cast<SpellGroup_t>(spellId), newTicks);
} else {
sendSpellCooldown(spellId, newTicks);
}
triggered = true;
}
}
++it;
}
if (triggered) {
g_game().addMagicEffect(getPosition(), CONST_ME_HOURGLASS);
sendTextMessage(MESSAGE_ATTENTION, "Momentum was triggered.");
}
}

if (!getTile()->hasFlag(TILESTATE_NOLOGOUT) && !isAccessPlayer() && !isExerciseTraining()) {
idleTime += interval;
const int32_t kickAfterMinutes = g_configManager().getNumber(KICK_AFTER_MINUTES);
Expand Down
23 changes: 23 additions & 0 deletions src/creatures/players/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,29 @@ class Player final : public Creature, public Cylinder
return nullptr;
}

double_t getDodgeChance() const {
Item* item = inventory[CONST_SLOT_ARMOR];
if (!item) {
return 0;
}
return (*dodgeChance.find(static_cast<Tiers_t>(item->getTier()))).second;
}

double_t getFatalChance() const {
Item* item = inventory[CONST_SLOT_LEFT];
if (!item) {
return 0;
}
return (*fatalChance.find(static_cast<Tiers_t>(item->getTier()))).second;
}

double_t getMomentumChance() const {
Item* item = inventory[CONST_SLOT_HEAD];
if (!item) {
return 0;
}
return (*momentumChance.find(static_cast<Tiers_t>(item->getTier()))).second;
}

private:
std::forward_list<Condition*> getMuteConditions() const;
Expand Down
12 changes: 12 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5540,6 +5540,8 @@ bool Game::combatBlockHit(CombatDamage& damage, Creature* attacker, Creature* ta
addMagicEffect(targetPos, CONST_ME_POFF);
} else if (blockType == BLOCK_ARMOR) {
addMagicEffect(targetPos, CONST_ME_BLOCKHIT);
} else if (blockType == BLOCK_ARMOR) {
addMagicEffect(targetPos, CONST_ME_DODGE);
} else if (blockType == BLOCK_IMMUNITY) {
uint8_t hitEffect = 0;
switch (combatType) {
Expand Down Expand Up @@ -5571,6 +5573,16 @@ bool Game::combatBlockHit(CombatDamage& damage, Creature* attacker, Creature* ta
}
};

// dodge (ruse)
if (Player* targetPlayer = target->getPlayer()) {
double_t chance = targetPlayer->getDodgeChance();
if (chance > 0 && uniform_random(1, 100) <= chance) {
sendBlockEffect(BLOCK_DODGE, damage.primary.type, target->getPosition());
targetPlayer->sendTextMessage(MESSAGE_ATTENTION, "You dodged an attack. (Ruse)");
return true;
}
}

bool canHeal = false;
CombatDamage damageHeal;
damageHeal.primary.type = COMBAT_HEALING;
Expand Down
19 changes: 19 additions & 0 deletions src/items/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,16 @@ Attr_ReadValue Item::readAttr(AttrTypes_t attr, PropStream& propStream)
break;
}

case ATTR_TIER: {
uint8_t tier;
if (!propStream.read<uint8_t>(tier)) {
return ATTR_READ_ERROR;
}

setIntAttr(ITEM_ATTRIBUTE_TIER, tier);
break;
}

default:
return ATTR_READ_ERROR;
}
Expand Down Expand Up @@ -943,6 +953,11 @@ void Item::serializeAttr(PropWriteStream& propWriteStream) const
propWriteStream.write<uint8_t>(ATTR_IMBUEMENT_TYPE);
propWriteStream.writeString(getStrAttr(ITEM_ATTRIBUTE_IMBUEMENT_TYPE));
}

if (hasAttribute(ITEM_ATTRIBUTE_TIER)) {
propWriteStream.write<uint8_t>(ATTR_TIER);
propWriteStream.write<uint8_t>(getTier());
}
}

bool Item::hasProperty(ItemProperty prop) const
Expand Down Expand Up @@ -2286,6 +2301,10 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance,

s << parseImbuementDescription(item);

if (uint16_t classification = item->getClassification(); classification > 1) {
s << std::endl << "Classification: " << classification << " Tier: " << item->getTier() << ".";
}

if (lookDistance <= 1) {
if (item) {
const uint32_t weight = item->getWeight();
Expand Down
16 changes: 16 additions & 0 deletions src/items/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ class ItemAttributes
checkTypes |= ITEM_ATTRIBUTE_OPENCONTAINER;
checkTypes |= ITEM_ATTRIBUTE_QUICKLOOTCONTAINER;
checkTypes |= ITEM_ATTRIBUTE_DURATION_TIMESTAMP;
checkTypes |= ITEM_ATTRIBUTE_TIER;
return (type & static_cast<ItemAttrTypes>(checkTypes)) != 0;
}
static bool isStrAttrType(ItemAttrTypes type) {
Expand Down Expand Up @@ -1096,6 +1097,21 @@ class Item : virtual public Thing
return false;
}

uint16_t getTier() const {
if (hasAttribute(ITEM_ATTRIBUTE_TIER)) {
return getIntAttr(ITEM_ATTRIBUTE_TIER);
}
return 0;
}
void addTier(uint8_t tier) {
if (items[id].upgradeClassification) {
setIntAttr(ITEM_ATTRIBUTE_TIER, tier);
}
}
uint16_t getClassification() const {
return items[id].upgradeClassification;
}

protected:
std::string getWeightDescription(uint32_t weight) const;

Expand Down
5 changes: 4 additions & 1 deletion src/items/items_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ enum AttrTypes_t {
ATTR_OPENCONTAINER = 36,
ATTR_CUSTOM_ATTRIBUTES = 37,
ATTR_QUICKLOOTCONTAINER = 38,
ATTR_IMBUEMENT_TYPE = 39
ATTR_IMBUEMENT_TYPE = 39,
ATTR_TIER = 40
};

enum ImbuementTypes_t : int64_t {
Expand Down Expand Up @@ -316,6 +317,8 @@ enum ItemAttrTypes : uint32_t {
ITEM_ATTRIBUTE_QUICKLOOTCONTAINER = 1 << 26,
ITEM_ATTRIBUTE_DURATION_TIMESTAMP = 1 << 27,
ITEM_ATTRIBUTE_IMBUEMENT_TYPE = 1 << 28,
ITEM_ATTRIBUTE_TIER = 1 << 29,

ITEM_ATTRIBUTE_CUSTOM = 1U << 31
};

Expand Down
28 changes: 28 additions & 0 deletions src/lua/functions/items/item_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,3 +799,31 @@ int ItemFunctions::luaItemGetImbuementSlot(lua_State* L) {
lua_pushnumber(L, item->getImbuementSlot());
return 1;
}

int ItemFunctions::luaItemGetTier(lua_State* L) {
// item:getTier()
Item* item = getUserdata<Item>(L, 1);
if (!item) {
reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

item->getTier();
pushBoolean(L, true);
return 1;
}

int ItemFunctions::luaItemAddTier(lua_State* L) {
// item:addTier(tier)
Item* item = getUserdata<Item>(L, 1);
if (!item) {
reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

item->addTier(getNumber<uint8_t>(L, 2));
pushBoolean(L, true);
return 1;
}
6 changes: 6 additions & 0 deletions src/lua/functions/items/item_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class ItemFunctions final : LuaScriptInterface {
registerMethod(L, "Item", "getImbuementSlot", ItemFunctions::luaItemGetImbuementSlot);
registerMethod(L, "Item", "getImbuement", ItemFunctions::luaItemGetImbuement);

registerMethod(L, "Item", "getTier", ItemFunctions::luaItemGetTier);
registerMethod(L, "Item", "addTier", ItemFunctions::luaItemAddTier);

ContainerFunctions::init(L);
ImbuementFunctions::init(L);
ItemTypeFunctions::init(L);
Expand Down Expand Up @@ -144,6 +147,9 @@ class ItemFunctions final : LuaScriptInterface {

static int luaItemGetImbuementSlot(lua_State* L);
static int luaItemGetImbuement(lua_State* L);

static int luaItemGetTier(lua_State* L);
static int luaItemAddTier(lua_State* L);
};

#endif // SRC_LUA_FUNCTIONS_ITEMS_ITEM_FUNCTIONS_HPP_
Loading

0 comments on commit 844f374

Please sign in to comment.