• Welcome to Freedom Reborn Archive.
 

New Attribute: Power Reserve

Started by TaskMasterX, July 10, 2007, 01:37:15 PM

Previous topic - Next topic

TaskMasterX

Here's another one. With this attribute your character gets commands to boost one of the physical stats (strength, speed, agility, endurance)+2 points or to boost powers (get an attack bonus). When you boost something, you spend 33 Energy Points and lower your Energy -2 so you recharge slower. The boost and energy drain lasts 15 seconds after which all stats return to normal. You can only boost one thing at a time and can cancel it at any time while boosted. You can customize it with a dummy power and control what things your character can boost. For instance, if you only wanted a character who can boost agility or speed.
Here's the code for ffx.py:
############################## Power Reserve ######################################################
# Allows the character to boost one physical stat (Strength, Speed, Agility, or Endurance)
# +2 points or increase damage output of powers temporarily while lowering the Energy Stat
# -2 and by spending 33 points of Energy.
# -TaskmasterX
# Strings.txt Entries:
# ATTRIB_POWERRESERVE_01, power reserve
# ATTRIB_POWERRESERVE_DESC_01, you can temporarilty increase one physical stat at the cost of Energy.
# BOOST_STRENGTH_01, boost strength
# BOOST_STRENGTH_DESC_01, spend energy to increase strength
# BOOST_SPEED_01, boost speed
# BOOST_SPEED_DESC_01, spend energy to increase speed
# BOOST_AGILITY_01, boost agility
# BOOST_AGILITY_DESC_01, spend energy to increase agility
# BOOST_ENDURANCE_01, boost endurance
# BOOST_ENDURANCE_DESC_01, spend energy to increase endurance
# BOOST_POWERS_01, boost powers
# BOOST_POWERS_DESC_01, spend energy to increase damage from powers
# TURN_OFF_POWER_RESERVE_01, turn off power reserve
# TURN_OFF_POWER_RESERVE_DESC_01, stop using energy to increase a physical stat or damage output
###################################################################################################

def initpowerreserve(char,update):
    cmd1=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,2)
    cmd2=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,3)
    cmd3=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,4)
    cmd4=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,5)
    cmd5=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,6)
    objects = Mission_GetObjects()
    for obj in objects:
        if ((Object_GetClass(obj)&FFX_CHARACTER)!=0) & (obj==char):
            if cmd1!='':
                Mission_CustomAction(cmd1,char,char,'boostStr',5,0)
            if cmd2!='':
                Mission_CustomAction(cmd2,char,char,'boostSpd',5,0)
            if cmd3!='':
                Mission_CustomAction(cmd3,char,char,'boostAgl',5,0)
            if cmd4!='':
                Mission_CustomAction(cmd4,char,char,'boostEnd',5,0)
            if cmd5!='':
                Mission_CustomAction(cmd5,char,char,'boostPwr',5,0)

def boostStr(target,char):
    if chargeEP(char,33)==0:
        return
    Trigger_Power(char,target,getByTemplate(char,FFX_POWERRESERVE_CUSTOM,1),'')
    basestr=Object_GetAttr(char,'strength')
    newStrength=basestr+2
    Object_SetAttr(char,'strength',newStrength)
    str=Object_GetAttr(char,'strength')
    baseeng=Object_GetAttr(char,'energy')
    newEnergy=baseeng/2
    Object_SetAttr(char,'energy',newEnergy)
    eng=Object_GetAttr(char,'energy')
    FFX_ObjectSetAttr(char,'PRstr',1)
    RegTimer('playPREffect',1,0,char)
    cmd1=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,2)
    cmd2=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,3)
    cmd3=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,4)
    cmd4=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,5)
    cmd5=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,6)
    objects = Mission_GetObjects()
    for obj in objects:
        if ((Object_GetClass(obj)&FFX_CHARACTER)!=0) & (obj==char):
            Mission_CustomAction('TURN_OFF_POWER_RESERVE',char,char,'turnOffPR',5,0)
            removeCommand(cmd1,char)
            removeCommand(cmd2,char)
            removeCommand(cmd3,char)
            removeCommand(cmd4,char)
            removeCommand(cmd5,char)
    RegTimer('powerReserveOff',15,0,char)

