mirror of
https://github.com/magefree/mage.git
synced 2025-12-30 07:22:03 -08:00
Moved Mage.Common classes from src to src/main/java
This commit is contained in:
parent
e9d31aa93c
commit
21eb420c16
102 changed files with 0 additions and 0 deletions
28
Mage.Common/src/main/java/mage/cards/CardBorder.java
Normal file
28
Mage.Common/src/main/java/mage/cards/CardBorder.java
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
package mage.cards;
|
||||
|
||||
/**
|
||||
* @author stravant@gmail.com
|
||||
*
|
||||
* Enum listing the possible card faces for a card
|
||||
*
|
||||
* Because of Time Spiral block's shifted cards it is
|
||||
* not sufficient to just look at a card's edition to
|
||||
* determine what the card face should be.
|
||||
*/
|
||||
public enum CardBorder {
|
||||
/* Old border card frames. ALPHA -> 8th ED */
|
||||
OLD,
|
||||
|
||||
/* Future Sight frames. FUT futureshifted */
|
||||
FUT,
|
||||
|
||||
/* Planar Chaos frames. PLC planeshifted */
|
||||
PLC,
|
||||
|
||||
/* Modern card frames. 8th ED -> M15 */
|
||||
MOD,
|
||||
|
||||
/* New border cards, M15 -> current */
|
||||
M15
|
||||
}
|
||||
68
Mage.Common/src/main/java/mage/cards/CardDimensions.java
Normal file
68
Mage.Common/src/main/java/mage/cards/CardDimensions.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.cards;
|
||||
|
||||
import static mage.constants.Constants.*;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CardDimensions {
|
||||
|
||||
public int frameHeight;
|
||||
public int frameWidth;
|
||||
public int symbolHeight;
|
||||
public int symbolWidth;
|
||||
public int contentXOffset;
|
||||
public int nameYOffset;
|
||||
public int typeYOffset;
|
||||
public int textYOffset;
|
||||
public int textWidth;
|
||||
public int textHeight;
|
||||
public int powBoxTextTop;
|
||||
public int powBoxTextLeft;
|
||||
public int nameFontSize;
|
||||
|
||||
public CardDimensions(double scaleFactor) {
|
||||
frameHeight = (int) (FRAME_MAX_HEIGHT * scaleFactor);
|
||||
frameWidth = (int) (FRAME_MAX_WIDTH * scaleFactor);
|
||||
symbolHeight = (int) (SYMBOL_MAX_HEIGHT * scaleFactor);
|
||||
symbolWidth = (int) (SYMBOL_MAX_WIDTH * scaleFactor);
|
||||
contentXOffset = (int) (CONTENT_MAX_XOFFSET * scaleFactor);
|
||||
nameYOffset = (int) (NAME_MAX_YOFFSET * scaleFactor);
|
||||
typeYOffset = (int) (TYPE_MAX_YOFFSET * scaleFactor);
|
||||
textYOffset = (int) (TEXT_MAX_YOFFSET * scaleFactor);
|
||||
textWidth = (int) (TEXT_MAX_WIDTH * scaleFactor);
|
||||
textHeight = (int) (TEXT_MAX_HEIGHT * scaleFactor);
|
||||
powBoxTextTop = (int) (POWBOX_TEXT_MAX_TOP * scaleFactor);
|
||||
powBoxTextLeft = (int) (POWBOX_TEXT_MAX_LEFT * scaleFactor);
|
||||
nameFontSize = Math.max(9, (int) (NAME_FONT_MAX_SIZE * scaleFactor));
|
||||
}
|
||||
|
||||
}
|
||||
61
Mage.Common/src/main/java/mage/cards/MageCard.java
Normal file
61
Mage.Common/src/main/java/mage/cards/MageCard.java
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package mage.cards;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.util.UUID;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import mage.cards.action.ActionCallback;
|
||||
import mage.view.CardView;
|
||||
|
||||
public abstract class MageCard extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 6089945326434301879L;
|
||||
|
||||
public abstract void onBeginAnimation();
|
||||
|
||||
public abstract void onEndAnimation();
|
||||
|
||||
public abstract boolean isTapped();
|
||||
|
||||
public abstract boolean isFlipped();
|
||||
|
||||
public abstract void setAlpha(float transparency);
|
||||
|
||||
public abstract float getAlpha();
|
||||
|
||||
public abstract CardView getOriginal();
|
||||
|
||||
// sets the vertical text offset for the card name on the image
|
||||
public abstract void setTextOffset(int yOffset);
|
||||
|
||||
public abstract void setCardBounds(int x, int y, int width, int height);
|
||||
|
||||
public abstract void update(CardView card);
|
||||
|
||||
public abstract void updateArtImage();
|
||||
|
||||
public abstract Image getImage();
|
||||
|
||||
public abstract void setZone(String zone);
|
||||
|
||||
public abstract String getZone();
|
||||
|
||||
public abstract void updateCallback(ActionCallback callback, UUID gameId);
|
||||
|
||||
public abstract void toggleTransformed();
|
||||
|
||||
public abstract boolean isTransformed();
|
||||
|
||||
public abstract void showCardTitle();
|
||||
|
||||
public abstract void setSelected(boolean selected);
|
||||
|
||||
public abstract void setCardAreaRef(JPanel cardArea);
|
||||
|
||||
public abstract void setChoosable(boolean isChoosable);
|
||||
|
||||
public abstract void setPopupMenu(JPopupMenu popupMenu);
|
||||
|
||||
public abstract JPopupMenu getPopupMenu();
|
||||
|
||||
}
|
||||
13
Mage.Common/src/main/java/mage/cards/MagePermanent.java
Normal file
13
Mage.Common/src/main/java/mage/cards/MagePermanent.java
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package mage.cards;
|
||||
|
||||
import mage.view.PermanentView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MagePermanent extends MageCard {
|
||||
private static final long serialVersionUID = -3469258620601702171L;
|
||||
public abstract List<MagePermanent> getLinks();
|
||||
public abstract void update(PermanentView card);
|
||||
public abstract PermanentView getOriginalPermanent();
|
||||
|
||||
}
|
||||
49
Mage.Common/src/main/java/mage/cards/TextPopup.form
Normal file
49
Mage.Common/src/main/java/mage/cards/TextPopup.form
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
|
||||
<LineBorder/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,0,24,0,0,1,37"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTextArea" name="popupText">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="cc" green="cc" red="cc" type="rgb"/>
|
||||
</Property>
|
||||
<Property name="columns" type="int" value="20"/>
|
||||
<Property name="editable" type="boolean" value="false"/>
|
||||
<Property name="lineWrap" type="boolean" value="true"/>
|
||||
<Property name="rows" type="int" value="1"/>
|
||||
<Property name="wrapStyleWord" type="boolean" value="true"/>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
|
||||
<EmptyBorder bottom="2" left="2" right="2" top="2"/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="First"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
93
Mage.Common/src/main/java/mage/cards/TextPopup.java
Normal file
93
Mage.Common/src/main/java/mage/cards/TextPopup.java
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
/*
|
||||
* TextPopup.java
|
||||
*
|
||||
* Created on Apr 6, 2010, 9:36:13 AM
|
||||
*/
|
||||
|
||||
package mage.cards;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TextPopup extends javax.swing.JPanel {
|
||||
private String text;
|
||||
private boolean needsUpdate;
|
||||
|
||||
/** Creates new form TextPopup */
|
||||
public TextPopup() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
if(!text.equals(this.text)) {
|
||||
this.text = text;
|
||||
this.needsUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateText() {
|
||||
if(this.needsUpdate) {
|
||||
popupText.setText(this.text);
|
||||
this.needsUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
popupText = new javax.swing.JTextArea();
|
||||
|
||||
setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
|
||||
setLayout(new java.awt.BorderLayout());
|
||||
|
||||
popupText.setBackground(new java.awt.Color(204, 204, 204));
|
||||
popupText.setColumns(20);
|
||||
popupText.setEditable(false);
|
||||
popupText.setLineWrap(true);
|
||||
popupText.setRows(1);
|
||||
popupText.setWrapStyleWord(true);
|
||||
popupText.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 2, 2, 2));
|
||||
add(popupText, java.awt.BorderLayout.PAGE_START);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JTextArea popupText;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package mage.cards.action;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
|
||||
public interface ActionCallback {
|
||||
|
||||
void mouseClicked(MouseEvent e, TransferData data);
|
||||
|
||||
void mousePressed(MouseEvent e, TransferData data);
|
||||
|
||||
void mouseReleased(MouseEvent e, TransferData data);
|
||||
|
||||
void mouseMoved(MouseEvent e, TransferData data);
|
||||
|
||||
void mouseDragged(MouseEvent e, TransferData data);
|
||||
|
||||
void mouseEntered(MouseEvent e, TransferData data);
|
||||
|
||||
void mouseExited(MouseEvent e, TransferData data);
|
||||
|
||||
void mouseWheelMoved(MouseWheelEvent e, TransferData data);
|
||||
|
||||
void hideOpenComponents();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package mage.cards.action;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
import java.util.UUID;
|
||||
import mage.cards.TextPopup;
|
||||
import mage.view.CardView;
|
||||
|
||||
public class TransferData {
|
||||
public Component component;
|
||||
public TextPopup popupText;
|
||||
public Point locationOnScreen;
|
||||
public int popupOffsetX;
|
||||
public int popupOffsetY;
|
||||
public UUID gameId;
|
||||
public CardView card;
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package mage.cards.action.impl;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import mage.cards.action.ActionCallback;
|
||||
import mage.cards.action.TransferData;
|
||||
|
||||
/**
|
||||
* Callback that does nothing on any action
|
||||
*
|
||||
* @author nantuko84
|
||||
*/
|
||||
public class EmptyCallback implements ActionCallback {
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e, TransferData data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e, TransferData data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e, TransferData data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e, TransferData data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent e, TransferData data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideOpenComponents() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e, TransferData data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e, TransferData data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e, TransferData data) {
|
||||
}
|
||||
|
||||
}
|
||||
17
Mage.Common/src/main/java/mage/components/CardInfoPane.java
Normal file
17
Mage.Common/src/main/java/mage/components/CardInfoPane.java
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package mage.components;
|
||||
|
||||
import mage.view.CardView;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Card info pane for displaying card rules.
|
||||
* Supports drawing mana symbols.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public interface CardInfoPane {
|
||||
|
||||
void setCard(CardView card, Component container);
|
||||
boolean isCurrentCard (CardView card);
|
||||
}
|
||||
97
Mage.Common/src/main/java/mage/components/ImagePanel.java
Normal file
97
Mage.Common/src/main/java/mage/components/ImagePanel.java
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
package mage.components;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JViewport;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ImagePanel extends JPanel {
|
||||
|
||||
|
||||
private BufferedImage image;
|
||||
private ImagePanelStyle style;
|
||||
private float alignmentX = 0.5f;
|
||||
private float alignmentY = 0.5f;
|
||||
|
||||
public ImagePanel(BufferedImage image) {
|
||||
this(image, ImagePanelStyle.TILED);
|
||||
}
|
||||
|
||||
public ImagePanel(BufferedImage image, ImagePanelStyle style) {
|
||||
this.image = image;
|
||||
this.style = style;
|
||||
setLayout(new BorderLayout());
|
||||
}
|
||||
|
||||
public void setImageAlignmentX(float alignmentX) {
|
||||
this.alignmentX = alignmentX > 1.0f ? 1.0f : alignmentX < 0.0f ? 0.0f : alignmentX;
|
||||
}
|
||||
|
||||
public void setImageAlignmentY(float alignmentY) {
|
||||
this.alignmentY = alignmentY > 1.0f ? 1.0f : alignmentY < 0.0f ? 0.0f : alignmentY;
|
||||
|
||||
}
|
||||
|
||||
public void add(JComponent component) {
|
||||
add(component, null);
|
||||
}
|
||||
|
||||
public void add(JComponent component, Object constraints) {
|
||||
component.setOpaque(false);
|
||||
|
||||
if (component instanceof JScrollPane) {
|
||||
JScrollPane scrollPane = (JScrollPane) component;
|
||||
JViewport viewport = scrollPane.getViewport();
|
||||
viewport.setOpaque(false);
|
||||
Component c = viewport.getView();
|
||||
|
||||
if (c instanceof JComponent) {
|
||||
((JComponent) c).setOpaque(false);
|
||||
}
|
||||
}
|
||||
|
||||
super.add(component, constraints);
|
||||
}
|
||||
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
if (image == null)
|
||||
return;
|
||||
|
||||
switch (style) {
|
||||
case TILED:
|
||||
drawTiled(g);
|
||||
break;
|
||||
case SCALED:
|
||||
Dimension d = getSize();
|
||||
g.drawImage(image, 0, 0, d.width, d.height, null);
|
||||
break;
|
||||
case ACTUAL:
|
||||
drawActual(g);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void drawTiled(Graphics g) {
|
||||
Dimension d = getSize();
|
||||
int width = image.getWidth(null);
|
||||
int height = image.getHeight(null);
|
||||
|
||||
for (int x = 0; x < d.width; x += width) {
|
||||
for (int y = 0; y < d.height; y += height) {
|
||||
g.drawImage(image, x, y, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawActual(Graphics g) {
|
||||
Dimension d = getSize();
|
||||
float x = (d.width - image.getWidth(null)) * alignmentX;
|
||||
float y = (d.height - image.getHeight(null)) * alignmentY;
|
||||
g.drawImage(image, (int) x, (int) y, this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package mage.components;
|
||||
|
||||
/**
|
||||
* Created by IGOUDT on 7-3-2017.
|
||||
*/
|
||||
public enum ImagePanelStyle {
|
||||
TILED, SCALED, ACTUAL
|
||||
}
|
||||
94
Mage.Common/src/main/java/mage/constants/Constants.java
Normal file
94
Mage.Common/src/main/java/mage/constants/Constants.java
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.constants;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public final class Constants {
|
||||
|
||||
private Constants() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final int FRAME_MAX_HEIGHT = 367;
|
||||
public static final int FRAME_MAX_WIDTH = 256;
|
||||
public static final int ART_MAX_HEIGHT = 168;
|
||||
public static final int ART_MAX_WIDTH = 227;
|
||||
public static final int SYMBOL_MAX_HEIGHT = 14;
|
||||
public static final int SYMBOL_MAX_WIDTH = 14;
|
||||
public static final int SYMBOL_MAX_XOFFSET = 27;
|
||||
public static final int SYMBOL_MAX_YOFFSET = 15;
|
||||
public static final int SYMBOL_MAX_SPACE = 14;
|
||||
public static final int CONTENT_MAX_XOFFSET = 15;
|
||||
public static final int ART_MAX_YOFFSET = 37;
|
||||
public static final int NAME_MAX_YOFFSET = 28;
|
||||
public static final int TYPE_MAX_YOFFSET = 223;
|
||||
public static final int ICON_MAX_HEIGHT = 16;
|
||||
public static final int ICON_MAX_WIDTH = 16;
|
||||
public static final int ICON_MAX_XOFFSET = 238;
|
||||
public static final int ICON_MAX_YOFFSET = 210;
|
||||
public static final int TEXT_MAX_YOFFSET = 232;
|
||||
public static final int TEXT_MAX_WIDTH = 227;
|
||||
public static final int TEXT_MAX_HEIGHT = 105;
|
||||
public static final int NAME_FONT_MAX_SIZE = 13;
|
||||
public static final int TEXT_FONT_MAX_SIZE = 11;
|
||||
public static final int POWBOX_MAX_TOP = 336;
|
||||
public static final int POWBOX_MAX_LEFT = 202;
|
||||
public static final int POWBOX_TEXT_MAX_TOP = 352;
|
||||
public static final int POWBOX_TEXT_MAX_LEFT = 212;
|
||||
public static final int DAMAGE_MAX_LEFT = 180;
|
||||
|
||||
public static final double SCALE_FACTOR = 0.5;
|
||||
|
||||
public static final int MIN_AVATAR_ID = 10;
|
||||
public static final int MAX_AVATAR_ID = 32;
|
||||
public static final int DEFAULT_AVATAR_ID = 10;
|
||||
|
||||
/**
|
||||
* Time each player has during the game to play using his\her priority.
|
||||
*/
|
||||
public static final int PRIORITY_TIME_SEC = 1200;
|
||||
|
||||
|
||||
|
||||
public enum Option {
|
||||
|
||||
;
|
||||
|
||||
public static final String POSSIBLE_ATTACKERS = "possibleAttackers";
|
||||
public static final String SPECIAL_BUTTON = "specialButton";
|
||||
// used to control automatic answers of optional effects
|
||||
public static final String ORIGINAL_ID = "originalId";
|
||||
public static final String SECOND_MESSAGE = "secondMessage";
|
||||
public static final String HINT_TEXT = "hintText";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
74
Mage.Common/src/main/java/mage/db/EntityManager.java
Normal file
74
Mage.Common/src/main/java/mage/db/EntityManager.java
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
package mage.db;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
import mage.db.model.Feedback;
|
||||
import mage.db.model.Log;
|
||||
import mage.utils.properties.PropertiesUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author noxx, North
|
||||
*/
|
||||
public enum EntityManager {
|
||||
|
||||
instance;
|
||||
|
||||
private Dao<Log, Object> logDao;
|
||||
private Dao<Feedback, Object> feedbackDao;
|
||||
|
||||
private EntityManager() {
|
||||
File file = new File("db");
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
try {
|
||||
ConnectionSource logConnectionSource = new JdbcConnectionSource(PropertiesUtil.getDBLogUrl());
|
||||
TableUtils.createTableIfNotExists(logConnectionSource, Log.class);
|
||||
logDao = DaoManager.createDao(logConnectionSource, Log.class);
|
||||
|
||||
ConnectionSource feedbackConnectionSource = new JdbcConnectionSource(PropertiesUtil.getDBFeedbackUrl());
|
||||
TableUtils.createTableIfNotExists(feedbackConnectionSource, Feedback.class);
|
||||
feedbackDao = DaoManager.createDao(feedbackConnectionSource, Feedback.class);
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void insertLog(String key, java.util.Date date, String... args) throws SQLException {
|
||||
Log logEntity = new Log(key, date);
|
||||
logEntity.setArguments(args);
|
||||
logDao.create(logEntity);
|
||||
}
|
||||
|
||||
public List<Log> getAllLogs() {
|
||||
List<Log> logs = new ArrayList<>();
|
||||
try {
|
||||
logs = logDao.queryForAll();
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
|
||||
return logs;
|
||||
}
|
||||
|
||||
public void insertFeedback(String username, String title, String type, String message, String email, String host, java.util.Date created) throws SQLException {
|
||||
Feedback feedback = new Feedback(username, title, type, message, email, host, created, "new");
|
||||
feedbackDao.create(feedback);
|
||||
}
|
||||
|
||||
public List<Feedback> getAllFeedbacks() {
|
||||
List<Feedback> feedbacks = new ArrayList<>();
|
||||
try {
|
||||
feedbacks = feedbackDao.queryForAll();
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return feedbacks;
|
||||
}
|
||||
}
|
||||
46
Mage.Common/src/main/java/mage/db/EntityManagerTest.java
Normal file
46
Mage.Common/src/main/java/mage/db/EntityManagerTest.java
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package mage.db;
|
||||
|
||||
import mage.db.model.Feedback;
|
||||
import mage.db.model.Log;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public final class EntityManagerTest {
|
||||
|
||||
private static DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.FULL);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
List<Log> logs = EntityManager.instance.getAllLogs();
|
||||
System.out.println("logs found: " + logs.size());
|
||||
for (Log log : logs) {
|
||||
System.out.println(" key=" + log.getKey());
|
||||
System.out.println(" date=" + timeFormatter.format(log.getCreatedDate()));
|
||||
System.out.print(" arguments=[ ");
|
||||
if (log.getArguments() != null) {
|
||||
for (String argument : log.getArguments()) {
|
||||
System.out.print("arg=" + argument + ' ');
|
||||
}
|
||||
}
|
||||
System.out.println("]");
|
||||
System.out.println(" --------------");
|
||||
}
|
||||
|
||||
System.out.println("********************************");
|
||||
|
||||
List<Feedback> feedbackList = EntityManager.instance.getAllFeedbacks();
|
||||
System.out.println("feedbacks found: " + feedbackList.size());
|
||||
int count = 1;
|
||||
for (Feedback feedback : feedbackList) {
|
||||
System.out.println(count + ". " + feedback.toString());
|
||||
System.out.println("message=" + feedback.getMessage());
|
||||
System.out.println("mail=" + feedback.getEmail());
|
||||
System.out.println("--------------");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
113
Mage.Common/src/main/java/mage/db/Statistics.java
Normal file
113
Mage.Common/src/main/java/mage/db/Statistics.java
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
package mage.db;
|
||||
|
||||
import mage.db.model.Log;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public final class Statistics {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
List<Log> logs = EntityManager.instance.getAllLogs();
|
||||
System.out.println("logs found: " + logs.size());
|
||||
|
||||
Map<String, Integer> nicknames = displayCommonNumbers(logs);
|
||||
List<Integer> games = displayTop3(nicknames);
|
||||
displayPlayedOnlyOnce(games);
|
||||
|
||||
System.out.println("Done");
|
||||
}
|
||||
|
||||
private static void displayPlayedOnlyOnce(List<Integer> games) {
|
||||
Integer oneGame = 0;
|
||||
for (Integer numberOfGames : games) {
|
||||
if (numberOfGames == 1) {
|
||||
oneGame++;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Number of players played only one game: " + oneGame);
|
||||
}
|
||||
|
||||
private static List<Integer> displayTop3(Map<String, Integer> nicknames) {
|
||||
Collection<Integer> values = nicknames.values();
|
||||
List<Integer> games = new ArrayList<>();
|
||||
games.addAll(values);
|
||||
Collections.sort(games, new Comparator<Integer>() {
|
||||
@Override
|
||||
public int compare(Integer i1, Integer i2) {
|
||||
return i2.compareTo(i1);
|
||||
}
|
||||
});
|
||||
|
||||
// Top-3
|
||||
List<Integer> numbersToFind = new ArrayList<>();
|
||||
for (Integer numberOfGames : games) {
|
||||
numbersToFind.add(numberOfGames);
|
||||
if (numbersToFind.size() == 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Map<Integer, String> players = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, Integer> entry : nicknames.entrySet()) {
|
||||
if (check(numbersToFind, entry.getValue())) {
|
||||
players.put(entry.getValue(), entry.getKey());
|
||||
}
|
||||
if (players.size() == 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Top-3");
|
||||
for (Map.Entry<Integer, String> entry : players.entrySet()) {
|
||||
System.out.println(" " + entry.getValue() + ": " + entry.getKey());
|
||||
}
|
||||
return games;
|
||||
}
|
||||
|
||||
private static Map<String, Integer> displayCommonNumbers(List<Log> logs) {
|
||||
int count = 0;
|
||||
Map<String, Integer> nicknames = new HashMap<>();
|
||||
for (Log log : logs) {
|
||||
if (log.getKey().equals("gameStarted")) {
|
||||
if (log.getArguments() != null) {
|
||||
int index = 0;
|
||||
for (String argument : log.getArguments()) {
|
||||
if (index > 0) {
|
||||
inc(nicknames, argument);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("********************************");
|
||||
System.out.println("Games played: " + count);
|
||||
System.out.println("Number of players: " + nicknames.size());
|
||||
return nicknames;
|
||||
}
|
||||
|
||||
public static void inc(Map<String, Integer> map, String player) {
|
||||
if (map.containsKey(player)) {
|
||||
Integer count = map.get(player);
|
||||
count++;
|
||||
map.put(player, count);
|
||||
} else {
|
||||
map.put(player, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean check(List<Integer> numbers, Integer value) {
|
||||
for (Integer number : numbers) {
|
||||
if (number.equals(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
122
Mage.Common/src/main/java/mage/db/model/Feedback.java
Normal file
122
Mage.Common/src/main/java/mage/db/model/Feedback.java
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
package mage.db.model;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author noxx, North
|
||||
*/
|
||||
@DatabaseTable(tableName = "feedbacks")
|
||||
public class Feedback {
|
||||
|
||||
@DatabaseField
|
||||
private String username;
|
||||
@DatabaseField
|
||||
private String title;
|
||||
@DatabaseField
|
||||
private String type;
|
||||
@DatabaseField
|
||||
private String message;
|
||||
@DatabaseField
|
||||
private String email;
|
||||
@DatabaseField
|
||||
private String host;
|
||||
@DatabaseField(columnName = "created_dt")
|
||||
private Date createdDate;
|
||||
|
||||
@DatabaseField
|
||||
private String status;
|
||||
|
||||
public Feedback() {
|
||||
}
|
||||
|
||||
public Feedback(String username, String title, String type, String message, String email, String host, Date createdDate, String status) {
|
||||
this.username = username;
|
||||
this.title = title;
|
||||
this.type = type;
|
||||
this.message = message;
|
||||
this.email = email;
|
||||
this.host = host;
|
||||
this.createdDate = createdDate;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Date getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(Date createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String msg = message != null && message.length() > 5 ? message.substring(0, 5) : message;
|
||||
sb.append("Feedback [username=").append(username)
|
||||
.append(", host=").append(host)
|
||||
.append(", title=").append(title)
|
||||
.append(", type=").append(type)
|
||||
.append(", message=").append(msg)
|
||||
.append("...]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
100
Mage.Common/src/main/java/mage/db/model/Log.java
Normal file
100
Mage.Common/src/main/java/mage/db/model/Log.java
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
package mage.db.model;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author noxx, North
|
||||
*/
|
||||
@DatabaseTable(tableName = "logs")
|
||||
public class Log {
|
||||
|
||||
@DatabaseField
|
||||
private String key;
|
||||
@DatabaseField(columnName = "created_dt")
|
||||
private Date createdDate;
|
||||
@DatabaseField
|
||||
private String arg0;
|
||||
@DatabaseField
|
||||
private String arg1;
|
||||
@DatabaseField
|
||||
private String arg2;
|
||||
@DatabaseField
|
||||
private String arg3;
|
||||
@DatabaseField
|
||||
private String arg4;
|
||||
@DatabaseField
|
||||
private String arg5;
|
||||
|
||||
public Log() {
|
||||
}
|
||||
|
||||
public Log(String key, Date createdDate) {
|
||||
this.key = key;
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public Date getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(Date createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public List<String> getArguments() {
|
||||
ArrayList<String> arguments = new ArrayList<>();
|
||||
if (arg0 != null) {
|
||||
arguments.add(arg0);
|
||||
}
|
||||
if (arg1 != null) {
|
||||
arguments.add(arg1);
|
||||
}
|
||||
if (arg2 != null) {
|
||||
arguments.add(arg2);
|
||||
}
|
||||
if (arg3 != null) {
|
||||
arguments.add(arg3);
|
||||
}
|
||||
if (arg4 != null) {
|
||||
arguments.add(arg4);
|
||||
}
|
||||
if (arg5 != null) {
|
||||
arguments.add(arg5);
|
||||
}
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public void setArguments(String... arguments) {
|
||||
if (arguments.length > 0) {
|
||||
arg0 = arguments[0];
|
||||
}
|
||||
if (arguments.length > 1) {
|
||||
arg1 = arguments[1];
|
||||
}
|
||||
if (arguments.length > 2) {
|
||||
arg2 = arguments[2];
|
||||
}
|
||||
if (arguments.length > 3) {
|
||||
arg3 = arguments[3];
|
||||
}
|
||||
if (arguments.length > 4) {
|
||||
arg4 = arguments[4];
|
||||
}
|
||||
if (arguments.length > 5) {
|
||||
arg5 = arguments[5];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package mage.filters;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.BufferedImageOp;
|
||||
import java.awt.image.ColorModel;
|
||||
|
||||
/**
|
||||
* Mage abstract class that implements single-input/single-output
|
||||
* operations performed on {@link java.awt.image.BufferedImage}.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public abstract class MageBufferedImageOp implements BufferedImageOp {
|
||||
|
||||
/**
|
||||
* Creates compatible image for @param src image.
|
||||
*/
|
||||
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dest) {
|
||||
if (dest == null) {
|
||||
dest = src.getColorModel();
|
||||
}
|
||||
return new BufferedImage(dest, dest.createCompatibleWritableRaster(src.getWidth(), src.getHeight()), dest.isAlphaPremultiplied(), null);
|
||||
}
|
||||
|
||||
public RenderingHints getRenderingHints() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Rectangle2D getBounds2D(BufferedImage src) {
|
||||
return new Rectangle(0, 0, src.getWidth(), src.getHeight());
|
||||
}
|
||||
|
||||
public Point2D getPoint2D(Point2D srcPt, Point2D destPt) {
|
||||
if (destPt == null) {
|
||||
destPt = new Point2D.Double();
|
||||
}
|
||||
destPt.setLocation(srcPt.getX(), srcPt.getY());
|
||||
return destPt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ARGB pixels from image. Solves the performance
|
||||
* issue of BufferedImage.getRGB method.
|
||||
*/
|
||||
public int[] getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
|
||||
int type = image.getType();
|
||||
if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) {
|
||||
return (int[]) image.getRaster().getDataElements(x, y, width, height, pixels);
|
||||
}
|
||||
return image.getRGB(x, y, width, height, pixels, 0, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ARGB pixels in image. Solves the performance
|
||||
* issue of BufferedImage.setRGB method.
|
||||
*/
|
||||
public void setRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
|
||||
int type = image.getType();
|
||||
if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) {
|
||||
image.getRaster().setDataElements(x, y, width, height, pixels);
|
||||
} else {
|
||||
image.setRGB(x, y, width, height, pixels, 0, width);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Mage.Common/src/main/java/mage/interfaces/Action.java
Normal file
18
Mage.Common/src/main/java/mage/interfaces/Action.java
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package mage.interfaces;
|
||||
|
||||
import mage.MageException;
|
||||
|
||||
/**
|
||||
* Light weight action interface.
|
||||
* For executing actions without any context.
|
||||
*
|
||||
* @author ayratn, noxx
|
||||
*/
|
||||
public interface Action {
|
||||
|
||||
/**
|
||||
* Executes action.
|
||||
* @throws mage.MageException
|
||||
*/
|
||||
void execute() throws MageException;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package mage.interfaces;
|
||||
|
||||
import mage.MageException;
|
||||
|
||||
/**
|
||||
* Light weight action interface.
|
||||
* For executing actions without any context.
|
||||
*
|
||||
* @param <T> Type to return as a result of execution.
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public interface ActionWithResult<T> {
|
||||
|
||||
/**
|
||||
* Executes and returns result.
|
||||
* @return
|
||||
*/
|
||||
T execute() throws MageException;
|
||||
|
||||
/**
|
||||
* Defines negative result specific for type <T>.
|
||||
* @return
|
||||
*/
|
||||
T negativeResult();
|
||||
}
|
||||
49
Mage.Common/src/main/java/mage/interfaces/MageClient.java
Normal file
49
Mage.Common/src/main/java/mage/interfaces/MageClient.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.interfaces;
|
||||
|
||||
import mage.interfaces.callback.CallbackClient;
|
||||
import mage.utils.MageVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface MageClient extends CallbackClient {
|
||||
|
||||
MageVersion getVersion();
|
||||
|
||||
void connected(String message);
|
||||
|
||||
void disconnected(boolean errorCall);
|
||||
|
||||
void showMessage(String message);
|
||||
|
||||
void showError(String message);
|
||||
|
||||
}
|
||||
217
Mage.Common/src/main/java/mage/interfaces/MageServer.java
Normal file
217
Mage.Common/src/main/java/mage/interfaces/MageServer.java
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.interfaces;
|
||||
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.constants.ManaType;
|
||||
import mage.constants.PlayerAction;
|
||||
import mage.game.GameException;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.players.PlayerType;
|
||||
import mage.players.net.UserData;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.view.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface MageServer {
|
||||
|
||||
// registers a user to the user DB.
|
||||
boolean registerUser(String sessionId, String userName, String password, String email) throws MageException;
|
||||
|
||||
boolean emailAuthToken(String sessionId, String email) throws MageException;
|
||||
|
||||
boolean resetPassword(String sessionId, String email, String authToken, String password) throws MageException;
|
||||
|
||||
boolean connectUser(String userName, String password, String sessionId, MageVersion version, String userIdStr) throws MageException;
|
||||
|
||||
boolean connectAdmin(String password, String sessionId, MageVersion version) throws MageException;
|
||||
|
||||
// update methods
|
||||
List<ExpansionInfo> getMissingExpansionData(List<String> codes);
|
||||
|
||||
List<CardInfo> getMissingCardsData(List<String> classNames);
|
||||
|
||||
// user methods
|
||||
boolean setUserData(String userName, String sessionId, UserData userData, String clientVersion, String userIdStr) throws MageException;
|
||||
|
||||
void sendFeedbackMessage(String sessionId, String username, String title, String type, String message, String email) throws MageException;
|
||||
|
||||
// server state methods
|
||||
ServerState getServerState() throws MageException;
|
||||
|
||||
List<RoomUsersView> getRoomUsers(UUID roomId) throws MageException;
|
||||
|
||||
List<MatchView> getFinishedMatches(UUID roomId) throws MageException;
|
||||
|
||||
Object getServerMessagesCompressed(String sessionId) throws MageException; // messages of the day
|
||||
|
||||
// ping - extends session
|
||||
boolean ping(String sessionId, String pingInfo) throws MageException;
|
||||
|
||||
//table methods
|
||||
TableView createTable(String sessionId, UUID roomId, MatchOptions matchOptions) throws MageException;
|
||||
|
||||
TableView createTournamentTable(String sessionId, UUID roomId, TournamentOptions tournamentOptions) throws MageException;
|
||||
|
||||
boolean joinTable(String sessionId, UUID roomId, UUID tableId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws MageException, GameException;
|
||||
|
||||
boolean joinTournamentTable(String sessionId, UUID roomId, UUID tableId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws MageException, GameException;
|
||||
|
||||
boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
|
||||
|
||||
void updateDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
|
||||
|
||||
boolean watchTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
boolean watchTournamentTable(String sessionId, UUID tableId) throws MageException;
|
||||
|
||||
boolean leaveTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
void swapSeats(String sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws MageException;
|
||||
|
||||
void removeTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
boolean isTableOwner(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
Optional<TableView> getTable(UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
List<TableView> getTables(UUID roomId) throws MageException;
|
||||
|
||||
//chat methods
|
||||
void sendChatMessage(UUID chatId, String userName, String message) throws MageException;
|
||||
|
||||
void joinChat(UUID chatId, String sessionId, String userName) throws MageException;
|
||||
|
||||
void leaveChat(UUID chatId, String sessionId) throws MageException;
|
||||
|
||||
Optional<UUID> getTableChatId(UUID tableId) throws MageException;
|
||||
|
||||
Optional<UUID> getGameChatId(UUID gameId) throws MageException;
|
||||
|
||||
Optional<UUID> getRoomChatId(UUID roomId) throws MageException;
|
||||
|
||||
Optional<UUID> getTournamentChatId(UUID tournamentId) throws MageException;
|
||||
|
||||
//room methods
|
||||
UUID getMainRoomId() throws MageException;
|
||||
|
||||
//game methods
|
||||
boolean startMatch(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
void joinGame(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void watchGame(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void stopWatching(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void sendPlayerUUID(UUID gameId, String sessionId, UUID data) throws MageException;
|
||||
|
||||
void sendPlayerString(UUID gameId, String sessionId, String data) throws MageException;
|
||||
|
||||
void sendPlayerBoolean(UUID gameId, String sessionId, Boolean data) throws MageException;
|
||||
|
||||
void sendPlayerInteger(UUID gameId, String sessionId, Integer data) throws MageException;
|
||||
|
||||
void sendPlayerManaType(UUID gameId, UUID playerId, String sessionId, ManaType data) throws MageException;
|
||||
|
||||
void quitMatch(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
GameView getGameView(UUID gameId, String sessionId, UUID playerId) throws MageException;
|
||||
|
||||
// priority, undo, concede, mana pool
|
||||
void sendPlayerAction(PlayerAction playerAction, UUID gameId, String sessionId, Object data) throws MageException;
|
||||
|
||||
//tournament methods
|
||||
boolean startTournament(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
void joinTournament(UUID draftId, String sessionId) throws MageException;
|
||||
|
||||
void quitTournament(UUID tournamentId, String sessionId) throws MageException;
|
||||
|
||||
TournamentView getTournament(UUID tournamentId) throws MageException;
|
||||
|
||||
//draft methods
|
||||
void joinDraft(UUID draftId, String sessionId) throws MageException;
|
||||
|
||||
void quitDraft(UUID draftId, String sessionId) throws MageException;
|
||||
|
||||
DraftPickView sendCardPick(UUID draftId, String sessionId, UUID cardId, Set<UUID> hiddenCards) throws MageException;
|
||||
|
||||
void sendCardMark(UUID draftId, String sessionId, UUID cardId) throws MageException;
|
||||
|
||||
//challenge methods
|
||||
// void startChallenge(String sessionId, UUID roomId, UUID tableId, UUID challengeId) throws MageException;
|
||||
//replay methods
|
||||
void replayGame(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void startReplay(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void stopReplay(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void nextPlay(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void previousPlay(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void skipForward(UUID gameId, String sessionId, int moves) throws MageException;
|
||||
|
||||
//test methods
|
||||
void cheat(UUID gameId, String sessionId, UUID playerId, DeckCardLists deckList) throws MageException;
|
||||
|
||||
boolean cheat(UUID gameId, String sessionId, UUID playerId, String cardName) throws MageException;
|
||||
|
||||
//admin methods
|
||||
List<UserView> getUsers(String sessionId) throws MageException;
|
||||
|
||||
void disconnectUser(String sessionId, String userSessionId) throws MageException;
|
||||
|
||||
void endUserSession(String sessionId, String userSessionId) throws MageException;
|
||||
|
||||
void muteUser(String sessionId, String userName, long durationMinutes) throws MageException;
|
||||
|
||||
void lockUser(String sessionId, String userName, long durationMinutes) throws MageException;
|
||||
|
||||
void setActivation(String sessionId, String userName, boolean active) throws MageException;
|
||||
|
||||
void toggleActivation(String sessionId, String userName) throws MageException;
|
||||
|
||||
void removeTable(String sessionId, UUID tableId) throws MageException;
|
||||
|
||||
void sendBroadcastMessage(String sessionId, String message) throws MageException;
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package mage.interfaces;
|
||||
|
||||
import mage.MageException;
|
||||
|
||||
/**
|
||||
* Exception thrown by plugin on errors.
|
||||
*
|
||||
* @author nantuko
|
||||
*
|
||||
*/
|
||||
public class PluginException extends MageException {
|
||||
|
||||
private static final long serialVersionUID = 5528005696138392272L;
|
||||
|
||||
public PluginException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PluginException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
}
|
||||
112
Mage.Common/src/main/java/mage/interfaces/ServerState.java
Normal file
112
Mage.Common/src/main/java/mage/interfaces/ServerState.java
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.interfaces;
|
||||
|
||||
import mage.players.PlayerType;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.view.GameTypeView;
|
||||
import mage.view.TournamentTypeView;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ServerState implements Serializable {
|
||||
|
||||
private final List<GameTypeView> gameTypes;
|
||||
private final List<TournamentTypeView> tournamentTypes;
|
||||
private final PlayerType[] playerTypes;
|
||||
private final String[] deckTypes;
|
||||
private final String[] draftCubes;
|
||||
private final boolean testMode;
|
||||
private final MageVersion version;
|
||||
private final long cardsContentVersion;
|
||||
private final long expansionsContentVersion;
|
||||
|
||||
public ServerState(List<GameTypeView> gameTypes, List<TournamentTypeView> tournamentTypes,
|
||||
PlayerType[] playerTypes, String[] deckTypes, String[] draftCubes, boolean testMode,
|
||||
MageVersion version, long cardsContentVersion, long expansionsContentVersion) {
|
||||
this.gameTypes = gameTypes;
|
||||
this.tournamentTypes = tournamentTypes;
|
||||
this.playerTypes = playerTypes;
|
||||
this.deckTypes = deckTypes;
|
||||
this.draftCubes = draftCubes;
|
||||
this.testMode = testMode;
|
||||
this.version = version;
|
||||
this.cardsContentVersion = cardsContentVersion;
|
||||
this.expansionsContentVersion = expansionsContentVersion;
|
||||
|
||||
}
|
||||
|
||||
public List<GameTypeView> getGameTypes() {
|
||||
return gameTypes;
|
||||
}
|
||||
|
||||
public List<GameTypeView> getTournamentGameTypes() {
|
||||
return gameTypes.stream()
|
||||
.filter(gameTypeView -> gameTypeView.getMinPlayers() == 2 && gameTypeView.getMaxPlayers() == 2)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<TournamentTypeView> getTournamentTypes() {
|
||||
return tournamentTypes;
|
||||
}
|
||||
|
||||
public PlayerType[] getPlayerTypes() {
|
||||
return playerTypes;
|
||||
}
|
||||
|
||||
public String[] getDeckTypes() {
|
||||
return deckTypes;
|
||||
}
|
||||
|
||||
public String[] getDraftCubes() {
|
||||
return draftCubes;
|
||||
}
|
||||
|
||||
public boolean isTestMode() {
|
||||
return testMode;
|
||||
}
|
||||
|
||||
public MageVersion getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public long getCardsContentVersion() {
|
||||
return cardsContentVersion;
|
||||
}
|
||||
|
||||
public long getExpansionsContentVersion() {
|
||||
return expansionsContentVersion;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.interfaces.callback;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface CallbackClient {
|
||||
|
||||
void processCallback(ClientCallback callback);
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.interfaces.callback;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ClientCallback implements Serializable {
|
||||
|
||||
private UUID objectId;
|
||||
private Object data;
|
||||
private ClientCallbackMethod method;
|
||||
private int messageId;
|
||||
|
||||
public ClientCallback() {}
|
||||
|
||||
public ClientCallback(ClientCallbackMethod method, UUID objectId, Object data) {
|
||||
this.method = method;
|
||||
this.objectId = objectId;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ClientCallback(ClientCallbackMethod method, UUID objectId) {
|
||||
this(method, objectId, null);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
method = null;
|
||||
data = null;
|
||||
}
|
||||
|
||||
public UUID getObjectId() {
|
||||
return objectId;
|
||||
}
|
||||
|
||||
public void setObjectId(UUID objectId) {
|
||||
this.objectId = objectId;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ClientCallbackMethod getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(ClientCallbackMethod method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public void setMessageId(int messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public int getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package mage.interfaces.callback;
|
||||
|
||||
/**
|
||||
* Created by IGOUDT on 4-4-2017.
|
||||
*/
|
||||
public enum ClientCallbackMethod {
|
||||
|
||||
CHATMESSAGE("chatMessage"),
|
||||
TOURNAMENT_INIT("tournamentInit"),
|
||||
TOURNAMENT_UPDATE("tournamentUpdate"),
|
||||
TOURNAMENT_OVER("tournamentOver"),
|
||||
JOINED_TABLE("joinedTable"),
|
||||
START_DRAFT("startDraft"),
|
||||
START_TOURNAMENT("startTournament"),
|
||||
SIDEBOARD("sideboard"),
|
||||
CONSTRUCT("construct"),
|
||||
SHOW_USERMESSAGE("showUserMessage"),
|
||||
WATCHGAME("watchGame"),
|
||||
REPLAY_GAME("replayGame"),
|
||||
START_GAME("startGame"),
|
||||
SHOW_TOURNAMENT("showTournament"),
|
||||
SHOW_GAME_END_DIALOG("showGameEndDialog"),
|
||||
SERVER_MESSAGE("serverMessage"),
|
||||
GAME_INIT("gameInit"),
|
||||
GAME_OVER("gameOver"),
|
||||
GAME_INFORM("gameInform"),
|
||||
GAME_INFORM_PERSONAL("gameInformPersonal"),
|
||||
GAME_ERROR("gameError"),
|
||||
GAME_UPDATE("gameUpdate"),
|
||||
DRAFT_OVER("draftOver"),
|
||||
REPLAY_DONE("replayDone"),
|
||||
USER_REQUEST_DIALOG("userRequestDialog"),
|
||||
REPLAY_UPDATE("replayUpdate"),
|
||||
REPLAY_INIT("replayInit"),
|
||||
END_GAME_INFO("endGameInfo"),
|
||||
GAME_TARGET("gameTarget"),
|
||||
GAME_CHOOSE_ABILITY("gameChooseAbility"),
|
||||
GAME_CHOOSE_PILE("gameChoosePile"),
|
||||
GAME_CHOOSE_CHOICE("gameChooseChoice"), GAME_ASK("gameAsk"), GAME_SELECT("gameSelect"), GAME_PLAY_MANA("gamePlayMana"), GAME_PLAY_XMANA("gamePlayXMana"), GAME_GET_AMOUNT("gameSelectAmount"), DRAFT_INIT("draftInit"), DRAFT_INFORM("draftInform"), DRAFT_PICK("draftPick"), DRAFT_UPDATE("draftUpdate");
|
||||
|
||||
String value;
|
||||
|
||||
ClientCallbackMethod(String value){
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package mage.interfaces.plugin;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.swing.*;
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.cards.action.ActionCallback;
|
||||
import mage.view.CardView;
|
||||
import mage.view.PermanentView;
|
||||
import net.xeoh.plugins.base.Plugin;
|
||||
|
||||
/**
|
||||
* Interface for card plugins
|
||||
*
|
||||
* @version 0.6 17.07.2011 added options to #sortPermanents
|
||||
* @version 0.3 21.11.2010 #getMageCard
|
||||
* @version 0.2 07.11.2010 #downloadImages
|
||||
* @version 0.1 31.10.2010 #getMagePermanent, #sortPermanents
|
||||
* @author nantuko
|
||||
*/
|
||||
public interface CardPlugin extends Plugin {
|
||||
|
||||
MagePermanent getMagePermanent(PermanentView permanent, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage);
|
||||
|
||||
MagePermanent getMageCard(CardView permanent, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage);
|
||||
|
||||
int sortPermanents(Map<String, JComponent> ui, Collection<MagePermanent> cards, boolean nonPermanentsOwnRow, boolean topPanel);
|
||||
|
||||
/**
|
||||
* Download various symbols (mana, tap, set).
|
||||
*
|
||||
* @param imagesPath Path to check in and store symbols to. Can be null, in
|
||||
* such case default path should be used.
|
||||
*/
|
||||
void downloadSymbols(String imagesPath);
|
||||
|
||||
void onAddCard(MagePermanent card, int count);
|
||||
|
||||
void onRemoveCard(MagePermanent card, int count);
|
||||
|
||||
JComponent getCardInfoPane();
|
||||
|
||||
BufferedImage getOriginalImage(CardView card);
|
||||
|
||||
void changeGUISize();
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package mage.interfaces.plugin;
|
||||
|
||||
import mage.interfaces.PluginException;
|
||||
import net.xeoh.plugins.base.Plugin;
|
||||
|
||||
/**
|
||||
* Interface for counter plugins
|
||||
*
|
||||
* @version 0.1 14.112010
|
||||
* @author nantuko
|
||||
*/
|
||||
public interface CounterPlugin extends Plugin {
|
||||
void addGamePlayed() throws PluginException;
|
||||
int getGamePlayed() throws PluginException;
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package mage.interfaces.plugin;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.xeoh.plugins.base.Plugin;
|
||||
|
||||
/**
|
||||
* Interface for theme plugins
|
||||
*
|
||||
* @version 0.1 31.10.2010
|
||||
* @author nantuko
|
||||
*/
|
||||
public interface ThemePlugin extends Plugin {
|
||||
void applyInGame(Map<String, JComponent> ui);
|
||||
JComponent updateTable(Map<String, JComponent> ui);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package mage.interfaces.rate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
|
||||
/**
|
||||
* Interface for the class responsible for rating cards.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public interface RateCallback {
|
||||
int rateCard(Card card);
|
||||
Card getBestBasicLand(ColoredManaSymbol color, List<String> setsToUse);
|
||||
}
|
||||
300
Mage.Common/src/main/java/mage/remote/Connection.java
Normal file
300
Mage.Common/src/main/java/mage/remote/Connection.java
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import mage.players.net.UserData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Connection {
|
||||
|
||||
private String host;
|
||||
private int port;
|
||||
private String username;
|
||||
private String password;
|
||||
private String email;
|
||||
private String authToken;
|
||||
private String adminPassword;
|
||||
private ProxyType proxyType;
|
||||
private String proxyHost;
|
||||
private int proxyPort;
|
||||
private String proxyUsername;
|
||||
private String proxyPassword;
|
||||
private int clientCardDatabaseVersion;
|
||||
private boolean forceDBComparison;
|
||||
private String userIdStr;
|
||||
private int socketWriteTimeout;
|
||||
|
||||
private UserData userData;
|
||||
|
||||
// private int avatarId;
|
||||
// private boolean showAbilityPickerForced;
|
||||
// private boolean allowRequestShowHandCards;
|
||||
// private boolean confirmEmptyManaPool;
|
||||
// private String flagName;
|
||||
// private UserSkipPrioritySteps userSkipPrioritySteps;
|
||||
private static final String serialization = "?serializationtype=jboss";
|
||||
private static final String transport = "bisocket";
|
||||
|
||||
private final String parameter;
|
||||
|
||||
public Connection() {
|
||||
this("");
|
||||
}
|
||||
|
||||
public Connection(String parameter) {
|
||||
this.parameter = parameter;
|
||||
socketWriteTimeout = 10000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (transport + host + Integer.toString(port) + proxyType.toString()).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof Connection)) {
|
||||
return false;
|
||||
}
|
||||
Connection otherConnection = (Connection) object;
|
||||
return hashCode() == otherConnection.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return host + ':' + Integer.toString(port) + '/' + serialization + parameter;
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
if (host.equals("localhost")) {
|
||||
try {
|
||||
InetAddress inet = getLocalAddress();
|
||||
if (inet != null) {
|
||||
return transport + "://" + inet.getHostAddress() + ':' + port + '/' + serialization + parameter;
|
||||
}
|
||||
} catch (SocketException ex) {
|
||||
// just use localhost if can't find local ip
|
||||
}
|
||||
}
|
||||
return transport + "://" + host + ':' + port + '/' + serialization + parameter;
|
||||
}
|
||||
|
||||
public ProxyType getProxyType() {
|
||||
return proxyType;
|
||||
}
|
||||
|
||||
public void setProxyType(ProxyType proxyType) {
|
||||
this.proxyType = proxyType;
|
||||
}
|
||||
|
||||
public enum ProxyType {
|
||||
|
||||
SOCKS("Socks"), HTTP("HTTP"), NONE("None");
|
||||
|
||||
private final String text;
|
||||
|
||||
ProxyType(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static ProxyType valueByText(String value) {
|
||||
for (ProxyType type : values()) {
|
||||
if (type.text.equals(value)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getUserIdStr() {
|
||||
return userIdStr;
|
||||
}
|
||||
|
||||
public void setUserIdStr(String userIdStr) {
|
||||
this.userIdStr = userIdStr;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getAuthToken() {
|
||||
return authToken;
|
||||
}
|
||||
|
||||
public void setAuthToken(String authToken) {
|
||||
this.authToken = authToken;
|
||||
}
|
||||
|
||||
public String getAdminPassword() {
|
||||
return adminPassword;
|
||||
}
|
||||
|
||||
public void setAdminPassword(String adminPassword) {
|
||||
this.adminPassword = adminPassword;
|
||||
}
|
||||
|
||||
public String getProxyHost() {
|
||||
return proxyHost;
|
||||
}
|
||||
|
||||
public void setProxyHost(String proxyHost) {
|
||||
this.proxyHost = proxyHost;
|
||||
}
|
||||
|
||||
public int getProxyPort() {
|
||||
return proxyPort;
|
||||
}
|
||||
|
||||
public void setProxyPort(int proxyPort) {
|
||||
this.proxyPort = proxyPort;
|
||||
}
|
||||
|
||||
public String getProxyUsername() {
|
||||
return proxyUsername;
|
||||
}
|
||||
|
||||
public void setProxyUsername(String proxyUsername) {
|
||||
this.proxyUsername = proxyUsername;
|
||||
}
|
||||
|
||||
public String getProxyPassword() {
|
||||
return proxyPassword;
|
||||
}
|
||||
|
||||
public void setProxyPassword(String proxyPassword) {
|
||||
this.proxyPassword = proxyPassword;
|
||||
}
|
||||
|
||||
public static InetAddress getLocalAddress() throws SocketException {
|
||||
for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements();) {
|
||||
NetworkInterface iface = interfaces.nextElement();
|
||||
if (iface.isLoopback()) {
|
||||
continue;
|
||||
}
|
||||
for (InterfaceAddress addr : iface.getInterfaceAddresses()) {
|
||||
if (addr != null) {
|
||||
InetAddress iaddr = addr.getAddress();
|
||||
if (iaddr != null && iaddr instanceof Inet4Address) {
|
||||
return iaddr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getMAC() throws SocketException {
|
||||
StringBuilder allMACs = new StringBuilder();
|
||||
for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements();) {
|
||||
NetworkInterface iface = interfaces.nextElement();
|
||||
byte[] mac = iface.getHardwareAddress();
|
||||
|
||||
if (mac != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < mac.length; i++) {
|
||||
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
|
||||
}
|
||||
sb.append(';');
|
||||
allMACs.append(sb.toString());
|
||||
}
|
||||
}
|
||||
return allMACs.toString();
|
||||
}
|
||||
|
||||
public void setUserData(UserData userData) {
|
||||
this.userData = userData;
|
||||
}
|
||||
|
||||
public UserData getUserData() {
|
||||
return userData;
|
||||
}
|
||||
|
||||
public boolean isForceDBComparison() {
|
||||
return forceDBComparison;
|
||||
}
|
||||
|
||||
public void setForceDBComparison(boolean forceDBComparison) {
|
||||
this.forceDBComparison = forceDBComparison;
|
||||
}
|
||||
|
||||
public int getSocketWriteTimeout() {
|
||||
return socketWriteTimeout;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.remote;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class MageRemoteException extends Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote;
|
||||
|
||||
import mage.MageException;
|
||||
import mage.utils.MageVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class MageVersionException extends MageException {
|
||||
|
||||
private final MageVersion serverVersion;
|
||||
|
||||
public MageVersionException(MageVersion clientVersion, MageVersion serverVersion) {
|
||||
super("Wrong client version " + clientVersion + ", expecting version " + serverVersion + ". \r\n\r\nPlease download needed version from http://XMage.de or http://www.slightlymagic.net/forum/viewforum.php?f=70");
|
||||
this.serverVersion = serverVersion;
|
||||
}
|
||||
|
||||
public MageVersion getServerVersion() {
|
||||
return serverVersion;
|
||||
}
|
||||
}
|
||||
49
Mage.Common/src/main/java/mage/remote/Session.java
Normal file
49
Mage.Common/src/main/java/mage/remote/Session.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.remote;
|
||||
|
||||
import mage.remote.interfaces.ChatSession;
|
||||
import mage.remote.interfaces.ClientData;
|
||||
import mage.remote.interfaces.Connect;
|
||||
import mage.remote.interfaces.Feedback;
|
||||
import mage.remote.interfaces.GamePlay;
|
||||
import mage.remote.interfaces.GameTypes;
|
||||
import mage.remote.interfaces.PlayerActions;
|
||||
import mage.remote.interfaces.Replays;
|
||||
import mage.remote.interfaces.ServerState;
|
||||
import mage.remote.interfaces.Testable;
|
||||
|
||||
/**
|
||||
* Extracted interface for SessionImpl class.
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public interface Session extends ClientData, Connect, GamePlay, GameTypes, ServerState, ChatSession, Feedback, PlayerActions, Replays, Testable {
|
||||
|
||||
}
|
||||
1649
Mage.Common/src/main/java/mage/remote/SessionImpl.java
Normal file
1649
Mage.Common/src/main/java/mage/remote/SessionImpl.java
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote.interfaces;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public interface ChatSession {
|
||||
|
||||
Optional<UUID> getRoomChatId(UUID roomId);
|
||||
|
||||
Optional<UUID> getTableChatId(UUID tableId);
|
||||
|
||||
Optional<UUID> getGameChatId(UUID gameId);
|
||||
|
||||
Optional<UUID> getTournamentChatId(UUID tournamentId);
|
||||
|
||||
boolean joinChat(UUID chatId);
|
||||
|
||||
boolean leaveChat(UUID chatId);
|
||||
|
||||
boolean sendChatMessage(UUID chatId, String message);
|
||||
|
||||
boolean sendBroadcastMessage(String message);
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote.interfaces;
|
||||
|
||||
import mage.players.net.UserData;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public interface ClientData {
|
||||
|
||||
String getUserName();
|
||||
|
||||
boolean updatePreferencesForServer(UserData userData);
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote.interfaces;
|
||||
|
||||
import mage.remote.Connection;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public interface Connect {
|
||||
|
||||
boolean register(Connection connection);
|
||||
|
||||
boolean emailAuthToken(Connection connection);
|
||||
|
||||
boolean resetPassword(Connection connection);
|
||||
|
||||
boolean connect(Connection connection);
|
||||
|
||||
boolean stopConnecting();
|
||||
|
||||
void disconnect(boolean showMessage);
|
||||
|
||||
void reconnect(Throwable throwable);
|
||||
|
||||
boolean ping();
|
||||
|
||||
boolean isConnected();
|
||||
|
||||
Optional<String> getServerHostname();
|
||||
|
||||
boolean disconnectUser(String userSessionId);
|
||||
|
||||
boolean endUserSession(String userSessionId);
|
||||
|
||||
boolean muteUserChat(String userName, long durationMinute);
|
||||
|
||||
boolean setActivation(String userName, boolean active);
|
||||
|
||||
boolean toggleActivation(String userName);
|
||||
|
||||
boolean lockUser(String userName, long durationMinute);
|
||||
|
||||
String getSessionId();
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote.interfaces;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public interface Feedback {
|
||||
boolean sendFeedback(String title, String type, String message, String email);
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote.interfaces;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.constants.ManaType;
|
||||
import mage.constants.PlayerAction;
|
||||
import mage.view.DraftPickView;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public interface GamePlay {
|
||||
|
||||
boolean startMatch(UUID roomId, UUID tableId);
|
||||
|
||||
boolean watchGame(UUID gameId);
|
||||
|
||||
boolean stopWatching(UUID gameId);
|
||||
|
||||
boolean sendPlayerUUID(UUID gameId, UUID data);
|
||||
|
||||
boolean sendPlayerBoolean(UUID gameId, boolean data);
|
||||
|
||||
boolean sendPlayerInteger(UUID gameId, int data);
|
||||
|
||||
boolean sendPlayerString(UUID gameId, String data);
|
||||
|
||||
boolean sendPlayerManaType(UUID gameId, UUID playerId, ManaType data);
|
||||
|
||||
boolean quitMatch(UUID gameId);
|
||||
|
||||
boolean quitTournament(UUID tournamentId);
|
||||
|
||||
boolean quitDraft(UUID draftId);
|
||||
|
||||
boolean submitDeck(UUID tableId, DeckCardLists deck);
|
||||
|
||||
boolean updateDeck(UUID tableId, DeckCardLists deck);
|
||||
|
||||
DraftPickView sendCardPick(UUID draftId, UUID cardId, Set<UUID> hiddenCards);
|
||||
DraftPickView sendCardMark(UUID draftId, UUID cardId);
|
||||
|
||||
/**
|
||||
* magenoxx:
|
||||
* it should be done separately as sendPlayer* methods calls are injected into the game flow
|
||||
* - this is similar to concedeGame method
|
||||
*
|
||||
* This method sends player actions for a game
|
||||
* priority handling, undo
|
||||
*
|
||||
* @param passPriorityAction
|
||||
* @param gameId
|
||||
* @param Data
|
||||
* @return
|
||||
*/
|
||||
boolean sendPlayerAction(PlayerAction passPriorityAction, UUID gameId, Object Data);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote.interfaces;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import mage.players.PlayerType;
|
||||
import mage.view.GameTypeView;
|
||||
import mage.view.TournamentTypeView;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public interface GameTypes {
|
||||
|
||||
PlayerType[] getPlayerTypes();
|
||||
|
||||
List<GameTypeView> getGameTypes();
|
||||
List<GameTypeView> getTournamentGameTypes();
|
||||
|
||||
String[] getDeckTypes();
|
||||
|
||||
String[] getDraftCubes();
|
||||
|
||||
List<TournamentTypeView> getTournamentTypes();
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote.interfaces;
|
||||
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.players.PlayerType;
|
||||
import mage.remote.MageRemoteException;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public interface PlayerActions {
|
||||
|
||||
TableView createTable(UUID roomId, MatchOptions matchOptions);
|
||||
|
||||
TableView createTournamentTable(UUID roomId, TournamentOptions tournamentOptions);
|
||||
|
||||
boolean removeTable(UUID roomId, UUID tableId);
|
||||
|
||||
boolean removeTable(UUID tableId);
|
||||
|
||||
boolean joinGame(UUID gameId);
|
||||
|
||||
boolean joinDraft(UUID draftId);
|
||||
|
||||
boolean joinTournament(UUID tournamentId);
|
||||
|
||||
boolean leaveTable(UUID roomId, UUID tableId);
|
||||
|
||||
boolean swapSeats(UUID roomId, UUID tableId, int seatNum1, int seatNum2);
|
||||
|
||||
boolean startTournament(UUID roomId, UUID tableId);
|
||||
|
||||
// boolean startChallenge(UUID roomId, UUID tableId, UUID challengeId);
|
||||
|
||||
boolean joinTournamentTable(UUID roomId, UUID tableId, String playerName, PlayerType playerType, int skill, DeckCardLists deckList, String password);
|
||||
|
||||
boolean watchTable(UUID roomId, UUID tableId);
|
||||
|
||||
boolean watchTournamentTable(UUID tableId);
|
||||
|
||||
boolean joinTable(UUID roomId, UUID tableId, String playerName, PlayerType playerType, int skill, DeckCardLists deckList, String password);
|
||||
|
||||
Optional<TableView> getTable(UUID roomId, UUID tableId);
|
||||
|
||||
TournamentView getTournament(UUID tournamentId) throws MageRemoteException;
|
||||
|
||||
boolean isTableOwner(UUID roomId, UUID tableId);
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote.interfaces;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public interface Replays {
|
||||
|
||||
boolean replayGame(UUID gameId);
|
||||
|
||||
boolean startReplay(UUID gameId);
|
||||
|
||||
boolean stopReplay(UUID gameId);
|
||||
|
||||
boolean nextPlay(UUID gameId);
|
||||
|
||||
boolean previousPlay(UUID gameId);
|
||||
|
||||
boolean skipForward(UUID gameId, int moves);
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote.interfaces;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import mage.remote.MageRemoteException;
|
||||
import mage.view.MatchView;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.UserView;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public interface ServerState {
|
||||
|
||||
UUID getMainRoomId();
|
||||
|
||||
List<UserView> getUsers();
|
||||
|
||||
Collection<RoomUsersView> getRoomUsers (UUID roomId) throws MageRemoteException;
|
||||
|
||||
List<String> getServerMessages();
|
||||
|
||||
Collection<TableView> getTables(UUID roomId) throws MageRemoteException;
|
||||
|
||||
Collection<MatchView> getFinishedMatches(UUID roomId) throws MageRemoteException;
|
||||
|
||||
String getVersionInfo();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.remote.interfaces;
|
||||
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public interface Testable {
|
||||
|
||||
boolean isTestMode();
|
||||
|
||||
boolean cheat(UUID gameId, UUID playerId, DeckCardLists deckList);
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package mage.remote.traffic;
|
||||
|
||||
/**
|
||||
* Base interface for class wrapping non compressed objects.
|
||||
* Provides methods for compressing that should be used before sending it over internet and decompressing to get actual
|
||||
* data.
|
||||
*
|
||||
* @author ayrat
|
||||
*/
|
||||
public interface ZippedObject<T> {
|
||||
|
||||
void zip(T object);
|
||||
|
||||
T unzip();
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package mage.remote.traffic;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* Implementation for compressing and decompressing objects using {@link GZIPInputStream} and {@link GZIPOutputStream}.
|
||||
* Can be used to send any {@link Object} over internet to reduce traffic usage.
|
||||
*
|
||||
* @author ayrat
|
||||
*/
|
||||
public class ZippedObjectImpl<T> implements ZippedObject<T>, Serializable {
|
||||
|
||||
private byte[] data;
|
||||
|
||||
public ZippedObjectImpl(T object) {
|
||||
zip(object);
|
||||
}
|
||||
|
||||
public void zip(T object) {
|
||||
try {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gz = new GZIPOutputStream(bos);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(gz);
|
||||
oos.writeObject(object);
|
||||
oos.close();
|
||||
data = bos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T unzip() {
|
||||
try {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(data);
|
||||
GZIPInputStream gz = new GZIPInputStream(bis);
|
||||
ObjectInputStream ois = new ObjectInputStream(gz);
|
||||
Object o = ois.readObject();
|
||||
return (T)o;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package mage.utils;
|
||||
|
||||
import mage.interfaces.ActionWithResult;
|
||||
|
||||
/**
|
||||
* Used to write less code for ActionWithResult anonymous classes with Boolean return type.
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public abstract class ActionWithBooleanResult implements ActionWithResult<Boolean> {
|
||||
@Override
|
||||
public Boolean negativeResult() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package mage.utils;
|
||||
|
||||
import mage.interfaces.ActionWithResult;
|
||||
|
||||
/**
|
||||
* This class always returns null independently from type <T> used.
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public abstract class ActionWithNullNegativeResult<T> implements ActionWithResult<T> {
|
||||
@Override
|
||||
public T negativeResult() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package mage.utils;
|
||||
|
||||
import mage.view.TableView;
|
||||
|
||||
/**
|
||||
* Used to write less code for ActionWithResult anonymous classes with TableView return type.
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public abstract class ActionWithTableViewResult extends ActionWithNullNegativeResult<TableView> {
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package mage.utils;
|
||||
|
||||
import mage.view.TableView;
|
||||
|
||||
/**
|
||||
* Used to write less code for ActionWithResult anonymous classes with UUID return type.
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public abstract class ActionWithUUIDResult extends ActionWithNullNegativeResult<TableView> {
|
||||
}
|
||||
72
Mage.Common/src/main/java/mage/utils/CardUtil.java
Normal file
72
Mage.Common/src/main/java/mage/utils/CardUtil.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
package mage.utils;
|
||||
|
||||
import mage.ObjectColor;
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.constants.CardType;
|
||||
import mage.view.CardView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility class for {@link CardView}
|
||||
*
|
||||
* @version 0.1 02.11.2010
|
||||
* @author nantuko
|
||||
*/
|
||||
public final class CardUtil {
|
||||
|
||||
private static final String regexBlack = ".*\\x7b.{0,2}B.{0,2}\\x7d.*";
|
||||
private static final String regexBlue = ".*\\x7b.{0,2}U.{0,2}\\x7d.*";
|
||||
private static final String regexRed = ".*\\x7b.{0,2}R.{0,2}\\x7d.*";
|
||||
private static final String regexGreen = ".*\\x7b.{0,2}G.{0,2}\\x7d.*";
|
||||
private static final String regexWhite = ".*\\x7b.{0,2}W.{0,2}\\x7d.*";
|
||||
|
||||
|
||||
|
||||
|
||||
public static boolean isCreature(MagePermanent card) {
|
||||
return is(card.getOriginal(), CardType.CREATURE);
|
||||
}
|
||||
|
||||
public static boolean isPlaneswalker(MagePermanent card) {
|
||||
return is(card.getOriginal(), CardType.PLANESWALKER);
|
||||
}
|
||||
|
||||
public static boolean isLand(MagePermanent card) {
|
||||
return is(card.getOriginal(), CardType.LAND);
|
||||
}
|
||||
|
||||
public static boolean is(CardView card, CardType type) {
|
||||
return card.getCardTypes().contains(type);
|
||||
}
|
||||
|
||||
public static int getColorIdentitySortValue(List<String> manaCost, ObjectColor originalColor, List<String> rules) {
|
||||
ObjectColor color = new ObjectColor(originalColor);
|
||||
for (String rule : rules) {
|
||||
rule = rule.replaceAll("(?i)<i.*?</i>", ""); // Ignoring reminder text in italic
|
||||
if (rule.matches(regexBlack)) {
|
||||
color.setBlack(true);
|
||||
}
|
||||
if (rule.matches(regexBlue)) {
|
||||
color.setBlue(true);
|
||||
}
|
||||
if (rule.matches(regexGreen)) {
|
||||
color.setGreen(true);
|
||||
}
|
||||
if (rule.matches(regexRed)) {
|
||||
color.setRed(true);
|
||||
}
|
||||
if (rule.matches(regexWhite)) {
|
||||
color.setWhite(true);
|
||||
}
|
||||
}
|
||||
|
||||
int hash = 3;
|
||||
hash = 23 * hash + (color.isWhite() || manaCost.contains("{W}") ? 1 : 0);
|
||||
hash = 23 * hash + (color.isBlue() || manaCost.contains("{U}") ? 1 : 0);
|
||||
hash = 23 * hash + (color.isBlack() || manaCost.contains("{B}") ? 1 : 0);
|
||||
hash = 23 * hash + (color.isRed() || manaCost.contains("{R}") ? 1 : 0);
|
||||
hash = 23 * hash + (color.isGreen() || manaCost.contains("{G}") ? 1 : 0);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
60
Mage.Common/src/main/java/mage/utils/CompressUtil.java
Normal file
60
Mage.Common/src/main/java/mage/utils/CompressUtil.java
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package mage.utils;
|
||||
|
||||
import mage.remote.traffic.ZippedObject;
|
||||
import mage.remote.traffic.ZippedObjectImpl;
|
||||
|
||||
/**
|
||||
* Helps to compress and decompress data if needed.
|
||||
*
|
||||
* @author ayrat
|
||||
*/
|
||||
public final class CompressUtil {
|
||||
|
||||
/**
|
||||
* Defines should data be compressed or not. True by default. Read from
|
||||
* system property:
|
||||
*/
|
||||
private static boolean compressData = true;
|
||||
|
||||
/**
|
||||
* Defines the system property name to disable any compressing.
|
||||
*/
|
||||
private static final String NO_COMPRESS_DATA_PROPERTY = "nocompress";
|
||||
|
||||
static {
|
||||
compressData = System.getProperty(NO_COMPRESS_DATA_PROPERTY) == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hidden constructor
|
||||
*/
|
||||
private CompressUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompress data, but only if it was compressed previously return original
|
||||
* object otherwise.
|
||||
*
|
||||
* @param data Data to decompress
|
||||
* @return Decompressed object
|
||||
*/
|
||||
public static Object decompress(Object data) {
|
||||
if (data == null || !(data instanceof ZippedObject)) {
|
||||
return data;
|
||||
}
|
||||
return ((ZippedObject) data).unzip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress data.
|
||||
*
|
||||
* @param data Data to compress
|
||||
* @return Compressed object
|
||||
*/
|
||||
public static Object compress(Object data) {
|
||||
if (data != null && compressData) {
|
||||
return new ZippedObjectImpl<>(data);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
315
Mage.Common/src/main/java/mage/utils/DeckBuilder.java
Normal file
315
Mage.Common/src/main/java/mage/utils/DeckBuilder.java
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
package mage.utils;
|
||||
|
||||
import mage.Mana;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.interfaces.rate.RateCallback;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Builds deck from provided card pool.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public final class DeckBuilder {
|
||||
|
||||
private static final int DECK_COUNT40[] = {3, 6, 6, 4, 3, 2};
|
||||
private static final int DECK_COUNT60[] = {4, 9, 9, 5, 5, 3};
|
||||
private static final int DECK_COST[] = {1, 2, 3, 4, 6, 10};
|
||||
private static final int MIN_CARD_SCORE = 25;
|
||||
private static final int MIN_SOURCE = 3; // minmal number of sources for a mana color, will be taken also if ratio would give a lower number
|
||||
private static Deck deck;
|
||||
|
||||
private static int deckCount[];
|
||||
private static int deckSize;
|
||||
private static int deckSpells;
|
||||
private static int deckLands;
|
||||
|
||||
/**
|
||||
* Hide constructor.
|
||||
*/
|
||||
private DeckBuilder() {
|
||||
}
|
||||
|
||||
public synchronized static Deck buildDeck(List<Card> spellCardPool, List<ColoredManaSymbol> allowedColors, List<String> setsToUse, List<Card> landCardPool, int deckCardSize, RateCallback callback) {
|
||||
deckSize = deckCardSize;
|
||||
deck = new Deck();
|
||||
|
||||
final Collection<MageScoredCard> remainingCards = new ArrayList<>();
|
||||
Set<String> names = new HashSet<>();
|
||||
for (final Card card : spellCardPool) {
|
||||
if (names.contains(card.getName())) {
|
||||
continue;
|
||||
}
|
||||
remainingCards.add(new MageScoredCard(card, allowedColors, callback));
|
||||
names.add(card.getName());
|
||||
}
|
||||
// prints score and manaScore to log
|
||||
// for(MageScoredCard scoreCard :remainingCards) {
|
||||
// Logger.getLogger(DeckBuilder.class).info(
|
||||
// new StringBuilder("Score: ")
|
||||
// .append(scoreCard.getScore())
|
||||
// .append(" ManaScore: ")
|
||||
// .append(scoreCard.getManaCostScore(scoreCard.getCard(), allowedColors))
|
||||
// .append(" ")
|
||||
// .append(scoreCard.getCard().getName())
|
||||
// .append(" ")
|
||||
// .append(scoreCard.getCard().getManaCost().getText()).toString()
|
||||
// );
|
||||
// }
|
||||
int min = 0;
|
||||
if (deckSize == 40) {
|
||||
deckCount = DECK_COUNT40;
|
||||
deckSpells = 23;
|
||||
deckLands = 17;
|
||||
} else {
|
||||
deckCount = DECK_COUNT60;
|
||||
deckSpells = 35;
|
||||
deckLands = 25;
|
||||
}
|
||||
|
||||
for (int index = 0; index < deckCount.length; index++) {
|
||||
final int max = DECK_COST[index];
|
||||
addCardsToDeck(remainingCards, min, max, deckCount[index]);
|
||||
min = max + 1;
|
||||
}
|
||||
addCardsToDeck(remainingCards, 0, 4, deckSpells - deck.getCards().size());
|
||||
addCardsToDeck(remainingCards, 5, 10, deckSpells - deck.getCards().size());
|
||||
addLandsToDeck(allowedColors, setsToUse, landCardPool, callback);
|
||||
|
||||
Deck returnedDeck = deck;
|
||||
deck = null;
|
||||
return returnedDeck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that chosen card can produce mana of specific color.
|
||||
*
|
||||
* @param card
|
||||
* @param allowedColors
|
||||
* @return
|
||||
*/
|
||||
private static boolean cardCardProduceChosenColors(Card card, List<ColoredManaSymbol> allowedColors) {
|
||||
int score = 0;
|
||||
for (Mana mana : card.getMana()) {
|
||||
for (ColoredManaSymbol color : allowedColors) {
|
||||
score = score + mana.getColor(color);
|
||||
}
|
||||
}
|
||||
if (score > 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Chosed best scored card and adds it to the deck.
|
||||
*
|
||||
* @param remainingCards
|
||||
* @param minCost
|
||||
* @param maxCost
|
||||
* @param count
|
||||
*/
|
||||
private static void addCardsToDeck(final Collection<MageScoredCard> remainingCards, final int minCost, final int maxCost,
|
||||
final int count) {
|
||||
|
||||
for (int c = count; c > 0; c--) {
|
||||
|
||||
MageScoredCard bestCard = null;
|
||||
int bestScore = -1;
|
||||
|
||||
for (final MageScoredCard draftedCard : remainingCards) {
|
||||
|
||||
final int score = draftedCard.getScore();
|
||||
final int cost = draftedCard.getConvertedCost();
|
||||
if (score > bestScore && cost >= minCost && cost <= maxCost) {
|
||||
bestScore = score;
|
||||
bestCard = draftedCard;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestCard == null || bestScore < MIN_CARD_SCORE) {
|
||||
break;
|
||||
}
|
||||
deck.getCards().add(bestCard.card);
|
||||
remainingCards.remove(bestCard);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds lands from non basic land (if provided), adds basic lands getting them from provided {@link RateCallback}}.
|
||||
*
|
||||
* @param allowedColors
|
||||
* @param landCardPool
|
||||
* @param callback
|
||||
*/
|
||||
private static void addLandsToDeck(List<ColoredManaSymbol> allowedColors, List<String> setsToUse, List<Card> landCardPool, RateCallback callback) {
|
||||
|
||||
// Calculate statistics per color.
|
||||
final Map<String, Integer> colorCount = new HashMap<>();
|
||||
for (final Card card : deck.getCards()) {
|
||||
|
||||
for (String symbol : card.getManaCost().getSymbols()) {
|
||||
int count = 0;
|
||||
symbol = symbol.replace("{", "").replace("}", "");
|
||||
if (isColoredMana(symbol)) {
|
||||
for (ColoredManaSymbol allowed : allowedColors) {
|
||||
if (symbol.contains(allowed.toString())) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
Integer typeCount = colorCount.get(symbol);
|
||||
if (typeCount == null) {
|
||||
typeCount = 0;
|
||||
}
|
||||
typeCount += 1;
|
||||
colorCount.put(symbol, typeCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add suitable non basic lands to deck in order of pack.
|
||||
final Map<String, Integer> colorSource = new HashMap<>();
|
||||
for (final ColoredManaSymbol color : ColoredManaSymbol.values()) {
|
||||
colorSource.put(color.toString(), 0);
|
||||
}
|
||||
if (landCardPool != null) {
|
||||
for (final Card landCard : landCardPool) {
|
||||
deck.getCards().add(landCard);
|
||||
for (Mana mana : landCard.getMana()) {
|
||||
for (ColoredManaSymbol color : allowedColors) {
|
||||
int amount = mana.getColor(color);
|
||||
if (amount > 0) {
|
||||
Integer count = colorSource.get(color.toString());
|
||||
count += amount;
|
||||
colorSource.put(color.toString(), count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add optimal basic lands to deck.
|
||||
while (deck.getCards().size() < deckSize) {
|
||||
ColoredManaSymbol bestColor = null;
|
||||
//Default to a color in the allowed colors
|
||||
if (allowedColors != null && !allowedColors.isEmpty()) {
|
||||
bestColor = allowedColors.get(RandomUtil.nextInt(allowedColors.size()));
|
||||
}
|
||||
int lowestRatio = Integer.MAX_VALUE;
|
||||
for (final ColoredManaSymbol color : ColoredManaSymbol.values()) {
|
||||
|
||||
final Integer count = colorCount.get(color.toString());
|
||||
if (count != null && count > 0) {
|
||||
final int source = colorSource.get(color.toString());
|
||||
final int ratio;
|
||||
if (source < MIN_SOURCE) {
|
||||
ratio = source - count;
|
||||
} else {
|
||||
ratio = source * 100 / count;
|
||||
}
|
||||
if (ratio < lowestRatio) {
|
||||
lowestRatio = ratio;
|
||||
bestColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
final Card landCard = callback.getBestBasicLand(bestColor, setsToUse);
|
||||
Integer count = colorSource.get(bestColor.toString());
|
||||
count++;
|
||||
colorSource.put(bestColor.toString(), count);
|
||||
deck.getCards().add(landCard);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MageScoredCard {
|
||||
|
||||
private Card card;
|
||||
private final int score;
|
||||
|
||||
private static final int SINGLE_PENALTY[] = {0, 1, 1, 3, 6, 9};
|
||||
//private static final int DOUBLE_PENALTY[] = { 0, 0, 1, 2, 4, 6 };
|
||||
|
||||
public MageScoredCard(Card card, List<ColoredManaSymbol> allowedColors, RateCallback cardRater) {
|
||||
this.card = card;
|
||||
|
||||
int type;
|
||||
if (card.isCreature()) {
|
||||
type = 10;
|
||||
} else if (card.getSubtype(null).contains("Equipment")) {
|
||||
type = 8;
|
||||
} else if (card.getSubtype(null).contains("Aura")) {
|
||||
type = 5;
|
||||
} else if (card.isInstant()) {
|
||||
type = 7;
|
||||
} else {
|
||||
type = 6;
|
||||
}
|
||||
|
||||
this.score =
|
||||
// 5*card.getValue() + // not possible now
|
||||
3 * cardRater.rateCard(card) +
|
||||
// 3*card.getRemoval() + // not possible now
|
||||
type + getManaCostScore(card, allowedColors);
|
||||
}
|
||||
|
||||
private int getManaCostScore(Card card, List<ColoredManaSymbol> allowedColors) {
|
||||
int converted = card.getManaCost().convertedManaCost();
|
||||
final Map<String, Integer> singleCount = new HashMap<>();
|
||||
int maxSingleCount = 0;
|
||||
int multicolor = 0;
|
||||
Set<String> colors = new HashSet<>();
|
||||
for (String symbol : card.getManaCost().getSymbols()) {
|
||||
int count = 0;
|
||||
symbol = symbol.replace("{", "").replace("}", "");
|
||||
if (isColoredMana(symbol)) {
|
||||
for (ColoredManaSymbol allowed : allowedColors) {
|
||||
if (symbol.contains(allowed.toString())) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
// colored but no selected colors, go back with negative value
|
||||
if (count == 0) {
|
||||
return -30;
|
||||
}
|
||||
if (!colors.contains(symbol)) {
|
||||
multicolor += 1;
|
||||
colors.add(symbol);
|
||||
}
|
||||
Integer typeCount = singleCount.get(symbol);
|
||||
if (typeCount == null) {
|
||||
typeCount = 0;
|
||||
}
|
||||
typeCount += 1;
|
||||
singleCount.put(symbol, typeCount);
|
||||
maxSingleCount = Math.max(maxSingleCount, typeCount);
|
||||
}
|
||||
}
|
||||
int multicolorBonus = multicolor > 1 ? 30 : 0;
|
||||
maxSingleCount = Math.min(maxSingleCount, SINGLE_PENALTY.length - 1);
|
||||
return 2 * converted + 3 * (10 - SINGLE_PENALTY[maxSingleCount]/*-DOUBLE_PENALTY[doubleCount]*/) + multicolorBonus;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return this.score;
|
||||
}
|
||||
|
||||
public int getConvertedCost() {
|
||||
return this.card.getManaCost().convertedManaCost();
|
||||
}
|
||||
|
||||
public Card getCard() {
|
||||
return this.card;
|
||||
}
|
||||
}
|
||||
|
||||
protected static boolean isColoredMana(String symbol) {
|
||||
return symbol.equals("W") || symbol.equals("G") || symbol.equals("U") || symbol.equals("B") || symbol.equals("R") || symbol.contains("/");
|
||||
}
|
||||
|
||||
}
|
||||
97
Mage.Common/src/main/java/mage/utils/MageVersion.java
Normal file
97
Mage.Common/src/main/java/mage/utils/MageVersion.java
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.utils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class MageVersion implements Serializable, Comparable<MageVersion> {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final static int MAGE_VERSION_MAJOR = 1;
|
||||
public final static int MAGE_VERSION_MINOR = 4;
|
||||
public final static int MAGE_VERSION_PATCH = 23;
|
||||
public final static String MAGE_VERSION_MINOR_PATCH = "V1";
|
||||
public final static String MAGE_VERSION_INFO = "";
|
||||
|
||||
private final int major;
|
||||
private final int minor;
|
||||
private final int patch;
|
||||
private final String minorPatch; // doesn't matter for compatibility
|
||||
|
||||
private String info = "";
|
||||
|
||||
public MageVersion(int major, int minor, int patch, String minorPatch, String info) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
this.minorPatch = minorPatch;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return minor;
|
||||
}
|
||||
|
||||
public int getPatch() {
|
||||
return patch;
|
||||
}
|
||||
|
||||
public String getMinorPatch() {
|
||||
return minorPatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return major + "." + minor + '.' + patch + info + minorPatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MageVersion o) {
|
||||
if (major != o.major) {
|
||||
return major - o.major;
|
||||
}
|
||||
if (minor != o.minor) {
|
||||
return minor - o.minor;
|
||||
}
|
||||
if (patch != o.patch) {
|
||||
return patch - o.patch;
|
||||
}
|
||||
return info.compareTo(o.info);
|
||||
}
|
||||
|
||||
}
|
||||
81
Mage.Common/src/main/java/mage/utils/ThreadUtils.java
Normal file
81
Mage.Common/src/main/java/mage/utils/ThreadUtils.java
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
package mage.utils;
|
||||
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Util method to work with threads.
|
||||
*
|
||||
* @author ayrat
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class ThreadUtils {
|
||||
|
||||
public static final ThreadPoolExecutor threadPool;
|
||||
public static final ThreadPoolExecutor threadPool2;
|
||||
public static final ThreadPoolExecutor threadPool3;
|
||||
private static int threadCount;
|
||||
|
||||
static {
|
||||
/**
|
||||
* used in CardInfoPaneImpl
|
||||
*
|
||||
*/
|
||||
threadPool = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable runnable) {
|
||||
threadCount++;
|
||||
Thread thread = new Thread(runnable, "Util" + threadCount);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
}
|
||||
});
|
||||
threadPool.prestartAllCoreThreads();
|
||||
|
||||
/**
|
||||
* Used for MageActionCallback
|
||||
*/
|
||||
threadPool2 = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable runnable) {
|
||||
threadCount++;
|
||||
Thread thread = new Thread(runnable, "TP2" + threadCount);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
}
|
||||
});
|
||||
threadPool2.prestartAllCoreThreads();
|
||||
/**
|
||||
* Used for Enlarged view
|
||||
*/
|
||||
|
||||
threadPool3 = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable runnable) {
|
||||
threadCount++;
|
||||
Thread thread = new Thread(runnable, "EV" + threadCount);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
}
|
||||
});
|
||||
threadPool3.prestartAllCoreThreads();
|
||||
}
|
||||
|
||||
public static void sleep(int millis) {
|
||||
try {
|
||||
Thread.sleep(millis);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void wait(Object lock) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
lock.wait();
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package mage.utils.properties;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public final class PropertiesUtil {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(PropertiesUtil.class);
|
||||
|
||||
private static final String LOG_JDBC_URL = "jdbc:h2:file:./db/mage.h2;AUTO_SERVER=TRUE";
|
||||
private static final String FEEDBACK_JDBC_URL = "jdbc:h2:file:./db/feedback.h2;AUTO_SERVER=TRUE";
|
||||
|
||||
private static Properties properties = new Properties();
|
||||
|
||||
static {
|
||||
InputStream in = PropertiesUtil.class.getResourceAsStream("/xmage.properties");
|
||||
if (in != null) {
|
||||
try {
|
||||
properties.load(in);
|
||||
} catch (IOException e) {
|
||||
logger.error("Couldn't load properties", e);
|
||||
}
|
||||
} else {
|
||||
logger.warn("No xmage.properties were found on classpath");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide constructor
|
||||
*/
|
||||
private PropertiesUtil() {
|
||||
|
||||
}
|
||||
|
||||
public static String getDBLogUrl() {
|
||||
String url = properties.getProperty(PropertyKeys.KEY_DB_LOG_URL, LOG_JDBC_URL);
|
||||
if (url != null) {
|
||||
return url.trim();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getDBFeedbackUrl() {
|
||||
String url = properties.getProperty(PropertyKeys.KEY_DB_FEEDBACK_URL, FEEDBACK_JDBC_URL);
|
||||
if (url != null) {
|
||||
return url.trim();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package mage.utils.properties;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public final class PropertyKeys {
|
||||
|
||||
public static final String KEY_DB_LOG_URL = "db.log.url";
|
||||
public static final String KEY_DB_FEEDBACK_URL = "db.feedback.url";
|
||||
}
|
||||
109
Mage.Common/src/main/java/mage/utils/timer/PriorityTimer.java
Normal file
109
Mage.Common/src/main/java/mage/utils/timer/PriorityTimer.java
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
package mage.utils.timer;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import mage.MageException;
|
||||
import mage.interfaces.Action;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public class PriorityTimer extends TimerTask {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(PriorityTimer.class);
|
||||
|
||||
private final long delay;
|
||||
private final Action taskOnTimeout;
|
||||
|
||||
private int count;
|
||||
private Action taskOnTick;
|
||||
private States state = States.NONE;
|
||||
|
||||
enum States {
|
||||
NONE,
|
||||
INIT,
|
||||
RUNNING,
|
||||
PAUSED,
|
||||
FINISHED
|
||||
}
|
||||
|
||||
public PriorityTimer(int count, long delay, Action taskOnTimeout) {
|
||||
this.count = count;
|
||||
this.delay = delay;
|
||||
this.taskOnTimeout = taskOnTimeout;
|
||||
}
|
||||
|
||||
public void init(UUID gameId) {
|
||||
state = States.INIT;
|
||||
Timer timer = new Timer("Priority Timer-" + gameId.toString(), false);
|
||||
long delayMs = delay * (int) (1000L / delay);
|
||||
timer.scheduleAtFixedRate(this, delayMs, delayMs);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (state == States.NONE) {
|
||||
throw new IllegalStateException("Timer should have been initialized first");
|
||||
}
|
||||
if (state == States.FINISHED) {
|
||||
throw new IllegalStateException("Timer has already finished its work");
|
||||
}
|
||||
state = States.RUNNING;
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
state = States.PAUSED;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
state = States.FINISHED;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
public void resume() {
|
||||
if (state == States.FINISHED) {
|
||||
throw new IllegalStateException("Timer has already finished its work");
|
||||
}
|
||||
state = States.RUNNING;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public void setTaskOnTick(Action taskOnTick) {
|
||||
this.taskOnTick = taskOnTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (state == States.RUNNING) {
|
||||
count--;
|
||||
if (taskOnTick != null) {
|
||||
try {
|
||||
taskOnTick.execute();
|
||||
} catch (MageException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Count is: " + count);
|
||||
}
|
||||
//System.out.println("Count is: " + count);
|
||||
if (count <= 0) {
|
||||
cancel();
|
||||
try {
|
||||
taskOnTimeout.execute();
|
||||
} catch (MageException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
68
Mage.Common/src/main/java/mage/view/AbilityPickerView.java
Normal file
68
Mage.Common/src/main/java/mage/view/AbilityPickerView.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class AbilityPickerView implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Map<UUID, String> choices = new LinkedHashMap<>();
|
||||
|
||||
public AbilityPickerView(String objectName, List<? extends Ability> abilities) {
|
||||
for (Ability ability : abilities) {
|
||||
if (objectName == null) {
|
||||
choices.put(ability.getId(), ability.getRule(true));
|
||||
} else {
|
||||
String rule = ability.getRule(objectName);
|
||||
if (rule.isEmpty()) {
|
||||
rule = ability.toString();
|
||||
}
|
||||
choices.put(ability.getId(), rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AbilityPickerView(Map<UUID, String> modes) {
|
||||
this.choices = modes;
|
||||
}
|
||||
|
||||
public Map<UUID, String> getChoices() {
|
||||
return choices;
|
||||
}
|
||||
}
|
||||
75
Mage.Common/src/main/java/mage/view/AbilityView.java
Normal file
75
Mage.Common/src/main/java/mage/view/AbilityView.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SuperType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class AbilityView extends CardView {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String sourceName;
|
||||
private final CardView sourceCard;
|
||||
|
||||
public AbilityView(Ability ability, String sourceName, CardView sourceCard) {
|
||||
this.id = ability.getId();
|
||||
this.name = "Ability";
|
||||
this.sourceName = sourceName;
|
||||
this.sourceCard = sourceCard;
|
||||
this.rules = new ArrayList<>();
|
||||
rules.add(ability.getRule());
|
||||
this.power = "";
|
||||
this.toughness = "";
|
||||
this.loyalty = "";
|
||||
this.cardTypes = EnumSet.noneOf(CardType.class);
|
||||
this.subTypes = new ArrayList<>();
|
||||
this.superTypes =EnumSet.noneOf(SuperType.class);
|
||||
this.color = new ObjectColor();
|
||||
this.manaCost = ability.getManaCosts().getSymbols();
|
||||
}
|
||||
|
||||
public CardView getSourceCard() {
|
||||
return this.sourceCard;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1031
Mage.Common/src/main/java/mage/view/CardView.java
Normal file
1031
Mage.Common/src/main/java/mage/view/CardView.java
Normal file
File diff suppressed because it is too large
Load diff
178
Mage.Common/src/main/java/mage/view/CardsView.java
Normal file
178
Mage.Common/src/main/java/mage/view/CardsView.java
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.command.Emblem;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentToken;
|
||||
import mage.target.targetpointer.TargetPointer;
|
||||
import mage.util.GameLog;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CardsView extends LinkedHashMap<UUID, CardView> {
|
||||
|
||||
public CardsView() {
|
||||
}
|
||||
|
||||
public CardsView(Collection<? extends Card> cards) {
|
||||
for (Card card : cards) {
|
||||
this.put(card.getId(), new CardView(card));
|
||||
}
|
||||
}
|
||||
|
||||
public CardsView(Game game, Collection<? extends Card> cards) {
|
||||
for (Card card : cards) {
|
||||
this.put(card.getId(), new CardView(card, game, false));
|
||||
}
|
||||
}
|
||||
|
||||
public CardsView(Game game, Collection<? extends Card> cards, boolean showFaceDown, boolean storeZone) {
|
||||
for (Card card : cards) {
|
||||
this.put(card.getId(), new CardView(card, game, false, showFaceDown, storeZone));
|
||||
}
|
||||
}
|
||||
|
||||
public CardsView(Collection<? extends Ability> abilities, Game game) {
|
||||
for (Ability ability : abilities) {
|
||||
MageObject sourceObject = null;
|
||||
AbilityView abilityView = null;
|
||||
boolean isCard = false;
|
||||
boolean isPermanent = false;
|
||||
switch (ability.getZone()) {
|
||||
case ALL:
|
||||
case EXILED:
|
||||
case GRAVEYARD:
|
||||
sourceObject = game.getCard(ability.getSourceId());
|
||||
if (sourceObject == null) {
|
||||
sourceObject = game.getPermanent(ability.getSourceId());
|
||||
}
|
||||
if (sourceObject == null) {
|
||||
sourceObject = game.getObject(ability.getSourceId());
|
||||
if (sourceObject instanceof PermanentToken) {
|
||||
isPermanent = true;
|
||||
}
|
||||
} else {
|
||||
isCard = true;
|
||||
}
|
||||
break;
|
||||
case BATTLEFIELD:
|
||||
sourceObject = game.getPermanent(ability.getSourceId());
|
||||
if (sourceObject == null) {
|
||||
sourceObject = (Permanent) game.getLastKnownInformation(ability.getSourceId(), Zone.BATTLEFIELD);
|
||||
}
|
||||
isPermanent = true;
|
||||
break;
|
||||
case STACK:
|
||||
sourceObject = game.getObject(ability.getSourceId());
|
||||
if (sourceObject instanceof Card) {
|
||||
isCard = true;
|
||||
}
|
||||
break;
|
||||
case COMMAND:
|
||||
sourceObject = game.getObject(ability.getSourceId());
|
||||
if (sourceObject instanceof Emblem) {
|
||||
// Card sourceCard = (Card) ((Emblem) sourceObject).getSourceObject();
|
||||
// if (sourceCard == null) {
|
||||
// throw new IllegalArgumentException("Source card for emblem not found.");
|
||||
// }
|
||||
abilityView = new AbilityView(ability, sourceObject.getName(), new CardView(new EmblemView((Emblem) sourceObject)));
|
||||
abilityView.setName(((Emblem) sourceObject).getName());
|
||||
// abilityView.setExpansionSetCode(sourceCard.getExpansionSetCode());
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (sourceObject != null) {
|
||||
if (abilityView == null) {
|
||||
CardView sourceCardView;
|
||||
if (isPermanent) {
|
||||
sourceCardView = new CardView((Permanent) sourceObject);
|
||||
} else if (isCard) {
|
||||
sourceCardView = new CardView((Card) sourceObject);
|
||||
} else {
|
||||
sourceCardView = new CardView(sourceObject);
|
||||
}
|
||||
abilityView = new AbilityView(ability, sourceObject.getName(), sourceCardView);
|
||||
}
|
||||
if (!ability.getTargets().isEmpty()) {
|
||||
abilityView.setTargets(ability.getTargets());
|
||||
} else {
|
||||
List<UUID> abilityTargets = new ArrayList<>();
|
||||
for (Effect effect : ability.getEffects()) {
|
||||
TargetPointer targetPointer = effect.getTargetPointer();
|
||||
if (targetPointer != null) {
|
||||
List<UUID> targetList = targetPointer.getTargets(game, ability);
|
||||
abilityTargets.addAll(targetList);
|
||||
}
|
||||
}
|
||||
if (!abilityTargets.isEmpty()) {
|
||||
abilityView.overrideTargets(abilityTargets);
|
||||
List<String> names = new ArrayList<>();
|
||||
for (UUID uuid : abilityTargets) {
|
||||
MageObject mageObject = game.getObject(uuid);
|
||||
if (mageObject != null) {
|
||||
if ((mageObject instanceof Card) && ((Card) mageObject).isFaceDown(game)) {
|
||||
continue;
|
||||
}
|
||||
names.add(GameLog.getColoredObjectIdNameForTooltip(mageObject));
|
||||
}
|
||||
}
|
||||
if (!names.isEmpty()) {
|
||||
abilityView.getRules().add("<i>Related objects: " + names.toString() + "</i>");
|
||||
}
|
||||
}
|
||||
}
|
||||
this.put(ability.getId(), abilityView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CardsView(Collection<? extends Ability> abilities, GameState state) {
|
||||
for (Ability ability : abilities) {
|
||||
Card sourceCard = state.getPermanent(ability.getSourceId());
|
||||
if (sourceCard != null) {
|
||||
this.put(ability.getId(), new AbilityView(ability, sourceCard.getName(), new CardView(sourceCard)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
108
Mage.Common/src/main/java/mage/view/ChatMessage.java
Normal file
108
Mage.Common/src/main/java/mage/view/ChatMessage.java
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ChatMessage implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String username;
|
||||
private String time;
|
||||
private String message;
|
||||
private MessageColor color;
|
||||
private SoundToPlay soundToPlay;
|
||||
private MessageType messageType;
|
||||
|
||||
public enum MessageColor {
|
||||
BLACK, RED, GREEN, BLUE, ORANGE, YELLOW
|
||||
}
|
||||
|
||||
public enum MessageType {
|
||||
USER_INFO, STATUS, GAME, TALK, WHISPER_FROM, WHISPER_TO
|
||||
}
|
||||
|
||||
public enum SoundToPlay {
|
||||
PlayerLeft, PlayerQuitTournament, PlayerSubmittedDeck, PlayerWhispered
|
||||
}
|
||||
|
||||
public ChatMessage(String username, String message, String time, MessageColor color) {
|
||||
this(username, message, time, color, null);
|
||||
}
|
||||
|
||||
public ChatMessage(String username, String message, String time, MessageColor color, SoundToPlay soundToPlay) {
|
||||
this(username, message, time, color, MessageType.TALK, soundToPlay);
|
||||
}
|
||||
|
||||
public ChatMessage(String username, String message, String time, MessageColor color, MessageType messageType, SoundToPlay soundToPlay) {
|
||||
this.username = username;
|
||||
this.message = message;
|
||||
this.time = time;
|
||||
this.color = color;
|
||||
this.messageType = messageType;
|
||||
this.soundToPlay = soundToPlay;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public MessageColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public boolean isUserMessage() {
|
||||
return color != null && (color==MessageColor.BLUE || color==MessageColor.YELLOW);
|
||||
}
|
||||
|
||||
public boolean isStatusMessage() {
|
||||
return color != null && color== MessageColor.ORANGE;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public SoundToPlay getSoundToPlay() {
|
||||
return soundToPlay;
|
||||
}
|
||||
|
||||
public MessageType getMessageType() {
|
||||
return messageType;
|
||||
}
|
||||
|
||||
}
|
||||
92
Mage.Common/src/main/java/mage/view/CombatGroupView.java
Normal file
92
Mage.Common/src/main/java/mage/view/CombatGroupView.java
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import mage.game.Game;
|
||||
import mage.game.combat.CombatGroup;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CombatGroupView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final CardsView attackers = new CardsView();
|
||||
private final CardsView blockers = new CardsView();
|
||||
private String defenderName = "";
|
||||
private final UUID defenderId;
|
||||
|
||||
public CombatGroupView(CombatGroup combatGroup, Game game) {
|
||||
Player player = game.getPlayer(combatGroup.getDefenderId());
|
||||
if (player != null) {
|
||||
this.defenderName = player.getName();
|
||||
}
|
||||
else {
|
||||
Permanent perm = game.getPermanent(combatGroup.getDefenderId());
|
||||
if (perm != null) {
|
||||
this.defenderName = perm.getName();
|
||||
}
|
||||
}
|
||||
this.defenderId = combatGroup.getDefenderId();
|
||||
for (UUID id: combatGroup.getAttackers()) {
|
||||
Permanent attacker = game.getPermanent(id);
|
||||
if (attacker != null) {
|
||||
attackers.put(id, new PermanentView(attacker, game.getCard(attacker.getId()),null, game));
|
||||
}
|
||||
}
|
||||
for (UUID id: combatGroup.getBlockerOrder()) {
|
||||
Permanent blocker = game.getPermanent(id);
|
||||
if (blocker != null) {
|
||||
blockers.put(id, new PermanentView(blocker, game.getCard(blocker.getId()), null, game));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getDefenderName() {
|
||||
return defenderName;
|
||||
}
|
||||
|
||||
public CardsView getAttackers() {
|
||||
return attackers;
|
||||
}
|
||||
|
||||
public CardsView getBlockers() {
|
||||
return blockers;
|
||||
}
|
||||
|
||||
public UUID getDefenderId() {
|
||||
return defenderId;
|
||||
}
|
||||
}
|
||||
47
Mage.Common/src/main/java/mage/view/CommandObjectView.java
Normal file
47
Mage.Common/src/main/java/mage/view/CommandObjectView.java
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Plopman
|
||||
*/
|
||||
public interface CommandObjectView extends Serializable {
|
||||
public String getExpansionSetCode();
|
||||
|
||||
public String getName();
|
||||
|
||||
public UUID getId();
|
||||
|
||||
public List<String> getRules();
|
||||
}
|
||||
46
Mage.Common/src/main/java/mage/view/CommanderView.java
Normal file
46
Mage.Common/src/main/java/mage/view/CommanderView.java
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.MageObjectType;
|
||||
import mage.game.Game;
|
||||
import mage.game.command.Commander;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Plopman
|
||||
*/
|
||||
public class CommanderView extends CardView implements CommandObjectView, Serializable{
|
||||
|
||||
public CommanderView(Commander commander, Card sourceCard, Game game) {
|
||||
super(sourceCard, game, false);
|
||||
this.mageObjectType = MageObjectType.COMMANDER;
|
||||
}
|
||||
}
|
||||
73
Mage.Common/src/main/java/mage/view/CounterView.java
Normal file
73
Mage.Common/src/main/java/mage/view/CounterView.java
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.counters.Counter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CounterView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String name;
|
||||
private int count;
|
||||
|
||||
public CounterView(Counter counter) {
|
||||
this.name = counter.getName();
|
||||
this.count = counter.getCount();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == this) {
|
||||
return true;
|
||||
}
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(other instanceof CounterView)) {
|
||||
return false;
|
||||
}
|
||||
CounterView oth = (CounterView)other;
|
||||
return
|
||||
(count == oth.count) &&
|
||||
(name.equals(oth.name));
|
||||
}
|
||||
}
|
||||
59
Mage.Common/src/main/java/mage/view/DeckView.java
Normal file
59
Mage.Common/src/main/java/mage/view/DeckView.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.cards.decks.Deck;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
public class DeckView implements Serializable {
|
||||
|
||||
private final String name;
|
||||
private final SimpleCardsView cards;
|
||||
private final SimpleCardsView sideboard;
|
||||
|
||||
public DeckView(Deck deck) {
|
||||
name = deck.getName();
|
||||
cards = new SimpleCardsView(deck.getCards(), false);
|
||||
sideboard = new SimpleCardsView(deck.getSideboard(), false);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public SimpleCardsView getCards() {
|
||||
return cards;
|
||||
}
|
||||
|
||||
public SimpleCardsView getSideboard() {
|
||||
return sideboard;
|
||||
}
|
||||
}
|
||||
64
Mage.Common/src/main/java/mage/view/DraftClientMessage.java
Normal file
64
Mage.Common/src/main/java/mage/view/DraftClientMessage.java
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class DraftClientMessage implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private DraftView draftView;
|
||||
private DraftPickView draftPickView;
|
||||
private String message;
|
||||
|
||||
public DraftClientMessage(DraftView draftView) {
|
||||
this.draftView = draftView;
|
||||
}
|
||||
|
||||
public DraftClientMessage(DraftPickView draftPickView) {
|
||||
this.draftPickView = draftPickView;
|
||||
}
|
||||
|
||||
public DraftClientMessage(DraftView draftView, String message) {
|
||||
this.message = message;
|
||||
this.draftView = draftView;
|
||||
}
|
||||
|
||||
public DraftPickView getDraftPickView() {
|
||||
return draftPickView;
|
||||
}
|
||||
|
||||
public DraftView getDraftView() {
|
||||
return draftView;
|
||||
}
|
||||
}
|
||||
68
Mage.Common/src/main/java/mage/view/DraftPickView.java
Normal file
68
Mage.Common/src/main/java/mage/view/DraftPickView.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.game.draft.DraftPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class DraftPickView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected SimpleCardsView booster;
|
||||
protected SimpleCardsView picks;
|
||||
protected boolean picking;
|
||||
protected int timeout;
|
||||
|
||||
public DraftPickView(DraftPlayer player, int timeout) {
|
||||
this.booster = new SimpleCardsView(player.getBooster(), false);
|
||||
this.picks = new SimpleCardsView(player.getDeck().getSideboard(), false);
|
||||
this.picking = player.isPicking();
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public SimpleCardsView getBooster() {
|
||||
return booster;
|
||||
}
|
||||
|
||||
public SimpleCardsView getPicks() {
|
||||
return picks;
|
||||
}
|
||||
|
||||
public boolean isPicking() {
|
||||
return this.picking;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
}
|
||||
82
Mage.Common/src/main/java/mage/view/DraftView.java
Normal file
82
Mage.Common/src/main/java/mage/view/DraftView.java
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.draft.DraftPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class DraftView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final List<String> sets = new ArrayList<>();
|
||||
private final int boosterNum;
|
||||
private final int cardNum;
|
||||
private final List<String> players = new ArrayList<>();
|
||||
|
||||
public DraftView(Draft draft) {
|
||||
if (draft.getDraftCube() != null) {
|
||||
for (int i = 0; i < draft.getNumberBoosters(); i++) {
|
||||
sets.add(draft.getDraftCube().getName());
|
||||
}
|
||||
} else {
|
||||
for (ExpansionSet set: draft.getSets()) {
|
||||
sets.add(set.getName());
|
||||
}
|
||||
}
|
||||
this.boosterNum = draft.getBoosterNum();
|
||||
this.cardNum = draft.getCardNum();
|
||||
for(DraftPlayer draftPlayer :draft.getPlayers()) {
|
||||
players.add(draftPlayer.getPlayer().getName());
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getSets() {
|
||||
return sets;
|
||||
}
|
||||
|
||||
public List<String> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
public int getBoosterNum() {
|
||||
return boosterNum;
|
||||
}
|
||||
|
||||
public int getCardNum() {
|
||||
return cardNum;
|
||||
}
|
||||
}
|
||||
57
Mage.Common/src/main/java/mage/view/EmblemView.java
Normal file
57
Mage.Common/src/main/java/mage/view/EmblemView.java
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.cards.Card;
|
||||
import mage.game.command.Emblem;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public class EmblemView implements CommandObjectView, Serializable {
|
||||
|
||||
protected UUID id;
|
||||
protected String name;
|
||||
protected String expansionSetCode;
|
||||
protected List<String> rules;
|
||||
|
||||
public EmblemView(Emblem emblem, Card sourceCard) {
|
||||
id = emblem.getId();
|
||||
name = "Emblem " + sourceCard.getName();
|
||||
if (emblem.getExpansionSetCodeForImage() == null) {
|
||||
expansionSetCode = sourceCard.getExpansionSetCode();
|
||||
} else {
|
||||
expansionSetCode = emblem.getExpansionSetCodeForImage();
|
||||
}
|
||||
|
||||
rules = emblem.getAbilities().getRules(sourceCard.getName());
|
||||
}
|
||||
|
||||
public EmblemView(Emblem emblem) {
|
||||
id = emblem.getId();
|
||||
name = emblem.getName();
|
||||
expansionSetCode = emblem.getExpansionSetCodeForImage();
|
||||
rules = emblem.getAbilities().getRules(emblem.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpansionSetCode() {
|
||||
return expansionSetCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRules() {
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
62
Mage.Common/src/main/java/mage/view/ExileView.java
Normal file
62
Mage.Common/src/main/java/mage/view/ExileView.java
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.cards.Card;
|
||||
import mage.game.ExileZone;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ExileView extends CardsView {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String name;
|
||||
private final UUID id;
|
||||
|
||||
public ExileView(ExileZone exileZone, Game game) {
|
||||
this.name = exileZone.getName();
|
||||
this.id = exileZone.getId();
|
||||
for (Card card: exileZone.getCards(game)) {
|
||||
this.put(card.getId(), new CardView(card, game, false));
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
158
Mage.Common/src/main/java/mage/view/GameClientMessage.java
Normal file
158
Mage.Common/src/main/java/mage/view/GameClientMessage.java
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.choices.Choice;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class GameClientMessage implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private GameView gameView;
|
||||
private CardsView cardsView;
|
||||
private CardsView cardsView2;
|
||||
private String message;
|
||||
private boolean flag;
|
||||
private String[] strings;
|
||||
private Set<UUID> targets;
|
||||
private int min;
|
||||
private int max;
|
||||
private Map<String, Serializable> options;
|
||||
private Choice choice;
|
||||
|
||||
public GameClientMessage(GameView gameView) {
|
||||
this.gameView = gameView;
|
||||
}
|
||||
|
||||
public GameClientMessage(GameView gameView, String message) {
|
||||
this.gameView = gameView;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public GameClientMessage(GameView gameView, String message, Map<String, Serializable> options) {
|
||||
this.gameView = gameView;
|
||||
this.message = message;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
private GameClientMessage(GameView gameView, String question, CardsView cardView, Set<UUID> targets, boolean required) {
|
||||
this.gameView = gameView;
|
||||
this.message = question;
|
||||
this.cardsView = cardView;
|
||||
this.targets = targets;
|
||||
this.flag = required;
|
||||
}
|
||||
|
||||
public GameClientMessage(GameView gameView, String question, CardsView cardView, Set<UUID> targets, boolean required, Map<String, Serializable> options) {
|
||||
this(gameView, question, cardView, targets, required);
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public GameClientMessage(String[] choices, String message) {
|
||||
this.strings = choices;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public GameClientMessage(String message, int min, int max) {
|
||||
this.message = message;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public GameClientMessage(String message, CardsView pile1, CardsView pile2) {
|
||||
this.message = message;
|
||||
this.cardsView = pile1;
|
||||
this.cardsView2 = pile2;
|
||||
}
|
||||
|
||||
public GameClientMessage(CardsView cardView, String name) {
|
||||
this.cardsView = cardView;
|
||||
this.message = name;
|
||||
}
|
||||
|
||||
public GameClientMessage(Choice choice) {
|
||||
this.choice = choice;
|
||||
}
|
||||
|
||||
public GameView getGameView() {
|
||||
return gameView;
|
||||
}
|
||||
|
||||
public CardsView getCardsView() {
|
||||
return cardsView;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean isFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public String[] getStrings() {
|
||||
return strings;
|
||||
}
|
||||
|
||||
public Set<UUID> getTargets() {
|
||||
return targets;
|
||||
}
|
||||
|
||||
public CardsView getPile1() {
|
||||
return cardsView;
|
||||
}
|
||||
|
||||
public CardsView getPile2() {
|
||||
return cardsView2;
|
||||
}
|
||||
|
||||
public int getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public Map<String, Serializable> getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
public Choice getChoice() {
|
||||
return choice;
|
||||
}
|
||||
|
||||
}
|
||||
184
Mage.Common/src/main/java/mage/view/GameEndView.java
Normal file
184
Mage.Common/src/main/java/mage/view/GameEndView.java
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.Table;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class GameEndView implements Serializable {
|
||||
|
||||
private PlayerView clientPlayer = null;
|
||||
private final List<PlayerView> players = new ArrayList<>();
|
||||
private final Date startTime;
|
||||
private final Date endTime;
|
||||
private String gameInfo;
|
||||
private final String matchInfo;
|
||||
private final String additionalInfo;
|
||||
private boolean won;
|
||||
private final MatchView matchView;
|
||||
private int wins;
|
||||
private int loses;
|
||||
private final int winsNeeded;
|
||||
|
||||
public GameEndView(GameState state, Game game, UUID playerId, Table table) {
|
||||
startTime = game.getStartTime();
|
||||
endTime = game.getEndTime();
|
||||
|
||||
// set result message
|
||||
int winner = 0;
|
||||
Player you = null;
|
||||
for (Player player: state.getPlayers().values()) {
|
||||
PlayerView playerView = new PlayerView(player, state, game, playerId, null);
|
||||
if (playerView.getPlayerId().equals(playerId)) {
|
||||
clientPlayer = playerView;
|
||||
you = player;
|
||||
won = you.hasWon(); // needed to control image
|
||||
}
|
||||
players.add(playerView);
|
||||
if (player.hasWon()) {
|
||||
winner++;
|
||||
}
|
||||
}
|
||||
if (you != null) {
|
||||
if (you.hasWon()) {
|
||||
gameInfo = new StringBuilder("You won the game on turn ").append(game.getTurnNum()).append('.').toString();
|
||||
} else if (winner > 0) {
|
||||
gameInfo = new StringBuilder("You lost the game on turn ").append(game.getTurnNum()).append('.').toString();
|
||||
} else {
|
||||
gameInfo = new StringBuilder("Game is a draw on Turn ").append(game.getTurnNum()).append('.').toString();
|
||||
}
|
||||
}
|
||||
matchView = new MatchView(table);
|
||||
|
||||
Match match = table.getMatch();
|
||||
MatchPlayer matchWinner = null;
|
||||
winsNeeded = match.getOptions().getWinsNeeded();
|
||||
StringBuilder additonalText = new StringBuilder();
|
||||
for (MatchPlayer matchPlayer: match.getPlayers()) {
|
||||
if (matchPlayer.getPlayer().equals(you)) {
|
||||
wins = matchPlayer.getWins();
|
||||
}
|
||||
if (matchPlayer.isMatchWinner()) {
|
||||
matchWinner = matchPlayer;
|
||||
}
|
||||
if (matchPlayer.getPlayer().hasTimerTimeout()) {
|
||||
if (matchPlayer.getPlayer().equals(you)) {
|
||||
additonalText.append("You run out of time. ");
|
||||
} else {
|
||||
additonalText.append(matchPlayer.getName()).append(" runs out of time. ");
|
||||
}
|
||||
} else if (matchPlayer.getPlayer().hasIdleTimeout()) {
|
||||
if (matchPlayer.getPlayer().equals(you)) {
|
||||
additonalText.append("You lost the match for being idle. ");
|
||||
} else {
|
||||
additonalText.append(matchPlayer.getName()).append(" lost for being idle. ");
|
||||
}
|
||||
} else if (matchPlayer.hasQuit()) {
|
||||
if (matchPlayer.getPlayer().equals(you)) {
|
||||
additonalText.append("You have quit the match. ");
|
||||
} else {
|
||||
additonalText.append(matchPlayer.getName()).append(" has quit the match. ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (matchWinner != null) {
|
||||
if (matchWinner.getPlayer().equals(you)) {
|
||||
matchInfo = "You won the match!";
|
||||
} else {
|
||||
matchInfo = new StringBuilder(matchWinner.getName()).append(" won the match!").toString();
|
||||
}
|
||||
} else {
|
||||
matchInfo = new StringBuilder("You need ").append(winsNeeded - wins == 1 ? "one more win ":winsNeeded - wins + " more wins ").append("to win the match.").toString();
|
||||
}
|
||||
additionalInfo = additonalText.toString();
|
||||
|
||||
}
|
||||
|
||||
public Date getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public Date getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public List<PlayerView> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
public String getGameInfo() {
|
||||
return gameInfo;
|
||||
}
|
||||
|
||||
public String getMatchInfo() {
|
||||
return matchInfo;
|
||||
}
|
||||
|
||||
public String getAdditionalInfo() {
|
||||
return additionalInfo;
|
||||
}
|
||||
|
||||
public boolean hasWon() {
|
||||
return won;
|
||||
}
|
||||
|
||||
public MatchView getMatchView() {
|
||||
return matchView;
|
||||
}
|
||||
|
||||
public int getWins() {
|
||||
return wins;
|
||||
}
|
||||
|
||||
public int getLoses() {
|
||||
return loses;
|
||||
}
|
||||
|
||||
public int getWinsNeeded() {
|
||||
return winsNeeded;
|
||||
}
|
||||
|
||||
public PlayerView getClientPlayer() {
|
||||
return clientPlayer;
|
||||
}
|
||||
|
||||
}
|
||||
93
Mage.Common/src/main/java/mage/view/GameTypeView.java
Normal file
93
Mage.Common/src/main/java/mage/view/GameTypeView.java
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.game.match.MatchType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class GameTypeView extends Object implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String name;
|
||||
private final int minPlayers;
|
||||
private final int maxPlayers;
|
||||
private final int numTeams;
|
||||
private final int playersPerTeam;
|
||||
private final boolean useRange;
|
||||
private final boolean useAttackOption;
|
||||
|
||||
public GameTypeView(MatchType gameType) {
|
||||
this.name = gameType.getName();
|
||||
this.minPlayers = gameType.getMinPlayers();
|
||||
this.maxPlayers = gameType.getMaxPlayers();
|
||||
this.numTeams = gameType.getNumTeams();
|
||||
this.playersPerTeam = gameType.getPlayersPerTeam();
|
||||
this.useAttackOption = gameType.isUseAttackOption();
|
||||
this.useRange = gameType.isUseRange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getMinPlayers() {
|
||||
return minPlayers;
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
public int getNumTeams() {
|
||||
return numTeams;
|
||||
}
|
||||
|
||||
public int getPlayersPerTeam() {
|
||||
return playersPerTeam;
|
||||
}
|
||||
|
||||
public boolean isUseRange() {
|
||||
return useRange;
|
||||
}
|
||||
|
||||
public boolean isUseAttackOption() {
|
||||
return useAttackOption;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
354
Mage.Common/src/main/java/mage/view/GameView.java
Normal file
354
Mage.Common/src/main/java/mage/view/GameView.java
Normal file
|
|
@ -0,0 +1,354 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.TurnPhase;
|
||||
import mage.constants.Zone;
|
||||
import mage.designations.Designation;
|
||||
import mage.game.ExileZone;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.combat.CombatGroup;
|
||||
import mage.game.command.Emblem;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
import mage.game.permanent.PermanentToken;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.game.stack.StackAbility;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.players.Player;
|
||||
import mage.watchers.common.CastSpellLastTurnWatcher;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class GameView implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(GameView.class);
|
||||
|
||||
private final int priorityTime;
|
||||
private final List<PlayerView> players = new ArrayList<>();
|
||||
private CardsView hand;
|
||||
private Set<UUID> canPlayInHand;
|
||||
private Map<String, SimpleCardsView> opponentHands;
|
||||
private Map<String, SimpleCardsView> watchedHands;
|
||||
private final CardsView stack = new CardsView();
|
||||
private final List<ExileView> exiles = new ArrayList<>();
|
||||
private final List<RevealedView> revealed = new ArrayList<>();
|
||||
private List<LookedAtView> lookedAt = new ArrayList<>();
|
||||
private final List<CombatGroupView> combat = new ArrayList<>();
|
||||
private final TurnPhase phase;
|
||||
private final PhaseStep step;
|
||||
private final UUID activePlayerId;
|
||||
private String activePlayerName = "";
|
||||
private String priorityPlayerName;
|
||||
private final int turn;
|
||||
private boolean special = false;
|
||||
private final boolean isPlayer; // false = watching user
|
||||
private final int spellsCastCurrentTurn;
|
||||
private final boolean rollbackTurnsAllowed;
|
||||
|
||||
public GameView(GameState state, Game game, UUID createdForPlayerId, UUID watcherUserId) {
|
||||
Player createdForPlayer = null;
|
||||
this.isPlayer = createdForPlayerId != null;
|
||||
this.priorityTime = game.getPriorityTime();
|
||||
for (Player player : state.getPlayers().values()) {
|
||||
players.add(new PlayerView(player, state, game, createdForPlayerId, watcherUserId));
|
||||
if (player.getId().equals(createdForPlayerId)) {
|
||||
createdForPlayer = player;
|
||||
}
|
||||
}
|
||||
for (StackObject stackObject : state.getStack()) {
|
||||
if (stackObject instanceof StackAbility) {
|
||||
// Stack Ability
|
||||
MageObject object = game.getObject(stackObject.getSourceId());
|
||||
Card card = game.getCard(stackObject.getSourceId());
|
||||
if (card == null && (object instanceof PermanentCard)) {
|
||||
card = ((PermanentCard) object).getCard();
|
||||
}
|
||||
if (card != null) {
|
||||
if (object != null) {
|
||||
if (object instanceof Permanent) {
|
||||
boolean controlled = ((Permanent) object).getControllerId().equals(createdForPlayerId);
|
||||
stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, ((Permanent) object).getName(), new CardView(((Permanent) object), game, controlled, false, false)));
|
||||
} else {
|
||||
stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, card.getName(), new CardView(card, game, false, false, false)));
|
||||
}
|
||||
} else {
|
||||
stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, "", new CardView(card)));
|
||||
}
|
||||
if (card.isTransformable()) {
|
||||
updateLatestCardView(game, card, stackObject.getId());
|
||||
}
|
||||
checkPaid(stackObject.getId(), (StackAbility) stackObject);
|
||||
} else if (object != null) {
|
||||
if (object instanceof PermanentToken) {
|
||||
PermanentToken token = (PermanentToken) object;
|
||||
stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, token.getName(), new CardView(token)));
|
||||
checkPaid(stackObject.getId(), (StackAbility) stackObject);
|
||||
} else if (object instanceof Emblem) {
|
||||
CardView cardView = new CardView(new EmblemView((Emblem) object));
|
||||
// Card sourceCard = (Card) ((Emblem) object).getSourceObject();
|
||||
((StackAbility) stackObject).setName(((Emblem) object).getName());
|
||||
// ((StackAbility) stackObject).setExpansionSetCode(sourceCard.getExpansionSetCode());
|
||||
stack.put(stackObject.getId(),
|
||||
new StackAbilityView(game, (StackAbility) stackObject, object.getName(), cardView));
|
||||
checkPaid(stackObject.getId(), ((StackAbility) stackObject));
|
||||
} else if (object instanceof Designation) {
|
||||
Designation designation = (Designation) game.getObject(object.getId());
|
||||
if (designation != null) {
|
||||
stack.put(stackObject.getId(), new CardView(designation, (StackAbility) stackObject));
|
||||
} else {
|
||||
LOGGER.fatal("Designation object not found: " + object.getName() + ' ' + object.toString() + ' ' + object.getClass().toString());
|
||||
}
|
||||
|
||||
} else if (object instanceof StackAbility) {
|
||||
StackAbility stackAbility = ((StackAbility) object);
|
||||
stackAbility.newId();
|
||||
stack.put(stackObject.getId(), new CardView(((StackAbility) stackObject)));
|
||||
checkPaid(stackObject.getId(), ((StackAbility) stackObject));
|
||||
} else {
|
||||
LOGGER.fatal("Object can't be cast to StackAbility: " + object.getName() + ' ' + object.toString() + ' ' + object.getClass().toString());
|
||||
}
|
||||
} else {
|
||||
// can happen if a player times out while ability is on the stack
|
||||
LOGGER.debug("Stack Object for stack ability not found: " + stackObject.getStackAbility().getRule());
|
||||
}
|
||||
} else {
|
||||
// Spell
|
||||
stack.put(stackObject.getId(), new CardView((Spell) stackObject, game, stackObject.getControllerId().equals(createdForPlayerId)));
|
||||
checkPaid(stackObject.getId(), (Spell) stackObject);
|
||||
}
|
||||
//stackOrder.add(stackObject.getId());
|
||||
}
|
||||
//Collections.reverse(stackOrder);
|
||||
for (ExileZone exileZone : state.getExile().getExileZones()) {
|
||||
exiles.add(new ExileView(exileZone, game));
|
||||
}
|
||||
for (String name : state.getRevealed().keySet()) {
|
||||
revealed.add(new RevealedView(name, state.getRevealed().get(name), game));
|
||||
}
|
||||
this.phase = state.getTurn().getPhaseType();
|
||||
this.step = state.getTurn().getStepType();
|
||||
this.turn = state.getTurnNum();
|
||||
this.activePlayerId = state.getActivePlayerId();
|
||||
if (state.getActivePlayerId() != null) {
|
||||
this.activePlayerName = state.getPlayer(state.getActivePlayerId()).getName();
|
||||
} else {
|
||||
this.activePlayerName = "";
|
||||
}
|
||||
Player priorityPlayer = null;
|
||||
if (state.getPriorityPlayerId() != null) {
|
||||
priorityPlayer = state.getPlayer(state.getPriorityPlayerId());
|
||||
this.priorityPlayerName = priorityPlayer != null ? priorityPlayer.getName() : "";
|
||||
} else {
|
||||
this.priorityPlayerName = "";
|
||||
}
|
||||
for (CombatGroup combatGroup : state.getCombat().getGroups()) {
|
||||
combat.add(new CombatGroupView(combatGroup, game));
|
||||
}
|
||||
if (isPlayer) { // no watcher
|
||||
// has only to be set for active player with priority (e.g. pay mana by delve or Quenchable Fire special action)
|
||||
if (priorityPlayer != null && createdForPlayer != null && createdForPlayerId != null && createdForPlayer.isGameUnderControl()
|
||||
&& (createdForPlayerId.equals(priorityPlayer.getId()) // player controls the turn
|
||||
|| createdForPlayer.getPlayersUnderYourControl().contains(priorityPlayer.getId()))) { // player controls active players turn
|
||||
this.special = !state.getSpecialActions().getControlledBy(priorityPlayer.getId(), priorityPlayer.isInPayManaMode()).isEmpty();
|
||||
}
|
||||
} else {
|
||||
this.special = false;
|
||||
}
|
||||
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getName());
|
||||
if (watcher != null) {
|
||||
spellsCastCurrentTurn = watcher.getAmountOfSpellsAllPlayersCastOnCurrentTurn();
|
||||
} else {
|
||||
spellsCastCurrentTurn = 0;
|
||||
}
|
||||
rollbackTurnsAllowed = game.getOptions().rollbackTurnsAllowed;
|
||||
}
|
||||
|
||||
private void checkPaid(UUID uuid, StackAbility stackAbility) {
|
||||
for (Cost cost : stackAbility.getManaCostsToPay()) {
|
||||
if (!cost.isPaid()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
CardView cardView = stack.get(uuid);
|
||||
cardView.paid = true;
|
||||
}
|
||||
|
||||
private void checkPaid(UUID uuid, Spell spell) {
|
||||
for (Cost cost : spell.getSpellAbility().getManaCostsToPay()) {
|
||||
if (!cost.isPaid()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
CardView cardView = stack.get(uuid);
|
||||
cardView.paid = true;
|
||||
}
|
||||
|
||||
private void setPaid(UUID uuid) {
|
||||
CardView cardView = stack.get(uuid);
|
||||
cardView.paid = true;
|
||||
}
|
||||
|
||||
private void updateLatestCardView(Game game, Card card, UUID stackId) {
|
||||
if (!card.isTransformable()) {
|
||||
return;
|
||||
}
|
||||
Permanent permanent = game.getPermanent(card.getId());
|
||||
if (permanent == null) {
|
||||
permanent = (Permanent) game.getLastKnownInformation(card.getId(), Zone.BATTLEFIELD);
|
||||
}
|
||||
if (permanent != null) {
|
||||
if (permanent.isTransformed()) {
|
||||
StackAbilityView stackAbilityView = (StackAbilityView) stack.get(stackId);
|
||||
stackAbilityView.getSourceCard().setTransformed(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<PlayerView> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
public CardsView getHand() {
|
||||
return hand;
|
||||
}
|
||||
|
||||
public void setHand(CardsView hand) {
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
public Map<String, SimpleCardsView> getOpponentHands() {
|
||||
return opponentHands;
|
||||
}
|
||||
|
||||
public void setOpponentHands(Map<String, SimpleCardsView> opponentHands) {
|
||||
this.opponentHands = opponentHands;
|
||||
}
|
||||
|
||||
public Map<String, SimpleCardsView> getWatchedHands() {
|
||||
return watchedHands;
|
||||
}
|
||||
|
||||
public void setWatchedHands(Map<String, SimpleCardsView> watchedHands) {
|
||||
this.watchedHands = watchedHands;
|
||||
}
|
||||
|
||||
public TurnPhase getPhase() {
|
||||
return phase;
|
||||
}
|
||||
|
||||
public PhaseStep getStep() {
|
||||
return step;
|
||||
}
|
||||
|
||||
public CardsView getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
public List<ExileView> getExile() {
|
||||
return exiles;
|
||||
}
|
||||
|
||||
public List<RevealedView> getRevealed() {
|
||||
return revealed;
|
||||
}
|
||||
|
||||
public List<LookedAtView> getLookedAt() {
|
||||
return lookedAt;
|
||||
}
|
||||
|
||||
public void setLookedAt(List<LookedAtView> list) {
|
||||
this.lookedAt = list;
|
||||
}
|
||||
|
||||
public List<CombatGroupView> getCombat() {
|
||||
return combat;
|
||||
}
|
||||
|
||||
public int getTurn() {
|
||||
return this.turn;
|
||||
}
|
||||
|
||||
public String getActivePlayerName() {
|
||||
return activePlayerName;
|
||||
}
|
||||
|
||||
public String getPriorityPlayerName() {
|
||||
return priorityPlayerName;
|
||||
}
|
||||
|
||||
public boolean getSpecial() {
|
||||
return special;
|
||||
}
|
||||
|
||||
public int getPriorityTime() {
|
||||
return priorityTime;
|
||||
}
|
||||
|
||||
public UUID getActivePlayerId() {
|
||||
return activePlayerId;
|
||||
}
|
||||
|
||||
public boolean isPlayer() {
|
||||
return isPlayer;
|
||||
}
|
||||
|
||||
public Set<UUID> getCanPlayInHand() {
|
||||
return canPlayInHand;
|
||||
}
|
||||
|
||||
public void setCanPlayInHand(Set<UUID> canPlayInHand) {
|
||||
this.canPlayInHand = canPlayInHand;
|
||||
}
|
||||
|
||||
public int getSpellsCastCurrentTurn() {
|
||||
return spellsCastCurrentTurn;
|
||||
}
|
||||
|
||||
public boolean isRollbackTurnsAllowed() {
|
||||
return rollbackTurnsAllowed;
|
||||
}
|
||||
|
||||
}
|
||||
60
Mage.Common/src/main/java/mage/view/LookedAtView.java
Normal file
60
Mage.Common/src/main/java/mage/view/LookedAtView.java
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Cards;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com, nantuko
|
||||
*/
|
||||
public class LookedAtView implements Serializable {
|
||||
|
||||
private final String name;
|
||||
private final SimpleCardsView cards = new SimpleCardsView();
|
||||
|
||||
public LookedAtView(String name, Cards cards, Game game) {
|
||||
this.name = name;
|
||||
for (Card card: cards.getCards(game)) {
|
||||
this.cards.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), card.getTokenSetCode(), card.getTokenDescriptor()));
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public SimpleCardsView getCards() {
|
||||
return cards;
|
||||
}
|
||||
}
|
||||
90
Mage.Common/src/main/java/mage/view/ManaPoolView.java
Normal file
90
Mage.Common/src/main/java/mage/view/ManaPoolView.java
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.ConditionalMana;
|
||||
import mage.players.ManaPool;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ManaPoolView implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int red;
|
||||
private int green;
|
||||
private int blue;
|
||||
private int white;
|
||||
private int black;
|
||||
private int colorless;
|
||||
|
||||
public ManaPoolView(ManaPool pool) {
|
||||
this.red = pool.getRed();
|
||||
this.green = pool.getGreen();
|
||||
this.blue = pool.getBlue();
|
||||
this.white = pool.getWhite();
|
||||
this.black = pool.getBlack();
|
||||
this.colorless = pool.getColorless();
|
||||
for (ConditionalMana mana : pool.getConditionalMana()) {
|
||||
this.red += mana.getRed();
|
||||
this.green += mana.getGreen();
|
||||
this.blue += mana.getBlue();
|
||||
this.white += mana.getWhite();
|
||||
this.black += mana.getBlack();
|
||||
this.colorless += mana.getColorless();
|
||||
}
|
||||
}
|
||||
|
||||
public int getRed() {
|
||||
return red;
|
||||
}
|
||||
|
||||
public int getGreen() {
|
||||
return green;
|
||||
}
|
||||
|
||||
public int getBlue() {
|
||||
return blue;
|
||||
}
|
||||
|
||||
public int getWhite() {
|
||||
return white;
|
||||
}
|
||||
|
||||
public int getBlack() {
|
||||
return black;
|
||||
}
|
||||
|
||||
public int getColorless() {
|
||||
return colorless;
|
||||
}
|
||||
|
||||
}
|
||||
215
Mage.Common/src/main/java/mage/view/MatchView.java
Normal file
215
Mage.Common/src/main/java/mage/view/MatchView.java
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.game.Game;
|
||||
import mage.game.Table;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class MatchView implements Serializable {
|
||||
|
||||
private final UUID tableId;
|
||||
private UUID matchId;
|
||||
private String matchName;
|
||||
private String gameType;
|
||||
private String deckType;
|
||||
|
||||
private final List<UUID> games = new ArrayList<>();
|
||||
private String result;
|
||||
private String players;
|
||||
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
private boolean replayAvailable;
|
||||
private final boolean isTournament;
|
||||
private boolean rated;
|
||||
|
||||
public MatchView(Table table) {
|
||||
this.tableId = table.getId();
|
||||
this.isTournament = table.isTournament();
|
||||
if (table.isTournament()) {
|
||||
initTournamentTable(table);
|
||||
} else {
|
||||
initMatchTable(table);
|
||||
}
|
||||
}
|
||||
|
||||
// used for matches
|
||||
private void initMatchTable(Table table) {
|
||||
Match match = table.getMatch();
|
||||
this.matchId = match.getId();
|
||||
this.matchName = match.getName();
|
||||
this.gameType = match.getOptions().getGameType();
|
||||
|
||||
if (table.getName() != null && !table.getName().isEmpty()) {
|
||||
this.deckType = match.getOptions().getDeckType() + " [" + table.getName() + ']';
|
||||
} else {
|
||||
this.deckType = match.getOptions().getDeckType();
|
||||
}
|
||||
|
||||
for (Game game: match.getGames()) {
|
||||
games.add(game.getId());
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
StringBuilder sb2 = new StringBuilder();
|
||||
for (MatchPlayer matchPlayer: match.getPlayers()) {
|
||||
sb1.append(matchPlayer.getName());
|
||||
if(matchPlayer.hasQuit()) {
|
||||
if (matchPlayer.getPlayer().hasTimerTimeout()) {
|
||||
sb1.append(" [timer] ");
|
||||
} else if (matchPlayer.getPlayer().hasIdleTimeout()) {
|
||||
sb1.append(" [idle] ");
|
||||
} else {
|
||||
sb1.append(" [quit] ");
|
||||
}
|
||||
}
|
||||
int lostGames = match.getNumGames() - (matchPlayer.getWins() + match.getDraws());
|
||||
sb1.append(", ");
|
||||
sb2.append(matchPlayer.getName()).append(" [");
|
||||
sb2.append(matchPlayer.getWins()).append('-');
|
||||
if (match.getDraws() > 0) {
|
||||
sb2.append(match.getDraws()).append('-');
|
||||
}
|
||||
sb2.append(lostGames).append("], ");
|
||||
}
|
||||
if (sb1.length() > 2) {
|
||||
players = sb1.substring(0, sb1.length() - 2);
|
||||
result = sb2.substring(0, sb2.length() - 2);
|
||||
} else {
|
||||
players = "[no players]";
|
||||
result = "";
|
||||
}
|
||||
this.startTime = match.getStartTime();
|
||||
this.endTime = match.getEndTime();
|
||||
this.replayAvailable = match.isReplayAvailable();
|
||||
this.rated = match.getOptions().isRated();
|
||||
}
|
||||
|
||||
// used for tournaments
|
||||
private void initTournamentTable(Table table) {
|
||||
this.matchId = table.getTournament().getId();
|
||||
this.matchName = table.getName();
|
||||
this.gameType = table.getGameType();
|
||||
if (table.getTournament().getOptions().getNumberRounds() > 0) {
|
||||
this.gameType = new StringBuilder(this.gameType).append(' ').append(table.getTournament().getOptions().getNumberRounds()).append(" Rounds").toString();
|
||||
}
|
||||
StringBuilder sbDeckType = new StringBuilder(table.getDeckType());
|
||||
if (!table.getTournament().getBoosterInfo().isEmpty()) {
|
||||
sbDeckType.append(' ').append(table.getTournament().getBoosterInfo());
|
||||
}
|
||||
if (table.getName() != null && !table.getName().isEmpty()) {
|
||||
sbDeckType.append(table.getDeckType()).append(" [").append(table.getName()).append(']');
|
||||
}
|
||||
this.deckType = sbDeckType.toString();
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (TournamentPlayer tPlayer : table.getTournament().getPlayers()) {
|
||||
sb1.append(tPlayer.getPlayer().getName()).append(" (").append(tPlayer.getPoints()).append(" P.) ");
|
||||
}
|
||||
this.players = sb1.toString();
|
||||
StringBuilder sb2 = new StringBuilder();
|
||||
if (!table.getTournament().getRounds().isEmpty()) {
|
||||
for (TournamentPlayer tPlayer : table.getTournament().getPlayers()) {
|
||||
sb2.append(tPlayer.getPlayer().getName()).append(": ").append(tPlayer.getResults()).append(' ');
|
||||
}
|
||||
} else {
|
||||
sb2.append("Canceled");
|
||||
}
|
||||
this.result = sb2.toString();
|
||||
this.startTime = table.getTournament().getStartTime();
|
||||
this.endTime = table.getTournament().getEndTime();
|
||||
this.replayAvailable = false;
|
||||
this.rated = table.getTournament().getOptions().getMatchOptions().isRated();
|
||||
}
|
||||
|
||||
public UUID getMatchId() {
|
||||
return matchId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return matchName;
|
||||
}
|
||||
|
||||
public String getGameType() {
|
||||
return gameType;
|
||||
}
|
||||
|
||||
public String getDeckType() {
|
||||
return deckType;
|
||||
}
|
||||
|
||||
public List<UUID> getGames() {
|
||||
return games;
|
||||
}
|
||||
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
public Date getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public Date getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public String getMatchName() {
|
||||
return matchName;
|
||||
}
|
||||
|
||||
public boolean isReplayAvailable() {
|
||||
return replayAvailable;
|
||||
}
|
||||
|
||||
public boolean isTournament() {
|
||||
return isTournament;
|
||||
}
|
||||
|
||||
public UUID getTableId() {
|
||||
return tableId;
|
||||
}
|
||||
|
||||
public boolean isRated() {
|
||||
return rated;
|
||||
}
|
||||
}
|
||||
217
Mage.Common/src/main/java/mage/view/PermanentView.java
Normal file
217
Mage.Common/src/main/java/mage/view/PermanentView.java
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.TurnFaceUpAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentToken;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class PermanentView extends CardView {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private boolean tapped;
|
||||
private final boolean flipped;
|
||||
private final boolean phasedIn;
|
||||
private final boolean summoningSickness;
|
||||
private final int damage;
|
||||
private List<UUID> attachments;
|
||||
private final CardView original;
|
||||
private final boolean copy;
|
||||
private final String nameOwner; // only filled if != controller
|
||||
private final boolean controlled;
|
||||
private final UUID attachedTo;
|
||||
private final boolean morphed;
|
||||
private final boolean manifested;
|
||||
private final boolean attachedToPermanent;
|
||||
|
||||
public PermanentView(Permanent permanent, Card card, UUID createdForPlayerId, Game game) {
|
||||
super(permanent, game, permanent.getControllerId().equals(createdForPlayerId));
|
||||
this.controlled = permanent.getControllerId().equals(createdForPlayerId);
|
||||
this.rules = permanent.getRules(game);
|
||||
this.tapped = permanent.isTapped();
|
||||
this.flipped = permanent.isFlipped();
|
||||
this.phasedIn = permanent.isPhasedIn();
|
||||
this.summoningSickness = permanent.hasSummoningSickness();
|
||||
this.morphed = permanent.isMorphed();
|
||||
this.manifested = permanent.isManifested();
|
||||
this.damage = permanent.getDamage();
|
||||
if (!permanent.getAttachments().isEmpty()) {
|
||||
attachments = new ArrayList<>();
|
||||
attachments.addAll(permanent.getAttachments());
|
||||
}
|
||||
this.attachedTo = permanent.getAttachedTo();
|
||||
if (isToken()) {
|
||||
original = new CardView(((PermanentToken) permanent).getToken());
|
||||
original.expansionSetCode = permanent.getExpansionSetCode();
|
||||
tokenSetCode = original.getTokenSetCode();
|
||||
tokenDescriptor = original.getTokenDescriptor();
|
||||
} else {
|
||||
if (card != null) {
|
||||
// original may not be face down
|
||||
original = new CardView(card);
|
||||
} else {
|
||||
original = null;
|
||||
}
|
||||
}
|
||||
this.transformed = permanent.isTransformed();
|
||||
this.copy = permanent.isCopy();
|
||||
|
||||
// for fipped, transformed or copied cards, switch the names
|
||||
if (original != null && !original.getName().equals(this.getName())) {
|
||||
if (permanent.isCopy() && permanent.isFlipCard()) {
|
||||
this.alternateName = permanent.getFlipCardName();
|
||||
this.originalName = this.getName();
|
||||
} else {
|
||||
if (controlled // controller may always know
|
||||
|| (!morphed && !manifested)) { // others don't know for morph or transformed cards
|
||||
this.alternateName = original.getName();
|
||||
this.originalName = this.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!permanent.getOwnerId().equals(permanent.getControllerId())) {
|
||||
Player owner = game.getPlayer(permanent.getOwnerId());
|
||||
if (owner != null) {
|
||||
this.nameOwner = owner.getName();
|
||||
} else {
|
||||
this.nameOwner = "";
|
||||
}
|
||||
} else {
|
||||
this.nameOwner = "";
|
||||
}
|
||||
|
||||
if (permanent.isFaceDown(game) && card != null) {
|
||||
if (controlled) {
|
||||
// must be a morphed or manifested card
|
||||
for (Ability permanentAbility : permanent.getAbilities()) {
|
||||
if (permanentAbility instanceof TurnFaceUpAbility && !permanentAbility.getRuleVisible()) {
|
||||
this.rules.add(permanentAbility.getRule(true));
|
||||
}
|
||||
if (permanentAbility.getWorksFaceDown()) {
|
||||
this.rules.add(permanentAbility.getRule());
|
||||
}
|
||||
}
|
||||
this.name = card.getName();
|
||||
this.displayName = card.getName();
|
||||
this.expansionSetCode = card.getExpansionSetCode();
|
||||
this.cardNumber = card.getCardNumber();
|
||||
} else {
|
||||
if (permanent.isManifested()) {
|
||||
this.rules.add("A manifested creature card can be turned face up any time for it's mana cost."
|
||||
+ " A face-down card can also be turned face up for its morph cost.");
|
||||
} else if (permanent.isMorphed()) {
|
||||
this.rules.add("If the controller has priority, he or she may turn this permanent face up."
|
||||
+ " This is a special action; it doesn't use the stack. To do this he or she pays the morph costs,"
|
||||
+ " then turns this permanent face up.");
|
||||
}
|
||||
}
|
||||
}
|
||||
// determines if shown in it's own column
|
||||
if (permanent.getAttachedTo() != null) {
|
||||
attachedToPermanent = game.getPermanent(permanent.getAttachedTo()) != null;
|
||||
} else {
|
||||
attachedToPermanent = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTapped() {
|
||||
return tapped;
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
public boolean isFlipped() {
|
||||
return flipped;
|
||||
}
|
||||
|
||||
public boolean isCopy() {
|
||||
return copy;
|
||||
}
|
||||
|
||||
public boolean isPhasedIn() {
|
||||
return phasedIn;
|
||||
}
|
||||
|
||||
public boolean hasSummoningSickness() {
|
||||
return summoningSickness;
|
||||
}
|
||||
|
||||
public List<UUID> getAttachments() {
|
||||
return attachments;
|
||||
}
|
||||
|
||||
public CardView getOriginal() {
|
||||
return original;
|
||||
}
|
||||
|
||||
public void overrideTapped(boolean tapped) {
|
||||
this.tapped = tapped;
|
||||
}
|
||||
|
||||
public String getNameOwner() {
|
||||
return nameOwner;
|
||||
}
|
||||
|
||||
public boolean isControlled() {
|
||||
return controlled;
|
||||
}
|
||||
|
||||
public UUID getAttachedTo() {
|
||||
return attachedTo;
|
||||
}
|
||||
|
||||
public boolean isAttachedTo() {
|
||||
return attachedTo != null;
|
||||
}
|
||||
|
||||
public boolean isAttachedToPermanent() {
|
||||
return attachedToPermanent;
|
||||
}
|
||||
|
||||
public boolean isMorphed() {
|
||||
return morphed;
|
||||
}
|
||||
|
||||
public boolean isManifested() {
|
||||
return manifested;
|
||||
}
|
||||
}
|
||||
308
Mage.Common/src/main/java/mage/view/PlayerView.java
Normal file
308
Mage.Common/src/main/java/mage/view/PlayerView.java
Normal file
|
|
@ -0,0 +1,308 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.counters.Counters;
|
||||
import mage.game.ExileZone;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.command.CommandObject;
|
||||
import mage.game.command.Commander;
|
||||
import mage.game.command.Emblem;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.players.net.UserData;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class PlayerView implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final UUID playerId;
|
||||
private final String name;
|
||||
private final int life;
|
||||
private final Counters counters;
|
||||
private final int wins;
|
||||
private final int winsNeeded;
|
||||
private final long deckHashCode;
|
||||
private final int libraryCount;
|
||||
private final int handCount;
|
||||
private final boolean isActive;
|
||||
private final boolean hasPriority;
|
||||
private final boolean timerActive;
|
||||
private final boolean hasLeft;
|
||||
private final ManaPoolView manaPool;
|
||||
private final CardsView graveyard = new CardsView();
|
||||
private final CardsView exile = new CardsView();
|
||||
private final Map<UUID, PermanentView> battlefield = new LinkedHashMap<>();
|
||||
private final CardView topCard;
|
||||
private final UserData userData;
|
||||
private final List<CommandObjectView> commandList = new ArrayList<>();
|
||||
private final List<UUID> attachments = new ArrayList<>();
|
||||
private final int statesSavedSize;
|
||||
private final int priorityTimeLeft;
|
||||
private final boolean passedTurn; // F4
|
||||
private final boolean passedUntilEndOfTurn; // F5
|
||||
private final boolean passedUntilNextMain; // F6
|
||||
private final boolean passedUntilStackResolved; // F8
|
||||
private final boolean passedAllTurns; // F9
|
||||
private final boolean passedUntilEndStepBeforeMyTurn; // F11
|
||||
private final boolean monarch;
|
||||
|
||||
public PlayerView(Player player, GameState state, Game game, UUID createdForPlayerId, UUID watcherUserId) {
|
||||
this.playerId = player.getId();
|
||||
this.name = player.getName();
|
||||
this.life = player.getLife();
|
||||
this.counters = player.getCounters();
|
||||
this.wins = player.getMatchPlayer().getWins();
|
||||
this.winsNeeded = player.getMatchPlayer().getWinsNeeded();
|
||||
// If match ended immediately before, deck can be set to null so check is necessarry here
|
||||
this.deckHashCode = player.getMatchPlayer().getDeck() != null ? player.getMatchPlayer().getDeck().getDeckHashCode() : 0;
|
||||
this.libraryCount = player.getLibrary().size();
|
||||
this.handCount = player.getHand().size();
|
||||
this.manaPool = new ManaPoolView(player.getManaPool());
|
||||
this.isActive = (player.getId().equals(state.getActivePlayerId()));
|
||||
this.hasPriority = player.getId().equals(state.getPriorityPlayerId());
|
||||
this.priorityTimeLeft = player.getPriorityTimeLeft();
|
||||
this.timerActive = (this.hasPriority && player.isGameUnderControl())
|
||||
|| (player.getPlayersUnderYourControl().contains(state.getPriorityPlayerId()))
|
||||
|| player.getId().equals(game.getState().getChoosingPlayerId());
|
||||
|
||||
this.hasLeft = player.hasLeft();
|
||||
for (Card card : player.getGraveyard().getCards(game)) {
|
||||
graveyard.put(card.getId(), new CardView(card, game, false));
|
||||
}
|
||||
for (ExileZone exileZone : game.getExile().getExileZones()) {
|
||||
for (Card card : exileZone.getCards(game)) {
|
||||
if (player.getId().equals(card.getOwnerId())) {
|
||||
exile.put(card.getId(), new CardView(card, game, false)); // unnown if it's allowed to look under a face down card
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
for (Permanent permanent : state.getBattlefield().getAllPermanents()) {
|
||||
if (showInBattlefield(permanent, state)) {
|
||||
PermanentView view = new PermanentView(permanent, game.getCard(permanent.getId()), createdForPlayerId, game);
|
||||
battlefield.put(view.getId(), view);
|
||||
}
|
||||
}
|
||||
} catch (ConcurrentModificationException e) {
|
||||
// can happen as a player left battlefield while PlayerView is created
|
||||
}
|
||||
Card cardOnTop = (player.isTopCardRevealed() && player.getLibrary().hasCards())
|
||||
? player.getLibrary().getFromTop(game) : null;
|
||||
this.topCard = cardOnTop != null ? new CardView(cardOnTop) : null;
|
||||
if (player.getUserData() != null) {
|
||||
this.userData = player.getUserData();
|
||||
} else {
|
||||
this.userData = UserData.getDefaultUserDataView();
|
||||
}
|
||||
|
||||
for (CommandObject commandObject : game.getState().getCommand()) {
|
||||
if (commandObject instanceof Emblem) {
|
||||
Emblem emblem = (Emblem) commandObject;
|
||||
if (emblem.getControllerId().equals(this.playerId)) {
|
||||
commandList.add(new EmblemView(emblem));
|
||||
}
|
||||
} else if (commandObject instanceof Commander) {
|
||||
Commander commander = (Commander) commandObject;
|
||||
if (commander.getControllerId().equals(this.playerId)) {
|
||||
Card sourceCard = game.getCard(commander.getSourceId());
|
||||
if (sourceCard != null) {
|
||||
commandList.add(new CommanderView(commander, sourceCard, game));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (player.getAttachments() != null) {
|
||||
attachments.addAll(player.getAttachments());
|
||||
}
|
||||
|
||||
this.statesSavedSize = player.getStoredBookmark();
|
||||
|
||||
this.passedTurn = player.getPassedTurn();
|
||||
this.passedUntilEndOfTurn = player.getPassedUntilEndOfTurn();
|
||||
this.passedUntilNextMain = player.getPassedUntilNextMain();
|
||||
this.passedAllTurns = player.getPassedAllTurns();
|
||||
this.passedUntilStackResolved = player.getPassedUntilStackResolved();
|
||||
this.passedUntilEndStepBeforeMyTurn = player.getPassedUntilEndStepBeforeMyTurn();
|
||||
this.monarch = player.getId().equals(game.getMonarchId());
|
||||
}
|
||||
|
||||
private boolean showInBattlefield(Permanent permanent, GameState state) {
|
||||
|
||||
//show permanents controlled by player or attachments to permanents controlled by player
|
||||
if (permanent.getAttachedTo() == null) {
|
||||
return permanent.getControllerId().equals(playerId);
|
||||
} else {
|
||||
Permanent attachedTo = state.getPermanent(permanent.getAttachedTo());
|
||||
if (attachedTo != null) {
|
||||
return attachedTo.getControllerId().equals(playerId);
|
||||
} else {
|
||||
return permanent.getControllerId().equals(playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getLife() {
|
||||
return this.life;
|
||||
}
|
||||
|
||||
public Counters getCounters() {
|
||||
return this.counters;
|
||||
}
|
||||
|
||||
public int getLibraryCount() {
|
||||
return this.libraryCount;
|
||||
}
|
||||
|
||||
public int getWins() {
|
||||
return wins;
|
||||
}
|
||||
|
||||
public int getWinsNeeded() {
|
||||
return winsNeeded;
|
||||
}
|
||||
|
||||
public long getDeckHashCode() {
|
||||
return deckHashCode;
|
||||
}
|
||||
|
||||
public int getHandCount() {
|
||||
return this.handCount;
|
||||
}
|
||||
|
||||
public ManaPoolView getManaPool() {
|
||||
return this.manaPool;
|
||||
}
|
||||
|
||||
public CardsView getGraveyard() {
|
||||
return this.graveyard;
|
||||
}
|
||||
|
||||
public CardsView getExile() {
|
||||
return exile;
|
||||
}
|
||||
|
||||
public Map<UUID, PermanentView> getBattlefield() {
|
||||
return this.battlefield;
|
||||
}
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return this.playerId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return this.isActive;
|
||||
}
|
||||
|
||||
public boolean hasLeft() {
|
||||
return this.hasLeft;
|
||||
}
|
||||
|
||||
public CardView getTopCard() {
|
||||
return this.topCard;
|
||||
}
|
||||
|
||||
public UserData getUserData() {
|
||||
return this.userData;
|
||||
}
|
||||
|
||||
public List<CommandObjectView> getCommandObjectList() {
|
||||
return commandList;
|
||||
}
|
||||
|
||||
public List<UUID> getAttachments() {
|
||||
return attachments;
|
||||
}
|
||||
|
||||
public boolean hasAttachments() {
|
||||
return attachments != null && !attachments.isEmpty();
|
||||
}
|
||||
|
||||
public int getStatesSavedSize() {
|
||||
return statesSavedSize;
|
||||
}
|
||||
|
||||
public int getPriorityTimeLeft() {
|
||||
return priorityTimeLeft;
|
||||
}
|
||||
|
||||
public boolean hasPriority() {
|
||||
return hasPriority;
|
||||
}
|
||||
|
||||
public boolean isTimerActive() {
|
||||
return timerActive;
|
||||
}
|
||||
|
||||
public boolean isPassedTurn() {
|
||||
return passedTurn;
|
||||
}
|
||||
|
||||
public boolean isPassedUntilEndOfTurn() {
|
||||
return passedUntilEndOfTurn;
|
||||
}
|
||||
|
||||
public boolean isPassedUntilNextMain() {
|
||||
return passedUntilNextMain;
|
||||
}
|
||||
|
||||
public boolean isPassedAllTurns() {
|
||||
return passedAllTurns;
|
||||
}
|
||||
|
||||
public boolean isPassedUntilStackResolved() {
|
||||
return passedUntilStackResolved;
|
||||
}
|
||||
|
||||
public boolean isPassedUntilEndStepBeforeMyTurn() {
|
||||
return passedUntilEndStepBeforeMyTurn;
|
||||
}
|
||||
|
||||
public boolean isMonarch() {
|
||||
return monarch;
|
||||
}
|
||||
|
||||
}
|
||||
59
Mage.Common/src/main/java/mage/view/RevealedView.java
Normal file
59
Mage.Common/src/main/java/mage/view/RevealedView.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Cards;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class RevealedView implements Serializable {
|
||||
|
||||
private final String name;
|
||||
private final CardsView cards = new CardsView();
|
||||
|
||||
public RevealedView(String name, Cards cards, Game game) {
|
||||
this.name = name;
|
||||
for (Card card : cards.getCards(game)) {
|
||||
this.cards.put(card.getId(), new CardView(card, game, card.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CardsView getCards() {
|
||||
return cards;
|
||||
}
|
||||
}
|
||||
72
Mage.Common/src/main/java/mage/view/RoomUsersView.java
Normal file
72
Mage.Common/src/main/java/mage/view/RoomUsersView.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class RoomUsersView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int numberActiveGames;
|
||||
private final int numberGameThreads;
|
||||
private final int numberMaxGames;
|
||||
|
||||
private final List<UsersView> usersView;
|
||||
|
||||
public RoomUsersView(List<UsersView> usersView, int numberActiveGames, int numberGameThreads, int numberMaxGames) {
|
||||
|
||||
this.numberActiveGames = numberActiveGames;
|
||||
this.numberGameThreads = numberGameThreads;
|
||||
this.numberMaxGames = numberMaxGames;
|
||||
|
||||
this.usersView = usersView;
|
||||
}
|
||||
|
||||
public int getNumberActiveGames() {
|
||||
return numberActiveGames;
|
||||
}
|
||||
|
||||
public int getNumberGameThreads() {
|
||||
return numberGameThreads;
|
||||
}
|
||||
|
||||
public int getNumberMaxGames() {
|
||||
return numberMaxGames;
|
||||
}
|
||||
|
||||
public List<UsersView> getUsersView() {
|
||||
return usersView;
|
||||
}
|
||||
|
||||
}
|
||||
80
Mage.Common/src/main/java/mage/view/RoundView.java
Normal file
80
Mage.Common/src/main/java/mage/view/RoundView.java
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mage.game.Game;
|
||||
import mage.game.GameInfo;
|
||||
import mage.game.tournament.Round;
|
||||
import mage.game.tournament.TournamentPairing;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class RoundView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
List<TournamentGameView> games = new ArrayList<>();
|
||||
|
||||
public RoundView(Round round) {
|
||||
try {
|
||||
for (TournamentPairing pair : round.getPairs()) {
|
||||
// get info of finished games from match
|
||||
if (pair.getMatch() != null) {
|
||||
for (GameInfo gameInfo : pair.getMatch().getGamesInfo()) {
|
||||
games.add(new TournamentGameView(round.getRoundNumber(), gameInfo.getMatchId(), gameInfo.getGameId(), gameInfo.getState(), gameInfo.getResult(), gameInfo.getPlayers(), gameInfo.getTableId()));
|
||||
}
|
||||
if (!pair.getMatch().hasEnded()) {
|
||||
int numberSavedGames = pair.getMatch().getGamesInfo().size();
|
||||
if (pair.getMatch() != null) {
|
||||
int gameCount = 0;
|
||||
for (Game game : pair.getMatch().getGames()) {
|
||||
gameCount++;
|
||||
if (gameCount > numberSavedGames) {
|
||||
// only unfinished game info directly from game
|
||||
games.add(new TournamentGameView(round.getRoundNumber(), pair, game));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<TournamentGameView> getGames() {
|
||||
return games;
|
||||
}
|
||||
|
||||
}
|
||||
114
Mage.Common/src/main/java/mage/view/SeatView.java
Normal file
114
Mage.Common/src/main/java/mage/view/SeatView.java
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import mage.game.Seat;
|
||||
import mage.players.PlayerType;
|
||||
import mage.players.net.UserData;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class SeatView implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String flagName;
|
||||
private UUID playerId;
|
||||
private final String playerName;
|
||||
private final PlayerType playerType;
|
||||
private final String history;
|
||||
private final int generalRating;
|
||||
private final int constructedRating;
|
||||
private final int limitedRating;
|
||||
|
||||
public SeatView(Seat seat) {
|
||||
if (seat.getPlayer() != null) {
|
||||
this.playerId = seat.getPlayer().getId();
|
||||
this.playerName = seat.getPlayer().getName();
|
||||
if (seat.getPlayer().getUserData() == null) {
|
||||
this.flagName = UserData.getDefaultFlagName();
|
||||
this.history = "";
|
||||
this.generalRating = 0;
|
||||
this.constructedRating = 0;
|
||||
this.limitedRating = 0;
|
||||
} else {
|
||||
this.flagName = seat.getPlayer().getUserData().getFlagName();
|
||||
this.history = seat.getPlayer().getUserData().getHistory();
|
||||
this.generalRating = seat.getPlayer().getUserData().getGeneralRating();
|
||||
this.constructedRating = seat.getPlayer().getUserData().getConstructedRating();
|
||||
this.limitedRating = seat.getPlayer().getUserData().getLimitedRating();
|
||||
}
|
||||
} else {
|
||||
// Empty seat
|
||||
this.playerName = "";
|
||||
this.flagName = "";
|
||||
this.history = "";
|
||||
this.generalRating = 0;
|
||||
this.constructedRating = 0;
|
||||
this.limitedRating = 0;
|
||||
}
|
||||
this.playerType = seat.getPlayerType();
|
||||
}
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public PlayerType getPlayerType() {
|
||||
return playerType;
|
||||
}
|
||||
|
||||
public String getFlagName() {
|
||||
return flagName;
|
||||
}
|
||||
|
||||
public String getHistory() {
|
||||
return history;
|
||||
}
|
||||
|
||||
public int getGeneralRating() {
|
||||
return generalRating;
|
||||
}
|
||||
|
||||
public int getConstructedRating() {
|
||||
return constructedRating;
|
||||
}
|
||||
|
||||
public int getLimitedRating() {
|
||||
return limitedRating;
|
||||
}
|
||||
}
|
||||
87
Mage.Common/src/main/java/mage/view/SimpleCardView.java
Normal file
87
Mage.Common/src/main/java/mage/view/SimpleCardView.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class SimpleCardView implements Serializable {
|
||||
protected UUID id;
|
||||
protected String expansionSetCode;
|
||||
protected String tokenSetCode;
|
||||
protected String tokenDescriptor;
|
||||
protected String cardNumber;
|
||||
protected boolean usesVariousArt;
|
||||
protected boolean gameObject;
|
||||
|
||||
public SimpleCardView(UUID id, String expansionSetCode, String cardNumber, boolean usesVariousArt, String tokenSetCode, String tokenDescriptor) {
|
||||
this(id, expansionSetCode, cardNumber, usesVariousArt, tokenSetCode, false, tokenDescriptor);
|
||||
}
|
||||
public SimpleCardView(UUID id, String expansionSetCode, String cardNumber, boolean usesVariousArt, String tokenSetCode, boolean isGameObject, String tokenDescriptor) {
|
||||
this.id = id;
|
||||
this.expansionSetCode = expansionSetCode;
|
||||
this.tokenDescriptor = tokenDescriptor;
|
||||
this.cardNumber = cardNumber;
|
||||
this.usesVariousArt = usesVariousArt;
|
||||
this.tokenSetCode = tokenSetCode;
|
||||
this.gameObject = isGameObject;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getExpansionSetCode() {
|
||||
return expansionSetCode;
|
||||
}
|
||||
|
||||
public String getCardNumber() {
|
||||
return cardNumber;
|
||||
}
|
||||
|
||||
public boolean getUsesVariousArt() {
|
||||
return usesVariousArt;
|
||||
}
|
||||
|
||||
public String getTokenSetCode() {
|
||||
return tokenSetCode;
|
||||
}
|
||||
|
||||
public String getTokenDescriptor() {
|
||||
return tokenDescriptor;
|
||||
}
|
||||
|
||||
public boolean isGameObject() {
|
||||
return gameObject;
|
||||
}
|
||||
}
|
||||
52
Mage.Common/src/main/java/mage/view/SimpleCardsView.java
Normal file
52
Mage.Common/src/main/java/mage/view/SimpleCardsView.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import mage.cards.Card;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class SimpleCardsView extends LinkedHashMap<UUID, SimpleCardView> {
|
||||
|
||||
public SimpleCardsView() {}
|
||||
|
||||
public SimpleCardsView(Collection<Card> cards, boolean isGameObject) {
|
||||
for (Card card: cards) {
|
||||
this.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), card.getTokenSetCode(), isGameObject,
|
||||
card.getTokenDescriptor()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
152
Mage.Common/src/main/java/mage/view/StackAbilityView.java
Normal file
152
Mage.Common/src/main/java/mage/view/StackAbilityView.java
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.Modes;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.AbilityType;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.MageObjectType;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.StackAbility;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.target.targetpointer.TargetPointer;
|
||||
import mage.util.GameLog;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class StackAbilityView extends CardView {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final CardView sourceCard;
|
||||
|
||||
public StackAbilityView(Game game, StackAbility ability, String sourceName, CardView sourceCard) {
|
||||
this.id = ability.getId();
|
||||
this.mageObjectType = MageObjectType.ABILITY_STACK;
|
||||
this.abilityType = ability.getStackAbility().getAbilityType();
|
||||
this.sourceCard = sourceCard;
|
||||
this.sourceCard.setMageObjectType(mageObjectType);
|
||||
this.name = "Ability";
|
||||
this.loyalty = "";
|
||||
|
||||
this.cardTypes = ability.getCardType();
|
||||
this.subTypes = ability.getSubtype(game);
|
||||
this.superTypes = ability.getSuperType();
|
||||
this.color = ability.getColor(game);
|
||||
this.manaCost = ability.getManaCost().getSymbols();
|
||||
this.cardTypes = ability.getCardType();
|
||||
this.subTypes = ability.getSubtype(game);
|
||||
this.superTypes = ability.getSuperType();
|
||||
this.color = ability.getColor(game);
|
||||
this.manaCost = ability.getManaCost().getSymbols();
|
||||
this.power = ability.getPower().toString();
|
||||
this.toughness = ability.getToughness().toString();
|
||||
String nameToShow;
|
||||
if (sourceCard.isFaceDown()) {
|
||||
CardView tmpSourceCard = this.getSourceCard();
|
||||
tmpSourceCard.displayName = "Face Down";
|
||||
tmpSourceCard.superTypes.clear();
|
||||
tmpSourceCard.subTypes.clear();
|
||||
tmpSourceCard.cardTypes.clear();
|
||||
tmpSourceCard.cardTypes.add(CardType.CREATURE);
|
||||
tmpSourceCard.manaCost.clear();
|
||||
tmpSourceCard.power = "2";
|
||||
tmpSourceCard.toughness = "2";
|
||||
nameToShow = "creature without name";
|
||||
} else {
|
||||
nameToShow = sourceName;
|
||||
}
|
||||
this.rules = new ArrayList<>();
|
||||
rules.add(ability.getRule(nameToShow));
|
||||
this.counters = sourceCard.getCounters();
|
||||
|
||||
updateTargets(game, ability);
|
||||
}
|
||||
|
||||
private void updateTargets(Game game, StackAbility ability) {
|
||||
List<String> names = new ArrayList<>();
|
||||
for (UUID modeId : ability.getModes().getSelectedModes()) {
|
||||
Mode mode = ability.getModes().get(modeId);
|
||||
if (!mode.getTargets().isEmpty()) {
|
||||
setTargets(mode.getTargets());
|
||||
} else {
|
||||
List<UUID> targetList = new ArrayList<>();
|
||||
for (Effect effect : mode.getEffects()) {
|
||||
TargetPointer targetPointer = effect.getTargetPointer();
|
||||
if (targetPointer instanceof FixedTarget) {
|
||||
targetList.add(((FixedTarget) targetPointer).getTarget());
|
||||
}
|
||||
}
|
||||
if (!targetList.isEmpty()) {
|
||||
overrideTargets(targetList);
|
||||
|
||||
for (UUID uuid : targetList) {
|
||||
MageObject mageObject = game.getObject(uuid);
|
||||
if (mageObject != null) {
|
||||
if ((mageObject instanceof Card) && ((Card) mageObject).isFaceDown(game)) {
|
||||
continue;
|
||||
}
|
||||
names.add(GameLog.getColoredObjectIdNameForTooltip(mageObject));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!names.isEmpty()) {
|
||||
getRules().add("<i>Related objects: " + names.toString() + "</i>");
|
||||
}
|
||||
// show for modal ability, which mode was choosen
|
||||
if (ability.isModal()) {
|
||||
Modes modes = ability.getModes();
|
||||
for (UUID modeId : modes.getSelectedModes()) {
|
||||
Mode mode = modes.get(modeId);
|
||||
this.rules.add("<span color='green'><i>Chosen mode: " + mode.getEffects().getText(mode) + "</i></span>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CardView getSourceCard() {
|
||||
return this.sourceCard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbilityType getAbilityType() {
|
||||
return abilityType;
|
||||
}
|
||||
|
||||
}
|
||||
106
Mage.Common/src/main/java/mage/view/TableClientMessage.java
Normal file
106
Mage.Common/src/main/java/mage/view/TableClientMessage.java
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.cards.decks.Deck;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TableClientMessage implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private DeckView deck;
|
||||
private UUID roomId;
|
||||
private UUID tableId;
|
||||
private UUID gameId;
|
||||
private UUID playerId;
|
||||
private int time;
|
||||
private boolean flag = false;
|
||||
|
||||
public TableClientMessage(Deck deck, UUID tableId, int time) {
|
||||
this.deck = new DeckView(deck);
|
||||
this.tableId = tableId;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public TableClientMessage(Deck deck, UUID tableId, int time, boolean flag) {
|
||||
this.deck = new DeckView(deck);
|
||||
this.tableId = tableId;
|
||||
this.time = time;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public TableClientMessage(UUID gameId, UUID playerId) {
|
||||
this.gameId = gameId;
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
public TableClientMessage(UUID roomId, UUID tableId, boolean flag) {
|
||||
this.roomId = roomId;
|
||||
this.tableId = tableId;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public DeckView getDeck() {
|
||||
return deck;
|
||||
}
|
||||
|
||||
public UUID getTableId() {
|
||||
return tableId;
|
||||
}
|
||||
|
||||
public UUID getRoomId() {
|
||||
return roomId;
|
||||
}
|
||||
|
||||
public UUID getGameId() {
|
||||
return gameId;
|
||||
}
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public boolean getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
|
||||
}
|
||||
}
|
||||
257
Mage.Common/src/main/java/mage/view/TableView.java
Normal file
257
Mage.Common/src/main/java/mage/view/TableView.java
Normal file
|
|
@ -0,0 +1,257 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.constants.SkillLevel;
|
||||
import mage.constants.TableState;
|
||||
import mage.game.Game;
|
||||
import mage.game.Seat;
|
||||
import mage.game.Table;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TableView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private UUID tableId;
|
||||
private String gameType;
|
||||
private final String deckType;
|
||||
private String tableName;
|
||||
private String controllerName;
|
||||
private final String additionalInfo;
|
||||
private Date createTime;
|
||||
private TableState tableState;
|
||||
private final SkillLevel skillLevel;
|
||||
private final String tableStateText;
|
||||
private boolean isTournament;
|
||||
private List<SeatView> seats = new ArrayList<>();
|
||||
private List<UUID> games = new ArrayList<>();
|
||||
private final String quitRatio;
|
||||
private final boolean limited;
|
||||
private final boolean rated;
|
||||
private final boolean passworded;
|
||||
|
||||
public TableView(Table table) {
|
||||
this.tableId = table.getId();
|
||||
this.gameType = table.getGameType();
|
||||
this.tableName = table.getName();
|
||||
String tableNameInfo = null;
|
||||
if (tableName != null && !tableName.isEmpty()) {
|
||||
tableNameInfo = " [" + table.getName() + ']';
|
||||
}
|
||||
this.controllerName = table.getControllerName();
|
||||
this.tableState = table.getState();
|
||||
if (table.getState() == TableState.WAITING ||
|
||||
table.getState() == TableState.READY_TO_START ||
|
||||
table.getState() == TableState.STARTING) {
|
||||
this.createTime = table.getCreateTime();
|
||||
} else {
|
||||
if (table.isTournament()) {
|
||||
this.createTime = table.getTournament().getStartTime();
|
||||
} else {
|
||||
this.createTime = table.getMatch().getStartTime();
|
||||
}
|
||||
}
|
||||
this.isTournament = table.isTournament();
|
||||
for (Seat seat : table.getSeats()) {
|
||||
seats.add(new SeatView(seat));
|
||||
}
|
||||
if (!table.isTournament()) {
|
||||
// MATCH
|
||||
if (table.getState()==TableState.WAITING || table.getState()==TableState.READY_TO_START) {
|
||||
tableStateText = table.getState().toString() + " (" + table.getMatch().getPlayers().size() + '/' + table.getSeats().length + ')';
|
||||
} else {
|
||||
tableStateText = table.getState().toString();
|
||||
}
|
||||
for (Game game : table.getMatch().getGames()) {
|
||||
games.add(game.getId());
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sbScore = new StringBuilder();
|
||||
for (MatchPlayer matchPlayer : table.getMatch().getPlayers()) {
|
||||
if (matchPlayer.getPlayer() == null) {
|
||||
sb.append(", ").append("[unknown]");
|
||||
sbScore.append('-').append(matchPlayer.getWins());
|
||||
} else if (!matchPlayer.getName().equals(table.getControllerName())) {
|
||||
sb.append(", ").append(matchPlayer.getName());
|
||||
sbScore.append('-').append(matchPlayer.getWins());
|
||||
} else {
|
||||
sbScore.insert(0, matchPlayer.getWins()).insert(0, " Score: ");
|
||||
}
|
||||
}
|
||||
if (table.getMatch().getDraws() > 0) {
|
||||
sbScore.append(" Draws: ").append(table.getMatch().getDraws());
|
||||
}
|
||||
this.controllerName += sb.toString();
|
||||
this.deckType = table.getDeckType() + (tableNameInfo != null ? tableNameInfo : "");
|
||||
StringBuilder addInfo = new StringBuilder();
|
||||
if (table.getMatch().getGames().isEmpty()) {
|
||||
addInfo.append("Wins:").append(table.getMatch().getWinsNeeded());
|
||||
addInfo.append(" Time: ").append(table.getMatch().getOptions().getMatchTimeLimit().toString());
|
||||
if (table.getMatch().getFreeMulligans() > 0) {
|
||||
addInfo.append(" Free Mul.: ").append(table.getMatch().getFreeMulligans());
|
||||
}
|
||||
} else {
|
||||
addInfo.append("Wins:").append(table.getMatch().getWinsNeeded());
|
||||
addInfo.append(sbScore.toString());
|
||||
}
|
||||
this.additionalInfo = addInfo.toString();
|
||||
this.skillLevel = table.getMatch().getOptions().getSkillLevel();
|
||||
this.quitRatio = Integer.toString(table.getMatch().getOptions().getQuitRatio());
|
||||
this.limited = table.getMatch().getOptions().isLimited();
|
||||
this.rated = table.getMatch().getOptions().isRated();
|
||||
this.passworded = !table.getMatch().getOptions().getPassword().isEmpty();
|
||||
} else {
|
||||
// TOURNAMENT
|
||||
if (table.getTournament().getOptions().getNumberRounds() > 0) {
|
||||
this.gameType = new StringBuilder(this.gameType).append(' ').append(table.getTournament().getOptions().getNumberRounds()).append(" Rounds").toString();
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (TournamentPlayer tp : table.getTournament().getPlayers()) {
|
||||
if (!tp.getPlayer().getName().equals(table.getControllerName())) {
|
||||
sb1.append(", ").append(tp.getPlayer().getName());
|
||||
}
|
||||
}
|
||||
this.controllerName += sb1.toString();
|
||||
StringBuilder infoText = new StringBuilder();
|
||||
StringBuilder stateText = new StringBuilder(table.getState().toString());
|
||||
infoText.append("Wins:").append(table.getTournament().getOptions().getMatchOptions().getWinsNeeded());
|
||||
infoText.append(" Seats: ").append(table.getTournament().getPlayers().size()).append('/').append(table.getNumberOfSeats());
|
||||
switch (table.getState()) {
|
||||
case WAITING:
|
||||
stateText.append(" (").append(table.getTournament().getPlayers().size()).append('/').append(table.getNumberOfSeats()).append(')');
|
||||
case READY_TO_START:
|
||||
case STARTING:
|
||||
infoText.append(" Time: ").append(table.getTournament().getOptions().getMatchOptions().getMatchTimeLimit().toString());
|
||||
if (table.getTournament().getOptions().getMatchOptions().getFreeMulligans() > 0) {
|
||||
infoText.append(" Fr.Mul: ").append(table.getTournament().getOptions().getMatchOptions().getFreeMulligans());
|
||||
}
|
||||
if (table.getTournament().getTournamentType().isLimited()) {
|
||||
infoText.append(" Constr.: ").append(table.getTournament().getOptions().getLimitedOptions().getConstructionTime() / 60).append(" Min.");
|
||||
}
|
||||
break;
|
||||
case DUELING:
|
||||
stateText.append(" Round: ").append(table.getTournament().getRounds().size());
|
||||
break;
|
||||
case DRAFTING:
|
||||
Draft draft = table.getTournament().getDraft();
|
||||
if (draft != null) {
|
||||
stateText.append(' ').append(draft.getBoosterNum()).append('/').append(draft.getCardNum() - 1);
|
||||
}
|
||||
default:
|
||||
}
|
||||
this.additionalInfo = infoText.toString();
|
||||
this.tableStateText = stateText.toString();
|
||||
this.deckType = table.getDeckType() + ' ' + table.getTournament().getBoosterInfo() + (tableNameInfo != null ? tableNameInfo : "");
|
||||
this.skillLevel = table.getTournament().getOptions().getMatchOptions().getSkillLevel();
|
||||
this.quitRatio = Integer.toString(table.getTournament().getOptions().getQuitRatio());
|
||||
this.limited = table.getTournament().getOptions().getMatchOptions().isLimited();
|
||||
this.rated = table.getTournament().getOptions().getMatchOptions().isRated();
|
||||
this.passworded = !table.getTournament().getOptions().getPassword().isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getTableId() {
|
||||
return tableId;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public String getControllerName() {
|
||||
return controllerName;
|
||||
}
|
||||
|
||||
public String getGameType() {
|
||||
return gameType;
|
||||
}
|
||||
|
||||
public String getDeckType() {
|
||||
return deckType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public TableState getTableState() {
|
||||
return tableState;
|
||||
}
|
||||
|
||||
public List<SeatView> getSeats() {
|
||||
return seats;
|
||||
}
|
||||
|
||||
public List<UUID> getGames() {
|
||||
return games;
|
||||
}
|
||||
|
||||
public boolean isTournament() {
|
||||
return this.isTournament;
|
||||
}
|
||||
|
||||
public String getAdditionalInfo() {
|
||||
return this.additionalInfo;
|
||||
}
|
||||
|
||||
public String getTableStateText() {
|
||||
return tableStateText;
|
||||
}
|
||||
|
||||
public SkillLevel getSkillLevel() {
|
||||
return skillLevel;
|
||||
}
|
||||
|
||||
public String getQuitRatio() {
|
||||
return quitRatio;
|
||||
}
|
||||
|
||||
public boolean isLimited() {
|
||||
return limited;
|
||||
}
|
||||
|
||||
public boolean isRated() {
|
||||
return rated;
|
||||
}
|
||||
|
||||
public boolean isPassworded() {
|
||||
return passworded;
|
||||
}
|
||||
}
|
||||
117
Mage.Common/src/main/java/mage/view/TournamentGameView.java
Normal file
117
Mage.Common/src/main/java/mage/view/TournamentGameView.java
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import mage.game.Game;
|
||||
import mage.game.tournament.TournamentPairing;
|
||||
import mage.util.DateFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
||||
public class TournamentGameView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final int roundNum;
|
||||
private final UUID matchId;
|
||||
private final UUID gameId;
|
||||
private final String state;
|
||||
private final String result;
|
||||
private final String players;
|
||||
private final UUID tableId;
|
||||
|
||||
TournamentGameView(int roundNum, UUID matchId, UUID gameId, String state, String result, String players, UUID tableId) {
|
||||
this.roundNum = roundNum;
|
||||
this.matchId = matchId;
|
||||
this.gameId = gameId;
|
||||
this.state = state;
|
||||
this.result = result;
|
||||
this.players = players;
|
||||
this.tableId = tableId;
|
||||
}
|
||||
|
||||
TournamentGameView(int roundNum, TournamentPairing pair, Game game) {
|
||||
this.roundNum = roundNum;
|
||||
this.matchId = pair.getMatch().getId();
|
||||
this.gameId = game.getId();
|
||||
this.players = pair.getPlayer1().getPlayer().getName() + " - " + pair.getPlayer2().getPlayer().getName();
|
||||
String duelingTime = "";
|
||||
|
||||
if (game.hasEnded()) {
|
||||
if (game.getEndTime() != null) {
|
||||
duelingTime = " (" + DateFormat.getDuration((game.getEndTime().getTime() - game.getStartTime().getTime())/1000) + ')';
|
||||
}
|
||||
this.state = "Finished" + duelingTime;
|
||||
this.result = game.getWinner();
|
||||
}
|
||||
else {
|
||||
if (game.getStartTime() != null) {
|
||||
duelingTime = " (" + DateFormat.getDuration((new Date().getTime() - game.getStartTime().getTime())/1000) + ')';
|
||||
}
|
||||
this.state = "Dueling" + duelingTime;
|
||||
this.result = "";
|
||||
}
|
||||
this.tableId = pair.getTableId();
|
||||
|
||||
}
|
||||
|
||||
public int getRoundNum() {
|
||||
return roundNum;
|
||||
}
|
||||
|
||||
public UUID getMatchId() {
|
||||
return this.matchId;
|
||||
}
|
||||
|
||||
public UUID getGameId() {
|
||||
return this.gameId;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public String getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public String getPlayers() {
|
||||
return this.players;
|
||||
}
|
||||
|
||||
public UUID getTableId() {
|
||||
return tableId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentPlayerView implements Serializable, Comparable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String flagName;
|
||||
private final String name;
|
||||
private final String state;
|
||||
private final String results;
|
||||
private final String history;
|
||||
private final int points;
|
||||
private final boolean quit;
|
||||
|
||||
TournamentPlayerView(TournamentPlayer tournamentPlayer) {
|
||||
this.name = tournamentPlayer.getPlayer().getName();
|
||||
StringBuilder sb = new StringBuilder(tournamentPlayer.getState().toString());
|
||||
String stateInfo = tournamentPlayer.getStateInfo();
|
||||
if (!stateInfo.isEmpty()) {
|
||||
sb.append(" (").append(stateInfo).append(')');
|
||||
}
|
||||
sb.append(tournamentPlayer.getDisconnectInfo());
|
||||
this.state = sb.toString();
|
||||
this.points = tournamentPlayer.getPoints();
|
||||
this.results = tournamentPlayer.getResults();
|
||||
this.quit = !tournamentPlayer.isInTournament();
|
||||
this.history = tournamentPlayer.getPlayer().getUserData().getHistory();
|
||||
this.flagName = tournamentPlayer.getPlayer().getUserData().getFlagName();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return this.points;
|
||||
}
|
||||
|
||||
public String getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public boolean hasQuit() {
|
||||
return quit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object t) {
|
||||
return ((TournamentPlayerView) t).getPoints() - this.getPoints();
|
||||
}
|
||||
|
||||
public String getFlagName() {
|
||||
return flagName;
|
||||
}
|
||||
|
||||
public String getHistory() {
|
||||
return history;
|
||||
}
|
||||
|
||||
}
|
||||
109
Mage.Common/src/main/java/mage/view/TournamentTypeView.java
Normal file
109
Mage.Common/src/main/java/mage/view/TournamentTypeView.java
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.game.tournament.TournamentType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentTypeView implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
||||
private final String name;
|
||||
private final int minPlayers;
|
||||
private final int maxPlayers;
|
||||
private final int numBoosters;
|
||||
private final boolean draft;
|
||||
private final boolean limited;
|
||||
private final boolean cubeBooster;
|
||||
private final boolean elimination;
|
||||
private final boolean random;
|
||||
private final boolean richMan;
|
||||
|
||||
public TournamentTypeView(TournamentType tournamentType) {
|
||||
this.name = tournamentType.getName();
|
||||
this.minPlayers = tournamentType.getMinPlayers();
|
||||
this.maxPlayers = tournamentType.getMaxPlayers();
|
||||
this.numBoosters = tournamentType.getNumBoosters();
|
||||
this.draft = tournamentType.isDraft();
|
||||
this.limited = tournamentType.isLimited();
|
||||
this.cubeBooster = tournamentType.isCubeBooster();
|
||||
this.elimination = tournamentType.isElimination();
|
||||
this.random = tournamentType.isRandom();
|
||||
this.richMan = tournamentType.isRichMan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getMinPlayers() {
|
||||
return minPlayers;
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
public int getNumBoosters() {
|
||||
return numBoosters;
|
||||
}
|
||||
|
||||
public boolean isDraft() {
|
||||
return draft;
|
||||
}
|
||||
|
||||
public boolean isLimited() {
|
||||
return limited;
|
||||
}
|
||||
|
||||
public boolean isCubeBooster() {
|
||||
return cubeBooster;
|
||||
}
|
||||
|
||||
public boolean isElimination() {
|
||||
return elimination;
|
||||
}
|
||||
|
||||
public boolean isRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
public boolean isRichMan() {
|
||||
return richMan;
|
||||
}
|
||||
}
|
||||
146
Mage.Common/src/main/java/mage/view/TournamentView.java
Normal file
146
Mage.Common/src/main/java/mage/view/TournamentView.java
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import mage.game.tournament.Round;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TournamentView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String tournamentName;
|
||||
private final String tournamentType;
|
||||
private final String tournamentState;
|
||||
|
||||
private final Date startTime;
|
||||
private final Date endTime;
|
||||
private final Date stepStartTime;
|
||||
private final Date serverTime;
|
||||
private final int constructionTime;
|
||||
private final boolean watchingAllowed;
|
||||
|
||||
private final List<RoundView> rounds = new ArrayList<>();
|
||||
private final List<TournamentPlayerView> players = new ArrayList<>();
|
||||
private final String runningInfo;
|
||||
|
||||
public TournamentView(Tournament tournament) {
|
||||
|
||||
tournamentName = tournament.getOptions().getName();
|
||||
StringBuilder typeText = new StringBuilder(tournament.getOptions().getTournamentType());
|
||||
if (!tournament.getTournamentType().isLimited()) {
|
||||
typeText.append(" / ").append(tournament.getOptions().getMatchOptions().getDeckType());
|
||||
}
|
||||
if (tournament.getNumberRounds() > 0) {
|
||||
typeText.append(' ').append(tournament.getNumberRounds()).append(" rounds");
|
||||
}
|
||||
tournamentType = typeText.toString();
|
||||
startTime = tournament.getStartTime();
|
||||
endTime = tournament.getEndTime();
|
||||
stepStartTime = tournament.getStepStartTime();
|
||||
constructionTime = tournament.getOptions().getLimitedOptions().getConstructionTime();
|
||||
watchingAllowed = tournament.getOptions().isWatchingAllowed();
|
||||
serverTime = new Date();
|
||||
tournamentState = tournament.getTournamentState();
|
||||
|
||||
if (tournament.getTournamentState().equals("Drafting") && tournament.getDraft() != null) {
|
||||
runningInfo = "booster/card: " + tournament.getDraft().getBoosterNum() + '/' + (tournament.getDraft().getCardNum() -1);
|
||||
} else {
|
||||
runningInfo = "";
|
||||
}
|
||||
for (TournamentPlayer player: tournament.getPlayers()) {
|
||||
players.add(new TournamentPlayerView(player));
|
||||
}
|
||||
Collections.sort(players);
|
||||
for (Round round: tournament.getRounds()) {
|
||||
rounds.add(new RoundView(round));
|
||||
}
|
||||
}
|
||||
|
||||
public String getTournamentName() {
|
||||
return tournamentName;
|
||||
}
|
||||
|
||||
public String getTournamentType() {
|
||||
return tournamentType;
|
||||
}
|
||||
|
||||
public Date getStartTime() {
|
||||
return new Date(startTime.getTime());
|
||||
}
|
||||
|
||||
public Date getEndTime() {
|
||||
if (endTime == null) {
|
||||
return null;
|
||||
}
|
||||
return new Date(endTime.getTime());
|
||||
}
|
||||
|
||||
public boolean isWatchingAllowed() {
|
||||
return watchingAllowed;
|
||||
}
|
||||
|
||||
public List<TournamentPlayerView> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
public List<RoundView> getRounds() {
|
||||
return rounds;
|
||||
}
|
||||
|
||||
public String getTournamentState() {
|
||||
return tournamentState;
|
||||
}
|
||||
|
||||
public Date getStepStartTime() {
|
||||
return stepStartTime;
|
||||
}
|
||||
|
||||
public int getConstructionTime() {
|
||||
return constructionTime;
|
||||
}
|
||||
|
||||
public Date getServerTime() {
|
||||
return serverTime;
|
||||
}
|
||||
|
||||
public String getRunningInfo() {
|
||||
return runningInfo;
|
||||
}
|
||||
|
||||
}
|
||||
82
Mage.Common/src/main/java/mage/view/UserDataView.java
Normal file
82
Mage.Common/src/main/java/mage/view/UserDataView.java
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.players.net.UserData;
|
||||
import mage.players.net.UserSkipPrioritySteps;
|
||||
|
||||
/**
|
||||
* Transfer object for {@link mage.players.net.UserData}
|
||||
*
|
||||
* @author ayrat
|
||||
*/
|
||||
public class UserDataView implements Serializable {
|
||||
|
||||
protected int avatarId;
|
||||
protected int userGroup;
|
||||
protected boolean showAbilityPickerForced;
|
||||
protected boolean allowRequestShowHandCards;
|
||||
protected boolean confirmEmptyManaPool;
|
||||
protected UserSkipPrioritySteps userSkipPrioritySteps;
|
||||
String flagName;
|
||||
protected boolean askMoveToGraveOrder;
|
||||
|
||||
static UserData getDefaultUserData() {
|
||||
return UserData.getDefaultUserDataView();
|
||||
}
|
||||
|
||||
public static UserDataView getDefaultUserDataView() {
|
||||
return new UserDataView(getDefaultUserData());
|
||||
}
|
||||
|
||||
public UserDataView(int avatarId, boolean showAbilityPickerForced, boolean allowRequestShowHandCards,
|
||||
boolean confirmEmptyManaPool, UserSkipPrioritySteps userSkipPrioritySteps, String flagName, boolean askMoveToGraveOrder) {
|
||||
this.avatarId = avatarId;
|
||||
this.showAbilityPickerForced = showAbilityPickerForced;
|
||||
this.allowRequestShowHandCards = allowRequestShowHandCards;
|
||||
this.userSkipPrioritySteps = userSkipPrioritySteps;
|
||||
this.confirmEmptyManaPool = confirmEmptyManaPool;
|
||||
this.flagName = flagName;
|
||||
this.askMoveToGraveOrder = askMoveToGraveOrder;
|
||||
|
||||
}
|
||||
|
||||
public UserDataView(UserData userData) {
|
||||
this.avatarId = userData.getAvatarId();
|
||||
this.userGroup = userData.getGroupId();
|
||||
this.allowRequestShowHandCards = userData.isAllowRequestShowHandCards();
|
||||
this.showAbilityPickerForced = userData.isShowAbilityPickerForced();
|
||||
this.userSkipPrioritySteps = userData.getUserSkipPrioritySteps();
|
||||
this.confirmEmptyManaPool = userData.confirmEmptyManaPool();
|
||||
this.flagName = userData.getFlagName();
|
||||
this.askMoveToGraveOrder = userData.askMoveToGraveOrder();
|
||||
}
|
||||
|
||||
public int getAvatarId() {
|
||||
return avatarId;
|
||||
}
|
||||
|
||||
public boolean isShowAbilityPickerForced() {
|
||||
return showAbilityPickerForced;
|
||||
}
|
||||
|
||||
public boolean allowRequestShowHandCards() {
|
||||
return allowRequestShowHandCards;
|
||||
}
|
||||
|
||||
public UserSkipPrioritySteps getUserSkipPrioritySteps() {
|
||||
return userSkipPrioritySteps;
|
||||
}
|
||||
|
||||
public boolean confirmEmptyManaPool() {
|
||||
return confirmEmptyManaPool;
|
||||
}
|
||||
|
||||
public String getFlagName() {
|
||||
return flagName;
|
||||
}
|
||||
|
||||
public boolean askMoveToGraveOrder() {
|
||||
return askMoveToGraveOrder;
|
||||
}
|
||||
|
||||
}
|
||||
173
Mage.Common/src/main/java/mage/view/UserRequestMessage.java
Normal file
173
Mage.Common/src/main/java/mage/view/UserRequestMessage.java
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import mage.constants.PlayerAction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class UserRequestMessage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String titel;
|
||||
private final String message;
|
||||
private UUID relatedUserId;
|
||||
private String relatedUserName;
|
||||
private UUID matchId;
|
||||
private UUID tournamentId;
|
||||
private UUID gameId;
|
||||
private UUID roomId;
|
||||
private UUID tableId;
|
||||
|
||||
private String button1Text;
|
||||
private PlayerAction button1Action;
|
||||
|
||||
private String button2Text;
|
||||
private PlayerAction button2Action;
|
||||
|
||||
private String button3Text;
|
||||
private PlayerAction button3Action;
|
||||
|
||||
public UserRequestMessage(String titel, String message) {
|
||||
this.titel = titel;
|
||||
this.message = message;
|
||||
this.button1Action = null;
|
||||
this.button2Action = null;
|
||||
this.button3Action = null;
|
||||
}
|
||||
|
||||
public void setMatchId(UUID matchId) {
|
||||
this.matchId = matchId;
|
||||
}
|
||||
|
||||
public void setGameId(UUID gameId) {
|
||||
this.gameId = gameId;
|
||||
}
|
||||
|
||||
public void setRelatedUser(UUID userId, String name) {
|
||||
this.relatedUserId = userId;
|
||||
this.relatedUserName = name;
|
||||
}
|
||||
|
||||
public void setButton1(String text, PlayerAction buttonAction) {
|
||||
this.button1Text = text;
|
||||
this.button1Action = buttonAction;
|
||||
}
|
||||
|
||||
public void setButton2(String text, PlayerAction buttonAction) {
|
||||
this.button2Text = text;
|
||||
this.button2Action = buttonAction;
|
||||
}
|
||||
|
||||
public void setButton3(String text, PlayerAction buttonAction) {
|
||||
this.button3Text = text;
|
||||
this.button3Action = buttonAction;
|
||||
}
|
||||
|
||||
public String getTitel() {
|
||||
return titel;
|
||||
}
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public UUID getRelatedUserId() {
|
||||
return relatedUserId;
|
||||
}
|
||||
|
||||
public String getRelatedUserName() {
|
||||
return relatedUserName;
|
||||
}
|
||||
|
||||
public UUID getMatchId() {
|
||||
return matchId;
|
||||
}
|
||||
|
||||
public UUID getGameId() {
|
||||
return gameId;
|
||||
}
|
||||
|
||||
public UUID getTournamentId() {
|
||||
return tournamentId;
|
||||
}
|
||||
|
||||
public void setTournamentId(UUID tournamentId) {
|
||||
this.tournamentId = tournamentId;
|
||||
}
|
||||
|
||||
public UUID getRoomId() {
|
||||
return roomId;
|
||||
}
|
||||
|
||||
public void setRoomId(UUID roomId) {
|
||||
this.roomId = roomId;
|
||||
}
|
||||
|
||||
public UUID getTableId() {
|
||||
return tableId;
|
||||
}
|
||||
|
||||
public void setTableId(UUID tableId) {
|
||||
this.tableId = tableId;
|
||||
}
|
||||
|
||||
public String getButton1Text() {
|
||||
return button1Text;
|
||||
}
|
||||
|
||||
public PlayerAction getButton1Action() {
|
||||
return button1Action;
|
||||
}
|
||||
|
||||
public String getButton2Text() {
|
||||
return button2Text;
|
||||
}
|
||||
|
||||
public PlayerAction getButton2Action() {
|
||||
return button2Action;
|
||||
}
|
||||
|
||||
public String getButton3Text() {
|
||||
return button3Text;
|
||||
}
|
||||
|
||||
public PlayerAction getButton3Action() {
|
||||
return button3Action;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue