View Javadoc

1   // %368918737:hoplugins.transfers.vo%
2   package hoplugins.transfers.vo;
3   
4   import hoplugins.Commons;
5   
6   import hoplugins.transfers.constants.TransferTypes;
7   import hoplugins.transfers.dao.PlayerMatchesDAO;
8   import hoplugins.transfers.dao.TransferTypeDAO;
9   
10  import plugins.ISpieler;
11  
12  
13  /***
14   * Transferred Player value object
15   *
16   * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
17   */
18  public class TransferredPlayer {
19      //~ Instance fields ----------------------------------------------------------------------------
20  
21      private String playerName;
22      private boolean bought = false;
23      private boolean sold = false;
24      private double officialMatch = 0;
25      private int age = 17;
26      private int endWeek = 0;
27      private int experience = 0;
28      private int experienceSkillups = 0;
29      private int id = 0;
30      private int income;
31      private int leadership = 0;
32      private int skillups = 0;
33      private int startWeek;
34  
35      //~ Constructors -------------------------------------------------------------------------------
36  
37      /***
38       * Creates a new TransferredPlayer object.
39       *
40       * @param player PlayerId of the Transferred Player
41       */
42      public TransferredPlayer(ISpieler player) {
43          age = player.getAlter();
44          id = player.getSpielerID();
45          experience = player.getErfahrung();
46          leadership = player.getFuehrung();
47          playerName = player.getName();
48          skillups += player.getAllLevelUp(ISpieler.SKILL_TORWART).size();
49          skillups += player.getAllLevelUp(ISpieler.SKILL_SPIELAUFBAU).size();
50          skillups += player.getAllLevelUp(ISpieler.SKILL_PASSSPIEL).size();
51          skillups += player.getAllLevelUp(ISpieler.SKILL_FLUEGEL).size();
52          skillups += player.getAllLevelUp(ISpieler.SKILL_VERTEIDIGUNG).size();
53          skillups += player.getAllLevelUp(ISpieler.SKILL_TORSCHUSS).size();
54          skillups += player.getAllLevelUp(ISpieler.SKILL_STANDARDS).size();
55  
56          //player.getAllLevelUp(ISpieler.SKILL_KONDITION).size();
57          experienceSkillups = player.getAllLevelUp(ISpieler.SKILL_EXPIERIENCE).size();
58          officialMatch = PlayerMatchesDAO.getAppearance(player.getSpielerID(), true);
59  
60          //testMatch = PlayerMatchesDAO.getAppearance(player.getSpielerID(), false);
61          endWeek = Commons.getModel().getBasics().getSpieltag()
62                    + (Commons.getModel().getBasics().getSeason() * 16);
63      }
64  
65      /***
66       * Creates a new TransferredPlayer object.
67       *
68       * @param pt Player Transfer to Analyze
69       */
70      public TransferredPlayer(PlayerTransfer pt) {
71          id = pt.getPlayerId();
72          playerName = pt.getPlayerName();
73          age = 17;
74      }
75  
76      //~ Methods ------------------------------------------------------------------------------------
77  
78      /***
79       * Returns the Net Income of the Transfer
80       *
81       * @return income in euro
82       */
83      public final int getIncome() {
84          return income;
85      }
86  
87      /***
88       * Return the Id of the player
89       *
90       * @return id
91       */
92      public final int getPlayerId() {
93          return this.id;
94      }
95  
96      /***
97       * Return the name of the player
98       *
99       * @return Name
100      */
101     public final String getPlayerName() {
102         return playerName;
103     }
104 
105     /***
106      * Returns the Transfer Type
107      *
108      * @return transfer type code
109      */
110     public final int getTransferType() {
111         int type = TransferTypeDAO.getType(id);
112 
113         if (type > -2) {
114             return type;
115         }
116 
117         if (bought && !sold) {
118             return getActualPlayerType();
119         }
120 
121         if (!bought && sold) {
122             return getTeamPlayerType();
123         }
124 
125         return getOldPlayerType();
126     }
127 
128     /***
129      * Add a transfer for the specified player
130      *
131      * @param transfer The Transfer Detail
132      */
133     public final void addTransfer(PlayerTransfer transfer) {
134         if (transfer.getPlayerId() != id) {
135             return;
136         }
137 
138         final int teamid = Commons.getModel().getBasics().getTeamId();
139 
140         // Fix for RE-Bought players
141         if ((transfer.getBuyerid() == teamid) && (transfer.getSellerid() == teamid)) {
142             return;
143         }
144 
145         if (transfer.getBuyerid() == teamid) {
146             bought = true;
147             income -= transfer.getPrice();
148             startWeek = transfer.getWeek() + (transfer.getSeason() * 16);
149             return;
150         }
151 
152         if (transfer.getSellerid() == teamid) {
153             sold = true;
154             income += transfer.getPrice();
155             endWeek = transfer.getWeek() + (transfer.getSeason() * 16);
156             return;
157         }
158     }
159 
160     /***
161      * Method that calculates the Transfer Type for players still on roster
162      *
163      * @return transfer type code
164      */
165     private int getActualPlayerType() {
166         if (skillups > 0) {
167             return TransferTypes.TRAINED_ROSTER;
168         }
169 
170         if (isStarter()) {
171             return TransferTypes.STARTER_ROSTER;
172         }
173 
174         return TransferTypes.BACKUP_ROSTER;
175     }
176 
177     /***
178      * Method that calculates the Transfer Type for old players
179      *
180      * @return transfer type code
181      */
182     private int getOldPlayerType() {
183         if ((getWeekOnRoster() <= 3) && (skillups == 0)) {
184             return TransferTypes.DAY_TRADING;
185         }
186 
187         if ((getWeekOnRoster() <= 6) && (skillups == 1)) {
188             return TransferTypes.SKILL_TRADING;
189         }
190 
191         if ((experienceSkillups > 0) && (experience >= 5) && (leadership >= 5)) {
192             return TransferTypes.FUTURE_TRAINER;
193         }
194 
195         if (skillups == 0) {
196             if (isStarter()) {
197                 return TransferTypes.OLD_STARTER;
198             }
199 
200             return TransferTypes.OLD_BACKUP;
201         }
202 
203         return TransferTypes.OLD_TRAINED;
204     }
205 
206     /***
207      * Method the returns the type of player, starter or backup based on the number of matches and
208      * the time on roster
209      *
210      * @return true if player is a starter, false if a backup
211      */
212     private boolean isStarter() {
213         final double ratio = officialMatch / (getWeekOnRoster() + 1);
214 
215         if (ratio > 0.35) {
216             return true;
217         }
218 
219         return false;
220     }
221 
222     /***
223      * Method that calculates the Transfer Type for players sold but never bought
224      *
225      * @return transfer type code
226      */
227     private int getTeamPlayerType() {
228         if (age > 20) {
229             return TransferTypes.ORIGINAL_ROSTER;
230         }
231 
232         return TransferTypes.YOUTH_PULL;
233     }
234 
235     /***
236      * Gets the weeks the player was/is on roster
237      *
238      * @return Amount of weeks on roster
239      */
240     private int getWeekOnRoster() {
241         return endWeek - startWeek;
242     }
243 }