Ver Fonte

Cleaned up and added documentation for Taxes

aleos89 há 7 anos atrás
pai
commit
a5897a1c3c
4 ficheiros alterados com 49 adições e 11 exclusões
  1. 4 5
      conf/import-tmpl/tax.yml
  2. 4 5
      conf/tax.yml
  3. 7 0
      src/map/buyingstore.cpp
  4. 34 1
      src/map/tax.cpp

+ 4 - 5
conf/import-tmpl/tax.yml

@@ -1,7 +1,7 @@
 ## Taxes for selling something (vending)
-## The zeny that you received will be reduced after tax
+## Zeny received for the seller will be reduced after taxes from the total selling price but the buyer pays just the total selling price
 #Selling:
-#  # Tax applies in total transaction
+#  # Tax applied for total transaction
 #  In_Total:
 #  - Minimal_Value: 0
 #    Tax: 0
@@ -13,10 +13,9 @@
 #    Tax: 1000
 #
 ## Taxes for buying something (buyingstore)
-## The zeny that you must be paid will be increased after tax
-## but player who sells still get the value without tax
+## Zeny received for the seller will be the total selling price but the buyer must pay taxes for the total selling price
 #Buying:
-#  # Tax applies in total transaction
+#  # Tax applied for total transaction
 #  In_Total:
 #  - Minimal_Value: 0
 #    Tax: 0

+ 4 - 5
conf/tax.yml

@@ -1,7 +1,7 @@
 # Taxes for selling something (vending)
-# The zeny that you received will be reduced after tax
+# Zeny received for the seller will be reduced after taxes from the total selling price but the buyer pays just the total selling price
 Selling:
-  # Tax applies in total transaction
+  # Tax applied for total transaction
   In_Total:
   - Minimal_Value: 0
     Tax: 0
@@ -25,10 +25,9 @@ Selling:
     Tax: 200
 
 # Taxes for buying something (buyingstore)
-# The zeny that you must be paid will be increased after tax
-# but player who sells still get the value without tax
+# Zeny received for the seller will be the total selling price but the buyer must pay taxes for the total selling price
 Buying:
-  # Tax applies in total transaction
+  # Tax applied for total transaction
   In_Total:
   - Minimal_Value: 0
     Tax: 0

+ 7 - 0
src/map/buyingstore.cpp

@@ -341,6 +341,13 @@ void buyingstore_open(struct map_session_data* sd, uint32 account_id)
 	clif_buyingstore_itemlist(sd, pl_sd);
 }
 
+/**
+ * Calculates taxes for Buyingstore purchases.
+ * @param sd: Player data.
+ * @param itemlist: List of sold items { <index>.W, <nameid>.W, <amount>.W }*.
+ * @param count: Item list count.
+ * @return Taxed price
+ */
 static unsigned short buyinstore_tax_intotal(struct map_session_data* sd, const uint8* itemlist, int count) {
 	s_tax *tax = tax_get(TAX_BUYING);
 

+ 34 - 1
src/map/tax.cpp

@@ -16,18 +16,36 @@
 static struct s_tax TaxDB[TAX_MAX];
 std::string tax_conf = "conf/store_tax.yml";
 
+/**
+ * Returns the tax rate of a given amount.
+ * @param entry: Tax data.
+ * @param price: Value of item.
+ * @return Tax rate
+ */
 unsigned short s_tax::get_tax(const std::vector <struct s_tax_entry> entry, double price) {
 	const auto &tax = std::find_if(entry.begin(), entry.end(),
 		[&price](const s_tax_entry &e) { return price >= e.minimal; });
 	return tax != entry.end() ? tax->tax : 0;
 }
 
+/**
+ * Returns the tax type based on selling or buying.
+ * @param type: Tax type.
+ * @return Tax data.
+ */
 struct s_tax *tax_get(enum e_tax_type type) {
 	if (type < TAX_SELLING || type >= TAX_MAX)
 		return NULL;
 	return &TaxDB[type];
 }
 
+/**
+ * Reads and parses an entry from the tax database.
+ * @param node: YAML node containing the entry.
+ * @param taxdata: Tax data.
+ * @param count: The sequential index of the current entry.
+ * @param source: The source YAML file.
+ */
 static void tax_readdb_sub(const YAML::Node &node, struct s_tax *taxdata, int *count, const std::string &source) {
 	if (node["In_Total"].IsDefined()) {
 		for (const auto &tax : node["In_Total"]) {
@@ -57,6 +75,9 @@ static void tax_readdb_sub(const YAML::Node &node, struct s_tax *taxdata, int *c
 	}
 }
 
+/**
+ * Loads taxes from the tax database.
+ */
 void tax_readdb(void) {
 	YAML::Node config;
 
@@ -77,18 +98,30 @@ void tax_readdb(void) {
 	ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'\n", count, tax_conf.c_str());
 }
 
+/**
+ * Reload tax values for autotrade players (unused)
+ */
 void tax_reload_vendors(void) {
 	// reload VAT price on vendors
 }
 
-void tax_set_conf(const std::string filename) {
+/**
+ * Sets the tax database file name from the map_athena.conf
+ */
+ void tax_set_conf(const std::string filename) {
 	tax_conf = filename;
 }
 
+/**
+ * Initializes the tax database
+ */
 void do_init_tax(void) {
 	tax_readdb();
 }
 
+/**
+ * Finalizes the tax database
+ */
 void do_final_tax(void) {
 
 }