Exemplo n.º 1
0
def get_party_open_time_range(h1, h2):
    today = get_start_time_of_today()

    time1 = today.replace(hours=h1)
    time2 = today.replace(hours=h2)

    return time1, time2
Exemplo n.º 2
0
    def try_add_self_in_arena(self):
        doc = MongoArena.db(self.server_id).find_one(
            {'_id': str(self.char_id)},
            {'honor_rewards': 1}
        )

        if doc:
            # 清理过期的 honor_rewards 记录
            honor_rewards = doc.get('honor_rewards', {})
            if not honor_rewards:
                return

            today_key = str(get_start_time_of_today().timestamp)

            unset = {}
            for k in honor_rewards.keys():
                if k != today_key:
                    unset['honor_rewards.{0}'.format(k)] = 1

            if unset:
                MongoArena.db(self.server_id).update_one(
                    {'_id': str(self.char_id)},
                    {'$unset': unset}
                )

            return

        doc = MongoArena.document()
        doc['_id'] = str(self.char_id)
        doc['search_index'] = ConfigArenaSearchRange.START_INDEX
        MongoArena.db(self.server_id).insert_one(doc)

        ArenaScore(self.server_id, self.char_id).set_score(ARENA_DEFAULT_SCORE)
Exemplo n.º 3
0
    def send_notify(self, task_ids=None):
        # 日常任务的的时间范围肯定就是当天了
        start_time = get_start_time_of_today()
        end_time = start_time.replace(days=1)

        start_at = start_time.timestamp
        end_at = end_time.timestamp

        if task_ids:
            act = ACT_UPDATE
        else:
            act = ACT_INIT
            task_ids = self.doc['tasks']

        notify = TaskDailyNotify()
        notify.act = act
        for tid in task_ids:
            current_value, status = self.get_task_status(tid,
                                                         start_at=start_at,
                                                         end_at=end_at)

            notify_task = notify.tasks.add()
            notify_task.id = tid
            notify_task.value = current_value
            notify_task.status = status

        MessagePipe(self.char_id).put(msg=notify)
Exemplo n.º 4
0
    def get_honor_reward(self, honor_id):
        config = ConfigArenaHonorReward.get(honor_id)
        if not config:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        if honor_id > self.get_honor_points():
            raise GameException(ConfigErrorMessage.get_error_id("ARENA_HONOR_REWARD_POINT_NOT_ENOUGH"))

        reward_info = self.get_today_honor_reward_info()
        if honor_id in reward_info:
            raise GameException(ConfigErrorMessage.get_error_id("ARENA_HONOR_REWARD_ALREADY_GOT"))

        resource_classified = ResourceClassification.classify(config.reward)
        resource_classified.add(self.server_id, self.char_id, message="Arena.get_honor_reward:{0}".format(honor_id))

        today_key = str(get_start_time_of_today().timestamp)
        MongoArena.db(self.server_id).update_one(
            {'_id': str(self.char_id)},
            {
                '$push': {
                    'honor_rewards.{0}'.format(today_key): honor_id
                }
            }
        )

        reward_info.append(honor_id)
        self.send_honor_notify(reward_info=reward_info)
        return resource_classified
Exemplo n.º 5
0
    def try_add_self_in_arena(self):
        doc = MongoArena.db(self.server_id).find_one(
            {'_id': str(self.char_id)}, {'honor_rewards': 1})

        if doc:
            # 清理过期的 honor_rewards 记录
            honor_rewards = doc.get('honor_rewards', {})
            if not honor_rewards:
                return

            today_key = str(get_start_time_of_today().timestamp)

            unset = {}
            for k in honor_rewards.keys():
                if k != today_key:
                    unset['honor_rewards.{0}'.format(k)] = 1

            if unset:
                MongoArena.db(self.server_id).update_one(
                    {'_id': str(self.char_id)}, {'$unset': unset})

            return

        doc = MongoArena.document()
        doc['_id'] = str(self.char_id)
        doc['search_index'] = ConfigArenaSearchRange.START_INDEX
        MongoArena.db(self.server_id).insert_one(doc)

        ArenaScore(self.server_id, self.char_id).set_score(ARENA_DEFAULT_SCORE)
Exemplo n.º 6
0
    def job_of_login_notification(cls):
        connection.close()

        today = get_start_time_of_today()
        yesterday = today.replace(days=-1)
        day_before_yesterday = yesterday.replace(days=-1)

        day_before_yesterday_logged_account_ids = set()

        condition = Q(login_at__gte=day_before_yesterday.format("YYYY-MM-DD HH:mm:ssZ")) & \
                    Q(login_at__lt=yesterday.format("YYYY-MM-DD HH:mm:ssZ"))

        for log in AccountLoginLog.objects.filter(condition):
            day_before_yesterday_logged_account_ids.add(log.account_id)

        yesterday_to_now_logged_account_ids = set()
        condition = Q(login_at__gte=yesterday.format("YYYY-MM-DD HH:mm:ssZ")) & \
                    Q(login_at__lt=arrow.utcnow().format("YYYY-MM-DD HH:mm:ssZ"))

        for log in AccountLoginLog.objects.filter(condition):
            yesterday_to_now_logged_account_ids.add(log.account_id)

        not_logged_account_ids = day_before_yesterday_logged_account_ids - yesterday_to_now_logged_account_ids

        title = u"你已经一天没有上线了"
        content = u"赶快上线吧"
        count = 0

        for account_id in not_logged_account_ids:
            pushed = GeTui(account_id).push_of_login(title, content)
            if pushed:
                count += 1

        return count
Exemplo n.º 7
0
    def get_today_honor_reward_info(self):
        today_key = str(get_start_time_of_today().timestamp)
        doc = MongoArena.db(self.server_id).find_one(
            {'_id': str(self.char_id)},
            {'honor_rewards.{0}'.format(today_key): 1})

        return doc.get('honor_rewards', {}).get(today_key, [])
Exemplo n.º 8
0
    def get_task_status(self, task_id, start_at=None, end_at=None):
        """

        :rtype: (int, int)
        """

        if not start_at or not end_at:
            # 日常任务的的时间范围肯定就是当天了
            start_time = get_start_time_of_today()
            end_time = start_time.replace(days=1)

            start_at = start_time.timestamp
            end_at = end_time.timestamp

        config = ConfigTaskDaily.get(task_id)
        config_condition = ConfigTaskCondition.get(config.condition_id)
        if not config_condition:
            current_value = 0
        else:
            current_value = config_condition.get_value(self.server_id, self.char_id, start_at=start_at, end_at=end_at)

        if task_id in self.doc['done']:
            return current_value, TASK_DONE

        if task_id not in self.doc['tasks']:
            return None, None

        if config_condition.compare_value(self.server_id, self.char_id, current_value, config.condition_value):
            return current_value, TASK_FINISH

        return current_value, TASK_DOING
Exemplo n.º 9
0
    def get_honor_reward(self, honor_id):
        config = ConfigArenaHonorReward.get(honor_id)
        if not config:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        if honor_id > self.get_honor_points():
            raise GameException(
                ConfigErrorMessage.get_error_id(
                    "ARENA_HONOR_REWARD_POINT_NOT_ENOUGH"))

        reward_info = self.get_today_honor_reward_info()
        if honor_id in reward_info:
            raise GameException(
                ConfigErrorMessage.get_error_id(
                    "ARENA_HONOR_REWARD_ALREADY_GOT"))

        resource_classified = ResourceClassification.classify(config.reward)
        resource_classified.add(
            self.server_id,
            self.char_id,
            message="Arena.get_honor_reward:{0}".format(honor_id))

        today_key = str(get_start_time_of_today().timestamp)
        MongoArena.db(self.server_id).update_one(
            {'_id': str(self.char_id)},
            {'$push': {
                'honor_rewards.{0}'.format(today_key): honor_id
            }})

        reward_info.append(honor_id)
        self.send_honor_notify(reward_info=reward_info)
        return resource_classified
Exemplo n.º 10
0
 def count_of_today(self, sub_id=None):
     # 今天多少次
     today = get_start_time_of_today()
     tomorrow = today.replace(days=1)
     return self.count(sub_id=sub_id,
                       start_at=today.timestamp,
                       end_at=tomorrow.timestamp)
Exemplo n.º 11
0
    def send_notify(self, task_ids=None):
        # 日常任务的的时间范围肯定就是当天了
        start_time = get_start_time_of_today()
        end_time = start_time.replace(days=1)

        start_at = start_time.timestamp
        end_at = end_time.timestamp

        if task_ids:
            act = ACT_UPDATE
        else:
            act = ACT_INIT
            task_ids = self.doc['tasks']

        notify = TaskDailyNotify()
        notify.act = act
        for tid in task_ids:
            current_value, status = self.get_task_status(tid, start_at=start_at, end_at=end_at)

            notify_task = notify.tasks.add()
            notify_task.id = tid
            notify_task.value = current_value
            notify_task.status = status

        MessagePipe(self.char_id).put(msg=notify)
Exemplo n.º 12
0
    def job_of_login_notification(cls):
        connection.close()

        today = get_start_time_of_today()
        yesterday = today.replace(days=-1)
        day_before_yesterday = yesterday.replace(days=-1)

        day_before_yesterday_logged_account_ids = set()

        condition = Q(login_at__gte=day_before_yesterday.format("YYYY-MM-DD HH:mm:ssZ")) & \
                    Q(login_at__lt=yesterday.format("YYYY-MM-DD HH:mm:ssZ"))

        for log in AccountLoginLog.objects.filter(condition):
            day_before_yesterday_logged_account_ids.add(log.account_id)

        yesterday_to_now_logged_account_ids = set()
        condition = Q(login_at__gte=yesterday.format("YYYY-MM-DD HH:mm:ssZ")) & \
                    Q(login_at__lt=arrow.utcnow().format("YYYY-MM-DD HH:mm:ssZ"))

        for log in AccountLoginLog.objects.filter(condition):
            yesterday_to_now_logged_account_ids.add(log.account_id)

        not_logged_account_ids = day_before_yesterday_logged_account_ids - yesterday_to_now_logged_account_ids

        title = u"你已经一天没有上线了"
        content = u"赶快上线吧"
        count = 0

        for account_id in not_logged_account_ids:
            pushed = GeTui(account_id).push_of_login(title, content)
            if pushed:
                count += 1

        return count
Exemplo n.º 13
0
def get_party_open_time_range(h1, h2):
    today = get_start_time_of_today()

    time1 = today.replace(hours=h1)
    time2 = today.replace(hours=h2)

    return time1, time2
Exemplo n.º 14
0
def find_level_match_at(lv):
    today = get_start_time_of_today()
    weekday = today.weekday()

    days_shift = 0
    while True:
        if weekday in APPLY_WEEKDAY:
            break

        weekday -= 1
        if weekday < 0:
            weekday = 6

        days_shift += 1
        if days_shift >= 7:
            raise RuntimeError("ChampionshipLevel find match at error!")

    that_day = today.replace(days=-days_shift)

    prev_lv = LEVEL_PREVIOUS_TABLE[lv]
    hour, minute = LEVEL_MATCH_TIMES_TO_HOUR_MINUTE_TABLE[prev_lv]

    that_day = that_day.replace(hour=hour)
    that_day = that_day.replace(minute=minute)
    return that_day
Exemplo n.º 15
0
    def batch_count_of_today(self):
        """

        :rtype: dict[str, int]
        """
        today = get_start_time_of_today()
        tomorrow = today.replace(days=1)
        return self.batch_count(start_at=today.timestamp, end_at=tomorrow.timestamp)
Exemplo n.º 16
0
    def get_today_honor_reward_info(self):
        today_key = str(get_start_time_of_today().timestamp)
        doc = MongoArena.db(self.server_id).find_one(
            {'_id': str(self.char_id)},
            {'honor_rewards.{0}'.format(today_key): 1}
        )

        return doc.get('honor_rewards', {}).get(today_key, [])
Exemplo n.º 17
0
    def create(cls, server_id, char_id, club_name, club_flag):
        from core.staff import StaffManger
        from core.formation import Formation
        from core.mail import MailManager
        from apps.config.models import Mail as ModelMail

        doc = MongoCharacter.document()
        doc['_id'] = char_id
        doc['create_at'] = arrow.utcnow().timestamp

        doc['name'] = club_name
        doc['flag'] = club_flag
        doc['gold'] = CHAR_INIT_GOLD
        doc['diamond'] = CHAR_INIT_DIAMOND
        doc['crystal'] = CHAR_INIT_CRYSTAL
        doc['gas'] = CHAR_INIT_GAS

        sm = StaffManger(server_id, char_id)

        formation_init_data = []
        for staff_id, unit_id in CHAR_INIT_STAFFS:
            uid = sm.add(staff_id, send_notify=False, trig_signal=False)
            formation_init_data.append((uid, unit_id))

        fm = Formation(server_id, char_id)
        fm.initialize(formation_init_data)

        MongoCharacter.db(server_id).insert_one(doc)

        # add welfare mail
        start_time = get_start_time_of_today()
        condition = Q(send_at__gte=start_time.format("YYYY-MM-DD HH:mm:ssZ")) &\
                    Q(send_at__lte=arrow.utcnow().format("YYYY-MM-DD HH:mm:ssZ"))
        mails = ModelMail.objects.filter(condition)

        m = MailManager(server_id, char_id)
        for m_obj in mails:
            if not m_obj.welfare:
                continue

            ok = False
            if m_obj.condition_type == 1:
                ok = True
            elif m_obj.condition_type == 2 and server_id in m_obj.get_parsed_condition_value():
                ok = True
            elif m_obj.condition_type == 3 and server_id not in m_obj.get_parsed_condition_value():
                ok = True

            if not ok:
                continue

            if m_obj.items:
                rc = ResourceClassification.classify(m_obj.get_parsed_items())
                attachment = rc.to_json()
            else:
                attachment = ""

            m.add(m_obj.title, m_obj.content, attachment=attachment, send_notify=False)
Exemplo n.º 18
0
    def batch_count_of_today(self):
        """

        :rtype: dict[str, int]
        """
        today = get_start_time_of_today()
        tomorrow = today.replace(days=1)
        return self.batch_count(start_at=today.timestamp,
                                end_at=tomorrow.timestamp)
Exemplo n.º 19
0
    def get_retained_for_date(self, sid, char_ids, date_text, days):
        # 找这个date的 days留存
        date = arrow.get(date_text).replace(tzinfo=settings.TIME_ZONE).replace(days=days)
        if date > get_start_time_of_today():
            return '?'

        if not char_ids:
            return '0.0%'

        login_amount = self.get_login_amount_for_date(sid, date, char_ids)
        retained = float(login_amount) / len(char_ids)
        value = '%.1f' % (retained * 100) + '%'
        return value
Exemplo n.º 20
0
    def get_recent_login_account_ids(cls, recent_days):
        from utils.functional import get_start_time_of_today

        assert recent_days > 0
        recent_days -= 1

        limit = get_start_time_of_today()
        limit = limit.replace(days=-recent_days)
        account_ids = {}

        for log in cls.objects.filter(login_at__gte=limit.format("YYYY-MM-DD HH:mm:ssZ")).order_by('login_at'):
            account_ids[log.account_id] = log.to_server_id

        return account_ids
Exemplo n.º 21
0
    def __init__(self, server_id, char_id):
        self.server_id = server_id
        self.char_id = char_id
        self.doc = MongoActivityNewPlayer.db(self.server_id).find_one({'_id': self.char_id})
        if not self.doc:
            self.doc = MongoActivityNewPlayer.document()
            self.doc['_id'] = self.char_id
            MongoActivityNewPlayer.db(self.server_id).insert_one(self.doc)

        self.create_day = Club.create_days(server_id, char_id)

        today = get_start_time_of_today()
        self.create_start_date = today.replace(days=-(self.create_day - 1))

        self.activity_end_at = self.create_start_date.replace(days=7).timestamp
        self.reward_end_at = self.create_start_date.replace(days=8).timestamp
Exemplo n.º 22
0
    def __init__(self, server_id, char_id):
        self.server_id = server_id
        self.char_id = char_id
        self.doc = MongoActivityNewPlayer.db(self.server_id).find_one(
            {'_id': self.char_id})
        if not self.doc:
            self.doc = MongoActivityNewPlayer.document()
            self.doc['_id'] = self.char_id
            MongoActivityNewPlayer.db(self.server_id).insert_one(self.doc)

        self.create_day = Club.create_days(server_id, char_id)

        today = get_start_time_of_today()
        self.create_start_date = today.replace(days=-(self.create_day - 1))

        self.activity_end_at = self.create_start_date.replace(days=7).timestamp
        self.reward_end_at = self.create_start_date.replace(days=8).timestamp
