summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java
blob: 1eb9b0cbccc0d36c79fa1b379ae564bd4b9a7d0b (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
/*
 * 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;

/**
 *
 * @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))
        {
            int n1 = Game.getSaveFile().getVariables().get(variableID);
            int n2 = Game.getSaveFile().getVariables().get(variableID2);
            
            switch (comparison)
            {
                case Less: return (n1 < n2);
                case Greater: return (n1 > n2);
                case Equal: return (n1 == n2);
            }
        }
        
        return false;
    }

}