def parse_rune_craft_data(craft_data, owner): # craft_type_id = 5 digit number # Work backwards to figure it out # [-1:] = quality # [-4:-2] = stat # [:-4] = rune set com2us_id = craft_data['craft_item_id'] craft = RuneCraftInstance.objects.filter(com2us_id=com2us_id, owner=owner).first() if not craft: craft = RuneCraftInstance(com2us_id=com2us_id, owner=owner) craft_type_id = str(craft_data['craft_type_id']) quality = int(craft_type_id[-1:]) stat = int(craft_type_id[-4:-2]) rune_set = int(craft_type_id[:-4]) craft.type = RuneCraftInstance.COM2US_CRAFT_TYPE_MAP.get( craft_data['craft_type']) craft.quality = RuneCraftInstance.COM2US_QUALITY_MAP.get(quality) craft.stat = RuneCraftInstance.COM2US_STAT_MAP.get(stat) craft.rune = RuneCraftInstance.COM2US_TYPE_MAP.get(rune_set) craft.quantity = craft_data.get('amount', 1) craft.value = craft_data['sell_value'] return craft
def parse_rune_craft_data(craft_data, owner): # craft_type_id = 5 digit number # Work backwards to figure it out # [:-1] = quality # [-4:-2] = stat # [:-4] = rune set com2us_id = craft_data['craft_item_id'] craft = RuneCraftInstance.objects.filter(com2us_id=com2us_id, owner=owner).first() if not craft: craft = RuneCraftInstance() craft_type_id = str(craft_data['craft_type_id']) quality = int(craft_type_id[-1:]) stat = int(craft_type_id[-4:-2]) rune_set = int(craft_type_id[:-4]) craft.type = com2us_mapping.craft_type_map.get(craft_data['craft_type']) craft.quality = com2us_mapping.craft_quality_map.get(quality) craft.stat = com2us_mapping.rune_stat_type_map.get(stat) craft.rune = com2us_mapping.rune_set_map.get(rune_set) craft.value = craft_data['sell_value'] return craft
def get_craft_stats_by_type(request, craft_type): valid_stats = RuneCraftInstance.get_valid_stats_for_type(int(craft_type)) if valid_stats: return JsonResponse({ 'code': 'success', 'data': valid_stats, }) else: return JsonResponse({ 'code': 'error', })
def parse_rune_craft_data(craft_data, owner): # craft_type_id = 5 digit number # Work backwards to figure it out # [-1:] = quality # [-4:-2] = stat # [:-4] = rune set com2us_id = craft_data['craft_item_id'] craft = RuneCraftInstance.objects.filter(com2us_id=com2us_id, owner=owner).first() if not craft: is_new = True craft = RuneCraftInstance(com2us_id=com2us_id, owner=owner) else: is_new = False craft_type_id = str(craft_data['craft_type_id']) quality = int(craft_type_id[-1:]) stat = int(craft_type_id[-4:-2]) rune_set = int(craft_type_id[:-4]) # if craft data already exists w/o quantity change, then we assume it's the same as it was before import if not is_new and craft.quantity == craft_data.get('amount', 1): return craft, False # craft obj, has_changed_or_new craft.type = RuneCraftInstance.COM2US_CRAFT_TYPE_MAP.get( craft_data['craft_type']) craft.quality = RuneCraftInstance.COM2US_QUALITY_MAP.get(quality) craft.stat = RuneCraftInstance.COM2US_STAT_MAP.get(stat) craft.rune = RuneCraftInstance.COM2US_TYPE_MAP.get(rune_set) craft.quantity = craft_data.get('amount', 1) craft.value = craft_data['sell_value'] return craft, True # craft obj, has_changed_or_new