Announcement

Collapse
No announcement yet.

The old betleH Combat System (bCS)

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • The old betleH Combat System (bCS)

    I've been recently digging around my old website code, and my eventual goal is to get all of it up on GitHub. The betleH Tournament System (or bTS) is an extensive nightmare of now decade-old code, and most of it is wholly uninteresting anyways, but I'm fixing it for modern PHP (if anyone had visited betleh.org in the last few years, they'd have found most pages broken and it impossible to login) and to try and cap off some of the more egregious security flaws before making everything publicly visible.

    But there were two components I felt might be fun to share that some folks might enjoy, the betleH Combat System (bCS) and a requisite component of it, the Combat Stats Processor (CSP). Essentially the CSP took the biographical data people entered such as their characters' species, ages, heights, weights, years of combat training, honor in fighting, etc. and turned them into numbers more fitting a tabletop RPG combat system. I believe the bCS and CSP was written after reading from the Palladium system book, though a lot of liberties were taken, and most weighting for stats and combat values were by feel, not robust playtesting.

    If memory serves, I was not involved in running the numbers for betleH 6, this system was used for betleH 7 but I had to run matches manually with no solid logging strategy. If betleH 8 had occurred as originally scheduled, a fully logged match tracker would've been in place.

    Side note: It appears the forum has butched the line breaks in this code. Sorry. :/

    CSP:
    PHP Code:
       function run_csp($c_id)     {           $query="SELECT * FROM betleh_chars WHERE char_id = '$c_id'";     $result=mysql_query($query);           $str 0;     $spe 0;     $hp 0;     $atk 0;     $atkdef 0;     $numb 0;     $c_id=mysql_result($result,$qq,"char_id");     $c_name=mysql_result($result,$qq,"char_name");     $c_height=mysql_result($result,$qq,"height");     $c_weight=mysql_result($result,$qq,"weight");     $c_birthdate=mysql_result($result,$qq,"birthdate");     $age_offset=mysql_result($result,$qq,"age_offset");     $age_training=mysql_result($result,$qq,"age_training");     $freq_training=mysql_result($result,$qq,"freq_training");     $c_honor=mysql_result($result,$qq,"honor");     $c_species=mysql_result($result,$qq,"species");     $c_b1=mysql_result($result,$qq,"b1");     $c_b2=mysql_result($result,$qq,"b2");     $c_b3=mysql_result($result,$qq,"b3");     $c_b4=mysql_result($result,$qq,"b4");     $c_b5=mysql_result($result,$qq,"b5");     $c_b6=mysql_result($result,$qq,"b6");     $c_b7=mysql_result($result,$qq,"b7");     $c_age calcage($c_birthdate,$age_offset);           if ($age_training != 0)     $yrsxp $c_age $age_training;     else $yrsxp 0;           // These species have genetic memory so they get a few years tacked on.     if ($c_species == "Dracanian" || $c_species == "Trill (Joined)")     $yrsxp = $yrsxp + 10;           // These species are incredibly weak.     if ($c_species == "Commelinaceae" || $c_species == "Elaysian" || $c_species == "Ferengi")     $str = $str - 1;           // These species are semi-strong.     if ($c_species == "Cardassian" || $c_species == "Hadian" || $c_species == "Hirogen" || $c_species == "Klingon")     $str = $str + 1;           // This gives hybrids of strong species a slight bonus.     if ($c_species != "Dracanian" && $c_species != "Gorn" && $c_species != "Polar Bear" && $c_species != "Romulan" && $c_species != "Saurian" && $c_species != "Vulcan")     {     if (substr_count($c_species, "Dracanian") > 0 || substr_count($c_species, "Gorn") > 0 || substr_count($c_species, "Polar Bear") > 0 || substr_count($c_species, "Romulan") > 0 || substr_count($c_species, "Saurian") > 0 || substr_count($c_species, "Vulcan") > 0)     $str = $str + 1;     }           // These species are strong.     if ($c_species == "Dracanian" || $c_species == "Gorn" || $c_species == "Polar Bear" || $c_species == "Romulan" || $c_species == "Saurian" || $c_species == "Vulcan")     $str = $str + 2;           $hp = $c_weight;     $hp = ( -0.001 * $hp * $hp ) + ( 1.11 * $hp ) + 5.3;     if ($c_height >= 72 && $c_height <= 78) $spe = $spe + 1;     if ($c_height >= 79) $spe = $spe + 2;           if ($c_weight >= 200 && $c_weight <= 249) $spe = $spe - 1;     if ($c_weight >= 250 && $c_weight <= 299) $spe = $spe - 2;     if ($c_weight >= 300) $spe = $spe - 3;           if ($c_weight >= 1 && $c_weight <= 100) $str = $str + 1;     if ($c_weight >= 101 && $c_weight <= 150) $str = $str + 2;     if ($c_weight >= 151 && $c_weight <= 175) $str = $str + 3;     if ($c_weight >= 176 && $c_weight <= 200) $str = $str + 4;     if ($c_weight >= 201 && $c_weight <= 250) $str = $str + 5;     if ($c_weight >= 251 && $c_weight <= 300) $str = $str + 6;     if ($c_weight >= 301) $str = $str + 7;           if ($freq_training == 26) {     $spe = $spe + 1;     $atkdef = $atkdef + 1;}     if ($freq_training == 14) {     $spe = $spe + 2;     $atkdef = $atkdef + 2;}     if ($freq_training == 25) {     $spe = $spe + 3;     $atkdef = $atkdef + 3;}     if ($freq_training == 13) {     $spe = $spe + 4;     $atkdef = $atkdef + 4;}           if ($c_honor == 30) $atk = $atk + 2;     if ($c_honor == 18) $atk = $atk + 1;     if ($c_honor == 29) $atk = $atk - 1;     if ($c_honor == 17) $atk = $atk - 2;           if ($c_age < 40) $str = $str + 1;     if ($c_age < 30) $str = $str + 2;           if ($yrsxp >= 6 && $yrsxp <= 10) $atkdef = $atkdef + 1;     if ($yrsxp >= 11 && $yrsxp <= 15) $atkdef = $atkdef + 2;     if ($yrsxp >= 16 && $yrsxp <= 20) $atkdef = $atkdef + 3;     if ($yrsxp >= 21) $atkdef = $atkdef + 4;           if ($c_b1 == "C") $numb++;     if ($c_b2 == "C") $numb++;     if ($c_b3 == "C") $numb++;     if ($c_b4 == "C") $numb++;     if ($c_b5 == "C") $numb++;     if ($c_b6 == "C") $numb++;     if ($c_b7 == "C") $numb++;           if ($numb == 1) $atkdef++;     if ($numb > 1) $atkdef = $atkdef + 2;           if(mysql_num_rows(mysql_query("SELECT char_id FROM betleh_combatants WHERE char_id = '$c_id'")) > 0){     $query="UPDATE betleh_combatants SET health='$hp', strength='$str', speed='$spe', atkdefroll='$atkdef', atkroll='$atk' WHERE char_id='$c_id'";     }       else     {     $query = "INSERT INTO betleh_combatants (char_id, health, strength, speed, atkdefroll, atkroll) VALUES('$c_id', '$hp', '$str', '$spe', '$atkdef', '$atk')";     }     mysql_query($query);        } 


    bCS:

    PHP Code:
       function run_bcs($c1id,$c2id,$mode)     {           echo "bCS 1.1.0<p>";           $query="SELECT * FROM betleh_combatants WHERE char_id='$c1id'";     $result=mysql_query($query);           $char1_id mysql_result($result,$mm,"char_id");     $char1_name getcharname($char1_id);     $char1_hp mysql_result($result,$mm,"health");     $char1_ohp $char1_hp;     $char1_str mysql_result($result,$mm,"strength");     $char1_spe mysql_result($result,$mm,"speed");     $char1_atk mysql_result($result,$mm,"atkroll");     $char1_atkdef mysql_result($result,$mm,"atkdefroll");           $query="SELECT * FROM betleh_combatants WHERE char_id='$c2id'";     $result=mysql_query($query);           $char2_id mysql_result($result,$mm,"char_id");     $char2_name getcharname($char2_id);     $char2_hp mysql_result($result,$mm,"health");     $char2_ohp $char2_hp;     $char2_str mysql_result($result,$mm,"strength");     $char2_spe mysql_result($result,$mm,"speed");     $char2_atk mysql_result($result,$mm,"atkroll");     $char2_atkdef mysql_result($result,$mm,"atkdefroll");           if ($mode == "o")     {     echo "<table><tr><td>$char1_name<br>HP: $char1_hp<br>STR: $char1_str<br>SPE: $char1_spe<br>WPS: $char1_atkdef<br>HNR: $char1_atk</td><td>$char2_name<br>HP: $char2_hp<br>STR: $char2_str<br>SPE: $char2_spe<br>WPS: $char2_atkdef<br>HNR: $char2_atk</td></tr></table><p>";     }           //initrolls     $char1_init = rand(1, 20) + $char1_spe;     $char2_init = rand(1, 20) + $char2_spe;     if ($mode == "o")     {     echo "$char1_name rolls $char1_init.<br>$char2_name rolls $char2_init.<p>";     }     if ($char1_init == $char2_init)     {     $reroll = rand(1,2);     if ($reroll == 1)     {$char1_init++;}     else     {$char2_init++;}     }           //AssignChars     if ($char2_init > $char1_init)     {     $defchar_id = $char1_id;     $defchar_name = $char1_name;     $defchar_hp = $char1_hp;     $defchar_ohp = $char1_ohp;     $defchar_str = $char1_str;     $defchar_spe = $char1_spe;     $defchar_atk = $char1_atk;     $defchar_atkdef = $char1_atkdef;     $atkchar_id = $char2_id;     $atkchar_name = $char2_name;     $atkchar_hp = $char2_hp;     $atkchar_ohp = $char2_ohp;     $atkchar_str = $char2_str;     $atkchar_spe = $char2_spe;     $atkchar_atk = $char2_atk;     $atkchar_atkdef = $char2_atkdef;     $fightstring = "2";     }     if ($char2_init < $char1_init)     {     $defchar_id = $char2_id;     $defchar_name = $char2_name;     $defchar_hp = $char2_hp;     $defchar_ohp = $char2_ohp;     $defchar_str = $char2_str;     $defchar_spe = $char2_spe;     $defchar_atk = $char2_atk;     $defchar_atkdef = $char2_atkdef;     $atkchar_id = $char1_id;     $atkchar_name = $char1_name;     $atkchar_hp = $char1_hp;     $atkchar_ohp = $char1_ohp;     $atkchar_str = $char1_str;     $atkchar_spe = $char1_spe;     $atkchar_atk = $char1_atk;     $atkchar_atkdef = $char1_atkdef;     $fightstring = "1";     }     echo "$atkchar_name is attacking first.<p>";                 do {           $crityes = "";     $atkroll = rand(1,20) + $atkchar_atkdef + $atkchar_atk;     $defroll = rand(1,20) + $defchar_atkdef;     if ($mode == "o")     {     echo "$atkchar_name rolls an attack roll of $atkroll<br>$defchar_name rolls a defense roll of $defroll<br>";     }     else     {     echo "$atkchar_name rolls to attack.<br>$defchar_name rolls to block.<br>";     }     if ($atkroll > $defroll)     {     $dmgroll1 = rand(1,20);     $dmgroll2 = $dmgroll1 + $atkchar_str + 5;     if ($dmgroll1 == 20) {     $dmgroll2 = $dmgroll2 * 3;     $crityes = " (critical)";     $fightstring = $fightstring . "c";     }     else     {     $fightstring = $fightstring . "h";     }     $defchar_hp = $defchar_hp - $dmgroll2;     if ($mode == "o")     echo "$atkchar_name hits $defchar_name for $dmgroll2. $crityes<br>$defchar_name's health is reduced to $defchar_hp<p>";     else     echo "$atkchar_name hits $defchar_name. $crityes<br>$defchar_name's health is reduced.<p>";     }     else     {     echo "$atkchar_name's attack is blocked.<p>";     $fightstring = $fightstring . "b";     }           $tmp_id = $atkchar_id;     $tmp_name = $atkchar_name;     $tmp_hp = $atkchar_hp;     $tmp_ohp = $atkchar_ohp;     $tmp_str = $atkchar_str;     $tmp_spe = $atkchar_spe;     $tmp_atk = $atkchar_atk;     $tmp_atkdef = $atkchar_atkdef;     $atkchar_id = $defchar_id;     $atkchar_name = $defchar_name;     $atkchar_hp = $defchar_hp;     $atkchar_ohp = $defchar_ohp;     $atkchar_str = $defchar_str;     $atkchar_spe = $defchar_spe;     $atkchar_atk = $defchar_atk;     $atkchar_atkdef = $defchar_atkdef;     $defchar_id = $tmp_id;     $defchar_name = $tmp_name;     $defchar_hp = $tmp_hp;     $defchar_ohp = $tmp_ohp;     $defchar_str = $tmp_str;     $defchar_spe = $tmp_spe;     $defchar_atk = $tmp_atk;     $defchar_atkdef = $tmp_atkdef;           } while ($atkchar_hp > 0 && $defchar_hp > 0);           if ($atkchar_hp > 0) {     $winchar_id = $atkchar_id;     $winchar_name = $atkchar_name;     $winchar_hp = $atkchar_hp;     $winchar_ohp = $atkchar_ohp;     $winchar_hnr = $atkchar_atk;     $winchar_str = $atkchar_str;     $winchar_spe = $atkchar_spe;     $winchar_wps = $atkchar_atkdef;     $losechar_id = $defchar_id;     $losechar_name = $defchar_name;     $losechar_hp = $defchar_hp;     $losechar_ohp = $defchar_ohp;     $losechar_hnr = $defchar_atk;     $losechar_str = $defchar_str;     $losechar_spe = $defchar_spe;     $losechar_wps = $defchar_atkdef;     }     if ($defchar_hp > 0) {     $winchar_id = $defchar_id;     $winchar_name = $defchar_name;     $winchar_hp = $defchar_hp;     $winchar_ohp = $defchar_ohp;     $winchar_hnr = $defchar_atk;     $winchar_str = $defchar_str;     $winchar_spe = $defchar_spe;     $winchar_wps = $defchar_atkdef;     $losechar_id = $atkchar_id;     $losechar_name = $atkchar_name;     $losechar_hp = $atkchar_hp;     $losechar_ohp = $atkchar_ohp;     $losechar_hnr = $atkchar_atk;     $losechar_str = $atkchar_str;     $losechar_spe = $atkchar_spe;     $losechar_wps = $atkchar_atkdef;     }           echo "$winchar_name is still standing!<br>";     if ($winchar_id == $char1_id)     $standing = "1";     if ($winchar_id == $char2_id)     $standing = "2";           if ($winchar_hnr > 0 && $losechar_hp < -14)     {     echo "$winchar_name has been disqualified! $losechar_name is awarded the win!";     if ($losechar_id == $char1_id)     $win = "1";     $condition = "d";     if ($losechar_id == $char2_id)     $win = "2";     $condition = "d";     }     else     {     if ($winchar_id == $char1_id)     $win = "1";     if ($winchar_id == $char2_id)     $win = "2";     if ($winchar_hp >= (0.4 * $winchar_ohp))     {     $condition = "e";     echo "$winchar_name wins easily!";     }     if ($winchar_hp > (0.25 * $winchar_ohp) && $winchar_hp < (0.4 * $winchar_ohp))     {     $condition = "s";     echo "$winchar_name has won!";     }     if ($winchar_hp <= (0.25 * $winchar_ohp))     {     $condition = "c";     echo "$winchar_name wins in a close match!";     }     }           $fightstring = $standing . $win . $condition . "-" . $fightstring;           if ($mode == "o")     echo "<p>Log String: $fightstring";           return $fightstring;  } 
    Last edited by Soraya Xel; 01-09-2019, 11:35 PM.

  • #2
    Awesome! Great to see this code still is alive!

    Comment


    • #3
      Originally posted by BlackWolf View Post
      Awesome! Great to see this code still is alive!
      "Alive" is a relative term. But archival and long-term availability has always been important to me on the web. I've gotten away from it from time to time, but I want to ensure all of this stuff stays out there long term, so a couple patches here and there to keep it going is worthwhile.

      There's actually a long story about the ways this code would've been extended had history unfolded differently. bTS was my first really extensive PHP platform, and shortly afterwards, I wrote a platform I call XRF which has a lot of improvements. I actually have some pieces of code lying around that was intended to migrate the data in bTS over to a set of XRF modules that I had loosely sketched out. XRF could be extended out to a Nova-ish simming platform, or something akin to the BFMS (massive tip of the hat to JonM for that system), or whatever else. Digging back in has reminded me of a lot of history.
      Last edited by Soraya Xel; 01-11-2019, 04:09 PM. Reason: LOL, that word censor.

      Comment

      Working...
      X