public function test_get_total_weight()
 {
     $x = new CharacterSheet($this->dbObj, __METHOD__, 1);
     $this->assertTrue(is_numeric($x->characterId), ToolBox::debug_print($x));
     $this->assertEquals(0, $x->get_total_weight(false));
     $this->assertEquals($x->get_total_weight(true), $x->get_total_weight(false));
     //now create some gear.
     $manualWeight = 0;
     $itemList = array();
     $createThis = array(array('torches', 1, 10), array('lead nuggets', 10, 10), array('misc', 4, 200));
     $g = new Gear();
     $g->characterId = $x->characterId;
     foreach ($createThis as $data) {
         $manualWeight += round($data[1] * $data[2], 1);
         $xData = array('character_id' => $x->characterId, 'gear_name' => $data[0], 'weight' => $data[1], 'quantity' => $data[2]);
         $id = $g->create($this->dbObj, $xData);
         $itemList[$id] = $xData;
     }
     $this->assertEquals($manualWeight, Gear::calculate_list_weight($itemList));
     //now, at first, this should be 0 because we haven't re-loaded the sheet.
     $this->assertEquals(0, $x->get_total_weight(false));
     $this->assertEquals(0, $x->get_total_weight(true));
     $x->load();
     $this->assertEquals($manualWeight, $x->get_total_weight(false));
     $this->assertEquals($manualWeight, $x->get_total_weight(true));
     $withWeapons = $manualWeight;
     $w = new Weapon();
     $w->characterId = $x->characterId;
     $wpns = array('great_sword' => 5, 'long_sword' => 2, 'short_sword' => 1);
     foreach ($wpns as $name => $wgt) {
         $xData = array('character_id' => $x->characterId, 'weapon_name' => $name, 'weight' => $wgt);
         $id = $w->create($this->dbObj, $xData);
         $itemList[$id] = $xData;
         $withWeapons += $wgt;
     }
     $x->load();
     $this->assertNotEquals($manualWeight, $withWeapons);
     $this->assertTrue($withWeapons > $manualWeight);
     $this->assertEquals($manualWeight, $x->get_total_weight(false));
     $this->assertEquals($x->get_total_weight(), $x->get_total_weight(false));
     $this->assertEquals($withWeapons, $x->get_total_weight(true));
     $withArmor = $withWeapons;
     $a = new Armor();
     $rmr = array('big' => 10, 'small' => 1);
     foreach ($rmr as $name => $wgt) {
         $xData = array('character_id' => $x->characterId, 'armor_name' => $name, 'weight' => $wgt);
         $id = $a->create($this->dbObj, $xData);
         $itemList[$id] = $xData;
         $withArmor += $wgt;
     }
     $x->load();
     $this->assertNotEquals($manualWeight, $withArmor);
     $this->assertTrue($withArmor > $withWeapons);
     $this->assertEquals($manualWeight, $x->get_total_weight(false));
     $this->assertEquals($x->get_total_weight(), $x->get_total_weight(false));
     $this->assertEquals($withArmor, $x->get_total_weight(true));
 }
 public function get_sheet_data()
 {
     //NOTE: there's a lot of unset() and renames that are present simply for comparing old functionality to new.
     if (!is_array($this->_abilities)) {
         $this->load();
     }
     $retval = array();
     foreach ($this->_char->data as $idx => $v) {
         $sheetId = $this->create_sheet_id('main', $idx);
         $retval[$sheetId] = $v;
     }
     $retval = array_merge($retval, $this->get_misc_data());
     $sk = new Skill();
     $retval[Sskill::sheetIdPrefix] = $sk->get_sheet_data($this->dbObj, $this->characterId);
     $_saves = new Save();
     $retval[$_saves::sheetIdPrefix] = $_saves->get_sheet_data($this->dbObj, $this->characterId);
     $ab = new Ability();
     $retval[Ability::sheetIdPrefix] = $ab->get_sheet_data($this->dbObj, $this->characterId);
     foreach ($this->_abilities as $k => $data) {
         $retval[Ability::sheetIdPrefix . '__' . $k . '_score'] = $data['ability_score'];
         $retval[Ability::sheetIdPrefix . '__' . $k . '_modifier'] = Ability::calculate_ability_modifier($data['ability_score']);
     }
     $armor = new Armor();
     $retval['characterArmor'] = $armor->get_sheet_data($this->dbObj, $this->characterId);
     $wpn = new Weapon();
     $retval[$wpn::sheetIdPrefix] = $wpn->get_sheet_data($this->dbObj, $this->characterId);
     $specialAbilities = new SpecialAbility();
     $retval[$specialAbilities::sheetIdPrefix] = $specialAbilities->get_sheet_data($this->dbObj, $this->characterId);
     $gear = new Gear();
     $retval[$gear::sheetIdPrefix] = $gear->get_sheet_data($this->dbObj, $this->characterId);
     $retval[$gear::sheetIdPrefix . '__total_weight__generated'] = Gear::calculate_list_weight($gear->get_all($this->dbObj, $this->characterId));
     foreach ($this->get_strength_stats() as $k => $v) {
         $retval[$this->create_sheet_id('generated', $k)] = $v;
     }
     return $retval;
 }