Deleted32045420User Posted March 1, 2016 Share Posted March 1, 2016 (edited) yeah the title is kinda bombastic i know but it's a short for everything i am having trouble with. Now first thing first when i am resetting a soldier's class and then rank him up through Unit.RankUpSoldier it wont give him the basic ability until i get out of the promotion screen and back in, if i dont do that the soldier will remain without his new base perk. Commander's Choice code function UpdateCC(UIButton ccButton) { local XComGameState AGameState,AGameState2,AGameState3; local XCom_HiddenPotential HidP; local float UnitStats[30]; local array<float> AllStats; local int idx; local int k; local float newStat; local ECharStatType Stat; local float Will; local Object ThisObj ; local array<SoldierClassStatType> StatProgression; `log("Template: "@Unit.GetSoldierClassTemplate().DataName); HidP=new class 'XCom_HiddenPotential'; HidP.InitHiddenPotential(Unit); HidP=new class 'XCom_HiddenPotential'; AllStats=HidP.GetStatsForCC(Unit); for(idx = 0; idx < eStat_MAX; idx++) { stat= ECharStatType(idx); if(stat==eStat_Will) will= Unit.GetMaxStat(stat); NewStat=(Unit.GetMaxStat(Stat)-AllStats[idx]); UnitStats[idx]=(NewStat); `log(stat @" Old Stats: "@Unit.GetMaxStat(ECharStatType(idx))); `log(stat @" Stat Amount: "@AllStats[idx]); `log(stat @" New Stats: "@NewStat); Unit.SetBaseMaxStat(stat, NewStat); `log(stat @" Applied Stats: "@Unit.GetMaxStat(stat)); `log(" "); } HidP=new class 'XCom_HiddenPotential'; AllStats=HidP.GetAfterStatsForCC(Unit,SelectedClass.DataName); AGameState=class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Updating Unit Class"); Unit.RankUpSoldier( AGameState, SelectedClass.DataName); Unit.ResetSoldierAbilities(); Unit.ResetRankToRookie(); Unit.RankUpSoldier( AGameState, SelectedClass.DataName); for(idx = 0; idx < eStat_MAX; idx++) { stat= ECharStatType(idx); Unit.SetBaseMaxStat(stat,(UnitStats[idx]+AllStats[idx])); Unit.SetCurrentStat(stat,(UnitStats[idx]+AllStats[idx])); } Unit.SetBaseMaxStat(eStat_Will, Will); Unit.SetCurrentStat(eStat_Will, Will); `XSTRATEGYSOUNDMGR.PlaySoundEvent("StrategyUI_Recruit_Soldier"); AGameState.AddStateObject(Unit); `XCOMHISTORY.AddGameStateToHistory(AGameState); ParentScreen.PopulateData(); } another problem i have is with the ComponentGameState not being read until i get out of the promotion screen and back in, i guess it's all around the same line of problem which will be solved with the same fix but i cant seem to find it Main Hidden Potential Code for init. function InitHiddenPotential(XComGameState_Unit Unit,optional bool NewClass=false,optional name ClassName=' ') { local XComGameState NewGameState; local XComGameState_Unit_HiddenPotential HiddenP; local array<SoldierClassRank> SelectedRanks; local int idx,k; NewGameState=class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Getting New HiddenP component"); HiddenP=XComGameState_Unit_HiddenPotential(NewGameState.CreateStateObject(class'XComGameState_Unit_HiddenPotential')); for(k=0;k<SoldierClasses.length;k++) { if((SoldierClasses[k]~=String(ClassName)&&NewClass)||(!NewClass && SoldierClasses[k]~=String(Unit.GetSoldierClassTemplateName()))) { for(idx=k*7;idx<7*(k+1);idx++) { SelectedRanks.additem(SoldierRanks[idx]); } } } if(NewClass&&Unit.FindComponentObject(class'XComGameState_Unit_HiddenPotential')!=none) { Unit.RemoveComponentObject(HiddenP); HiddenP.InitHiddenP(SelectedRanks); HiddenP.UpdateLatestPromotion(Unit.GetRank(),Unit); Unit.AddComponentObject(HiddenP); NewGameState.AddStateObject(HiddenP); `XCOMHISTORY.AddGameStateToHistory(NewGameState); } else if(Unit.FindComponentObject(class'XComGameState_Unit_HiddenPotential')==none) { HiddenP.InitHiddenP(SelectedRanks); HiddenP.UpdateLatestPromotion(Unit.GetRank(),Unit); Unit.AddComponentObject(HiddenP); NewGameState.AddStateObject(HiddenP); `XCOMHISTORY.AddGameStateToHistory(NewGameState); } else if(!NewClass&&Unit.FindComponentObject(class'XComGameState_Unit_HiddenPotential')!=none) { `XCOMHISTORY.CleanupPendingGameState(NewGameState); } } Rest of Hidden Potential code (mostly getting the actual stats) function Array<float> GetStatsForCC(XComGameState_Unit Unit) { local XComGameState_Unit_HiddenPotential HiddenP; local int idx,k,i; local float UnitStats[30]; local Array<float> UnitStatsRet; local array<SoldierClassRank> SelectedRanks; local ECharStatType Stat; local float newStat,will; HiddenP=XComGameState_Unit_HiddenPotential(Unit.FindComponentObject(class'XComGameState_Unit_HiddenPotential')); if(HiddenP==none) { for(idx = 0; idx < eStat_MAX; idx++) { for(k=0;k<Unit.GetSoldierClassTemplate().GetStatProgression(Unit.GetRank()-1).length;k++) { stat= ECharStatType(idx); if(stat==eStat_Will) will= Unit.GetCurrentStat(stat); if(stat==Unit.GetSoldierClassTemplate().GetStatProgression(Unit.GetRank()-1)[k].StatType) { UnitStats[idx]=(Unit.GetSoldierClassTemplate().GetStatProgression(Unit.GetRank()-1)[k].StatAmount); `log(stat @" Stat Amount: "@Unit.GetSoldierClassTemplate().GetStatProgression(Unit.GetRank()-1)[k].StatAmount); `log(" "); } } } InitHiddenPotential(Unit); } else { for(idx = 0; idx < eStat_MAX; idx++) { HiddenP.UpdateLatestPromotion(Unit.GetRank(),Unit); for(idx = 0; idx < eStat_MAX; idx++) { for(k=0;k<HiddenP.StatProgression.length;k++) { stat= ECharStatType(idx); if(stat==eStat_Will) will= Unit.GetCurrentStat(stat); if(stat==HiddenP.StatProgression[k].StatType) { UnitStats[idx]=(HiddenP.StatProgression[k].StatAmount); `log(stat @" Stat Amount: "@HiddenP.StatProgression[k].StatAmount); `log(" "); } } } } } for(i = 0; i < eStat_MAX; i++) { UnitStatsRet.AddItem(UnitStats[i]); } return UnitStatsRet; } function Array<float> GetAfterStatsForCC(XComGameState_Unit Unit, name ClassName) { local XComGameState_Unit_HiddenPotential HiddenP; local int idx,k; local float UnitStats[30]; local Array<float> UnitStatsRet; local ECharStatType Stat; local array<SoldierClassRank> SelectedRanks; local float newStat,will; InitHiddenPotential(Unit,true,ClassName); HiddenP=XComGameState_Unit_HiddenPotential(Unit.FindComponentObject(class'XComGameState_Unit_HiddenPotential')); if(HiddenP==none) { `log("Didnt Find HiddenP"); for(idx = 0; idx < eStat_MAX; idx++) { for(k=0;k< class'X2SoldierClassTemplateManager'.static.GetSoldierClassTemplateManager().FindSoldierClassTemplate(ClassName).GetStatProgression(Unit.GetRank()-1).length;k++) { stat= ECharStatType(idx); if(stat==eStat_Will) will= Unit.GetCurrentStat(stat); if(stat==class'X2SoldierClassTemplateManager'.static.GetSoldierClassTemplateManager().FindSoldierClassTemplate(ClassName).GetStatProgression(Unit.GetRank()-1)[k].StatType) { UnitStats[idx]=(class'X2SoldierClassTemplateManager'.static.GetSoldierClassTemplateManager().FindSoldierClassTemplate(ClassName).GetStatProgression(Unit.GetRank()-1)[k].StatAmount); `log(stat @" Stat Amount: "@ class'X2SoldierClassTemplateManager'.static.GetSoldierClassTemplateManager().FindSoldierClassTemplate(ClassName).GetStatProgression(Unit.GetRank()-1)[k].StatAmount); `log(" "); } } } } else { `log("Found HiddenP"); for(k=0;k<SoldierClasses.length;k++) { if( SoldierClasses[k]~=String(ClassName)) { for(idx=k*7;idx<7*(k+1);idx++) { SelectedRanks.additem(SoldierRanks[idx]); } } } HiddenP.InitHiddenP(SelectedRanks); HiddenP.UpdateLatestPromotion(Unit.GetRank(),Unit); for(idx = 0; idx < eStat_MAX; idx++) { for(k=0;k<HiddenP.StatProgression.length;k++) { stat= ECharStatType(idx); if(stat==eStat_Will) will= Unit.GetCurrentStat(stat); if(stat==HiddenP.StatProgression[k].StatType) { UnitStats[idx]=(HiddenP.StatProgression[k].StatAmount); `log(stat @" Stat Amount: "@HiddenP.StatProgression[k].StatAmount); `log(" "); } } } } for(idx = 0; idx < eStat_MAX; idx++) { UnitStatsRet.AddItem(UnitStats[idx]); } return UnitStatsRet; } Actual Object i am adding to the unit as a component: Class XComGameState_Unit_HiddenPotential extends XComGameState_BaseObject Config(SecondWave); var Config bool bIs_HiddenPotential_Active; var Array<SoldierClassStatType> StatProgression; var array<SoldierClassRank> SoldierRanks; function InitHiddenP(Array<SoldierClassRank> ranks) { local int j,k,rnd,tRand; local float save,temp; SoldierRanks=ranks; for(j=0;j<SoldierRanks.Length;j++) { for(k=0 ;k<SoldierRanks[j].aStatProgression.length;k++) { save= SoldierRanks[j].aStatProgression[k].StatAmount; rnd= SoldierRanks[j].aStatProgression[k].RandStatAmount+1; tRand= (Rand(rnd)); temp=Save + float(tRand); SoldierRanks[j].aStatProgression[k].StatAmount=temp; SoldierRanks[j].aStatProgression[k].RandStatAmount=0; `log("StatAmounts:"@temp @save @tRand @rnd); } } } function UpdateLatestPromotion(int rank,XComGameState_Unit Unit) { if(bIs_HiddenPotential_Active) StatProgression=SoldierRanks[rank-1].aStatProgression; else StatProgression=Unit.GetSoldierClassTemplate().GetStatProgression(rank-1); } function Array<float> GetOriginalStats( XComGameState_Unit Unit) { local int i,idx,k; local int UnitStats[30]; local array<float> ToRet; local ECharStatType stat; local float will,NewStat; for(i=0;i<Unit.GetRank();i++) { for(idx = 0; idx < eStat_MAX; idx++) { for(k=0;k<SoldierRanks[i].aStatProgression.length;k++) { stat= ECharStatType(idx); if(stat==eStat_Will) will= Unit.GetMaxStat(stat); if(stat==SoldierRanks[i].aStatProgression[k].StatType) { NewStat=(Unit.GetMaxStat(Stat)-SoldierRanks[i].aStatProgression[k].StatAmount); ToRet.additem(NewStat); `log(stat @" Old Stats: "@Unit.GetMaxStat(ECharStatType(idx))); `log(stat @" Stat Amount: "@SoldierRanks[i].aStatProgression[k].StatAmount); `log(stat @" New Stats: "@NewStat); `log(stat @" Applied Stats: "@Unit.GetMaxStat(stat)); `log(" "); } else ToRet.additem(Unit.GetMaxStat(ECharStatType(idx))); } } } return ToRet; } Thanks in advance for your help, EladDv Edited March 1, 2016 by Guest Link to comment Share on other sites More sharing options...
Recommended Posts