viewing paste cashshop_doc | Diff

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
Index: cashshop.c
===================================================================
--- cashshop.c  (revision 17301)
+++ cashshop.c  (working copy)
@@ -15,13 +15,59 @@
 #include <string.h> // memset
 #include <stdlib.h> // atoi
 
-static int cashshop_parse_dbrow( char** str, const char* source, int line );
-
 struct cash_item_db cash_shop_items[CASHSHOP_TAB_SEARCH];
 
 extern char item_cash_db_db[32];
 extern char item_cash_db2_db[32];
 
+/*
+ * Read one line of db and assign it to ram
+ * return
+ *  0 = failure
+ *  1 = succes
+ */
+static int cashshop_parse_dbrow( char** str, const char* source, int line ){
+       uint32 nameid = atoi( str[1] );
+
+       if( itemdb_exists( nameid ) ){
+               uint16 tab = atoi( str[0] );
+               uint32 price = atoi( str[2] );
+               struct cash_item_data* cid;
+               int j;
+
+               if( tab > CASHSHOP_TAB_SEARCH ){
+                       ShowWarning( "cashshop_parse_dbrow: Invalid tab %d in line %d of \"%s\", skipping.\n", tab, line, source );
+                       return 0;
+               }else if( price < 1 ){
+                       ShowWarning( "cashshop_parse_dbrow: Invalid price %d in line %d of \"%s\", skipping.\n", price, line, source );
+                       return 0;
+               }
+
+               ARR_FIND( 0, cash_shop_items[tab].count, j, nameid == cash_shop_items[tab].item[j]->nameid );
+
+               if( j == cash_shop_items[tab].count ){
+                       RECREATE( cash_shop_items[tab].item, struct cash_item_data *, ++cash_shop_items[tab].count );
+                       CREATE( cash_shop_items[tab].item[ cash_shop_items[tab].count - 1], struct cash_item_data, 1 );
+                       cid = cash_shop_items[tab].item[ cash_shop_items[tab].count - 1];
+               }else{
+                       cid = cash_shop_items[tab].item[j];
+               }
+
+               cid->nameid = nameid;
+               cid->price = price;
+
+               return 1;
+       }else{
+               ShowWarning( "cashshop_parse_dbrow: Invalid id %d in line %d of \"%s\", skipping.\n", nameid, line, source );
+       }
+
+       return 0;
+}
+
+/*
+ * Read database from txt format,
+ * parse line and send them to parse_dbrow
+ */
 static void cashshop_read_db_txt( void ){
        const char* filename[] = { DBPATH"item_cash_db.txt", "item_cash_db2.txt" };
        int fi;
@@ -88,6 +134,10 @@
        }
 }
 
+/*
+ * Read database from sql format,
+ * parse line and send them to parse_dbrow
+ */
 static int cashshop_read_db_sql( void ){
        const char* cash_db_name[] = { item_cash_db_db, item_cash_db2_db };
        int fi;
@@ -128,6 +178,11 @@
        return 0;
 }
 
+/*
+ * Read cashshop database main
+ * choose wich reader to use depending of config :
+ * conf/map_athena.conf  db_use_sqldbs
+ */
 static void cashshop_read_db( void ){
        if( db_use_sqldbs ){
                cashshop_read_db_sql();
@@ -136,44 +191,12 @@
        }
 }
 
-static int cashshop_parse_dbrow( char** str, const char* source, int line ){
-       uint32 nameid = atoi( str[1] );
-
-       if( itemdb_exists( nameid ) ){
-               uint16 tab = atoi( str[0] );
-               uint32 price = atoi( str[2] );
-               struct cash_item_data* cid;
-               int j;
-
-               if( tab > CASHSHOP_TAB_SEARCH ){
-                       ShowWarning( "cashshop_parse_dbrow: Invalid tab %d in line %d of \"%s\", skipping.\n", tab, line, source );
-                       return 0;
-               }else if( price < 1 ){
-                       ShowWarning( "cashshop_parse_dbrow: Invalid price %d in line %d of \"%s\", skipping.\n", price, line, source );
-                       return 0;
-               }
-
-               ARR_FIND( 0, cash_shop_items[tab].count, j, nameid == cash_shop_items[tab].item[j]->nameid );
-
-               if( j == cash_shop_items[tab].count ){
-                       RECREATE( cash_shop_items[tab].item, struct cash_item_data *, ++cash_shop_items[tab].count );
-                       CREATE( cash_shop_items[tab].item[ cash_shop_items[tab].count - 1], struct cash_item_data, 1 );
-                       cid = cash_shop_items[tab].item[ cash_shop_items[tab].count - 1];
-               }else{
-                       cid = cash_shop_items[tab].item[j];
-               }
-
-               cid->nameid = nameid;
-               cid->price = price;
-
-               return 1;
-       }else{
-               ShowWarning( "cashshop_parse_dbrow: Invalid id %d in line %d of \"%s\", skipping.\n", nameid, line, source );
-       }
-
-       return 0;
-}
-
+/*
+ * Attempt to buy a cashshop item from list
+ * check if valid transaction and if user have enough place to receive item
+ * if yes take cashpoint and give else
+ * else return clif_error
+ */
 void cashshop_buylist( struct map_session_data* sd, uint32 kafrapoints, int n, uint16* item_list ){
        uint32 totalcash = 0;
        uint32 totalweight = 0;
@@ -227,10 +250,7 @@
                totalweight += itemdb_weight( nameid ) * quantity;
        }
 
-       if( ( totalcash - kafrapoints ) > sd->cashPoints || kafrapoints > sd->kafraPoints ){
-               clif_cashshop_result( sd, 0, CASHSHOP_RESULT_ERROR_SHORTTAGE_CASH );
-               return;
-       }else if( ( totalweight + sd->weight ) > sd->max_weight ){
+       if( ( totalweight + sd->weight ) > sd->max_weight ){
                clif_cashshop_result( sd, 0, CASHSHOP_RESULT_ERROR_INVENTORY_WEIGHT );
                return;
        }else if( pc_inventoryblank( sd ) < new_ ){
@@ -238,7 +258,10 @@
                return;
        }
 
-       pc_paycash( sd, totalcash, kafrapoints, LOG_TYPE_CASH );
+       if(pc_paycash( sd, totalcash, kafrapoints, LOG_TYPE_CASH ) < 0){
+               clif_cashshop_result( sd, 0, CASHSHOP_RESULT_ERROR_SHORTTAGE_CASH );
+               return;
+       }
 
        for( i = 0; i < n; ++i ){
                uint32 nameid = *( item_list + i * 5 );
@@ -273,11 +296,19 @@
        clif_cashshop_result( sd, 0, CASHSHOP_RESULT_SUCCESS );
 }
 
+/*
+ * Reload database of cashshop
+ * by destroying and read it again
+ */
 void cashshop_reloaddb( void ){
        do_final_cashshop();
        do_init_cashshop();
 }
 
+/*
+ * Destroy cashshop class
+ * Close all and cleanup
+ */
 int do_final_cashshop( void ){
        int tab, i;
 
@@ -285,15 +316,18 @@
                for( i = 0; i < cash_shop_items[tab].count; i++ ){
                        aFree( cash_shop_items[tab].item[i] );
                }
-
                aFree( cash_shop_items[tab].item );
        }
-
        memset( cash_shop_items, 0, sizeof( cash_shop_items ) );
 
        return 0;
 }
 
+/*
+ * Initialise cashshop class
+ * return
+ *  0 : success
+ */
 int do_init_cashshop( void ){
        cashshop_read_db();
Viewed 641 times, submitted by lighta.