|
8 | 8 |
|
9 | 9 | namespace ReviaRace.Comps |
10 | 10 | { |
11 | | - public class InvokeBlessing : CompUseEffect |
| 11 | + public abstract class InvokeBlessing : CompUseEffect |
12 | 12 | { |
13 | 13 | public override void DoEffect(Pawn pawn) |
14 | 14 | { |
15 | 15 | base.DoEffect(pawn); |
16 | | - var srComp = pawn.GetComp<SoulReaper>(); |
17 | | - Messages.Message($"{pawn.Name} offers some bloodstones to the bloody god.", pawn, MessageTypeDefOf.NeutralEvent, false); |
18 | 16 |
|
19 | | - if (pawn.MapHeld == null || srComp == null) |
| 17 | + if (!ViabilityCheck(pawn)) |
20 | 18 | { |
21 | | - Messages.Message($"Invalid target. srcomp null = {srComp == null}", pawn, MessageTypeDefOf.CautionInput, false); |
22 | 19 | return; |
23 | 20 | } |
24 | 21 |
|
25 | | - var soulReapTier = srComp.GetSoulReapTier(); |
26 | | - if (soulReapTier == -1) |
27 | | - { |
28 | | - Messages.Message("The bloodstone does nothing for the uninitiated...", pawn, MessageTypeDefOf.NegativeEvent, false); |
29 | | - return; |
30 | | - } |
31 | | - else if (soulReapTier == 9) |
32 | | - { |
33 | | - Messages.Message($"{pawn.Name} is already at the height of {pawn.ProSubj()} power!", pawn, MessageTypeDefOf.NeutralEvent, false); |
34 | | - return; |
35 | | - } |
| 22 | + var srComp = pawn.GetComp<SoulReaper>(); |
| 23 | + var srTier = srComp.GetSoulReapTier(); |
| 24 | + var cost = CalculateAdvanceCost(srTier); |
36 | 25 |
|
37 | | - // Check that we have enough bloodstones in the stack to proceed. |
38 | | - int cost = CalculateAdvanceCost(soulReapTier); |
39 | 26 | if (cost > parent.stackCount) |
40 | 27 | { |
41 | | - Messages.Message($"{pawn.Name}'s offering was rejected. The blood god demands more blood.", pawn, MessageTypeDefOf.NeutralEvent, false); |
| 28 | + Messages.Message($"{pawn.NameShortColored}'s offering was rejected. The blood god demands more blood.", pawn, MessageTypeDefOf.NeutralEvent, false); |
| 29 | + Messages.Message($"{cost} {parent.LabelNoCount}s were demanded.", pawn, MessageTypeDefOf.NeutralEvent, false); |
42 | 30 | return; |
| 31 | + } |
| 32 | + else |
| 33 | + { |
| 34 | + DecrementOnUse(pawn, cost); |
| 35 | + IncreaseSoulReapTier(pawn); |
43 | 36 | } |
| 37 | + } |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Increase the soul reap tier of this pawn. |
| 41 | + /// </summary> |
| 42 | + /// <param name="pawn">The pawn to increase the Soul Reap tier of.</param> |
| 43 | + protected void IncreaseSoulReapTier(Pawn pawn) |
| 44 | + { |
| 45 | + var srComp = pawn.GetComp<SoulReaper>(); |
| 46 | + var soulReapTier = srComp.GetSoulReapTier(); |
44 | 47 |
|
45 | 48 | // Blood for the blood god! Skulls for the skull throne! |
46 | 49 | srComp.RemoveSoulReapHediffs(); |
47 | 50 | srComp.AddSoulReapTier(soulReapTier + 1); |
48 | | - Messages.Message($"The blessing has succeeded, and {pawn.Name} has grown stronger.", pawn, MessageTypeDefOf.PositiveEvent); |
| 51 | + |
| 52 | + Messages.Message($"The blessing has succeeded, and {pawn.NameShortColored} has grown stronger.", pawn, MessageTypeDefOf.PositiveEvent); |
| 53 | + } |
49 | 54 |
|
50 | | - // Destroy the bloodstones that were used up. If there were exactly enough, destroy the stack. |
| 55 | + /// <summary> |
| 56 | + /// Decrement the number of consumed items. If the count would be zero or less, destroy the stack. |
| 57 | + /// </summary> |
| 58 | + /// <param name="pawn">The pawn using the stack.</param> |
| 59 | + /// <param name="cost">The cost of the invocation.</param> |
| 60 | + protected void DecrementOnUse(Pawn pawn, int cost) |
| 61 | + { |
| 62 | + Messages.Message($"{cost} {parent.LabelNoCount}(s) were consumed in {pawn.NameShortColored}'s offering.", pawn, MessageTypeDefOf.NeutralEvent); |
51 | 63 | if (parent.stackCount == cost) |
52 | 64 | { |
53 | 65 | parent.Destroy(); |
54 | 66 | } |
55 | | - else |
| 67 | + else if (parent.stackCount > cost) |
56 | 68 | { |
57 | 69 | parent.stackCount -= cost; |
58 | 70 | } |
| 71 | + else |
| 72 | + { |
| 73 | + throw new ArgumentException("Attempting to use more items than is available!"); |
| 74 | + } |
59 | 75 | } |
60 | 76 |
|
| 77 | + protected abstract int CalculateAdvanceCost(int tier); |
| 78 | + |
61 | 79 | /// <summary> |
62 | | - /// The cost of advancing is 2 ^ (n-2) bloodstones, |
| 80 | + /// Checks if the pawn is eligible to advance soul reap tiers. |
63 | 81 | /// </summary> |
64 | | - /// <param name="pawn">The pawn to check</param> |
65 | | - /// <returns>True if the random number generated passes the RNG check. |
66 | | - /// False if the hediff wasn't a soulreap that can be levelled up, |
67 | | - /// or if the RNG check failed.</returns> |
68 | | - private int CalculateAdvanceCost(int tier) |
| 82 | + /// <param name="pawn"></param> |
| 83 | + /// <returns></returns> |
| 84 | + protected bool ViabilityCheck(Pawn pawn) |
69 | 85 | { |
70 | | - if (tier == -1 || tier == 9) |
| 86 | + var srComp = pawn.GetComp<SoulReaper>(); |
| 87 | + Messages.Message($"{pawn.Name} offers some {parent.LabelNoCount}s to the bloody god.", pawn, MessageTypeDefOf.NeutralEvent, false); |
| 88 | + |
| 89 | + var soulReapTier = srComp.GetSoulReapTier(); |
| 90 | + if (soulReapTier == -1) |
71 | 91 | { |
72 | | - return -1; |
| 92 | + Messages.Message($"The {parent.LabelNoCount} does nothing for the uninitiated...", pawn, MessageTypeDefOf.NegativeEvent, false); |
| 93 | + return false; |
| 94 | + } |
| 95 | + else if (soulReapTier == 9) |
| 96 | + { |
| 97 | + Messages.Message($"{pawn.NameShortColored} is already at the height of {pawn.ProSubj()} power!", pawn, MessageTypeDefOf.NeutralEvent, false); |
| 98 | + return false; |
73 | 99 | } |
74 | 100 |
|
75 | | - double cost = Math.Max(1.0, Math.Pow(2, tier - 2)); |
76 | | - |
77 | | - return (int)cost; |
| 101 | + return true; |
78 | 102 | } |
79 | 103 | } |
80 | 104 | } |
0 commit comments