How to use iActions method in fMBT

Best Python code snippet using fMBT_python

actions_validator.py

Source:actions_validator.py Github

copy

Full Screen

1# Python bytecode 2.7 (decompiled from Python 2.7)2# Embedded file name: scripts/client/gui/prb_control/entities/base/actions_validator.py3import logging4import weakref5from CurrentVehicle import g_currentPreviewVehicle, g_currentVehicle6from gui.prb_control.items import ValidationResult7from gui.prb_control.settings import PREBATTLE_RESTRICTION8from helpers import dependency9from skeletons.tutorial import ITutorialLoader10from soft_exception import SoftException11_logger = logging.getLogger(__name__)12class IActionsValidator(object):13 def canPlayerDoAction(self):14 raise NotImplementedError15class NotSupportedActionsValidator(IActionsValidator):16 def canPlayerDoAction(self):17 return ValidationResult(False)18class BaseActionsValidator(IActionsValidator):19 def __init__(self, entity):20 super(BaseActionsValidator, self).__init__()21 self._entity = weakref.proxy(entity)22 def canPlayerDoAction(self, ignoreEnable=False):23 return self._validate() if ignoreEnable or self._isEnabled() else None24 def _validate(self):25 return None26 def _isEnabled(self):27 return True28class CurrentVehicleActionsValidator(BaseActionsValidator):29 def _validate(self):30 if g_currentPreviewVehicle.isPresent():31 return ValidationResult(False, PREBATTLE_RESTRICTION.PREVIEW_VEHICLE_IS_PRESENT)32 if not g_currentVehicle.isReadyToFight():33 if not g_currentVehicle.isPresent():34 return ValidationResult(False, PREBATTLE_RESTRICTION.VEHICLE_NOT_PRESENT)35 if g_currentVehicle.isInBattle() or g_currentVehicle.isDisabled():36 return ValidationResult(False, PREBATTLE_RESTRICTION.VEHICLE_IN_BATTLE)37 if g_currentVehicle.isTooHeavy():38 return ValidationResult(False, PREBATTLE_RESTRICTION.VEHICLE_TOO_HEAVY)39 if not g_currentVehicle.isCrewFull():40 return ValidationResult(False, PREBATTLE_RESTRICTION.CREW_NOT_FULL)41 if g_currentVehicle.isBroken():42 return ValidationResult(False, PREBATTLE_RESTRICTION.VEHICLE_BROKEN)43 if g_currentVehicle.isDisabledInRoaming():44 return ValidationResult(False, PREBATTLE_RESTRICTION.VEHICLE_ROAMING)45 if g_currentVehicle.isDisabledInPremIGR():46 return ValidationResult(False, PREBATTLE_RESTRICTION.VEHICLE_IN_PREMIUM_IGR_ONLY)47 if g_currentVehicle.isDisabledInRent():48 if g_currentVehicle.isPremiumIGR():49 return ValidationResult(False, PREBATTLE_RESTRICTION.VEHICLE_IGR_RENTALS_IS_OVER)50 return ValidationResult(False, PREBATTLE_RESTRICTION.VEHICLE_RENTALS_IS_OVER)51 if g_currentVehicle.isRotationGroupLocked():52 return ValidationResult(False, PREBATTLE_RESTRICTION.VEHICLE_ROTATION_GROUP_LOCKED)53 return ValidationResult(False, PREBATTLE_RESTRICTION.VEHICLE_NOT_SUPPORTED) if g_currentVehicle.isUnsuitableToQueue() else super(CurrentVehicleActionsValidator, self)._validate()54class TutorialActionsValidator(BaseActionsValidator):55 __tutorialLoader = dependency.descriptor(ITutorialLoader)56 def _validate(self):57 tutorial = self.__tutorialLoader.tutorial58 return ValidationResult(False, PREBATTLE_RESTRICTION.TUTORIAL_NOT_FINISHED) if tutorial is not None and not tutorial.isAllowedToFight() else super(TutorialActionsValidator, self)._validate()59class ActionsValidatorComposite(BaseActionsValidator):60 def __init__(self, entity, validators=None, warnings=None):61 super(ActionsValidatorComposite, self).__init__(entity)62 self.__validators = validators or []63 self.__warnings = warnings or []64 def addValidator(self, validator):65 if isinstance(validator, IActionsValidator):66 self.__validators.append(validator)67 else:68 _logger.error('Validator should extends IActionsValidator: %r', validator)69 def removeValidator(self, validator):70 self.__validators.remove(validator)71 def addWarning(self, warning):72 if isinstance(warning, IActionsValidator):73 self.__warnings.append(warning)74 else:75 _logger.error('Warning object should extends IActionsValidator: %r', warning)76 def removeWarning(self, warning):77 self.__warnings.remove(warning)78 def _validate(self):79 for validator in self.__validators:80 result = validator.canPlayerDoAction()81 if result is not None:82 return result83 for warning in self.__warnings:84 result = warning.canPlayerDoAction()85 if result is not None:86 if not result.isValid:87 raise SoftException('Warnings could not be invalid!')88 return result...