Exemplo n.º 23
0
    def energy_reward_get(self):
        now = arrow.utcnow().to(settings.TIME_ZONE)
        today = get_start_time_of_today()

        for index, (start_hour, end_hour) in enumerate(ENERGY_TIME_RANGE):

            start_at = today.replace(hour=start_hour)
            end_at = today.replace(hour=end_hour)
            if start_at <= now <= end_at:
                times = ValueLogWelfareEnergyRewardTimes(self.server_id, self.char_id).count_of_today(sub_id=index)
                if times > 0:
                    raise GameException(ConfigErrorMessage.get_error_id("WELFARE_ENERGY_ALREADY_GOT"))

                ValueLogWelfareEnergyRewardTimes(self.server_id, self.char_id).record(sub_id=index)

                config = ConfigItemUse.get(-1)
                items = config.using_result()
                rc = ResourceClassification.classify(items)
                rc.add(self.server_id, self.char_id, message="Welfare.energy_reward_get")

                self.send_energy_reward_notify()
                return rc

        raise GameException(ConfigErrorMessage.get_error_id("WELFARE_ENERGY_CAN_NOT_GET_NOT_IN_TIME"))
Exemplo n.º 24
0
    def get_task_status(self, task_id, start_at=None, end_at=None):
        """

        :rtype: (int, int)
        """

        if not start_at or not end_at:
            # 日常任务的的时间范围肯定就是当天了
            start_time = get_start_time_of_today()
            end_time = start_time.replace(days=1)

            start_at = start_time.timestamp
            end_at = end_time.timestamp

        config = ConfigTaskDaily.get(task_id)
        config_condition = ConfigTaskCondition.get(config.condition_id)
        if not config_condition:
            current_value = 0
        else:
            current_value = config_condition.get_value(self.server_id,
                                                       self.char_id,
                                                       start_at=start_at,
                                                       end_at=end_at)

        if task_id in self.doc['done']:
            return current_value, TASK_DONE

        if task_id not in self.doc['tasks']:
            return None, None

        if config_condition.compare_value(self.server_id, self.char_id,
                                          current_value,
                                          config.condition_value):
            return current_value, TASK_FINISH

        return current_value, TASK_DOING
Exemplo n.º 25
0
 def get_purchase_info_of_day_shift(self, days=0):
     today = get_start_time_of_today()
     start = today.replace(days=days)
     end = start.replace(days=1)
     return self._get_purchase_info(start.timestamp, end.timestamp)
Exemplo n.º 26
0
 def _set_cache(self, key):
     today = get_start_time_of_today()
     tomorrow = today.replace(days=1)
     expire = tomorrow.timestamp - arrow.utcnow().timestamp
     cache.set(key, 1, expire=expire)
Exemplo n.º 27
0
 def get_daily_reward_info(self):
     key = get_start_time_of_today().format("YYYY-MM-DD")
     return key, self.doc.get('daily_reward', {}).get(key, {})
Exemplo n.º 28
0
 def count_of_today(self, sub_id=None):
     # 今天多少次
     today = get_start_time_of_today()
     tomorrow = today.replace(days=1)
     return self.count(sub_id=sub_id, start_at=today.timestamp, end_at=tomorrow.timestamp)
Exemplo n.º 29
0
 def get_daily_reward_info(self):
     key = get_start_time_of_today().format("YYYY-MM-DD")
     return key, self.doc.get('daily_reward', {}).get(key, {})
Exemplo n.º 30
0
 def _set_cache(self, key):
     today = get_start_time_of_today()
     tomorrow = today.replace(days=1)
     expire = tomorrow.timestamp - arrow.utcnow().timestamp
     cache.set(key, 1, expire=expire)
Exemplo n.º 31
0
 def get_purchase_info_of_day_shift(self, days=0):
     today = get_start_time_of_today()
     start = today.replace(days=days)
     end = start.replace(days=1)
     return self._get_purchase_info(start.timestamp, end.timestamp)
Exemplo n.º 32
0
 def count_of_today(self):
     today = get_start_time_of_today()
     tomorrow = today.replace(days=1)
     return self.count(start_at=today.timestamp, end_at=tomorrow.timestamp)