示例#1
0
 public void OnRoll(NetworkMessage msg)
 {
     if (msg.conn.connectionId == battle.currentTurn && battle.rollsLeft > 0)
     {
         PlayerPawn pawn    = battle.GetCurrentPawn() as PlayerPawn;
         int[]      rolls   = new int[battle.rolls.Length];
         double[]   weights = new double[pawn.Affinities.Length];
         for (int i = 0; i < weights.Length; i++)
         {
             weights[i] = pawn.GetAffinity(i);
         }
         for (int i = 0; i < rolls.Length; i++)
         {
             if (battle.locks[i])
             {
                 rolls[i] = battle.rolls[i].GetId();
             }
             else
             {
                 rolls[i] = Element.All[REX.Weighted(weights)].GetId();
             }
             battle.rolls[i] = Element.All[rolls[i]];
         }
         battle.rollsLeft -= 1;
         NetworkServer.SendToAll(GameMsg.Roll, new GameMsg.MsgIntegerArray()
         {
             array = rolls
         });
     }
 }
示例#2
0
            public static int GetFromDuration(string time, REX r)
            {
                if (r != REX.Seconds && r != REX.Milliseconds)
                {
                    return(0);
                }
                int   sec = 0, millis = 0;
                Match match = Regex.Match(time, @"(\d+).?(\d*)?");

                if (match.Groups[1].Value != String.Empty)
                {
                    if (!int.TryParse(match.Groups[1].Value, out sec))
                    {
                        sec = 0;
                    }
                    else if (match.Groups[1].Value == String.Empty)
                    {
                        sec = 0;
                    }
                }
                if (match.Groups[2].Value != String.Empty)
                {
                    if (!int.TryParse(match.Groups[2].Value, out millis))
                    {
                        millis = 0;
                    }
                    else if (match.Groups[2].Value == String.Empty)
                    {
                        millis = 0;
                    }
                }
                return(r == REX.Seconds ? sec : millis);
            }
示例#3
0
    public void OnConnect(NetworkMessage msg)
    {
        LobbyPlayer lobbyPlayer = new LobbyPlayer()
        {
            id = msg.conn.connectionId, charName = REX.Choice(DB.CharNames)
        };

        lobbyPlayers.Add(lobbyPlayer);
        GameMsg.MsgPlayerLobbyUpdate playerLobbyUpdate = new GameMsg.MsgPlayerLobbyUpdate()
        {
            lobbyPlayer = lobbyPlayer
        };
        for (int i = 0; i < NetworkServer.connections.Count; i++)
        {
            if (i == msg.conn.connectionId)
            {
                LobbyPlayer[] clients = lobbyPlayers.ToArray();
                GameMsg.MsgPlayerLobbyList lobbyList = new GameMsg.MsgPlayerLobbyList()
                {
                    lobbyPlayerList = clients, clientId = i
                };
                NetworkServer.connections[i].Send(GameMsg.PlayerLobbyList, lobbyList);
            }
            else
            {
                NetworkServer.connections[i].Send(GameMsg.PlayerLobbyUpdate, playerLobbyUpdate);
            }
        }
    }
示例#4
0
    public override PlayerPawn Create(LobbyClientHandler.LobbyPlayer lobbyPlayer)
    {
        PlayerPawn player = new PlayerPawn(lobbyPlayer.charName, maxHp);

        player.SetId(lobbyPlayer.id);
        int[]   affinityCounts = new int[Element.Count];
        Spell[] spellsToLearn  = REX.Choice(DB.BuyableSpells, 4);
        for (int i = 0; i < spellsToLearn.Length; i++)
        {
            ElementDisplay[] d = spellsToLearn[i].GetElementDisplays(RollContext.Null);
            for (int j = 0; j < d.Length; j++)
            {
                affinityCounts[d[j].element.GetId()]++;
            }
        }
        foreach (Spell spell in spellsToLearn)
        {
            player.AddSpell(spell);
        }
        for (int i = 0; i < Element.Count; i++)
        {
            if (affinityCounts[i] > 0)
            {
                player.Affinities[i].AddModifier(new AttributeModifier(GetName(), AttributeModifier.Operation.AddBase, affinityCounts[i]));
            }
        }
        return(player);
    }