Full Screen

Full Screen

IActions.py

Source:IActions.py Github

copy

Full Screen

1from abc import ABC, abstractmethod2import pickle3class IActions(ABC):4 5 def __init__(self):6 super().__init__()7 8 @abstractmethod9 def do_action(self):10 pass11class Win(IActions):12 13 def __init__(self,):14 pass15 def do_action(self,sock,gui):16 for i in range(len(gui.board)):17 gui.board[i].configure(bg="gray")18 gui.enemyboard[i].configure(bg="gray")19 print("Win")20class Turn(IActions):21 22 def __init__(self,):23 self.flag=True24 def do_action(self,sock,gui):25 print("attak its your turn ")26 for i in range(len(gui.enemyboard)):27 gui.enemyboard[i].configure(command= lambda i=i:self.send_attak(sock,i+11))28 return 1029 def send_attak(self,sock,coordiante):30 if(int(coordiante)>9 and int(coordiante)<100 and self.flag):31 self.flag=False32 print(coordiante)33 sock.send(str(coordiante).encode('ascii'))34 35class Miss(IActions):36 37 def __init__(self,):38 self.coordinate=1139 def do_action(self,sock,gui):40 print("Miss")41 print(self.coordinate-11)42 gui.enemyboard[self.coordinate-11].configure(bg="blue")43 def set_coordinate(self,coordinate):44 self.coordinate=int(coordinate)45class Lose(IActions):46 47 def __init__(self,):48 pass49 def do_action(self,sock,gui):50 for i in range(len(gui.board)):51 gui.board[i].configure(bg="gray")52 gui.enemyboard[i].configure(bg="gray")53 print("Lose")54class Hit(IActions):55 56 def __init__(self,):57 self.coordinate=1158 def do_action(self,sock,gui):59 print("hit")60 print(self.coordinate-11)61 gui.enemyboard[self.coordinate-11].configure(bg="red")62 63 def set_coordinate(self,coordinate):64 self.coordinate=int(coordinate)65class HitMe(IActions):66 def __init__(self,):67 self.coordinate=1168 def do_action(self,sock,gui):69 print("hit")70 print(self.coordinate-11)71 gui.board[self.coordinate-11].configure(bg="red")72 73 def set_coordinate(self,coordinate):74 self.coordinate=int(coordinate)75class Init_Ship(IActions):76 def __init__(self):77 self.shiplist=[]78 def do_action(self,sock,gui):79 gui.search.configure(text="in game")80 print("init your ships")81 gui.search.configure(command=lambda: self.disablesearch)82 for i in range(len(gui.board)):83 gui.board[i].configure(command= lambda i=i:self.init_Shiplist(sock,i+11,gui))84 return 1085 86 def disablesearch(self):87 pass88 def send_Shiplist(self,sock):89 Pshiplist=pickle.dumps(self.shiplist)90 sock.send(Pshiplist)91 def init_Shiplist(self,sock,coordinate,gui):92 if(len(self.shiplist)<2):93 if(self.inList(int(coordinate))):94 self.shiplist.append(int(coordinate))95 print(coordinate)96 97 gui.board[coordinate-11].configure(bg="green")98 if(len(self.shiplist)==2):99 print("send my ships")100 self.send_Shiplist(sock)101 102 else:103 print("invalid number")104 def inList(self,value):105 for i in self.shiplist:106 if i==value:107 return False108 return True109 110class Wait(IActions):111 def __init__(self):112 pass113 def do_action(self,sock,gui):114 print("Wait")115 gui.search.configure(command=lambda: self.donothing())116 gui.search.configure(text="waiting")117 118 def donothing(self):119 pass120class Error(IActions):121 def __init__(self):122 pass123 def do_action(self,sock,gui):124 print("error")125 return 0126class Options(IActions):127 def __init__(self):128 pass129 def do_action(self,sock,gui):130 print("options")131 gui.search.configure(text="search")132 gui.search.configure(command=lambda: self.play_one_vs_one(sock))133 134 def play_one_vs_one(self,sock):...

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 fMBT 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