{ // OOP-Setup, thanks to Florian Rappl for this piece of Code // Source: // http://www.florian-rappl.de/Articles/Page/116/super-mario5-article var reflection = {}; (function(){ var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; // The base Class implementation (does nothing) this.Class = function(){ }; // Create a new Class that inherits from this class Class.extend = function(prop, ref_name) { if(ref_name) reflection[ref_name] = Class; var _super = this.prototype; // Instantiate a base class (but only create the instance, // don't run the init constructor) initializing = true; var prototype = new this(); initializing = false; // Copy the properties over onto the new prototype for (var name in prop) { // Check if we're overwriting an existing function prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn) { return function() { var tmp = this._super; // Add a new ._super() method that is the same method // but on the super-class this._super = _super[name]; // The method only need to be bound temporarily, so we // remove it when we're done executing var ret = fn.apply(this, arguments); this._super = tmp; return ret; }; })(name, prop[name]) : prop[name]; } // The dummy class constructor function Class() { // All construction is actually done in the init method if ( !initializing && this.init ) this.init.apply(this, arguments); } // Populate our constructed prototype object Class.prototype = prototype; // Enforce the constructor to be what we expect Class.prototype.constructor = Class; // And make this class extendable Class.extend = arguments.callee; return Class; }; })(); // Helper-Funcs var clearoutput = function() { $('#output').empty(); }; var clearui = function() { $('#output').empty(); $('#ui').empty(); }; // Probe-Function: checks, whether a given "effort" is succesfull, according to the rules of DS // Not yet implemented: Tests for values larger than 20 var dice = function(probe) { var diceval=new Array(); var rolls=Math.floor(probe/20)+1; // Player may be allowed to roll the dice several times. var tvalues=new Array(); var result=0; var tmpval; for(var i=0; i"); var attack_val = dice(this.battle[this.att]); if (attack_val == 0 ) { output.append('Angriff Fehlgeschlagen!
'); } else { output.append(this.info.cname + " trifft mit " + attack_val + "
"); if ( this.defendible ) { var defense_val = dice(this.battle.defense); console.log(attack_val + ", " + defense_val); attack_val -= defense_val; attack_val = Math.max(attack_val, 0); if ( ! defense_val ) { output.append(enem.info.cname + " kann sich nicht wehren!
"); } else { output.append(enem.info.cname + " wehrt sich mit " + defense_val+".
"); } if ( attack_val === 0 ) { output.append("Vollständig Abgewehrt!
"); return; } } else { output.append("Nicht abwehrbar!
"); }; output.append("Schaden: "+attack_val+"
"); enem.life -= attack_val; // If an "enemie" dies, he should really die, a player-char should only get "unconcious" if( enem.life <= 0 ) { if ( enem.enem ){ output.append(enem.info.cname + " ist besiegt
"); enem.die(); } else { output.append(enem.info.cname + " ist bewusstlos
"); enem.unconsc(); }; } } }, calc_battle_base: function() { // This is given by DS-Rules this.battle_base["life"] = this.attributes.body + this.properties.strength + 10;; this.battle_base["defense"] = this.attributes.body + this.properties.hardness; this.battle_base["ini"] = this.attributes.agility + this.properties.movement; this.battle_base["walk"] = (this.attributes.agility / 2) +1; this.battle_base["melee"] = this.attributes.body + this.properties.strength; this.battle_base["shoot"] = this.attributes.agility + this.properties.mind; this.battle_base["chant"] = this.attributes.spirit + this.properties.aura; this.battle_base["shoot_chant"] = this.attributes.spirit + this.properties.skill; }, // The next three funcs are self-explaining die: function() { this.graphelement.destroy(); delete(player[this.info.pname]); }, unconsc: function() { this.graphelement.oldcolor = this.graphelement.color(); this.graphelement.color("#A0A0C0"); }, consc: function() { if ( this.graphelement.oldcolor ) { this.graphelement.color(this.graphelement.oldcolor); } }, // Write out the UI for attack-selection, including binding. sel_att: function() { var outstr="

"; outstr += "Angriffstyp?
"; outstr += "
"; outstr += "Abwehrbar? "; outstr += "
"; outstr += "Waffenbonus Fernkampf:
"; outstr += "Panzerungsbonus:
"; outstr += "Zauberbonus:
"; $('#uibon').html(outstr); $('.bon').bind("change", function() { cur_sel.extern.weapon_near = $('#wbn').val()*1; cur_sel.extern.weapon_far = $('#wbf').val()*1; cur_sel.extern.armor = $('#pb').val()*1; cur_sel.extern.chant = $('#zb').val()*1; cur_sel.recalc_battle(); cur_sel.sel_att(); cur_sel.printoutput(); }); $('#wbn').attr("value", cur_sel.extern.weapon_near+""); $('#wbf').attr("value", cur_sel.extern.weapon_far); $('#pb').attr("value",cur_sel.extern.armor); $('#zb').attr("value",cur_sel.extern.chant); }, printoutput: function() { outstr = "

"; outstr += this.info.cname + " (gespielt von "+this.info.pname +")
"; outstr += "Greift derzeit durch " + this.att + " mit einer Stärke von " + this.battle[this.att] + " an.
"; outstr += "Ist "+this.calc_dist()+"m von der alten Position entfernt (max ??)
"; outstr += "Verteidigungsstärke: " + this.battle.defense + "
"; outstr += "Kraftpunkte: " + this.life; outstr += "

"; $('#output').html(outstr); } }); var Beast = Creature.extend({ init: function(info,attributes,properties,drawinfo,battle){ /* Additional to Creature, a Beast has: * Cname for compability reasons in some functions, set to match pname * the "enem"-bool, specifying it as an enemy that really dies * A print-function as in Player */ this._super(info,attributes,properties,drawinfo,battle); this.info.cname=this.info.pname; this.enem = true; }, printoutput: function() { clearoutput(); outstr = "

"; outstr += "Ein "+ this.info.race + "
"; outstr += "Greift derzeit durch " + this.att + " mit einer Stärke von " + this.battle[this.att] + " an.
"; outstr += "Ist "+this.calc_dist()+"m von der alten Position entfernt (max ??)
"; outstr += "Verteidigungsstärke: " + this.battle.defense + "
"; outstr += "Kraftpunkte: " + this.life; outstr += "

"; $('#output').html(outstr); } }); }