How to use FindByName method in websmith

Best Python code snippet using websmith_python

CharacterCreation.py

Source:CharacterCreation.py Github

copy

Full Screen

12from client import *34# Character Templates5CharacterTemplates = (6 ("Samurai", 1062948, 1062950, 5591, Skills.Bushido, 50, Skills.Swordsmanship, 50, Skills.Wrestling, 0, 40, 30, 10),7 ("Ninja", 1062949, 1062951, 5589, Skills.Ninjitsu, 50, Skills.Hiding, 50, Skills.Wrestling, 0, 40, 30, 10),8 ("Paladin", 1061177, 1061227, 5587, Skills.Chivalry, 50, Skills.Tactics, 50, Skills.Wrestling, 0, 45, 20, 15),9 ("Necromancer", 1061178, 1061228, 5557, Skills.Necromancy, 50, Skills.Swordsmanship, 30, Skills.Tactics, 20, 25, 20, 35),10 ("Warrior", 1061180, 1061230, 5577, Skills.Tactics, 50, Skills.Healing, 45, Skills.Swordsmanship, 5, 35, 35, 10),11 ("Mage", 1061179, 1061229, 5569, Skills.Magery, 50, Skills.Meditation, 50, Skills.Wrestling, 0, 25, 10, 45),12 ("Blacksmith", 1061181, 1061231, 5555, Skills.Blacksmithy, 50, Skills.Tinkering, 45, Skills.Mining, 5, 60, 10, 10),13 ("Advanced", 3000448, 3000448, 5505, Skills.Alchemy, 50, Skills.Alchemy, 50, Skills.Alchemy, 0, 30, 25, 25),14)1516# City Names17CityNames = ("Yew", "Minoc", "Britain", "Moonglow", "Trinsic", "Magincia", "Jhelom", "Skara Brae", "Vesper")1819# Description of a city displayed in the right html gump20CityDescriptions = (1075072, 1075073, 1075074, 1075075, 1075076, 1075077, 1075078, 1075079, 1075080)2122# In this order: None, Short, Long, Ponytail, Mohawk, Pageboy, Topknot, Curly, Receding, Pigtails23HairstyleIds = (0, 0x203b, 0x203c, 0x203d, 0x2044, 0x2045, 0x204a, 0x2047, 0x2048, 0x2049)2425# In this order: None, Goatee, Long Beard, Short Beard, Moustache, Medium Short Beard, Medium Long beard, Vandyke26FacialHairstyleIds = (0, 0x2040, 0x203e, 0x203f, 0x2041, 0x204b, 0x204c, 0x204d)2728CTINDEX_NAME = 0 # Index Constant for the template name29CTINDEX_LOCALIZEDNAME = 130CTINDEX_LOCALIZEDDESC = 231CTINDEX_GUMP = 332CTINDEX_SKILL1 = 433CTINDEX_SKILL1VALUE = 534CTINDEX_SKILL2 = 635CTINDEX_SKILL2VALUE = 736CTINDEX_SKILL3 = 837CTINDEX_SKILL3VALUE = 938CTINDEX_STRENGTH = 1039CTINDEX_DEXTERITY = 1140CTINDEX_INTELLIGENCE = 124142GENDER_MALE = 043GENDER_FEMALE = 14445# Note: This won't work with sphere46MAXIMUM_STATS = 8047MAX_STAT = 6048MIN_STAT = 1049SKILLCOUNT = Skills.count()5051# List of forbidden name contents52FORBIDDEN = ("lord", "lady", "gm", "counselor", "seer")5354# Return true if character name is valid55def isValidName(name):56 name = name.lower()57 for word in FORBIDDEN:58 # Contains wrong word59 if word in name:60 return False61 62 # Also the name may only contain certain characters,63 # but the first char has to be a letter64 if ord(name[0]) < ord('a') or ord(name[0]) > ord('z'):65 return False66 67 # Check the rest of the chars68 for ch in name:69 if ch != ' ' and ch != '-' and ch != '\'' and ch != '.' and (ord(ch) < ord('a') or ord(ch) > ord('z')):70 return False7172 return True7374# This class manages the context of the current character creation75class Context:76 """77 Setup the contexts default78 """79 def __init__(self):80 self.profession = -181 self.strength = 1082 self.dexterity = 1083 self.intelligence = 1084 self.skill1 = -185 self.skill2 = -186 self.skill3 = -187 self.skill1Value = 5088 self.skill2Value = 5089 self.skill3Value = 090 self.normalizingSkills = False91 self.hairstyle = 092 self.facialhairstyle = 093 self.pantscolor = random(2, 0x3e9)94 self.shirtcolor = random(2, 0x3e9)95 self.gender = GENDER_MALE96 self.haircolor = random(0x44e, 0x47d)97 self.facialhaircolor = random(0x44e, 0x47d)98 self.skincolor = random(0x3ea, 0x422)99 self.name = 'Nobody'100101 """102 Show the first page of the character creation103 """104 def showFirst(self):105 loginDialog = Gui.findByName("LoginDialog")106 loginDialog.findByName("CharacterCreation1").visible = True107 108 """109 Hide all character creation pages110 """111 def hideAll(self):112 loginDialog = Gui.findByName("LoginDialog")113 loginDialog.findByName("CharacterCreation1").visible = False114 loginDialog.findByName("CharacterCreation2").visible = False115 loginDialog.findByName("CharacterCreation3").visible = False 116117 """118 Select the profession with the given id119 """120 def selectProfession(self, id):121 self.profession = id122 123 self.setStrength(CharacterTemplates[id][CTINDEX_STRENGTH], True)124 self.setDexterity(CharacterTemplates[id][CTINDEX_DEXTERITY], True)125 self.setIntelligence(CharacterTemplates[id][CTINDEX_INTELLIGENCE], True)126 127 self.setSkillValue(1, CharacterTemplates[id][CTINDEX_SKILL1VALUE], True)128 self.setSkillValue(2, CharacterTemplates[id][CTINDEX_SKILL2VALUE], True)129 self.setSkillValue(3, CharacterTemplates[id][CTINDEX_SKILL3VALUE], True)130 dialog = Gui.findByName("CharacterCreation2")131 dialog.findByName("SkillBox1").selectItem(CharacterTemplates[id][CTINDEX_SKILL1])132 dialog.findByName("SkillBox2").selectItem(CharacterTemplates[id][CTINDEX_SKILL2])133 dialog.findByName("SkillBox3").selectItem(CharacterTemplates[id][CTINDEX_SKILL3])134135 # Hide current dialog and show next136 loginDialog = Gui.findByName("LoginDialog")137 loginDialog.findByName("CharacterCreation1").visible = False138 139 if CharacterTemplates[id][CTINDEX_NAME] == "Advanced":140 loginDialog.findByName("CharacterCreation2").visible = True141 else:142 self.dialog2Next(None)143 144 """145 Initialize the Character creation dialog (page 1)146 """147 def setupDialog1(self, dialog):148 # Center the title label149 label = dialog.findByName("TitleLabel") 150 if label:151 label.update()152 label.x = label.x + (400 - label.width) / 2 153 154 xpos = 135155 ypos = 147156 157 # Add profession selection buttons158 for i in range(0, len(CharacterTemplates)):159 template = CharacterTemplates[i]160 optn = Gui.createDialog("CharacterTemplate")161 if optn:162 # Set the label text and the gump id163 label = optn.findByName("TemplateLabel")164 label.text = Localization.get(template[CTINDEX_LOCALIZEDNAME])165 btn = optn.findByName("TemplateButton")166 btn.setStateGump(BS_UNPRESSED, template[CTINDEX_GUMP])167 btn.setStateGump(BS_PRESSED, template[CTINDEX_GUMP] + 1)168 btn.setStateGump(BS_HOVER, template[CTINDEX_GUMP] + 1)169 btn.setTag("profession", str(i))170 connect(btn, "onButtonPress(cControl*)", self.characterCreation1Next)171 172 optn.setPosition(xpos, ypos)173 dialog.addControl(optn)174 175 if i % 2 == 0:176 xpos += 205177 else:178 xpos -= 205179 ypos += 70180 181 connect(dialog.findByName("BackButton"), "onButtonPress(cControl*)", self.dialog1Back)182 183 def dialog1Back(self, button):184 LoginDialog.show(PAGE_SELECTCHAR) 185 186 """187 Select a profession and advance to the next page.188 """189 def characterCreation1Next(self, button):190 # We only process profession buttons here191 if not button.hasTag("profession"):192 return 193194 self.selectProfession(int(button.getTag("profession")))195196 """197 Go back198 """199 def dialog2Back(self, button):200 # Hide current dialog and show next201 loginDialog = Gui.findByName("LoginDialog")202 loginDialog.findByName("CharacterCreation2").visible = False203 loginDialog.findByName("CharacterCreation1").visible = True204 205 """206 Close an error dialog and show207 self.showAfterError instead208 """209 def closeErrorDialog(self, button):210 loginDialog = Gui.findByName("LoginDialog")211 212 errorDialog = loginDialog.findByName("CharacterCreationError") 213 errorDialog.visible = False214 errorDialog.deleteLater()215 216 dialog = loginDialog.findByName(self.showAfterError)217 dialog.visible = True218 219 """220 Check if the skills differ, then next screen221 """222 def dialog2Next(self, button):223 loginDialog = Gui.findByName("LoginDialog")224 dialog = loginDialog.findByName("CharacterCreation2")225 self.skill1 = dialog.findByName("SkillBox1").selectionIndex()226 self.skill2 = dialog.findByName("SkillBox2").selectionIndex()227 self.skill3 = dialog.findByName("SkillBox3").selectionIndex()228 229 # Check if the user has selected three different skillst230 if self.skill1 == self.skill2 or self.skill1 == self.skill3 or self.skill2 == self.skill3 or self.skill1 == -1 or self.skill2 == -1 or self.skill3 == -1:231 dialog.visible = False232 self.showError("Please Select Three Different Skills.", "CharacterCreation2")233 return234 235 # Hide current dialog and show next236 dialog.visible = False 237 self.showDialog3()238 239 def showError(self, message, showAfter):240 loginDialog = Gui.findByName("LoginDialog")241 errorDialog = loginDialog.findByName("CharacterCreationError")242 if not errorDialog:243 errorDialog = Gui.createDialog("CharacterCreationError")244 loginDialog.addControl(errorDialog)245 246 label = errorDialog.findByName("MessageLabel")247 label.text = message248 label.x = 25 + (180 - label.width) / 2249 250 self.showAfterError = showAfter251 connect(errorDialog.findByName("OkButton"), "onButtonPress(cControl*)", self.closeErrorDialog)252 errorDialog.visible = True253 254 def strengthScrolled(self, value):255 loginDialog = Gui.findByName("LoginDialog")256 strengthScroller = loginDialog.findByName("StrengthScroller")257 self.setStrength(strengthScroller.pos)258 259 def dexterityScrolled(self, value):260 loginDialog = Gui.findByName("LoginDialog")261 dexterityScroller = loginDialog.findByName("DexterityScroller")262 self.setDexterity(dexterityScroller.pos)263 264 def intelligenceScrolled(self, value):265 loginDialog = Gui.findByName("LoginDialog")266 intelligenceScroller = loginDialog.findByName("IntelligenceScroller")267 self.setIntelligence(intelligenceScroller.pos)268 269 def skill1Scrolled(self, value):270 if self.normalizingSkills:271 return272 loginDialog = Gui.findByName("LoginDialog")273 scroller = loginDialog.findByName("SkillScroller1")274 self.setSkillValue(1, scroller.pos)275 276 def skill2Scrolled(self, value):277 if self.normalizingSkills:278 return 279 loginDialog = Gui.findByName("LoginDialog")280 scroller = loginDialog.findByName("SkillScroller2")281 self.setSkillValue(2, scroller.pos)282 283 def skill3Scrolled(self, value):284 if self.normalizingSkills:285 return 286 loginDialog = Gui.findByName("LoginDialog")287 scroller = loginDialog.findByName("SkillScroller3")288 self.setSkillValue(3, scroller.pos) 289290 """291 Initialize the Character creation dialog (page 2)292 """293 def setupDialog2(self, dialog): 294 # Center the title label295 label = dialog.findByName("TitleLabel")296 if label:297 label.update() # Make sure the size is correct298 label.x = label.x + (400 - label.width) / 2299 300 backButton = dialog.findByName("BackButton")301 nextButton = dialog.findByName("NextButton")302 connect(backButton, "onButtonPress(cControl*)", self.dialog2Back)303 connect(nextButton, "onButtonPress(cControl*)", self.dialog2Next)304 305 connect(dialog.findByName("StrengthScroller"), "scrolled(int)", self.strengthScrolled)306 connect(dialog.findByName("DexterityScroller"), "scrolled(int)", self.dexterityScrolled)307 connect(dialog.findByName("IntelligenceScroller"), "scrolled(int)", self.intelligenceScrolled)308 connect(dialog.findByName("SkillScroller1"), "scrolled(int)", self.skill1Scrolled)309 connect(dialog.findByName("SkillScroller2"), "scrolled(int)", self.skill2Scrolled)310 connect(dialog.findByName("SkillScroller3"), "scrolled(int)", self.skill3Scrolled) 311312 items = []313 for i in range(0, SKILLCOUNT - 1):314 items.append(Localization.get(1044060 + i))315316 # Set up the combo boxes317 cb1 = dialog.findByName("SkillBox1")318 cb1.setItems(items)319 cb2 = dialog.findByName("SkillBox2")320 cb2.setItems(items)321 cb3 = dialog.findByName("SkillBox3")322 cb3.setItems(items)323 324 """325 Change the shirt color326 """327 def setShirtColor(self, color):328 dialog = Gui.findByName("LoginDialog")329 gump = dialog.findByName("PaperdollTorso")330 gump.hue = color331 self.shirtcolor = color332 333 """334 Change the pants color335 """336 def setPantsColor(self, color):337 dialog = Gui.findByName("LoginDialog")338 gump = dialog.findByName("PaperdollLegs")339 gump.hue = color340 self.pantscolor = color341 342 """343 The hair style changed344 """345 def hairStyleChanged(self):346 dialog = Gui.findByName("CharacterCreation3")347 348 cb = dialog.findByName("HairStyle")349 style = cb.selectionIndex()350 351 self.hairstyle = style352 353 gump = dialog.findByName("PaperdollHair")354 if style == 0:355 gump.visible = False356 else:357 # Get the gump id358 tiledata = Tiledata.getItemInfo(HairstyleIds[style]) 359 360 gump.visible = True361 if self.gender == GENDER_FEMALE and Gumpart.exists(60000 + tiledata.animation):362 gump.setId(60000 + tiledata.animation)363 else:364 gump.setId(50000 + tiledata.animation) 365 366 """367 The facial hair style changed368 """369 def facialHairStyleChanged(self):370 dialog = Gui.findByName("CharacterCreation3")371 372 cb = dialog.findByName("FacialHairStyle")373 style = cb.selectionIndex()374 self.facialhairstyle = style375 376 gump = dialog.findByName("PaperdollFacialHair")377 378 # No beards for females379 if self.gender == GENDER_FEMALE: 380 self.facialhairstyle = 0381 gump.visible = False382 return383 384 if style == 0:385 gump.visible = False386 else:387 # Get the gump id388 tiledata = Tiledata.getItemInfo(FacialHairstyleIds[style])389 390 gump.visible = True391 gump.setId(50000 + tiledata.animation)392 393 """394 Show dialog 3395 """ 396 def showDialog3(self):397 self.setShirtColor(self.shirtcolor)398 self.setPantsColor(self.pantscolor)399 loginDialog = Gui.findByName("LoginDialog")400 charCreation = loginDialog.findByName("CharacterCreation3")401 402 # Select random hairstyle403 cb = charCreation.findByName("HairStyle")404 cb.selectItem(random(0, len(HairstyleIds) - 1))405 406 charCreation.visible = True 407 408 """409 Change the color of the skin.410 """411 def setSkinColor(self, color, dialog = None):412 if not dialog:413 loginDialog = Gui.findByName("LoginDialog")414 dialog = loginDialog.findByName("CharacterCreation3")415 gump = dialog.findByName("PaperdollBody")416 gump.hue = color417 self.skincolor = color418 419 """420 Change the color of the hair.421 """422 def setHairColor(self, color, dialog = None):423 if not dialog:424 loginDialog = Gui.findByName("LoginDialog")425 dialog = loginDialog.findByName("CharacterCreation3")426 gump = dialog.findByName("PaperdollHair")427 gump.hue = color428 self.haircolor = color429 430 """431 Change the color of the facial hair.432 """433 def setFacialHairColor(self, color, dialog = None):434 if not dialog:435 loginDialog = Gui.findByName("LoginDialog")436 dialog = loginDialog.findByName("CharacterCreation3")437 gump = dialog.findByName("PaperdollFacialHair")438 gump.hue = color 439 self.facialhaircolor = color440 441 """442 The hair color button has been clicked443 """444 def changeHairColorClicked(self, button):445 self.setDialog3Visibility(False)446 447 dialog = Gui.findByName("CharacterCreation3")448 dialog.findByName("HairColorPicker").visible = True449 self.selectingColor = "hair"450 451 """452 The facial hair color button has been clicked453 """454 def changeFacialHairColorClicked(self, button):455 self.setDialog3Visibility(False)456 457 dialog = Gui.findByName("CharacterCreation3")458 dialog.findByName("HairColorPicker").visible = True459 self.selectingColor = "facial"460461 """462 Gender button slots463 """464 def setFemaleGender(self, button):465 self.setGender(GENDER_FEMALE)466 467 def setMaleGender(self, button):468 self.setGender(GENDER_MALE)469 470 """471 Change gender472 """473 def setGender(self, gender):474 if self.gender == gender:475 return476 477 self.gender = gender # Change local gender setting478 479 # Change Paperdoll Body480 loginDialog = Gui.findByName("LoginDialog")481 dialog = loginDialog.findByName("CharacterCreation3")482 gump = dialog.findByName("PaperdollBody")483 if gender == GENDER_FEMALE:484 gump.id = 0xd485 else:486 gump.id = 0xc487488 # Refresh the gumps489 self.hairStyleChanged()490 self.facialHairStyleChanged()491 492 # Shoes493 gump = dialog.findByName("PaperdollFeet")494 if gender == GENDER_FEMALE:495 gump.id = 60480496 else:497 gump.id = 50480498499 # Legs500 gump = dialog.findByName("PaperdollLegs")501 if gender == GENDER_FEMALE:502 gump.id = 60449503 else:504 gump.id = 50430505506 # Torso507 gump = dialog.findByName("PaperdollTorso")508 if gender == GENDER_FEMALE:509 gump.id = 60434510 else:511 gump.id = 50434512513 # Hide or show the facial hairstyle button514 dialog.findByName("FacialHairStyle").visible = (gender == GENDER_MALE)515 dialog.findByName("FacialHairColorButton").visible = (gender == GENDER_MALE)516 517 # Rename the Skirt/Pants color button accordingly518 if gender == GENDER_MALE:519 dialog.findByName("PantsColorButton").text = Localization.get(3000441)520 else:521 dialog.findByName("PantsColorButton").text = Localization.get(3000439 )522 523 """524 Set up the third dialog page525 """526 def setupDialog3(self, dialog):527 styles = []528 for i in range(0, len(HairstyleIds)):529 styles.append(Localization.get(3000340 + i))530 531 cb = dialog.findByName("HairStyle")532 cb.setItems(styles)533 cb.selectItem(0)534 connect(cb, "selectionChanged()", self.hairStyleChanged)535 connect(dialog.findByName("HairColorButton"), "onButtonPress(cControl*)", self.changeHairColorClicked)536 537 styles = [Localization.get(3000340)]538 for i in range(0, len(FacialHairstyleIds)-1):539 styles.append(Localization.get(3000351 + i))540 541 cb = dialog.findByName("FacialHairStyle")542 cb.setItems(styles)543 cb.selectItem(0)544 connect(cb, "selectionChanged()", self.facialHairStyleChanged)545 connect(dialog.findByName("FacialHairColorButton"), "onButtonPress(cControl*)", self.changeFacialHairColorClicked)546547 connect(dialog.findByName("FemaleButton"), "onButtonPress(cControl*)", self.setFemaleGender) 548 connect(dialog.findByName("MaleButton"), "onButtonPress(cControl*)", self.setMaleGender)549 connect(dialog.findByName("ShirtColorButton"), "onButtonPress(cControl*)", self.selectShirtColor)550 connect(dialog.findByName("PantsColorButton"), "onButtonPress(cControl*)", self.selectPantsColor)551 connect(dialog.findByName("ClothColorPicker"), "colorSelected(ushort)", self.clothColorSelected)552 connect(dialog.findByName("SkinColorPicker"), "colorSelected(ushort)", self.skinToneSelected)553 connect(dialog.findByName("HairColorPicker"), "colorSelected(ushort)", self.hairColorSelected)554 connect(dialog.findByName("SkinToneButton"), "onButtonPress(cControl*)", self.selectSkinTone)555 556 connect(dialog.findByName("BackButton"), "onButtonPress(cControl*)", self.dialog3Back)557 connect(dialog.findByName("NextButton"), "onButtonPress(cControl*)", self.dialog3Next)558 559 self.setHairColor(self.haircolor, dialog)560 self.setFacialHairColor(self.facialhaircolor, dialog)561 self.setSkinColor(self.skincolor, dialog)562 563 """564 Set up the fourth dialog page565 """566 def setupDialog4(self, dialog):567 connect(dialog.findByName("BackButton"), "onButtonPress(cControl*)", self.dialog4Back)568 connect(dialog.findByName("NextButton"), "onButtonPress(cControl*)", self.dialog4Next)569 connect(dialog.findByName("CityInfoScroller"), "scrolled(int)", self.cityScrollerScroll)570 571 # Bind the combo box change event 572 for city in CityNames:573 connect(dialog.findByName(city), "stateChanged()", self.citySelected)574 575 """576 City scroller has been used.577 """578 def cityScrollerScroll(self, oldpos):579 dialog = Gui.findByName("CharacterCreation4")580 scroller = dialog.findByName("CityInfoScroller")581 label = dialog.findByName("CityInfo")582 label.y = - scroller.pos583 584 """585 The city selection has changed586 """587 def citySelected(self):588 dialog = Gui.findByName("CharacterCreation4")589 text = ''590 591 # Check which one was selected592 for i in range(0, len(CityNames)):593 radio = dialog.findByName(CityNames[i])594 if radio.checked:595 text = Localization.get(CityDescriptions[i])596 break597 598 label = dialog.findByName("CityInfo")599 label.height = 0600 label.text = text601 label.update()602 label.y = 0603604 diff = 1 + label.height - label.parent.height605 606 if diff <= 0:607 diff = 1608 609 scroller = dialog.findByName("CityInfoScroller")610 scroller.pos = 0611 scroller.setRange(0, diff)612613 """614 Dialog 4 Next/Back615 """616 def dialog4Back(self, button):617 loginDialog = Gui.findByName("LoginDialog")618 loginDialog.findByName("CharacterCreation4").visible = False619 loginDialog.findByName("CharacterCreation3").visible = True620 621 def dialog4Next(self, button):622 loginDialog = Gui.findByName("LoginDialog")623 dialog = loginDialog.findByName("CharacterCreation4") 624 selected = None625 626 # Make sure a city has been selected627 for city in CityNames:628 if dialog.findByName(city).checked:629 selected = city630 break631 632 # Show error if not633 if not selected:634 dialog.visible = False635 self.showError("Please select a start location.", "CharacterCreation4")636 return637 638 # Look it up in the starting locations array and639 # submit the given start location id640 startLocations = UoSocket.startLocations()641 642 for location in startLocations:643 if location[1] == selected or location[2] == selected:644 self.startLocation = location[0]645 break646 647 self.finalize()648649 """650 Finalize the character creation651 """652 def finalize(self):653 # Hide the entire dialog654 self.hideAll()655 656 # Create parameter list657 params = (self.name, self.gender == GENDER_FEMALE, self.strength, self.dexterity, self.intelligence,658 self.skill1, self.skill1Value, self.skill2, self.skill2Value, self.skill3, self.skill3Value, 659 self.skincolor, self.haircolor, self.facialhaircolor,660 HairstyleIds[self.hairstyle], FacialHairstyleIds[self.facialhairstyle], 661 self.startLocation, 0, self.shirtcolor, self.pantscolor)662 Network.createCharacter(params)663664 """665 Back + Next Button666 """667 def dialog3Next(self, dialog): 668 loginDialog = Gui.findByName("LoginDialog")669 dialog = loginDialog.findByName("CharacterCreation3")670 self.name = dialog.findByName("NameTextfield").text671 672 # Check the name673 if len(self.name) < 2:674 dialog.visible = False 675 self.showError(Localization.get(3000612), "CharacterCreation3") # Your character name is too short.676 return677 678 # Check if the name is valid679 if not isValidName(self.name):680 dialog.visible = False681 self.showError(Localization.get(3000611), "CharacterCreation3") # Your character name is too short.682 return683 684 startLocations = UoSocket.startLocations()685 686 # If there is only one start location or if we're chosing a template,687 # jump directly into the game688 if len(startLocations) == 1 or CharacterTemplates[self.profession][CTINDEX_NAME] != 'Advanced':689 self.startLocation = random(0, len(startLocations)-1)690 self.finalize()691 else:692 loginDialog = Gui.findByName("LoginDialog")693 loginDialog.findByName("CharacterCreation3").visible = False694 loginDialog.findByName("CharacterCreation4").visible = True695696 def dialog3Back(self, dialog):697 loginDialog = Gui.findByName("LoginDialog")698 loginDialog.findByName("CharacterCreation3").visible = False699 700 # Advanced Profession701 if self.profession == len(CharacterTemplates) - 1:702 loginDialog.findByName("CharacterCreation2").visible = True703 else:704 loginDialog.findByName("CharacterCreation1").visible = True705706 """707 The button for selecting the skin color has been pressed708 """709 def selectSkinTone(self, button):710 self.setDialog3Visibility(False)711 712 dialog = Gui.findByName("CharacterCreation3")713 dialog.findByName("SkinColorPicker").visible = True714715 """716 The button for selecting the shirt color has been pressed717 """718 def selectShirtColor(self, button):719 self.setDialog3Visibility(False)720 721 dialog = Gui.findByName("CharacterCreation3")722 dialog.findByName("ClothColorPicker").visible = True723 self.selectingColor = 'shirt' # Remember what we're picking the color for724725 """726 The button for selecting the pants color has been pressed727 """728 def selectPantsColor(self, button):729 self.setDialog3Visibility(False)730 731 dialog = Gui.findByName("CharacterCreation3")732 dialog.findByName("ClothColorPicker").visible = True733 self.selectingColor = 'pants' # Remember what we're picking the color for734735 """736 This gets triggered when a skin color is selected.737 """738 def skinToneSelected(self, color):739 self.setSkinColor(color)740 741 # Hide the skin color picker742 dialog = Gui.findByName("CharacterCreation3")743 dialog.findByName("SkinColorPicker").visible = False744 745 # Show all other controls746 self.setDialog3Visibility(True)747 748 """749 This gets triggered when a hair color is selected.750 """751 def hairColorSelected(self, color):752 if self.selectingColor == 'hair':753 self.setHairColor(color)754 elif self.selectingColor == 'facial':755 self.setFacialHairColor(color)756 757 # Hide the skin color picker758 dialog = Gui.findByName("CharacterCreation3")759 dialog.findByName("HairColorPicker").visible = False760 761 # Show all other controls762 self.setDialog3Visibility(True) 763764 """765 This gets triggered when a cloth color is selected.766 """767 def clothColorSelected(self, color):768 if self.selectingColor == 'shirt':769 self.setShirtColor(color)770 elif self.selectingColor == 'pants':771 self.setPantsColor(color)772 773 # Hide the cloth color picker774 dialog = Gui.findByName("CharacterCreation3")775 dialog.findByName("ClothColorPicker").visible = False776 777 # Show all other controls778 self.setDialog3Visibility(True)779 780 """781 Hide or show the contents of dialog 3782 """783 def setDialog3Visibility(self, visibility):784 dialog = Gui.findByName("CharacterCreation3")785 ids = ("MaleButton", "FemaleButton", "ShirtColorButton", "PantsColorButton", "SkinToneButton", "HairStyle", "HairColorButton", "FacialHairStyle", "FacialHairColorButton")786 for id in ids:787 ctrl = dialog.findByName(id)788 ctrl.visible = visibility789790 """791 Change one of the characters skills (1, 2 or 3)792 """793 def setSkillValue(self, skill, value, dontnormalize = False):794 if self.normalizingSkills and not dontnormalize:795 return796 797 loginDialog = Gui.findByName("LoginDialog")798 799 # Update the scrollbar800 scroller = loginDialog.findByName("SkillScroller%u" % skill)801 if scroller.pos != value:802 scroller.pos = value803 804 # Update the label805 label = loginDialog.findByName("SkillLabel%u" % skill)806 label.text = str(value)807 808 # Save strength809 if skill == 1:810 self.skill1 = value811 elif skill == 2:812 self.skill2 = value813 elif skill == 3:814 self.skill3 = value 815 816 if not dontnormalize:817 self.normalizeSkills(skill)818819 """820 Change the character strength821 """822 def setStrength(self, strength, dontnormalize = False):823 loginDialog = Gui.findByName("LoginDialog")824 825 # Update the scrollbar826 strengthScroller = loginDialog.findByName("StrengthScroller")827 if strengthScroller.pos != strength:828 strengthScroller.pos = strength829 830 # Update the label831 strengthLabel = loginDialog.findByName("StrengthLabel")832 strengthLabel.text = strength833 834 # Save strength835 self.strength = strength836 837 if not dontnormalize:838 self.normalizeStats(0)839 840 """841 Change the character dexterity842 """843 def setDexterity(self, dexterity, dontnormalize = False):844 loginDialog = Gui.findByName("LoginDialog")845 846 # Update the scrollbar847 dexterityScroller = loginDialog.findByName("DexterityScroller")848 if dexterityScroller.pos != dexterity:849 dexterityScroller.pos = dexterity850 851 # Update the label852 dexterityLabel = loginDialog.findByName("DexterityLabel")853 dexterityLabel.text = dexterity854 855 # Save dexterity856 self.dexterity = dexterity857 858 if not dontnormalize:859 self.normalizeStats(1)860 861 """862 Change the character intelligence863 """864 def setIntelligence(self, intelligence, dontnormalize = False):865 loginDialog = Gui.findByName("LoginDialog")866 867 # Update the scrollbar868 intelligenceScroller = loginDialog.findByName("IntelligenceScroller")869 if intelligenceScroller.pos != intelligence:870 intelligenceScroller.pos = intelligence871 872 # Update the label873 intelligenceLabel = loginDialog.findByName("IntelligenceLabel")874 intelligenceLabel.text = intelligence875 876 # Save intelligence877 self.intelligence = intelligence878 879 if not dontnormalize:880 self.normalizeStats(2)881 882 """883 If the statsum is greater than the maximum allowance, 884 reduce several stats.885 """886 def normalizeStats(self, excludeStat):887 # Temporary variables for str, dex, int888 strength = self.strength889 dexterity = self.dexterity890 intelligence = self.intelligence891 892 statsum = strength + dexterity + intelligence893 overflow = statsum - MAXIMUM_STATS894 895 if overflow > 0:896 # Exclude Strength897 if excludeStat == 0:898 if dexterity > intelligence:899 dexterity -= overflow900 if dexterity < MIN_STAT:901 intelligence -= MIN_STAT - dexterity902 dexterity = MIN_STAT 903 else:904 intelligence -= overflow;905 if intelligence < MIN_STAT:906 dexterity -= MIN_STAT - intelligence907 intelligence = MIN_STAT908 909 # Exclude Dexterity 910 elif excludeStat == 1:911 if strength > intelligence:912 strength -= overflow913 if strength < MIN_STAT:914 intelligence -= MIN_STAT - strength915 strength = MIN_STAT916 else:917 intelligence -= overflow918 if intelligence < MIN_STAT:919 strength -= MIN_STAT - intelligence920 intelligence = MIN_STAT921 922 # Exclude Intelligence923 elif excludeStat == 2:924 if strength > dexterity:925 strength -= overflow926 if strength < MIN_STAT:927 dexterity -= MIN_STAT - strength928 strength = MIN_STAT929 else:930 dexterity -= overflow931 if dexterity < MIN_STAT:932 strength -= MIN_STAT - dexterity933 dexterity = MIN_STAT934 elif overflow < 0:935 # Exclude Strength936 if excludeStat == 0:937 if dexterity < intelligence:938 dexterity -= overflow939 if dexterity < MIN_STAT:940 intelligence -= MIN_STAT - dexterity941 dexterity = MIN_STAT942 else:943 intelligence -= overflow;944 945 # Exclude Dexterity 946 elif excludeStat == 1:947 if strength < intelligence:948 strength -= overflow949 if strength < MIN_STAT:950 intelligence -= MIN_STAT - strength951 strength = MIN_STAT952 else:953 intelligence -= overflow954 955 # Exclude Intelligence956 elif excludeStat == 2:957 if strength < dexterity:958 strength -= overflow959 if strength < MIN_STAT:960 dexterity -= MIN_STAT - strength961 strength = MIN_STAT962 else:963 dexterity -= overflow964965 if strength != self.strength:966 self.setStrength(strength, True) # Set strength but dont normalize again967 if dexterity != self.dexterity:968 self.setDexterity(dexterity, True) # Set dexterity but dont normalize again969 if intelligence != self.intelligence:970 self.setIntelligence(intelligence, True) # Set intelligence but dont normalize again971 972 """973 If the skillsum is greater than the maximum allowance, 974 reduce several skills.975 """976 def normalizeSkills(self, excludeSkill):977 if self.normalizingSkills:978 return979 980 self.normalizingSkills = True981 982 # Temporary variables for str, dex, int983 skill1 = self.skill1984 skill2 = self.skill2985 skill3 = self.skill3986 987 statsum = skill1 + skill2 + skill3988 overflow = statsum - 100989990 if overflow > 0:991 # Exclude Skill1992 if excludeSkill == 1:993 if skill2 < skill3:994 skill2 -= overflow995 if skill2 < 0:996 skill3 -= 0 - skill2997 skill2 = 0998 else:999 skill3 -= overflow;1000 if skill3 < 0:1001 skill2 -= 0 - skill31002 skill3 = 01003 1004 # Exclude Skill2 1005 elif excludeSkill == 2:1006 if skill1 < skill3:1007 skill1 -= overflow1008 if skill1 < 0:1009 skill3 -= 0 - skill11010 skill1 = 01011 else:1012 skill3 -= overflow1013 if skill3 < 0:1014 skill1 -= 0 - skill31015 skill3 = 01016 1017 # Exclude Skill31018 elif excludeSkill == 3:1019 if skill1 < skill2:1020 skill1 -= overflow1021 if skill1 < 0:1022 skill2 -= 0 - skill11023 skill1 = 01024 else:1025 skill2 -= overflow1026 if skill2 < 0:1027 skill1 -= 0 - skill21028 skill2 = 01029 elif overflow < 0:1030 # Exclude Skill11031 if excludeSkill == 1:1032 if skill2 > skill3:1033 skill2 -= overflow1034 if skill2 > 50:1035 skill3 += skill2 - 501036 skill2 = 501037 else:1038 skill3 -= overflow;1039 if skill3 > 50:1040 skill2 += skill3 - 501041 skill3 = 501042 1043 # Exclude Skill2 1044 elif excludeSkill == 2:1045 if skill1 > skill3:1046 skill1 -= overflow1047 if skill1 > 50:1048 skill3 += skill1 - 501049 skill1 = 501050 else:1051 skill3 -= overflow1052 if skill3 > 50:1053 skill1 += skill3 - 501054 skill3 = 501055 1056 # Exclude Skill31057 elif excludeSkill == 3:1058 if skill1 > skill2:1059 skill1 -= overflow1060 if skill1 > 50:1061 skill2 += skill1 - 501062 skill1 = 501063 else:1064 skill2 -= overflow1065 if skill2 > 50:1066 skill1 += skill2 - 501067 skill2 = 501068 1069 if skill1 != self.skill1:1070 self.setSkillValue(1, skill1, True) # Set skill1 but dont normalize again1071 if skill2 != self.skill1:1072 self.setSkillValue(2, skill2, True) # Set skill2 but dont normalize again1073 if skill3 != self.skill3:1074 self.setSkillValue(3, skill3, True) # Set skill3 but dont normalize again 10751076 self.normalizingSkills = False10771078# Create the Character Creation context 1079context = Context()10801081def initialize(dialog):1082 global context1083 if dialog.objectName == "CharacterCreation1":1084 context.setupDialog1(dialog)1085 connect(LoginDialog, "showCharacterCreation()", context.showFirst)1086 connect(LoginDialog, "hideCharacterCreation()", context.hideAll)1087 elif dialog.objectName == "CharacterCreation2":1088 context.setupDialog2(dialog)1089 elif dialog.objectName == "CharacterCreation3":1090 context.setupDialog3(dialog)1091 elif dialog.objectName == "CharacterCreation4": ...

