// File: /workspace/github_cpp_makefile_star2_O3/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 0x964c(%rip), %r14      # 0x11fd0
leaq 0x3ee8(%rip), %rsi      # 0xc873
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 0x3ec4(%rip), %rsi      # 0xc87c
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 0x4173(%rip), %rsi      # 0xcb66
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 0x9037
cmpl $0x0, 0xa0(%rbx)
jne 0x8a76
movq 0x40(%rbx), %rax
cmpq 0x38(%rbx), %rax
je 0x91c2
movq 0x9553(%rip), %r14      # 0x11fd0
leaq 0x413b(%rip), %rsi      # 0xcbbf
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 0x86f2
movq %rbx, %rdi
callq 0x91d4
movq %rbx, %rdi
callq 0x92d6
xorl %eax, %eax
movl %eax, 0x14(%rsp)
movl %eax, 0x10(%rsp)
cmpl %eax, 0xa0(%rbx)
je 0x910f
leaq 0x4097(%rip), %rsi      # 0xcbbf
leaq 0x4b3f(%rip), %r13      # 0xd66e
movq 0x94aa(%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 0x90aa
cmpl $0x79, %eax
je 0x8cc1
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x3e, %edx
movq %rax, %rdi
leaq 0x3fdc(%rip), %rsi      # 0xcbd2
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 0x8bb7
movq %rbx, %rdi
callq 0x91d4
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x31, %edx
movq %rax, %rdi
leaq 0x3fdb(%rip), %rsi      # 0xcc3d
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 0x8c32
movq 0x50(%rbx), %rcx
movq 0x58(%rbx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jb 0x8c32
decl %eax
movq (%rcx,%rax,8), %rdi
callq 0x7c70
testb %al, %al
jne 0x8d9e
movl $0x3b, %edx
movq %r14, %rdi
leaq 0x3f67(%rip), %rsi      # 0xcc6f
jmp 0x8e10
movq %rbx, %rdi
callq 0x86f2
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x45, %edx
movq %rax, %rdi
leaq 0x3f6e(%rip), %rsi      # 0xccab
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 0x8d0d
movq 0x20(%rbx), %rcx
movq 0x28(%rbx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jb 0x8d0d
decl %eax
movq (%rcx,%rax,8), %rax
movl 0x28(%rax), %ecx
cmpl 0xa0(%rbx), %ecx
jbe 0x8de5
movl $0x34, %edx
movq %r14, %rdi
leaq 0x3f0e(%rip), %rsi      # 0xccf1
jmp 0x8e10
movl 0x58(%rax), %r12d
movl 0x14(%rsp), %eax
decl %eax
movq 0x50(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x7b88
cmpl %eax, %r12d
jbe 0x8e57
movl $0x50, %edx
movq %r14, %rdi
leaq 0x3f16(%rip), %rsi      # 0xcd26
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
xorl %eax, %eax
leaq 0x3d7a(%rip), %rsi      # 0xcbbf
cmpl $0x0, 0xa0(%rbx)
jne 0x8b3b
jmp 0x910f
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 0x7dbc
movl $0x3e, %edx
movq %r14, %rdi
leaq 0x3ee7(%rip), %rsi      # 0xcd77
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 0x8fd5
movb $0x30, 0xf(%rsp)
movb $0x30, %al
cmpb $0x6e, %al
je 0x8fd5
movzbl %al, %eax
cmpl $0x79, %eax
je 0x8f82
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
movq %r14, %rdi
callq 0x31a0
movq %rax, %r12
movl $0x3f, %edx
movq %rax, %rdi
leaq 0x3e74(%rip), %rsi      # 0xcdb6
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
movb 0xf(%rsp), %al
jmp 0x8f0a
movl 0x10(%rsp), %eax
decl %eax
movq 0x20(%rbx), %rcx
movq (%rcx,%rax,8), %rax
movl 0x60(%rax), %ecx
subl %ecx, 0xa0(%rbx)
movq 0x50(%rax), %xmm0
movd 0x5c(%rax), %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, 0x50(%rax)
movl $0x38, %edx
movq %r14, %rdi
leaq 0x3e36(%rip), %rsi      # 0xcdf6
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 0x7da8
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 0x9021
leaq (%rcx,%rax,8), %rdi
subq %rsi, %rdx
callq 0x31e0
movq 0x28(%rbx), %rdx
xorl %eax, %eax
leaq 0x3b95(%rip), %rsi      # 0xcbbf
addq $-0x8, %rdx
movq %rdx, 0x28(%rbx)
jmp 0x8e45
leaq 0x385c(%rip), %rsi      # 0xc89a
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 0x3b60(%rip), %rsi      # 0xcc11
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 0x3d19(%rip), %rsi      # 0xce2f
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 0x3cfe(%rip), %rsi      # 0xce6c
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 0x39ad(%rip), %rsi      # 0xcb76
movl $0x48, %edx
jmp 0x9043
nop