Contract con_survival1


Contract Code


  
1 import currency
2 __game = Hash(default_value=0, contract='con_survival1', name='game')
3 __operator = Variable(contract='con_survival1', name='operator')
4 __distributionAmount = Variable(contract='con_survival1', name=
5 'distributionAmount')
6 __zombiesAmount = Variable(contract='con_survival1', name='zombiesAmount')
7 __survivorAmount = Variable(contract='con_survival1', name='survivorAmount')
8
9
10 def ____(vk: str):
11 __operator.set(vk)
12 __distributionAmount.set(0)
13 __zombiesAmount.set(0)
14 __survivorAmount.set(0)
15 __game['last_redeem'] = now
16 __game['play_cost'] = 20
17 __game['redeem_time'] = 1
18 __game['fail_attack'] = 5
19
20
21 @__export('con_survival1')
22 def attack_survivor():
23 caller = ctx.caller
24 GAMEID = __game['gameId']
25 SURVIVOR = __game[GAMEID, 'survivor']
26 ATTACK_SHIELD = __shield()
27 __game[GAMEID, 'game_amount'] += 20
28 random.seed()
29 randomFirstAttack = random.randint(1, 33)
30 if randomFirstAttack == 33:
31 if ATTACK_SHIELD is True:
32 __game[GAMEID, SURVIVOR, 'have_shield'] = 0
33 else:
34 STEAL_AMOUNT = 50 * (now - __game[GAMEID, 'last_redeem']).hours
35 __game['gameId'] = hashlib.sha3(str(now))
36 GAMEID = __game['gameId']
37 __game[GAMEID, 'survivor'] = caller
38 __game[GAMEID, 'game_amount'] = 0
39 __game[GAMEID, 'last_redeem'] = now
40 if STEAL_AMOUNT > 0:
41 currency.transfer_from(STEAL_AMOUNT, caller, __operator.get())
42 return {'survivor': caller, 'time': now, 'status':
43 'new_survivor', 'attack': True, 'fatal_attack': True,
44 'amount': STEAL_AMOUNT, 'gameId': GAMEID}
45 else:
46 randomSecondAttack = random.randint(1, 10)
47 if randomFirstAttack == 10:
48 if __game[GAMEID, SURVIVOR, 'survivor_life'] < 2:
49 STEAL_AMOUNT = 50 * (now - __game[GAMEID, 'last_redeem']).hours
50 __game['gameId'] = hashlib.sha3(str(now))
51 GAMEID = __game['gameId']
52 __game[GAMEID, 'survivor'] = caller
53 __game[GAMEID, 'game_amount'] = 0
54 __game[GAMEID, 'last_redeem'] = now
55 if STEAL_AMOUNT > 0:
56 currency.transfer_from(STEAL_AMOUNT, caller, __operator
57 .get())
58 return {'survivor': caller, 'time': now, 'status':
59 'new_survivor_second_attack', 'attack': True,
60 'fatal_attack': True, 'amount': STEAL_AMOUNT, 'gameId':
61 GAMEID}
62 else:
63 __game[GAMEID, SURVIVOR, 'survivor_life'] -= 1
64 STEAL_AMOUNT = 50 * (now - __game[GAMEID, 'last_redeem']
65 ).hours * decimal('0.15')
66 __game[GAMEID, 'game_amount'] -= STEAL_AMOUNT
67 if STEAL_AMOUNT > 0:
68 currency.transfer_from(STEAL_AMOUNT, caller, __operator
69 .get())
70 return {'survivor': SURVIVOR, 'time': now, 'status':
71 'steal_life', 'attack': True, 'fatal_attack': False,
72 'amount': STEAL_AMOUNT, 'gameId': GAMEID}
73 else:
74 currency.transfer_from(__game['fail_attack'], SURVIVOR,
75 __operator.get())
76 fail_amount = __game['fail_attack']
77 __game[GAMEID, 'game_amount'] -= fail_amount
78 return {'survivor': SURVIVOR, 'time': now, 'status':
79 'fail_attack', 'attack': False, 'fatal_attack': False,
80 'amount': fail_amount, 'gameId': GAMEID}
81
82
83 @__export('con_survival1')
84 def redeem():
85 caller = ctx.caller
86 assert (now - __game[GAMEID, 'last_redeem']).hours > 1, 'Not Cant redeem'
87 SURVIVOR = __game['survivor']
88 GAMEID = __game['gameId']
89 if caller == SURVIVOR:
90 AMOUNT = 50 * (now - __game[GAMEID, 'last_redeem']).hours
91 if AMOUNT > 0:
92 __game[GAMEID, 'last_redeem'] = now
93 __game[GAMEID, 'game_amount'] -= AMOUNT
94 currency.transfer_from(AMOUNT, SURVIVOR, __operator.get())
95 return AMOUNT
96
97
98 @__export('con_survival1')
99 def start(account: str):
100 __game['gameId'] = hashlib.sha3(str(now))
101 GAMEID = __game['gameId']
102 __game[GAMEID, 'survivor'] = account
103 __game[GAMEID, 'last_redeem'] = now
104 __game[GAMEID, 'game_amount'] = 1000
105 __game[GAMEID, account, 'survivor_life'] = 5
106
107
108 def __shield():
109 GAMEID = __game['gameId']
110 SURVIVOR = __game[GAMEID, 'survivor']
111 HAVE_SHIELD = __game[GAMEID, SURVIVOR, 'have_shield']
112 if HAVE_SHIELD == 1:
113 random.seed()
114 randomShield = random.randint(1, 2)
115 if randomShield == 1:
116 return True
117 else:
118 return False
119
120
121 @__export('con_survival1')
122 def set_nick_name(nickname: str):
123 caller = ctx.caller
124 assert len(nickname) <= 25, 'Nickname too long (25 chars max).'
125 assert len(nickname) > 0, 'Nickname too short.'
126 names_uid = hashlib.sha3(nickname.lower().replace(' ', ''))
127 assert not __game['nicknames', names_uid
128 ], 'A form of this name already belongs to ' + balances['nicknames',
129 names_uid]
130 __game[caller, 'nickname'] = nickname
131 __game['nicknames', names_uid] = nickname
132