Full Screen

Full Screen

findby_name.py

Source:findby_name.py Github

copy

Full Screen

1# coding: utf-82from __future__ import absolute_import3from datetime import date, datetime # noqa: F4014from typing import List, Dict # noqa: F4015from swagger_server.models.base_model_ import Model6from swagger_server import util7class FindbyName(Model):8 """NOTE: This class is auto generated by the swagger code generator program.9 Do not edit the class manually.10 """11 def __init__(self, _date: datetime=None, orph_acode: int=None, preferred_term: str=None): # noqa: E50112 """FindbyName - a model defined in Swagger13 :param _date: The _date of this FindbyName. # noqa: E50114 :type _date: datetime15 :param orph_acode: The orph_acode of this FindbyName. # noqa: E50116 :type orph_acode: int17 :param preferred_term: The preferred_term of this FindbyName. # noqa: E50118 :type preferred_term: str19 """20 self.swagger_types = {21 '_date': datetime,22 'orph_acode': int,23 'preferred_term': str24 }25 self.attribute_map = {26 '_date': 'Date',27 'orph_acode': 'ORPHAcode',28 'preferred_term': 'Preferred term'29 }30 self.__date = _date31 self._orph_acode = orph_acode32 self._preferred_term = preferred_term33 @classmethod34 def from_dict(cls, dikt) -> 'FindbyName':35 """Returns the dict as a model36 :param dikt: A dict.37 :type: dict38 :return: The FindbyName of this FindbyName. # noqa: E50139 :rtype: FindbyName40 """41 return util.deserialize_model(dikt, cls)42 @property43 def _date(self) -> datetime:44 """Gets the _date of this FindbyName.45 :return: The _date of this FindbyName.46 :rtype: datetime47 """48 return self.__date49 @_date.setter50 def _date(self, _date: datetime):51 """Sets the _date of this FindbyName.52 :param _date: The _date of this FindbyName.53 :type _date: datetime54 """55 self.__date = _date56 @property57 def orph_acode(self) -> int:58 """Gets the orph_acode of this FindbyName.59 :return: The orph_acode of this FindbyName.60 :rtype: int61 """62 return self._orph_acode63 @orph_acode.setter64 def orph_acode(self, orph_acode: int):65 """Sets the orph_acode of this FindbyName.66 :param orph_acode: The orph_acode of this FindbyName.67 :type orph_acode: int68 """69 self._orph_acode = orph_acode70 @property71 def preferred_term(self) -> str:72 """Gets the preferred_term of this FindbyName.73 :return: The preferred_term of this FindbyName.74 :rtype: str75 """76 return self._preferred_term77 @preferred_term.setter78 def preferred_term(self, preferred_term: str):79 """Sets the preferred_term of this FindbyName.80 :param preferred_term: The preferred_term of this FindbyName.81 :type preferred_term: str82 """...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run websmith automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful