예제 #1
0
파일: models.py 프로젝트: yezooz/crime-corp
    def do_job(self, user):
        res = {}

        # Job req
        if not user.match_req(self.reqs):
            res['result'] = 'NO_REQ'
            return res

        # Check!
        chance = get_chance(user.team_attack, \
                            user.team_respect, \
                            self.req_attack, \
                            self.req_respect, \
                            0, \
                            user.heat, \
                            user.max_heat, \
                            self.heat)
        rand_chance = random.randint(1, 100)
        if chance < rand_chance:
            res['result'] = 'NO_CHANCE'
            return res

        res['result'] = True
        res['cash'] = int(self.base_instant_cash) * random.uniform(0.8, 1.2)
        res['attack'] = int(self.base_attack) * random.uniform(float(self.attack_modifier_min),
                                                               float(self.attack_modifier_max))
        res['defense'] = int(self.base_attack) * random.uniform(float(self.attack_modifier_min),
                                                                float(self.attack_modifier_max))
        res['respect'] = int(self.base_respect) * random.uniform(float(self.respect_modifier_min),
                                                                 float(self.respect_modifier_max))
        # TODO: bonus! 1/100

        return res
예제 #2
0
파일: models.py 프로젝트: yezooz/crime-corp
    def do_job(self, user):
        import math

        res = {}

        if self.is_premium and not user.is_premium:
            res['result'] = 'NO_PREMIUM'
            return res

        # Job req
        if not user.match_req(self.reqs):
            res['result'] = 'NO_REQ'
            return res

        chance = get_chance(user.total_attack, \
                            user.total_respect, \
                            self.req_attack, \
                            self.req_respect, \
                            0, \
                            user.heat, \
                            user.max_heat, \
                            self.heat)
        rand_chance = random.randint(1, 100)
        if chance < rand_chance:
            logging.debug("%s failed job %s" % (str(user.user), str(self.id)))

            res['result'] = 'NO_CHANCE'
            return res

        res['result'] = True
        res['cash'] = int(math.ceil(int(self.base_instant_cash) * random.uniform(0.8, 1.2)))
        res['attack'] = int(self.base_attack) * random.uniform(float(self.attack_modifier_min),
                                                               float(self.attack_modifier_max))
        res['defense'] = int(self.base_attack) * random.uniform(float(self.attack_modifier_min),
                                                                float(self.attack_modifier_max))
        res['respect'] = int(self.base_respect) * random.uniform(float(self.respect_modifier_min),
                                                                 float(self.respect_modifier_max))

        res['attack'] = round(res['attack'], 2)
        res['defense'] = round(res['defense'], 2)
        res['respect'] = round(res['respect'], 2)

        res['loot'] = self.draw_loot()

        logging.debug("%s done job %s" % (str(user.user), str(self.id)))

        return res