Transaction

d169aec8b4e5d4028626703bbd1346fc27b9ef0126c38736d1b25eb3cf9c688d
( - )
128,032
2022-04-05 13:03:52
1
11,387 B

3 Outputs

Total Output:
  • jrun cryptofightsMâ*{"in":1,"ref":["743a27f9c3fb50e35bfdc4f09bb7b1dd98f19d347c2ab858776aa28241c80c16_o1","b38c3477cc661c65e8a6bf6fa1fd046ef21c6069391f24ccba43a168becd2dac_o1","e5602b14f529aa66499a6dc2b93f7fdf2f091edbbc2b0efd8b2e2161d59b5ca5_o1","5334f688050535806987424ec00ba75b74a2087c8c3945765dd9107ac81af1a7_o1","9f0e192f744258c3484a1c19fa88ef68e46ee6cf75acc78cfe2ad5a0d2340d0e_o1","aa2ebcab82c10e20f2f8cb0751fc5e1692252ce71fe3ba62c75a984da7d8e1f9_o1","e2f4d8e09c9835156a2a221aedd8bb04db191d9642573906439bbd889dde40d0_o1","5dc606e8c78f47a10ecb5f8645f2dbe09a3b3a2da87e7e614dcc150203adba1a_o1","870c20f2e1b5f421a3083f749776c059e5bf227d6b2d555f11ffda2306389c56_o1","44d5c97722775235faffedab3b1a0820e8b0adb7057df6f2600afc618a269737_o1","f97d4ac2a3d6f5ed09fad4a4f341619dc5a3773d9844ff95c99c5d4f8388de2f_o1","689b8b60b0fd93ebb108fbab647f1928d10a39fcaf427892345c8ad13d564a4f_o1"],"out":["7582cac75d568d910ac5b6728538e395734f3078f9f883ff7df66819bfa38b52"],"del":[],"cre":[],"exec":[{"op":"UPGRADE","data":[{"$jig":0},"class Battle extends FyxJig {\n init(validator, rules, players, id, timestamp) {\n this.id = this.random = id;\n this.timestamp = timestamp;\n this.rules = rules;\n\n this.battlePlayers = players.map((player, i) => this.joinBattle(player, i < rules.playerCount));\n this.battlegroundTier = rules.tier;\n this.dice = new Dice(id);\n this.state = BattleUtils.buildBattleState(this.battlePlayers, this.dice);\n\n this.turnCount = 0;\n\n this.stateHash = Sha256.hashToHex(JSON.stringify(this.state));\n this.status = Constants.Status.Open;\n this.stateHistory = [];\n this.actor = players[this.state.playerToAct].userId;\n this.stage = 'created';\n \n this.owner = this.validator = validator;\n\n const tempPlayerToAct = this.state.playerToAct;\n\n for (let i = 0; i < 2; i++) {\n this.state.playerToAct = i;\n let skills = this.battlePlayers[i].fighter.skills;\n if (skills.includes(Constants.SkillType.Shadowy))\n {\n var playerName = BattleUtils.getPrettifiedPlayerName(this, this.state);\n let log = `${playerName} uses <sprite name=\"${BattleUtils.parseSkillName(Constants.SkillType.Hide)}\">${BattleUtils.parseSkillName(Constants.SkillType.Hide)}\\n`;\n this.state.actionLogs.push(BattleUtils.abilityCheckAndApplyStatusEffect(this, this.state, this.dice, Constants.SkillType.Hide\n , Constants.Ability.Dexterity, Constants.Ability.Intelligence, Constants.StatusEffect.Hidden, 99, true, log));\n \n }\n }\n this.state.fighterStates = BattleUtils.computeFighterStates(this, this.state);\n this.state.fighterStates.forEach(fs => fs.timeLeft = 120000);\n \n this.state.playerToAct = tempPlayerToAct; \n }\n\n joinBattle(player, auth) {\n const { userId, pubkey, owner, items, fighter, battleSkills, tags, lobbyId } = player;\n\n if(auth) {\n fighter.auth();\n items.forEach(item => item && item.auth());\n }\n \n const [mainhand, offhand, armor, hat, disguise] = items.map(i => i && i.item && FyxClass.deepClone(i.item));\n let skills = player.skills.filter(x => x);\n return {\n userId,\n pubkey,\n owner,\n fighter,\n mainhand,\n offhand,\n armor,\n hat,\n disguise,\n battleSkills,\n skills,\n tags: tags || [],\n baseQr : items.reduce((acc, i) => acc + ((i === null || i === void 0 ? void 0 : i.item.rating) || 0), 0),\n lobbyId: lobbyId\n };\n }\n\n begin(timestamp) {\n if (this.stage !== 'created') throw new Error('Invalid Stage');\n this.timestamp = timestamp;\n delete this.stage;\n }\n\n resolve(random, timestamp, actionIndex, sig, actionOptions) {\n const location = this.location;\n console.log('Resolve', this.location);\n if (this.status !== Constants.Status.Open) throw new Error('Invalid Status');\n if (!BattleUtils.validateRandom(random, this.random)) throw new Error('Invalid Random');\n this.sig = sig;\n this.random = random;\n \n this.stateHistory[this.turnCount] = {\n location,\n ...this.getState()\n };\n \n const timePassed = timestamp - this.timestamp;\n this.state.fighterStates[this.state.playerToAct].timeLeft -= timePassed;\n\n const state = FyxClass.deepClone(this.state);\n state.actionLogs = [];\n this.dice = new Dice(random);\n\n var skipTurn = false;\n if (actionIndex === -1 || actionIndex === undefined) {\n skipTurn = true;\n this.state = BattleUtils.skipTurn(this, state, this.dice, `idle`);\n } else {\n const attacker = this.battlePlayers[this.state.playerToAct];\n const skill = attacker.skills.find( x => x.skillType == this.state.fighterStates[this.state.playerToAct].battleSkills[actionIndex] );\n if (!skill) throw new Error(`resolve: ${attacker.fighter.displayName} used an invalid Skill ID: ${actionIndex}`);\n this.state = skill.run(this, state, this.dice, timestamp, actionOptions);\n }\n\n this.status = this.state.status;\n this.timestamp = timestamp;\n this._endTurn(skipTurn);\n }\n\n simulate(state, random, actionIndex) {\n const attacker = this.battlePlayers[state.playerToAct];\n const skill = attacker.skills.find( x => x.skillType == this.state.fighterStates[this.state.playerToAct].battleSkills[actionIndex] );\n state.actionLogs = [];\n if (!skill) throw new Error(`simulate: ${attacker.fighter.displayName} used an invalid Skill ID: ${actionIndex}`);\n let { turnCount } = state;\n state = skill.run(this, state, new Dice(random));\n \n return {\n battleId: this.id,\n ...state,\n battleStatus: state.status,\n random,\n turnCount: turnCount + 1,\n actor: this.battlePlayers[state.playerToAct].userId,\n stateHash: Sha256.hashToHex(JSON.stringify(state)),\n location: this.origin,\n origin: this.origin,\n };\n }\n\n forfeit(userId, sig, timestamp) {\n if (this.status !== Constants.Status.Open) throw new Error('Invalid Status');\n this.stateHistory[this.turnCount] = {\n location: this.location,\n ...this.getState()\n };\n const playerIndex = this.battlePlayers.findIndex(p => p.userId === userId);\n const player = this.battlePlayers[playerIndex];\n const victorIndex = this.battlePlayers.findIndex(p => p.userId !== userId);\n const victor = this.battlePlayers[victorIndex];\n \n const state = FyxClass.deepClone(this.state);\n state.victor = {\n pubkey: victor.pubkey,\n owner: victor.owner,\n fighter: victor.fighter,\n userId: victor.userId\n };\n state.actionLogs = [{\n playerIndex: playerIndex,\n actionLogMessage: `<gradient=!player${playerIndex}-color><b>${player.fighter.metadata.name.toUpperCase()}</b> <gradient=!log-color> Forfeited`\n }];\n state.playerToAct = victorIndex;\n state.status = Constants.Status.Forfeit;\n this.state = state;\n\n this.status = this.state.status;\n this.timestamp = timestamp;\n this._endTurn();\n }\n\n _endTurn(skipTurn = false) {\n if (this.status !== Constants.Status.Open) {\n this.victor = {...this.battlePlayers[this.state.playerToAct]};\n }\n this.turnCount++;\n this.stateHash = Sha256.hashToHex(JSON.stringify(this.state));\n this.actor = this.battlePlayers[this.state.playerToAct].userId;\n if (!skipTurn) { \n this.state.fighterStates[this.state.playerToAct].timeLeft = Math.min(\n this.state.fighterStates[this.state.playerToAct].timeLeft + 45000,\n 240000\n ); \n }\n }\n\n finalize() {\n this.stateHistory[this.turnCount] = {\n location: this.location,\n ...this.getState()\n };\n if(![Constants.Status.Complete, Constants.Status.Forfeit].includes(this.status)) throw new Error('Invalid Status');\n const victor = this.victor;\n const loser = this.battlePlayers.find(p => p.userId !== victor.userId);\n\n this.xp = 0;\n // TODO: We should use rawXP instead of level\n // Otherwise they might forego levelling to farm low level mobs for XP\n if(victor.fighter.level <= Battle.LevelCap){ // Level cap\n const xpBonus = this.rules.xpBonus;\n const baseXp = victor.fighter.level * Battle.XPRate + xpBonus;\n\n if(victor.fighter.level<=loser.fighter.level){ // Higher level mobs\n const diff = loser.fighter.level - victor.fighter.level;\n this.xp = parseInt(baseXp * (1 + 0.5*diff));\n }else{ // Lower level mobs\n this.xp = 0;\n }\n }\n \n if (!victor.tags.includes('bot')) {\n const items = issueRewards(this.dice, this.battlegroundTier);\n this.rewards = items.map(i => new FyxItem(victor.fighter.owner, i.metadata, i.item, i.satoshis));\n }\n \n this.owner = victor.fighter.owner;\n this.status = Constants.Status.Finalized;\n }\n \n getState() {\n const state = {\n ...this.state,\n location: this.origin,\n origin: this.origin,\n actor: this.actor,\n battleId: this.id,\n random: this.random,\n stateHash: this.stateHash,\n timestamp: this.timestamp,\n turnCount: this.turnCount,\n battleStatus: this.status\n };\n return state;\n }\n\n static async deploy (deployer, prev) {\n if(!prev) {\n console.log('Deploying');\n return deployer.run.deploy(Battle);\n } else {\n console.log('Upgrading');\n prev.upgrade(Battle);\n await prev.sync();\n return prev;\n }\n }\n}",{"LevelCap":10,"MaxRounds":100,"XPRate":20,"deps":{"BattleUtils":{"$jig":1},"Config":{"$jig":2},"Constants":{"$jig":3},"Dice":{"$jig":4},"FyxClass":{"$jig":5},"FyxItem":{"$jig":6},"FyxJig":{"$jig":7},"Math":{"$jig":8},"Sha256":{"$jig":9},"Skills":{"$jig":10},"expect":{"$jig":11},"issueRewards":{"$jig":12}},"hash":"9916065637d4623f273e6c431d69709818b6e8cd91605c57cc486adff2d565d8","metadata":{"app":"Cryptofights","emoji":"⚔","name":"Battle","publisher":"FYX"}}]}]}
    https://whatsonchain.com/tx/d169aec8b4e5d4028626703bbd1346fc27b9ef0126c38736d1b25eb3cf9c688d