Corrections from code review

This commit is contained in:
Atemo 2023-06-13 17:21:23 +02:00
parent 480cf26283
commit 86fcc98081
7 changed files with 62 additions and 118 deletions

View File

@ -51,4 +51,3 @@ Header:
Footer: Footer:
Imports: Imports:
- Path: db/pre-re/skill_produce_db.yml - Path: db/pre-re/skill_produce_db.yml
- Path: db/pre-re/skill_changematerial_db.yml

View File

@ -1,45 +0,0 @@
# This file is a part of rAthena.
# Copyright(C) 2022 rAthena Development Team
# https://rathena.org - https://github.com/rathena
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###########################################################################
# Item Produce Database
###########################################################################
#
# Item Produce Settings
#
###########################################################################
# - ItemLevel Number which determines what kind of a crafting window will pop-up.
# Recipe:
# - Product AegisName of the produced item.
# SkillName Skill name required. (Default: null)
# SkillLevel Skill level required. (Default: 1)
# Consumed: List of items consumed to produce the Product.
# - Item AegisName of the consumed item.
# Amount Amount required.
# Clear Remove the item with the given AegisName from Consumed. (Optional)
# NotConsumed: List of items not consumed to produce the Product. (Default: null)
# - Item AegisName of the unconsumed item.
# Clear Remove the item with the given AegisName from NotConsumed. (Optional)
# BaseRate Base rate (in n/10%). (Default: 1000)
# Make: List of item amounts with their individual rate produced by Change Material. (Default: null)
# - Amount Amount of item created (unique to the list).
# Rate Rate to create the Amount (in n/10%). Default: 1000. 0 to remove on import.
###########################################################################
Header:
Type: PRODUCE_DB
Version: 1

View File

@ -1,5 +1,5 @@
# This file is a part of rAthena. # This file is a part of rAthena.
# Copyright(C) 2022 rAthena Development Team # Copyright(C) 2023 rAthena Development Team
# https://rathena.org - https://github.com/rathena # https://rathena.org - https://github.com/rathena
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify

View File

@ -1645,7 +1645,7 @@ Body:
Amount: 1 Amount: 1
NotConsumed: NotConsumed:
- Item: Normal_Potion_Book - Item: Normal_Potion_Book
- Product: aegis_100371 - Product: Homun_F_Tablet
SkillName: AM_PHARMACY SkillName: AM_PHARMACY
SkillLevel: 1 SkillLevel: 1
Consumed: Consumed:
@ -1663,34 +1663,34 @@ Body:
SkillName: SA_CREATECON SkillName: SA_CREATECON
SkillLevel: 1 SkillLevel: 1
Consumed: Consumed:
- Item: Scorpion's_Tail - Item: Boody_Red
Amount: 3 Amount: 1
- Item: Scroll - Item: Scroll
Amount: 1 Amount: 1
- Product: Elemental_Water - Product: Elemental_Water
SkillName: SA_CREATECON SkillName: SA_CREATECON
SkillLevel: 1 SkillLevel: 1
Consumed: Consumed:
- Item: Crystal_Blue
Amount: 1
- Item: Scroll - Item: Scroll
Amount: 1 Amount: 1
- Item: Snail's_Shell
Amount: 3
- Product: Elemental_Earth - Product: Elemental_Earth
SkillName: SA_CREATECON SkillName: SA_CREATECON
SkillLevel: 1 SkillLevel: 1
Consumed: Consumed:
- Item: Horn
Amount: 3
- Item: Scroll - Item: Scroll
Amount: 1 Amount: 1
- Item: Wind_Of_Verdure
Amount: 1
- Product: Elemental_Wind - Product: Elemental_Wind
SkillName: SA_CREATECON SkillName: SA_CREATECON
SkillLevel: 1 SkillLevel: 1
Consumed: Consumed:
- Item: Colorful_Shell
Amount: 3
- Item: Scroll - Item: Scroll
Amount: 1 Amount: 1
- Item: Yellow_Live
Amount: 1
- ItemLevel: 24 - ItemLevel: 24
Recipe: Recipe:
- Product: Ansila - Product: Ansila
@ -2203,18 +2203,18 @@ Body:
Amount: 10 Amount: 10
- Item: Empty_Potion - Item: Empty_Potion
Amount: 5 Amount: 5
- Item: Red_Syrup - Item: High_RedPotion
Amount: 15 Amount: 15
- Product: Concentrated_B_P - Product: Concentrated_B_P
SkillName: GN_S_PHARMACY SkillName: GN_S_PHARMACY
SkillLevel: 1 SkillLevel: 1
Consumed: Consumed:
- Item: Blue_Syrup
Amount: 15
- Item: Empty_Cylinder - Item: Empty_Cylinder
Amount: 10 Amount: 10
- Item: Empty_Potion - Item: Empty_Potion
Amount: 5 Amount: 5
- Item: High_BluePotion
Amount: 15
- Product: Concentrated_G_P - Product: Concentrated_G_P
SkillName: GN_S_PHARMACY SkillName: GN_S_PHARMACY
SkillLevel: 1 SkillLevel: 1
@ -2223,9 +2223,9 @@ Body:
Amount: 10 Amount: 10
- Item: Empty_Potion - Item: Empty_Potion
Amount: 5 Amount: 5
- Item: White_Syrup - Item: High_WhitePotion
Amount: 10 Amount: 10
- Item: Yellow_Syrup - Item: High_YelloPotion
Amount: 10 Amount: 10
- ItemLevel: 30 - ItemLevel: 30
Recipe: Recipe:
@ -2336,7 +2336,7 @@ Body:
- Item: Portable_Furnace - Item: Portable_Furnace
Amount: 5 Amount: 5
NotConsumed: NotConsumed:
- Item: Device_Creation_Guide - Item: Device_M_Book
- Product: Auto_Battle_Capsule - Product: Auto_Battle_Capsule
SkillName: MT_M_MACHINE SkillName: MT_M_MACHINE
SkillLevel: 1 SkillLevel: 1
@ -2348,7 +2348,7 @@ Body:
- Item: Portable_Furnace - Item: Portable_Furnace
Amount: 5 Amount: 5
NotConsumed: NotConsumed:
- Item: Device_Creation_Guide - Item: Device_M_Book
- ItemLevel: 32 - ItemLevel: 32
Recipe: Recipe:
- Product: Flame_Acid_Bottle - Product: Flame_Acid_Bottle

View File

@ -6393,8 +6393,6 @@ void clif_skill_produce_mix_list( map_session_data *sd, int skill_id, int trigge
int count = 0; int count = 0;
for (const auto &itemlvit : skill_produce_db) { for (const auto &itemlvit : skill_produce_db) {
if (itemlvit.second->data.empty())
continue;
for (const auto &datait : itemlvit.second->data) { for (const auto &datait : itemlvit.second->data) {
if (skill_can_produce_mix(sd, datait.second->nameid, trigger, 1) != nullptr && if (skill_can_produce_mix(sd, datait.second->nameid, trigger, 1) != nullptr &&
(skill_id <= 0 || (skill_id > 0 && datait.second->req_skill == skill_id)) (skill_id <= 0 || (skill_id > 0 && datait.second->req_skill == skill_id))
@ -6446,8 +6444,6 @@ void clif_cooking_list( map_session_data *sd, int trigger, uint16 skill_id, int
int count = 0; int count = 0;
for (const auto &itemlvit : skill_produce_db) { for (const auto &itemlvit : skill_produce_db) {
if (itemlvit.second->data.empty())
continue;
for (const auto &datait : itemlvit.second->data) { for (const auto &datait : itemlvit.second->data) {
if( skill_can_produce_mix( sd, datait.second->nameid, trigger, qty ) == nullptr ){ if( skill_can_produce_mix( sd, datait.second->nameid, trigger, qty ) == nullptr ){
continue; continue;
@ -19518,8 +19514,6 @@ void clif_elementalconverter_list( map_session_data *sd ){
int count = 0; int count = 0;
for (const auto &itemlvit : skill_produce_db) { for (const auto &itemlvit : skill_produce_db) {
if (itemlvit.second->data.empty())
continue;
for (const auto &datait : itemlvit.second->data) { for (const auto &datait : itemlvit.second->data) {
if( skill_can_produce_mix( sd, datait.second->nameid, 23, 1 ) ){ if( skill_can_produce_mix( sd, datait.second->nameid, 23, 1 ) ){
p->items[count].itemId = client_nameid( datait.second->nameid ); p->items[count].itemId = client_nameid( datait.second->nameid );

View File

@ -21408,17 +21408,15 @@ std::shared_ptr<s_skill_produce_db_entry> skill_can_produce_mix(map_session_data
std::shared_ptr<s_skill_produce_db_entry> produce = nullptr; std::shared_ptr<s_skill_produce_db_entry> produce = nullptr;
for (const auto &itemlvit : skill_produce_db) { for (const auto &itemlvit : skill_produce_db) {
if (itemlvit.second->data.empty())
continue;
for (const auto &datait : itemlvit.second->data) { for (const auto &datait : itemlvit.second->data) {
if (datait.second->nameid == nameid) { if (datait.second->nameid != nameid)
if (datait.second->req_skill > 0 && pc_checkskill(sd, datait.second->req_skill) < datait.second->req_skill_lv) continue;
continue; // must iterate again to check other skills that produce it. [malufett] if (datait.second->req_skill > 0 && pc_checkskill(sd, datait.second->req_skill) < datait.second->req_skill_lv)
if (datait.second->req_skill > 0 && sd->menuskill_id > 0 && sd->menuskill_id != datait.second->req_skill) continue; // must iterate again to check other skills that produce it. [malufett]
continue; // special case if (datait.second->req_skill > 0 && sd->menuskill_id > 0 && sd->menuskill_id != datait.second->req_skill)
produce = datait.second; continue; // special case
break; produce = datait.second;
} break;
} }
if (produce != nullptr) if (produce != nullptr)
break; break;
@ -21539,32 +21537,30 @@ bool skill_produce_mix(map_session_data *sd, uint16 skill_id, t_itemid nameid, i
} }
} }
if (!produce->materials.empty()) { for (const auto &mat : produce->materials) {
for (const auto &mat : produce->materials) { short x, j;
short x, j; t_itemid id = mat.first;
t_itemid id = mat.first;
if (!item_db.exists(id)) if (!item_db.exists(id))
continue; continue;
num++; num++;
x = (skill_id == RK_RUNEMASTERY ? 1 : qty) * mat.second; x = (skill_id == RK_RUNEMASTERY ? 1 : qty) * mat.second;
do { do {
int y = 0; int y = 0;
j = pc_search_inventory(sd,id); j = pc_search_inventory(sd,id);
if (j >= 0) { if (j >= 0) {
y = sd->inventory.u.items_inventory[j].amount; y = sd->inventory.u.items_inventory[j].amount;
if (y > x) if (y > x)
y = x; y = x;
pc_delitem(sd,j,y,0,0,LOG_TYPE_PRODUCE); pc_delitem(sd,j,y,0,0,LOG_TYPE_PRODUCE);
} else { } else {
ShowError("skill_produce_mix: material item error\n"); ShowError("skill_produce_mix: material item error\n");
return false; return false;
} }
x -= y; x -= y;
} while( j >= 0 && x > 0 ); } while( j >= 0 && x > 0 );
}
} }
if ((equip = (itemdb_isequip(nameid) && skill_id != GN_CHANGEMATERIAL && skill_id != GN_MAKEBOMB)) && itemdb_type(nameid) == IT_WEAPON ) if ((equip = (itemdb_isequip(nameid) && skill_id != GN_CHANGEMATERIAL && skill_id != GN_MAKEBOMB)) && itemdb_type(nameid) == IT_WEAPON )
@ -21987,7 +21983,7 @@ bool skill_produce_mix(map_session_data *sd, uint16 skill_id, t_itemid nameid, i
} }
if (skill_id == GN_CHANGEMATERIAL && tmp_item.amount) { //Success if (skill_id == GN_CHANGEMATERIAL && tmp_item.amount) { //Success
int k = 0, l; bool is_produce_success = false;
bool isStackable = itemdb_isstackable(tmp_item.nameid); bool isStackable = itemdb_isstackable(tmp_item.nameid);
if (!produce->qty.empty()) { if (!produce->qty.empty()) {
@ -21995,7 +21991,7 @@ bool skill_produce_mix(map_session_data *sd, uint16 skill_id, t_itemid nameid, i
if (rnd()%1000 < qtyit.second){ if (rnd()%1000 < qtyit.second){
uint16 total_qty = qty * qtyit.first; uint16 total_qty = qty * qtyit.first;
tmp_item.amount = (isStackable ? total_qty : 1); tmp_item.amount = (isStackable ? total_qty : 1);
for (l = 0; l < total_qty; l += tmp_item.amount) { for ( int l = 0; l < total_qty; l += tmp_item.amount ) {
if ((flag = pc_additem(sd,&tmp_item,tmp_item.amount,LOG_TYPE_PRODUCE))) { if ((flag = pc_additem(sd,&tmp_item,tmp_item.amount,LOG_TYPE_PRODUCE))) {
clif_additem(sd,0,0,flag); clif_additem(sd,0,0,flag);
if( battle_config.skill_drop_items_full ){ if( battle_config.skill_drop_items_full ){
@ -22003,11 +21999,11 @@ bool skill_produce_mix(map_session_data *sd, uint16 skill_id, t_itemid nameid, i
} }
} }
} }
k++; is_produce_success = true;
} }
} }
} }
if (k) { if (is_produce_success) {
clif_produceeffect(sd,6,nameid); clif_produceeffect(sd,6,nameid);
clif_misceffect(&sd->bl,5); clif_misceffect(&sd->bl,5);
clif_msg_skill(sd,skill_id,ITEM_PRODUCE_SUCCESS); clif_msg_skill(sd,skill_id,ITEM_PRODUCE_SUCCESS);
@ -22474,7 +22470,7 @@ int skill_elementalanalysis(map_session_data* sd, int n, uint16 skill_lv, unsign
} }
int skill_changematerial(map_session_data *sd, int n, unsigned short *item_list) { int skill_changematerial(map_session_data *sd, int n, unsigned short *item_list) {
int k, c, p = 0, amount; int k, c, qty = 0, amount;
t_itemid nameid; t_itemid nameid;
nullpo_ret(sd); nullpo_ret(sd);
@ -22494,7 +22490,7 @@ int skill_changematerial(map_session_data *sd, int n, unsigned short *item_list)
if (data->materials.empty()) if (data->materials.empty())
return 0; return 0;
p = 0; qty = 0;
do { do {
c = 0; c = 0;
// Verification of overlap between the objects required and the list submitted. // Verification of overlap between the objects required and the list submitted.
@ -22512,20 +22508,20 @@ int skill_changematerial(map_session_data *sd, int n, unsigned short *item_list)
clif_msg_skill(sd,GN_CHANGEMATERIAL,ITEM_UNIDENTIFIED); clif_msg_skill(sd,GN_CHANGEMATERIAL,ITEM_UNIDENTIFIED);
return 0; return 0;
} }
if (nameid == mat.first && (amount - p * mat.second) >= mat.second && (amount - p * mat.second) % mat.second == 0) // must be in exact amount if (nameid == mat.first && (amount - qty * mat.second) >= mat.second && (amount - qty * mat.second) % mat.second == 0) // must be in exact amount
c++; // match c++; // match
} }
} }
p++; qty++;
} while(n == data->materials.size() && c == n); } while(n == data->materials.size() && c == n);
p--; qty--;
if ( p > 0 ) { if ( qty > 0 ) {
skill_produce_mix(sd,GN_CHANGEMATERIAL,datait.second->nameid,0,0,0,p, datait.second); skill_produce_mix(sd,GN_CHANGEMATERIAL,datait.second->nameid,0,0,0,qty, datait.second);
return 1; return 1;
} }
} }
if( p == 0) if( qty == 0)
clif_msg_skill(sd,GN_CHANGEMATERIAL,ITEM_CANT_COMBINE); clif_msg_skill(sd,GN_CHANGEMATERIAL,ITEM_CANT_COMBINE);
return 0; return 0;
@ -24570,7 +24566,7 @@ static bool skill_parse_row_nocastdb(char* split[], int columns, int current)
return true; return true;
} }
bool SkillProduceDatabase::add_itemconsumed(const ryml::NodeRef& node, std::shared_ptr<s_skill_produce_db_entry> &entry, bool isConsumed) { bool SkillProduceDatabase::addItemConsumed(const ryml::NodeRef& node, std::shared_ptr<s_skill_produce_db_entry> &entry, bool isConsumed) {
for (const auto &it : node) { for (const auto &it : node) {
if (this->nodeExists(it, "Clear")) { if (this->nodeExists(it, "Clear")) {
std::string item_name; std::string item_name;
@ -24767,12 +24763,12 @@ uint64 SkillProduceDatabase::parseBodyNode(const ryml::NodeRef &node) {
} }
if (this->nodeExists(subit, "Consumed")) { if (this->nodeExists(subit, "Consumed")) {
if (!this->add_itemconsumed(subit["Consumed"], entry, true)) if (!this->addItemConsumed(subit["Consumed"], entry, true))
return 0; return 0;
} }
if (this->nodeExists(subit, "NotConsumed")) { if (this->nodeExists(subit, "NotConsumed")) {
if (!this->add_itemconsumed(subit["NotConsumed"], entry, false)) if (!this->addItemConsumed(subit["NotConsumed"], entry, false))
return 0; return 0;
} }

View File

@ -465,7 +465,7 @@ public:
const std::string getDefaultLocation() override; const std::string getDefaultLocation() override;
uint64 parseBodyNode(const ryml::NodeRef& node) override; uint64 parseBodyNode(const ryml::NodeRef& node) override;
bool add_itemconsumed(const ryml::NodeRef& node, std::shared_ptr<s_skill_produce_db_entry> &entry, bool isConsumed); bool addItemConsumed(const ryml::NodeRef& node, std::shared_ptr<s_skill_produce_db_entry> &entry, bool isConsumed);
}; };
extern SkillProduceDatabase skill_produce_db; extern SkillProduceDatabase skill_produce_db;