def initCharacterInterest(): ''' 初始化全部角色兴趣/精力/天赋数值分配 ''' interestList = [] languageSkills = TextLoading.getGameData(TextLoading.languageSkillsPath) interestList += list(languageSkills.keys()) knowledgeData = TextLoading.getGameData(TextLoading.knowledge) for knowledgeTag in knowledgeData: knowledgeList = knowledgeData[knowledgeTag] interestList += list(knowledgeList['Knowledge'].keys()) interestAverage = 100 / len(interestList) for character in CacheContorl.characterData['character']: nowInterestValueMax = 100 nowInterestList = interestList.copy() numpy.random.shuffle(nowInterestList) for interest in nowInterestList: if interest != nowInterestList[-1]: nowInterestAverage = nowInterestValueMax / len(nowInterestList) nowInterValue = nowInterestAverage * random.uniform(0.75, 1.25) nowInterestValueMax -= nowInterValue CacheContorl.characterData['character'][character]['Interest'][ interest] = nowInterValue / interestAverage else: CacheContorl.characterData['character'][character]['Interest'][ interest] = nowInterestValueMax
def setRichTextPrint(textMessage: str, defaultStyle: str) -> list: ''' 获取文本的富文本样式列表 Keyword arguments: textMessage -- 原始文本 defaultStyle -- 无富文本样式时的默认样式 ''' printJudge = False styleNameList = { key: 0 for key in GameConfig.getFontDataList() + list(TextLoading.getGameData(TextLoading.barConfigPath).keys()) } styleIndex = 0 styleLastIndex = None styleMaxIndex = None styleList = [] for key in styleNameList: styleTextHead = '<' + key + '>' if styleTextHead in textMessage: styleIndex = 1 if styleIndex == 0: styleList = [defaultStyle] * len(textMessage) else: for i in range(0, len(textMessage)): inputTextStyleSize = textMessage.find('>', i) + 1 inputTextStyle = textMessage[i + 1:inputTextStyleSize - 1] if textMessage[i] == '<' and ( (inputTextStyle in styleNameList) or (inputTextStyle[1:] in styleNameList)): styleLastIndex = i styleMaxIndex = inputTextStyleSize if inputTextStyle[0] == '/': if CacheContorl.textStylePosition['position'] == 1: CacheContorl.outputTextStyle = 'standard' CacheContorl.textStylePosition['position'] = 0 CacheContorl.textStyleCache = ['standard'] else: CacheContorl.textStylePosition[ 'position'] = CacheContorl.textStylePosition[ 'position'] - 1 CacheContorl.outputTextStyle = CacheContorl.textStyleCache[ CacheContorl.textStylePosition['position']] else: CacheContorl.textStylePosition['position'] = len( CacheContorl.textStyleCache) CacheContorl.textStyleCache.append(inputTextStyle) CacheContorl.outputTextStyle = CacheContorl.textStyleCache[ CacheContorl.textStylePosition['position']] else: if styleLastIndex != None: if i == len(textMessage): CacheContorl.textStylePosition['position'] = 0 CacheContorl.outputTextStyle = 'standard' CacheContorl.textStyleCache = ['standard'] if i not in range(styleLastIndex, styleMaxIndex): styleList.append(CacheContorl.outputTextStyle) else: styleList.append(CacheContorl.outputTextStyle) return styleList
def getTextIndex(text:str) -> int: ''' 计算文本最终显示的真实长度 Keyword arguments: text -- 要进行长度计算的文本 ''' textStyleList = RichText.setRichTextPrint(text, 'standard') textIndex = 0 stylewidth = 0 barlist = list(TextLoading.getGameData(TextLoading.barConfigPath).keys()) styleNameList = GameConfig.getFontDataList() + barlist for i in range(0, len(styleNameList)): styleTextHead = '<' + styleNameList[i] + '>' styleTextTail = '</' + styleNameList[i] + '>' if styleTextHead in text: if styleNameList[i] in barlist: text = text.replace(styleTextHead, '') text = text.replace(styleTextTail, '') else: text = text.replace(styleTextHead, '') text = text.replace(styleTextTail, '') for i in range(len(text)): if textStyleList[i] in barlist: textwidth = TextLoading.getTextData(TextLoading.barConfigPath,textStyleList[i])['width'] textIndex = textIndex + int(textwidth) else: textIndex += wcswidth(text[i]) return textIndex + stylewidth
def p(string:str, style='standard',richTextJudge=True): ''' 游戏基础的文本绘制实现 Keyword arguments: string -- 需要绘制的文本 style -- 文本的默认样式 (default 'standard') richTextJudge -- 启用富文本的开关 (default True) ''' if richTextJudge: barlist = list(TextLoading.getGameData(TextLoading.barConfigPath).keys()) string = Dictionaries.handleText(string) styleList = RichText.setRichTextPrint(string, style) global last_char if len(string) > 0: last_char = string[-1:] string = RichText.removeRichCache(string) string = r'' + string for i in range(0,len(string)): if styleList[i] in barlist: styledata = TextLoading.getTextData(TextLoading.barConfigPath,styleList[i]) truebar = styledata['truebar'] nullbar = styledata['nullbar'] if string[i] == '0': pimage(nullbar, 'bar') elif string[i] == '1': pimage(truebar, 'bar') else: IoInit.eraPrint(string[i], styleList[i]) else: IoInit.eraPrint(string[i], styleList[i]) else: IoInit.eraPrint(string,style)
def getStatureText(characterId: str) -> list: ''' 按角色Id获取身材描述信息 Keyword arguments: characterId -- 角色Id ''' statureJudge = judgeCharacterStature(characterId) for priority in CacheContorl.statureDescritionPrioritionData: for descript in CacheContorl.statureDescritionPrioritionData[priority]: if judgeStatureDescription( statureJudge, TextLoading.getGameData(TextLoading.statureDescriptionPath) ['Priority'][priority][descript]['Condition']): return TextLoading.getGameData( TextLoading.statureDescriptionPath )['Priority'][priority][descript]['Description'] return ''
def initClassTimeTable(): ''' 初始化各班级课程表 ''' courseSession = TextLoading.getGameData(TextLoading.courseSession) classTimeTable = {} for phase in CacheContorl.courseData['ClassHour']: classTime = {} classTimeTable[phase] = {} classDay = 0 if phase <= 5: classTime = courseSession['PrimarySchool'] classDay = 6 elif phase <= 7: classTime = courseSession['JuniorMiddleSchool'] classDay = 7 else: classTime = courseSession['SeniorHighSchool'] classDay = 8 classHour = CacheContorl.courseData['ClassHour'][phase] classHourIndex = {} for course in reversed(list(classHour.keys())): classHourIndex.setdefault(course, 0) while classHourIndex[course] < classHour[course]: for day in range(1, classDay): oldDay = day - 1 if oldDay == 0: oldDay = classDay - 1 classTimeTable[phase].setdefault(day, {}) classTimeTable[phase].setdefault(oldDay, {}) for i in range(1, len(classTime.keys())): time = list(classTime.keys())[i] if time not in classTimeTable[phase][ oldDay] and time not in classTimeTable[phase][ day]: classTimeTable[phase][day][time] = course classHourIndex[course] += 1 break elif time not in classTimeTable[phase][day]: if course != classTimeTable[phase][oldDay][time]: classTimeTable[phase][day][time] = course classHourIndex[course] += 1 break elif i == len(classTime) - 1: classTimeTable[phase][day][time] = course classHourIndex[course] += 1 break elif all([ k in classTimeTable[phase][day] for k in list(classTime.keys())[i + 1:] ]): classTimeTable[phase][day][time] = course classHourIndex[course] += 1 break if classHourIndex[course] >= classHour[course]: break CacheContorl.courseData['ClassTimeTable'] = classTimeTable
def getRandomNature(): ''' 初始化角色性格 ''' natureList = TextLoading.getGameData(TextLoading.naturePath) natureData = { bDimension: random.uniform(0, 100) for aDimension in natureList for bDimension in natureList[aDimension]['Factor'] } return natureData
def judgeChestGroup(chest: int): ''' 判断胸围差所属罩杯 Keyword arguments: chest -- 胸围差 ''' chestGroup = TextLoading.getGameData( TextLoading.attrTemplatePath)['ChestTem'] for chestTem in chestGroup: if int(chest) >= int(chestGroup[chestTem][0]) and int( chest) < chestGroup[chestTem][1]: return chestTem
def judgeAgeGroup(age: int): ''' 判断所属年龄段 Keyword arguments: age -- 年龄 ''' ageGroup = TextLoading.getGameData(TextLoading.attrTemplatePath)['AgeTem'] for ageTem in ageGroup: if int(age) >= int(ageGroup[ageTem]['MiniAge']) and int(age) < int( ageGroup[ageTem]['MaxAge']): return ageTem return 'YoundAdult'
def seeCharacterLanguagePanel(characterId: str): ''' 查看角色语言能力面板 Keyword arguments: characterId -- 角色Id ''' languageTextData = TextLoading.getGameData(TextLoading.languageSkillsPath) characterLanguage = CacheContorl.characterData['character'][ characterId].Language infoList = [ languageTextData[language]['Name'] + ":" + AttrText.getLevelColorText(characterLanguage[language]) for language in characterLanguage ] EraPrint.plist(infoList, 4, 'center')
def initAttr(self): ''' 随机生成角色属性 ''' self.Language[self.MotherTongue] = 10000 self.Birthday = AttrCalculation.getRandNpcBirthDay(self.Age) self.Height = AttrCalculation.getHeight(self.Sex,self.Age,{}) bmi = AttrCalculation.getBMI(self.WeigtTem) self.Weight = AttrCalculation.getWeight(bmi,self.Height['NowHeight']) self.BodyFat = AttrCalculation.getBodyFat(self.Sex,self.BodyFatTem) self.Measurements = AttrCalculation.getMeasurements(self.Sex,self.Height['NowHeight'],self.Weight,self.BodyFat,self.BodyFatTem) self.SexExperience = AttrCalculation.getSexExperience(self.SexExperienceTem) self.SexGrade = AttrCalculation.getSexGrade(self.SexExperience) defaultClothingData = Clothing.creatorSuit(self.ClothingTem,self.Sex) self.Clothing = {clothing:{uuid.uuid1():defaultClothingData[clothing]} if clothing in defaultClothingData else {} for clothing in self.Clothing} self.Chest = AttrCalculation.getChest(self.ChestTem,self.Birthday) self.HitPointMax = AttrCalculation.getMaxHitPoint(self.HitPointTem) self.HitPoint = self.HitPointMax self.ManaPointMax = AttrCalculation.getMaxManaPoint(self.ManaPointTem) self.ManaPoint = self.ManaPointMax self.Nature = Nature.getRandomNature() self.Status = TextLoading.getGameData(TextLoading.characterStatePath) self.WearItem = { "Wear":{key:{} for key in TextLoading.getGameData(TextLoading.wearItemPath)['Wear']}, "Item":{}, } self.Engraving = { "Pain":0, "Happy":0, "Yield":0, "Fear":0, "Resistance":0 } self.SocialContact = {social:{} for social in TextLoading.getTextData(TextLoading.stageWordPath,'144')} self.initClass() self.putOn()
def removeRichCache(string: str) -> str: ''' 移除文本中的富文本标签 Keyword arguments: string -- 原始文本 ''' string = Dictionaries.handleText(string) barlist = list(TextLoading.getGameData(TextLoading.barConfigPath).keys()) styleNameList = GameConfig.getFontDataList() + barlist for i in range(0, len(styleNameList)): styleTextHead = '<' + styleNameList[i] + '>' styleTextTail = '</' + styleNameList[i] + '>' if styleTextHead in string: string = string.replace(styleTextHead, '') string = string.replace(styleTextTail, '') return string
def seeCharacterKnowledgePanel(characterId: str): ''' 查看角色技能信息面板 Keyword arguments: characterId -- 角色Id ''' knowledgeTextData = TextLoading.getGameData(TextLoading.knowledge) characterKnowledge = CacheContorl.characterData['character'][ characterId].Knowledge for knowledge in knowledgeTextData: EraPrint.sontitleprint(knowledgeTextData[knowledge]['Name']) if knowledge in characterKnowledge: infoList = [ knowledgeTextData[knowledge]['Knowledge'][skill]['Name'] + ":" + AttrText.getLevelColorText( characterKnowledge[knowledge][skill]) for skill in characterKnowledge[knowledge] ] EraPrint.plist(infoList, 6, 'center')
def seeCharacter(characterId: str, judge: bool) -> list: ''' 用于任何时候查看角色性格信息面板 Keyword arguments: characterId -- 角色Id judge -- 绘制按钮校验 Return arguments: list -- 按钮列表 ''' natureTextData = TextLoading.getGameData(TextLoading.naturePath) characterNature = CacheContorl.characterData['character'][ characterId].Nature cmdList = [] for nature in natureTextData: natureText = natureTextData[nature]['Name'] if 'Good' in natureText: nowNatureValues = [ characterNature[sonNature] for sonNature in natureTextData[nature]['Factor'] ] nowNatureValue = sum(nowNatureValues) nowNatureMax = len(nowNatureValues) * 100 if nowNatureValue < nowNatureMax / 2: natureText = natureText['Bad'] else: natureText = natureText['Good'] EraPrint.sontitleprint(natureText) infoList = [ natureTextData[nature]['Factor'][sonNature][judgeNatureGood( characterNature[sonNature])] for sonNature in natureTextData[nature]['Factor'] ] if judge: nowSonList = [son for son in natureTextData[nature]['Factor']] cmdList += nowSonList CmdButtonQueue.optionstr(None, len(nowSonList), 'center', False, False, infoList, '', nowSonList) else: EraPrint.plist(infoList, len(infoList), 'center') return cmdList
CacheContorl.courseData['ClassTeacher'][ 'Classroom_' + str(phase)][classroom][course] = [] for teacher in CacheContorl.teacherCourseExperience[ course]: if teacher not in teacherData: CacheContorl.courseData['ClassTeacher'][ 'Classroom_' + str(phase)][classroom][course].append(teacher) teacherCourseIndex += 1 if teacherCourseIndex == 2: teacherCourseIndex = 0 teacherData[teacher] = 0 break courseKnowledgeData = TextLoading.getGameData(TextLoading.course) def initPhaseCourseHourExperience(): ''' 按年级计算各科目课时经验标准量 ''' phaseExperience = {} for phase in CacheContorl.courseData['ClassHour']: phaseExperience[phase] = {} for course in CacheContorl.courseData['ClassHour'][phase]: courseHour = CacheContorl.courseData['ClassHour'][phase][course] for knowledge in courseKnowledgeData[course]['Knowledge']: if knowledge not in phaseExperience[phase]: phaseExperience[phase][knowledge] = {} for skill in courseKnowledgeData[course]['Knowledge'][