summaryrefslogtreecommitdiff
path: root/DiscoBot/Auxiliary/TalentEnumerableExtension.cs
blob: df01de3ea329e89c461def4e6814c7a9b8b4df39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSALib;


namespace DiscoBot.Auxiliary
{
    using DiscoBot.Audio;
    using DiscoBot.DSA_Game.Characters;


    public static class TalentEnumerableExtension
    {
        public static string ProbenTest(this IEnumerable<Talent> List, Character c, string talent, int erschwernis = 0)
        {
            var output = new StringBuilder();
            var sc = new SpellCorrect();
            var tTalent = List.OrderBy(x => sc.Compare(talent, x.Name)).First();

            if (sc.Compare(talent, tTalent.Name) > SpellCorrect.ErrorThreshold)
            {
                try
                {
                    SoundEffects.Play("Stupid");
                }
                catch { }
                return $"{c.Name} kann nicht {talent}...";
            }

            var props = tTalent.GetEigenschaften(); // get the required properties
            int tap = tTalent.Value; // get taw
            var werte = props.Select(p => c.Eigenschaften[c.PropTable[p]]).ToList();

            output.AppendFormat(
                "{0} würfelt: {1} \n{2} - {3}   taw:{4} {5} \n",
                c.Name,
                tTalent.Name,
                tTalent.Probe,
                string.Join("/", werte),
                tTalent.Value,
                erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis);

            output.Append("         ");
            tap -= erschwernis;
            int gesamtErschwernis = tap;
            if (gesamtErschwernis < 0)
            {
                tap = 0;
                for (int i = 0; i <= 2; i++)
                {
                    // foreach property, dice and tap 
                    int temp = Dice.Roll();
                    int eigenschaft = c.Eigenschaften[c.PropTable[props[i]]];

                    if (eigenschaft + gesamtErschwernis < temp)
                    {
                        tap -= temp - (eigenschaft + gesamtErschwernis);
                    }

                    output.Append($"[{temp}]"); // add to string
                }

                if (tap >= 0)
                {
                    tap = 1;
                }
            }
            else
            {
                for (int i = 0; i <= 2; i++)
                {
                    // foreach property, dice and tap 
                    int temp = Dice.Roll();
                    int eigenschaft = c.Eigenschaften[c.PropTable[props[i]]];

                    if (eigenschaft < temp)
                    {
                        tap -= temp - eigenschaft;
                    }

                    output.Append($"[{temp}]"); // add to string
                }
            }

            tap = (tap == 0) ? 1 : tap;

            if (tap < 0)
            {
                try
                {
                    SoundEffects.Play("Wrong");
                }
                catch { }
            }

            output.AppendFormat(" tap: {0,2}", tap);

            return output.ToString(); // return output
        }
    }
}