-
Notifications
You must be signed in to change notification settings - Fork 1
/
MerchantCard.cs
112 lines (81 loc) · 3.03 KB
/
MerchantCard.cs
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using UnityEngine;
using System.Collections;
public class MerchantCard : MonoBehaviour {
public DesertGenerator.GoodItem first_good;
public DesertGenerator.GoodItem second_good;
public DesertGenerator.GoodItem third_good;
public GameObject first_position;
public GameObject second_position;
public GameObject third_position;
public GameObject player;
public GameController controller;
float doubleClickStart = 0;
// Use this for initialization
// Use this for initialization
void Start () {
SetGoods (first_good, second_good, third_good);
controller = GameObject.Find ("GameController").GetComponent<GameController> ();
}
public void SetGoods(DesertGenerator.GoodItem first, DesertGenerator.GoodItem second, DesertGenerator.GoodItem third) {
first_good = first;
second_good = second;
third_good = third;
first_position.GetComponent<TradePlacement>().setGood(first_good);
second_position.GetComponent<TradePlacement>().setGood(second_good);
if (third_good == (DesertGenerator.GoodItem)(-1)) {
Destroy (third_position);
} else {
third_position.GetComponent<TradePlacement>().setGood(third_good);
}
}
// Update is called once per frame
void Update () {
}
void OnMouseUp ()
{
if ((Time.time - doubleClickStart) < 0.3f) {
this.OnDoubleClick ();
doubleClickStart = -1;
} else {
doubleClickStart = Time.time;
}
}
//in general double click is how a player ends his turn early (ie before running out of wter)
void OnDoubleClick ()
{
GameObject currentPlayer = GameObject.Find ("GameController").GetComponent<GameController> ().currentPlayer ();
Vector3 originalPosition = gameObject.transform.position;
PlayerInventory inventory = currentPlayer.GetComponent<PlayerInventory> ();
if (!player || currentPlayer == player)
{
if (third_good == (DesertGenerator.GoodItem)(-1))
{
if (inventory.hasNumberOfGivenGoodItem(first_good,1) && inventory.hasNumberOfGivenGoodItem(second_good, 1))
{
inventory.removeGoods(first_good,1);
inventory.removeGoods(second_good,1);
inventory.AddVictoryPoint ();
if (!player) {
GameObject new_card = controller.deck.Pop();
iTween.MoveTo(new_card, originalPosition, 1.0f);
}
controller.Discard(gameObject);
iTween.MoveTo(gameObject, ((currentPlayer.transform.position + Vector3.left *20) - gameObject.transform.position ) * 2, 1.0f);
}
} else {
if (inventory.hasNumberOfGivenGoodItem(first_good,1) && inventory.hasNumberOfGivenGoodItem(second_good, 1) && inventory.hasNumberOfGivenGoodItem(third_good,1) ) {
inventory.removeGoods(first_good,1);
inventory.removeGoods(second_good,1);
inventory.removeGoods(third_good,1);
inventory.AddVictoryPoint ();
if (!player) {
GameObject new_card = controller.deck.Pop();
iTween.MoveTo(new_card, originalPosition, 1.0f);
}
controller.Discard(gameObject);
iTween.MoveTo(gameObject, ((currentPlayer.transform.position + Vector3.left *20) - gameObject.transform.position ) * 2, 1.0f);
}
}
}
}
}