Widget:PriceCalculator: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
(perfection)
(Use math.round)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>
<includeonly>
<table id="bg3wiki-price-calculator-form">
<div id="bg3wiki-price-calculator">
    <tr>
    <table id="bg3wiki-price-calculator-form">
        <th><label for="item-value">Item value</label></th><td><input type="number" id="item-value" size="7" value="1000"/></td>
        <tr>
    </tr>
            <th><label for="item-value">Item value</label></th><td><input type="number" id="item-value" size="7" value="1000"/></td>
    <tr>
        </tr>
        <th><label for="persuasion-mod">Persuasion modifier</label></th><td><input type="number" id="persuasion-mod" size="3" value="0"/></td>
        <tr>
    </tr>
            <th><label for="persuasion-mod">Persuasion modifier</label></th><td><input type="number" id="persuasion-mod" size="3" value="0"/></td>
    <tr>
        </tr>
        <th><label for="attitude">Attitude</label></th><td><input type="number" id="attitude" size="4"/></td>
        <tr>
    </tr>
            <th><label for="attitude">Attitude</label></th><td><input type="number" id="attitude" size="4"/></td>
    <tr>
        </tr>
        <th><label for="difficulty">Difficulty</label></th><td>
        <tr>
            <input type="radio" name="difficulty" id="difficulty-explorer" value="explorer" required/><label for="difficulty-explorer">Explorer</label>
            <th><label for="difficulty">Difficulty</label></th><td>
            <input type="radio" name="difficulty" id="difficulty-balanced" value="balanced" checked /><label for="difficulty-balanced">Balanced</label>
                <input type="radio" name="difficulty" id="difficulty-explorer" value="explorer" required/><label for="difficulty-explorer">Explorer</label>
            <input type="radio" name="difficulty" id="difficulty-tactician" value="tactician" /><label for="difficulty-tactician">Tactician</label>
                <input type="radio" name="difficulty" id="difficulty-balanced" value="balanced" checked /><label for="difficulty-balanced">Balanced</label>
        </td>
                <input type="radio" name="difficulty" id="difficulty-tactician" value="tactician" /><label for="difficulty-tactician">Tactician</label>
    </tr>
            </td>
    <tr>
        </tr>
        <th></th><td><input type="button" value="Submit" id="submit" /></td>
        <tr>
    </tr>
            <th></th><td><input type="button" value="Submit" id="submit" /></td>
</table>
        </tr>
<div id="bg3wiki-price-calculator-result"></div>
    </table>
    <hr/>
    <div id="bg3wiki-price-calculator-result"></div>
</div>
<script>
<script>
     document.querySelector("#bg3wiki-price-calculator-form #submit").addEventListener("click", do_calculation);
     document.querySelector("#bg3wiki-price-calculator-form #submit").addEventListener("click", do_calculation);
Line 54: Line 57:
         let get_value = (selector) => document.querySelector(selector).value;
         let get_value = (selector) => document.querySelector(selector).value;
         let item_value = sanitize(get_value('#item-value'));
         let item_value = sanitize(get_value('#item-value'));
         let persuasion_mod = sanitize(get_value('#persuasion-mod')) * 0.05;
         let persuasion_mod = sanitize(get_value('#persuasion-mod')) * 0.1;
         let attitude = sanitize(get_value('#attitude')) * 0.0025;
         let attitude = sanitize(get_value('#attitude')) * 0.005;
         let difficulty = document.querySelector('input[name="difficulty"]:checked').value;
         let difficulty = document.querySelector('input[name="difficulty"]:checked').value;
         difficulty = get_difficulty_mod(difficulty)
         difficulty = get_difficulty_mod(difficulty)
          
          
         let price_mod = Math.max(1.0, 2.5 - persuasion_mod - attitude - difficulty);
         let price_mod = Math.max(1.0, 2.5 - persuasion_mod - attitude - difficulty);
         let price_buy = item_value * price_mod;
         let price_buy = Math.round(item_value * price_mod);
         let price_sell = item_value / price_mod;
         let price_sell = Math.round(item_value / price_mod);
 
        console.log(`persuasion mod ${persuasion_mod} attitude mod ${attitude} difficulty mod ${difficulty}`)
 
         output.textContent = '';
         output.textContent = '';
         let table = document.createElement('table');
         let table = document.createElement('table');
        table.classList.add('wikitable');
         table.appendChild(create_output_row('Base item price', item_value));
         table.appendChild(create_output_row('Base item price', item_value));
         table.appendChild(create_output_row('Item price when selling to a trader', price_sell));
         table.appendChild(create_output_row('Item price (selling)', price_sell));
         table.appendChild(create_output_row('Item price when buying from a trader', price_buy));
         table.appendChild(create_output_row('Item price (buying)', price_buy));
         output.appendChild(table);
         output.appendChild(table);
     }
     }
</script>
</script>
</includeonly>
</includeonly>
<noinclude>{{#widget:PriceCalculator}}</noinclude>
<noinclude>{{PageSeo
| title = Widget:PriceCalculator
| description = Price calculator for determining the buy & sell price of items.
}}{{#widget:PriceCalculator}}</noinclude>

Latest revision as of 22:37, 22 November 2023