// File: AngelPn[P]L5R-card_game/src/Player.cpp
// Function: Player::equipPhase()
void Player::equipPhase()
{
	cout << "Player: " << this->name << " is playing " << endl;
	cout << "Equip Phase ..." << endl << endl;
	//player prints hand and army if has any
	if (!army.size())
	{
		cout << "No army found, phase is skipped :(" << endl << endl;
		return;
	}
	else if (!money && holdings.size() == 0)
	{
		cout << "No money and holdings available (you're broke dude), phase is skipped :(" << endl << endl;
		return;
	}

	else //proceed only if army and money are both available
	{
		cout << "Available money : " << money << endl << endl;
		this->printHand();
		this->printArmy();
	}

	this->tapHoldings(); //tap any holdings in case you need money

	char input;
	unsigned int soldier = 0, card = 0;

	while(money)  //while player has money and wants to
	{
		input = '0';
		soldier=0;
		card = 0;
		cout << "Available money : " << money << endl << endl;
		while (input != 'y' && input != 'n')
		{
			cout << this->name<< ", do you want to buy any cards from your hand (y:yes / n:no) ?" << endl;
			cin >> input;
		}

		if (input == 'n')
		{
			cout << "Well, okay then, get ready for battle phase" << endl << endl;
			break; //exit equip phase
		}
		while (soldier < 1 || soldier > army.size())
		{
			this->printArmy();
			cout << this->name<< ", choose a personality of your army to equip: (1-" << army.size() << ")" << endl;
			cin >> soldier;
		}

		//if the upper bound of green cards for the personality is  exceeded
		if (army[soldier-1]->belowBound() == false)
		{
			cout << "Personality already has max green cards, purchase cancelled" << endl;
			continue;
		}

		while (card < 1 || card > hand.size())
		{
			this->printHand();
			cout << this->name<< ", choose a card in your hand to equip selected personality with : (1-" << hand.size() << ")" << endl;
			cin >> card;
		}

		//if money is not enough for purchase
		if (hand[card-1]->get_cost() > money)
		{
			cout << "Selected card cannot be afforded, purchase cancelled" << endl;
			continue;
		}

		//if minimum honour of selected card is not matched by honour of selected personality
		if (hand[card-1]->get_honour() > army[soldier-1]->get_honour())
		{
			cout << "Selected card's honour is too high for your selected soldier, purchase cancelled" << endl;
			continue;
		}

		//at this point purchase is made
		money -= hand[card-1]->get_cost();   //make purchase
		//assign card (item or follower) to personality
		army[soldier-1]->equip(hand[card-1]);
		cout << "Purchase successfully made, card was assigned to your soldier " << endl << endl;
		//if player has available money to buy the effect cost of card
		if (hand[card-1]->get_effectCost() <= money)
		{
			input = '0';
			while (input != 'y' && input != 'n')
			{
				cout << this->name<< ", do you want buy the effect bonus of the card (y:yes / n:no) ?" << endl;
				cin >> input;
			}

			if (input == 'y')
			{
				money -= hand[card-1]->get_effectCost(); //make purchase
				//apply effectBonus to card
				hand[card-1]->applyBonus();
				cout << "Purchase successfully made,effect bonus of card applied " << endl << endl;
			}
		}

		//add attack/defense bonuses of card directly to soldier (this can be done either here or in battle phase)
		army[soldier-1]->applyBonus(hand[card-1]);
		hand.erase(hand.begin() + (card-1)); //erase card from hand

	}


	//HERE: money == roundMoney + the sum of all the harvest values of the tapped holdings - the sum of the cost of the cards bought
	//Thus if money - roundMoney > 0 => the sum of all the harvest values of the tapped holdings > the sum of the cost of the cards bought =>
	//some money (exactly money - roundMoney) from the tapping of the holdings was not used and it needs to be substracted
	//so in this case the new value of money would be money - (money - roundMoney) == roundMoney , hence the assignment money = roundMoney
	//else no substraction is made ,money remains intact and is assigned to roundMoney.

	cout << "Any remainder of the money from the tapped holdings is lost " << endl;
	money = (money > roundMoney) ? roundMoney : money ;  //if money  > roundMoney that means that some money from the tapping of the holdings was not used
	roundMoney = money;									 //and it needs to be substracted , thus money is set to be roundMoney
	cout << "Available money now is " << money << endl;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x150c2(%rip), %rdi     # 0x24fd0
leaq 0x8853(%rip), %rsi      # 0x18768
callq 0x4200
movq -0x40(%rbp), %rsi
movq %rax, %rdi
addq $0xa8, %rsi
callq 0x41d0
movq %rax, %rdi
leaq 0x883a(%rip), %rsi      # 0x18771
callq 0x4200
movq %rax, %rdi
movq 0x1507a(%rip), %rsi     # 0x24fc0
callq 0x4230
movq 0x1507e(%rip), %rdi     # 0x24fd0
leaq 0x8ab0(%rip), %rsi      # 0x18a09
callq 0x4200
movq %rax, %rdi
movq 0x15058(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x15049(%rip), %rsi     # 0x24fc0
callq 0x4230
movq -0x40(%rbp), %rdi
addq $0x50, %rdi
callq 0x13930
cmpq $0x0, %rax
jne 0xffc5
movq 0x1503a(%rip), %rdi     # 0x24fd0
leaq 0x87f2(%rip), %rsi      # 0x1878f
callq 0x4200
movq %rax, %rdi
movq 0x15014(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x15005(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0x10739
movq -0x40(%rbp), %rax
cmpl $0x0, 0xa0(%rax)
jne 0x1001b
movq -0x40(%rbp), %rdi
addq $0x38, %rdi
callq 0x13910
cmpq $0x0, %rax
jne 0x1001b
movq 0x14fe4(%rip), %rdi     # 0x24fd0
leaq 0x8a26(%rip), %rsi      # 0x18a19
callq 0x4200
movq %rax, %rdi
movq 0x14fbe(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x14faf(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0x10739
movq 0x14fae(%rip), %rdi     # 0x24fd0
leaq 0x8a39(%rip), %rsi      # 0x18a62
callq 0x4200
movq %rax, %rdi
movq -0x40(%rbp), %rax
movl 0xa0(%rax), %esi
callq 0x42c0
movq %rax, %rdi
movq 0x14f76(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x14f67(%rip), %rsi     # 0x24fc0
callq 0x4230
movq -0x40(%rbp), %rdi
callq 0xfcd0
movq -0x40(%rbp), %rdi
callq 0x10750
jmp 0x10072
movq -0x40(%rbp), %rdi
callq 0x10830
movl $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0xa0(%rax)
je 0x10693
movb $0x30, -0x9(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq 0x14f1d(%rip), %rdi     # 0x24fd0
leaq 0x89a8(%rip), %rsi      # 0x18a62
callq 0x4200
movq %rax, %rdi
movq -0x40(%rbp), %rax
movl 0xa0(%rax), %esi
callq 0x42c0
movq %rax, %rdi
movq 0x14ee5(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x14ed6(%rip), %rsi     # 0x24fc0
callq 0x4230
movsbl -0x9(%rbp), %ecx
xorl %eax, %eax
cmpl $0x79, %ecx
movb %al, -0x41(%rbp)
je 0x1010a
movsbl -0x9(%rbp), %eax
cmpl $0x6e, %eax
setne %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x10113
jmp 0x1015a
movq -0x40(%rbp), %rsi
addq $0xa8, %rsi
movq 0x14eab(%rip), %rdi     # 0x24fd0
callq 0x41d0
movq %rax, %rdi
leaq 0x8941(%rip), %rsi      # 0x18a75
callq 0x4200
movq %rax, %rdi
movq 0x14e7d(%rip), %rsi     # 0x24fc0
callq 0x4230
movq 0x14e91(%rip), %rdi     # 0x24fe0
leaq -0x9(%rbp), %rsi
callq 0x42b0
jmp 0x100ef
movsbl -0x9(%rbp), %eax
cmpl $0x6e, %eax
jne 0x10199
movq 0x14e66(%rip), %rdi     # 0x24fd0
leaq 0x8943(%rip), %rsi      # 0x18ab4
callq 0x4200
movq %rax, %rdi
movq 0x14e40(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x14e31(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0x10693
jmp 0x1019b
movb $0x1, %al
cmpl $0x1, -0x10(%rbp)
movb %al, -0x42(%rbp)
jb 0x101ca
movq -0x40(%rbp), %rdi
movl -0x10(%rbp), %eax
movq %rax, -0x50(%rbp)
addq $0x50, %rdi
callq 0x13930
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
seta %al
movb %al, -0x42(%rbp)
movb -0x42(%rbp), %al
testb $0x1, %al
jne 0x101d3
jmp 0x10252
movq -0x40(%rbp), %rdi
callq 0x10750
movq -0x40(%rbp), %rsi
addq $0xa8, %rsi
movq 0x14de2(%rip), %rdi     # 0x24fd0
callq 0x41d0
movq %rax, %rdi
leaq 0x88e3(%rip), %rsi      # 0x18ae0
callq 0x4200
movq -0x40(%rbp), %rdi
movq %rax, -0x58(%rbp)
addq $0x50, %rdi
callq 0x13930
movq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0x4090
movq %rax, %rdi
leaq 0x92e8(%rip), %rsi      # 0x19511
callq 0x4200
movq %rax, %rdi
movq 0x14d88(%rip), %rsi     # 0x24fc0
callq 0x4230
movq 0x14d9c(%rip), %rdi     # 0x24fe0
leaq -0x10(%rbp), %rsi
callq 0x4050
jmp 0x1019b
movq -0x40(%rbp), %rdi
addq $0x50, %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d30
movq (%rax), %rdi
callq 0xde60
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x102a2
movq 0x14d4e(%rip), %rdi     # 0x24fd0
leaq 0x8889(%rip), %rsi      # 0x18b12
callq 0x4200
movq %rax, %rdi
movq 0x14d28(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0x10089
jmp 0x102a4
movb $0x1, %al
cmpl $0x1, -0x14(%rbp)
movb %al, -0x59(%rbp)
jb 0x102d3
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %eax
movq %rax, -0x68(%rbp)
addq $0x20, %rdi
callq 0xbd80
movq %rax, %rcx
movq -0x68(%rbp), %rax
cmpq %rcx, %rax
seta %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x102dc
jmp 0x1035b
movq -0x40(%rbp), %rdi
callq 0xfcd0
movq -0x40(%rbp), %rsi
addq $0xa8, %rsi
movq 0x14cd9(%rip), %rdi     # 0x24fd0
callq 0x41d0
movq %rax, %rdi
leaq 0x8848(%rip), %rsi      # 0x18b4e
callq 0x4200
movq -0x40(%rbp), %rdi
movq %rax, -0x70(%rbp)
addq $0x20, %rdi
callq 0xbd80
movq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x4090
movq %rax, %rdi
leaq 0x91df(%rip), %rsi      # 0x19511
callq 0x4200
movq %rax, %rdi
movq 0x14c7f(%rip), %rsi     # 0x24fc0
callq 0x4230
movq 0x14c93(%rip), %rdi     # 0x24fe0
leaq -0x14(%rbp), %rsi
callq 0x4050
jmp 0x102a4
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d50
movq (%rax), %rdi
callq 0x13d70
movq -0x40(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
jbe 0x103ad
movq 0x14c43(%rip), %rdi     # 0x24fd0
leaq 0x8800(%rip), %rsi      # 0x18b94
callq 0x4200
movq %rax, %rdi
movq 0x14c1d(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0x10089
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d50
movq (%rax), %rdi
callq 0x13d90
movq -0x40(%rbp), %rdi
movl %eax, -0x74(%rbp)
addq $0x50, %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d30
movq (%rax), %rdi
callq 0xdbf0
movl %eax, %ecx
movl -0x74(%rbp), %eax
cmpl %ecx, %eax
jbe 0x1041e
movq 0x14bd2(%rip), %rdi     # 0x24fd0
leaq 0x87c4(%rip), %rsi      # 0x18bc9
callq 0x4200
movq %rax, %rdi
movq 0x14bac(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0x10089
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d50
movq (%rax), %rdi
callq 0x13d70
movq -0x40(%rbp), %rdi
movl %eax, %ecx
movl 0xa0(%rdi), %eax
subl %ecx, %eax
movl %eax, 0xa0(%rdi)
addq $0x50, %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d30
movq -0x40(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x80(%rbp)
addq $0x20, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d50
movq -0x80(%rbp), %rdi
movq (%rax), %rsi
callq 0xe030
movq 0x14b3b(%rip), %rdi     # 0x24fd0
leaq 0x877e(%rip), %rsi      # 0x18c1a
callq 0x4200
movq %rax, %rdi
movq 0x14b15(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x14b06(%rip), %rsi     # 0x24fc0
callq 0x4230
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d50
movq (%rax), %rdi
callq 0x13db0
movq -0x40(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
ja 0x105f0
movb $0x30, -0x9(%rbp)
movsbl -0x9(%rbp), %ecx
xorl %eax, %eax
cmpl $0x79, %ecx
movb %al, -0x81(%rbp)
je 0x10513
movsbl -0x9(%rbp), %eax
cmpl $0x6e, %eax
setne %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x1051f
jmp 0x10566
movq -0x40(%rbp), %rsi
addq $0xa8, %rsi
movq 0x14a9f(%rip), %rdi     # 0x24fd0
callq 0x41d0
movq %rax, %rdi
leaq 0x8719(%rip), %rsi      # 0x18c59
callq 0x4200
movq %rax, %rdi
movq 0x14a71(%rip), %rsi     # 0x24fc0
callq 0x4230
movq 0x14a85(%rip), %rdi     # 0x24fe0
leaq -0x9(%rbp), %rsi
callq 0x42b0
jmp 0x104f2
movsbl -0x9(%rbp), %eax
cmpl $0x79, %eax
jne 0x105ee
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d50
movq (%rax), %rdi
callq 0x13db0
movq -0x40(%rbp), %rdi
movl %eax, %ecx
movl 0xa0(%rdi), %eax
subl %ecx, %eax
movl %eax, 0xa0(%rdi)
addq $0x20, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d50
movq (%rax), %rdi
callq 0x13dd0
movq 0x14a0c(%rip), %rdi     # 0x24fd0
leaq 0x86ce(%rip), %rsi      # 0x18c99
callq 0x4200
movq %rax, %rdi
movq 0x149e6(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x149d7(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0x105f0
movq -0x40(%rbp), %rdi
addq $0x50, %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d30
movq -0x40(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x98(%rbp)
addq $0x20, %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x13d50
movq -0x98(%rbp), %rdi
movq (%rax), %rsi
callq 0xdfe0
movq -0x40(%rbp), %rdi
movq %rdi, %rax
addq $0x20, %rax
movq %rax, -0x90(%rbp)
addq $0x20, %rdi
callq 0x7d50
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0xc010
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x13e60
movq -0x90(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x13df0
movq %rax, -0x38(%rbp)
jmp 0x10089
movq 0x14936(%rip), %rdi     # 0x24fd0
leaq 0x8631(%rip), %rsi      # 0x18cd2
callq 0x4200
movq %rax, %rdi
movq 0x14910(%rip), %rsi     # 0x24fc0
callq 0x4230
movq -0x40(%rbp), %rcx
movl 0xa0(%rcx), %eax
cmpl 0xa4(%rcx), %eax
jbe 0x106d9
movq -0x40(%rbp), %rax
movl 0xa4(%rax), %eax
movl %eax, -0x9c(%rbp)
jmp 0x106e9
movq -0x40(%rbp), %rax
movl 0xa0(%rax), %eax
movl %eax, -0x9c(%rbp)
movq -0x40(%rbp), %rax
movl -0x9c(%rbp), %ecx
movl %ecx, 0xa0(%rax)
movl 0xa0(%rax), %ecx
movl %ecx, 0xa4(%rax)
movq 0x148c4(%rip), %rdi     # 0x24fd0
leaq 0x85fc(%rip), %rsi      # 0x18d0f
callq 0x4200
movq %rax, %rdi
movq -0x40(%rbp), %rax
movl 0xa0(%rax), %esi
callq 0x42c0
movq %rax, %rdi
movq 0x1488c(%rip), %rsi     # 0x24fc0
callq 0x4230
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)