Making item quality effect its max health?

Started by Woyzeck, April 15, 2015, 09:40:52 PM

Previous topic - Next topic

Woyzeck

Anyone else tried doing this?

I added this to Stats_Weapons_Ranged and Stats_Apparel:

Quote<StatDef>
    <defName>MaxHealth</defName>
    <label>max health</label>
    <description>The maximum health of an object.</description>
    <category>Weapon</category>
    <parts>
      <li Class="StatPart_Quality">
        <factorAwful>0.60</factorAwful>
        <factorShoddy>0.80</factorShoddy>
        <factorPoor>0.90</factorPoor>
        <factorNormal>1</factorNormal>
        <factorGood>1.10</factorGood>
        <factorSuperior>1.20</factorSuperior>
        <factorExcellent>1.40</factorExcellent>
        <factorMasterwork>1.80</factorMasterwork>
        <factorLegendary>2.60</factorLegendary>
      </li>
    </parts>
  </StatDef>

Upside, it does indeed work to modify the max health of individual Things in-game.

The downside is that they still spawn within the range of their default health - i.e. if a type of gun has 100 MaxHealth in Weapons_Guns, a Legendary example will spawn with 100/260 health, tops. And an Awful example of the same gun can still spawn at 100/60.

Is there something other than "MaxHealth" I should be using in the defName?

BBream

#1
In my experience, you should apply this value yourself.

This code bring stat value and apply it.

...
public override void SpawnSetup()
{
       base.SpawnSetup();
       maxItem = (int)this.GetStatValue(DefDatabase<StatDef>.GetNamed("BackpackMaxItem"));
}


So if you want to set max health, then code like this:
but it is not tested!

public override void SpawnSetup()
{
       base.SpawnSetup();
this.def.statBases.Find((StatModifier statModifier) => (statModifier.stat == StatDefOf.MaxHitPoints && )).value = this.GetStatValue(StatDefOf.MaxHitPoints);
}


OH! I misunderstand...
In Core/Defs/StatDefs/Stats_Basics_General.xml
you can find this code:

  <StatDef>
    <defName>MaxHitPoints</defName>
    <label>max hit points</label>
    <description>The maximum hit points of an object. This represents how much damage it can take before being destroyed.</description>
    <category>BasicsNonPawn</category>
    <defaultBaseValue>100</defaultBaseValue>
    <minValue>1</minValue>
    <roundValue>true</roundValue>
    <toStringStyle>FloatZero</toStringStyle>
    <roundToFiveOver>200</roundToFiveOver>
  </StatDef>


Add your definition this line with new value. This will not affect already spawned item. But it is still constant. Item that has no hitpoint value cannot assign different value.

    <defaultBaseValue>100</defaultBaseValue>

mrofa

Wont this method change max health for every item that have this def name in entire game session(untill you restart the game client) ?
All i do is clutter all around.

BBream

#3
Quote from: mrofa on April 18, 2015, 10:44:31 AM
Wont this method change max health for every item that have this def name in entire game session(untill you restart the game client) ?

Yes, It will. Every item will be changed max health after loading game because this dll code will be placed in each items class.

mrofa

It might be my bad since i see you use statmodifier insted of statbase. So my earlier statement with a bit more explaning as a question ;p

If i do research that activate your code in game1, but then i load diffrent game save that dont have this research, will thsi code still be active ?

I did use statbase but they have the problem of being persistant, untill i restart the game client, so each game a load in current session of client, even without the reseaerch did have thier stat changed as if research was done.
All i do is clutter all around.

1000101

This behaviour will happen when modding any game.  That is, modifying core game data vs game session data.

Mods which want to do this sort of thing would need to also check that when the research *isn't* done that it needs to reset the value back to it's core value.  This way while the change will persist between saves, the newly loaded save will *reset* it until it should set it's modified value.

Basically just add an else case to your "if( myResearchDone )" which set's it back to the core value.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

mrofa

All i do is clutter all around.

1000101

It's creating an object instance in the game session, not a core object def in the game dictionary.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

BBream

Quote from: mrofa on April 18, 2015, 11:48:35 AM
It might be my bad since i see you use statmodifier insted of statbase. So my earlier statement with a bit more explaning as a question ;p

If i do research that activate your code in game1, but then i load diffrent game save that dont have this research, will thsi code still be active ?

I did use statbase but they have the problem of being persistant, untill i restart the game client, so each game a load in current session of client, even without the reseaerch did have thier stat changed as if research was done.

I think this code won't affect other loaded game. I don't modify defdatabase.
Game state            |  Rimworld is executing  |  item spawn               | modify thingDef if researched
DefDatabase  state |  Loaded                       | copy thingDef to item  |  Nothing to do   

If statBase changed in current session, then it will run like this.
Game state            |  still running                 |  loaded game             |  item spawn
DefDatabase  state | stored the modified stat |  Nothing to do            |  copy thingDef to item
Problem                                                                                             Already changed!!
                                                                     
So it will affect every game if you modify DefDatabase. But to make sure, I want to see your code.
I don't know how you change statBase. Have you changed DefDatabase by modifing xml file or item thingdef? Need more explain.

mrofa

I used it like this.
  thingDef1.SetStatBaseValue(StatDefOf.MaxHitPoints, 500f);
All i do is clutter all around.

mrofa

Tested your code in game and it works like my, its still persistant thrugh saves
All i do is clutter all around.

BBream

Quote from: mrofa on April 19, 2015, 03:44:30 AM
I used it like this.
  thingDef1.SetStatBaseValue(StatDefOf.MaxHitPoints, 500f);

I think you surely check researchManager.IsFinished().
Did you add code that if research is not finished then it set previous statbasevalue?

mrofa

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using RimWorld;
using Verse;

namespace Clutter
{
    public class MapComponent_ResearchUpdates : MapComponent
    {
        private int updateCounter;
        private bool ReinforcedResearchFlag = false;
       
        public override void MapComponentTick()
        {

            updateCounter--;
            if (updateCounter <= 0)
            {
                ReinforcedResearch();

                updateCounter = 250;
            }

        }

        private void ReinforcedResearch()
        {
            ThingDef thingDef1 = DefDatabase<ThingDef>.GetNamed("ClutterSIlverWall");
            ThingDef thingDef2 = DefDatabase<ThingDef>.GetNamed("ClutterReinforcedDoor");


            if (Find.ResearchManager.IsFinished(ResearchProjectDef.Named("WallReinforcmentHealth")) && !ReinforcedResearchFlag)
            {
                             
                thingDef1.SetStatBaseValue(StatDefOf.MaxHitPoints, 500f);
                thingDef1.SetStatBaseValue(StatDefOf.WorkToMake, 600f);
                thingDef2.SetStatBaseValue(StatDefOf.MaxHitPoints, 400f);
                thingDef2.SetStatBaseValue(StatDefOf.WorkToMake, 1300f);
               
                ReinforcedResearchFlag = true;

               
            }
            else if (thingDef1.GetStatValueAbstract(StatDefOf.MaxHitPoints) == 500 && !Find.ResearchManager.IsFinished(ResearchProjectDef.Named("WallReinforcmentHealth")))
            {
                thingDef1.SetStatBaseValue(StatDefOf.MaxHitPoints, 350);
                thingDef1.SetStatBaseValue(StatDefOf.WorkToMake, 300f);
                thingDef2.SetStatBaseValue(StatDefOf.MaxHitPoints, 250f);
                thingDef2.SetStatBaseValue(StatDefOf.WorkToMake, 650f);
            }
        }

         
       
    }
}



Yehh current version works, but i was just looking for a way that dont to restore base values, something like, stuff system that adds a offset to maxhealth with a nice label and that other stuff
All i do is clutter all around.

soltysek

yeah but i'm confusd whot are yut ppl try to achive change max health of bulding or item ??