summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java
blob: da16d090bc9b8d3b26548844bbb83e692d57590e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition;

import com.fourisland.fourpuzzle.util.Comparison;
import com.fourisland.fourpuzzle.Game;

/**
 * VariableVariablePrecondition compares two variables together with a specified
 * Comparison.
 *
 * @author hatkirby
 */
public class VariableVariablePrecondition implements Precondition {
    
    private String variableID;
    private Comparison comparison;
    private String variableID2;
    
    public VariableVariablePrecondition(String variableID, Comparison comparison, String variableID2)
    {
        this.variableID = variableID;
        this.comparison = comparison;
        this.variableID2 = variableID2;
    }
    
    public boolean match()
    {
        if (Game.getSaveFile().getVariables().containsKey(variableID))
        {
            if (Game.getSaveFile().getVariables().containsKey(variableID2))
            {
                int n1 = Game.getSaveFile().getVariables().get(variableID);
                int n2 = Game.getSaveFile().getVariables().get(variableID2);

                return comparison.compare(n1, n2);
            }
        }
        
        return false;
    }

}