MCPcopy Create free account
hub / github.com/candybox2/candybox2.github.io / transferTo

Method transferTo

code/main/Resource.ts:48–66  ·  view source on GitHub ↗
(resource: Resource, howMany: number = -1, ratio: number = 1)

Source from the content-addressed store, hash-verified

46 }
47
48 public transferTo(resource: Resource, howMany: number = -1, ratio: number = 1): boolean{
49 // If howMany is below 0, then we transfer everything
50 if(howMany < 0)
51 howMany = this.current;
52 else{
53 // If we don't have enough to transfer, we return false
54 if(howMany > this.current)
55 return false;
56 }
57
58 // We lower our current quantity
59 this.add(-howMany);
60
61 // We add to the other resource
62 resource.add(howMany * ratio);
63
64 // We return true
65 return true;
66 }
67
68 // Public getters
69 public getAccumulated(): number{

Calls 2

addMethod · 0.95
addMethod · 0.65

Tested by

no test coverage detected