Byte Code

e3000000000000000000000000050000004000000073ac000000640064016c005a00650164006402640364048d035a0265036402640564068d025a0465036402640764068d025a0565036402640864068d025a0665036402640964068d025a076508640a9c01640b640c84045a09650a64028301640d640e840083015a0b650a64028301640f6410840083015a0c650a64028301650864119c0164126413840483015a0d6414641584005a0e650a64028301650864169c0164176418840483015a0f640153002919e9000000004eda0d636f6e5f737572766976616c31da0467616d652903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da086f70657261746f72290272050000007206000000da12646973747269627574696f6e416d6f756e74da0d7a6f6d62696573416d6f756e74da0e7375727669766f72416d6f756e742901da02766b630100000000000000010000000300000043000000734c00000074006a017c008301010074026a0164018301010074036a0164018301010074046a016401830101007405740664023c006403740664043c006405740664063c006407740664083c006400530029094e7201000000da0b6c6173745f72656465656de914000000da09706c61795f636f7374e901000000da0b72656465656d5f74696d65e905000000da0b6661696c5f61747461636b2907da0a5f5f6f70657261746f72da03736574da145f5f646973747269627574696f6e416d6f756e74da0f5f5f7a6f6d62696573416d6f756e74da105f5f7375727669766f72416d6f756e74da036e6f77da065f5f67616d652901720b000000a900721a000000da00da045f5f5f5f0a000000731000000000010a010a010a010a01080108010801721c000000630000000000000000080000000800000043000000736002000074006a017d007402640119007d0174027c016402660219007d02740383007d0374027c0164036602050019006404370003003c0074046a058300010074046a066405640683027d047c0464066b0272ee7c0364076b087268640874027c017c02640966033c006e82640a740774027c01640b6602190018006a0814007d0574096a0a740b740783018301740264013c007402640119007d017c0074027c01640266023c00640874027c01640366023c00740774027c01640b66023c007c0564086b0472d6740c6a0d7c057c00740e6a0f8300830301007c007407640c640764077c057c01640d9c07530090016e6e74046a066405640e83027d067c04640e6b029002721674027c017c02640f6603190064106b009001729c640a740774027c01640b6602190018006a0814007d0574096a0a740b740783018301740264013c007402640119007d017c0074027c01640266023c00640874027c01640366023c00740774027c01640b66023c007c0564086b0490017288740c6a0d7c057c00740e6a0f8300830301007c0074076411640764077c057c01640d9c07530074027c017c02640f6603050019006405380003003c00640a740774027c01640b6602190018006a08140074106412830114007d0574027c0164036602050019007c05380003003c007c0564086b0490027200740c6a0d7c057c00740e6a0f8300830301007c0274076413640764147c057c01640d9c0753006e46740c6a0d7402641519007c02740e6a0f8300830301007402641519007d0774027c0164036602050019007c07380003003c007c0274076415641464147c077c01640d9c0753006400530029164eda0667616d654964da087375727669766f72da0b67616d655f616d6f756e74720d000000720f000000e921000000547201000000da0b686176655f736869656c64e932000000720c000000da0c6e65775f7375727669766f722907721e000000da0474696d65da06737461747573da0661747461636bda0c666174616c5f61747461636bda06616d6f756e74721d000000e90a000000da0d7375727669766f725f6c696665e902000000da1a6e65775f7375727669766f725f7365636f6e645f61747461636b7a04302e3135da0a737465616c5f6c6966654672120000002911da03637478da0663616c6c65727219000000da085f5f736869656c64da0672616e646f6dda0473656564da0772616e64696e747218000000da05686f757273da07686173686c6962da0473686133da03737472da0863757272656e6379da0d7472616e736665725f66726f6d7213000000da03676574da07646563696d616c2908722f000000da0647414d454944da085355525649564f52da0d41545441434b5f534849454c44da1172616e646f6d466972737441747461636bda0c535445414c5f414d4f554e54da1272616e646f6d5365636f6e6441747461636bda0b6661696c5f616d6f756e74721a000000721a000000721b000000da0f61747461636b5f7375727669766f721500000073660000000002060108010c010601140108010c010801080110021601120108010c010c010c0108011201040106010e020c010a0114011601120108010c010c010c010a011202040104010401080216021e0114010a011202040106010c020c010a0108011401040106017243000000630000000000000000040000000500000043000000739400000074006a017d00740274037c0164016602190018006a0464026b04732474056403830182017403640419007d027403640519007d017c007c026b0272906406740274037c0164016602190018006a0414007d037c0364076b047290740274037c01640166023c0074037c0164086602050019007c03380003003c0074066a077c037c0274086a098300830301007c0353006400530029094e720c000000720f0000007a0f4e6f742043616e742072656465656d721e000000721d00000072220000007201000000721f000000290a722e000000722f000000721800000072190000007234000000da0e417373657274696f6e4572726f72723800000072390000007213000000723a0000002904722f000000723c000000723d000000da06414d4f554e54721a000000721a000000721b000000da0672656465656d530000007316000000000206011e01080108010801160108010c011401120172460000002901da076163636f756e74630100000000000000020000000500000043000000735000000074006a017402740383018301740464013c007404640119007d017c0074047c01640266023c00740374047c01640366023c00640474047c01640566023c00640674047c017c00640766033c006400530029084e721d000000721e000000720c00000069e8030000721f0000007211000000722a00000029057235000000723600000072370000007218000000721900000029027247000000723c000000721a000000721a000000721b000000da05737461727462000000730c0000000002120108010c010c010c01724800000063000000000000000004000000040000004300000073540000007400640119007d0074007c006402660219007d0174007c007c016403660319007d027c0264046b02724c74016a028300010074016a036404640583027d037c0364046b027250640653006e04640753006400530029084e721d000000721e0000007221000000720f000000722b0000005446290472190000007231000000723200000072330000002904723c000000723d000000da0b484156455f534849454c44da0c72616e646f6d536869656c64721a000000721a000000721b00000072300000006c0000007312000000000108010c010e01080108010c010801060272300000002901da086e69636b6e616d65630100000000000000030000000500000043000000738200000074006a017d0174027c00830164016b01731a740364028301820174027c00830164036b04732e740364048301820174046a057c006a0683006a0764056406830283017d02740864077c02660219000c00736674036408740964077c02660219001700830182017c0074087c01640966023c007c00740864077c0266023c0064005300290a4ee9190000007a214e69636b6e616d6520746f6f206c6f6e6720283235206368617273206d6178292e72010000007a134e69636b6e616d6520746f6f2073686f72742efa0120721b000000da096e69636b6e616d65737a274120666f726d206f662074686973206e616d6520616c72656164792062656c6f6e677320746f20724b000000290a722e000000722f000000da036c656e724400000072350000007236000000da056c6f776572da077265706c6163657219000000da0862616c616e6365732903724b000000722f000000da096e616d65735f756964721a000000721a000000721b000000da0d7365745f6e69636b5f6e616d6579000000731200000000020601140114011601100106010c010c01725400000029107238000000da04486173687219000000da085661726961626c6572130000007215000000721600000072170000007237000000721c000000da085f5f6578706f727472430000007246000000724800000072300000007254000000721a000000721a000000721a000000721b000000da083c6d6f64756c653e01000000731c00000008010e010c01040108010c010c030e0b103e100f06011009080d0601