// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x96b0(%rip), %r14      # 0x11fd0
leaq 0x3f60(%rip), %rsi      # 0xc887
movl $0x8, %edx
movq %r14, %rdi
callq 0x31a0
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %r15
leaq 0x3f3c(%rip), %rsi      # 0xc890
movl $0xc, %edx
movq %rax, %rdi
callq 0x31a0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
leaq 0x41eb(%rip), %rsi      # 0xcb7a
movl $0xf, %edx
movq %r14, %rdi
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq 0x58(%rbx), %rax
cmpq 0x50(%rbx), %rax
je 0x8fb4
cmpl $0x0, 0xa0(%rbx)
jne 0x8a12
movq 0x40(%rbx), %rax
cmpq 0x38(%rbx), %rax
je 0x913f
movq 0x95b7(%rip), %r14      # 0x11fd0
leaq 0x41b3(%rip), %rsi      # 0xcbd3
movl $0x12, %edx
movq %r14, %rdi
callq 0x31a0
movl 0xa0(%rbx), %esi
movq %r14, %rdi
callq 0x30e0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rbx, %rdi
callq 0x868e
movq %rbx, %rdi
callq 0x9150
movq %rbx, %rdi
callq 0x9252
xorl %eax, %eax
movl %eax, 0x14(%rsp)
movl %eax, 0x10(%rsp)
cmpl %eax, 0xa0(%rbx)
je 0x908c
leaq 0x410f(%rip), %rsi      # 0xcbd3
leaq 0x4bb7(%rip), %r13      # 0xd682
movq 0x950e(%rip), %rbp      # 0x11fe0
leaq 0x14(%rsp), %r15
movb $0x30, 0xf(%rsp)
movl %eax, 0x14(%rsp)
movl %eax, 0x10(%rsp)
movl $0x12, %edx
movq %r14, %rdi
callq 0x31a0
movl 0xa0(%rbx), %esi
movq %r14, %rdi
callq 0x30e0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movzbl 0xf(%rsp), %eax
cmpl $0x6e, %eax
je 0x9027
cmpl $0x79, %eax
je 0x8c5d
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x3e, %edx
movq %rax, %rdi
leaq 0x4054(%rip), %rsi      # 0xcbe6
callq 0x31a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rbp, %rdi
leaq 0xf(%rsp), %rsi
callq 0x31c0
jmp 0x8b53
movq %rbx, %rdi
callq 0x9150
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x31, %edx
movq %rax, %rdi
leaq 0x4053(%rip), %rsi      # 0xcc51
callq 0x31a0
movq 0x58(%rbx), %rsi
subq 0x50(%rbx), %rsi
sarq $0x3, %rsi
movq %r12, %rdi
callq 0x30e0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x31a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rbp, %rdi
movq %r15, %rsi
callq 0x3210
movl 0x14(%rsp), %eax
testq %rax, %rax
je 0x8bce
movq 0x50(%rbx), %rcx
movq 0x58(%rbx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jb 0x8bce
decl %eax
movq (%rcx,%rax,8), %rdi
callq 0x7c10
testb %al, %al
jne 0x8d3a
movl $0x3b, %edx
movq %r14, %rdi
leaq 0x3fdf(%rip), %rsi      # 0xcc83
jmp 0x8dac
movq %rbx, %rdi
callq 0x868e
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x45, %edx
movq %rax, %rdi
leaq 0x3fe6(%rip), %rsi      # 0xccbf
callq 0x31a0
movq 0x28(%rbx), %rsi
subq 0x20(%rbx), %rsi
sarq $0x3, %rsi
movq %r12, %rdi
callq 0x30e0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x31a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3210
movl 0x10(%rsp), %eax
testq %rax, %rax
je 0x8ca9
movq 0x20(%rbx), %rcx
movq 0x28(%rbx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jb 0x8ca9
decl %eax
movq (%rcx,%rax,8), %rax
movl 0x28(%rax), %ecx
cmpl 0xa0(%rbx), %ecx
jbe 0x8d81
movl $0x34, %edx
movq %r14, %rdi
leaq 0x3f86(%rip), %rsi      # 0xcd05
jmp 0x8dac
movl 0x58(%rax), %r12d
movl 0x14(%rsp), %eax
decl %eax
movq 0x50(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x7b28
cmpl %eax, %r12d
jbe 0x8df6
movl $0x50, %edx
movq %r14, %rdi
leaq 0x3f8e(%rip), %rsi      # 0xcd3a
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
cmpl $0x0, 0xa0(%rbx)
movl $0x0, %eax
leaq 0x3de8(%rip), %rsi      # 0xcbd3
jne 0x8ad7
jmp 0x908c
movl 0x10(%rsp), %eax
decl %eax
movq 0x20(%rbx), %rcx
movq 0x50(%rbx), %rdx
movq (%rcx,%rax,8), %rsi
movl 0x28(%rsi), %eax
subl %eax, 0xa0(%rbx)
movl 0x14(%rsp), %eax
decl %eax
movq (%rdx,%rax,8), %rdi
callq 0x7d56
movl $0x3e, %edx
movq %r14, %rdi
leaq 0x3f5c(%rip), %rsi      # 0xcd8b
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movl 0x10(%rsp), %eax
decl %eax
movq 0x20(%rbx), %rcx
movq (%rcx,%rax,8), %rax
movl 0x60(%rax), %eax
cmpl 0xa0(%rbx), %eax
ja 0x8f62
movb $0x30, 0xf(%rsp)
movzbl 0xf(%rsp), %eax
cmpl $0x6e, %eax
je 0x8f62
cmpl $0x79, %eax
je 0x8f1e
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x3f, %edx
movq %rax, %rdi
leaq 0x3ee8(%rip), %rsi      # 0xcdca
callq 0x31a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rbp, %rdi
leaq 0xf(%rsp), %rsi
callq 0x31c0
jmp 0x8ea7
movl 0x10(%rsp), %eax
decl %eax
movq 0x20(%rbx), %rcx
movq (%rcx,%rax,8), %rax
movl 0x60(%rax), %ecx
subl %ecx, 0xa0(%rbx)
movl 0x5c(%rax), %ecx
addl %ecx, 0x50(%rax)
addl %ecx, 0x54(%rax)
movl $0x38, %edx
movq %r14, %rdi
leaq 0x3ebd(%rip), %rsi      # 0xce0a
callq 0x31a0
movq %r14, %rdi
callq 0x3090
movq %rax, %rdi
callq 0x3090
movl 0x14(%rsp), %eax
decl %eax
movq 0x20(%rbx), %rcx
movq 0x50(%rbx), %rdx
movq (%rdx,%rax,8), %rdi
movl 0x10(%rsp), %eax
decl %eax
movq (%rcx,%rax,8), %rsi
callq 0x7d48
movl 0x10(%rsp), %eax
decl %eax
movq 0x20(%rbx), %rcx
movq 0x28(%rbx), %rdx
leaq (%rcx,%rax,8), %rsi
addq $0x8, %rsi
cmpq %rdx, %rsi
je 0x8faa
leaq (%rcx,%rax,8), %rdi
subq %rsi, %rdx
callq 0x31e0
addq $-0x8, 0x28(%rbx)
jmp 0x8dd8
leaq 0x38f3(%rip), %rsi      # 0xc8ae
movl $0x22, %edx
movq %r14, %rdi
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30f0
leaq 0x3bf7(%rip), %rsi      # 0xcc25
movl $0x2b, %edx
movq %r14, %rdi
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
leaq 0x3db0(%rip), %rsi      # 0xce43
movl $0x3c, %edx
movq %r14, %rdi
callq 0x31a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movl 0xa0(%rbx), %eax
movl 0xa4(%rbx), %ecx
cmpl %ecx, %eax
cmovbl %eax, %ecx
movl %ecx, 0xa0(%rbx)
movl %ecx, 0xa4(%rbx)
leaq 0x3d95(%rip), %rsi      # 0xce80
movl $0x17, %edx
movq %r14, %rdi
callq 0x31a0
movl 0xa0(%rbx), %esi
movq %r14, %rdi
callq 0x30e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3a44(%rip), %rsi      # 0xcb8a
movl $0x48, %edx
jmp 0x8fc0