1
+ import { Logger } from "app/core/electron/logger.helper" ;
2
+
3
+ import { Mod } from "../mod" ;
4
+ import { HarvestBar } from "./harvestBar" ;
5
+
6
+ export class Harvest extends Mod {
7
+ private harvestBar : HarvestBar ;
8
+ private statedElements : Map < number , number > = new Map ( ) ;
9
+ private isInHarvest : boolean = false ;
10
+
11
+ startMod ( ) : void {
12
+ this . params = this . settings . option . vip . general ;
13
+
14
+ if ( this . params . _harvest_indicator ) {
15
+
16
+ Logger . info ( '- enable Harvest indicator' ) ;
17
+
18
+ const harvestCss = document . createElement ( 'style' ) ;
19
+ harvestCss . id = 'harvestCss' ;
20
+ harvestCss . innerHTML = `
21
+ .harvestBarContainer {
22
+ box-sizing: border-box;
23
+ border: 1px gray solid;
24
+ background-color: #222;
25
+ height: 6px;
26
+ width: 80px;
27
+ position: absolute;
28
+ border-radius: 3px;
29
+ overflow: hidden;
30
+ transition-duration: 500ms;
31
+ margin-top: 10px;
32
+ }
33
+ .harvestBar {
34
+ transition-duration: 300ms;
35
+ height: 100%;
36
+ width: 100%;
37
+ background-color: orange;
38
+ }
39
+ .harvestTimeText {
40
+ font-size: 11px;
41
+ font-weight: bold;
42
+ text-align: center;
43
+ position: absolute;
44
+ width: 80px;
45
+ color: white;
46
+ text-shadow: 0px 0px 5px rgba(0, 0, 0, 0.9);
47
+ transition-duration: 500ms;
48
+ margin-top: 4px;
49
+ }` ;
50
+ this . wGame . document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( harvestCss ) ;
51
+
52
+ this . harvestBar = new HarvestBar ( this . wGame ) ;
53
+
54
+ this . removeOnFinish ( ) ;
55
+ this . displayOnStart ( ) ;
56
+ this . setHarvestStart ( ) ;
57
+ }
58
+ }
59
+
60
+ private setHarvestStart ( ) : void {
61
+ this . on ( this . wGame . dofus . connectionManager , 'StatedElementUpdatedMessage' , ( e : any ) => {
62
+ try {
63
+ this . statedElements . set ( e . statedElement . elementId , e . statedElement . elementCellId ) ;
64
+ } catch ( ex ) {
65
+ Logger . info ( ex ) ;
66
+ }
67
+ } ) ;
68
+ }
69
+
70
+ private displayOnStart ( ) : void {
71
+ this . on ( this . wGame . dofus . connectionManager , 'InteractiveUsedMessage' , ( e : any ) => {
72
+ try {
73
+ if ( this . statedElements . has ( e . elemId ) && e . entityId == this . wGame . isoEngine . actorManager . userId ) {
74
+ this . harvestBar . harvestStarted ( this . statedElements . get ( e . elemId ) , e . duration ) ;
75
+ this . isInHarvest = true ;
76
+ this . statedElements . clear ( ) ;
77
+ }
78
+ } catch ( ex ) {
79
+ Logger . info ( ex ) ;
80
+ }
81
+ } ) ;
82
+ }
83
+
84
+ private removeOnFinish ( ) : void {
85
+ this . on ( this . wGame . dofus . connectionManager , 'InteractiveUseEndedMessage' , ( e : any ) => {
86
+ try {
87
+ this . isInHarvest = ! ( this . harvestBar . destroy ( ) ) ;
88
+ } catch ( ex ) {
89
+ Logger . info ( ex ) ;
90
+ }
91
+ } ) ;
92
+ }
93
+
94
+
95
+ public reset ( ) {
96
+ super . reset ( ) ;
97
+ if ( this . params . harvest_indicator ) {
98
+ if ( this . harvestBar ) this . harvestBar . destroy ( ) ;
99
+ const bar = this . wGame . document . getElementById ( 'harvestBarContainer' ) ;
100
+ if ( bar ) bar . remove ( ) ;
101
+ const time = this . wGame . document . getElementById ( 'harvestTime' ) ;
102
+ if ( time ) time . remove ( ) ;
103
+ const harvestCss = this . wGame . document . getElementById ( 'harvestCss' ) ;
104
+ if ( harvestCss && harvestCss . parentElement ) harvestCss . parentElement . removeChild ( harvestCss ) ;
105
+ }
106
+ }
107
+
108
+ }
0 commit comments