Kitteh6660 / Corruption-of-Champions-Mod

CoC source from fenoxo, modded by Kitteh6660
233 stars 98 forks source link

[Feature] Long wait/rest #71

Closed openaz closed 9 years ago

openaz commented 9 years ago

Somewhere I came across note, that long wait (using shift key) might be implemented. So this might be helpful.

diff --git a/classes/classes/Scenes/Camp.as b/classes/classes/Scenes/Camp.as
index 3828e25..de03cfa 100644
--- a/classes/classes/Scenes/Camp.as
+++ b/classes/classes/Scenes/Camp.as
@@ -747,8 +747,8 @@ private function doCamp():void { //Only called by playerMenu
        addButton(8, "Masturbate", kGAMECLASS.masturbation.masturbateMenu);
        if (((player.findPerk(PerkLib.HistoryReligious) >= 0 && player.cor <= 66) || (player.findPerk(PerkLib.Enlightened) >= 0 && player.cor < 10)) && !(player.findStatusAffect(StatusAffects.Exgartuan) >= 0 && player.statusAffectv2(StatusAffects.Exgartuan) == 0) || flags[kFLAGS.SFW_MODE] >= 1) addButton(8, "Meditate", kGAMECLASS.masturbation.masturbateMenu);
    }
-   addButton(9, "Wait", doWait, null, null, null, "Wait for four hours.");
-   if (player.fatigue > 40 || player.HP / player.maxHP() <= .9) addButton(9, "Rest", rest, null, null, null, "Rest for four hours.");
+   addButton(9, "Wait", doWait, null, null, null, "Wait for four hours.\n\nShift click to wait for night.");
+   if (player.fatigue > 40 || player.HP / player.maxHP() <= .9) addButton(9, "Rest", rest, null, null, null, "Rest for four hours.\n\nShift click to rest until fully healed or night comes.");
    if (model.time.hours >= 21 || model.time.hours < 6) addButton(9, "Sleep", doSleep, null, null, null, "Turn yourself in for the night.");

    //Remove buttons according to conditions.
@@ -1507,18 +1507,51 @@ public function rest():void {
    }
    //Fatigue recovery
    var fatRecovery:Number = 4;
+   var hpRecovery:Number = 10;
    if (player.findPerk(PerkLib.SpeedyRecovery) >= 0) fatRecovery *= 1.5;
    if (player.findPerk(PerkLib.ControlledBreath) >= 0) fatRecovery *= 1.1;
    if (timeQ == 0) {
+
+       // Rest until fully healed
+       if (flags[kFLAGS.SHIFT_KEY_DOWN] == 1) {
+           // Calculate fatigue over 40, which is minimum for resting
+           var diffFatigue:Number = (player.fatigue < 40) ? 0 : player.fatigue - 40;
+           // Calculate missing hp to 90%, which is minimum for resting
+           var diffHp:Number = (player.HP / player.maxHP() < 0.9) ? ((player.maxHP() * 0.9) - player.HP) : 0;
+
+           // Marble's Milk affection reduces hp recovery by 50%
+           if (player.findStatusAffect(StatusAffects.MarbleWithdrawl) >= 0) { hpRecovery *= 0.5; }
+
+           // Rest until fully healed so we need maximum length of rest
+           timeQ = Math.round(Math.max(diffFatigue / fatRecovery / multiplier, diffHp / hpRecovery) / multiplier);
+
+           // Stop resting at 9pm as it's time to go sleep instead
+           if (timeQ > 21 - model.time.hours) {
+               timeQ = 21 - model.time.hours;
+           }
+       } // Regular rest for 4 hours
+       else {
+           timeQ = 4;
+       }
+
        if (flags[kFLAGS.CAMP_BUILT_CABIN] > 0 && flags[kFLAGS.CAMP_CABIN_FURNITURE_BED] > 0)
        {
-           outputText("You head into your cabin to rest. You lie down on your bed to rest for four hours.", false);
+           outputText("You head into your cabin to rest. You lie down on your bed to rest ", false);
+           if (timeQ == 4) {
+               outputText("for four hours.\n", false);
+           } else {
+               outputText("until fully healed.\n", false);
+           }
        }
        else 
        {
-           outputText("You lie down to rest for four hours.\n", false);
+           outputText("You lie down to rest ", false);
+           if (timeQ == 4) {
+               outputText("for four hours.\n", false);
+           } else {
+               outputText("until fully healed.\n", false);
+           }
        }
-       timeQ = 4;
        //Hungry
        if (flags[kFLAGS.HUNGER_ENABLED] > 0)
        {
@@ -1531,7 +1564,7 @@ public function rest():void {
        if(player.findStatusAffect(StatusAffects.MarbleWithdrawl) >= 0) {
            outputText("\nYour rest is very troubled, and you aren't able to settle down.  You get up feeling tired and unsatisfied, always thinking of Marble's milk.\n", false);

-           HPChange(timeQ * 5 * multiplier, true);
+           HPChange(timeQ * hpRecovery * multiplier, true);

            dynStats("tou", -.1, "int", -.1);
            //fatigue
@@ -1548,7 +1581,7 @@ public function rest():void {
        }
        //REGULAR HP/FATIGUE RECOVERY
        else {
-           HPChange(timeQ * 10 * multiplier, true);
+           HPChange(timeQ * hpRecovery * multiplier, true);
            //fatigue
            fatigue(-fatRecovery * timeQ * multiplier); 
        }
@@ -1569,10 +1602,15 @@ public function doWait():void {
    //Fatigue recovery
    var fatRecovery:Number = 2;
    if (player.findPerk(PerkLib.SpeedyRecovery) >= 0) fatRecovery *= 1.5;
-   if (player.findPerk(PerkLib.ControlledBreath) >= 0) fatRecovery *= 1.1;
    if(timeQ == 0) {
-       outputText("You wait four hours...\n", false);
-       timeQ = 4;
+       if (flags[kFLAGS.SHIFT_KEY_DOWN] == 1) {
+           outputText("You wait whole day...\n", false);
+           timeQ = 21 - model.time.hours;
+       } else {
+           outputText("You wait four hours...\n", false);
+           timeQ = 4;
+       }
+
        //Marble withdrawl
        if(player.findStatusAffect(StatusAffects.MarbleWithdrawl) >= 0) {
            outputText("\nYour time spent waiting is very troubled, and you aren't able to settle down.  You get up feeling tired and unsatisfied, always thinking of Marble's milk.\n", false);
openaz commented 9 years ago

Possible improvements I have in my mind:

  1. User defined sleep time (another alarm in cabin)
  2. Improved text - convert number to text to provide exact info instead of general text
Kitteh6660 commented 9 years ago

I'm currently working on this right now.

openaz commented 9 years ago

Whoops. Well, in this case, simply ignore this issue :) I was so bored when I did rapier training that it got priority for me. And calculating maximum relax time gave me quite headache