mirror of
https://github.com/AndorsTrailRelease/andors-trail.git
synced 2026-02-13 21:28:10 +01:00
Updated content editor to display automatic price calculation.
git-svn-id: https://andors-trail.googlecode.com/svn/trunk@145 08aca716-68be-ccc6-4d58-36f5abd142ac
This commit is contained in:
@@ -74,7 +74,7 @@ function addExampleModelItems(model) {
|
||||
|
||||
model.quests.add({id: "testQuest", name: "Test quest", stages: [ { progress: 10, logText: "Stage 10"} , { progress: 20, logText: "Stage 20", finishesQuest: 1 } ] });
|
||||
|
||||
model.items.add({iconID: "items_tiles:70", name: "Test item", searchTag: "item0", category: 0, baseMarketCost: 51, hasEquipEffect: 1, equip_attackChance: 10, equip_attackDamage_Min: 2, equip_attackDamage_Max: 4});
|
||||
model.items.add({iconID: "items_tiles:70", name: "Test item", searchTag: "item0", category: 0, baseMarketCost: 51, hasEquipEffect: 1, equip_attackChance: 10, equip_attackDamage_Min: 2, equip_attackDamage_Max: 4, equip_attackCost: 4});
|
||||
model.items.add({iconID: "items_tiles:266", name: "Ring of damage +1", searchTag: "dmg_ring1", category: 7, baseMarketCost: 62, hasEquipEffect: 1, equip_attackDamage_Min: 1, equip_attackDamage_Max: 1});
|
||||
|
||||
model.droplists.add({id: "merchant1", items: [ { itemID: 'dmg_ring1', quantity_Min: 4, quantity_Max: 5, chance: 100 } , { itemID: 'item0', quantity_Min: 1, quantity_Max: 1, chance: 100 } ] } );
|
||||
@@ -110,7 +110,7 @@ function startEditor() {
|
||||
})
|
||||
,items: new DataStore({
|
||||
objectTypename: 'item'
|
||||
,fieldList: new FieldList("[searchTag|iconID|name|category|displaytype|baseMarketCost|"
|
||||
,fieldList: new FieldList("[searchTag|iconID|name|category|displaytype|hasManualPrice|baseMarketCost|"
|
||||
+ "hasEquipEffect|equip_boostMaxHP|equip_boostMaxAP|equip_moveCostPenalty|equip_attackCost|equip_attackChance|equip_criticalChance|equip_criticalMultiplier|equip_attackDamage_Min|equip_attackDamage_Max|equip_blockChance|equip_damageResistance|equip_conditions[condition|magnitude|]|"
|
||||
+ "hasUseEffect|use_boostHP_Min|use_boostHP_Max|use_boostAP_Min|use_boostAP_Max|use_conditionsSource[condition|magnitude|duration|chance|]|"
|
||||
+ "hasHitEffect|hit_boostHP_Min|hit_boostHP_Max|hit_boostAP_Min|hit_boostAP_Max|hit_conditionsSource[condition|magnitude|duration|chance|]|hit_conditionsTarget[condition|magnitude|duration|chance|]|"
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
|
||||
function sgn(v) {
|
||||
if (v < 0) return -1;
|
||||
else if (v > 0) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
function createItemEditor(obj) {
|
||||
var div = $( "#templates #editItem" ).clone();
|
||||
applyCommonEditorBindings(div, obj, model.items);
|
||||
@@ -55,12 +61,97 @@ function createItemEditor(obj) {
|
||||
editorSetup: setupEditor
|
||||
});
|
||||
|
||||
$( "#baseMarketCost", div ).change(function() {
|
||||
var val = parseInt( $( this ).val() );
|
||||
|
||||
var itemCostDependsOn = [];
|
||||
var v = function(s) {
|
||||
var field = $( s, div );
|
||||
itemCostDependsOn.push(field);
|
||||
var val = field.val();
|
||||
if (!val) return 0;
|
||||
return parseInt(val);
|
||||
}
|
||||
var cb = function(s) {
|
||||
var field = $( s, div );
|
||||
itemCostDependsOn.push(field);
|
||||
return field.attr("checked");
|
||||
}
|
||||
var calculateItemCost = function() {
|
||||
itemCostDependsOn = [];
|
||||
var averageHPBoost = (v("#use_boostHP_Min") + v("#use_boostHP_Max")) / 2;
|
||||
var costBoostHP = Math.round(0.1*sgn(averageHPBoost)*Math.pow(Math.abs(averageHPBoost), 2) + 3*averageHPBoost);
|
||||
var itemUsageCost = costBoostHP;
|
||||
|
||||
var isWeapon = v("#category") == 0;
|
||||
|
||||
var equip_blockChance = v("#equip_blockChance");
|
||||
var equip_attackChance = v("#equip_attackChance");
|
||||
var equip_attackCost = v("#equip_attackCost");
|
||||
var equip_damageResistance = v("#equip_damageResistance");
|
||||
var equip_attackDamage_Min = v("#equip_attackDamage_Min");
|
||||
var equip_attackDamage_Max = v("#equip_attackDamage_Max");
|
||||
var equip_criticalChance = v("#equip_criticalChance");
|
||||
var equip_criticalMultiplier = v("#equip_criticalMultiplier");
|
||||
var costBC = Math.round(3*Math.pow(Math.max(0,equip_blockChance), 2.5) + 28*equip_blockChance);
|
||||
var costAC = Math.round(0.4*Math.pow(Math.max(0,equip_attackChance), 2.5) - 7*Math.pow(Math.abs(Math.min(0,equip_attackChance)),2.7));
|
||||
var costAP = isWeapon ?
|
||||
Math.round(0.2*Math.pow(10/equip_attackCost, 8) - 25*equip_attackCost)
|
||||
: -3125 * equip_attackCost;
|
||||
var costDR = 1325*equip_damageResistance;
|
||||
var costDMG_Min = isWeapon ?
|
||||
Math.round(10*Math.pow(equip_attackDamage_Min, 2.5))
|
||||
:Math.round(10*Math.pow(equip_attackDamage_Min, 3) + equip_attackDamage_Min*80);
|
||||
var costDMG_Max = isWeapon ?
|
||||
Math.round(2*Math.pow(equip_attackDamage_Max, 2.1))
|
||||
:Math.round(2*Math.pow(equip_attackDamage_Max, 3) + equip_attackDamage_Max*20);
|
||||
var costCC = Math.round(2.2*Math.pow(equip_criticalChance, 3));
|
||||
var costCM = Math.round(50*Math.pow(Math.max(0, equip_criticalMultiplier), 2));
|
||||
if (!cb("#equip_hasCritical")) {
|
||||
costCC = 0;
|
||||
costCM = 0;
|
||||
}
|
||||
var costCombat = costBC + costAC + costAP + costDR + costDMG_Min + costDMG_Max + costCC + costCM;
|
||||
|
||||
var equip_boostMaxHP = v("#equip_boostMaxHP");
|
||||
var equip_boostMaxAP = v("#equip_boostMaxAP");
|
||||
var equip_moveCostPenalty = v("#equip_moveCostPenalty");
|
||||
var costMaxHP = Math.round(30*Math.pow(Math.max(0,equip_boostMaxHP), 1.2) + 70*equip_boostMaxHP);
|
||||
var costMaxAP = Math.round(50*Math.pow(Math.max(0,equip_boostMaxAP), 3) + 750*equip_boostMaxAP);
|
||||
var costMovement = Math.round(10*Math.pow(Math.max(0,equip_moveCostPenalty), 2) + 350*equip_moveCostPenalty);
|
||||
var itemEquipCost = costCombat + costMaxHP + costMaxAP + costMovement;
|
||||
|
||||
if (!cb("#hasEquipEffect")) { itemEquipCost = 0; }
|
||||
if (!cb("#hasUseEffect")) { itemUsageCost = 0; }
|
||||
|
||||
return itemEquipCost + itemUsageCost;
|
||||
}
|
||||
|
||||
var divBaseMarketCost = $( "#baseMarketCost", div );
|
||||
var recalculateStorePrice = function() {
|
||||
var val = parseInt(obj.baseMarketCost);
|
||||
if (!obj.hasManualPrice) {
|
||||
val = calculateItemCost(obj);
|
||||
obj.baseMarketCost = val;
|
||||
divBaseMarketCost.val(val);
|
||||
}
|
||||
$( "#marketCost_Sell", div ).val(Math.round(val * (100 + 15) / 100));
|
||||
$( "#marketCost_Buy", div ).val(Math.round(val * (100 - 15) / 100));
|
||||
};
|
||||
|
||||
divBaseMarketCost.change(recalculateStorePrice);
|
||||
$( "#hasManualPrice", div ).change(function() {
|
||||
if (obj.hasManualPrice) {
|
||||
divBaseMarketCost.removeAttr("readonly");
|
||||
} else {
|
||||
divBaseMarketCost.attr("readonly", "readonly");
|
||||
}
|
||||
recalculateStorePrice();
|
||||
}).change();
|
||||
|
||||
calculateItemCost();
|
||||
jQuery.each(itemCostDependsOn, function(idx, o) {
|
||||
o.change(recalculateStorePrice);
|
||||
});
|
||||
|
||||
return div;
|
||||
}
|
||||
|
||||
|
||||
@@ -362,7 +362,10 @@
|
||||
</div>
|
||||
<div class="fieldWithLabel">
|
||||
<label for="baseMarketCost" class="label">Base market cost (gold):</label>
|
||||
<input class="field" type="text" size="7" id="baseMarketCost" class="fieldInput integer" title="The actual price is adjusted 15% depending on if the item is being bought or sold. Set to 0 to prohibit selling this item type (for example, for a quest item)." />
|
||||
<input class="field" type="text" size="7" id="baseMarketCost" readonly="readonly" class="fieldInput integer" title="The actual price is adjusted 15% depending on if the item is being bought or sold. Set to 0 to prohibit selling this item type (for example, for a quest item)." />
|
||||
</div>
|
||||
<div class="fieldWithLabel">
|
||||
<div class="label"><input type="checkbox" id="hasManualPrice" />Item has manually specified store price</div>
|
||||
</div>
|
||||
<div class="fieldWithLabel">
|
||||
<label for="marketCost_Sell" class="label">Actual price (gold):</label>
|
||||
|
||||
Reference in New Issue
Block a user