How to use whoami method in fMBT

Best Python code snippet using fMBT_python

data-set.test.ts

Source:data-set.test.ts Github

copy

Full Screen

1import { expect } from "chai";2import { DELETE, DataSet } from "../src";3interface Item1 {4 whoami: number;5 foo: string;6 bar: boolean;7}8interface Item2 {9 whoami: number;10 payload: {11 foo: string;12 bar: boolean;13 };14}15interface Item3 {16 whoami: number;17 payload?: {18 p1?: string;19 p2?: number;20 p3?: boolean;21 };22}23describe("Data Set", function (): void {24 describe("Update Only", function (): void {25 it("No id", function (): void {26 const ds = new DataSet<Item1, "whoami">(27 [28 { whoami: 7, foo: "7", bar: true },29 { whoami: 8, foo: "8", bar: false },30 { whoami: 9, foo: "9", bar: true },31 ],32 { fieldId: "whoami" }33 );34 expect((): void => {35 ds.updateOnly({ foo: "new", bar: false } as any);36 }, "Items without ids shouldn’t be allowed during updates.").to.throw();37 expect(38 ds.length,39 "There should be no new items or old missing."40 ).to.equal(3);41 expect(ds.get(7), "Other items should be intact.").to.deep.equal({42 whoami: 7,43 foo: "7",44 bar: true,45 });46 expect(ds.get(8), "Other items should be intact.").to.deep.equal({47 whoami: 8,48 foo: "8",49 bar: false,50 });51 expect(ds.get(9), "Other items should be intact.").to.deep.equal({52 whoami: 9,53 foo: "9",54 bar: true,55 });56 });57 it("New id", function (): void {58 const ds = new DataSet<Item1, "whoami">(59 [60 { whoami: 7, foo: "7", bar: true },61 { whoami: 8, foo: "8", bar: false },62 { whoami: 9, foo: "9", bar: true },63 ],64 { fieldId: "whoami" }65 );66 expect((): void => {67 ds.updateOnly({ whoami: 1, foo: "new", bar: false });68 }, "New items shouldn’t be allowed during updates.").to.throw();69 expect(70 ds.length,71 "There should be no new items or old missing."72 ).to.equal(3);73 expect(ds.get(1), "New items shouldn’t be created.").to.be.null;74 expect(ds.get(7), "Other items should be intact.").to.deep.equal({75 whoami: 7,76 foo: "7",77 bar: true,78 });79 expect(ds.get(8), "Other items should be intact.").to.deep.equal({80 whoami: 8,81 foo: "8",82 bar: false,83 });84 expect(ds.get(9), "Other items should be intact.").to.deep.equal({85 whoami: 9,86 foo: "9",87 bar: true,88 });89 });90 it("Id only", function (): void {91 const originalItem8 = { whoami: 8, foo: "8", bar: false };92 const ds = new DataSet<Item1, "whoami">(93 [94 { whoami: 7, foo: "7", bar: true },95 originalItem8,96 { whoami: 9, foo: "9", bar: true },97 ],98 { fieldId: "whoami" }99 );100 ds.updateOnly({ whoami: 8 });101 expect(102 ds.length,103 "There should be no new items or old missing."104 ).to.equal(3);105 expect(ds.get(7), "Other items should be intact.").to.deep.equal({106 whoami: 7,107 foo: "7",108 bar: true,109 });110 expect(111 ds.get(8),112 "There were no other props, nothing should be changed."113 ).to.deep.equal({114 whoami: 8,115 foo: "8",116 bar: false,117 });118 expect(ds.get(9), "Other items should be intact.").to.deep.equal({119 whoami: 9,120 foo: "9",121 bar: true,122 });123 expect(124 ds.get(8),125 "Update should not modify the item in place (a new object should be created)."126 ).to.not.equal(originalItem8);127 });128 it("Id and foo", function (): void {129 const originalItem8 = { whoami: 8, foo: "8", bar: false };130 const ds = new DataSet<Item1, "whoami">(131 [132 { whoami: 7, foo: "7", bar: true },133 originalItem8,134 { whoami: 9, foo: "9", bar: true },135 ],136 { fieldId: "whoami" }137 );138 ds.updateOnly({ whoami: 8, foo: "#8" });139 expect(140 ds.length,141 "There should be no new items or old missing."142 ).to.equal(3);143 expect(ds.get(7), "Other items should be intact.").to.deep.equal({144 whoami: 7,145 foo: "7",146 bar: true,147 });148 expect(ds.get(8), "Only the foo prop should be updated.").to.deep.equal({149 whoami: 8,150 foo: "#8",151 bar: false,152 });153 expect(ds.get(9), "Other items should be intact.").to.deep.equal({154 whoami: 9,155 foo: "9",156 bar: true,157 });158 expect(159 ds.get(8),160 "Update should not modify the item in place (a new object should be created)."161 ).to.not.equal(originalItem8);162 });163 it("Id and nested props", function (): void {164 const originalItem8 = { whoami: 8, payload: { foo: "8", bar: false } };165 const ds = new DataSet<Item2, "whoami">(166 [167 { whoami: 7, payload: { foo: "7", bar: true } },168 originalItem8,169 { whoami: 9, payload: { foo: "9", bar: true } },170 ],171 { fieldId: "whoami" }172 );173 ds.updateOnly({ whoami: 8, payload: { foo: "#8" } });174 expect(175 ds.length,176 "There should be no new items or old missing."177 ).to.equal(3);178 expect(ds.get(7), "Other items should be intact.").to.deep.equal({179 whoami: 7,180 payload: {181 foo: "7",182 bar: true,183 },184 });185 expect(ds.get(8), "Only the foo prop should be updated.").to.deep.equal({186 whoami: 8,187 payload: {188 foo: "#8",189 bar: false,190 },191 });192 expect(ds.get(9), "Other items should be intact.").to.deep.equal({193 whoami: 9,194 payload: {195 foo: "9",196 bar: true,197 },198 });199 expect(200 ds.get(8),201 "Update should not modify the item in place (a new object should be created)."202 ).to.not.equal(originalItem8);203 });204 it("Delete props through updateOnly", function (): void {205 const ds = new DataSet<Item3, "whoami">(206 [{ whoami: 7, payload: { p1: "7", p2: 7, p3: true } }],207 { fieldId: "whoami" }208 );209 ds.updateOnly({ whoami: 7, payload: { p1: DELETE } });210 expect(ds.get(7), "DELETE should delete properties").to.deep.equal({211 whoami: 7,212 payload: {213 p2: 7,214 p3: true,215 },216 });217 ds.updateOnly({ whoami: 7, payload: { p2: DELETE, p3: DELETE } });218 expect(ds.get(7), "DELETE should delete properties").to.deep.equal({219 whoami: 7,220 payload: {},221 });222 ds.updateOnly({ whoami: 7, payload: DELETE });223 expect(ds.get(7), "DELETE should delete properties").to.deep.equal({224 whoami: 7,225 });226 });227 });228 it("Add, clear and readd", function (): void {229 const generateItems = (): Item2[] => [230 { whoami: 7, payload: { foo: "7", bar: true } },231 { whoami: 8, payload: { foo: "8", bar: false } },232 { whoami: 9, payload: { foo: "9", bar: true } },233 ];234 const ds = new DataSet<Item2, "whoami">({ fieldId: "whoami" });235 ds.add(generateItems());236 expect(ds.get(), "The items should be present before clear").to.deep.equal(237 generateItems()238 );239 ds.clear();240 expect(241 ds.get(),242 "The items shouldn't be present after clear"243 ).to.deep.equal([]);244 expect((): void => {245 ds.add(generateItems());246 }, "It should be possible to add items with the same ids that existed before clear").to.not.throw();247 expect(248 ds.get(),249 "The items should be present again since they were readded"250 ).to.deep.equal(generateItems());251 });...

Full Screen

Full Screen

Ice.py

Source:Ice.py Github

copy

Full Screen

1import Crossfire,random,math,sys2import CFDataBase3CFDB=CFDataBase.CFDataBase("PShop")4Params=Crossfire.ScriptParameters()5def GetObjectByName(object, Name):6 while object.Name!=Name:7 object=object.Above8 if not object:9 return 010 return object11def FindFridge(object):12 TRUE=False13 while object!=None:14 if object.Name=="Shop Floor":15 TRUE=True16 object=None17 else:18 object=object.Below19 return TRUE20def FindPuddle(object):21 a=object22 while object!=None:23 if object.Name.find("Puddle")>-1:24 return object25 else:26 object=object.Above27 object=a28 while object!=None:29 if object.Name.find("Puddle")>-1:30 return object31 else:32 object=object.Below33 return None34if Params=="Destroy":35 whoami=Crossfire.WhoAmI()36 a=whoami.Inventory37 while a !=None:38 a.Remove()39 a=whoami.Inventory40 b=whoami.CreateObject("icecube")41 b.Weight=042 z=b.CreateObject("event_time")43 b.Speed=0.0010000000475*444 if whoami.Map.Path.find("/world_")>-1:45 b.Speed=b.Speed*1046 z.Title="Python"47 z.Name="Puddle"48 z.Slaying="/python/pshop/Ice.py"49 z=b.CreateObject("event_destroy")50 z.Title="Python"51 z.Name="PuddleDeath"52 z.Slaying="/python/pshop/Ice.py"53 b.NamePl=str(1)54 b.Teleport(whoami.Map,whoami.X,whoami.Y)55 g=FindPuddle(b)56 if g!=None:57 b.Remove()58 b=g59 b.Weight+=whoami.Weight60 b.Name="Puddle"61 if b.Weight<2000:62 b.Face="rain1.111"63 elif b.Weight<20000:64 b.Face="rain2.111"65 elif b.Weight<200000:66 b.Face="rain3.111"67 elif b.Weight<2000000:68 b.Face="rain4.111"69 else:70 b.Face="rain5.111"71 b.Pickable=072elif Params=="FogDeath":73 whoami=Crossfire.WhoAmI()74 a=whoami.Inventory75 while a !=None:76 a.Remove()77 a=whoami.Inventory78elif Params=="Fog":79 whoami=Crossfire.WhoAmI()80 Rand=random.randint(0,8)81 if Rand!=0:82 whoami.Move(Rand)83 whoami.Weight-=184 if whoami.Weight>=0:85 Crossfire.SetReturnValue(1)86elif Params=="Get":87 whoami=Crossfire.WhoAmI()88 activator=Crossfire.WhoIsActivator()89 Dict=CFDB.get("pshop")90 WL=str(whoami.WeightLimit)91 Me=Dict.get(WL)92 a=(Me[0],"PickedUp",Me[2])93 #Me=str(Me[0],(activator.X,activator.Y),Me[1])94 Dict.update({str(whoami.WeightLimit):(a[0],a[1],a[2])})95 CFDB.store("pshop",Dict)96elif Params=="Player":97 whoami=Crossfire.WhoAmI()98elif Params=="PuddleDeath":99 whoami=Crossfire.WhoAmI()100 Fogs=int(whoami.Weight/1000)101 Fogs=max(Fogs,1)102 a=whoami.Inventory103 while a !=None:104 a.Remove()105 a=whoami.Inventory106 FogsTmp=Fogs107 if whoami.Name=="fog":108 FogsTmp=whoami.Value109 if Fogs > 50:110 z=whoami.CreateObject("temp_fog")111 Z=z.CreateObject("event_destroy")112 Z.Name="PuddleDeath"113 Z.Title="Python"114 Z.Slaying="/python/pshop/Ice.py"115 z.Weight=(Fogs-50)*1000116 Fogs=50117 z.Speed*=2118 z.Value=FogsTmp119 for i in range(Fogs):120 z=whoami.CreateObject("temp_fog")121 z.Speed+=0.3122 z.Weight=(3+random.randint(1,10+int(math.sqrt(FogsTmp))))*3123 Rand=random.randint(1,2+int(FogsTmp/10))124 z.Speed*=Rand125 z.Weight*=int(Rand/10)+1126 y=z.CreateObject("event_time")127 y.Name="Fog"128 y.Title="Python"129 y.Slaying="/python/pshop/Ice.py"130 #y=z.CreateObject("event_destroy")131 #y.Name="FogDeath"132 #y.Title="Python"133 #y.Slaying="/python/pshop/Ice.py"134elif Params=="Puddle":135 whoami=Crossfire.WhoAmI()136 whoami.Value+=1137 #whoami.Speed+=(0.00010000000475/2)138 Mass=int(math.sqrt(whoami.Weight))139 IntMass=int(Mass/1000)140 for i in range(IntMass):141 z=whoami.CreateObject("temp_fog")142 y=z.CreateObject("event_time")143 y.Name="Fog"144 y.Title="Python"145 y.Slaying="/python/pshop/Ice.py"146 #y=z.CreateObject("event_destroy")147 #y.Name="FogDeath"148 #y.Title="Python"149 #y.Slaying="/python/pshop/Ice.py"150 z.Weight=(3+random.randint(1,int(IntMass)+10))151 z.Speed=5*z.Speed152 whoami.Drop(z)153 whoami.Weight-=Mass154 if whoami.Weight<=0:155 whoami.Remove()156 else:157 if whoami.Weight>20000:158 a=whoami.CreateObject('icecube')159 Mass=random.randint(1,int(whoami.Weight/2))160 whoami.Weight-=Mass161 a.Weight=Mass162 Direction=random.randint(1,8)163 whoami.Drop(a)164 tmp=0165 CTRL=0166 if whoami.Map.Path.find("/world/world_")>-1:167 tmp=0168 CTRL=0169 XY=(whoami.X,whoami.Y)170 while tmp==0:171 tmp=whoami.Move(Direction)172 Direction+=1173 if Direction==9:174 Direction=1175 CTRL+=1176 if CTRL==8:177 tmp=2178 a.Teleport(whoami.Map, whoami.X,whoami.Y)179 whoami.Teleport(whoami.Map,XY[0],XY[1])180 else:181 while tmp==0:182 tmp=a.Move(Direction)183 Direction+=1184 if Direction==9:185 Direction=1186 CTRL+=1187 if CTRL==8:188 tmp=1189 b=a.Map.ObjectAt(a.X,a.Y)190 b=FindPuddle(b)191 if b!=None:192 b.Weight+=a.Weight193 a.Remove()194 a=b195 else:196 a.Name=whoami.Name197 if a.Weight < 1600:198 a.Face="rain1.111"199 elif a.Weight < 3200:200 a.Face="rain2.111"201 elif a.Weight<6400:202 a.Face="rain3.111"203 elif a.Weight<12800:204 a.Face="rain4.111"205 else:206 a.Face="rain5.111"207 Z=False208 y=a.Inventory209 while y!=None:210 if y.Name.find("Puddle")>-1:211 Z=True212 y=None213 else:214 y=y.Below215 if Z==False:216 z=a.CreateObject("event_time")217 a.Speed=0.0010000000475*4218 z.Title="Python"219 z.Name="Puddle"220 z.Slaying="/python/pshop/Ice.py"221 z=a.CreateObject("event_destroy")222 z.Title="Python"223 z.Name="PuddleDeath"224 z.Slaying="/python/pshop/Ice.py"225 #a.CreateTimer(500,2)226 a.NamePl=str(1)227 a.Pickable=0228 a.Speed=(0.0010000000475*4)229 if whoami.Weight < 1600:230 whoami.Face="rain1.111"231 elif whoami.Weight < 3200:232 whoami.Face="rain2.111"233 elif whoami.Weight<6400:234 whoami.Face="rain3.111"235 elif whoami.Weight<12800:236 whoami.Face="rain4.111"237 else:238 whoami.Face="rain5.111"239 whoami.Speed=(0.0010000000475*4)+0.0010000000475*whoami.Value/(whoami.Weight/1000)240 #whoami.Speed=max(whoami.Speed,0.0010000000475*4)241elif Params=="Timer":242 whoami=Crossfire.WhoAmI()243 b=FindPuddle(whoami.Map.ObjectAt(whoami.X,whoami.Y))244 if b==None:245 b=whoami.CreateObject("icecube")246 b.Weight=0247 z=b.CreateObject("event_time")248 b.Speed=0.0010000000475*4249 if whoami.Map.Path.find("/world_")>-1:250 b.Speed=10*b.Speed251 z.Title="Python"252 z.Name="Puddle"253 z.Slaying="/python/pshop/Ice.py"254 z=b.CreateObject("event_destroy")255 z.Title="Python"256 z.Name="PuddleDeath"257 z.Slaying="/python/pshop/Ice.py"258 #b.CreateTimer(500,2)259 b.NamePl=str(1)260 whoami.Drop(b)261 #b.Speed+=.00001262 b.Name="Puddle"263 Mass=int(100+math.sqrt(whoami.Weight))264 b.Weight+=max(Mass,50)265 whoami.Weight-=max(Mass,50)266 b.Pickable=0267 if b.Weight<2000:268 b.Face="rain1.111"269 elif b.Weight<4000:270 b.Face="rain2.111"271 elif b.Weight<8000:272 b.Face="rain3.111"273 elif b.Weight<16000:274 b.Face="rain4.111"275 else:276 b.Face="rain5.111"277 if whoami.Weight<=0:278 whoami.Quantity=0279 whoami.Speed+=0.00010000000475280else:281 whoami=Crossfire.WhoAmI()282 activator=Crossfire.WhoIsActivator()283 mymap=activator.Map284 t=mymap.ObjectAt(activator.X, activator.Y)285 if (FindFridge(t)):286 whoami.Speed=0287 Dict=CFDB.get("pshop")288 WL=str(whoami.WeightLimit)289 Me=Dict.get(WL)290 a=(Me[0],(activator.X,activator.Y),Me[2])291 #Me=str(Me[0],(activator.X,activator.Y),Me[1])292 Dict.update({str(whoami.WeightLimit):(a[0],a[1],a[2])})293 CFDB.store("pshop",Dict)294 Crossfire.SetReturnValue(0)295 else:296 whoami.Speed=0.0010000000475*4297 if activator.Map.Path.find("/world_")>-1:298 #whoami.CreateTimer(1,2)299 whoami.Speed=whoami.Speed*10...

Full Screen

Full Screen

rolanda.py

Source:rolanda.py Github

copy

Full Screen

1'''2This script is part of the Witherspoon quest, that starts in /scorn/mansion/witherspoon_manor_attic.3Check the README file in the same directory as this file for more details.4Script for Rolanda, in /scorn/houses/rolanda.5Support to be called for TIME, TIMER and CUSTOM events.6'''7import Crossfire8import CFMove9import random10whoami = Crossfire.WhoAmI()11whoisother = Crossfire.WhoIsOther()12command = Crossfire.WhatIsMessage()13event = Crossfire.WhatIsEvent()14pl = Crossfire.WhoIsActivator()15# Message color for player16color = Crossfire.MessageFlag.NDI_BROWN17# coordinates to look for chairs18search_chairs = [ [ 0, -1 ], [ 0, 1 ], [ -1, 0 ], [ 1, 0 ] ]19def do_give():20 '''handle the player giving an item.'''21 if whoisother.ReadKey('special_item') != 'ghost_dagger':22 whoami.Say('And what am I supposed to do with this %s.'%whoisother.Name)23 return24 whoami.Say('Ohhhhhhhh... This, this dagger...');25 pl.Message('%s puts her hand to her forehead, and staggers.'%whoami.Name)26 whoami.WriteKey('witherspoon_saw_dagger', '1', 1)27 whoami.WriteKey('witherspoon_seated', '', 1)28 whoami.WriteKey('explaining_for', pl.Name, 1)29def search_chair():30 '''if fainting, try to find a chair when TIME happens.'''31 for search in range(0, len(search_chairs)):32 x = whoami.X + search_chairs[search][0]33 y = whoami.Y + search_chairs[search][1]34 obj = whoami.Map.ObjectAt(x, y)35 while obj:36 if obj.Name == 'chair':37 whoami.WriteKey('witherspoon_seated', '1', 1)38 whoami.Say('Thank you very much.')39 whoami.WriteKey('chair_x', str(x), 1)40 whoami.WriteKey('chair_y', str(y), 1)41 return42 obj = obj.Above43def move_to_chair():44 '''trying to move to first found chair.'''45 m = CFMove.get_object_to(whoami, int(whoami.ReadKey('chair_x')), int(whoami.ReadKey('chair_y')))46 if m == 0:47 whoami.WriteKey('witherspoon_seated', '2', 1)48 whoami.Map.Print('%s sits on the chair.'%whoami.Name, color)49 whoami.Say('I shall explain everything...')50 whoami.Map.Print('%s starts sobbing.'%whoami.Name, color)51 whoami.CreateTimer(random.randint(5, 10), 1)52 elif m == 2:53 whoami.Say('Please let me sit...')54def explain():55 '''explanation of the ghost story. Let Rolanda be still from now on.'''56 pl = Crossfire.FindPlayer(whoami.ReadKey('explaining_for'))57 if pl == None:58 # just in case someone else is around ^_-59 whoami.Say('Tss, people just aren\'t patient...')60 return61 pl.WriteKey('witherspoon_know_all', '1', 1)62 whoami.Say('See, this dagger...')63 whoami.Say('Alfred wanted...')64 whoami.Map.Print('%s sighes deeply, and goes on.'%whoami.Name)65 whoami.Say('he wanted to have some, shall I say, different experience, the kind a man and a woman can have together.')66 whoami.Say('And since he likes pain, he asked to suffer, to see if the pain would... excite him.')67 whoami.Map.Print('%s sobs'%whoami.Name)68 whoami.Say('But he didn\'t think he would die!')69 whoami.Say('So I... I hide the body, hoping to forget him.')70 whoami.Say('But now I can\'t forget him! Ever!')71 pl.Write('You wonder what the ghost (Alfred, according to %s) will make of that...'%whoami.Name, color)72if event.Subtype == Crossfire.EventType.USER and command == 'give':73 do_give()74elif event.Subtype == Crossfire.EventType.TIME:75 if whoami.ReadKey('witherspoon_saw_dagger') != '':76 # No moving while fainting77 Crossfire.SetReturnValue(1)78 if whoami.ReadKey('witherspoon_seated') == '':79 search_chair()80 elif whoami.ReadKey('witherspoon_seated') == '1':81 move_to_chair()82elif event.Subtype == Crossfire.EventType.SAY:83 if whoami.ReadKey('witherspoon_saw_dagger') != '':84 # No talking while fainting85 Crossfire.SetReturnValue(1)86 whoami.Say('Ohhhhhhh......')87 pl.Message('%s seems to be ready to faint.'%whoami.Name)88elif event.Subtype == Crossfire.EventType.TIMER:89 if whoami.ReadKey('witherspoon_seated') == '2':...

Full Screen

Full Screen

actions.ts

Source:actions.ts Github

copy

Full Screen

1/*2 There should be an actions.js file in every3 feature folder, and it should start with a list4 of constants defining all the types of actions5 that can be taken within that feature.6*/7import { WireElement } from '../../../../api/hdkCrud'8import { PROFILES_ZOME_NAME } from '../../../../holochainConfig'9import { Profile, WhoAmIOutput } from '../../../../types'10import { Action, CellIdString } from '../../../../types/shared'11/* action creator functions */12const WHOAMI = 'WHOAMI'13const CREATE_WHOAMI = 'CREATE_WHOAMI'14const UPDATE_WHOAMI = 'UPDATE_WHOAMI'15const whoami = (cellIdString: CellIdString, payload: WhoAmIOutput): Action<WhoAmIOutput> => {16 return {17 type: WHOAMI,18 payload,19 meta: { cellIdString }20 }21}22const createWhoami = (cellIdString: CellIdString, payload: WireElement<Profile>): Action<WireElement<Profile>> => {23 return {24 type: CREATE_WHOAMI,25 payload,26 meta: { cellIdString }27 }28}29const updateWhoami = (cellIdString: CellIdString, payload: WireElement<Profile>): Action<WireElement<Profile>> => {30 return {31 type: UPDATE_WHOAMI,32 payload,33 meta: { cellIdString }34 }35}36export { whoami, WHOAMI, createWhoami, CREATE_WHOAMI, updateWhoami, UPDATE_WHOAMI }...

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