コード例 #1
0
ファイル: Manage_Group.py プロジェクト: KariolWang/Hero
def find_den(conn, group, ranker):
    """
    生成贼寇据点,可征讨
    :param ranker: 
    :param group: 
    :param conn: 
    :return: den
    """
    den = dict()
    den['d_group'] = group.get('g_id')
    den['d_name'] = random.choice(['山贼', '土匪', '强盗', '蛮夷', '流寇', '叛将'])
    den['d_corps'] = random.choice(Conn.get_level_ranker(conn, 6))
    den['d_ranker'] = random.randint(round(group.get('g_ranker') * 0.3),
                                     round(group.get('g_ranker') * 3.2))
    den['d_gold'] = random.randint(round(den.get('d_ranker') / 10),
                                   round(den.get('d_ranker') / 5))
    den['d_rations'] = random.randint(round(den.get('d_ranker') * 1.5),
                                      round(den.get('d_ranker') * 3.5))
    k = random.random() * random.random()
    den['d_gem'] = random.choice(Conn.find_treasure(conn)) if k > 0.8 else 0
    if group.get('g_status') == 1:
        print('发现{0}据点,拥有{1}共{2}人!请发兵镇压!'.format(
            den.get('d_name'),
            ranker.get(den.get('d_corps')).get('r_name'), den.get('d_ranker')))
    Conn.insert_data(conn, 'den', den)
コード例 #2
0
ファイル: Manage_Group.py プロジェクト: KariolWang/Hero
def find_recluse_treasure(conn, group, heroes, hero_id, gems):
    """
    寻访,概率寻访到在野英雄、在野宝物、黄金、粮草
    :param hero_id: 
    :param conn: 
    :param group: 
    :param heroes: 
    :param gems: 
    :return: group
    """
    # 在野英雄ID列表
    recluse = Conn.find_recluse(conn)
    # 在野宝物ID列表
    treasure = Conn.find_treasure(conn)
    # 势力变更信息及开关
    new_group = dict()
    check_g = False
    # 英雄变更信息
    new_hero = dict()
    # 宝物变更信息
    new_gem = dict()
    # 获取势力钱粮信息
    g_rations = group.get('g_rations')
    g_gold = group.get('g_gold')
    for h_id in hero_id:
        # 概率参数
        # [0, 0.3) 30%概率寻访没有收获
        # [0.3, 0.5) 20%概率寻访发现粮草
        # [0.5, 0.7) 20%概率寻访发现黄金
        # [0.7, 0.9) 20%概率寻访发现英雄
        # [0.9, 1] 10%概率寻访发现宝物
        k = random.random() * (1 - random.random())
        if len(treasure) < 1 and len(recluse) > 0:
            k -= 0.11
        elif len(recluse) < 1 and len(treasure) > 0:
            k = 0.99
        elif len(recluse) + len(treasure) < 1:
            k -= 0.31
        hero = heroes.get(h_id)
        if 0.2 <= k < 0.45:
            rations = random.randint(
                hero.get('h_brain') + hero.get('h_charm'),
                (hero.get('h_brain') + hero.get('h_charm')) * 2)
            g_rations += rations
            group['g_rations'] = g_rations
            new_group['g_rations'] = g_rations
            if group.get('g_status') == 1:
                print('{0}发现粮草,{1}粮草增加{2}'.format(hero.get('h_name'),
                                                  group.get('g_name'),
                                                  rations))
            check_g = True
        elif 0.45 <= k < 0.7:
            gold = random.randint(
                hero.get('h_brain') + hero.get('h_charm'),
                (hero.get('h_brain') + hero.get('h_charm')) * 3)
            g_gold += gold
            group['g_gold'] = g_gold
            new_group['g_gold'] = g_gold
            if group.get('g_status') == 1:
                print('{0}发现黄金,{1}黄金增加{2}'.format(hero.get('h_name'),
                                                  group.get('g_name'), gold))
            check_g = True
        elif 0.7 <= k < 0.9:
            # 发现英雄ID
            try:
                re_id = random.choice(recluse)
            except Exception as e:
                print(e)
                print('{}本次寻访未发现任何事物'.format(hero.get('h_name')))
                continue
            # 英雄投奔概率
            # 受寻访英雄的智力和魅力值影响
            hero_1 = (hero.get('h_brain') + hero.get('h_charm')) / 2
            hero_2 = (heroes.get(re_id).get('h_brain') +
                      heroes.get(re_id).get('h_charm')) / 2
            if group.get('g_status') == 1:
                print('{0}发现在野英雄{1}!是否选择招揽!'.format(
                    hero.get('h_name'),
                    heroes.get(re_id).get('h_name')))
                print(
                    '姓名:{0}\n性别:{1}\n年龄:{2}\n身份:{3}\n统率:{4}\n武力:{5}\n智力:{6}\n政治:{7}\n魅力:{8}'
                    .format(
                        heroes.get(re_id).get('h_name'),
                        heroes.get(re_id).get('h_gender'),
                        heroes.get(re_id).get('h_age'),
                        heroes.get(re_id).get('h_identity'),
                        heroes.get(re_id).get('h_lead'),
                        heroes.get(re_id).get('h_force'),
                        heroes.get(re_id).get('h_brain'),
                        heroes.get(re_id).get('h_politics'),
                        heroes.get(re_id).get('h_charm')))
                is_get = int(input('1 招揽  2 放弃\n'))
                if is_get == 1:
                    choice = hero_1 / hero_2 - random.random()
                    print(
                        '{}:阁下慢走,方才见阁下举止不凡,一表人才,想来阁下绝非常人,何不投效我军,谋一个出路?'.format(
                            hero.get('h_name')))
                    if choice > 0.6:
                        print('{0}:久闻{1}大名,承蒙不弃,{0}愿效死力!'.format(
                            heroes.get(re_id).get('h_name'),
                            group.get('g_name')))
                        print('{0}:哈哈,我军得{1}相助,何愁天下不平?'.format(
                            hero.get('h_name'),
                            heroes.get(re_id).get('h_name')))
                    else:
                        print('{0}:多谢大人好意,然{0}并无意出仕,还望大人恕罪。'.format(
                            heroes.get(re_id).get('h_name')))
                        print('{0}:唉,既如此,{0}也不好再为难阁下,告辞。'.format(
                            hero.get('h_name')))
                    if choice > 0.6:
                        new_hero['h_group'] = group.get('g_id')
                        new_hero['h_status'] = 2
                        recluse.remove(re_id)
                        print('{0}成功招揽到英雄{1}!'.format(
                            group.get('g_name'),
                            heroes.get(re_id).get('h_name')))
                        condition_h = 'h_id = {}'.format(re_id)
                        Conn.update_data(conn, 'heroes', new_hero, condition_h)
        elif 0.9 <= k <= 1:
            # 发现宝物ID
            # 受势力民心影响
            treasure = [
                t_id for t_id in treasure if gems.get(t_id).get('t_level') < (
                    2 if group.get('g_morale') < 100 else
                    3 if group.get('g_morale') < 500 else 4)
            ]
            tr_id = random.choice(treasure)
            new_gem['t_group'] = group.get('g_id')
            condition_t = 't_id = {}'.format(tr_id)
            if group.get('g_status') == 1:
                print('{0}成功寻获到宝物{1}!'.format(hero.get('h_name'),
                                              gems.get(tr_id).get('t_name')))
            Conn.update_data(conn, 'gems', new_gem, condition_t)
        else:
            if group.get('g_status') == 1:
                print('{}本次寻访未发现任何事物'.format(hero.get('h_name')))
    if check_g:
        condition_g = 'g_id = {}'.format(group.get('g_id'))
        Conn.update_data(conn, 'hero_group', new_group, condition_g)
    return group
コード例 #3
0
ファイル: Manage_Group.py プロジェクト: KariolWang/Hero
def check_group(conn, group, heroes, gems):
    """
    势力现状评定,有几率触发特殊事件
    :param gems: 
    :param conn: 
    :param group: 
    :param heroes: 
    :return: group
    """
    g_morale = group.get('g_morale')
    g_gold = group.get('g_gold')
    g_rations = group.get('g_rations')
    g_ranker = group.get('g_ranker')
    g_populace = group.get('g_populace')
    group_hero = Conn.get_group_hero(conn, group.get('g_id'))
    # 下野英雄信息字典
    retire = dict()
    # 势力变更信息字典
    new_group = dict()
    # 势力变更开关
    check_g = False
    # 英雄变更开关
    check_h = False
    # 黄金小于0
    if g_gold < 0:
        k = random.random()
        if 0.2 < k < 0.7:
            # 兵力哗变叛逃
            deserter = random.randint(round(g_ranker * 0.05),
                                      round(g_ranker * 0.1))
            g_ranker -= deserter
            group['g_ranker'] = g_ranker
            new_group['g_ranker'] = g_ranker
            print('因{0}军饷不足,{1}名士兵哗变叛逃了!'.format(group.get('g_name'),
                                                 deserter))
            check_g = True
        if 0.5 < k < 0.55:
            # 英雄辞官下野
            h_id = random.choice(group_hero)
            group_hero.remove(h_id)
            retire[h_id] = {'h_group': 0, 'h_status': 1}
            print('因{0}军饷不足,{1}辞官下野了!'.format(group.get('g_name'),
                                              heroes.get(h_id).get('h_name')))
            check_h = True
    # 粮草小于0
    if g_rations < 0:
        k = random.random()
        if 0.2 < k < 0.8:
            # 兵力哗变叛逃
            deserter = random.randint(round(g_ranker * 0.08),
                                      round(g_ranker * 0.15))
            g_ranker -= deserter
            group['g_ranker'] = g_ranker
            new_group['g_ranker'] = g_ranker
            print('因{0}粮草不足,{1}名士兵哗变叛逃了!'.format(group.get('g_name'),
                                                 deserter))
        if 0.53 < k < 0.55:
            # 英雄辞官下野
            h_id = random.choice(group_hero)
            group_hero.remove(h_id)
            retire[h_id] = {'h_group': 0, 'h_status': 1}
            print('因{0}粮草不足,{1}辞官下野了!'.format(group.get('g_name'),
                                              heroes.get(h_id).get('h_name')))
            check_h = True
        g_ranker = round(g_ranker * 0.6)
        g_populace += round(g_ranker * 0.4)
        g_gold += round(g_ranker * 0.4 / 100)
        new_group['g_ranker'] = g_ranker
        new_group['g_gold'] = g_gold
        new_group['g_populace'] = g_populace
        group['g_ranker'] = g_ranker
        group['g_gold'] = g_gold
        group['g_populace'] = g_populace
        check_g = True
    # 民心大于600
    if g_morale > 600:
        k = random.random()
        if 0.3 < k < 0.7:
            # 人口迁入
            follower = random.randint(round(g_populace * 0.05),
                                      round(g_populace * 0.08))
            g_populace += follower
            group['g_populace'] = g_populace
            new_group['g_populace'] = g_populace
            print('因{0}民心所向,人口迁入了{1}人!'.format(group.get('g_name'), follower))
            check_g = True
        if 0.4 < k < 0.6:
            # 钱粮捐献
            gold = random.randint(round(g_populace / 500),
                                  round(g_populace / 200))
            rations = random.randint(round(g_populace / 80),
                                     round(g_populace / 30))
            g_gold += gold
            g_rations += rations
            group['g_gold'] = g_gold
            group['g_rations'] = g_rations
            new_group['g_gold'] = g_gold
            new_group['g_rations'] = g_rations
            print('因{0}民心所向,民众发起粮草捐赠,粮草增加{1}石,黄金增加{2}两!'.format(
                group.get('g_name'), rations, gold))
            check_g = True
        if 0.5 < k < 0.55:
            # 志愿参军
            volunteer = random.randint(round(g_populace * 0.003),
                                       round(g_populace * 0.08))
            g_ranker += volunteer
            g_populace -= volunteer
            group['g_ranker'] = g_ranker
            group['g_populace'] = g_populace
            new_group['g_ranker'] = g_ranker
            new_group['g_populace'] = g_populace
            print('因{0}民心所向,民众发起志愿参军,兵力增加{1}名!'.format(group.get('g_name'),
                                                       volunteer))
            check_g = True
        if 0.52 < k < 0.53:
            # 进贡宝物
            new_gems = dict()
            treasure = Conn.find_treasure(conn)
            t_id = random.choice(treasure)
            new_gems['t_group'] = group.get('g_id')
            condition_t = 't_id = {}'.format(t_id)
            print('因{0}民心所向,民众进贡传家宝物,{0}获得宝物{1}!'.format(
                group.get('g_name'),
                gems.get(t_id).get('t_name')))
            Conn.update_data(conn, 'gems', new_gems, condition_t)
    # 民心大于300
    elif g_morale > 300:
        k = random.random()
        if 0.5 < k < 0.6:
            # 人口迁入
            follower = random.randint(round(g_populace * 0.03),
                                      round(g_populace * 0.06))
            g_populace += follower
            group['g_populace'] = g_populace
            new_group['g_populace'] = g_populace
            print('因{0}民心所向,人口迁入了{1}人!'.format(group.get('g_name'), follower))
            check_g = True
        if 0.55 < k < 0.6:
            # 钱粮捐献
            gold = random.randint(round(g_populace / 500),
                                  round(g_populace / 200))
            rations = random.randint(round(g_populace / 80),
                                     round(g_populace / 30))
            g_gold += gold
            g_rations += rations
            group['g_gold'] = g_gold
            group['g_rations'] = g_rations
            new_group['g_gold'] = g_gold
            new_group['g_rations'] = g_rations
            print('因{0}民心所向,民众发起粮草捐赠,粮草增加{1}石,黄金增加{2}两!'.format(
                group.get('g_name'), rations, gold))
            check_g = True
    # 民心大于100
    elif g_morale > 100:
        k = random.random()
        if 0.5 < k < 0.6:
            # 人口迁入
            follower = random.randint(round(g_populace * 0.01),
                                      round(g_populace * 0.03))
            g_populace += follower
            group['g_populace'] = g_populace
            new_group['g_populace'] = g_populace
            print('因{0}民心所向,人口迁入了{1}人!'.format(group.get('g_name'), follower))
            check_g = True
    # 民心小于30
    if 10 < g_morale < 30:
        k = random.random()
        if 0.5 < k < 0.7:
            # 人口流失
            refugee = random.randint(round(g_populace * 0.03),
                                     round(g_populace * 0.05))
            g_populace -= refugee
            group['g_populace'] = g_populace
            new_group['g_populace'] = g_populace
            print('因{0}民心不足,人口流失了{1}人!'.format(group.get('g_name'), refugee))
            check_g = True
    # 民心小于10
    elif g_morale < 10:
        # 人口流失
        refugee = random.randint(round(g_populace * 0.05),
                                 round(g_populace * 0.08))
        g_populace -= refugee
        # 士兵哗变叛逃
        deserter = random.randint(round(g_ranker * 0.05),
                                  round(g_ranker * 0.08))
        g_ranker -= deserter
        group['g_ranker'] = g_ranker
        new_group['g_ranker'] = g_ranker
        group['g_populace'] = g_populace
        new_group['g_populace'] = g_populace
        print('因{0}民心不足,人口流失了{1}人,{2}名士兵哗变叛逃了!'.format(group.get('g_name'),
                                                       refugee, deserter))
        check_g = True
    if check_g:
        condition_g = 'g_id = {}'.format(group.get('g_id'))
        Conn.update_data(conn, 'hero_group', new_group, condition_g)
    if check_h:
        for hid in retire.keys():
            condition_h = 'h_id = {}'.format(hid)
            Conn.update_data(conn, 'heroes', retire.get(hid), condition_h)
    return group