44
44
import static mekhq .campaign .personnel .education .EducationController .makeEnrollmentCheck ;
45
45
import static mekhq .campaign .personnel .enums .PersonnelStatus .statusValidator ;
46
46
import static mekhq .campaign .personnel .enums .education .EducationLevel .DOCTORATE ;
47
+ import static mekhq .campaign .personnel .skills .Attributes .ATTRIBUTE_IMPROVEMENT_COST ;
48
+ import static mekhq .campaign .personnel .skills .Attributes .MAXIMUM_ATTRIBUTE_SCORE ;
47
49
import static mekhq .campaign .personnel .skills .SkillType .S_DOCTOR ;
48
50
import static mekhq .campaign .randomEvents .personalities .PersonalityController .writePersonalityDescription ;
49
51
import static mekhq .campaign .randomEvents .prisoners .PrisonerEventManager .processAdHocExecution ;
121
123
import mekhq .campaign .personnel .ranks .Ranks ;
122
124
import mekhq .campaign .personnel .skills .Skill ;
123
125
import mekhq .campaign .personnel .skills .SkillType ;
126
+ import mekhq .campaign .personnel .skills .enums .SkillAttribute ;
124
127
import mekhq .campaign .randomEvents .personalities .PersonalityController ;
125
128
import mekhq .campaign .randomEvents .prisoners .enums .PrisonerStatus ;
126
129
import mekhq .campaign .unit .Unit ;
@@ -179,6 +182,7 @@ public class PersonnelTableMouseAdapter extends JPopupMenuAdapter {
179
182
* @deprecated use {@code CMD_ADD_XP} instead
180
183
*/
181
184
@ Deprecated (since = "0.50.05" , forRemoval = true )
185
+ private static final String CMD_ADD_1_XP = "XP_ADD_1" ;
182
186
private static final String CMD_ADD_XP = "XP_ADD" ;
183
187
private static final String CMD_EDIT_BIOGRAPHY = "BIOGRAPHY" ;
184
188
private static final String CMD_EDIT_PORTRAIT = "PORTRAIT" ;
@@ -199,6 +203,8 @@ public class PersonnelTableMouseAdapter extends JPopupMenuAdapter {
199
203
private static final String CMD_ACQUIRE_CUSTOM_CHOICE = "CUSTOM_CHOICE" ;
200
204
private static final String CMD_IMPROVE = "IMPROVE" ;
201
205
private static final String CMD_BUY_TRAIT = "BUY_TRAIT" ;
206
+ private static final String CMD_CHANGE_ATTRIBUTE = "CHANGE_ATTRIBUTE" ;
207
+ private static final String CMD_SET_ATTRIBUTE = "SET_ATTRIBUTE" ;
202
208
private static final String CMD_ADD_SPOUSE = "SPOUSE" ;
203
209
private static final String CMD_REMOVE_SPOUSE = "REMOVE_SPOUSE" ;
204
210
private static final String CMD_ADD_PREGNANCY = "ADD_PREGNANCY" ;
@@ -330,8 +336,8 @@ public void actionPerformed(ActionEvent action) {
330
336
case CMD_RANK : {
331
337
List <Person > promotedPersonnel = new ArrayList <>();
332
338
try {
333
- final int rank = Integer .parseInt (data [1 ]);
334
- final int level = (data .length > 2 ) ? Integer .parseInt (data [2 ]) : 0 ;
339
+ final int rank = MathUtility .parseInt (data [1 ]);
340
+ final int level = (data .length > 2 ) ? MathUtility .parseInt (data [2 ]) : 0 ;
335
341
for (final Person person : people ) {
336
342
person .changeRank (getCampaign (), rank , level , true );
337
343
@@ -580,7 +586,7 @@ public void actionPerformed(ActionEvent action) {
580
586
}
581
587
case CMD_IMPROVE : {
582
588
String type = data [1 ];
583
- int cost = Integer .parseInt (data [2 ]);
589
+ int cost = MathUtility .parseInt (data [2 ]);
584
590
int oldExpLevel = selectedPerson .getExperienceLevel (getCampaign (), false );
585
591
selectedPerson .improveSkill (type );
586
592
selectedPerson .spendXP (cost );
@@ -600,8 +606,8 @@ public void actionPerformed(ActionEvent action) {
600
606
}
601
607
case CMD_BUY_TRAIT : {
602
608
String type = data [1 ];
603
- int cost = Integer .parseInt (data [2 ]);
604
- int target = Integer .parseInt (data [3 ]);
609
+ int cost = MathUtility .parseInt (data [2 ]);
610
+ int target = MathUtility .parseInt (data [3 ]);
605
611
606
612
switch (type ) {
607
613
case CONNECTIONS_LABEL -> selectedPerson .setConnections (target );
@@ -616,9 +622,44 @@ public void actionPerformed(ActionEvent action) {
616
622
getCampaign ().personUpdated (selectedPerson );
617
623
break ;
618
624
}
625
+ case CMD_CHANGE_ATTRIBUTE : {
626
+ SkillAttribute attribute = SkillAttribute .fromString (data [1 ]);
627
+
628
+ selectedPerson .changeAttributeScore (attribute , 1 );
629
+
630
+ int cost = MathUtility .parseInt (data [2 ]);
631
+ selectedPerson .spendXP (cost );
632
+
633
+ getCampaign ().personUpdated (selectedPerson );
634
+ break ;
635
+ }
636
+ case CMD_SET_ATTRIBUTE : {
637
+ SkillAttribute attribute = SkillAttribute .fromString (data [1 ]);
638
+
639
+ PopupValueChoiceDialog choiceDialog = new PopupValueChoiceDialog (getFrame (),
640
+ true ,
641
+ resources .getString ("spendOnAttributes.score" ),
642
+ selectedPerson .getAttributeScore (attribute ),
643
+ 0 );
644
+ choiceDialog .setVisible (true );
645
+
646
+ int choice = choiceDialog .getValue ();
647
+ if (choice <= 0 ) {
648
+ // <0 indicates Cancellation
649
+ return ;
650
+ }
651
+
652
+ for (Person person : people ) {
653
+ person .setAttributeScore (attribute , choice );
654
+ MekHQ .triggerEvent (new PersonChangedEvent (person ));
655
+ getCampaign ().personUpdated (person );
656
+ }
657
+
658
+ break ;
659
+ }
619
660
case CMD_ACQUIRE_ABILITY : {
620
661
String selected = data [1 ];
621
- int cost = Integer .parseInt (data [2 ]);
662
+ int cost = MathUtility .parseInt (data [2 ]);
622
663
selectedPerson .getOptions ().acquireAbility (PersonnelOptions .LVL3_ADVANTAGES , selected , true );
623
664
selectedPerson .spendXP (cost );
624
665
final String displayName = SpecialAbility .getDisplayName (selected );
@@ -631,7 +672,7 @@ public void actionPerformed(ActionEvent action) {
631
672
}
632
673
case CMD_ACQUIRE_WEAPON_SPECIALIST : {
633
674
String selected = data [1 ];
634
- int cost = Integer .parseInt (data [2 ]);
675
+ int cost = MathUtility .parseInt (data [2 ]);
635
676
selectedPerson .getOptions ()
636
677
.acquireAbility (PersonnelOptions .LVL3_ADVANTAGES ,
637
678
OptionsConstants .GUNNERY_WEAPON_SPECIALIST ,
@@ -649,7 +690,7 @@ public void actionPerformed(ActionEvent action) {
649
690
}
650
691
case CMD_ACQUIRE_SANDBLASTER : {
651
692
String selected = data [1 ];
652
- int cost = Integer .parseInt (data [2 ]);
693
+ int cost = MathUtility .parseInt (data [2 ]);
653
694
selectedPerson .getOptions ()
654
695
.acquireAbility (PersonnelOptions .LVL3_ADVANTAGES , OptionsConstants .GUNNERY_SANDBLASTER , selected );
655
696
selectedPerson .spendXP (cost );
@@ -665,7 +706,7 @@ public void actionPerformed(ActionEvent action) {
665
706
}
666
707
case CMD_ACQUIRE_SPECIALIST : {
667
708
String selected = data [1 ];
668
- int cost = Integer .parseInt (data [2 ]);
709
+ int cost = MathUtility .parseInt (data [2 ]);
669
710
selectedPerson .getOptions ()
670
711
.acquireAbility (PersonnelOptions .LVL3_ADVANTAGES , OptionsConstants .GUNNERY_SPECIALIST , selected );
671
712
selectedPerson .spendXP (cost );
@@ -681,7 +722,7 @@ public void actionPerformed(ActionEvent action) {
681
722
}
682
723
case CMD_ACQUIRE_RANGEMASTER : {
683
724
String selected = data [1 ];
684
- int cost = Integer .parseInt (data [2 ]);
725
+ int cost = MathUtility .parseInt (data [2 ]);
685
726
selectedPerson .getOptions ()
686
727
.acquireAbility (PersonnelOptions .LVL3_ADVANTAGES ,
687
728
OptionsConstants .GUNNERY_RANGE_MASTER ,
@@ -699,7 +740,7 @@ public void actionPerformed(ActionEvent action) {
699
740
}
700
741
case CMD_ACQUIRE_ENVSPEC : {
701
742
String selected = data [1 ];
702
- int cost = Integer .parseInt (data [2 ]);
743
+ int cost = MathUtility .parseInt (data [2 ]);
703
744
selectedPerson .getOptions ()
704
745
.acquireAbility (PersonnelOptions .LVL3_ADVANTAGES , OptionsConstants .MISC_ENV_SPECIALIST , selected );
705
746
selectedPerson .spendXP (cost );
@@ -715,7 +756,7 @@ public void actionPerformed(ActionEvent action) {
715
756
}
716
757
case CMD_ACQUIRE_HUMANTRO : {
717
758
String selected = data [1 ];
718
- int cost = Integer .parseInt (data [2 ]);
759
+ int cost = MathUtility .parseInt (data [2 ]);
719
760
selectedPerson .getOptions ()
720
761
.acquireAbility (PersonnelOptions .LVL3_ADVANTAGES , OptionsConstants .MISC_HUMAN_TRO , selected );
721
762
selectedPerson .spendXP (cost );
@@ -731,7 +772,7 @@ public void actionPerformed(ActionEvent action) {
731
772
}
732
773
case CMD_ACQUIRE_CUSTOM_CHOICE : {
733
774
String selected = data [1 ];
734
- int cost = Integer .parseInt (data [2 ]);
775
+ int cost = MathUtility .parseInt (data [2 ]);
735
776
String ability = data [3 ];
736
777
selectedPerson .getOptions ().acquireAbility (PersonnelOptions .LVL3_ADVANTAGES , ability , selected );
737
778
selectedPerson .spendXP (cost );
@@ -1515,7 +1556,7 @@ private void processApplication(Person[] people, String[] data, boolean isReEnro
1515
1556
person ,
1516
1557
data [1 ],
1517
1558
data [2 ],
1518
- Integer .parseInt (data [3 ]),
1559
+ MathUtility .parseInt (data [3 ]),
1519
1560
data [4 ],
1520
1561
data [5 ],
1521
1562
isReEnrollment );
@@ -2766,6 +2807,32 @@ protected Optional<JPopupMenu> createPopupMenu() {
2766
2807
traitsMenu .add (menuItem );
2767
2808
menu .add (traitsMenu );
2768
2809
2810
+ JMenu attributesMenuIncrease = new JMenu (resources .getString ("spendOnAttributes.increase" ));
2811
+ int attributeCost = (int ) round (ATTRIBUTE_IMPROVEMENT_COST * costMultiplier );
2812
+
2813
+ for (SkillAttribute attribute : SkillAttribute .values ()) {
2814
+ if (attribute .isNone ()) {
2815
+ continue ;
2816
+ }
2817
+
2818
+ int current = person .getAttributeScore (attribute );
2819
+ // Improve
2820
+ target = current + 1 ;
2821
+ menuItem = new JMenuItem (String .format (resources .getString ("spendOnAttributes.format" ),
2822
+ attribute .getLabel (),
2823
+ current ,
2824
+ target ,
2825
+ traitCost ));
2826
+ menuItem .setToolTipText (wordWrap (String .format (resources .getString ("spendOnAttributes.tooltip" ))));
2827
+ menuItem .setActionCommand (makeCommand (CMD_CHANGE_ATTRIBUTE ,
2828
+ String .valueOf (attribute ),
2829
+ String .valueOf (attributeCost )));
2830
+ menuItem .addActionListener (this );
2831
+ menuItem .setEnabled (target <= MAXIMUM_ATTRIBUTE_SCORE && person .getXP () >= attributeCost );
2832
+ attributesMenuIncrease .add (menuItem );
2833
+ }
2834
+ menu .add (attributesMenuIncrease );
2835
+
2769
2836
// Edge Purchasing
2770
2837
if (getCampaignOptions ().isUseEdge ()) {
2771
2838
JMenu edgeMenu = new JMenu (resources .getString ("edge.text" ));
@@ -3564,6 +3631,23 @@ protected Optional<JPopupMenu> createPopupMenu() {
3564
3631
menuItem .addActionListener (this );
3565
3632
menu .add (menuItem );
3566
3633
3634
+ JMenu attributesMenu = new JMenu (resources .getString ("spendOnAttributes.set" ));
3635
+
3636
+ for (SkillAttribute attribute : SkillAttribute .values ()) {
3637
+ if (attribute .isNone ()) {
3638
+ continue ;
3639
+ }
3640
+
3641
+ // Set
3642
+ menuItem = new JMenuItem (attribute .getLabel ());
3643
+ menuItem .setToolTipText (wordWrap (String .format (resources .getString ("spendOnAttributes.tooltip" ))));
3644
+ menuItem .setActionCommand (makeCommand (CMD_SET_ATTRIBUTE , String .valueOf (attribute )));
3645
+ menuItem .addActionListener (this );
3646
+ menuItem .setEnabled (getCampaign ().isGM ());
3647
+ attributesMenu .add (menuItem );
3648
+ }
3649
+ menu .add (attributesMenu );
3650
+
3567
3651
JMenuHelpers .addMenuIfNonEmpty (popup , menu );
3568
3652
}
3569
3653
// endregion GM Menu
0 commit comments