import { LocationId , Planet } from "@darkforest_eth/types" ; import GameManager from "@df_client/src/Backend/GameLogic/GameManager" ; import { getPlanetName } from "./utils" ; import { Context } from "./handler" ; import { html } from "htm/preact" ; import { VNode } from "preact" ; declare const df ; export interface HandlerAction { readonly continue : boolean ; readonly progress : number ; readonly planet : Planet ; execute ( df , context ) : void ; getMessage ( ) : VNode ; } export class NoAction implements HandlerAction { readonly progress = 0 ; readonly continue = true ; readonly planet : Planet ; constructor ( planet ) { this . planet = planet ; } execute ( df , context ) { } getMessage ( ) { return html `Nothing to do.` ; } } export class Wait implements HandlerAction { readonly continue = false ; readonly progress : number ; readonly action : HandlerAction ; constructor ( progress , action ) { this . progress = progress ; this . action = action ; } get planet ( ) { return this . action . planet ; } execute ( df , context ) { } getMessage ( ) { return html `${ Math . floor ( this . progress * 100 ) }% ${ this . action . getMessage ( ) }` ; } } export class ProspectPlanet implements HandlerAction { readonly progress = 1.0 ; readonly continue = false ; readonly planet : Planet ; constructor ( planet ) { this . planet = planet ; } execute ( df , context ) { df . prospectPlanet ( this . planet . locationId ) ; } getMessage ( ) { return html `Prospecting` ; } } export class FindArtifact implements HandlerAction { readonly progress = 1.0 ; readonly continue = false ; readonly planet : Planet ; constructor ( planet ) { this . planet = planet ; } execute ( df , context ) { df . findArtifact ( this . planet . locationId ) ; return false ; } getMessage ( ) { return html `Finding Artifact` ; } } export class Upgrade implements HandlerAction { readonly progress = 1.0 ; readonly continue = false ; readonly planet : Planet ; readonly branch : number ; constructor ( planet , branch ) { this . planet = planet ; this . branch = branch ; } execute ( df , context ) { df . upgrade ( this . planet . locationId , this . branch ) ; return false ; } getMessage ( ) { return html `Upgrading` ; } } export class Move implements HandlerAction { readonly progress = 1.0 ; readonly continue = false ; readonly planet : Planet ; readonly to : Planet ; readonly sendEnergy : number ; readonly sendSilver : number ; constructor ( planet , to , sendEnergy , sendSilver ) { this . planet = planet ; this . to = to ; this . sendEnergy = sendEnergy ; this . sendSilver = sendSilver ; } execute ( df , context ) { const { planet , to , sendEnergy , sendSilver } = this ; const energyArriving = Math . floor ( df . getEnergyArrivingForMove ( planet . locationId , to . locationId , undefined , sendEnergy ) ) ; context . updateIncoming ( to . locationId , planet . owner , energyArriving , sendSilver ) ; df . move ( planet . locationId , to . locationId , Math . floor ( sendEnergy ) , Math . floor ( sendSilver ) ) ; return false ; } getMessage ( ) { const { planet , to , sendEnergy , sendSilver } = this ; const energyArriving = Math . floor ( df . getEnergyArrivingForMove ( planet . locationId , to . locationId , undefined , sendEnergy ) ) ; if ( this . planet . owner == this . to . owner ) { if ( this . sendSilver > 0 ) { return html `Sending silver to ${ getPlanetName ( to ) }` ; } else { return html `Sending energy to ${ getPlanetName ( to ) }` ; } } else { return html `Attacking ${ getPlanetName ( to ) }` ; } } }