def boostSpd(target,char):
    if chargeEP(char,33)==0:
        return
    Trigger_Power(char,target,getByTemplate(char,FFX_POWERRESERVE_CUSTOM,1),'')
    basespd=Object_GetAttr(char,'speed')
    newSpeed=basespd+2
    Object_SetAttr(char,'speed',newSpeed)
    spd=Object_GetAttr(char,'speed')
    baseeng=Object_GetAttr(char,'energy')
    newEnergy=baseeng/2
    Object_SetAttr(char,'energy',newEnergy)
    eng=Object_GetAttr(char,'energy')
    FFX_ObjectSetAttr(char,'PRspd',1)
    RegTimer('playPREffect',1,0,char)
    cmd1=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,2)
    cmd2=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,3)
    cmd3=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,4)
    cmd4=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,5)
    cmd5=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,6)
    objects = Mission_GetObjects()
    for obj in objects:
        if ((Object_GetClass(obj)&FFX_CHARACTER)!=0) & (obj==char):
            Mission_CustomAction('TURN_OFF_POWER_RESERVE',char,char,'turnOffPR',5,0)
            removeCommand(cmd1,char)
            removeCommand(cmd2,char)
            removeCommand(cmd3,char)
            removeCommand(cmd4,char)
            removeCommand(cmd5,char)
    RegTimer('powerReserveOff',15,0,char)

def boostAgl(target,char):
    if chargeEP(char,33)==0:
        return
    Trigger_Power(char,target,getByTemplate(char,FFX_POWERRESERVE_CUSTOM,1),'')
    baseagl=Object_GetAttr(char,'agility')
    newAgility=baseagl+2
    Object_SetAttr(char,'agility',newAgility)
    agl=Object_GetAttr(char,'agility')
    baseeng=Object_GetAttr(char,'energy')
    newEnergy=baseeng/2
    Object_SetAttr(char,'energy',newEnergy)
    eng=Object_GetAttr(char,'energy')
    FFX_ObjectSetAttr(char,'PRagl',1)
    RegTimer('playPREffect',1,0,char)
    cmd1=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,2)
    cmd2=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,3)
    cmd3=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,4)
    cmd4=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,5)
    cmd5=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,6)
    objects = Mission_GetObjects()
    for obj in objects:
        if ((Object_GetClass(obj)&FFX_CHARACTER)!=0) & (obj==char):
            Mission_CustomAction('TURN_OFF_POWER_RESERVE',char,char,'turnOffPR',5,0)
            removeCommand(cmd1,char)
            removeCommand(cmd2,char)
            removeCommand(cmd3,char)
            removeCommand(cmd4,char)
            removeCommand(cmd5,char)
    RegTimer('powerReserveOff',15,0,char)

def boostEnd(target,char):
    if chargeEP(char,33)==0:
        return
    Trigger_Power(char,target,getByTemplate(char,FFX_POWERRESERVE_CUSTOM,1),'')
    baseHealth = GetBaseHealth(char)
    maxHP=Object_GetAttr(char,'maxHealth')
    hp=Object_GetAttr(char,'health')
    FFX_ObjectSetAttr(char,'prMaxHP',maxHP)
    newMaxHP=getPRHealth(char)
    Object_SetAttr(char,'maxHealth',newMaxHP)
    hpBonus = newMaxHP - maxHP
    FFX_ObjectSetAttr(char,'prHPBonus',hpBonus)
    newHP = hp + hpBonus
    Object_SetAttr(char,'health',newHP)
    baseeng=Object_GetAttr(char,'energy')
    newEnergy=baseeng/2
    Object_SetAttr(char,'energy',newEnergy)
    eng=Object_GetAttr(char,'energy')
    FFX_ObjectSetAttr(char,'PRend',1)
    RegTimer('playPREffect',1,0,char)
    cmd1=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,2)
    cmd2=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,3)
    cmd3=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,4)
    cmd4=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,5)
    cmd5=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,6)
    objects = Mission_GetObjects()
    for obj in objects:
        if ((Object_GetClass(obj)&FFX_CHARACTER)!=0) & (obj==char):
            Mission_CustomAction('TURN_OFF_POWER_RESERVE',char,char,'turnOffPR',5,0)
            removeCommand(cmd1,char)
            removeCommand(cmd2,char)
            removeCommand(cmd3,char)
            removeCommand(cmd4,char)
            removeCommand(cmd5,char)
    RegTimer('powerReserveOff',15,0,char)

def boostPwr(target,char):
    if chargeEP(char,33)==0:
        return
    Trigger_Power(char,target,getByTemplate(char,FFX_POWERRESERVE_CUSTOM,1),'')
    attackBonus=Object_GetAttr(char,'attackBonus')
    Object_SetGenericState(char,OBJSTATE_ATTACKBONUS,15,0)
    attackBonus=Object_GetAttr(char,'attackBonus')
    baseeng=Object_GetAttr(char,'energy')
    newEnergy=baseeng/2
    Object_SetAttr(char,'energy',newEnergy)
    eng=Object_GetAttr(char,'energy')
    FFX_ObjectSetAttr(char,'PRpwr',1)
    cmd1=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,2)
    cmd2=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,3)
    cmd3=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,4)
    cmd4=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,5)
    cmd5=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,6)
    objects = Mission_GetObjects()
    for obj in objects:
        if obj==char:
            Mission_CustomAction('TURN_OFF_POWER_RESERVE',char,char,'turnOffPR',5,0)
            removeCommand(cmd1,char)
            removeCommand(cmd2,char)
            removeCommand(cmd3,char)
            removeCommand(cmd4,char)
            removeCommand(cmd5,char)
    RegTimer('powerReserveOff',15,0,char)

def getPRHealth(char):
    baseEnd = GetCharacterData(char)['endurance']+2
    if Object_GetClass(char) & OC_CONTROLLABLE:
        return int (( baseEnd**2 + baseEnd + 2 ) * 5 )
    else:
        diff6health = (15,30,60,105,165,480,660,870,1110,1380)
        diffdiv = (0, 9, 4, 3, 2, 1.5, 1, 0)
        return int(diff6health[baseEnd]/diffdiv[int(ff.RPG_GAME_DIFFICULTY)] )

def turnOffPR(target,char):
    FFX_ObjectSetAttr(char,'PRoffByCmd',1)
    RegTimer('powerReserveOff',.1,0,char)

def playPREffect(event):
    char=event.object
    if FFX_ObjectGetAttr(char,'PRoff')==1:
        FFX_ObjectSetAttr(char,'PRoff',0)
        return
    if FFX_ObjectGetAttr(char,'PRstr')==1:
        handle=Object_PlayEffect(char,'effect_ffxpurplestrength','',FX_TRACK_OBJECT_FULL)
        Object_SetAttr(char,'powerreserve_str',handle)
    if FFX_ObjectGetAttr(char,'PRspd')==1:
        handle=Object_PlayEffect(char,'effect_ffxpurplespeed','',FX_TRACK_OBJECT_FULL)
        Object_SetAttr(char,'powerreserve_spd',handle)
    if FFX_ObjectGetAttr(char,'PRagl')==1:
        handle=Object_PlayEffect(char,'effect_ffxabsorbenergy','',FX_TRACK_OBJECT_FULL)
        Object_SetAttr(char,'powerreserve_agl',handle)
    if FFX_ObjectGetAttr(char,'PRend')==1:
        handle=Object_PlayEffect(char,'effect_ffxabsorbstrength','',FX_TRACK_OBJECT_FULL)
        Object_SetAttr(char,'powerreserve_end',handle)
    RegTimer('playPREffect',1,0,char)

def powerReserveOff(event):
    char=event.object
    if FFX_ObjectGetAttr(char,'PRoffByCmdoff')==1:
        FFX_ObjectSetAttr(char,'PRoffByCmdoff',0)
        return
    if FFX_ObjectGetAttr(char,'PRoffByCmd')==1:
        FFX_ObjectSetAttr(char,'PRoffByCmd',0)
        FFX_ObjectSetAttr(char,'PRoffByCmdoff',1)
    FFX_ObjectSetAttr(char,'PRoff',1)
    eng=Object_GetAttr(char,'energy')*2
    Object_SetAttr(char,'energy',eng)
    if FFX_ObjectGetAttr(char,'PRstr')==1:
        str=Object_GetAttr(char,'strength')-2
        Object_SetAttr(char,'strength',str)
        str=Object_GetAttr(char,'strength')
        Object_StopEffect(char,Object_GetAttr(char,'powerreserve_str'))
        FFX_ObjectSetAttr(char,'PRstr',0)
    if FFX_ObjectGetAttr(char,'PRspd')==1:
        oldSpd=Object_GetAttr(char,'templateSpeed')
        Object_SetAttr(char,'speed',oldSpd)
        spd=Object_GetAttr(char,'speed')
        Object_StopEffect(char,Object_GetAttr(char,'powerreserve_spd'))
        FFX_ObjectSetAttr(char,'PRspd',0)
    if FFX_ObjectGetAttr(char,'PRagl')==1:
        agl=Object_GetAttr(char,'agility')-2
        Object_SetAttr(char,'agility',agl)
        agl=Object_GetAttr(char,'agility')
        Object_StopEffect(char,Object_GetAttr(char,'powerreserve_agl'))
        FFX_ObjectSetAttr(char,'PRagl',0)
    if FFX_ObjectGetAttr(char,'PRend')==1:
        oldMaxHP=FFX_ObjectGetAttr(char,'prMaxHP')
        hpBonus=FFX_ObjectGetAttr(char,'prHPBonus')
        Object_SetAttr(char,'maxHealth',oldMaxHP)
        hp=Object_GetAttr(char,'health')-hpBonus
        Object_SetAttr(char,'health',hp)
        Object_StopEffect(char,Object_GetAttr(char,'powerreserve_end'))
        FFX_ObjectSetAttr(char,'PRend',0)
    cmd1=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,2)
    cmd2=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,3)
    cmd3=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,4)
    cmd4=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,5)
    cmd5=getByTemplate(char,FFX_POWERRESERVE_CUSTOM,6)
    objects = Mission_GetObjects()
    for obj in objects:
        if obj==char:
            if cmd1!='':
                Mission_CustomAction(cmd1,char,char,'boostStr',5,0)
            if cmd2!='':
                Mission_CustomAction(cmd2,char,char,'boostSpd',5,0)
            if cmd3!='':
                Mission_CustomAction(cmd3,char,char,'boostAgl',5,0)
            if cmd4!='':
                Mission_CustomAction(cmd4,char,char,'boostEnd',5,0)
            if cmd5!='':
                Mission_CustomAction(cmd5,char,char,'boostPwr',5,0)
            removeCommand('TURN_OFF_POWER_RESERVE',char)


and the code for ffxcustom.py with some example lines:
### Power Reserve
FFX_POWERRESERVE_CUSTOM=[
["default","ffx_power_scan","BOOST_STRENGTH","BOOST_SPEED","BOOST_AGILITY","BOOST_ENDURANCE","BOOST_POWERS"],
["types","dDummyPower"],
["black adam","ffx_power_scan","BOOST_STRENGTH","BOOST_SPEED","","BOOST_ENDURANCE","BOOST_POWERS"],
["airwalker","ffx_power_scan","BOOST_STRENGTH","","BOOST_AGILITY","BOOST_ENDURANCE",""],
["annihilus","ffx_power_scan","BOOST_STRENGTH","","BOOST_AGILITY","BOOST_ENDURANCE",""],
["annihilus(in negative zone)","ffx_power_scan","BOOST_STRENGTH","","BOOST_AGILITY","BOOST_ENDURANCE",""],
]


Add an entry for powerreserve in FFEdit and the appropriate lines for the commands and descriptions in the strings.txt file nad Generate the Language Files in FFEdit.

GGiant

I have an error when I try using the attribute :(
error initialising attribute powerreserve.

stumpy

GGiant: That seems like the sort of error you'd get if you hadn't added the code to the ffx.py for the right mod or there was a bad cut-and-paste somewhere. If you aren't sure, you might put a print statement at the beginning of the init function to test that it is being attempted.

TMX, I can't quite see why you are looping through all the objects in the mission in the initpowerreserve() and boostXxx() code. It seems like you just want to add / remove the command to the one character with the attribute, right? Maybe I am misunderstanding how the attribute is supposed to work...

Also, it looks like the character's energy stat isn't reduced -2. It looks like it is cut in half and then doubles it again at the end. (And note possible roundoff issues for characters with odd-valued energy stats or with energy temporarily changed by other effects.)

BTW, it seems like there are lots of ffx attributes and powers that modify these stats and they often don't interact predictably. E.g. what happens if someone hit by a weaken or gravity increase attack uses this to boost his strength? Just a heads up.

Indigo

Am I just going to ffx.py, then copy-paste the whole code and it'll be available as one of the attributes?

Can you guys suggest any tool in opening ffx.py besides notepad, pls?

catwhowalksbyhimself

You also need to add it to FFEdit.

Epimethee


TaskMasterX

Thanks, Stumpy! Any advice you can give is very welcome. I'll take a look again at this and see if there was a reason I did it that way. I don't think there is. I think I got carried away with copy and pasting code and left things in that could have been removed and cleaned up. As for the Energy, I think I changed it to divide by 2 rather than subtract 2 because I wanted the Energy recharge to take a bigger hit while the character is in boosted mode. I'll play around with it and see how to get the right balance and test it with other Stat-Modifying-Attributes to make sure it works right.

GGiant

It says It can't Identify PRpwr.

stumpy

"It" what? What software says that? And, what exactly are you trying to do when you get that message?

Epimethee

FWIW, the variable PRpwr is set in boostPwr(), but it's the only place, so as far as I can see it doesn't change anything. And since there are other functions requiring that "char" bedefined before, it shouldn't cause errors. So... as Stumpy said, GGiant, you'll need to provide TaskmasterX with a clearer bug report. ;)