mirror of
https://bitbucket.org/grumdrig/pq-web.git
synced 2026-09-29 00:34:00 -06:00
Char init logic moved to newguy.js; ListBox.save no longer needed
This commit is contained in:
@@ -219,9 +219,36 @@ function addToRoster(newguy) {
|
||||
}
|
||||
}
|
||||
|
||||
Number.prototype.div = function (divisor) {
|
||||
var dividend = this / divisor;
|
||||
return (dividend < 0 ? Math.ceil : Math.floor)(dividend);
|
||||
};
|
||||
|
||||
|
||||
function LevelUpTime(level) { // seconds
|
||||
// 20 minutes per level
|
||||
return 20 * level * 60;
|
||||
}
|
||||
|
||||
|
||||
var K = {};
|
||||
|
||||
K.Stats = ["STR","CON","DEX","INT","WIS","CHA"];
|
||||
K.Traits = ["Name", "Race", "Class", "Level"];
|
||||
|
||||
K.PrimeStats = ["STR","CON","DEX","INT","WIS","CHA"];
|
||||
K.Stats = K.PrimeStats.slice(0).concat(["HP Max","MP Max"]);
|
||||
|
||||
K.Equips = ["Weapon",
|
||||
"Shield",
|
||||
"Helm",
|
||||
"Hauberk",
|
||||
"Brassairts",
|
||||
"Vambraces",
|
||||
"Gauntlets",
|
||||
"Gambeson",
|
||||
"Cuisses",
|
||||
"Greaves",
|
||||
"Sollerets"];
|
||||
|
||||
K.Spells = [
|
||||
"Slime Finger",
|
||||
|
||||
@@ -299,7 +299,7 @@ function Dequeue() {
|
||||
var amt = GetI(Inventory, 1) * GetI(Traits,'Level');
|
||||
if (Pos(' of ', Inventory.label(1)) > 0)
|
||||
amt *= (1+RandomLow(10)) * (1+RandomLow(GetI(Traits,'Level')));
|
||||
Inventory.remove(1);
|
||||
Inventory.remove1();
|
||||
Add(Inventory, 'Gold', amt);
|
||||
}
|
||||
if (Inventory.length() > 1) {
|
||||
@@ -387,11 +387,6 @@ function PutUI(list, key, value) {
|
||||
item.each(function () {this.scrollIntoView();});
|
||||
}
|
||||
|
||||
function LevelUpTime(level) { // seconds
|
||||
// 20 minutes per level
|
||||
return 20 * level * 60;
|
||||
}
|
||||
|
||||
|
||||
function ProgressBar(id) {
|
||||
this.id = id;
|
||||
@@ -498,31 +493,17 @@ function ListBox(id, columns, fixedkeys) {
|
||||
return this.rows().length;
|
||||
};
|
||||
|
||||
this.remove = function (n) {
|
||||
this.box.find("tr").eq(n).remove();
|
||||
this.remove0 = function (n) {
|
||||
if (game[this.id])
|
||||
game[this.id].shift();
|
||||
this.box.find("tr").first().remove();
|
||||
};
|
||||
|
||||
|
||||
this.save = function (game) {
|
||||
return;
|
||||
var that = this;
|
||||
var dict = game[this.id];
|
||||
if (this.fixedkeys) {
|
||||
if (!dict) dict = {};
|
||||
this.rows().each(function (index) {
|
||||
dict[Key(this)] = Value(this);
|
||||
});
|
||||
} else {
|
||||
// Unfixed keys -- need to maintain order
|
||||
dict = [];
|
||||
this.rows().each(function (index) {
|
||||
if (that.columns == 2)
|
||||
dict.push([Key(this),Value(this)]);
|
||||
else
|
||||
dict.push($.trim($(this).text()));
|
||||
});
|
||||
}
|
||||
game[this.id] = dict;
|
||||
this.remove1 = function (n) {
|
||||
var t = game[this.id].shift();
|
||||
game[this.id].shift();
|
||||
game[this.id].unshift(t);
|
||||
this.box.find("tr").eq(1).remove();
|
||||
};
|
||||
|
||||
|
||||
@@ -556,67 +537,6 @@ var Kill;
|
||||
var AllBars, AllLists;
|
||||
|
||||
|
||||
function InitializeCharacter(sheet) {
|
||||
// TODO: some of the below is probably redundant
|
||||
// TODO: just set needed info and then load game?
|
||||
|
||||
game = sheet;
|
||||
randseed(game.seed);
|
||||
|
||||
game.tasks = 0;
|
||||
game.elapsed = 0;
|
||||
|
||||
Put(Traits, 'Name', sheet.Traits.Name);
|
||||
Put(Traits, 'Level', 1);
|
||||
Put(Traits, 'Race', sheet.Traits.Race);
|
||||
Put(Traits, 'Class', sheet.Traits.Class);
|
||||
|
||||
$.each(K.Stats, function (i,stat) { Put(Stats, stat, sheet.Stats[stat]); });
|
||||
Put(Stats, 'HP Max', Random(8) + sheet.Stats.CON.div(6));
|
||||
Put(Stats, 'MP Max', Random(8) + sheet.Stats.INT.div(6));
|
||||
|
||||
game.bestequip = 'Sharp Stick';
|
||||
Put(Equips, 'Weapon', game.bestequip);
|
||||
|
||||
Put(Inventory,'Gold',0);
|
||||
|
||||
SaveGame();
|
||||
|
||||
ClearAllSelections();
|
||||
|
||||
// GoButtonClick();
|
||||
|
||||
ExpBar.reset(LevelUpTime(1));
|
||||
|
||||
game.task = '';
|
||||
game.questmonster = '';
|
||||
game.queue = [];
|
||||
|
||||
Task('Loading.',2000); // that dot is spotted for later...
|
||||
Q('task|10|Experiencing an enigmatic and foreboding night vision');
|
||||
Q("task|6|Much is revealed about that wise old bastard you'd underestimated");
|
||||
Q('task|6|A shocking series of events leaves you alone and bewildered, but resolute');
|
||||
Q('task|4|Drawing upon an unexpected reserve of determination, you set out on a long and dangerous journey');
|
||||
Q('plot|2|Loading');
|
||||
|
||||
PlotBar.reset(26);
|
||||
Plots.AddUI((game.bestplot = 'Prologue'));
|
||||
game.act = 0;
|
||||
|
||||
QuestBar.reset(1);
|
||||
|
||||
EncumBar.reset(GetI(Stats, "STR") + 10);
|
||||
|
||||
Put(Equips, "Hauberk", "-3 Burlap");
|
||||
|
||||
ClearAllSelections();
|
||||
|
||||
StartTimer();
|
||||
|
||||
Brag('start');
|
||||
}
|
||||
|
||||
|
||||
function StrToIntDef(s, def) {
|
||||
var result = parseInt(s, 10);
|
||||
return isNaN(result) ? def : result;
|
||||
@@ -723,14 +643,14 @@ function WinItem() {
|
||||
}
|
||||
|
||||
function CompleteQuest() {
|
||||
QuestBar.reset(50 + Random(100));
|
||||
QuestBar.reset(50 + Random(1000));
|
||||
if (Quests.last().length) {
|
||||
Log('Quest completed: ' + Quests.last().text());
|
||||
Quests.rows().find("input:checkbox").attr("checked", "true");
|
||||
[WinSpell,WinEquip,WinStat,WinItem][Random(4)]();
|
||||
}
|
||||
while (Quests.length() > 99)
|
||||
Quests.remove(0);
|
||||
Quests.remove0();
|
||||
|
||||
game.questmonster = '';
|
||||
var caption;
|
||||
@@ -847,7 +767,7 @@ function CompleteAct() {
|
||||
game.act += 1;
|
||||
PlotBar.reset(60 * 60 * (1 + 5 * game.act)); // 1 hr + 5/act
|
||||
while (Plots.length() > 99)
|
||||
Plots.remove(0);
|
||||
Plots.remove0();
|
||||
Plots.AddUI((game.bestplot = 'Act ' + toRoman(game.act)));
|
||||
|
||||
if (game.act > 1) {
|
||||
@@ -917,11 +837,6 @@ function Sum(list) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Number.prototype.div = function (divisor) {
|
||||
var dividend = this / divisor;
|
||||
return (dividend < 0 ? Math.ceil : Math.floor)(dividend);
|
||||
};
|
||||
|
||||
|
||||
function LevelUp() {
|
||||
Add(Traits,'Level',1);
|
||||
@@ -1020,7 +935,6 @@ function FormCreate() {
|
||||
this.AddUI(i ? 'Act ' + toRoman(i) : "Prologue");
|
||||
|
||||
};
|
||||
Plots.save = function () {};
|
||||
|
||||
AllLists = [Traits,Stats,Spells,Equips,Inventory,Plots,Quests];
|
||||
|
||||
@@ -1056,12 +970,7 @@ function LoadCharacter() {
|
||||
storage = null;
|
||||
}
|
||||
|
||||
if (!sheet.Traits.Level) {
|
||||
// New game
|
||||
InitializeCharacter(sheet);
|
||||
} else {
|
||||
LoadGame(sheet);
|
||||
}
|
||||
|
||||
$("#title").text("Progress Quest - " + GameSaveName());
|
||||
|
||||
@@ -1119,6 +1028,11 @@ function Cheats() {
|
||||
WinItem();
|
||||
});
|
||||
|
||||
cheat("Clear items", function () {
|
||||
while (Inventory.length() > 1)
|
||||
Inventory.remove1();
|
||||
})
|
||||
|
||||
cheat("Spell", function () {
|
||||
WinSpell();
|
||||
});
|
||||
@@ -1163,7 +1077,7 @@ function HotOrNot() {
|
||||
|
||||
function SaveGame() {
|
||||
Log('Saving game: ' + GameSaveName());
|
||||
$.each(AllBars.concat(AllLists), function (i, e) { e.save(game); });
|
||||
$.each(AllBars, function (i, e) { e.save(game); });
|
||||
HotOrNot();
|
||||
game.date = ''+new Date();
|
||||
game.stamp = +new Date();
|
||||
@@ -1181,6 +1095,8 @@ function LoadGame(sheet) {
|
||||
this.rows().find("input:checkbox").not(':last').attr("checked", "true");
|
||||
});
|
||||
Log('Loaded game: ' + name);
|
||||
if (!game.elapsed)
|
||||
Brag('start');
|
||||
StartTimer();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,10 @@ var stats = {"history":[]};
|
||||
function RollEm() {
|
||||
var Total = $("#Total");
|
||||
stats.seed = randseed();
|
||||
stats.total =
|
||||
Roll("STR") +
|
||||
Roll("CON") +
|
||||
Roll("DEX") +
|
||||
Roll("INT") +
|
||||
Roll("WIS") +
|
||||
Roll("CHA");
|
||||
stats.total = 0;
|
||||
$.each(K.PrimeStats, function () { stats.total += Roll(this); });
|
||||
stats['HP Max'] = Random(8) + stats.CON.div(6);
|
||||
stats['MP Max'] = Random(8) + stats.INT.div(6);
|
||||
Total.text(stats.total);
|
||||
|
||||
var color =
|
||||
@@ -145,17 +142,43 @@ function sold() {
|
||||
Traits: {
|
||||
Name: $("#Name").val(),
|
||||
Race: $("input:radio[name=Race]:checked").val(),
|
||||
Class: $("input:radio[name=Class]:checked").val()
|
||||
Class: $("input:radio[name=Class]:checked").val(),
|
||||
Level: 1
|
||||
},
|
||||
dna: stats.seed,
|
||||
seed: stats.seed,
|
||||
birthday: ''+new Date(),
|
||||
birthstamp: +new Date(),
|
||||
Stats: {}
|
||||
Stats: stats,
|
||||
task: "",
|
||||
tasks: 0,
|
||||
elapsed: 0,
|
||||
bestequip: "Sharp Rock",
|
||||
Equips: {},
|
||||
Inventory: [['Gold', 0]],
|
||||
Spells: [],
|
||||
act: 0,
|
||||
Quests: [],
|
||||
questmonster: "",
|
||||
kill: "Loading....",
|
||||
ExpBar: { position: 0, max: LevelUpTime(1) },
|
||||
EncumBar: { position: 0, max: stats.STR + 10 },
|
||||
PlotBar: { position: 0, max: 26 },
|
||||
QuestBar: { position: 0, max: 1 },
|
||||
TaskBar: { position: 0, max: 2000 },
|
||||
queue: [
|
||||
'task|10|Experiencing an enigmatic and foreboding night vision',
|
||||
"task|6|Much is revealed about that wise old bastard you'd underestimated",
|
||||
'task|6|A shocking series of events leaves you alone and bewildered, but resolute',
|
||||
'task|4|Drawing upon an unexpected reserve of determination, you set out on a long and dangerous journey',
|
||||
'plot|2|Loading'
|
||||
],
|
||||
};
|
||||
$.each(K.Stats, function (index,value) {
|
||||
newguy.Stats[value] = stats[value];
|
||||
});
|
||||
|
||||
$.each(K.Equips, function (i,equip) { newguy.Equips[equip] = ''; });
|
||||
newguy.Equips.Weapon = newguy.bestequip;
|
||||
newguy.Equips.Hauberk = "-3 Burlap";
|
||||
|
||||
addToRoster(newguy);
|
||||
|
||||
// TODO: cheesy
|
||||
|
||||
Reference in New Issue
Block a user