Skip to content

Commit

Permalink
[Fix] Few prey/task hunting fixes and improvements (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosvf132 committed Jun 11, 2022
1 parent 116cc9e commit b1786d5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
31 changes: 19 additions & 12 deletions src/io/ioprey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ PreySlot::PreySlot(PreySlot_t id) :
eraseBonus();
reloadBonusValue();
reloadBonusType();
freeRerollTimeStamp = OTSYS_TIME() + g_configManager().getNumber(PREY_FREE_REROLL_TIME) * 1000;
}

void PreySlot::reloadBonusType()
{
if (bonusRarity == 10) {
PreyBonus_t bonus_tmp = bonus;
while (bonus_tmp == bonus) {
bonus = static_cast<PreyBonus_t>(normal_random(PreyBonus_First, PreyBonus_Last));
bonus = static_cast<PreyBonus_t>(uniform_random(PreyBonus_First, PreyBonus_Last));
}
return;
}

bonus = static_cast<PreyBonus_t>(normal_random(PreyBonus_First, PreyBonus_Last));
bonus = static_cast<PreyBonus_t>(uniform_random(PreyBonus_First, PreyBonus_Last));
}

void PreySlot::reloadBonusValue()
Expand All @@ -55,7 +56,7 @@ void PreySlot::reloadBonusValue()
if (bonusRarity >= 9) {
bonusRarity = 10;
} else {
bonusRarity = static_cast<uint8_t>(normal_random(bonusRarity + 1, 10));
bonusRarity = static_cast<uint8_t>(uniform_random(bonusRarity + 1, 10));
}

bonusPercentage = stagePercent * bonusRarity;
Expand Down Expand Up @@ -112,7 +113,7 @@ void PreySlot::reloadMonsterGrid(std::vector<uint16_t> blackList, uint32_t level
uint8_t tries = 0;
auto maxIndex = static_cast<int32_t>(bestiary.size() - 1);
while (raceIdList.size() < 9) {
uint16_t raceId = (*(std::next(bestiary.begin(), normal_random(0, maxIndex)))).first;
uint16_t raceId = (*(std::next(bestiary.begin(), uniform_random(0, maxIndex)))).first;
tries++;

if (std::count(blackList.begin(), blackList.end(), raceId) != 0) {
Expand Down Expand Up @@ -143,6 +144,11 @@ void PreySlot::reloadMonsterGrid(std::vector<uint16_t> blackList, uint32_t level
}

// Task hunting class
TaskHuntingSlot::TaskHuntingSlot(PreySlot_t id) :
id(id) {
freeRerollTimeStamp = OTSYS_TIME() + g_configManager().getNumber(TASK_HUNTING_FREE_REROLL_TIME) * 1000;
}

void TaskHuntingSlot::reloadMonsterGrid(std::vector<uint16_t> blackList, uint32_t level)
{
raceIdList.clear();
Expand Down Expand Up @@ -189,7 +195,7 @@ void TaskHuntingSlot::reloadMonsterGrid(std::vector<uint16_t> blackList, uint32_
uint8_t tries = 0;
auto maxIndex = static_cast<int32_t>(bestiary.size() - 1);
while (raceIdList.size() < 9) {
uint16_t raceId = (*(std::next(bestiary.begin(), normal_random(0, maxIndex)))).first;
uint16_t raceId = (*(std::next(bestiary.begin(), uniform_random(0, maxIndex)))).first;
tries++;

if (std::count(blackList.begin(), blackList.end(), raceId) != 0) {
Expand Down Expand Up @@ -232,13 +238,13 @@ void TaskHuntingSlot::reloadReward()

int32_t chance;
if (rarity == 0) {
chance = normal_random(0, 100);
chance = uniform_random(0, 100);
} else if (rarity == 1) {
chance = normal_random(0, 70);
chance = uniform_random(0, 70);
} else if (rarity == 2) {
chance = normal_random(0, 45);
chance = uniform_random(0, 45);
} else if (rarity == 3) {
chance = normal_random(0, 20);
chance = uniform_random(0, 20);
} else {
return;
}
Expand Down Expand Up @@ -292,7 +298,6 @@ void IOPrey::CheckPlayerPreys(Player* player, uint8_t amount) const
}

slot->eraseBonus();
slot->state = PreyDataState_Inactive;
player->reloadPreySlot(static_cast<PreySlot_t>(slotId));
} else {
slot->bonusTimeLeft -= amount;
Expand Down Expand Up @@ -324,7 +329,9 @@ void IOPrey::ParsePreyAction(Player* player,
}

slot->eraseBonus(true);
slot->state = PreyDataState_Selection;
if (slot->bonus != PreyBonus_None) {
slot->state = PreyDataState_SelectionChangeMonster;
}
slot->reloadMonsterGrid(player->getPreyBlackList(), player->getLevel());
} else if (action == PreyAction_ListAll_Cards) {
if (!player->usePreyCards(static_cast<uint16_t>(g_configManager().getNumber(PREY_SELECTION_LIST_PRICE)))) {
Expand Down Expand Up @@ -500,7 +507,7 @@ void IOPrey::ParseTaskHuntingAction(Player* player,

if (const TaskHuntingOption* option = GetTaskRewardOption(slot)) {
uint16_t reward;
int32_t boostChange = normal_random(0, 100);
int32_t boostChange = uniform_random(0, 100);
if (slot->rarity >= 4 && boostChange <= 5) {
boostChange = 20;
} else if (slot->rarity >= 4 && boostChange <= 10) {
Expand Down
4 changes: 2 additions & 2 deletions src/io/ioprey.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class PreySlot
}

bool canSelect() const {
return (state == PreyDataState_Selection || state == PreyDataState_ListSelection || state == PreyDataState_Inactive);
return (state == PreyDataState_Selection || state == PreyDataState_SelectionChangeMonster || state == PreyDataState_ListSelection || state == PreyDataState_Inactive);
}

void eraseBonus(bool maintainBonus = false) {
Expand Down Expand Up @@ -156,7 +156,7 @@ class TaskHuntingSlot
{
public:
TaskHuntingSlot() = default;
explicit TaskHuntingSlot(PreySlot_t id) : id(id) { }
explicit TaskHuntingSlot(PreySlot_t id);
virtual ~TaskHuntingSlot() = default;

bool isOccupied() const {
Expand Down
2 changes: 1 addition & 1 deletion src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6260,7 +6260,7 @@ void ProtocolGame::sendPreyData(const PreySlot* slot)
msg.addByte(static_cast<uint8_t>(slot->bonus));
msg.add<uint16_t>(slot->bonusPercentage);
msg.addByte(slot->bonusRarity);
msg.add<uint16_t>(static_cast<uint16_t>(slot->raceIdList.size()));
msg.addByte(static_cast<uint8_t>(slot->raceIdList.size()));
std::for_each(slot->raceIdList.begin(), slot->raceIdList.end(), [&msg](uint16_t raceId)
{
if (const MonsterType* mtype = g_monsters().getMonsterTypeByRaceId(raceId)) {
Expand Down

0 comments on commit b1786d5

Please sign in to comment.