UNPKG

swordfight-engine

Version:

A multiplayer sword fighting game engine with character management, round-based combat, and real-time multiplayer support

9 lines (8 loc) 37.3 kB
/** * swordfight-engine v1.0.6 * A multiplayer sword fighting game engine with character management, round-based combat, and real-time multiplayer support * * @author Michael * @license MIT */ var w=Object.defineProperty;var y=(s,e,o)=>e in s?w(s,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[e]=o;var a=(s,e,o)=>y(s,typeof e!="symbol"?e+"":e,o);var d=class{constructor(e,o,t,r,n){this.game=e,this.myMove=o,this.opponentsMove=t,this.myCharacter=r,this.opponentsCharacter=n,this.outcome=this.getOutcome(this.opponentsCharacter.tables,this.myMove,this.opponentsMove),this.result=this.getResult(this.outcome,this.opponentsCharacter),this.range=this.getRange(),this.restrictions=this.getRestrictions(),this.moveModifier=this.getModifier(),this.score=this.getScore(),this.bonus=this.getMyBonus(),this.nextRoundBonus=this.getBonus(this.myCharacter,this.myMove,this.opponentsMove),this.totalScore=this.getTotalScore(this.score,this.moveModifier,this.bonus)}getOutcome(e,o,t){let r=e.find(n=>n.id===o.id)?.outcomes[0];if(!r){console.error("Outcome table not found");return}return r[t.id]}getResult(e,o){let t=o.results.find(r=>r.id===e);if(!t){console.error("Result not found");return}return t}getRange(){return this.result.range}getScore(){return this.result.score}getModifier(){return this.myMove.mod}getRestrictions(){return this.result.restrict}getTotalScore(e,o,t){if(isNaN(e))return 0;let r=+e+ +o+ +t;return r<0&&(r=0),+r}getBonus(e,o,t){return this.game.rounds.length===1?0:this.getResult(this.getOutcome(e.tables,o,t),e).bonus||0}calculateBonus(e,o,t,r){let n=0,c=this.getBonus(e,t,r);return c.length&&c.forEach(l=>{for(let u in l)(o.type===u||o.tag===u)&&(n+=+l[u])}),n}getMyBonus(){if(this.game.rounds.length<=1)return 0;let e=this.game.rounds[this.game.rounds.length-2];return this.calculateBonus(this.myCharacter,this.myMove,e.myMove,e.opponentsMove)}};import{joinRoom as v}from"trystero";var m=class{constructor(e){let o=e.gameId;this.started=!1,console.log("Room ID: ",o);let t=v({appId:"swordfight.me"},o);if(t.getPeers().length>=2){console.error("Room is full");let r=new CustomEvent("roomFull");document.dispatchEvent(r);return}else console.log("You have joined the room");t.onPeerJoin(r=>{console.log("Peer joined: ",r);let n=t.getPeers();if(Object.keys(n).length>=1){this.started=!0,localStorage.getItem("playerName")?(e.myCharacter.name=localStorage.getItem("playerName"),this.sendName({name:e.myCharacter.name})):this.sendName({name:e.myCharacter.name}),window.logging&&console.log("Sent name: ",e.myCharacter.name);let c=new CustomEvent("start",{detail:{game:e}});document.dispatchEvent(c)}}),[this.sendMove,this.getMove]=t.makeAction("move"),[this.sendName,this.getName]=t.makeAction("name")}};var i=class{constructor(e,o=[]){a(this,"getMoveObject",e=>this.moves.find(o=>o.id===e));this.character=e,this.result=o,this.moves=this.character.moves,this.filteredMoves=this.filteredMoves()}getMoves(){return this.character.moves}filteredMoves(){return this.moves.filter(e=>!(this.result.allowOnly&&!this.result.allowOnly.includes(e.name)&&!this.result.allowOnly.includes(e.tag)||!this.character.weapon&&e.requiresWeapon||!this.character.shield&&e.requiresShield||e.name==="Retrieve Weapon"&&this.character.weapon||e.range!==this.result.range||this.result.restrict.includes(e.type)||this.result.restrict.includes(e.tag)))}};var g=class{constructor(e){this.game=e;let o=new CustomEvent("start",{detail:{game:this.game}});setTimeout(()=>{this.started=!0,document.dispatchEvent(o)},3e3)}getMove(e){if(!this.game.opponentsRoundData)return;let o=this.game.opponentsRoundData.result,t=new i(this.game.opponentsCharacter,o),r=t.filteredMoves[Math.floor(Math.random()*t.filteredMoves.length)];!this.game.opponentsCharacter.weapon&&Math.random()>.75&&(r=t.filteredMoves.find(n=>n.name==="Retrieve Weapon")),console.log(`Opponent move: ${r.name}`),e({move:r})}getName(e){e({name:this.game.opponentsCharacter.name})}sendMove(e){return e}sendName(e){return e}};var h={name:"Human Fighter",slug:"human-fighter",description:"Human with sword and shield",health:"12",firstMove:"62",weapon:!0,shield:!0,moves:[{tag:"Down Swing",name:"Smash",range:"close",type:"strong",id:"24",mod:"3",requiresWeapon:!0},{tag:"Side Swing",name:"Strong",range:"close",type:"strong",id:"28",mod:"2",requiresWeapon:!0},{tag:"Side Swing",name:"High",range:"close",type:"high",id:"10",mod:"1",requiresWeapon:!0},{tag:"Side Swing",name:"Low",range:"close",type:"low",id:"2",mod:"1",requiresWeapon:!0},{tag:"Thrust",name:"High",range:"close",type:"high",id:"32",mod:"0",requiresWeapon:!0},{tag:"Thrust",name:"Low",range:"close",type:"low",id:"14",mod:"0",requiresWeapon:!0},{tag:"Fake",name:"High",range:"close",type:"high",id:"42",mod:"0",requiresWeapon:!0},{tag:"Fake",name:"Low",range:"close",type:"low",id:"12",mod:"0",requiresWeapon:!0},{tag:"Fake",name:"Side Swing",range:"close",type:"low",id:"22",mod:"-1",requiresWeapon:!0},{tag:"Fake",name:"Thrust",range:"close",type:"high",id:"38",mod:"0",requiresWeapon:!0},{tag:"Protected Attack",name:"Down Swing",range:"close",type:"strong",id:"44",mod:"2",requiresWeapon:!0,requiresShield:!0},{tag:"Protected Attack",name:"Side Swing",range:"close",type:"low",id:"48",mod:"0",requiresWeapon:!0,requiresShield:!0},{tag:"Protected Attack",name:"Thrust",range:"close",type:"high",id:"6",mod:"-1",requiresWeapon:!0,requiresShield:!0},{tag:"Special",name:"Kick",range:"close",type:"low",id:"34",mod:"0",requiresWeapon:!1},{tag:"Special",name:"Wild Swing",range:"close",type:"risky",id:"40",mod:"2",requiresWeapon:!0},{tag:"Special",name:"Dislodge Weapon",range:"close",type:"low",id:"30",mod:"-4",requiresWeapon:!0},{tag:"Special",name:"Retrieve Weapon",range:"close",type:"defense",id:"46",mod:"-6",requiresWeapon:!1},{tag:"Shield Block",name:"High",range:"close",type:"defense",id:"26",mod:"1",requiresWeapon:!1,requiresShield:!0},{tag:"Shield Block",name:"Low",range:"close",type:"defense",id:"4",mod:"1",requiresWeapon:!1,requiresShield:!0},{tag:"Jump",name:"Up",range:"close",type:"defense",id:"18",mod:"-6",requiresWeapon:!1},{tag:"Jump",name:"Dodge",range:"close",type:"risky",id:"8",mod:"-4",requiresWeapon:!1},{tag:"Jump",name:"Duck",range:"close",type:"defense",id:"20",mod:"-5",requiresWeapon:!1},{tag:"Jump",name:"Away",range:"close",type:"risky",id:"16",mod:"-4",requiresWeapon:!1},{tag:"Extended Range",name:"Charge",range:"far",type:"extended",id:"50",mod:"3",requiresWeapon:!0},{tag:"Extended Range",name:"Swing High",range:"far",type:"extended",id:"64",mod:"-6",requiresWeapon:!0},{tag:"Extended Range",name:"Swing Low",range:"far",type:"extended",id:"58",mod:"-6",requiresWeapon:!0},{tag:"Extended Range",name:"Thrust High",range:"far",type:"extended",id:"54",mod:"-5",requiresWeapon:!0},{tag:"Extended Range",name:"Thrust Low",range:"far",type:"extended",id:"60",mod:"-5",requiresWeapon:!0},{tag:"Extended Range",name:"Block & Close",range:"far",type:"extended-defense",id:"56",mod:"0",requiresWeapon:!1},{tag:"Extended Range",name:"Dodge",range:"far",type:"extended-defense",id:"52",mod:"-6",requiresWeapon:!1},{tag:"Extended Range",name:"Jump Back",range:"far",type:"extended-defense",id:"62",mod:"-6",requiresWeapon:!1}],tables:[{id:"2",outcomes:[{"2":"49","4":"63","6":"13","8":"19","10":"13","12":"13","14":"49","16":"57","18":"37","20":"19","22":"49","24":"13","26":"13","28":"13","30":"49","32":"13","34":"41","36":"13","38":"13","40":"49","42":"49","44":"15","46":"27","48":"13"}]},{id:"4",outcomes:[{"2":"5","4":"59","6":"59","8":"33","10":"3","12":"59","14":"11","16":"57","18":"37","20":"59","22":"11","24":"15","26":"17","28":"3","30":"15","32":"9","34":"59","36":"15","38":"3","40":"5","42":"59","44":"15","46":"43","48":"59"}]},{id:"6",outcomes:[{"2":"19","4":"63","6":"17","8":"33","10":"3","12":"3","14":"49","16":"19","18":"19","20":"29","22":"11","24":"15","26":"17","28":"45","30":"5","32":"45","34":"19","36":"19","38":"19","40":"19","42":"19","44":"45","46":"19","48":"45"}]},{id:"8",outcomes:[{"2":"5","4":"63","6":"9","8":"33","10":"3","12":"3","14":"21","16":"57","18":"37","20":"29","22":"21","24":"15","26":"17","28":"3","30":"3","32":"9","34":"19","36":"15","38":"3","40":"5","42":"5","44":"15","46":"43","48":"3"}]},{id:"10",outcomes:[{"2":"31","4":"53","6":"9","8":"19","10":"45","12":"3","14":"7","16":"57","18":"13","20":"23","22":"7","24":"45","26":"17","28":"31","30":"3","32":"53","34":"25","36":"31","38":"45","40":"53","42":"31","44":"45","46":"43","48":"45"}]},{id:"12",outcomes:[{"2":"31","4":"63","6":"9","8":"19","10":"53","12":"45","14":"11","16":"57","18":"13","20":"29","22":"11","24":"45","26":"17","28":"31","30":"3","32":"45","34":"25","36":"31","38":"45","40":"53","42":"49","44":"15","46":"29","48":"45"}]},{id:"14",outcomes:[{"2":"45","4":"63","6":"49","8":"23","10":"13","12":"3","14":"13","16":"19","18":"37","20":"53","22":"11","24":"13","26":"13","28":"13","30":"5","32":"13","34":"13","36":"13","38":"13","40":"49","42":"49","44":"13","46":"53","48":"49"}]},{id:"16",outcomes:[{"2":"57","4":"57","6":"9","8":"61","10":"57","12":"57","14":"11","16":"57","18":"61","20":"61","22":"11","24":"19","26":"57","28":"21","30":"57","32":"9","34":"41","36":"41","38":"57","40":"21","42":"57","44":"57","46":"43","48":"57"}]},{id:"18",outcomes:[{"2":"5","4":"63","6":"17","8":"33","10":"3","12":"3","14":"11","16":"57","18":"37","20":"29","22":"11","24":"15","26":"17","28":"3","30":"3","32":"9","34":"41","36":"15","38":"3","40":"21","42":"5","44":"15","46":"43","48":"3"}]},{id:"20",outcomes:[{"2":"5","4":"63","6":"9","8":"33","10":"21","12":"3","14":"11","16":"57","18":"37","20":"29","22":"11","24":"15","26":"17","28":"21","30":"3","32":"9","34":"25","36":"15","38":"3","40":"5","42":"5","44":"15","46":"43","48":"3"}]},{id:"22",outcomes:[{"2":"49","4":"63","6":"9","8":"23","10":"13","12":"13","14":"13","16":"19","18":"37","20":"53","22":"19","24":"15","26":"17","28":"3","30":"5","32":"31","34":"25","36":"13","38":"3","40":"49","42":"49","44":"13","46":"43","48":"49"}]},{id:"24",outcomes:[{"2":"53","4":"41","6":"17","8":"33","10":"45","12":"45","14":"11","16":"1","18":"53","20":"7","22":"11","24":"7","26":"17","28":"3","30":"3","32":"45","34":"53","36":"15","38":"45","40":"21","42":"5","44":"15","46":"41","48":"17"}]},{id:"26",outcomes:[{"2":"5","4":"63","6":"59","8":"33","10":"3","12":"59","14":"11","16":"15","18":"59","20":"29","22":"11","24":"15","26":"59","28":"3","30":"3","32":"9","34":"25","36":"59","38":"3","40":"5","42":"59","44":"59","46":"43","48":"59"}]},{id:"28",outcomes:[{"2":"7","4":"31","6":"45","8":"19","10":"3","12":"53","14":"11","16":"23","18":"37","20":"23","22":"11","24":"53","26":"53","28":"19","30":"31","32":"9","34":"25","36":"31","38":"27","40":"41","42":"5","44":"15","46":"29","48":"3"}]},{id:"30",outcomes:[{"2":"49","4":"63","6":"9","8":"33","10":"3","12":"3","14":"11","16":"57","18":"37","20":"29","22":"27","24":"15","26":"17","28":"3","30":"27","32":"27","34":"25","36":"15","38":"27","40":"5","42":"27","44":"15","46":"27","48":"3"}]},{id:"32",outcomes:[{"2":"53","4":"53","6":"45","8":"33","10":"3","12":"45","14":"53","16":"19","18":"13","20":"29","22":"53","24":"45","26":"17","28":"53","30":"3","32":"31","34":"25","36":"53","38":"45","40":"31","42":"53","44":"45","46":"43","48":"17"}]},{id:"34",outcomes:[{"2":"5","4":"63","6":"11","8":"33","10":"51","12":"3","14":"11","16":"1","18":"37","20":"29","22":"51","24":"15","26":"51","28":"51","30":"51","32":"51","34":"51","36":"41","38":"3","40":"41","42":"5","44":"15","46":"27","48":"51"}]},{id:"36",outcomes:[{"2":"5","4":"7","6":"55","8":"33","10":"3","12":"3","14":"11","16":"1","18":"7","20":"7","22":"11","24":"15","26":"55","28":"7","30":"27","32":"9","34":"7","36":"15","38":"3","40":"7","42":"5","44":"55","46":"7","48":"55"}]},{id:"38",outcomes:[{"2":"31","4":"53","6":"9","8":"19","10":"45","12":"45","14":"7","16":"57","18":"18","20":"29","22":"9","24":"45","26":"17","28":"3","30":"5","32":"45","34":"25","36":"31","38":"45","40":"5","42":"31","44":"45","46":"43","48":"45"}]},{id:"40",outcomes:[{"2":"5","4":"63","6":"11","8":"33","10":"3","12":"3","14":"11","16":"1","18":"37","20":"29","22":"51","24":"15","26":"51","28":"51","30":"51","32":"51","34":"51","36":"41","38":"3","40":"41","42":"5","44":"15","46":"27","48":"51"}]},{id:"42",outcomes:[{"2":"49","4":"63","6":"9","8":"19","10":"13","12":"49","14":"49","16":"57","18":"37","20":"31","22":"49","24":"13","26":"17","28":"13","30":"5","32":"9","34":"41","36":"13","38":"13","40":"49","42":"49","44":"15","46":"27","48":"49"}]},{id:"44",outcomes:[{"2":"5","4":"19","6":"45","8":"33","10":"45","12":"3","14":"19","16":"57","18":"7","20":"19","22":"19","24":"15","26":"17","28":"19","30":"19","32":"45","34":"19","36":"19","38":"45","40":"19","42":"5","44":"45","46":"27","48":"45"}]},{id:"46",outcomes:[{"2":"5","4":"63","6":"9","8":"33","10":"3","12":"3","14":"11","16":"1","18":"37","20":"29","22":"11","24":"15","26":"17","28":"3","30":"15","32":"9","34":"25","36":"15","38":"3","40":"5","42":"5","44":"15","46":"43","48":"3"}]},{id:"48",outcomes:[{"2":"5","4":"19","6":"45","8":"19","10":"45","12":"45","14":"49","16":"57","18":"19","20":"29","22":"49","24":"19","26":"17","28":"19","30":"19","32":"9","34":"25","36":"19","38":"45","40":"19","42":"49","44":"45","46":"19","48":"49"}]},{id:"50",outcomes:[{"50":"45","52":"23","54":"9","56":"17","58":"41","60":"11","62":"19","64":"19"}]},{id:"52",outcomes:[{"50":"21","52":"61","54":"9","56":"57","58":"5","60":"11","62":"57","64":"57"}]},{id:"54",outcomes:[{"50":"53","52":"33","54":"45","56":"17","58":"35","60":"11","62":"35","64":"3"}]},{id:"56",outcomes:[{"50":"39","52":"61","54":"9","56":"17","58":"57","60":"57","62":"57","64":"3"}]},{id:"58",outcomes:[{"50":"39","52":"33","54":"47","56":"47","58":"5","60":"11","62":"57","64":"57"}]},{id:"60",outcomes:[{"50":"13","52":"33","54":"13","56":"57","58":"5","60":"11","62":"57","64":"47"}]},{id:"62",outcomes:[{"50":"39","52":"61","54":"57","56":"57","58":"57","60":"57","62":"57","64":"57"}]},{id:"64",outcomes:[{"50":"7","52":"35","54":"9","56":"17","58":"57","60":"35","62":"57","64":"3"}]}],results:[{id:"1",name:"Jumping away",mod:"2",range:"close",score:"",restrict:[],bonus:[{strong:"2",high:"2",low:"2",risky:"2"}]},{id:"3",name:"Swinging high",mod:"0",range:"close",score:"",restrict:["Thrust","high"]},{id:"5",name:"Swinging low",mod:"0",range:"close",score:"",restrict:["Thrust","low"]},{id:"7",name:"Dazed",mod:"0",range:"close",score:"6",restrict:["strong","high","low","risky"]},{id:"9",name:"Thrusting high",mod:"0",range:"close",score:"",restrict:["Side Swing"]},{id:"11",name:"Thrusting low",mod:"0",range:"close",score:"",restrict:["Side Swing","high"]},{id:"13",name:"Leg wound",mod:"0",range:"close",score:"3",restrict:["strong","high"]},{id:"15",name:"Swinging down",mod:"0",range:"close",score:"",restrict:["low"]},{id:"17",name:"Blocking high",mod:"0",range:"close",score:"-4",restrict:["low"]},{id:"19",name:"Knocked off balance",mod:"0",range:"close",score:"0",restrict:["strong","high","low"]},{id:"21",name:"Turned around",mod:"0",range:"close",score:"0",restrict:["strong","high","low","defense"]},{id:"23",name:"Behind you!",mod:"0",range:"close",score:"",restrict:[]},{id:"25",name:"Kicking",mod:"0",range:"close",score:"",restrict:["low","risky"]},{id:"27",name:"Weapon Dislodged",mod:"0",range:"close",score:"",restrict:[],weaponDislodged:!0},{id:"29",name:"Ducking",range:"close",score:"",restrict:["strong"],bonus:[{low:"2"}]},{id:"31",name:"Arm wound",mod:"0",range:"close",score:"2",restrict:["strong","high"]},{id:"33",name:"Dodging",range:"close",score:"",restrict:[],bonus:[{"Down Swing":"2","Side Swing":"2"}]},{id:"35",name:"Extended range body wound",mod:"0",range:"far",score:"4",restrict:["extended"]},{id:"37",name:"Jumping up",range:"close",score:"",restrict:["low"],bonus:[{strong:"2"}]},{id:"39",name:"Charging",mod:"0",range:"close",score:"",restrict:["defense","risky"]},{id:"41",name:"Knocked down",mod:"0",range:"close",score:"0",restrict:[],allowOnly:["Jump"]},{id:"43",name:"Retrieving Weapon",mod:"0",range:"close",score:"",restrict:[],retrieveWeapon:!0},{id:"45",name:"Parrying high",mod:"0",range:"close",score:"-4",restrict:[]},{id:"47",name:"Extended range leg wound",mod:"0",range:"far",score:"3",restrict:["extended"]},{id:"49",name:"Parrying low",mod:"0",range:"close",score:"-4",restrict:[]},{id:"51",name:"Kicked off balance",mod:"0",range:"close",score:"0",restrict:["strong","high","low"]},{id:"53",name:"Body wound",mod:"0",range:"close",score:"4",restrict:["strong","high","low"]},{id:"55",name:"Shield Smashed",mod:"0",range:"close",score:"0",restrict:[],shieldDestroyed:!0},{id:"57",name:"Extended range blocking",mod:"0",range:"far",score:"",restrict:[]},{id:"59",name:"Pushed off balance",mod:"0",range:"close",score:"0",restrict:["strong","high","low"]},{id:"61",name:"Extended range dodging",mod:"0",range:"far",score:"",restrict:[]},{id:"63",name:"Blocking low",mod:"0",range:"close",score:"-4",restrict:["strong"]}]};var p={name:"Evil Human Fighter",slug:"evil-human-fighter",description:"Evil human with sword and shield",health:"12",firstMove:"62",weapon:!0,shield:!0,moves:[{tag:"Down Swing",name:"Smash",range:"close",type:"strong",id:"24",mod:"3",requiresWeapon:!0},{tag:"Side Swing",name:"Strong",range:"close",type:"strong",id:"28",mod:"2",requiresWeapon:!0},{tag:"Side Swing",name:"High",range:"close",type:"high",id:"10",mod:"1",requiresWeapon:!0},{tag:"Side Swing",name:"Low",range:"close",type:"low",id:"2",mod:"1",requiresWeapon:!0},{tag:"Thrust",name:"High",range:"close",type:"high",id:"32",mod:"0",requiresWeapon:!0},{tag:"Thrust",name:"Low",range:"close",type:"low",id:"14",mod:"0",requiresWeapon:!0},{tag:"Fake",name:"High",range:"close",type:"high",id:"42",mod:"0",requiresWeapon:!0},{tag:"Fake",name:"Low",range:"close",type:"low",id:"12",mod:"0",requiresWeapon:!0},{tag:"Fake",name:"Side Swing",range:"close",type:"low",id:"22",mod:"-1",requiresWeapon:!0},{tag:"Fake",name:"Thrust",range:"close",type:"high",id:"38",mod:"0",requiresWeapon:!0},{tag:"Protected Attack",name:"Down Swing",range:"close",type:"strong",id:"44",mod:"2",requiresWeapon:!0,requiresShield:!0},{tag:"Protected Attack",name:"Side Swing",range:"close",type:"low",id:"48",mod:"0",requiresWeapon:!0,requiresShield:!0},{tag:"Protected Attack",name:"Thrust",range:"close",type:"high",id:"6",mod:"-1",requiresWeapon:!0,requiresShield:!0},{tag:"Special",name:"Kick",range:"close",type:"low",id:"34",mod:"0",requiresWeapon:!1},{tag:"Special",name:"Wild Swing",range:"close",type:"risky",id:"40",mod:"2",requiresWeapon:!0},{tag:"Special",name:"Dislodge Weapon",range:"close",type:"low",id:"30",mod:"-4",requiresWeapon:!0},{tag:"Special",name:"Retrieve Weapon",range:"close",type:"defense",id:"46",mod:"-6",requiresWeapon:!1},{tag:"Shield Block",name:"High",range:"close",type:"defense",id:"26",mod:"1",requiresWeapon:!1,requiresShield:!0},{tag:"Shield Block",name:"Low",range:"close",type:"defense",id:"4",mod:"1",requiresWeapon:!1,requiresShield:!0},{tag:"Jump",name:"Up",range:"close",type:"defense",id:"18",mod:"-6",requiresWeapon:!1},{tag:"Jump",name:"Dodge",range:"close",type:"risky",id:"8",mod:"-4",requiresWeapon:!1},{tag:"Jump",name:"Duck",range:"close",type:"defense",id:"20",mod:"-5",requiresWeapon:!1},{tag:"Jump",name:"Away",range:"close",type:"risky",id:"16",mod:"-4",requiresWeapon:!1},{tag:"Extended Range",name:"Charge",range:"far",type:"extended",id:"50",mod:"3",requiresWeapon:!0},{tag:"Extended Range",name:"Swing High",range:"far",type:"extended",id:"64",mod:"-6",requiresWeapon:!0},{tag:"Extended Range",name:"Swing Low",range:"far",type:"extended",id:"58",mod:"-6",requiresWeapon:!0},{tag:"Extended Range",name:"Thrust High",range:"far",type:"extended",id:"54",mod:"-5",requiresWeapon:!0},{tag:"Extended Range",name:"Thrust Low",range:"far",type:"extended",id:"60",mod:"-5",requiresWeapon:!0},{tag:"Extended Range",name:"Block & Close",range:"far",type:"extended-defense",id:"56",mod:"0",requiresWeapon:!1},{tag:"Extended Range",name:"Dodge",range:"far",type:"extended-defense",id:"52",mod:"-6",requiresWeapon:!1},{tag:"Extended Range",name:"Jump Back",range:"far",type:"extended-defense",id:"62",mod:"-6",requiresWeapon:!1}],tables:[{id:"2",outcomes:[{"2":"49","4":"63","6":"13","8":"19","10":"13","12":"13","14":"49","16":"57","18":"37","20":"19","22":"49","24":"13","26":"13","28":"13","30":"49","32":"13","34":"41","36":"13","38":"13","40":"49","42":"49","44":"15","46":"27","48":"13"}]},{id:"4",outcomes:[{"2":"5","4":"59","6":"59","8":"33","10":"3","12":"59","14":"11","16":"57","18":"37","20":"59","22":"11","24":"15","26":"17","28":"3","30":"15","32":"9","34":"59","36":"15","38":"3","40":"5","42":"59","44":"15","46":"43","48":"59"}]},{id:"6",outcomes:[{"2":"19","4":"63","6":"17","8":"33","10":"3","12":"3","14":"49","16":"19","18":"19","20":"29","22":"11","24":"15","26":"17","28":"45","30":"5","32":"45","34":"19","36":"19","38":"19","40":"19","42":"19","44":"45","46":"19","48":"45"}]},{id:"8",outcomes:[{"2":"5","4":"63","6":"9","8":"33","10":"3","12":"3","14":"21","16":"57","18":"37","20":"29","22":"21","24":"15","26":"17","28":"3","30":"3","32":"9","34":"19","36":"15","38":"3","40":"5","42":"5","44":"15","46":"43","48":"3"}]},{id:"10",outcomes:[{"2":"31","4":"53","6":"9","8":"19","10":"45","12":"3","14":"7","16":"57","18":"13","20":"23","22":"7","24":"45","26":"17","28":"31","30":"3","32":"53","34":"25","36":"31","38":"45","40":"53","42":"31","44":"45","46":"43","48":"45"}]},{id:"12",outcomes:[{"2":"31","4":"63","6":"9","8":"19","10":"53","12":"45","14":"11","16":"57","18":"13","20":"29","22":"11","24":"45","26":"17","28":"31","30":"3","32":"45","34":"25","36":"31","38":"45","40":"53","42":"49","44":"15","46":"29","48":"45"}]},{id:"14",outcomes:[{"2":"45","4":"63","6":"49","8":"23","10":"13","12":"3","14":"13","16":"19","18":"37","20":"53","22":"11","24":"13","26":"13","28":"13","30":"5","32":"13","34":"13","36":"13","38":"13","40":"49","42":"49","44":"13","46":"53","48":"49"}]},{id:"16",outcomes:[{"2":"57","4":"57","6":"9","8":"61","10":"57","12":"57","14":"11","16":"57","18":"61","20":"61","22":"11","24":"19","26":"57","28":"21","30":"57","32":"9","34":"41","36":"41","38":"57","40":"21","42":"57","44":"57","46":"43","48":"57"}]},{id:"18",outcomes:[{"2":"5","4":"63","6":"17","8":"33","10":"3","12":"3","14":"11","16":"57","18":"37","20":"29","22":"11","24":"15","26":"17","28":"3","30":"3","32":"9","34":"41","36":"15","38":"3","40":"21","42":"5","44":"15","46":"43","48":"3"}]},{id:"20",outcomes:[{"2":"5","4":"63","6":"9","8":"33","10":"21","12":"3","14":"11","16":"57","18":"37","20":"29","22":"11","24":"15","26":"17","28":"21","30":"3","32":"9","34":"25","36":"15","38":"3","40":"5","42":"5","44":"15","46":"43","48":"3"}]},{id:"22",outcomes:[{"2":"49","4":"63","6":"9","8":"23","10":"13","12":"13","14":"13","16":"19","18":"37","20":"53","22":"19","24":"15","26":"17","28":"3","30":"5","32":"31","34":"25","36":"13","38":"3","40":"49","42":"49","44":"13","46":"43","48":"49"}]},{id:"24",outcomes:[{"2":"53","4":"41","6":"17","8":"33","10":"45","12":"45","14":"11","16":"1","18":"53","20":"7","22":"11","24":"7","26":"17","28":"3","30":"3","32":"45","34":"53","36":"15","38":"45","40":"21","42":"5","44":"15","46":"41","48":"17"}]},{id:"26",outcomes:[{"2":"5","4":"63","6":"59","8":"33","10":"3","12":"59","14":"11","16":"15","18":"59","20":"29","22":"11","24":"15","26":"59","28":"3","30":"3","32":"9","34":"25","36":"59","38":"3","40":"5","42":"59","44":"59","46":"43","48":"59"}]},{id:"28",outcomes:[{"2":"7","4":"31","6":"45","8":"19","10":"3","12":"53","14":"11","16":"23","18":"37","20":"23","22":"11","24":"53","26":"53","28":"19","30":"31","32":"9","34":"25","36":"31","38":"27","40":"41","42":"5","44":"15","46":"29","48":"3"}]},{id:"30",outcomes:[{"2":"49","4":"63","6":"9","8":"33","10":"3","12":"3","14":"11","16":"57","18":"37","20":"29","22":"27","24":"15","26":"17","28":"3","30":"27","32":"27","34":"25","36":"15","38":"27","40":"5","42":"27","44":"15","46":"27","48":"3"}]},{id:"32",outcomes:[{"2":"53","4":"53","6":"45","8":"33","10":"3","12":"45","14":"53","16":"19","18":"13","20":"29","22":"53","24":"45","26":"17","28":"53","30":"3","32":"31","34":"25","36":"53","38":"45","40":"31","42":"53","44":"45","46":"43","48":"17"}]},{id:"34",outcomes:[{"2":"5","4":"63","6":"11","8":"33","10":"51","12":"3","14":"11","16":"1","18":"37","20":"29","22":"51","24":"15","26":"51","28":"51","30":"51","32":"51","34":"51","36":"41","38":"3","40":"41","42":"5","44":"15","46":"27","48":"51"}]},{id:"36",outcomes:[{"2":"5","4":"7","6":"55","8":"33","10":"3","12":"3","14":"11","16":"1","18":"7","20":"7","22":"11","24":"15","26":"55","28":"7","30":"27","32":"9","34":"7","36":"15","38":"3","40":"7","42":"5","44":"55","46":"7","48":"55"}]},{id:"38",outcomes:[{"2":"31","4":"53","6":"9","8":"19","10":"45","12":"45","14":"7","16":"57","18":"18","20":"29","22":"9","24":"45","26":"17","28":"3","30":"5","32":"45","34":"25","36":"31","38":"45","40":"5","42":"31","44":"45","46":"43","48":"45"}]},{id:"40",outcomes:[{"2":"5","4":"63","6":"11","8":"33","10":"3","12":"3","14":"11","16":"1","18":"37","20":"29","22":"51","24":"15","26":"51","28":"51","30":"51","32":"51","34":"51","36":"41","38":"3","40":"41","42":"5","44":"15","46":"27","48":"51"}]},{id:"42",outcomes:[{"2":"49","4":"63","6":"9","8":"19","10":"13","12":"49","14":"49","16":"57","18":"37","20":"31","22":"49","24":"13","26":"17","28":"13","30":"5","32":"9","34":"41","36":"13","38":"13","40":"49","42":"49","44":"15","46":"27","48":"49"}]},{id:"44",outcomes:[{"2":"5","4":"19","6":"45","8":"33","10":"45","12":"3","14":"19","16":"57","18":"7","20":"19","22":"19","24":"15","26":"17","28":"19","30":"19","32":"45","34":"19","36":"19","38":"45","40":"19","42":"5","44":"45","46":"27","48":"45"}]},{id:"46",outcomes:[{"2":"5","4":"63","6":"9","8":"33","10":"3","12":"3","14":"11","16":"1","18":"37","20":"29","22":"11","24":"15","26":"17","28":"3","30":"15","32":"9","34":"25","36":"15","38":"3","40":"5","42":"5","44":"15","46":"43","48":"3"}]},{id:"48",outcomes:[{"2":"5","4":"19","6":"45","8":"19","10":"45","12":"45","14":"49","16":"57","18":"19","20":"29","22":"49","24":"19","26":"17","28":"19","30":"19","32":"9","34":"25","36":"19","38":"45","40":"19","42":"49","44":"45","46":"19","48":"49"}]},{id:"50",outcomes:[{"50":"45","52":"23","54":"9","56":"17","58":"41","60":"11","62":"19","64":"19"}]},{id:"52",outcomes:[{"50":"21","52":"61","54":"9","56":"57","58":"5","60":"11","62":"57","64":"57"}]},{id:"54",outcomes:[{"50":"53","52":"33","54":"45","56":"17","58":"35","60":"11","62":"35","64":"3"}]},{id:"56",outcomes:[{"50":"39","52":"61","54":"9","56":"17","58":"57","60":"57","62":"57","64":"3"}]},{id:"58",outcomes:[{"50":"39","52":"33","54":"47","56":"47","58":"5","60":"11","62":"57","64":"57"}]},{id:"60",outcomes:[{"50":"13","52":"33","54":"13","56":"57","58":"5","60":"11","62":"57","64":"47"}]},{id:"62",outcomes:[{"50":"39","52":"61","54":"57","56":"57","58":"57","60":"57","62":"57","64":"57"}]},{id:"64",outcomes:[{"50":"7","52":"35","54":"9","56":"17","58":"57","60":"35","62":"57","64":"3"}]}],results:[{id:"1",name:"Jumping away",mod:"2",range:"close",score:"",restrict:[],bonus:[{strong:"2",high:"2",low:"2",risky:"2"}]},{id:"3",name:"Swinging high",mod:"0",range:"close",score:"",restrict:["Thrust","high"]},{id:"5",name:"Swinging low",mod:"0",range:"close",score:"",restrict:["Thrust","low"]},{id:"7",name:"Dazed",mod:"0",range:"close",score:"6",restrict:["strong","high","low","risky"]},{id:"9",name:"Thrusting high",mod:"0",range:"close",score:"",restrict:["Side Swing"]},{id:"11",name:"Thrusting low",mod:"0",range:"close",score:"",restrict:["Side Swing","high"]},{id:"13",name:"Leg wound",mod:"0",range:"close",score:"3",restrict:["strong","high"]},{id:"15",name:"Swinging down",mod:"0",range:"close",score:"",restrict:["low"]},{id:"17",name:"Blocking high",mod:"0",range:"close",score:"-4",restrict:["low"]},{id:"19",name:"Knocked off balance",mod:"0",range:"close",score:"0",restrict:["strong","high","low"]},{id:"21",name:"Turned around",mod:"0",range:"close",score:"0",restrict:["strong","high","low","defense"]},{id:"23",name:"Behind you!",mod:"0",range:"close",score:"",restrict:[]},{id:"25",name:"Kicking",mod:"0",range:"close",score:"",restrict:["low","risky"]},{id:"27",name:"Weapon Dislodged",mod:"0",range:"close",score:"",restrict:[],weaponDislodged:!0},{id:"29",name:"Ducking",range:"close",score:"",restrict:["strong"],bonus:[{low:"2"}]},{id:"31",name:"Arm wound",mod:"0",range:"close",score:"2",restrict:["strong","high"]},{id:"33",name:"Dodging",range:"close",score:"",restrict:[],bonus:[{"Down Swing":"2","Side Swing":"2"}]},{id:"35",name:"Extended range body wound",mod:"0",range:"far",score:"4",restrict:["extended"]},{id:"37",name:"Jumping up",range:"close",score:"",restrict:["low"],bonus:[{strong:"2"}]},{id:"39",name:"Charging",mod:"0",range:"close",score:"",restrict:["defense","risky"]},{id:"41",name:"Knocked down",mod:"0",range:"close",score:"0",restrict:[],allowOnly:["Jump"]},{id:"43",name:"Retrieving Weapon",mod:"0",range:"close",score:"",restrict:[],retrieveWeapon:!0},{id:"45",name:"Parrying high",mod:"0",range:"close",score:"-4",restrict:[]},{id:"47",name:"Extended range leg wound",mod:"0",range:"far",score:"3",restrict:["extended"]},{id:"49",name:"Parrying low",mod:"0",range:"close",score:"-4",restrict:[]},{id:"51",name:"Kicked off balance",mod:"0",range:"close",score:"0",restrict:["strong","high","low"]},{id:"53",name:"Body wound",mod:"0",range:"close",score:"4",restrict:["strong","high","low"]},{id:"55",name:"Shield Smashed",mod:"0",range:"close",score:"0",restrict:[],shieldDestroyed:!0},{id:"57",name:"Extended range blocking",mod:"0",range:"far",score:"",restrict:[]},{id:"59",name:"Pushed off balance",mod:"0",range:"close",score:"0",restrict:["strong","high","low"]},{id:"61",name:"Extended range dodging",mod:"0",range:"far",score:"",restrict:[]},{id:"63",name:"Blocking low",mod:"0",range:"close",score:"-4",restrict:["strong"]}]};var f=class{constructor(e){a(this,"init",async()=>{document.addEventListener("inputMove",this.inputMove)});a(this,"inputMove",e=>{try{if(!e||!e.detail||!e.detail.move)throw new Error("Invalid input event");this.rounds[this.roundNumber]||(this.rounds[this.roundNumber]={});let o=this.myCharacter.moves.find(r=>r.id===e.detail.move);if(!o)throw new Error("Invalid move ID");this.rounds[this.roundNumber].myMove=o,this.Multiplayer.sendMove({move:o,round:this.roundNumber});let t=new CustomEvent("myMove",{detail:o});document.dispatchEvent(t),this.setUp()}catch(o){console.error("Error in handleInput:",o)}});this.gameId=e,this.rounds=[],this.roundNumber=0,this.opponentsRound=0,this.myCharacter=h,this.opponentsCharacter=p,this.myMove=this.getInitialMove(this.myCharacter),this.opponentsMove=this.getInitialMove(this.opponentsCharacter),this.Moves=[],e==="computer"&&(this.opponentsCharacter.isComputer=!0),this.myCharacter.startingHealth=this.myCharacter.health,this.opponentsCharacter.startingHealth=this.opponentsCharacter.health,this.opponentsCharacter.isComputer?this.Multiplayer=new g(this):this.Multiplayer=new m(this),this.loadGame(),this.init()}getInitialMove(e){if(!e||!e.moves||!e.firstMove)throw new Error("Invalid character data");return e.moves.find(o=>o.id===e.firstMove)}setUp(){try{if(this.logGameState(),this.getOpponentsName(),!this.validateRoundNumbers())return;if(this.logFightBanner(),this.roundNumber===0&&(this.rounds[0]={myMove:this.myMove,opponentsMove:this.opponentsMove}),this.getOpponentsMove(),this.rounds[this.roundNumber]&&this.rounds[this.roundNumber].myMove&&this.rounds[this.roundNumber].opponentsMove){this.myMove=this.rounds[this.roundNumber].myMove,this.opponentsMove=this.rounds[this.roundNumber].opponentsMove,window.logging&&console.log("Both players have moved"),this.myRoundData=new d(this,this.myMove,this.opponentsMove,this.myCharacter,this.opponentsCharacter),this.opponentsRoundData=new d(this,this.opponentsMove,this.myMove,this.opponentsCharacter,this.myCharacter),this.takeDamage(this.myCharacter,this.opponentsRoundData),this.takeDamage(this.opponentsCharacter,this.myRoundData),this.Moves=new i(this.myCharacter,this.opponentsRoundData.result);let e=new CustomEvent("round",{detail:{myRoundData:this.myRoundData,opponentsRoundData:this.opponentsRoundData}});document.dispatchEvent(e),console.log("Round event dispatched"),window.logging&&(console.group(`Round ${this.roundNumber}`),console.log(`%cRange: ${this.myRoundData.result.range}`,"font-weight: bold;"),this.logRoundDetails(this.myRoundData,this.opponentsRoundData),this.logRoundDetails(this.opponentsRoundData,this.myRoundData),console.groupEnd()),this.loaded===!0&&(this.loaded=!1),this.checkForDefeat(),this.incrementRound();let o=new CustomEvent("setup");document.dispatchEvent(o),this.saveGame()}else if(this.rounds[this.roundNumber].myMove&&!this.rounds[this.roundNumber].opponentsMove){let e=new CustomEvent("move",{detail:this.rounds[this.roundNumber].myMove});document.dispatchEvent(e),window.logging&&console.log("Waiting for opponent's move")}else window.logging&&console.log("Waiting for your move")}catch(e){console.error("Error in setup:",e)}}saveGame(){let e={rounds:this.rounds,roundNumber:this.roundNumber-1,opponentsRound:this.opponentsRound-1,myCharacter:this.myCharacter,opponentsCharacter:this.opponentsCharacter,myMove:this.myMove,opponentsMove:this.opponentsMove};localStorage.setItem(this.gameId,JSON.stringify(e))}loadGame(){let e=JSON.parse(localStorage.getItem(this.gameId));e?(this.rounds=e.rounds,this.roundNumber=e.roundNumber,this.opponentsRound=e.opponentsRound,this.myCharacter=e.myCharacter,this.opponentsCharacter=e.opponentsCharacter,this.myMove=e.myMove,this.opponentsMove=e.opponentsMove,this.loaded=!0,window.logging&&console.log("Loaded game: ",this)):this.loaded=!1}logGameState(){window.logging&&console.log("Game",this)}validateRoundNumbers(){return this.roundNumber!==this.opponentsRound?(window.logging&&(console.error("Round numbers do not match"),console.log("My round number: ",this.roundNumber),console.log("Opponent's round number: ",this.opponentsRound)),!1):!0}logFightBanner(){window.logging&&this.roundNumber===0&&console.log(`%c${this.myCharacter.name} vs. ${this.opponentsCharacter.name}`,"font-weight: bold; color: green;")}getOpponentsMove(){try{this.Multiplayer.getMove(e=>{if(!e||!e.move||!e.move.id)throw new Error("Invalid move data received");this.rounds[this.roundNumber]||(this.rounds[this.roundNumber]={});let o=this.opponentsCharacter.moves.find(r=>r.id===e.move.id),t=new CustomEvent("opponentsMove",{detail:o});document.dispatchEvent(t),this.rounds[this.roundNumber].opponentsMove=o,this.setUp()})}catch(e){console.error("Error in getOpponentsMove:",e)}}getOpponentsName(){try{this.Multiplayer.getName(e=>{if(!e||!e.name)throw new Error("Invalid name data received");window.logging&&console.log("Received name: ",e.name),this.opponentsCharacter.name=e.name;let o=new CustomEvent("name");document.dispatchEvent(o)})}catch(e){console.error("Error in getOpponentsName:",e)}}takeDamage(e,o){this.loaded||o.score!==""&&o.totalScore>0&&(e.health-=o.totalScore),o.result.weaponDislodged&&(e.weapon=!1),o.result.retrieveWeapon&&(e.weapon=!0),o.result.shieldDestroyed&&(e.shield=!1)}logRoundDetails(e,o){if(console.group(`%c${e.myCharacter.name}`,"font-weight: bold; color: blue;"),console.log(`%c\u2764\uFE0F Health: %c${e.myCharacter.health}`,"font-weight: bold","color: red;"),console.log(`%c\u{1F5E1}\uFE0F Weapon: %c${e.myCharacter.weapon?"Yes":"No"}`,"font-weight: bold","color: black;"),console.log(`%c\u{1F6E1}\uFE0F Shield: %c${e.myCharacter.shield?"Yes":"No"}`,"font-weight: bold","color: black;"),console.log(`%c\u2694\uFE0F Move: %c${e.myMove.tag} ${e.myMove.name}, %c(${e.myMove.id})`,"font-weight: bold","color: brown;","color: black;"),e.nextRoundBonus){console.group("%cBonus next round:","font-weight: bold; color: purple;");for(let t in e.nextRoundBonus[0])console.log(`%c${t}: %c${e.nextRoundBonus[0][t]}`,"font-weight: bold","color: green;");console.groupEnd()}e.score!==""&&e.totalScore>0&&console.log(`%c\u{1F3AF} Score: %c${e.totalScore} (Hit for: ${e.score}, Move modifier: ${e.moveModifier}, Bonus from previous round: ${e.bonus})`,"font-weight: bold","color: green;"),o.score!==""&&o.totalScore>0&&console.log(`%c\u{1F4A5} You were hit: ${o.totalScore}`,"font-weight: bold; color: red;"),console.log(`%c\u{1F440} You see your opponent: %c${e.result.name}`,"font-weight: bold","color: orange;"),e.restrictions.length===1?console.log(`%c\u{1F6AB} Opponent's restrictions next turn: %c${e.restrictions[0]}`,"font-weight: bold","color: purple;"):e.restrictions.length>1?console.log(`%c\u{1F6AB} Opponent's restrictions next turn: %c${e.restrictions.join(", ")}`,"font-weight: bold","color: purple;"):console.log("%c\u{1F6AB} Opponent's restrictions next turn: %cNone","font-weight: bold","color: purple;"),console.groupEnd()}checkForDefeat(){let e=new CustomEvent("victory"),o=new CustomEvent("defeat");if(this.myCharacter.health<=0){console.log(`${this.myCharacter.name} (you) is defeated!`),document.dispatchEvent(o);return}if(this.opponentsCharacter.health<=0){console.log(`${this.opponentsCharacter.name} (your opponent) is defeated!`),document.dispatchEvent(e);return}}incrementRound(){this.roundNumber++,this.opponentsRound++}};export{f as Game};