AtomicTorch Studio Forums

CryoFall => Modding info => Topic started by: Formifer on June 05, 2019, 02:14:00 PM

Title: Q&A Useful to other modders
Post by: Formifer on June 05, 2019, 02:14:00 PM
First Q
-----------------------

Alright a summary of what i want to do for the power armor - Determine how much energy is currently in the equipped player, and have a indicator if energy is running low, have lights on the suit that are directly determined by if the suit is powered or not (I have so far setup a powered Boolean for this), the suit will also need to update its Protection depending on if its on or not.

questions below on this

- How do i see if the item is equipped (as im unsure as to how to do this yet)

- How do i have the item able to see how much energy is on the equipped player

- How do i attach lighting onto the suit that doesnt revolve around the LightedHelmet Script (is it just the skeleton rig code, or is there more needed)

- Is PrepareEffects run every interval, or should i apply the defence and movement changes under ServerUpdate, and if i should use ServerUpdate is there any specific way i should do this (This is a 2 state system using the Added Boolean for if suit power is on or off).

-  How would i have the suit give a warning to the player that there energy is low.

- What is the best method (in coding terms) to apply the energy drain within ServerUpdate, and is this the correct application for 1 second intervals:
                     public override double ServerUpdateIntervalSeconds => 1;

(AI_Enabled, will reply on this first Q when he gets the time to do so, any modder intrested in these current Q's should keep this thread marked as intrested - if thats possible on this forum)
Title: Re: Q&A Useful to other modders
Post by: ai_enabled on June 06, 2019, 09:39:49 AM
Hello!

Quote- How do i see if the item is equipped (as im unsure as to how to do this yet)
Every item has a Container property, every container property has an Owner property.
If there is a character owner, you can get its equipment container and compare it with the item's Container property value.
You need to keep in mind than offline players usually expect that items will not use any energy.
For example: (server update method in the item class)

protected override void ServerUpdate(ServerUpdateData data)
{
    base.ServerUpdate(data);

    var item = data.GameObject;
    var owner = item.Container.OwnerAsCharacter;
    if (owner == null
        || !owner.IsOnline)
    {
        // not owned by player character or player is offline
        return;
    }

    if (owner.SharedGetPlayerContainerEquipment() != item.Container)
    {
        // not in the owner character's equipment
        return;
    }

    var energyUsePerSecond = 1.0;
    CharacterEnergySystem.ServerDeductEnergyCharge(owner,
                                                   requiredEnergyAmount: energyUsePerSecond * data.DeltaTime);
}


Quote- How do i have the item able to see how much energy is on the equipped player
Please see public static methods of this class ΓÇö CharacterEnergySystem.

Quote- How do i attach lighting onto the suit that doesnt revolve around the LightedHelmet Script (is it just the skeleton rig code, or is there more needed)
Every equipable item has a method ClientSetupSkeleton which allows you to add extra components to the character skeleton. You can use it to add light source based on whether the item is in active state or not. Please see ProtoItemEquipmentHeadWithLight class, ClientSetupSkeleton method.

Quote- Is PrepareEffects run every interval, or should i apply the defence and movement changes under ServerUpdate, and if i should use ServerUpdate is there any specific way i should do this (This is a 2 state system using the Added Boolean for if suit power is on or off).
Prepare effects method is invoked only once per item type (during the game initialization) and it allows you to fill the "effects cache" of the item (a single array with all the effects predefined). Whether the effects apply or not, depends on the virtual method SharedCanApplyEffects. For example, you could override it this way for your power armor:
public override bool SharedCanApplyEffects(IItem item, IItemsContainer containerEquipment)
{       
    // determine whether the item is in active state or whether player has enough energy
    if (...)
    {
         // apply all effects
         return true;
    }

    // don't apply any effects
    return false;
}

Please note that when you will activate/deactivate the item on the server side you need to mark the final cache for recalculation (as disabled item should not apply any effects, but activated item should apply them). To do so, you need to call the extension method for the character instance:
character.SharedSetFinalStatsCacheDirty();

Quote-  How would i have the suit give a warning to the player that there energy is low.
I would suggest overriding ViewModelHUDEnergyChargeIndicator implementation and putting a check "if current energy value is lower than previous energy value and the current energy value is below X" to display a notification there via NotificationSystem.

Quote- What is the best method (in coding terms) to apply the energy drain within ServerUpdate, and is this the correct application for 1 second intervals:
public override double ServerUpdateIntervalSeconds => 1;
Please see the first code snippet in my post where I'm calling CharacterEnergySystem.ServerDeductEnergyCharge method.

Regards!