示例#5
0
    public override void Open()
    {
        base.Open();
        int shopAmount = 1;

        for (int i = 0; i < pawns.Length; i++)
        {
            List <string> buyableSpells = DB.BuyableSpells.Select(spell => spell.GetId()).ToList();
            buyableSpells.RemoveAll(pawns[i].DoesKnowSpell);
            string[] shop = REX.Choice(buyableSpells, shopAmount);
            NetworkServer.SendToClient(i, GameMsg.ShopList, new GameMsg.MsgStringArray(shop));
        }
    }
示例#6
0
            public static string Extrapolate(string s, REX r)
            {
                /*if (Regex.Match(s, @".*(.)$").Groups[1].Value == "Z")
                 * {
                 *  if (r == REX.Milliseconds) return "000";
                 *  return Regex.Match(s, @"(\d{4})-(\d{2})-(\d{2})([A-z]?)(\d{2})\:(\d{2})\:(\d{2})(.*?)(Z)").Groups[(int) r].Value;
                 * }*/
                var match = Regex.Match(s, @"(\d{4})-(\d{2})-(\d{2})([A-z]?)(\d{2})\:(\d{2})\:(\d{2})[:.]?(\d*)(.*)");

                if (r == REX.Milliseconds && match.Groups[(int)r].Value == "")
                {
                    return("000");
                }
                return(match.Groups[(int)r].Value);
            }
示例#7
0
    private void CastSpell(ServerBattle battle)
    {
        Spell  spell    = REX.Choice(GetSpells());
        string spellId  = spell.GetId();
        int    targetId = -1;

        if (spell.DoesRequireTarget())
        {
            List <int> possibleTargets = new List <int>();
            for (int i = 0; i < battle.allies.Length; i++)
            {
                if (battle.allies[i].IsAlive())
                {
                    possibleTargets.Add(battle.allies[i].GetId());
                }
            }
            targetId = REX.Choice(possibleTargets);
        }
        battle.CastSpell(spellId, targetId);
    }
示例#8
0
    public void DoTurn(ServerBattle battle)
    {
        int action = REX.Weighted(new float[] { spellWeight, passWeight, useItemWeight });

        switch (action)
        {
        case 0:
            CastSpell(battle);
            break;

        case 1:
            NetworkServer.SendToAll(GameMsg.Pass, new EmptyMessage());
            battle.NextTurn();
            break;

        case 2:
            Debug.Log("Enemy UseItem NYI");
            break;

        default:
            Debug.Log("Unknown AI Action ID");
            break;
        }
    }
    static void Main(string[] args)
    {
        try {
            string XML = File.ReadAllText(@"lewis.xml");

            List <Entry> DICT = compile(XML);

            foreach (var WORD in DICT)
            {
                WORD.correct();
            }

            Regex[] PATTERNS = Patterns();

            var UNK = new StringBuilder();

            Dictionary <char, StringBuilder> LINES = new Dictionary <char, StringBuilder>();

            foreach (var WORD in DICT)
            {
                Regex found = null;
                foreach (Regex REX in PATTERNS)
                {
                    if (REX.IsMatch(WORD.Declaration))
                    {
                        System.Diagnostics.Debug.Assert(found == null, "Duplicate regular expression pattern detected.");
                        found = REX;
                    }
                }
                if (found != null)
                {
                    char c = char.ToLowerInvariant(WORD.Declaration[0]);
                    if (c == '(')
                    {
                        c = WORD.Declaration[1];
                    }
                    switch (c)
                    {
                    case 'ā':
                        c = 'a';
                        break;

                    case 'ē':
                        c = 'e';
                        break;

                    case 'ō':
                        c = 'o';
                        break;

                    case 'ī':
                        c = 'i';
                        break;

                    case 'ū':
                        c = 'u';
                        break;
                    }
                    c = char.ToUpperInvariant(c);
                    if (!LINES.ContainsKey(c))
                    {
                        LINES[c] = new StringBuilder();
                    }
                    LINES[c].Append($"##### {WORD.Declaration}");
                    if (!string.IsNullOrWhiteSpace(WORD.Definition))
                    {
                        LINES[c].Append($"\r\n{WORD.Definition}");
                    }
                    LINES[c].Append($"\r\n");
                }
                else
                {
                    UNK.Append($"##### {WORD.Declaration}\r\n");
                }
            }

            foreach (var c in LINES)
            {
                if (c.Value != null)
                {
                    File.WriteAllText($"data//{c.Key}.md", c.Value.ToString());
                }
            }

            File.WriteAllText(@"lewis.md", UNK.ToString());
        } catch (Exception e) {
            Console.Error?.WriteLine(e);
        }

        Console.WriteLine("Done.");
    }